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

import com.yonge.cooleshow.biz.dal.entity.MusicSheetPurchaseRecord;
import com.yonge.cooleshow.biz.dal.dao.MusicSheetPurchaseRecordDao;
import com.yonge.cooleshow.biz.dal.enums.YesOrNoEnum;
import com.yonge.cooleshow.biz.dal.service.MusicSheetPurchaseRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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 final static Logger log = LoggerFactory.getLogger(MusicSheetPurchaseRecordServiceImpl.class);

    @Autowired
    private MusicSheetPurchaseRecordDao musicSheetPurchaseRecordDao;

    public MusicSheetPurchaseRecordDao getDao() {
        return musicSheetPurchaseRecordDao;
    }

    @Override
    public MusicSheetPurchaseRecord checkPurchase(Long userId, Long musicSheetId) {
        List<MusicSheetPurchaseRecord> list = this.lambdaQuery()
                                                  .eq(MusicSheetPurchaseRecord::getMusicSheetId, musicSheetId)
                                                  .eq(MusicSheetPurchaseRecord::getStudentId, userId)
                                                  .eq(MusicSheetPurchaseRecord::getOrderStatus,
                                                      YesOrNoEnum.YES.getCode())
                                                  .list();
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }
}