From 2ceb5cc35cdbe61a738b2864db5411a4ddc5da50 Mon Sep 17 00:00:00 2001 From: kongzy <kongzy> Date: 星期六, 12 十月 2024 16:41:19 +0800 Subject: [PATCH] 优化 --- exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/TripartiteInterfaceServiceImpl.java | 97 +++++++++++++++--------------------------------- 1 files changed, 30 insertions(+), 67 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 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); + } } -- Gitblit v1.9.2