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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
import com.qmth.teachcloud.report.business.entity.TAExamCourseTeacherCollegeDio;
import com.qmth.teachcloud.report.business.entity.TAExamCourseTeacherDio;
import com.qmth.teachcloud.report.business.mapper.TAExamCourseTeacherCollegeDioMapper;
import com.qmth.teachcloud.report.business.mapper.TAExamCourseTeacherDioMapper;
import com.qmth.teachcloud.report.business.service.TAExamCourseTeacherCollegeDioService;
import com.qmth.teachcloud.report.business.service.TBExamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 各个教师在考察学院下的各考察点得分情况表 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2021-07-20
 */
@Service
public class TAExamCourseTeacherCollegeDioServiceImpl extends ServiceImpl<TAExamCourseTeacherCollegeDioMapper, TAExamCourseTeacherCollegeDio> implements TAExamCourseTeacherCollegeDioService {
    @Resource
    private TAExamCourseTeacherCollegeDioMapper taExamCourseTeacherCollegeDioMapper;
    @Resource
    private TBExamService tbExamService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertByTAExamCourseRecordDio(Long examId, String courseCode) {
        if (examId == 0 || courseCode == null || courseCode.length() == 0) {
            throw ExceptionResultEnum.ERROR.exception("参数异常");
        }
        List<TAExamCourseTeacherCollegeDio> taExamCourseTeacherCollegeDioList = taExamCourseTeacherCollegeDioMapper.findByTAExamCourseRecordDio(examId, courseCode);
        for (TAExamCourseTeacherCollegeDio taExamCourseTeacherCollegeDio : taExamCourseTeacherCollegeDioList) {
            taExamCourseTeacherCollegeDio.setSchoolId(tbExamService.getById(taExamCourseTeacherCollegeDio.getExamId()).getSchoolId());
            taExamCourseTeacherCollegeDio.setId(SystemConstant.getDbUuid());
        }
        this.saveBatch(taExamCourseTeacherCollegeDioList);
    }
}
