kongzy
2024-10-12 3402a6cdef63a87cf046a8bbfdc2898bb842c93f
exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java
@@ -3,6 +3,7 @@
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.*;
@@ -11,6 +12,7 @@
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;
@@ -63,9 +65,11 @@
    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");
@@ -90,8 +94,11 @@
        }
        //参数校验
        validateQuestion(questionBankReqDTO);
        String valdateMessage=ValidatorUtils.validateFast(questionBankReqDTO);
        if(!StringUtils.isEmpty(valdateMessage)){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,valdateMessage);
        }
        //根据uuid查询数据
        ThQuestionBank qb = questionBankService.getQuestionInfoByUuid(questionBankReqDTO.getUuid());
        boolean i = true;
@@ -102,19 +109,18 @@
            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) {
@@ -1848,6 +1854,94 @@
        return AjaxResult.success();
    }
    @Override
    public AjaxResult receiveCerts(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);
        }
        //解密
        String decrypt = "";
        try {
            decrypt = AESUtils.decrypt(data);
        }catch (Exception e){
            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
        }
        //反序列化
        List<ThCertReqDTO> thCertReqDTOs = null;
        try {
            thCertReqDTOs = JSONObject.parseObject(decrypt, new TypeReference<List<ThCertReqDTO>>() {});
        }catch (Exception e){
            logger.error("学时证书反序列化失败!");
            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
        }
        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);
    }
    private void validate(){
    }
    private void validateStudyDetail(ThStudyDetailReqDTO studentDetailReqDTO) {
@@ -2075,43 +2169,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();