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.TAExamCourseCollegeInspectDio;
import com.qmth.teachcloud.report.business.entity.TAExamCourseTeacherDio;
import com.qmth.teachcloud.report.business.mapper.TAExamCourseCollegeInspectDioMapper;
import com.qmth.teachcloud.report.business.mapper.TAExamCourseTeacherDioMapper;
import com.qmth.teachcloud.report.business.service.TAExamCourseTeacherDioService;
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-06-16
 */
@Service
public class TAExamCourseTeacherDioServiceImpl extends ServiceImpl<TAExamCourseTeacherDioMapper, TAExamCourseTeacherDio> implements TAExamCourseTeacherDioService {
    @Resource
    private TAExamCourseTeacherDioMapper taExamCourseTeacherDioMapper;
    @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<TAExamCourseTeacherDio> taExamCourseTeacherDioList = taExamCourseTeacherDioMapper.findByTAExamCourseRecordDio(examId, courseCode);
        for (TAExamCourseTeacherDio taExamCourseTeacherDio : taExamCourseTeacherDioList) {
            taExamCourseTeacherDio.setSchoolId(tbExamService.getById(taExamCourseTeacherDio.getExamId()).getSchoolId());
            taExamCourseTeacherDio.setId(SystemConstant.getDbUuid());
        }
        this.saveBatch(taExamCourseTeacherDioList);
    }

}
