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.TBCommonLevelConfig;
import com.qmth.teachcloud.report.business.mapper.TBCommonLevelConfigMapper;
import com.qmth.teachcloud.report.business.service.TBCommonLevelConfigService;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 等级配置表（试卷难易度、成绩在学院排名百分比） 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2021-06-01
 */
@Service
public class TBCommonLevelConfigServiceImpl extends ServiceImpl<TBCommonLevelConfigMapper, TBCommonLevelConfig> implements TBCommonLevelConfigService {
    @Override
    public void importLevelConfig(Long examId, String courseCode, String courseName) {
        List<TBCommonLevelConfig> list = new ArrayList<>();
        TBCommonLevelConfig config0 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"难度等级","A","[0,0.3)","难",new BigDecimal("0"),new BigDecimal("0.3"));
        TBCommonLevelConfig config1 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"难度等级","B","[0.3,0.7]","中等难度",new BigDecimal("0.3"),new BigDecimal("0.7"));
        TBCommonLevelConfig config2 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"难度等级","C","(0.7,1]","容易",new BigDecimal("0.7"),new BigDecimal("1"));
        TBCommonLevelConfig config3 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"百分等级","A","[80,100)","A",new BigDecimal("80"),new BigDecimal("100"));
        TBCommonLevelConfig config4 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"百分等级","B","[60,80)","B",new BigDecimal("60"),new BigDecimal("80"));
        TBCommonLevelConfig config5 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"百分等级","C","[40,60)","C",new BigDecimal("40"),new BigDecimal("60"));
        TBCommonLevelConfig config6 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"百分等级","D","[20,40)","D",new BigDecimal("20"),new BigDecimal("40"));
        TBCommonLevelConfig config7 = new TBCommonLevelConfig(SystemConstant.getDbUuid(),examId,courseCode,courseName,"百分等级","E","[0,20)","E",new BigDecimal("0"),new BigDecimal("20"));
        list.add(config0);
        list.add(config1);
        list.add(config2);
        list.add(config3);
        list.add(config4);
        list.add(config5);
        list.add(config6);
        list.add(config7);
        this.remove(new QueryWrapper<TBCommonLevelConfig>().lambda()
                .eq(TBCommonLevelConfig::getExamId,examId)
                .eq(TBCommonLevelConfig::getCourseCode,courseCode)
                .eq(TBCommonLevelConfig::getCourseName,courseName));
        this.saveBatch(list);
    }
}
