From 2ceb5cc35cdbe61a738b2864db5411a4ddc5da50 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: 星期六, 12 十月 2024 16:41:19 +0800
Subject: [PATCH] 优化

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java                                     |    9 ++++
 exam-system/src/main/java/com/gkhy/exam/institutionalaccess/model/query/ThCertQuery.java                            |    4 +-
 exam-system/src/main/resources/mapper/institutionaccess/ThCertMapper.xml                                            |    4 +-
 exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java |   97 +++++++++++++++---------------------------------
 4 files changed, 43 insertions(+), 71 deletions(-)

diff --git a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/model/query/ThCertQuery.java b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/model/query/ThCertQuery.java
index 96f89da..7e610dd 100644
--- a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/model/query/ThCertQuery.java
+++ b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/model/query/ThCertQuery.java
@@ -10,10 +10,10 @@
     private String institutionName;
 
     //证书生成开始时间
-    private LocalDateTime startTime;
+    private String startTime;
 
     //证书生成结束时间
-    private LocalDateTime endTime;
+    private String endTime;
 
     //机构代码
     private String trainOrgName;
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 9bb6b63..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
@@ -71,34 +71,14 @@
     @Override
     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);
-        }
-        //反序列化
-        ThQuestionBankReqDTO questionBankReqDTO = null;
-        try {
-            questionBankReqDTO = JSONObject.parseObject(decrypt, new TypeReference<ThQuestionBankReqDTO>() {});
-
-        }catch (Exception e){
-            logger.error("组卷反序列化失败!");
-            throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
-
-        }
-
         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;
@@ -1815,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,"批次(班级)不可为空");
         }
@@ -1857,36 +1818,16 @@
     @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);
-        }
+        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)){
@@ -1900,7 +1841,6 @@
             }
             saveCertReqDTOList.add(thCertReqDTO);
         }
-
         List<ThCert> saveCertList = new ArrayList<>();
         List<ThCert> updateCertList = new ArrayList<>();
         for (ThCertReqDTO thCertReqDTO : saveCertReqDTOList) {
@@ -1939,8 +1879,31 @@
         return AjaxResult.success(errorDataRespDTOS);
     }
 
-    private void validate(){
-
+    /**
+     * 解密数据
+     * @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);
+        }
     }
 
 
diff --git a/exam-system/src/main/resources/mapper/institutionaccess/ThCertMapper.xml b/exam-system/src/main/resources/mapper/institutionaccess/ThCertMapper.xml
index 23e8467..6763a25 100644
--- a/exam-system/src/main/resources/mapper/institutionaccess/ThCertMapper.xml
+++ b/exam-system/src/main/resources/mapper/institutionaccess/ThCertMapper.xml
@@ -12,10 +12,10 @@
                  and a.institution_name =#{institutionName}
             </if>
             <if test="startTime!=null and startTime!=''">
-                and a.cert_ime &gt;= #{startTime}
+                and a.cert_time &gt;= #{startTime}
             </if>
             <if test="endTime!=null and endTime!=''">
-                and a.cert_ime &lt;= #{endTime}
+                and a.cert_time &lt;= #{endTime}
             </if>
             <if test="trainOrgName!=null and trainOrgName!=''">
                 and a.train_org_name =#{trainOrgName}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java
index b7bcfb0..60fe01a 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java
@@ -1,7 +1,13 @@
 package com.ruoyi.framework.config;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.TimeZone;
+
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -19,12 +25,15 @@
 @MapperScan({"com.ruoyi.**.mapper","com.gkhy.**.mapper"})
 public class ApplicationConfig
 {
+    @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
+    private String pattern;
     /**
      * 时区配置
      */
     @Bean
     public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization()
     {
+
         return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
     }
 }

--
Gitblit v1.9.2