package com.gkhy.exam.institutionalaccess.service.serviceImpl; 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.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; import com.ruoyi.common.enums.coalmineEnums.DeleteStatusEnum; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.signature.AESUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.common.utils.uuid.UUID; import com.ruoyi.framework.security.context.ThreeInContextHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Service("TripartiteInterfaceService") public class TripartiteInterfaceServiceImpl implements TripartiteInterfaceService { private Logger logger = LoggerFactory.getLogger(TripartiteInterfaceServiceImpl.class); @Autowired private ThQuestionBankService questionBankService; @Autowired private ThCourseService courseService; @Autowired private ThCourseChapterService courseChapterService; @Autowired private ThStudentService studentService; @Autowired private ThBatchService batchService; @Autowired private ThBatchCourseService batchCourseService; @Autowired private ThStudentBatchService studentBatchService; @Autowired private ThStudyAuthService studyAuthService; @Autowired private ThStudyTrackService studyTrackService; @Autowired private ThStudyDetailService studyDetailService; @Autowired private ThExamRecordService examRecordService; @Autowired private ThBatchCourseChapterService batchCourseChapterService; @Autowired private ThSubjectTypeService subjectTypeService; @Autowired private ThCertService certService; @Override public AjaxResult receiveQuestionBank(JSONObject jsonObject) throws Exception { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); List questionBankReqDTO = decryptData(jsonObject, new TypeReference>() {},"题库数据"); if(CollectionUtils.isEmpty(questionBankReqDTO)){ throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"题库数据不可为空"); } List errorDataRespDTOS = new ArrayList<>(); List thQuestionBankReqDTOS = new ArrayList<>(); for (ThQuestionBankReqDTO thQuestionBankReqDTO : questionBankReqDTO) { String valdateMessage=ValidatorUtils.validateFast(thQuestionBankReqDTO); if(!StringUtils.isEmpty(valdateMessage)){ // throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,valdateMessage); errorDataRespDTOS.add(new ThErrorDataRespDTO(thQuestionBankReqDTO.getUuid(),valdateMessage)); continue; } thQuestionBankReqDTOS.add(thQuestionBankReqDTO); } List savethQuestionBanks = new ArrayList<>(); List updatethQuestionBanks = new ArrayList<>(); for (ThQuestionBankReqDTO thQuestionBankReqDTO : thQuestionBankReqDTOS) { //根据uuid查询数据 ThQuestionBank qb = questionBankService.getQuestionInfoByUuid(thQuestionBankReqDTO.getUuid()); if(qb == null){ //新增 qb = new ThQuestionBank(); BeanUtils.copyProperties(thQuestionBankReqDTO, qb); qb.setUuid(thQuestionBankReqDTO.getUuid()); qb.setInstitutionId(institutionUser.getId()); qb.setInstitutionName(institutionUser.getInstitutionalName()); qb.setCreateBy(institutionUser.getInstitutionalName()); qb.setUpdateBy(institutionUser.getInstitutionalName()); savethQuestionBanks.add(qb); }else { //修改 BeanUtils.copyProperties(thQuestionBankReqDTO, qb); qb.setUpdateBy(institutionUser.getInstitutionalName()); updatethQuestionBanks.add(qb); } } questionBankService.saveBatch(savethQuestionBanks); questionBankService.updateBatchById(updatethQuestionBanks); return AjaxResult.success(errorDataRespDTOS); } @Transactional @Override public AjaxResult receiveCourse(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); //解密 List courseReqDTOList = decryptData(jsonObject, new TypeReference>() {},"课程"); // List courseReqDTOList = new ArrayList<>(); //反序列化 // try { // courseReqDTOList = JSONObject.parseObject(decrypt, new TypeReference>() {}); // // }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条 if (courseReqDTOList.size() > 1000){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR,"数据推送数据量过大"); } List reqAllCourseIds = new ArrayList<>(); List reqAllChapterIds = new ArrayList<>(); List errorDataRespDTOS = new ArrayList<>(); List saveCourseReqDTOList = new ArrayList<>(); for (ThCourseReqDTO courseReqDTO : courseReqDTOList) { if(StringUtils.isEmpty(courseReqDTO.getUuid()) || !UUID.checkIsUuid(courseReqDTO.getUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程uuid不符合规范")); continue; } if(StringUtils.isEmpty(courseReqDTO.getCourseCode())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程标识不可为空")); continue; } if(StringUtils.isEmpty(courseReqDTO.getCourseName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程名称不可为空")); continue; } /*if(StringUtils.isEmpty(courseReqDTO.getTrainOrgName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空")); continue; }*/ if(courseReqDTO.getLessonNum() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程总课时不可为空")); continue; } if(CollectionUtils.isEmpty(courseReqDTO.getChapters())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"课程大纲(大章)不可为空")); continue; } //章 boolean errorflag = false; List chapterIds = new ArrayList<>(); for (ThCourseChapterReqDTO chapter : courseReqDTO.getChapters()) { if(StringUtils.isEmpty(chapter.getUuid()) || !UUID.checkIsUuid(chapter.getUuid())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章uuid("+chapter.getUuid()+")不符合规范")); break; } if(StringUtils.isEmpty(chapter.getChapterCode())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")标识不可为空")); break; } if(StringUtils.isEmpty(chapter.getChapterName())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")名称不可为空")); break; } if(chapter.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(chapter.getDelFlag()) == null ){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")删除标识不符合规范")); break; } if (chapter.getLessonNum() == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")课时(保留1位小数)不可为空")); break; } if (chapter.getSerialno() == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")序号不可为空")); break; } if(chapter.getHaveResource() == null || CourseHaveResourse.get(chapter.getHaveResource()) == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")是否有资源不符合规范")); break; } if(CollectionUtils.isEmpty(chapter.getChildren())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(大章)("+chapter.getUuid()+")包含的章节(小节)列表不可为空")); break; } List sectionIds = new ArrayList<>(); for (ThCourseChapterReqDTO child : chapter.getChildren()) { if(StringUtils.isEmpty(child.getUuid()) || !UUID.checkIsUuid(child.getUuid())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)uuid("+child.getUuid()+")不符合规范")); break; } if(StringUtils.isEmpty(child.getChapterCode())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+child.getUuid()+")标识不可为空")); break; } if(StringUtils.isEmpty(child.getChapterName())){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+child.getUuid()+")名称不可为空")); break; } if(child.getDuration() == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+child.getUuid()+")视频时长(秒)不可为空")); break; } if (chapter.getSerialno() == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+child.getUuid()+")序号不可为空")); break; } if (child.getLessonNum() == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+child.getUuid()+")课时(保留1位小数)不可为空")); break; } if(child.getResourceType() == null || CourseResourceType.get(child.getResourceType()) == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)"+child.getUuid()+"资源类型不规范")); break; } if(child.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(child.getDelFlag()) == null ){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+child.getUuid()+")删除标识不符合规范")); break; } if(child.getHaveResource() == null || CourseHaveResourse.get(child.getHaveResource()) == null){ errorflag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(courseReqDTO.getUuid(),"章节(小节)("+chapter.getUuid()+")是否有资源不符合规范")); break; } sectionIds.add(child.getUuid()); } if(errorflag){ break; } //章 chapterIds.add(chapter.getUuid()); //节 chapterIds.addAll(sectionIds); } if(errorflag){ continue; } reqAllCourseIds.add(courseReqDTO.getUuid()); reqAllChapterIds.addAll(chapterIds); saveCourseReqDTOList.add(courseReqDTO); } //获取课程数据 List oldCourseList = courseService.getByUuidList(reqAllCourseIds); //获取章节数据 List oldCourseChapterList = courseChapterService.getByUuids(reqAllChapterIds); //变量 List saveCourseList = new ArrayList<>(); List updateCourseList = new ArrayList<>(); List updateCourseChapterList = new ArrayList<>(); List saveCourseChapterList = new ArrayList<>(); //获取数据 for (ThCourseReqDTO courseReqDTO : saveCourseReqDTOList){ List oCourseSelectList = oldCourseList.stream().filter(oc -> oc.getUuid().equals(courseReqDTO.getUuid())).collect(Collectors.toList()); if(oCourseSelectList.size() == 0){ //新增 //课程 ThCourse course = new ThCourse(); BeanUtils.copyProperties(courseReqDTO, course); course.setId(IdUtil.getSnowflake(0,0).nextId()); course.setCreateTime(LocalDateTime.now()); course.setUpdateTime(LocalDateTime.now()); course.setCreateBy(institutionUser.getInstitutionalName()); course.setUpdateBy(institutionUser.getInstitutionalName()); course.setInstitutionId(institutionUser.getId()); course.setDelFlag(DeleteStatusEnum.NO.getStatus()); course.setInstitutionName(institutionUser.getInstitutionalName()); saveCourseList.add(course); //章节(章) for (ThCourseChapterReqDTO chapterReqDTO : courseReqDTO.getChapters()) { ThCourseChapter chapter = new ThCourseChapter(); BeanUtils.copyProperties(chapterReqDTO, chapter); chapter.setCourseUuid(course.getUuid()); chapter.setId(IdUtil.getSnowflake(0,0).nextId()); chapter.setParentUuid("0"); chapter.setInstitutionId(institutionUser.getId()); chapter.setCreateTime(LocalDateTime.now()); chapter.setUpdateTime(LocalDateTime.now()); //chapter.setDelFlag(DeleteStatusEnum.NO.getStatus()); chapter.setCreateBy(institutionUser.getInstitutionalName()); chapter.setUpdateBy(institutionUser.getInstitutionalName()); saveCourseChapterList.add(chapter); //章节(节) for (ThCourseChapterReqDTO child : chapterReqDTO.getChildren()) { ThCourseChapter section = new ThCourseChapter(); BeanUtils.copyProperties(child, section); section.setCourseUuid(course.getUuid()); section.setId(IdUtil.getSnowflake(0,0).nextId()); section.setParentUuid(chapter.getUuid()); section.setInstitutionId(institutionUser.getId()); section.setCreateTime(LocalDateTime.now()); section.setUpdateTime(LocalDateTime.now()); //section.setDelFlag(DeleteStatusEnum.NO.getStatus()); section.setCreateBy(institutionUser.getInstitutionalName()); section.setUpdateBy(institutionUser.getInstitutionalName()); saveCourseChapterList.add(section); } } }else { ThCourse course = oCourseSelectList.get(0); //课程 course.setCourseCode(courseReqDTO.getCourseCode()); course.setCourseName(courseReqDTO.getCourseName()); course.setLessonNum(courseReqDTO.getLessonNum()); //course.setDelFlag(DeleteStatusEnum.NO.getStatus()); course.setUpdateBy(institutionUser.getInstitutionalName()); course.setUpdateTime(LocalDateTime.now()); updateCourseList.add(course); //过滤该课程所有章节 List oldCourseChapterSelectList = oldCourseChapterList.stream().filter(occ -> occ.getCourseUuid().equals(course.getUuid())).collect(Collectors.toList()); //修改 //章 /* List saveChapterList = new ArrayList<>(); List updateChapterList = new ArrayList<>();*/ //章 for (ThCourseChapterReqDTO chapterReqDTO : courseReqDTO.getChapters()) { List chapterSelectList = oldCourseChapterSelectList.stream().filter(cc -> cc.getUuid().equals(chapterReqDTO.getUuid())).collect(Collectors.toList()); if(chapterSelectList.size() > 0){ //存在,修改 ThCourseChapter chapter = chapterSelectList.get(0); BeanUtils.copyProperties(chapterReqDTO, chapter); chapter.setUpdateBy(institutionUser.getInstitutionalName()); chapter.setUpdateTime(LocalDateTime.now()); updateCourseChapterList.add(chapter); if(chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.NO.getStatus())){ //非删除(章) for (ThCourseChapterReqDTO child : chapterReqDTO.getChildren()) { List sectionSelectList = oldCourseChapterSelectList.stream().filter(cc -> cc.getUuid().equals(child.getUuid()) && cc.getParentUuid().equals(chapter.getUuid())).collect(Collectors.toList()); if(sectionSelectList.size() > 0){ //修改 ThCourseChapter section = sectionSelectList.get(0); BeanUtils.copyProperties(child, section); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); updateCourseChapterList.add(section); }else { //新增 ThCourseChapter section= new ThCourseChapter(); BeanUtils.copyProperties(child, section); section.setId(IdUtil.getSnowflake(0,0).nextId()); section.setCourseUuid(course.getUuid()); section.setParentUuid(chapter.getUuid()); section.setInstitutionId(institutionUser.getId()); //section.setDelFlag(DeleteStatusEnum.NO.getStatus()); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); section.setCreateBy(institutionUser.getInstitutionalName()); section.setCreateTime(LocalDateTime.now()); saveCourseChapterList.add(section); } } }else{ //删除(章) List sectionSelectList = oldCourseChapterSelectList .stream() .filter(cc -> cc.getParentUuid().equals(chapter.getUuid())) .collect(Collectors.toList()); sectionSelectList.forEach(section ->{ section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); section.setDelFlag(DeleteStatusEnum.YES.getStatus()); }); updateCourseChapterList.addAll(sectionSelectList); } }else { //不存在,新增 ThCourseChapter chapter = new ThCourseChapter(); BeanUtils.copyProperties(chapterReqDTO, chapter); chapter.setId(IdUtil.getSnowflake(0,0).nextId()); chapter.setParentUuid("0"); chapter.setCourseUuid(course.getUuid()); chapter.setInstitutionId(institutionUser.getId()); //chapter.setDelFlag(chapter.getDelFlag()); chapter.setCreateTime(LocalDateTime.now()); chapter.setUpdateTime(LocalDateTime.now()); chapter.setCreateBy(institutionUser.getInstitutionalName()); chapter.setUpdateBy(institutionUser.getInstitutionalName()); saveCourseChapterList.add(chapter); //章节(节) for (ThCourseChapterReqDTO child : chapterReqDTO.getChildren()) { ThCourseChapter section = new ThCourseChapter(); BeanUtils.copyProperties(child, section); section.setId(IdUtil.getSnowflake(0,0).nextId()); section.setParentUuid(chapter.getUuid()); section.setCourseUuid(course.getUuid()); //section.setDelFlag(child.getDelFlag()); section.setInstitutionId(institutionUser.getId()); section.setCreateTime(LocalDateTime.now()); section.setUpdateTime(LocalDateTime.now()); section.setCreateBy(institutionUser.getInstitutionalName()); section.setUpdateBy(institutionUser.getInstitutionalName()); saveCourseChapterList.add(section); } } } } } //数据插入 //课程插入 List> splitSaveCourseList = ListUtil.split(saveCourseList, 200); for(List courseList : splitSaveCourseList){ courseService.insertBatch(courseList); } //修改课程 List> splitUpdateCourseList = ListUtil.split(updateCourseList, 200); for(List courseList : splitUpdateCourseList){ courseService.updateBatch(courseList); } //插入章节 List> splitSaveChapterList = ListUtil.split(saveCourseChapterList, 200); for(List chapterList : splitSaveChapterList){ courseChapterService.insertBatch(chapterList); } //修改章节 List> splitUpdateChapterList = ListUtil.split(updateCourseChapterList, 200); for(List chapterList : splitUpdateChapterList){ courseChapterService.updateBatch(chapterList); } return AjaxResult.success(errorDataRespDTOS); } @Transactional @Override public AjaxResult receiveStudent(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); //解密 List studentReqDTOs = decryptData(jsonObject, new TypeReference>() {},"学员"); //反序列化 // List studentReqDTOs = new ArrayList<>(); // try { // studentReqDTOs = JSONObject.parseObject(decrypt, new TypeReference>() {}); // }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 idcardList = new ArrayList<>(); List batchUuidList = new ArrayList<>(); for(ThStudentReqDTO studentReqDTO : studentReqDTOs){ //去重 if(!idcardList.contains(studentReqDTO.getIdcard()) && StringUtils.isNotEmpty(studentReqDTO.getIdcard())){ idcardList.add(studentReqDTO.getIdcard()); } if(!batchUuidList.contains(studentReqDTO.getBatchUuid()) && StringUtils.isNotEmpty(studentReqDTO.getBatchUuid())){ batchUuidList.add(studentReqDTO.getBatchUuid()); } } //获取批次 List batchList = batchService.getByUuids(batchUuidList); //获取批次学生 List studentBatchList = studentBatchService.getByIdCards(idcardList); //获取学生表学生 List students = studentService.getByIdcards(idcardList); //错误 List errorDataRespDTOS = new ArrayList<>(); List saveStudentReqDTOList = new ArrayList<>(); for (ThStudentReqDTO studentReqDTO : studentReqDTOs) { if(StringUtils.isEmpty(studentReqDTO.getUuid()) || !UUID.checkIsUuid(studentReqDTO.getUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"学生uuid不符合规范")); continue; } if(StringUtils.isEmpty(studentReqDTO.getIdcard())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"身份证不可为空")); continue; } if(StringUtils.isEmpty(studentReqDTO.getName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"姓名不可为空")); continue; } if(StringUtils.isEmpty(studentReqDTO.getPhone())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"手机号不可为空")); continue; } if(studentReqDTO.getSex() == null || StudentSex.get(studentReqDTO.getSex()) == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"性别不可为空")); continue; } if(StringUtils.isEmpty(studentReqDTO.getAuthPhoto())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"实名认证照不可为空")); continue; } if(studentReqDTO.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(studentReqDTO.getDelFlag()) == null ){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学生删除标识不符合规范"); } if (StringUtils.isEmpty(studentReqDTO.getTrainOrgName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空")); continue; } if(StringUtils.isEmpty(studentReqDTO.getBatchUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(),"关联批次(班级)不可为空")); continue; } List collect = batchList.stream().filter(batchCourse -> batchCourse.getUuid().equals(studentReqDTO.getBatchUuid())).collect(Collectors.toList()); if (CollectionUtils.isEmpty(collect)) { errorDataRespDTOS.add(new ThErrorDataRespDTO(studentReqDTO.getUuid(), "批次(班级)不存在,请先添加批次(班级)")); continue; } saveStudentReqDTOList.add(studentReqDTO); } List saveSudentList = new ArrayList<>(); List updateStudentList = new ArrayList<>(); List saveThStudentBatchList = new ArrayList<>(); List updateThStudentBatchList = new ArrayList<>(); for (ThStudentReqDTO studentReqDTO : saveStudentReqDTOList) { //学生表中过滤 List collect = students.stream().filter(s -> s.getIdcard().equals(studentReqDTO.getIdcard()) && s.getInstitutionId().equals(institutionUser.getId()) ).collect(Collectors.toList()); if(collect.size() > 0){ ThStudent student = collect.get(0); //修改 BeanUtils.copyProperties(studentReqDTO, student); student.setUpdateBy(institutionUser.getInstitutionalName()); student.setUpdateTime(LocalDateTime.now()); student.setInstitutionId(institutionUser.getId()); student.setInstitutionName(institutionUser.getInstitutionalName()); updateStudentList.add(student); }else { //新增 ThStudent student = new ThStudent(); BeanUtils.copyProperties(studentReqDTO, student); student.setId(IdUtil.getSnowflake(0,0).nextId()); student.setUpdateBy(institutionUser.getInstitutionalName()); student.setUpdateTime(LocalDateTime.now()); student.setCreateBy(institutionUser.getInstitutionalName()); student.setCreateTime(LocalDateTime.now()); student.setInstitutionId(institutionUser.getId()); student.setInstitutionName(institutionUser.getInstitutionalName()); student.setDelFlag(DeleteStatusEnum.NO.getStatus()); saveSudentList.add(student); } //获取班级学生 List selectBatchStudentList = studentBatchList.stream() .filter(sb -> sb.getBatchUuid().equals(studentReqDTO.getBatchUuid()) && sb.getIdcard().equals(studentReqDTO.getIdcard())) .collect(Collectors.toList()); //判断是否存在(已经加入过该班级) if(selectBatchStudentList.size() > 0){ ThStudentBatch thStudentBatch = selectBatchStudentList.get(0); //存在 if(studentReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ //删除(学生退出班级) thStudentBatch.setDelFlag(DeleteStatusEnum.YES.getStatus()); updateThStudentBatchList.add(thStudentBatch); }else { //修改 BeanUtils.copyProperties(studentReqDTO, thStudentBatch); thStudentBatch.setUpdateBy(institutionUser.getInstitutionalName()); thStudentBatch.setUpdateTime(LocalDateTime.now()); updateThStudentBatchList.add(thStudentBatch); } }else { //不存在,新增 ThStudentBatch thStudentBatch = new ThStudentBatch(); BeanUtils.copyProperties(studentReqDTO, thStudentBatch); thStudentBatch.setId(IdUtil.getSnowflake(0,0).nextId()); thStudentBatch.setUpdateBy(institutionUser.getInstitutionalName()); thStudentBatch.setUpdateTime(LocalDateTime.now()); thStudentBatch.setCreateBy(institutionUser.getInstitutionalName()); thStudentBatch.setCreateTime(LocalDateTime.now()); thStudentBatch.setInstitutionId(institutionUser.getId()); thStudentBatch.setInstitutionName(institutionUser.getInstitutionalName()); thStudentBatch.setFinishStatus(FinishStatus.NO.getStatus()); thStudentBatch.setDelFlag(DeleteStatusEnum.NO.getStatus()); saveThStudentBatchList.add(thStudentBatch); } } //学生表新增 List> splitSaveStudentList = ListUtil.split(saveSudentList, 200); for (List studentList : splitSaveStudentList) { studentService.insertBatch(studentList); } //学生表更新 List> splitUpdateStudentList = ListUtil.split(updateStudentList, 200); for (List studentList : splitUpdateStudentList) { studentService.updateBatch(studentList); } //学生关联班级表 List> splitSaveThStudentBatchList = ListUtil.split(saveThStudentBatchList, 200); for (List studentBatcheList : splitSaveThStudentBatchList) { studentBatchService.insertBatch(studentBatcheList); } //学生关联班级表修改 List> splitUpdateThStudentBatchList = ListUtil.split(updateThStudentBatchList, 200); for (List studentBatcheList : splitUpdateThStudentBatchList) { studentBatchService.updateBatch(studentBatcheList); } return AjaxResult.success(errorDataRespDTOS); } /** * 班次 * @param jsonObject * @return */ @Transactional @Override public AjaxResult receiveBatch(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); //解密 List batchReqDTOList = decryptData(jsonObject, new TypeReference>() {},"班级"); //反序列化 // List batchReqDTOList = new ArrayList<>(); // try { // batchReqDTOList = JSONObject.parseObject(decrypt, new TypeReference>() {}); // // }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 reqAllBatchUuids = new ArrayList<>(); List reqCourseUuids = new ArrayList<>(); List reqChapterUuids = new ArrayList<>(); for(ThBatchReqDTO batchReqDTO : batchReqDTOList){ if(!reqAllBatchUuids.contains(batchReqDTO.getUuid()) && StringUtils.isNotEmpty(batchReqDTO.getUuid())){ reqAllBatchUuids.add(batchReqDTO.getUuid()); } if(!CollectionUtils.isEmpty(batchReqDTO.getCourseList())){ for (ThBatchCourseReqDTO thCourseReqDTO : batchReqDTO.getCourseList()){ if(!reqCourseUuids.contains(thCourseReqDTO.getCourseUuid()) && StringUtils.isNotEmpty(thCourseReqDTO.getCourseUuid())){ reqCourseUuids.add(thCourseReqDTO.getCourseUuid()); } if(!CollectionUtils.isEmpty(thCourseReqDTO.getChapterList())){ for (ThBatchCourseChapterReqDTO chapter : thCourseReqDTO.getChapterList()){ //去重 if(!reqChapterUuids.contains(chapter.getChapterUuid()) && StringUtils.isNotEmpty(chapter.getChapterUuid())){ reqChapterUuids.add(chapter.getChapterUuid()); } if(!CollectionUtils.isEmpty(chapter.getChildren())){ for (ThBatchCourseChapterReqDTO section : chapter.getChildren()){ //去重 if(!reqChapterUuids.contains(section.getChapterUuid()) && StringUtils.isNotEmpty(section.getChapterUuid())){ reqChapterUuids.add(section.getChapterUuid()); } } } } } } } } //获取已存在班级 List oldBatchList = batchService.getByUuids(reqAllBatchUuids); //获取已存在班级课程 List oldbatchCourseList = batchCourseService.getListByBatchUuids(reqAllBatchUuids); //获取已存在班级课程章节 List oldbatchCourseChapterList = batchCourseChapterService.getListByBatchUuids(reqAllBatchUuids); //获取课程 List thCourseList = courseService.getByUuidList(reqCourseUuids); //获取章节 List thCourseChapterList = courseChapterService.getByUuids(reqChapterUuids); //获取科目类别 List subjectTypeList = subjectTypeService.getSubjectTypeList(); //校验 List errorDataRespDTOS = new ArrayList<>(); List saveBatchReqDTOList = new ArrayList<>(); for (ThBatchReqDTO batchReqDTO : batchReqDTOList) { //获取该机构所有课程和章节 //参数校验 if(StringUtils.isEmpty(batchReqDTO.getUuid()) || !UUID.checkIsUuid(batchReqDTO.getUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"批次(班级)uuid不符合规范")); continue; } if(StringUtils.isEmpty(batchReqDTO.getBatchName())){ 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 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(),"所属培训机构统一社会信用代码不可为空")); continue; } if(batchReqDTO.getHaveExam() == null || HaveExam.get(batchReqDTO.getHaveExam()) == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"有无考试不规范")); continue; } 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){ errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"批次(班级)课时不可为空")); continue; } if(batchReqDTO.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(batchReqDTO.getDelFlag()) == null ){ errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"批次(班级)删除标识不符合规范")); continue; } if(CollectionUtils.isEmpty(batchReqDTO.getCourseList())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"关联课程不可为空")); continue; } boolean errorFlag = false; //校验课程 for (ThBatchCourseReqDTO thBatchCourseReqDTO : batchReqDTO.getCourseList()) { if(StringUtils.isEmpty(thBatchCourseReqDTO.getCourseUuid()) || !UUID.checkIsUuid(thBatchCourseReqDTO.getCourseUuid())){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"课程uuid("+thBatchCourseReqDTO.getCourseUuid()+")不符合规范")); break; } if(thBatchCourseReqDTO.getCourseLessonNum() == null){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"课程("+thBatchCourseReqDTO.getCourseUuid()+")课时不可为空")); break; } List selectCourseList = thCourseList.stream().filter(c -> c.getUuid().equals(thBatchCourseReqDTO.getCourseUuid())).collect(Collectors.toList()); if(selectCourseList.size() == 0){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"课程("+thBatchCourseReqDTO.getCourseUuid()+")不存在")); break; } if(thBatchCourseReqDTO.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(thBatchCourseReqDTO.getDelFlag()) == null ){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"课程("+thBatchCourseReqDTO.getCourseUuid()+")删除标识不符合规范")); break; } if(CollectionUtils.isEmpty(thBatchCourseReqDTO.getChapterList())){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"课程("+thBatchCourseReqDTO.getCourseUuid()+")章节(大章)不可为空")); break; } //校验章节(大) for (ThBatchCourseChapterReqDTO chapter : thBatchCourseReqDTO.getChapterList()) { if(StringUtils.isEmpty(chapter.getChapterUuid()) || !UUID.checkIsUuid(chapter.getChapterUuid())){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(大章)uuid("+chapter.getChapterUuid()+")不符合规范")); break; } if(chapter.getChapterLessonNum() == null){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(大章)("+chapter.getChapterUuid()+")课时不可为空")); break; } if(chapter.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(chapter.getDelFlag()) == null ){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(大章)("+chapter.getChapterUuid()+")删除标识不符合规范")); break; } //校验章节存在否 List chapterSelectList = thCourseChapterList .stream() .filter(courseChapter -> courseChapter.getUuid().equals(chapter.getChapterUuid()) && courseChapter.getCourseUuid().equals(thBatchCourseReqDTO.getCourseUuid()) && courseChapter.getParentUuid().equals("0") ).collect(Collectors.toList()); if(chapterSelectList.size() == 0){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(大章)("+chapter.getChapterUuid()+")不存在")); break; } if(CollectionUtils.isEmpty(chapter.getChildren())){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"大章("+chapter.getChapterUuid()+")包含章节(小节)不可为空")); break; } for (ThBatchCourseChapterReqDTO child : chapter.getChildren()) { if(StringUtils.isEmpty(child.getChapterUuid()) || !UUID.checkIsUuid(child.getChapterUuid())){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(小节)uuid("+child.getChapterUuid()+")不符合规范")); break; } if(child.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(child.getDelFlag()) == null ){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(小节)("+child.getChapterUuid()+")删除标识不符合规范")); break; } List sectionSelectList = thCourseChapterList .stream() .filter(courseChapter -> courseChapter.getUuid().equals(child.getChapterUuid()) && courseChapter.getCourseUuid().equals(thBatchCourseReqDTO.getCourseUuid()) && courseChapter.getParentUuid().equals(chapter.getChapterUuid()) ).collect(Collectors.toList()); if(sectionSelectList.size() == 0){ errorFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(batchReqDTO.getUuid(),"章节(小节)("+child.getChapterUuid()+")不存在")); break; } } if(errorFlag){ break; } } if(errorFlag){ break; } } if(errorFlag){ continue; } saveBatchReqDTOList.add(batchReqDTO); } //数据填充 List saveBatchList = new ArrayList<>(); List updateBatchList = new ArrayList<>(); List saveBatchCourseList = new ArrayList<>(); List updateBatchCourseList = new ArrayList<>(); List saveBatchCourseChapterList = new ArrayList<>(); List updateBatchCourseChapterList = new ArrayList<>(); for (ThBatchReqDTO batchReqDTO : saveBatchReqDTOList) { List oldBatchSelectList = oldBatchList.stream().filter(ob -> ob.getUuid().equals(batchReqDTO.getUuid())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(oldBatchSelectList)){ ThBatch batch = oldBatchSelectList.get(0); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ //删除班级 batch.setDelFlag(batchReqDTO.getDelFlag()); batch.setUpdateBy(institutionUser.getInstitutionalName()); batch.setUpdateTime(LocalDateTime.now()); updateBatchList.add(batch); List delectBatchCourseList = oldbatchCourseList .stream() .filter(obc -> obc.getBatchUuid().equals(batch.getUuid())) .collect(Collectors.toList()); delectBatchCourseList.forEach(item -> { item.setDelFlag(DeleteStatusEnum.YES.getStatus()); item.setUpdateBy(institutionUser.getInstitutionalName()); item.setUpdateTime(LocalDateTime.now()); }); updateBatchCourseList.addAll(delectBatchCourseList); List deleteBatchCourseChapterList = oldbatchCourseChapterList .stream() .filter(obcc -> obcc.getBatchUuid().equals(batch.getUuid())) .collect(Collectors.toList()); deleteBatchCourseChapterList.forEach(item -> { item.setDelFlag(DeleteStatusEnum.YES.getStatus()); item.setUpdateBy(institutionUser.getInstitutionalName()); item.setUpdateTime(LocalDateTime.now()); }); updateBatchCourseChapterList.addAll(deleteBatchCourseChapterList); }else { //非删除 BeanUtils.copyProperties(batchReqDTO,batch); batch.setUpdateBy(institutionUser.getInstitutionalName()); batch.setUpdateTime(LocalDateTime.now()); updateBatchList.add(batch); //修改课程 for(ThBatchCourseReqDTO courseReqDTO : batchReqDTO.getCourseList()){ List oldBatchCourseSelectList = oldbatchCourseList.stream().filter(c -> c.getCourseUuid().equals(courseReqDTO.getCourseUuid())).collect(Collectors.toList()); if(CollectionUtils.isEmpty(oldBatchCourseSelectList)){ //获取该课程信息 List courseInfoList = thCourseList.stream().filter(c -> c.getUuid().equals(courseReqDTO.getCourseUuid())).collect(Collectors.toList()); //插入课程 ThBatchCourse batchCourse = new ThBatchCourse(); BeanUtils.copyProperties(courseReqDTO,batchCourse); batchCourse.setCourseName(courseInfoList.get(0).getCourseName()); batchCourse.setBatchUuid(batch.getUuid()); //batchCourse.setCourseUuid(courseReqDTO.getCouserUuid()); batchCourse.setInstitutionId(institutionUser.getId()); batchCourse.setCreateBy(institutionUser.getInstitutionalName()); batchCourse.setCreateTime(LocalDateTime.now()); batchCourse.setUpdateBy(institutionUser.getInstitutionalName()); batchCourse.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ batchCourse.setDelFlag(DeleteStatusEnum.YES.getStatus()); } saveBatchCourseList.add(batchCourse); //插入章 for(ThBatchCourseChapterReqDTO chapterReqDTO : courseReqDTO.getChapterList()){ //获取其章 List chapterInfoList = thCourseChapterList.stream().filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(chapterReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter chapter = new ThBatchCourseChapter(); BeanUtils.copyProperties(chapterInfoList.get(0),chapter); chapter.setBatchUuid(batch.getUuid()); chapter.setLessonNum(chapterReqDTO.getChapterLessonNum()); chapter.setId(IdUtil.getSnowflake(0,0).nextId()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ chapter.setDelFlag(DeleteStatusEnum.YES.getStatus()); }else { chapter.setDelFlag(chapterReqDTO.getDelFlag()); } chapter.setDelFlag(DeleteStatusEnum.YES.getStatus()); chapter.setChapterUuid(chapterReqDTO.getChapterUuid()); chapter.setCreateBy(institutionUser.getInstitutionalName()); chapter.setCreateTime(LocalDateTime.now()); chapter.setUpdateBy(institutionUser.getInstitutionalName()); chapter.setUpdateTime(LocalDateTime.now()); saveBatchCourseChapterList.add(chapter); //插入节 for(ThBatchCourseChapterReqDTO sectionReqDTO : chapterReqDTO.getChildren()){ //获取节 List sectionInfoList = thCourseChapterList.stream() .filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(sectionReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter section = new ThBatchCourseChapter(); BeanUtils.copyProperties(sectionInfoList.get(0),section); section.setBatchUuid(batch.getUuid()); section.setLessonNum(sectionReqDTO.getChapterLessonNum()); section.setId(IdUtil.getSnowflake(0,0).nextId()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ section.setDelFlag(DeleteStatusEnum.YES.getStatus()); }else { section.setDelFlag(sectionReqDTO.getDelFlag()); } section.setChapterUuid(sectionReqDTO.getChapterUuid()); section.setCreateBy(institutionUser.getInstitutionalName()); section.setCreateTime(LocalDateTime.now()); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); saveBatchCourseChapterList.add(section); } } }else { //修改 ThBatchCourse batchCourse = oldBatchCourseSelectList.get(0); batchCourse.setDelFlag(courseReqDTO.getDelFlag()); batchCourse.setCourseLessonNum(courseReqDTO.getCourseLessonNum()); batchCourse.setUpdateBy(institutionUser.getInstitutionalName()); batchCourse.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ batchCourse.setDelFlag(DeleteStatusEnum.YES.getStatus()); } updateBatchCourseList.add(batchCourse); //章 for(ThBatchCourseChapterReqDTO chapterReqDTO : courseReqDTO.getChapterList()){ List oldChapterInfoList = oldbatchCourseChapterList.stream().filter(ochapter -> ochapter.getCourseUuid().equals(batchCourse.getCourseUuid()) && ochapter.getChapterUuid().equals(chapterReqDTO.getChapterUuid())).collect(Collectors.toList()); //章是否存在 if(!CollectionUtils.isEmpty(oldChapterInfoList)){ //存在修改 ThBatchCourseChapter chapter = oldChapterInfoList.get(0); BeanUtils.copyProperties(chapterReqDTO,chapter); chapter.setLessonNum(chapterReqDTO.getChapterLessonNum()); chapter.setUpdateBy(institutionUser.getInstitutionalName()); chapter.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ chapter.setDelFlag(DeleteStatusEnum.YES.getStatus()); } updateBatchCourseChapterList.add(chapter); for(ThBatchCourseChapterReqDTO sectionReqDTO : chapterReqDTO.getChildren()){ List oldsectionInfoList = oldbatchCourseChapterList.stream().filter(section -> section.getCourseUuid().equals(batchCourse.getCourseUuid()) && section.getChapterUuid().equals(sectionReqDTO.getChapterUuid())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(oldsectionInfoList)){ //存在,修改 ThBatchCourseChapter section = oldsectionInfoList.get(0); BeanUtils.copyProperties(sectionReqDTO,section); section.setLessonNum(sectionReqDTO.getChapterLessonNum()); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ section.setDelFlag(DeleteStatusEnum.YES.getStatus()); } updateBatchCourseChapterList.add(section); }else { //不存在,新增 //获取节 List sectionInfoList = thCourseChapterList.stream() .filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(sectionReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter section = new ThBatchCourseChapter(); BeanUtils.copyProperties(sectionInfoList.get(0),section); section.setBatchUuid(batch.getUuid()); section.setChapterUuid(sectionInfoList.get(0).getUuid()); section.setLessonNum(sectionReqDTO.getChapterLessonNum()); section.setId(IdUtil.getSnowflake(0,0).nextId()); section.setDelFlag(sectionReqDTO.getDelFlag()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ section.setDelFlag(DeleteStatusEnum.YES.getStatus()); } section.setCreateBy(institutionUser.getInstitutionalName()); section.setCreateTime(LocalDateTime.now()); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); saveBatchCourseChapterList.add(section); } } }else { //不存在,新增 //获取其章 List chapterInfoList = thCourseChapterList.stream().filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(chapterReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter chapter = new ThBatchCourseChapter(); BeanUtils.copyProperties(chapterInfoList.get(0),chapter); chapter.setChapterUuid(chapterInfoList.get(0).getUuid()); chapter.setBatchUuid(batch.getUuid()); chapter.setLessonNum(chapterReqDTO.getChapterLessonNum()); chapter.setId(IdUtil.getSnowflake(0,0).nextId()); chapter.setDelFlag(chapterReqDTO.getDelFlag()); chapter.setCreateBy(institutionUser.getInstitutionalName()); chapter.setCreateTime(LocalDateTime.now()); chapter.setUpdateBy(institutionUser.getInstitutionalName()); chapter.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ chapter.setDelFlag(DeleteStatusEnum.YES.getStatus()); } saveBatchCourseChapterList.add(chapter); //插入节 for(ThBatchCourseChapterReqDTO sectionReqDTO : chapterReqDTO.getChildren()){ //获取节 List sectionInfoList = thCourseChapterList.stream() .filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(sectionReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter section = new ThBatchCourseChapter(); BeanUtils.copyProperties(sectionInfoList.get(0),section); section.setChapterUuid(sectionInfoList.get(0).getUuid()); section.setBatchUuid(batch.getUuid()); section.setLessonNum(sectionReqDTO.getChapterLessonNum()); section.setId(IdUtil.getSnowflake(0,0).nextId()); section.setDelFlag(sectionReqDTO.getDelFlag()); section.setCreateBy(institutionUser.getInstitutionalName()); section.setCreateTime(LocalDateTime.now()); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ section.setDelFlag(DeleteStatusEnum.YES.getStatus()); } saveBatchCourseChapterList.add(section); } } } } } } }else { //新增 //班次新增 ThBatch batch = new ThBatch(); BeanUtils.copyProperties(batchReqDTO, batch); batch.setUpdateBy(institutionUser.getInstitutionalName()); batch.setUpdateTime(LocalDateTime.now()); batch.setCreateBy(institutionUser.getInstitutionalName()); batch.setCreateTime(LocalDateTime.now()); batch.setInstitutionId(institutionUser.getId()); batch.setInstitutionName(institutionUser.getInstitutionalName()); saveBatchList.add(batch); for(ThBatchCourseReqDTO courseReqDTO : batchReqDTO.getCourseList()) { //获取该课程信息 List courseInfoList = thCourseList.stream().filter(c -> c.getUuid().equals(courseReqDTO.getCourseUuid())).collect(Collectors.toList()); //插入课程 ThBatchCourse batchCourse = new ThBatchCourse(); BeanUtils.copyProperties(courseReqDTO, batchCourse); batchCourse.setCourseName(courseInfoList.get(0).getCourseName()); batchCourse.setBatchUuid(batch.getUuid()); //batchCourse.setCourseUuid(courseReqDTO.getCouserUuid()); batchCourse.setInstitutionId(institutionUser.getId()); batchCourse.setCreateBy(institutionUser.getInstitutionalName()); batchCourse.setCreateTime(LocalDateTime.now()); batchCourse.setUpdateBy(institutionUser.getInstitutionalName()); batchCourse.setUpdateTime(LocalDateTime.now()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ batchCourse.setDelFlag(DeleteStatusEnum.YES.getStatus()); }else { batchCourse.setDelFlag(DeleteStatusEnum.NO.getStatus()); } saveBatchCourseList.add(batchCourse); //插入章 for (ThBatchCourseChapterReqDTO chapterReqDTO : courseReqDTO.getChapterList()) { //获取其章 List chapterInfoList = thCourseChapterList.stream().filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(chapterReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter chapter = new ThBatchCourseChapter(); BeanUtils.copyProperties(chapterInfoList.get(0), chapter); chapter.setBatchUuid(batch.getUuid()); chapter.setLessonNum(chapterReqDTO.getChapterLessonNum()); chapter.setId(IdUtil.getSnowflake(0, 0).nextId()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ chapter.setDelFlag(DeleteStatusEnum.YES.getStatus()); }else { chapter.setDelFlag(DeleteStatusEnum.NO.getStatus()); } chapter.setChapterUuid(chapterReqDTO.getChapterUuid()); chapter.setChapterUuid(chapterReqDTO.getChapterUuid()); saveBatchCourseChapterList.add(chapter); //插入节 for (ThBatchCourseChapterReqDTO sectionReqDTO : chapterReqDTO.getChildren()) { //获取节 List sectionInfoList = thCourseChapterList.stream() .filter(cc -> cc.getCourseUuid().equals(batchCourse.getCourseUuid()) && cc.getUuid().equals(sectionReqDTO.getChapterUuid())).collect(Collectors.toList()); ThBatchCourseChapter section = new ThBatchCourseChapter(); BeanUtils.copyProperties(sectionInfoList.get(0), section); section.setBatchUuid(batch.getUuid()); section.setLessonNum(sectionReqDTO.getChapterLessonNum()); section.setId(IdUtil.getSnowflake(0, 0).nextId()); if(batchReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || courseReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || chapterReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus()) || sectionReqDTO.getDelFlag().equals(DeleteStatusEnum.YES.getStatus())){ section.setDelFlag(DeleteStatusEnum.YES.getStatus()); }else { section.setDelFlag(DeleteStatusEnum.NO.getStatus()); } section.setChapterUuid(sectionReqDTO.getChapterUuid()); section.setCreateBy(institutionUser.getInstitutionalName()); section.setCreateTime(LocalDateTime.now()); section.setUpdateBy(institutionUser.getInstitutionalName()); section.setUpdateTime(LocalDateTime.now()); section.setBatchUuid(batch.getUuid()); section.setChapterUuid(sectionReqDTO.getChapterUuid()); saveBatchCourseChapterList.add(section); } } } } } //插入班级数据 List> splitSaveBatchList = ListUtil.split(saveBatchList, 500); for (List batchList : splitSaveBatchList) { batchService.insertBatch(batchList); } //修改班级数据 List> splitUpdateBatchList = ListUtil.split(updateBatchList, 500); for (List batchList : splitUpdateBatchList) { batchService.updateBatch(batchList); } //插入课程 List> splitSaveBatchCourseList = ListUtil.split(saveBatchCourseList, 500); for (List courseList : splitSaveBatchCourseList) { batchCourseService.insertBatch(courseList); } //修改课程 List> splitUpdateBatchCourseList = ListUtil.split(updateBatchCourseList, 500); for (List courseList : splitUpdateBatchCourseList) { batchCourseService.updateBatch(courseList); } //插入章节 List> splitSaveBatchCourseChapterList = ListUtil.split(saveBatchCourseChapterList, 200); for (List chapterList : splitSaveBatchCourseChapterList) { batchCourseChapterService.insertBatch(chapterList); } //修改章节 List> splitUpdateBatchCourseChapterList = ListUtil.split(updateBatchCourseChapterList, 200); for (List chapterList : splitUpdateBatchCourseChapterList) { batchCourseChapterService.updateBatch(chapterList); } return AjaxResult.success(errorDataRespDTOS); } @Transactional @Override public AjaxResult receiveStudyDetail(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); //解密 List thStudyDetailReqDTOS = decryptData(jsonObject, new TypeReference>() {},"学习记录"); //反序列化 // List thStudyDetailReqDTOS = new ArrayList<>(); // try { // thStudyDetailReqDTOS = JSONObject.parseObject(decrypt, new TypeReference>() {}); // }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 chapterUuids = new ArrayList<>(); List idcards = new ArrayList<>(); List studyUuids = new ArrayList<>(); for (ThStudyDetailReqDTO studentDetailReqDTO : thStudyDetailReqDTOS) { if(!idcards.contains(studentDetailReqDTO.getIdcard()) && StringUtils.isNotEmpty(studentDetailReqDTO.getIdcard())){ idcards.add(studentDetailReqDTO.getIdcard()); } if(!chapterUuids.contains(studentDetailReqDTO.getChapterUuid()) && StringUtils.isNotEmpty(studentDetailReqDTO.getChapterUuid())){ chapterUuids.add(studentDetailReqDTO.getChapterUuid()); } studyUuids.add(studentDetailReqDTO.getUuid()); } List thStudentBatches = studentBatchService.getByIdCards(idcards); List batchCourseChapters = batchCourseChapterService.getByChapterUuids(chapterUuids); //校验 List updateStudentBatchList = new ArrayList<>(); List errorDataRespDTOS = new ArrayList<>(); List saveStudyDetailReqDTOS = new ArrayList<>(); for (ThStudyDetailReqDTO studentDetailReqDTO : thStudyDetailReqDTOS) { if(StringUtils.isEmpty(studentDetailReqDTO.getUuid()) || !UUID.checkIsUuid(studentDetailReqDTO.getUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习记录uuid标识不规范")); continue; } if(StringUtils.isEmpty(studentDetailReqDTO.getIdcard())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学生身份证不可为空")); continue; } if(StringUtils.isEmpty(studentDetailReqDTO.getCourseUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"课程不可为空")); continue; } if(StringUtils.isEmpty(studentDetailReqDTO.getBatchUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"批次不可为空")); continue; } if(StringUtils.isEmpty(studentDetailReqDTO.getChapterUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"章节不可为空")); continue; } //获取该平台课程 List StudentBatchSelectList = thStudentBatches.stream().filter(sb -> sb.getIdcard().equals(studentDetailReqDTO.getIdcard()) && sb.getBatchUuid().equals(studentDetailReqDTO.getBatchUuid())).collect(Collectors.toList()); studentBatchService.getByIdcardAndBatchUuid(studentDetailReqDTO.getIdcard(),studentDetailReqDTO.getBatchUuid()); List chapterSelectList = batchCourseChapters.stream().filter(bcc -> bcc.getChapterUuid().equals(studentDetailReqDTO.getChapterUuid()) && bcc.getCourseUuid().equals(studentDetailReqDTO.getCourseUuid()) && bcc.getBatchUuid().equals(studentDetailReqDTO.getBatchUuid())).collect(Collectors.toList()); if(StudentBatchSelectList.size() == 0){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"批次(班级)中学生信息不存在")); continue; } if(chapterSelectList.size() == 0){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"课程章节不存在")); continue; } if(StringUtils.isEmpty(studentDetailReqDTO.getTrainOrgName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空")); continue; } if(studentDetailReqDTO.getFinishStatus() == null || FinishStatus.get(studentDetailReqDTO.getFinishStatus()) == null){ 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){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习时长(秒)不可为空")); continue; } if(studentDetailReqDTO.getStartTime() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"开始时间不可为空")); continue; } if(studentDetailReqDTO.getFinishTime() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"结束时间不可为空")); continue; } if(studentDetailReqDTO.getStartPosition() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"开始位置不可为空")); continue; } if(studentDetailReqDTO.getFinishPosition() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"结束位置不可为空")); continue; } // if(StringUtils.isEmpty(studentDetailReqDTO.getLessonReportUrl())){ // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学时报告不可为空")); // continue; // } //认证记录集合 // if(CollectionUtils.isEmpty(studentDetailReqDTO.getAuthList())){ // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"认证记录集合不可为空")); // continue; // } //学习轨迹集合 // if(CollectionUtils.isEmpty(studentDetailReqDTO.getTrackList())){ // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习轨迹集合不可为空")); // continue; // } /*boolean authFlag = false; for(ThStudytAuthReqDTO item : studentDetailReqDTO.getAuthList()){ if(StringUtils.isEmpty(item.getUuid()) || !UUID.checkIsUuid(item.getUuid())){ authFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"认证记录uuid("+item.getUuid()+")不符合规范")); break; } if(StringUtils.isEmpty(item.getApprovePhoto())){ authFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"认证记录uuid("+item.getUuid()+"),认证照片不可为空")); break; } if(item.getAuthPosition() == null){ authFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"认证记录uuid("+item.getUuid()+"),认证位置不可为空")); break; } if(item.getAuthTime() == null){ authFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"认证记录uuid("+item.getUuid()+"),认证时间不可为空")); break; } if(item.getFaceType() == null || FaceType.get(item.getFaceType()) == null){ authFlag = true; errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"认证记录uuid("+item.getUuid()+"),认证类型不规范")); break; } } if(authFlag){ continue; }*/ // boolean trackFlag = false; // for(ThStudyTrackReqDTO item : studentDetailReqDTO.getTrackList()){ // if(StringUtils.isEmpty(item.getUuid()) || !UUID.checkIsUuid(item.getUuid())){ // trackFlag = true; // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习轨迹uuid("+item.getUuid()+")不符合规范")); // break; // } // if(item.getStartTime() == null){ // trackFlag = true; // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习轨迹uuid("+item.getUuid()+"),轨迹开始时间不可为空")); // break; // } // if(item.getEndTime() == null){ // trackFlag = true; // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习轨迹uuid("+item.getUuid()+"),轨迹结束时间不可为空")); // break; // } // if(item.getTimeInterval() == null) { // trackFlag = true; // errorDataRespDTOS.add(new ThErrorDataRespDTO(studentDetailReqDTO.getUuid(),"学习轨迹uuid("+item.getUuid()+"),时间间隔(秒)不可为空")); // break; // } // } // if(trackFlag){ // continue; // } saveStudyDetailReqDTOS.add(studentDetailReqDTO); //判断需要修改的批次学生 if(studentDetailReqDTO.getCompleteStatus().equals(FinishStatus.YES.getStatus())){ ThStudentBatch thStudentBatch = StudentBatchSelectList.get(0); thStudentBatch.setFinishStatus(studentDetailReqDTO.getCompleteStatus()); updateStudentBatchList.add(thStudentBatch); } } //获取历史记录 List oldThStudyDetails = studyDetailService.getByUuids(studyUuids); List oldStudyAuthList = studyAuthService.getByStudyDetaiUuids(studyUuids); List oldStudyTrackList = studyTrackService.getByStudyDetailUuids(studyUuids); List saveStudyDetailList = new ArrayList<>(); List updateStudyDetailList = new ArrayList<>(); List saveStudyAuthList = new ArrayList<>(); List saveStudyTrackList = new ArrayList<>(); for(ThStudyDetailReqDTO studyDetailReqDTO : saveStudyDetailReqDTOS){ List oldStudyDetailList = oldThStudyDetails .stream() .filter(sd -> sd.getUuid().equals(studyDetailReqDTO.getUuid())) .collect(Collectors.toList()); if(oldStudyDetailList.size() == 0){ //新增学习清单 ThStudyDetail thStudyDetail = new ThStudyDetail(); BeanUtils.copyProperties(studyDetailReqDTO, thStudyDetail); thStudyDetail.setUpdateBy(institutionUser.getInstitutionalName()); thStudyDetail.setUpdateTime(LocalDateTime.now()); thStudyDetail.setCreateBy(institutionUser.getInstitutionalName()); thStudyDetail.setCreateTime(LocalDateTime.now()); thStudyDetail.setInstitutionId(institutionUser.getId()); thStudyDetail.setInstitutionName(institutionUser.getInstitutionalName()); thStudyDetail.setDelFlag(DeleteStatusEnum.NO.getStatus()); thStudyDetail.setSerialNum(generateSerialNum()); saveStudyDetailList.add(thStudyDetail); //新增认证记录 List thStudyAuthList = studyDetailReqDTO.getAuthList().stream().map(sa -> { ThStudyAuth thStudyAuth = new ThStudyAuth(); BeanUtils.copyProperties(sa, thStudyAuth); thStudyAuth.setStudyDetailUuid(studyDetailReqDTO.getUuid()); return thStudyAuth; }).collect(Collectors.toList()); saveStudyAuthList.addAll(thStudyAuthList); //新增学习轨迹 List thStudyTrackList = studyDetailReqDTO.getTrackList().stream().map(track -> { ThStudyTrack thStudyTrack = new ThStudyTrack(); BeanUtils.copyProperties(track, thStudyTrack); thStudyTrack.setStudyDetailUuid(studyDetailReqDTO.getUuid()); return thStudyTrack; }).collect(Collectors.toList()); saveStudyTrackList.addAll(thStudyTrackList); }else { ThStudyDetail thStudyDetail = oldStudyDetailList.get(0); //修改 BeanUtils.copyProperties(studyDetailReqDTO, thStudyDetail); thStudyDetail.setUpdateBy(institutionUser.getInstitutionalName()); thStudyDetail.setUpdateTime(LocalDateTime.now()); updateStudyDetailList.add(thStudyDetail); //过滤该记录的认证记录 List authUuids = oldStudyAuthList .stream() .filter(a -> a.getStudyDetailUuid().equals(thStudyDetail.getUuid())) .map(ThStudyAuth::getUuid).collect(Collectors.toList()); //过滤出记录的轨迹记录 List trackUuids = oldStudyTrackList .stream() .filter(t -> t.getStudyDetailUuid().equals(thStudyDetail.getUuid())) .map(ThStudyTrack::getUuid).collect(Collectors.toList()); List saveAuthList = studyDetailReqDTO.getAuthList().stream() .filter(a -> !authUuids.contains(a.getUuid())) .map(a -> { ThStudyAuth thStudyAuth = new ThStudyAuth(); BeanUtils.copyProperties(a, thStudyAuth); thStudyAuth.setStudyDetailUuid(studyDetailReqDTO.getUuid()); return thStudyAuth; }) .collect(Collectors.toList()); saveStudyAuthList.addAll(saveAuthList); List saveTrackList = studyDetailReqDTO.getTrackList().stream() .filter(t -> !trackUuids.contains(t.getUuid())) .map(t -> { ThStudyTrack thStudyTrack = new ThStudyTrack(); BeanUtils.copyProperties(t, thStudyTrack); thStudyTrack.setStudyDetailUuid(studyDetailReqDTO.getUuid()); return thStudyTrack; }).collect(Collectors.toList()); saveStudyTrackList.addAll(saveTrackList); } } //插入学习记录 List> splitSaveDetailList = ListUtil.split(saveStudyDetailList, 200); for (List thStudyDetails : splitSaveDetailList) { studyDetailService.insertBatch(thStudyDetails); } //修改学习记录 List> splitUpdateDetailList = ListUtil.split(updateStudyDetailList, 200); for (List thStudyDetails : splitUpdateDetailList) { studyDetailService.updateBatch(thStudyDetails); } //插入认证记录 List> splitSaveAuthList = ListUtil.split(saveStudyAuthList, 200); for (List thStudyAuths : splitSaveAuthList) { studyAuthService.insetBatch(thStudyAuths); } //插入学习轨迹 List> splitSaveTrackList = ListUtil.split(saveStudyTrackList, 200); for (List thStudyTracks : splitSaveTrackList) { studyTrackService.insertBatch(thStudyTracks); } //修改学生完成状态 List> splitUpdateThStudentBatchList = ListUtil.split(updateStudentBatchList, 200); for (List studentBatcheList : splitUpdateThStudentBatchList) { studentBatchService.updateBatch(studentBatcheList); } return AjaxResult.success(errorDataRespDTOS); } @Transactional @Override public AjaxResult receiveExamRecord(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); //解密 List examRecordReqDTOS = decryptData(jsonObject, new TypeReference>() {},"考试记录"); //反序列化 // List examRecordReqDTOS = new ArrayList<>(); // try { // examRecordReqDTOS = JSONObject.parseObject(decrypt, new TypeReference>() {}); // }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 idcards = new ArrayList<>(); //List batchUuids = new ArrayList<>(); List examUuids = new ArrayList<>(); for (ThExamRecordReqDTO examRecordReqDTO : examRecordReqDTOS) { if(!idcards.contains(examRecordReqDTO.getIdcard())){ idcards.add(examRecordReqDTO.getIdcard()); } /*if(!batchUuids.contains(examRecordReqDTO.getBatchUuid())){ batchUuids.add(examRecordReqDTO.getBatchUuid()); }*/ examUuids.add(examRecordReqDTO.getUuid()); } //参数校验 List studentBatchList = studentBatchService.getByIdCards(idcards); List oldExamRecordList = examRecordService.getByUuids(examUuids); List errorDataRespDTOS = new ArrayList<>(); List saveExamRecordList = new ArrayList<>(); for (ThExamRecordReqDTO examRecordReqDTO : examRecordReqDTOS) { if(StringUtils.isEmpty(examRecordReqDTO.getUuid()) || !UUID.checkIsUuid(examRecordReqDTO.getUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"考试记录uuid不符合规范")); continue; } if(StringUtils.isEmpty(examRecordReqDTO.getIdcard())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"身份证不可为空")); continue; } if(StringUtils.isEmpty(examRecordReqDTO.getBatchUuid())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"批次(班级)不可为空")); continue; } List thStudentCourses = studentBatchList.stream().filter(sc -> sc.getBatchUuid().equals(examRecordReqDTO.getBatchUuid()) && sc.getIdcard().equals(examRecordReqDTO.getIdcard())).collect(Collectors.toList()); if(thStudentCourses.size() == 0){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"无学生"+examRecordReqDTO.getIdcard()+"培训信息")); continue; } if(StringUtils.isEmpty(examRecordReqDTO.getTrainOrgName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"所属培训机构统一社会信用代码不可为空")); continue; } if(StringUtils.isEmpty(examRecordReqDTO.getExamName())){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"考试名称不可为空")); continue; } if(examRecordReqDTO.getExamStartTime() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"开考时间不可为空")); continue; } if(examRecordReqDTO.getExamSubmitTime() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"结束时间不可为空")); continue; } if(examRecordReqDTO.getExamUserScore() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"学习成绩不可为空")); continue; } if(examRecordReqDTO.getExamTotalScore() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"试卷总分不可为空")); continue; } if(examRecordReqDTO.getExamPassScore() == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"合格分数不可为空")); continue; } if(examRecordReqDTO.getExamIsPass() == null || ExamIsPass.get(examRecordReqDTO.getExamIsPass()) == null){ errorDataRespDTOS.add(new ThErrorDataRespDTO(examRecordReqDTO.getUuid(),"是否通过考试状态不规范")); continue; } List examRecordSelectList = oldExamRecordList.stream().filter(e -> e.getUuid().equals(examRecordReqDTO.getUuid())).collect(Collectors.toList()); if(examRecordSelectList.size() == 0){ //新增 ThExamRecord thExamRecord = new ThExamRecord(); BeanUtils.copyProperties(examRecordReqDTO,thExamRecord); thExamRecord.setInstitutionId(institutionUser.getId()); thExamRecord.setInstitutionName(institutionUser.getInstitutionalName()); thExamRecord.setCreateTime(LocalDateTime.now()); thExamRecord.setUpdateTime(LocalDateTime.now()); thExamRecord.setCreateBy(institutionUser.getInstitutionalName()); thExamRecord.setUpdateBy(institutionUser.getInstitutionalName()); thExamRecord.setDelFlag(DeleteStatusEnum.NO.getStatus()); saveExamRecordList.add(thExamRecord); } } List> splitSaveExamList = ListUtil.split(saveExamRecordList, 500); for (List list : splitSaveExamList) { examRecordService.saveBatch(list); } return AjaxResult.success(errorDataRespDTOS); } @Transactional @Override public AjaxResult receiveCourseDelete(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); //解密 ThCourseDeleteReqDTO thCourseDeleteReqDTO = decryptData(jsonObject, new TypeReference() {},"课程删除"); //反序列化 // ThCourseDeleteReqDTO thCourseDeleteReqDTO = null; // try { // thCourseDeleteReqDTO = JSONObject.parseObject(decrypt, new TypeReference() {}); // // }catch (Exception e){ // logger.error("课程删除反序列化失败!"); // throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR); // // } if(thCourseDeleteReqDTO == null){ throw new BusinessException(ResultConstants.THREE_INSTITUTION_PARAMM_NULL); } if(StringUtils.isEmpty(thCourseDeleteReqDTO.getCourseUuid())){ throw new BusinessException(ResultConstants.THREE_INSTITUTION_PARAMM_NULL); } ThCourse thCourse = courseService.getByUuid(thCourseDeleteReqDTO.getCourseUuid()); List thCourseChapterVOS = courseChapterService.listByCourseUuid(thCourseDeleteReqDTO.getCourseUuid()); if(thCourse == null){ throw new BusinessException(ResultConstants.COURSE_IS_NOT_EXIST); } boolean exsit = batchCourseService.isExsit(thCourseDeleteReqDTO.getCourseUuid()); if(exsit){ throw new BusinessException(ResultConstants.BATCH_COURSE_EXIST); } thCourse.setDelFlag(DeleteStatusEnum.YES.getStatus()); thCourse.setUpdateTime(LocalDateTime.now()); thCourse.setUpdateBy(institutionUser.getInstitutionalName()); List thCourseChapters = thCourseChapterVOS.stream().map(cc -> { ThCourseChapter thCourseChapter = new ThCourseChapter(); BeanUtils.copyProperties(cc, thCourseChapter); thCourseChapter.setUpdateTime(LocalDateTime.now()); thCourseChapter.setUpdateBy(institutionUser.getInstitutionalName()); thCourseChapter.setDelFlag(DeleteStatusEnum.YES.getStatus()); return thCourseChapter; }).collect(Collectors.toList()); courseService.updateById(thCourse); //删除章节 if(thCourseChapters.size() > 0){ courseChapterService.updateBatchById(thCourseChapters); } return AjaxResult.success(); } @Override public AjaxResult receiveBatchOpen(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); ThBatchOpenReqDTO thBatchOpenReqDTO = decryptData(jsonObject, new TypeReference() {},"班级开始"); //反序列化 // ThBatchOpenReqDTO thBatchOpenReqDTO = null; // try { // thBatchOpenReqDTO = JSONObject.parseObject(decrypt, new TypeReference() {}); // }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,"批次(班级)不可为空"); } if(StringUtils.isEmpty(thBatchOpenReqDTO.getBatchUuid())){ throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)不可为空"); } ThBatch thBatch = batchService.getByUuid(thBatchOpenReqDTO.getBatchUuid()); if(thBatch == null){ throw new BusinessException(ResultConstants.BATCH_IS_NOT_EXIST); } if(!thBatch.getStatus().equals(OpenStatus.NO.getStatus())){ throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_OTHER_ERROR,"已开班或已结束不可重新开班"); } thBatch.setStatus(OpenStatus.START.getStatus()); thBatch.setUpdateTime(LocalDateTime.now()); thBatch.setUpdateBy(institutionUser.getInstitutionalName()); thBatch.setActualStartTime(LocalDateTime.now()); batchService.updateById(thBatch); return AjaxResult.success(); } @Transactional @Override public AjaxResult receiveBatchEnd(JSONObject jsonObject) { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); ThBatchEndReqDTO thBatchEndReqDTO = decryptData(jsonObject, new TypeReference() {},"批次(班级)"); if(thBatchEndReqDTO == null){ throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)不可为空"); } if(StringUtils.isEmpty(thBatchEndReqDTO.getBatchUuid())){ throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)不可为空"); } ThBatch thBatch = batchService.getByUuid(thBatchEndReqDTO.getBatchUuid()); if(thBatch == null){ throw new BusinessException(ResultConstants.BATCH_IS_NOT_EXIST); } thBatch.setStatus(OpenStatus.END.getStatus()); thBatch.setUpdateTime(LocalDateTime.now()); thBatch.setUpdateBy(institutionUser.getInstitutionalName()); thBatch.setActualEndTime(LocalDateTime.now()); batchService.updateById(thBatch); return AjaxResult.success(); } @Override public AjaxResult receiveCerts(JSONObject jsonObject) throws Exception { InstitutionUser institutionUser = ThreeInContextHolder.getContext(); List thCertReqDTOs = decryptData(jsonObject, new TypeReference>() {},"学时证书"); if(thCertReqDTOs.isEmpty() ||thCertReqDTOs.size()>50){ throw new BusinessException(this.getClass(), ResultConstants.RECORD_OVER_MAX); } //错误 List errorDataRespDTOS = new ArrayList<>(); List saveCertReqDTOList = new ArrayList<>(); List batchUuidList=thCertReqDTOs.stream().map(ThCertReqDTO::getBatchUuid).filter(batchUuid -> !StringUtils.isEmpty(batchUuid)).distinct().collect(Collectors.toList()); //获取批次 List 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 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 saveCertList = new ArrayList<>(); List 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()); if (cert.getDelFlag()==null) { cert.setDelFlag(DeleteStatusEnum.NO.getStatus()); } 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 */ private T decryptData(JSONObject jsonObject,TypeReference 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); } } private void validateStudyDetail(ThStudyDetailReqDTO studentDetailReqDTO) { if (studentDetailReqDTO == null) { throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学习记录清单不可为空"); } if(StringUtils.isEmpty(studentDetailReqDTO.getUuid()) || !UUID.checkIsUuid(studentDetailReqDTO.getUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学习记录uuid不符合规范"); } if(StringUtils.isEmpty(studentDetailReqDTO.getIdcard())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"身份证不可为空"); } if(StringUtils.isEmpty(studentDetailReqDTO.getCourseUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"课程不可为空"); } if(StringUtils.isEmpty(studentDetailReqDTO.getBatchUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次不可为空"); } if(StringUtils.isEmpty(studentDetailReqDTO.getChapterUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节不可为空"); } //获取该平台课程 ThStudentBatch thStudentBatch = studentBatchService.getByIdcardAndBatchUuid(studentDetailReqDTO.getIdcard(),studentDetailReqDTO.getBatchUuid()); ThBatchCourseChapter chapter = batchCourseChapterService.getByUuid(studentDetailReqDTO.getBatchUuid(),studentDetailReqDTO.getCourseUuid(),studentDetailReqDTO.getChapterUuid()); if(thStudentBatch == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)中学生信息不存在"); } if(chapter == null){ 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,"所属培训机构统一社会信用代码不可为空"); } if(studentDetailReqDTO.getFinishStatus() == null || FinishStatus.get(studentDetailReqDTO.getFinishStatus()) == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"完成状态不规范"); } if(studentDetailReqDTO.getDuration() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学习时长(秒)不可为空"); } if(studentDetailReqDTO.getStartTime() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"开始时间不可为空"); } if(studentDetailReqDTO.getFinishTime() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"结束时间不可为空"); } if(studentDetailReqDTO.getStartPosition() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"开始位置不可为空"); } if(studentDetailReqDTO.getFinishPosition() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"结束位置不可为空"); } if(StringUtils.isEmpty(studentDetailReqDTO.getLessonReportUrl())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学时报告不可为空"); } //认证记录集合 if(CollectionUtils.isEmpty(studentDetailReqDTO.getAuthList())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"认证记录集合不可为空"); } studentDetailReqDTO.getAuthList().forEach(item -> { if(StringUtils.isEmpty(item.getUuid()) || !UUID.checkIsUuid(item.getUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",认证记录uuid不符合规范"); } if(StringUtils.isEmpty(item.getApprovePhoto())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",认证照片不可为空"); } if(item.getAuthPosition() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",认证位置不可为空"); } if(item.getAuthTime() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",认证时间不可为空"); } if(item.getFaceType() == null || FaceType.get(item.getFaceType()) == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",认证类型不规范"); } }); //学习轨迹集合 if(CollectionUtils.isEmpty(studentDetailReqDTO.getTrackList())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学习轨迹集合不可为空"); } studentDetailReqDTO.getTrackList().forEach(item -> { if(StringUtils.isEmpty(item.getUuid()) || !UUID.checkIsUuid(item.getUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",认证记录uuid不符合规范"); } if(item.getStartTime() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",轨迹开始时间不可为空"); } if(item.getEndTime() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",轨迹结束时间不可为空"); } if(item.getTimeInterval() == null) { throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,item.getUuid() + ",时间间隔(秒)不可为空"); } }); } /** * 校验班次信息 * @param batchReqDTO */ private void validateBatch(ThBatchReqDTO batchReqDTO) { } /** * 校验学生信息 * @param studentReqDTOS */ private void validateStudent(List studentReqDTOS, Long institutionId) { if(CollectionUtils.isEmpty(studentReqDTOS)){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"学生信息不可为空"); } //获取所有该机构所有课程 List courseList = courseService.listByInstitutionId(institutionId); for (ThStudentReqDTO studentReqDTO : studentReqDTOS) { if(StringUtils.isEmpty(studentReqDTO.getIdcard())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"身份证不可为空"); } if(StringUtils.isEmpty(studentReqDTO.getName())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"姓名不可为空"); } if(StringUtils.isEmpty(studentReqDTO.getPhone())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"手机号不可为空"); } if(studentReqDTO.getSex() == null || StudentSex.get(studentReqDTO.getSex()) == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"性别不可为空"); } if(StringUtils.isEmpty(studentReqDTO.getAuthPhoto())){ 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,"所属培训机构统一社会信用代码不可为空"); } /*if(CollectionUtils.isEmpty(studentReqDTO.getBatchUuids())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"关联课程uuidd不可为空"); }*/ /*for (String batchaUuid : studentReqDTO.getBatchUuids()) { List collect = courseList.stream().filter(course -> course.getUuid().equals(courseReqDTO.getCourseUuid())).collect(Collectors.toList()); if(CollectionUtils.isEmpty(collect)){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"课程uuid不存在,请先添加课程"); } }*/ } } /** * 校验课程 * @param courseReqDTO */ private void validateCourse(ThCourseReqDTO courseReqDTO) { if(courseReqDTO == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_ERROR); } if(StringUtils.isEmpty(courseReqDTO.getUuid()) || !UUID.checkIsUuid(courseReqDTO.getUuid())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"uuid不符合规范"); } if(StringUtils.isEmpty(courseReqDTO.getCourseCode())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"课程标识不可为空"); } if(StringUtils.isEmpty(courseReqDTO.getCourseName())){ 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,"所属培训机构统一社会信用代码不可为空"); } if(courseReqDTO.getLessonNum() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"总课时不可为空"); } /* if(courseReqDTO.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(courseReqDTO.getDelFlag()) == null ){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"删除标识不符合规范"); }*/ if(CollectionUtils.isEmpty(courseReqDTO.getChapters())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"课程大纲(大章)不可为空"); } for (ThCourseChapterReqDTO chapter : courseReqDTO.getChapters()) { if(StringUtils.isEmpty(chapter.getChapterCode())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(大章)标识不可为空"); } if(StringUtils.isEmpty(chapter.getChapterName())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(大章)名称不可为空"); } if(chapter.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(chapter.getDelFlag()) == null ){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(大章)删除标识不符合规范"); } if (chapter.getLessonNum() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(大章)课时(保留1位小数)不可为空"); } if(chapter.getHaveResource() == null || CourseHaveResourse.get(chapter.getHaveResource()) == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"是否有资源不符合规范"); } if(CollectionUtils.isEmpty(chapter.getChildren())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(小节)列表不可为空"); } for (ThCourseChapterReqDTO child : chapter.getChildren()) { if(StringUtils.isEmpty(child.getChapterCode())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(小节)标识不可为空"); } if(StringUtils.isEmpty(child.getChapterName())){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(小节)名称不可为空"); } if(child.getDuration() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(小节)视频时长(秒)不可为空"); } if (child.getLessonNum() == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(小节)课时(保留1位小数)不可为空"); } if(child.getResourceType() == null || CourseResourceType.get(child.getResourceType()) == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"资源类型不规范"); } if(child.getDelFlag() == null || DeleteStatusEnum.getDeleteStatusEnum(child.getDelFlag()) == null ){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"章节(小节)删除标识不符合规范"); } if(child.getHaveResource() == null || CourseHaveResourse.get(child.getHaveResource()) == null){ throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"是否有资源不符合规范"); } } } } private String generateSerialNum() { Long count = studyDetailService.getCount(); String strCount = count.toString(); while (strCount.length() < 5){ strCount = "0" + strCount; } return strCount; } }