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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dto.search.StudentMusicSheetSearch;
import org.springframework.stereotype.Service;
import com.yonge.cooleshow.biz.dal.entity.MusicSheetPracticeRecord;
import com.yonge.cooleshow.biz.dal.vo.MusicSheetPracticeRecordVo;
import com.yonge.cooleshow.biz.dal.dto.search.MusicSheetPracticeRecordSearch;
import com.yonge.cooleshow.biz.dal.dao.MusicSheetPracticeRecordDao;
import com.yonge.cooleshow.biz.dal.service.MusicSheetPracticeRecordService;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


@Service
public class MusicSheetPracticeRecordServiceImpl extends ServiceImpl<MusicSheetPracticeRecordDao, MusicSheetPracticeRecord> implements MusicSheetPracticeRecordService {

	@Override
    public MusicSheetPracticeRecordVo detail(Long id) {
        MusicSheetPracticeRecordVo detail = baseMapper.detail(id);
        return detail;
    }
    
     @Override
    public IPage<MusicSheetPracticeRecordVo> selectPage(IPage<MusicSheetPracticeRecordVo> page, MusicSheetPracticeRecordSearch query){
        return page.setRecords(baseMapper.selectPage(page, query));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRecord(Long musicSheetId, Long userId) {
        MusicSheetPracticeRecord musicSheetPracticeRecord = new MusicSheetPracticeRecord();
        musicSheetPracticeRecord.setMusicSheetId(musicSheetId);
        musicSheetPracticeRecord.setUserId(userId);
        musicSheetPracticeRecord.setCreateTime(new Date());
        this.save(musicSheetPracticeRecord);
    }

    @Override
    public IPage<Long> selectPracticeMusic(StudentMusicSheetSearch query, long page, long size) {
        IPage<Long> iPage = new Page<>(page,size);
        return iPage.setRecords(baseMapper.selectPracticeMusicIdPage(iPage,query));
    }

}