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.common.util.ServletUtil;
import com.qmth.teachcloud.report.business.entity.TAExamCourseCollegeInspectDio;
import com.qmth.teachcloud.report.business.mapper.TAExamCourseCollegeInspectDioMapper;
import com.qmth.teachcloud.report.business.service.TAExamCourseCollegeInspectDioService;
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-01
 */
@Service
public class TAExamCourseCollegeInspectDioServiceImpl extends ServiceImpl<TAExamCourseCollegeInspectDioMapper, TAExamCourseCollegeInspectDio> implements TAExamCourseCollegeInspectDioService {
    @Resource
    private TAExamCourseCollegeInspectDioMapper taExamCourseCollegeInspectDioMapper;
    @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<TAExamCourseCollegeInspectDio> taExamCourseCollegeInspectDioList = taExamCourseCollegeInspectDioMapper.findByTAExamCourseRecordDio(examId, courseCode);
        for (TAExamCourseCollegeInspectDio taExamCourseCollegeInspectDio : taExamCourseCollegeInspectDioList) {
            taExamCourseCollegeInspectDio.setSchoolId(tbExamService.getById(taExamCourseCollegeInspectDio.getExamId()).getSchoolId());
            taExamCourseCollegeInspectDio.setId(SystemConstant.getDbUuid());
        }
        this.saveBatch(taExamCourseCollegeInspectDioList);
    }
}
