package com.yonge.cooleshow.biz.dal.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetApiWrapper;
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetApplicationExtendWrapper;
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetExtendWrapper;
import com.yonge.cooleshow.biz.dal.dto.search.*;
import com.yonge.cooleshow.biz.dal.entity.MusicSheet;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.vo.*;
import com.yonge.cooleshow.biz.dal.wrapper.MusicSheetWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.music.MusicCompareWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherHomeWrapper;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * MusicSheetDao数据库访问类
 *
 * @author yzp
 * @version v1.0
 * @date 2022-03-25 23:46:28
 **/
public interface MusicSheetDao extends BaseMapper<MusicSheet> {
    /**
     * 分页查询
     *
     * @return com.yonge.cooleshow.biz.dal.vo.MusicSheetVo
     */
    List<MusicSheetVo> selectPage(@Param("page") IPage<MusicSheetVo> page, @Param("param") MusicSheetSearch query);

    /**
     * 分页查询专辑详情里的曲目
     *
     * @param page  分页
     * @param query 查询条件
     * @return
     */
    List<MusicSheetVo> selectAlbumDetailPage(@Param("page") IPage<MusicSheetVo> page,
                                             @Param("param") MusicAlbumDetailSearch query);

    /**
     * 获取曲目详情
     *
     * @param id 曲目id
     * @return 曲目信息
     */
    MusicSheetDetailVo detail(Long id);

    /**
     * 分页查询
     */
    List<MusicSheetVo> selectStudentMusicPage(@Param("page") IPage<MusicSheetVo> page,
                                              @Param("param") StudentMusicSheetSearch query,
                                              @Param("clientType") ClientEnum clientType);

    /**
     * 我的单曲
     *
     * @param page  分页信息
     * @param query 查询条件
     * @return list
     */
    List<MusicSheetVo> selectMyMusicPage(@Param("page") IPage<MusicSheetVo> page, @Param(
            "param") StudentMusicSheetSearch query);

    /**
     * 收藏单曲
     *
     * @param page       分页信息
     * @param query      查询条件
     * @param clientType ClientEnum
     * @return list
     */
    List<MusicSheetVo> selectFavoriteMusicPage(@Param("page") IPage<MusicSheetVo> page,
                                               @Param("param") StudentMusicSheetSearch query,
                                               @Param("clientType") ClientEnum clientType);

    /**
     * 最近练习曲目
     *
     * @param query               查询条件
     * @param practiceMusicIdList 最近练习曲目id
     * @return list
     */
    List<MusicSheetVo> selectPracticeMusicPage(@Param("param") StudentMusicSheetSearch query, @Param(
            "practiceMusicIdList") List<Long> practiceMusicIdList);

    /**
     * 学生曲目购买信息
     *
     * @param page  分页
     * @param query 查询条件
     * @return list
     */
    List<StudentMusicSheetOrderVo> selectStudentOrderPage(@Param("page") IPage<StudentMusicSheetOrderVo> page, @Param(
            "param") StudentMusicSheetOrderSearch query);

    /**
     * 老师曲目信息
     *
     * @param page  分页
     * @param query 查询条件
     * @return list
     */
    List<TeacherMusicSheetVo> selectTeacherPage(@Param("page") IPage<TeacherMusicSheetVo> page, @Param(
            "param") TeacherMusicSheetSearch query);

    /**
     * 审核中心-乐谱审核
     *
     * @param page  分页
     * @param query 查询条件
     * @return list
     */
    List<TeacherMusicSheetVo> selectAuditPage(@Param("page") IPage<TeacherMusicSheetVo> page, @Param(
            "param") TeacherMusicSheetAuditSearch query);

    /**
     * 获取老师过审的曲目数量
     *
     * @param userId 老师id
     * @return
     */
    Integer selectTeacherMusicSheetCount(@Param("userId") Long userId);

    /**
     * 点播数量统计
     *
     * @return
     */
    HomeMusicSheetVo selectMusicNum();

    /**
     * 查询付费人数最多的前5个曲目
     *
     * @return
     */
    List<HomeMusicSheetVo.MusicSheetSmall> selectPayMusicSheet();

    /**
     * 查询老师曲目审核数量
     *
     * @param userId 老师id
     * @return
     */
    TeacherAuditMusicSheetVo selectTeacherCount(@Param("userId") Long userId);

    /**
     * 老师统计
     *
     * @param userId
     * @return
     */
    List<TeacherTotalVo> queryTeacherTotal(@Param("userId") Long userId);

