package com.yonge.cooleshow.biz.dal.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dao.MusicSheetPurchaseRecordDao;
import com.yonge.cooleshow.biz.dal.entity.CourseRelationMusicAlbum;
import com.yonge.cooleshow.biz.dal.entity.MusicSheetPurchaseRecord;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.enums.album.PurchaseRecordTypeEnum;
import com.yonge.cooleshow.biz.dal.service.MusicSheetPurchaseRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * MusicSheetPurchaseRecordService服务实现类
 * @author yzp
 * @date 2022-03-26 00:01:38
 * @version v1.0
 **/
@Service
public class MusicSheetPurchaseRecordServiceImpl extends ServiceImpl<MusicSheetPurchaseRecordDao,MusicSheetPurchaseRecord> implements MusicSheetPurchaseRecordService {

    private static final Logger log = LoggerFactory.getLogger(MusicSheetPurchaseRecordServiceImpl.class);

    @Autowired
    private MusicSheetPurchaseRecordDao musicSheetPurchaseRecordDao;

    public MusicSheetPurchaseRecordDao getDao() {
        return musicSheetPurchaseRecordDao;
    }

    @Override
    public MusicSheetPurchaseRecord checkPurchase(Long userId, Long musicSheetId, ClientEnum clientType, PurchaseRecordTypeEnum purchaseType) {
        List<MusicSheetPurchaseRecord> list = this.lambdaQuery()
                .eq(MusicSheetPurchaseRecord::getMusicSheetId, musicSheetId)
                .eq(MusicSheetPurchaseRecord::getStudentId, userId)
                .eq(MusicSheetPurchaseRecord::getClientType, clientType)
                .eq(MusicSheetPurchaseRecord::getPurchaseType, purchaseType)
                .list();
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public void updateCourseMusicAlbum(List<CourseRelationMusicAlbum> updateCourseRelationMusicAlbums) {
        musicSheetPurchaseRecordDao.updateCourseMusicAlbum(updateCourseRelationMusicAlbums);
    }
}