package com.qmth.teachcloud.report.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.report.business.entity.TBCommonRankLevelConfig;
import com.qmth.teachcloud.report.business.mapper.TBCommonRankLevelConfigMapper;
import com.qmth.teachcloud.report.business.service.TBCommonRankLevelConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 学生成绩在学院排名的配置表（赋分成绩在学院排名档次） 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2021-06-01
 */
@Service
public class TBCommonRankLevelConfigServiceImpl extends ServiceImpl<TBCommonRankLevelConfigMapper, TBCommonRankLevelConfig> implements TBCommonRankLevelConfigService {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void importRankLevelConfig(Long examId, String courseCode, String courseName) {
        List<TBCommonRankLevelConfig> list = new ArrayList<>();
        list.add(new TBCommonRankLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"A",new BigDecimal(80),new BigDecimal(100),"(0,0.20]","赋分在学院的排名在该范围"));
        list.add(new TBCommonRankLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"B",new BigDecimal(60),new BigDecimal(80),"(0.20,0.40]","赋分在学院的排名在该范围"));
        list.add(new TBCommonRankLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"C",new BigDecimal(40),new BigDecimal(60),"(0.40,0.60]","赋分在学院的排名在该范围"));
        list.add(new TBCommonRankLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"D",new BigDecimal(20),new BigDecimal(40),"(0.60,0.80]","赋分在学院的排名在该范围"));
        list.add(new TBCommonRankLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"E",new BigDecimal(0),new BigDecimal(20),"(0.80,1]","赋分在学院的排名在该范围"));
        this.remove(new QueryWrapper<TBCommonRankLevelConfig>().lambda()
                .eq(TBCommonRankLevelConfig::getExamId,examId)
                .eq(TBCommonRankLevelConfig::getCourseCode,courseCode)
                .eq(TBCommonRankLevelConfig::getCourseName,courseName));
        this.saveBatch(list);
    }
}
