package com.yonge.cooleshow.student.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.search.MusicAlbumDetailSearch;
import com.yonge.cooleshow.biz.dal.dto.search.MusicAlbumSearch;
import com.yonge.cooleshow.biz.dal.dto.search.StudentMusicAlbumSearch;
import com.yonge.cooleshow.biz.dal.dto.search.TeacherStyleSearch;
import com.yonge.cooleshow.biz.dal.entity.MusicSheet;
import com.yonge.cooleshow.biz.dal.entity.Student;
import com.yonge.cooleshow.biz.dal.entity.TenantAlbumMusic;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
import com.yonge.cooleshow.biz.dal.enums.album.PurchaseRecordTypeEnum;
import com.yonge.cooleshow.biz.dal.service.AppVersionInfoService;
import com.yonge.cooleshow.biz.dal.service.MusicAlbumService;
import com.yonge.cooleshow.biz.dal.service.StudentService;
import com.yonge.cooleshow.biz.dal.service.TenantAlbumMusicService;
import com.yonge.cooleshow.biz.dal.vo.AlbumDetailVo;
import com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo;
import com.yonge.cooleshow.biz.dal.vo.TeacherStyleVideoVo;
import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumMusicWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.mybatis.support.PageUtil;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 专辑表 web 控制层
 * @author yzp
 * @date 2022-03-26 00:21:46
 * @version v1.0
 **/
@RestController
@RequestMapping("/tenantAlbumMusic")
@Api(tags = "机构专辑曲目 API接口")
public class TenantAlbumSheetController extends BaseController {

    @Autowired
    private TenantAlbumMusicService tenantAlbumMusicService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "查询条件")
    @PostMapping("/selectCondition")
    public HttpResponseResult<TenantAlbumMusicWrapper.TenantAlbumMusicSelectData> selectCondition(@RequestBody TenantAlbumMusicWrapper.TenantAlbumMusicSelect query) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        query.setUserId(user.getId());
        /*if(StringUtils.isBlank(query.getSubjectId())){
        	Student student = studentService.getById(user.getId());
        	query.setSubjectId(student.getSubjectId());
        }*/
        return succeed(tenantAlbumMusicService.getTenantAlbumMusicQuery(query));
    }



    @ApiOperation(value = "分页查询")
    @PostMapping("/page")
    public HttpResponseResult<PageInfo<TenantAlbumMusicWrapper.StudentTenantAlbumMusic>> page(@RequestBody TenantAlbumMusicWrapper.StudentTenantAlbumMusicQuery query) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        // query.setTenantId(Optional.ofNullable(user.getTenantId()).orElse(-1L));
        query.setClientType(ClientEnum.TENANT_STUDENT);
        IPage<TenantAlbumMusicWrapper.StudentTenantAlbumMusic> page = tenantAlbumMusicService.selectPage(QueryInfo.getPage(query), query);
        return succeed((PageUtil.pageInfo(page)));
    }


}
