“djh”
2024-10-24 5fc609145a7072fb8c7bce501ece0daca0d46467
exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java
@@ -3,15 +3,16 @@
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.gkhy.exam.institutionalaccess.config.ExecutorConfig;
import com.gkhy.exam.institutionalaccess.entity.*;
import com.gkhy.exam.institutionalaccess.enums.*;
import com.gkhy.exam.institutionalaccess.model.req.*;
import com.gkhy.exam.institutionalaccess.model.resp.ThErrorDataRespDTO;
import com.gkhy.exam.institutionalaccess.model.vo.ThCourseChapterVO;
import com.gkhy.exam.institutionalaccess.service.*;
import com.gkhy.exam.institutionalaccess.utils.ValidatorUtils;
import com.ruoyi.common.constant.ResultConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.InstitutionUser;
@@ -60,38 +61,24 @@
    private ThStudyDetailService studyDetailService;
    @Autowired
    private ThExamRecordService examRecordService;
    @Autowired
    private ThBatchCourseChapterService batchCourseChapterService;
    @Autowired
    private ThSubjectTypeService subjectTypeService;
    @Autowired
    private ThCertService certService;
    @Override
    public boolean receiveQuestionBank(JSONObject jsonObject) {
    public boolean receiveQuestionBank(JSONObject jsonObject) throws Exception {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        ThQuestionBankReqDTO questionBankReqDTO =   decryptData(jsonObject, new TypeReference<ThQuestionBankReqDTO>() {},"题库数据");
        if(questionBankReqDTO==null){
            throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"题库数据不可为空");
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        String valdateMessage=ValidatorUtils.validateFast(questionBankReqDTO);
        if(!StringUtils.isEmpty(valdateMessage)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,valdateMessage);
        }
        //反序列化
        ThQuestionBankReqDTO questionBankReqDTO = null;
        try {
            questionBankReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThQuestionBankReqDTO>() {});
        }catch (Exception e){
            logger.error("组卷反序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
        //参数校验
        validateQuestion(questionBankReqDTO);
        //根据uuid查询数据
        ThQuestionBank qb = questionBankService.getQuestionInfoByUuid(questionBankReqDTO.getUuid());
        boolean i = true;
@@ -102,50 +89,43 @@
            qb.setUuid(questionBankReqDTO.getUuid());
            qb.setInstitutionId(institutionUser.getId());
            qb.setInstitutionName(institutionUser.getInstitutionalName());
            qb.setCreateTime(LocalDateTime.now());
            qb.setUpdateTime(LocalDateTime.now());
            qb.setCreateBy(institutionUser.getInstitutionalName());
            qb.setUpdateBy(institutionUser.getInstitutionalName());
            //qb.setDelFlag(DeleteStatusEnum.NO.getStatus());
            i = questionBankService.save(qb);
        }else {
            //修改
            BeanUtils.copyProperties(questionBankReqDTO, qb);
            qb.setUpdateBy(institutionUser.getInstitutionalName());
            i = questionBankService.updateById(qb);
        }
        return i;
    }
    @Transactional
    @Override
    public AjaxResult receiveCourse(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        List<ThCourseReqDTO> courseReqDTOList = new ArrayList<>();
        List<ThCourseReqDTO> courseReqDTOList =
                decryptData(jsonObject, new TypeReference<List<ThCourseReqDTO>>() {},"课程");
//        List<ThCourseReqDTO> courseReqDTOList = new ArrayList<>();
        //反序列化
        try {
            courseReqDTOList = JSONObject.parseObject(decrypt, new TypeReference<List<ThCourseReqDTO>>() {});
        }catch (Exception e){
            logger.error("课程反序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        try {
//            courseReqDTOList = JSONObject.parseObject(decrypt, new TypeReference<List<ThCourseReqDTO>>() {});
//
//        }catch (Exception e){
//            logger.error("课程反序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//
//        }
        if(CollectionUtils.isEmpty(courseReqDTOList)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送不可以为空");
        }
        //暂时不限制不能超过1000条
        //暂时限制不能超过1000条
        if (courseReqDTOList.size() > 1000){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送数据量过大");
        }
        List<String> reqAllCourseIds = new ArrayList<>();
        List<String> reqAllChapterIds = new ArrayList<>();
        List<ThErrorDataRespDTO> errorDataRespDTOS = new ArrayList<>();
@@ -163,10 +143,10 @@
                errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程名称不可为空"));
                continue;
            }
            if(StringUtils.isEmpty(courseReqDTO.getTrainOrgName())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"培训机构名称不可为空"));
            /*if(StringUtils.isEmpty(courseReqDTO.getTrainOrgName())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空"));
                continue;
            }
            }*/
            if(courseReqDTO.getLessonNum() == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程总课时不可为空"));
                continue;
@@ -472,28 +452,25 @@
    public AjaxResult receiveStudent(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        List<ThStudentReqDTO> studentReqDTOs =
                decryptData(jsonObject, new TypeReference<List<ThStudentReqDTO>>() {},"学员");
        //反序列化
        List<ThStudentReqDTO> studentReqDTOs = new ArrayList<>();
        try {
            studentReqDTOs = JSONObject.parseObject(decrypt, new TypeReference<List<ThStudentReqDTO>>() {});
        }catch (Exception e){
            logger.error("学员序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        List<ThStudentReqDTO> studentReqDTOs = new ArrayList<>();
//        try {
//            studentReqDTOs = JSONObject.parseObject(decrypt, new TypeReference<List<ThStudentReqDTO>>() {});
//        }catch (Exception e){
//            logger.error("学员序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//        }
        //参数校验
        if(CollectionUtils.isEmpty(studentReqDTOs)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学生信息不可为空");
        }
        //限制数据量不超过1000条
        if (studentReqDTOs.size() > 1000){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送数据量过大");
        }
        List<String> idcardList = new ArrayList<>();
@@ -546,7 +523,7 @@
                throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学生删除标识不符合规范");
            }
            if (StringUtils.isEmpty(studentReqDTO.getTrainOrgName())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"培训机构名称不可为空"));
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空"));
                continue;
            }
            if(StringUtils.isEmpty(studentReqDTO.getBatchUuid())){
@@ -662,29 +639,24 @@
    public AjaxResult receiveBatch(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        List<ThBatchReqDTO> batchReqDTOList = decryptData(jsonObject, new TypeReference<List<ThBatchReqDTO>>() {},"班级");
        //反序列化
        List<ThBatchReqDTO> batchReqDTOList = new ArrayList<>();
        try {
            batchReqDTOList = JSONObject.parseObject(decrypt, new TypeReference<List<ThBatchReqDTO>>() {});
        }catch (Exception e){
            logger.error("班级序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        List<ThBatchReqDTO> batchReqDTOList = new ArrayList<>();
//        try {
//            batchReqDTOList = JSONObject.parseObject(decrypt, new TypeReference<List<ThBatchReqDTO>>() {});
//
//        }catch (Exception e){
//            logger.error("班级序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//
//        }
        if(CollectionUtils.isEmpty(batchReqDTOList)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)集合不可为空");
        }
        //限制数据量不超过1000条
        if (batchReqDTOList.size() > 1000){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送数据量过大");
        }
        //过滤出本次请求所有班级课程章节
        List<String> reqAllBatchUuids = new ArrayList<>();
@@ -728,6 +700,8 @@
        List<ThCourse> thCourseList = courseService.getByUuidList(reqCourseUuids);
        //获取章节
        List<ThCourseChapter> thCourseChapterList = courseChapterService.getByUuids(reqChapterUuids);
        //获取科目类别
        List<ThSubjectType> subjectTypeList = subjectTypeService.getSubjectTypeList();
        //校验
        List<ThErrorDataRespDTO> errorDataRespDTOS = new ArrayList<>();
        List<ThBatchReqDTO> saveBatchReqDTOList = new ArrayList<>();
@@ -742,8 +716,25 @@
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"班次(班级)名称不可为空"));
                continue;
            }
            if(StringUtils.isEmpty(batchReqDTO.getSubjectCode())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"班次(班级)科目类别不可为空"));
                continue;
            }
            if(batchReqDTO.getExpectEndTime() == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"班次(班级)预期开始时间不可为空"));
                continue;
            }
            if(batchReqDTO.getExpectStartTime() == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"班次(班级)预期结束时间不可为空"));
                continue;
            }
            List<ThSubjectType> selectSubjectTypeList = subjectTypeList.stream().filter(st -> st.getCode().equals(batchReqDTO.getSubjectCode())).collect(Collectors.toList());
            if(selectSubjectTypeList.size() == 0){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"班次(班级)科目类别不合法"));
                continue;
            }
            if(StringUtils.isEmpty(batchReqDTO.getTrainOrgName())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"培训机构名称不可为空"));
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空"));
                continue;
            }
            if(batchReqDTO.getHaveExam() == null || HaveExam.get(batchReqDTO.getHaveExam()) == null){
@@ -752,6 +743,14 @@
            }
            if(batchReqDTO.getStatus() == null || OpenStatus.get(batchReqDTO.getStatus()) == null ){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"批次(班级)状态标识不符合规范"));
                continue;
            }
            if(batchReqDTO.getStatus().equals(OpenStatus.START.getStatus()) && batchReqDTO.getActualStartTime() == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"开班后,实际开班时间不可为空"));
                continue;
            }
            if(batchReqDTO.getStatus().equals(OpenStatus.END.getStatus()) && batchReqDTO.getActualEndTime() == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"结班,实际结束时间不可为空"));
                continue;
            }
            if(batchReqDTO.getBatchLessonNum() == null){
@@ -1248,28 +1247,23 @@
    public AjaxResult receiveStudyDetail(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        List<ThStudyDetailReqDTO> thStudyDetailReqDTOS = decryptData(jsonObject, new TypeReference<List<ThStudyDetailReqDTO>>() {},"学习记录");
        //反序列化
        List<ThStudyDetailReqDTO> thStudyDetailReqDTOS = new ArrayList<>();
        try {
           thStudyDetailReqDTOS = JSONObject.parseObject(decrypt, new TypeReference<List<ThStudyDetailReqDTO>>() {});
        }catch (Exception e){
            logger.error("学习记录序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        List<ThStudyDetailReqDTO> thStudyDetailReqDTOS = new ArrayList<>();
//        try {
//           thStudyDetailReqDTOS = JSONObject.parseObject(decrypt, new TypeReference<List<ThStudyDetailReqDTO>>() {});
//        }catch (Exception e){
//            logger.error("学习记录序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//        }
        //参数校验
        if(CollectionUtils.isEmpty(thStudyDetailReqDTOS)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学习记录清单不可为空");
        }
        //限制数据量不超过1000条
        if (thStudyDetailReqDTOS.size() > 1000){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送数据量过大");
        }
        //获取班级学生以及章节
        List<String> chapterUuids = new ArrayList<>();
@@ -1287,6 +1281,7 @@
        List<ThStudentBatch> thStudentBatches = studentBatchService.getByIdCards(idcards);
        List<ThBatchCourseChapter> batchCourseChapters = batchCourseChapterService.getByChapterUuids(chapterUuids);
        //校验
        List<ThStudentBatch> updateStudentBatchList = new ArrayList<>();
        List<ThErrorDataRespDTO> errorDataRespDTOS = new ArrayList<>();
        List<ThStudyDetailReqDTO> saveStudyDetailReqDTOS = new ArrayList<>();
        for (ThStudyDetailReqDTO studentDetailReqDTO : thStudyDetailReqDTOS) {
@@ -1325,11 +1320,15 @@
                continue;
            }
            if(StringUtils.isEmpty(studentDetailReqDTO.getTrainOrgName())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"培训机构名称不可为空"));
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空"));
                continue;
            }
            if(studentDetailReqDTO.getFinishStatus() == null || FinishStatus.get(studentDetailReqDTO.getFinishStatus()) == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"完成状态不规范"));
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"章节学习状态不规范"));
                continue;
            }
            if(studentDetailReqDTO.getCompleteStatus() == null || StudentFinishStatus.get(studentDetailReqDTO.getCompleteStatus()) == null){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"该学生在此批次(班级)学习状态不规范"));
                continue;
            }
            if(studentDetailReqDTO.getDuration() == null){
@@ -1425,6 +1424,13 @@
                continue;
            }
            saveStudyDetailReqDTOS.add(studentDetailReqDTO);
            //判断需要修改的批次学生
            if(studentDetailReqDTO.getCompleteStatus().equals(FinishStatus.YES.getStatus())){
                ThStudentBatch thStudentBatch = StudentBatchSelectList.get(0);
                thStudentBatch.setFinishStatus(studentDetailReqDTO.getCompleteStatus());
                updateStudentBatchList.add(thStudentBatch);
            }
        }
        //获取历史记录
