From 5eb29a5eab52a99c22e8fee4c4df34ddb55b044c Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: 星期三, 16 十月 2024 13:57:01 +0800
Subject: [PATCH] 增加题库搜索

---
 exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java |  187 ++++++++++++++++++++++++++--------------------
 1 files changed, 104 insertions(+), 83 deletions(-)

diff --git a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java
index 4db8897..d7110c8 100644
--- a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java
+++ b/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,35 +65,20 @@
     private ThBatchCourseChapterService batchCourseChapterService;
     @Autowired
     private ThSubjectTypeService subjectTypeService;
+    @Autowired
+    private ThCertService certService;
 
     @Override
-    public boolean receiveQuestionBank(JSONObject jsonObject) {
+    public boolean receiveQuestionBank(JSONObject jsonObject) throws Exception {
         InstitutionUser institutionUser = ThreeInContextHolder.getContext();
-
-        String data = jsonObject.getString("data");
-        if(StringUtils.isEmpty(data)){
-            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
+        ThQuestionBankReqDTO questionBankReqDTO =   decryptData(jsonObject, new TypeReference<ThQuestionBankReqDTO>() {});
+        if(questionBankReqDTO==null){
+            throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"题库数据不可为空");
         }
-        //解密
-        String decrypt = "";
-        try {
-            decrypt = AESUtils.decrypt(data);
-        }catch (Exception e){
-            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
+        String valdateMessage=ValidatorUtils.validateFast(questionBankReqDTO);
+        if(!StringUtils.isEmpty(valdateMessage)){
+            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL,valdateMessage);
         }
-        //反序列化
-        ThQuestionBankReqDTO questionBankReqDTO = null;
-        try {
-            questionBankReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThQuestionBankReqDTO>() {});
-
-        }catch (Exception e){
-            logger.error("组卷反序列化失败!");
-            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
-
-        }
-
-        //参数校验
-        validateQuestion(questionBankReqDTO);
         //根据uuid查询数据
         ThQuestionBank qb = questionBankService.getQuestionInfoByUuid(questionBankReqDTO.getUuid());
         boolean i = true;
@@ -102,19 +89,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) {
@@ -1809,26 +1795,7 @@
     @Override
     public AjaxResult receiveBatchEnd(JSONObject jsonObject) {
         InstitutionUser institutionUser = ThreeInContextHolder.getContext();
-
-        String data = jsonObject.getString("data");
-        if(StringUtils.isEmpty(data)){
-            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
-        }
-        //解密
-        String decrypt = "";
-        try {
-            decrypt = AESUtils.decrypt(data);
-        }catch (Exception e){
-            throw new BusinessException(this.getClass(), ResultConstants.THREE_INSTITUTION_PARAMM_NULL);
-        }
-        //反序列化
-        ThBatchEndReqDTO thBatchEndReqDTO = null;
-        try {
-            thBatchEndReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThBatchEndReqDTO>() {});
-        }catch (Exception e){
-            logger.error("班级结束反序列化失败!");
-            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
-        }
+        ThBatchEndReqDTO thBatchEndReqDTO = decryptData(jsonObject, new TypeReference<ThBatchEndReqDTO>() {});
         if(thBatchEndReqDTO == null){
             throw new BusinessException(this.getClass(),ResultConstants.THREE_INSTITUTION_PARAMM_NULL,"批次(班级)不可为空");
         }
@@ -1848,6 +1815,96 @@
         return AjaxResult.success();
     }
 
+    @Override
+    public AjaxResult receiveCerts(JSONObject jsonObject) throws Exception {
+        InstitutionUser institutionUser = ThreeInContextHolder.getContext();
+        List<ThCertReqDTO> thCertReqDTOs = decryptData(jsonObject, new TypeReference<List<ThCertReqDTO>>() {});
+        if(thCertReqDTOs.isEmpty() ||thCertReqDTOs.size()>50){
+            throw new BusinessException(this.getClass(), ResultConstants.RECORD_OVER_MAX);
+        }
+        //错误
+        List<ThErrorDataRespDTO> errorDataRespDTOS = new ArrayList<>();
+        List<ThCertReqDTO> saveCertReqDTOList = new ArrayList<>();
+        List<String> batchUuidList=thCertReqDTOs.stream().map(ThCertReqDTO::getBatchUuid).filter(batchUuid -> !StringUtils.isEmpty(batchUuid)).distinct().collect(Collectors.toList());
+        //获取批次
+        List<ThBatch> batchList = batchService.getByUuids(batchUuidList);
+        for(ThCertReqDTO thCertReqDTO : thCertReqDTOs){
+            String validateMessage=ValidatorUtils.validateFast(thCertReqDTO);
+            if(!StringUtils.isEmpty(validateMessage)){
+                errorDataRespDTOS.add(new ThErrorDataRespDTO(thCertReqDTO.getUuid(),validateMessage));
+                continue;
+            }
+            List<ThBatch> collect = batchList.stream().filter(batchCourse -> batchCourse.getUuid().equals(thCertReqDTO.getBatchUuid())).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(collect)) {
+                errorDataRespDTOS.add(new ThErrorDataRespDTO(thCertReqDTO.getUuid(), "批次(班级)不存在,请先添加批次(班级)"));
+                continue;
+            }
+            saveCertReqDTOList.add(thCertReqDTO);
+        }
+        List<ThCert> saveCertList = new ArrayList<>();
+        List<ThCert> updateCertList = new ArrayList<>();
+        for (ThCertReqDTO thCertReqDTO : saveCertReqDTOList) {
+            ThCert cert=certService.getCertByUuid(thCertReqDTO.getUuid());
+            if (cert!=null) {
+                //修改
+                BeanUtils.copyProperties(thCertReqDTO, cert);
+                cert.setUpdateBy(institutionUser.getInstitutionalName());
+                cert.setUpdateTime(LocalDateTime.now());
+                cert.setInstitutionId(institutionUser.getId());
+                cert.setInstitutionName(institutionUser.getInstitutionalName());
+                updateCertList.add(cert);
+            } else {
+                //新增
+                cert = new ThCert();
+                BeanUtils.copyProperties(thCertReqDTO, cert);
+                cert.setId(IdUtil.getSnowflake(0, 0).nextId());
+                cert.setUpdateBy(institutionUser.getInstitutionalName());
+                cert.setUpdateTime(LocalDateTime.now());
+                cert.setCreateBy(institutionUser.getInstitutionalName());
+                cert.setCreateTime(LocalDateTime.now());
+                cert.setInstitutionId(institutionUser.getId());
+                cert.setInstitutionName(institutionUser.getInstitutionalName());
+                cert.setDelFlag(DeleteStatusEnum.NO.getStatus());
+                saveCertList.add(cert);
+            }
+        }
+        //课时证书表新增
+        if(!saveCertList.isEmpty()){
+            certService.insertBatch(saveCertList);
+        }
+        //课时证书表更新
+        if(!updateCertList.isEmpty()) {
+            certService.updateBatch(updateCertList);
+        }
+        return AjaxResult.success(errorDataRespDTOS);
+    }
+
+    /**
+     * 解密数据
+     * @param jsonObject
+     * @param typeReference
+     * @return
+     * @param <T>
+     */
+    private <T> T decryptData(JSONObject jsonObject,TypeReference<T> typeReference){
+        String 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("学时证书反序列化失败!");
+            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
+        }
+    }
 
 
     private void validateStudyDetail(ThStudyDetailReqDTO studentDetailReqDTO) {
@@ -2075,43 +2132,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();

--
Gitblit v1.9.2