    /**
     * 学生统计
     *
     * @param userId
     * @return
     */
    List<StudentTotalVo> queryStudentTotal(@Param("userId") Long userId);

    /**
     * 审核历史记录
     *
     * @param musicSheetId 曲目id
     * @return
     */
    List<MusicSheetWrapper.MusicSheetDetailVo> auditDetailList(@Param("batchNo") String batchNo);


    MusicSheetDetailVo auditDetail(@Param("recordId") Long recordId);
    /**
     * 单曲数量统计
     *
     * @param musicIds 单曲ID
     * @return List<StatGroupWrapper>
     */
    List<StatGroupWrapper> selectMusicAlbumStatInfo(@Param("musicIds") List<Long> musicIds);

    Long selectMusicAlbumNum(@Param("musicId") Long musicId);

    /**
     * 修改收藏数
     */
    void updateFavoriteCount(@Param("musicSheetId") Long musicSheetId, @Param("state") YesOrNoEnum state);

    List<MusicSheetUploadCountVo> countByUser(@Param("userIds") List<Long> userIds);

    List<Long> searchMusic(@Param("page") IPage<TeacherMusicSheetVo> page,@Param("param") MusicCompareWrapper.MusicSearch queryInfo);
    List<Long> searchAlbum(@Param("page") IPage<TeacherMusicSheetVo> page,@Param("param") MusicCompareWrapper.MusicSearch queryInfo);

    void updateBatchByCbsId(@Param("vos") List<CbsMusicSheetApplicationExtendWrapper.MusicSheetApplicationExtend> updateMusicScore);

//    void batchInsert(@Param("vos") List<CbsMusicSheetApplicationExtendWrapper.MusicSheetApplicationExtend> addMusicSheet);

    void batchEnable(@Param("ids") String cbsMusicSheetIds, @Param("status") Boolean status, @Param("tenantFlag") boolean tenantFlag);

    void batchDel(@Param("ids") String cbsMusicSheetIds, @Param("tenantFlag") boolean tenantFlag);

    IPage<CbsMusicSheetExtendWrapper.MusicSheetExtend> personOwnerList(@Param("page") IPage<CbsMusicSheetExtendWrapper.MusicSheetExtend> page,
                                                                 @Param("param") CbsMusicSheetExtendWrapper.MusicSheetExtendQuery query);

    IPage<CbsMusicSheetExtendWrapper.MusicSheetExtend> orgOwnerList(@Param("page") IPage<CbsMusicSheetExtendWrapper.MusicSheetExtend> page,
                                                                 @Param("param") CbsMusicSheetExtendWrapper.MusicSheetExtendQuery query);

    void updateMusicSheet(@Param("param") CbsMusicSheetApiWrapper.MusicSheetUpdate musicSheetUpdate);

    MusicSheet get(Long id);

    IPage<MusicSheet> selectSyncPage(Page<Object> objectPage);

    IPage<MusicSheetVo> queryTenantRelatedList(@Param("page") IPage<Object> page, @Param("queryInfo") MusicSheetRelatedQueryInfo queryInfo);

    void updateTenantByCbsId(@Param("item") CbsMusicSheetApplicationExtendWrapper.MusicSheetApplicationExtend extend);

    void updatePlatformByCbsId(@Param("item") CbsMusicSheetApplicationExtendWrapper.MusicSheetApplicationExtend extend);

    void tenantInsert(@Param("item") CbsMusicSheetApplicationExtendWrapper.MusicSheetApplicationExtend extend);

    void platformInsert(@Param("item") CbsMusicSheetApplicationExtendWrapper.MusicSheetApplicationExtend extend);

    void updateState(@Param("ids") String ids);

    void delPractice(@Param("musicSheetId") Long musicSheetId, @Param("userId") Long userId, @Param("clientEnum") ClientEnum clientEnum);

    int countTeacherEnable(@Param("userId") Long userId);

    TeacherHomeWrapper.MusicSheetTotal musicSheetTotal(@Param("teacherId") Long teacherId);

    List<TeacherHomeWrapper.MusicSheetTotal> musicSheetPage(@Param("param") TeacherHomeWrapper.MusicSheetQuery query);

    void updateExposureNum(@Param("musicSheetId") Long musicSheetId, @Param("exposureNum") Integer exposureNum);

    IPage<MusicSheetWrapper.MusicSheetCloud> cloudPage(@Param("page") IPage<Object> page, @Param("param") MusicSheetWrapper.MusicSheetCloudQuery query);
}