@@ -1532,6 +1538,11 @@
        for (List<ThStudyTrack> thStudyTracks : splitSaveTrackList) {
            studyTrackService.insertBatch(thStudyTracks);
        }
        //修改学生完成状态
        List<List<ThStudentBatch>> splitUpdateThStudentBatchList = ListUtil.split(updateStudentBatchList, 500);
        for (List<ThStudentBatch> studentBatcheList : splitUpdateThStudentBatchList) {
            studentBatchService.updateBatch(studentBatcheList);
        }
        return AjaxResult.success(errorDataRespDTOS);
    }
@@ -1540,27 +1551,22 @@
    public AjaxResult receiveExamRecord(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        List<ThExamRecordReqDTO> examRecordReqDTOS = decryptData(jsonObject, new TypeReference<List<ThExamRecordReqDTO>>() {},"考试记录");
        //反序列化
        List<ThExamRecordReqDTO> examRecordReqDTOS = new ArrayList<>();
        try {
            examRecordReqDTOS = JSONObject.parseObject(decrypt, new TypeReference<List<ThExamRecordReqDTO>>() {});
        }catch (Exception e){
            logger.error("考试记录序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        List<ThExamRecordReqDTO> examRecordReqDTOS = new ArrayList<>();
//        try {
//            examRecordReqDTOS = JSONObject.parseObject(decrypt, new TypeReference<List<ThExamRecordReqDTO>>() {});
//        }catch (Exception e){
//            logger.error("考试记录序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//        }
        if (CollectionUtils.isEmpty(examRecordReqDTOS)) {
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"考试记录不可为空");
        }
        //限制数据量不超过1000条
        if (examRecordReqDTOS.size() > 1000){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送数据量过大");
        }
        List<String> idcards = new ArrayList<>();
        //List<String> batchUuids = new ArrayList<>();
@@ -1603,7 +1609,7 @@
                continue;
            }
            if(StringUtils.isEmpty(examRecordReqDTO.getTrainOrgName())){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"培训机构名称不可为空"));
                errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空"));
                continue;
            }
            if(StringUtils.isEmpty(examRecordReqDTO.getExamName())){
@@ -1662,28 +1668,19 @@
    public AjaxResult receiveCourseDelete(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        ThCourseDeleteReqDTO thCourseDeleteReqDTO = decryptData(jsonObject, new TypeReference<ThCourseDeleteReqDTO>() {},"课程删除");
        //反序列化
        ThCourseDeleteReqDTO thCourseDeleteReqDTO = null;
        try {
            thCourseDeleteReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThCourseDeleteReqDTO>() {});
        }catch (Exception e){
            logger.error("课程删除反序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        ThCourseDeleteReqDTO thCourseDeleteReqDTO = null;
//        try {
//            thCourseDeleteReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThCourseDeleteReqDTO>() {});
//
//        }catch (Exception e){
//            logger.error("课程删除反序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//
//        }
        if(thCourseDeleteReqDTO == null){
            throw new BusinessException(ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
@@ -1722,25 +1719,15 @@
    public AjaxResult receiveBatchOpen(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        ThBatchOpenReqDTO thBatchOpenReqDTO = decryptData(jsonObject, new TypeReference<ThBatchOpenReqDTO>() {},"班级开始");
        //反序列化
        ThBatchOpenReqDTO thBatchOpenReqDTO = null;
        try {
            thBatchOpenReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThBatchOpenReqDTO>() {});
        }catch (Exception e){
            logger.error("班级开始反序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
//        ThBatchOpenReqDTO thBatchOpenReqDTO = null;
//        try {
//            thBatchOpenReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThBatchOpenReqDTO>() {});
//        }catch (Exception e){
//            logger.error("班级开始反序列化失败!");
//            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
//        }
        if(thBatchOpenReqDTO == null){
            throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)不可为空");
        }
@@ -1757,6 +1744,7 @@
        thBatch.setStatus(OpenStatus.START.getStatus());
        thBatch.setUpdateTime(LocalDateTime.now());
        thBatch.setUpdateBy(institutionUser.getInstitutionalName());
        thBatch.setActualStartTime(LocalDateTime.now());
        batchService.updateById(thBatch);
        return AjaxResult.success();
    }
@@ -1764,26 +1752,7 @@
    @Override
    public AjaxResult receiveBatchEnd(JSONObject jsonObject) {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //反序列化
        ThBatchEndReqDTO thBatchEndReqDTO = null;
        try {
            thBatchEndReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThBatchEndReqDTO>() {});
        }catch (Exception e){
            logger.error("班级结束反序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
        ThBatchEndReqDTO thBatchEndReqDTO = decryptData(jsonObject, new TypeReference<ThBatchEndReqDTO>() {},"批次(班级)");
        if(thBatchEndReqDTO == null){
            throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)不可为空");
        }
@@ -1798,9 +1767,100 @@
        thBatch.setStatus(OpenStatus.END.getStatus());
        thBatch.setUpdateTime(LocalDateTime.now());
        thBatch.setUpdateBy(institutionUser.getInstitutionalName());
        thBatch.setActualEndTime(LocalDateTime.now());
        batchService.updateById(thBatch);
        studentBatchService.updateFinishStatusByBatchUuid(thBatchEndReqDTO.getBatchUuid());
        return AjaxResult.success();
    }
    @Override
    public AjaxResult receiveCerts(JSONObject jsonObject) throws Exception {
        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
        List<ThCertReqDTO> thCertReqDTOs = decryptData(jsonObject, new TypeReference<List<ThCertReqDTO>>() {},"学时证书");
        if(thCertReqDTOs.isEmpty() ||thCertReqDTOs.size()>50){
            throw new BusinessException(this.getClass(), ResultConstants.RECORD_OVER_MAX);
        }
        //错误
        List<ThErrorDataRespDTO> errorDataRespDTOS = new ArrayList<>();
        List<ThCertReqDTO> saveCertReqDTOList = new ArrayList<>();
        List<String> batchUuidList=thCertReqDTOs.stream().map(ThCertReqDTO::getBatchUuid).filter(batchUuid -> !StringUtils.isEmpty(batchUuid)).distinct().collect(Collectors.toList());
        //获取批次
        List<ThBatch> batchList = batchService.getByUuids(batchUuidList);
        for(ThCertReqDTO thCertReqDTO : thCertReqDTOs){
            String validateMessage=ValidatorUtils.validateFast(thCertReqDTO);
            if(!StringUtils.isEmpty(validateMessage)){
                errorDataRespDTOS.add(new ThErrorDataRespDTO(thCertReqDTO.getUuid(),validateMessage));
                continue;
            }
            List<ThBatch> collect = batchList.stream().filter(batchCourse -> batchCourse.getUuid().equals(thCertReqDTO.getBatchUuid())).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)) {
                errorDataRespDTOS.add(new ThErrorDataRespDTO(thCertReqDTO.getUuid(), "批次(班级)不存在,请先添加批次(班级)"));
                continue;
            }
            saveCertReqDTOList.add(thCertReqDTO);
        }
        List<ThCert> saveCertList = new ArrayList<>();
        List<ThCert> updateCertList = new ArrayList<>();
        for (ThCertReqDTO thCertReqDTO : saveCertReqDTOList) {
            ThCert cert=certService.getCertByUuid(thCertReqDTO.getUuid());
            if (cert!=null) {
                //修改
                BeanUtils.copyProperties(thCertReqDTO, cert);
                cert.setUpdateBy(institutionUser.getInstitutionalName());
                cert.setUpdateTime(LocalDateTime.now());
                cert.setInstitutionId(institutionUser.getId());
                cert.setInstitutionName(institutionUser.getInstitutionalName());
                updateCertList.add(cert);
            } else {
                //新增
                cert = new ThCert();
                BeanUtils.copyProperties(thCertReqDTO, cert);
                cert.setId(IdUtil.getSnowflake(0, 0).nextId());
                cert.setUpdateBy(institutionUser.getInstitutionalName());
                cert.setUpdateTime(LocalDateTime.now());
                cert.setCreateBy(institutionUser.getInstitutionalName());
                cert.setCreateTime(LocalDateTime.now());
                cert.setInstitutionId(institutionUser.getId());
                cert.setInstitutionName(institutionUser.getInstitutionalName());
                cert.setDelFlag(DeleteStatusEnum.NO.getStatus());
                saveCertList.add(cert);
            }
        }
        //课时证书表新增
        if(!saveCertList.isEmpty()){
            certService.insertBatch(saveCertList);
        }
        //课时证书表更新
        if(!updateCertList.isEmpty()) {
            certService.updateBatch(updateCertList);
        }
        return AjaxResult.success(errorDataRespDTOS);
    }
    /**
     * 解密数据
     * @param jsonObject
     * @param typeReference
     * @return
     * @param <T>
     */
    private <T> T decryptData(JSONObject jsonObject,TypeReference<T> typeReference,String type){
        String data = jsonObject.getString("data");
        if(StringUtils.isEmpty(data)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        try {
            return JSONObject.parseObject(decrypt,typeReference);
        }catch (Exception e){
            logger.error("{}反序列化失败!",type);
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
    }
@@ -1836,7 +1896,7 @@
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"课程章节不存在");
        }
        if(StringUtils.isEmpty(studentDetailReqDTO.getTrainOrgName())){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"培训机构名称不可为空");
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"所属培训机构统一社会信用代码不可为空");
        }
        if(studentDetailReqDTO.getFinishStatus() == null || FinishStatus.get(studentDetailReqDTO.getFinishStatus()) == null){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"完成状态不规范");
@@ -1936,7 +1996,7 @@
                throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"实名认证照不可为空");
            }
            if (StringUtils.isEmpty(studentReqDTO.getTrainOrgName())){
                throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"培训机构名称不可为空");
                throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"所属培训机构统一社会信用代码不可为空");
            }
            /*if(CollectionUtils.isEmpty(studentReqDTO.getBatchUuids())){
                throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"关联课程uuidd不可为空");
@@ -1970,7 +2030,7 @@
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"课程名称不可为空");
        }
        if(StringUtils.isEmpty(courseReqDTO.getTrainOrgName())){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"培训机构名称不可为空");
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"所属培训机构统一社会信用代码不可为空");
        }
        if(courseReqDTO.getLessonNum() == null){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"总课时不可为空");
@@ -2029,43 +2089,7 @@
    }
    /**
     * 校验题库组卷数据
     * @param questionBankReqDTO
     */
     private void validateQuestion(ThQuestionBankReqDTO questionBankReqDTO){
         if(questionBankReqDTO == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR);
         }
         if(StringUtils.isEmpty(questionBankReqDTO.getUuid()) || !UUID.checkIsUuid(questionBankReqDTO.getUuid())){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"题库组卷uuid不符合规范");
         }
         if(StringUtils.isEmpty(questionBankReqDTO.getUrl())){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"题库组卷预览路径不可为空");
         }
         if(questionBankReqDTO.getLastMonthCount() == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"上月题库总题目数不可为空");
         }
         if(questionBankReqDTO.getAddCount() == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"新增题目数不可为空");
         }
         if(questionBankReqDTO.getReduceCount() == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"减少题目数不可为空");
         }
         if(questionBankReqDTO.getBrushRate() == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"刷题应用率不可为空");
         }
         if(questionBankReqDTO.getAssemblyRate() == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"组卷应用率不可为空");
         }
         if(questionBankReqDTO.getMonth() == null){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"年月不可为空");
         }
         if(questionBankReqDTO.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(questionBankReqDTO.getDelFlag()) == null ){
             throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"删除标识不符合规范");
         }
    }
    private String generateSerialNum() {
        Long count = studyDetailService.getCount();
        String strCount = count.toString();