From 3aae8ddd5b9624626921abdcc33122dccdcd5c61 Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: 星期五, 27 十二月 2024 13:24:46 +0800
Subject: [PATCH] 修改学时证书接收接口

---
 exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThStudyRecordManagerServiceImpl.java |   81 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThStudyRecordManagerServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThStudyRecordManagerServiceImpl.java
index 8a4a0a6..a7b3560 100644
--- a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThStudyRecordManagerServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThStudyRecordManagerServiceImpl.java
@@ -1,23 +1,42 @@
 package com.gkhy.exam.institutionalaccess.service.serviceImpl;
 
+import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.TypeReference;
 import com.gkhy.exam.institutionalaccess.entity.*;
+import com.ruoyi.system.domain.enums.AccessAddressType;
 import com.gkhy.exam.institutionalaccess.model.query.ThStudyDetailQuery;
+import com.gkhy.exam.institutionalaccess.model.resp.ThPlatformStudentRespDTO;
 import com.gkhy.exam.institutionalaccess.model.vo.ThStudyAuthVO;
 import com.gkhy.exam.institutionalaccess.model.vo.ThStudyDetailVO;
 import com.gkhy.exam.institutionalaccess.model.vo.ThStudyTrackVO;
 import com.gkhy.exam.institutionalaccess.service.*;
 import com.gkhy.exam.institutionalaccess.utils.ConvertTimeUtils;
+import com.ruoyi.common.utils.HttpClientUtil;
+import com.gkhy.exam.noncoalmine.model.vo.ReturnVO;
+import com.ruoyi.common.constant.ResultConstants;
+import com.ruoyi.common.exception.BusinessException;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.signature.AESUtils;
+import com.ruoyi.system.domain.ThAccessAddress;
+import com.ruoyi.system.service.ThAccessAddressService;
+import lombok.extern.log4j.Log4j2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.time.Duration;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service("ThStudyRecordManagerService")
+@Log4j2
 public class ThStudyRecordManagerServiceImpl implements ThStudyRecordManagerService {
+    private Logger logger = LoggerFactory.getLogger(ThStudyRecordManagerServiceImpl.class);
+
     @Autowired
     private ThStudyDetailService thStudyDetailService;
     @Autowired
@@ -32,6 +51,8 @@
     private ThBatchService thBatchService;
     @Autowired
     private ThStudentService studentService;;
+    @Autowired
+    private ThAccessAddressService thAccessAddressService;
 
     @Override
     public List<ThStudyDetailVO> listByPage(ThStudyDetailQuery query) {
@@ -58,6 +79,10 @@
             List<String> idcards = thStudyDetailVOS.stream().map(ThStudyDetailVO::getIdcard).collect(Collectors.toList());
             List<ThStudent> studentList = studentService.getNameByIdcards(idcards);
             for(ThStudyDetailVO thStudyDetailVO : thStudyDetailVOS){
+                //计算自然时间差
+                Duration between = Duration.between(thStudyDetailVO.getStartTime(), thStudyDetailVO.getFinishTime());
+                thStudyDetailVO.setDifference(between.getSeconds());
+                thStudyDetailVO.setDifferenceDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getDifference()));
                 thStudyDetailVO.setDurationDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getDuration()));
                 thStudyDetailVO.setStartPositionDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getStartPosition()));
                 thStudyDetailVO.setFinishPositionDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getFinishPosition()));
@@ -100,5 +125,57 @@
         return thStudyDetailVOS;
     }
 
+    @Override
+    public ThPlatformStudentRespDTO getStudyRecordByIdcard(ThStudyDetailQuery query) {
+        if(StringUtils.isEmpty(query.getIdcard())){
+            throw new BusinessException(this.getClass(), ResultConstants.PARAM_ERROR_NULL,"学生身份证不可为空");
+        }
+        if(query.getInstitutionId() == null){
+            throw new BusinessException(this.getClass(), ResultConstants.PARAM_ERROR_NULL,"学生所属机构不可为空");
+        }
+        //获取该机构访问路径
+        ThAccessAddress accessAddress = thAccessAddressService.getByInstitutionIdAndType(query.getInstitutionId(), AccessAddressType.STUDY_RECORD.getType());
+        Map<String,String> params = new HashMap<>();
+        params.put("idcard",query.getIdcard());
+        String json = HttpClientUtil.doGet(accessAddress.getUrl(), params);
+        log.info("调用机构接口返回结果: "+json);
+
+        ReturnVO<String> returnVo = JSONObject.parseObject(json, new TypeReference<ReturnVO<String>>() {});
+        log.info("获得第三方数据:"+returnVo);
+        if(returnVo==null || returnVo.getCode() == null || returnVo.getCode() != 200){
+            throw new ServiceException("获取三方数据数据异常");
+        }
+        ThPlatformStudentRespDTO thPlatformStudentRespDTO = null;
+        if(!StringUtils.isEmpty(returnVo.getData())){
+            String decrypt = "";
+            try {
+                decrypt = AESUtils.decrypt(returnVo.getData());
+                log.info("解密后的数据为:"+decrypt);
+            }catch (Exception e){
+                throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR,"解密异常");
+            }
+            if(!StringUtils.isEmpty(decrypt)){
+                try {
+                    thPlatformStudentRespDTO = JSONObject.parseObject(decrypt, new TypeReference<ThPlatformStudentRespDTO>() {});
+
+                }catch (Exception e){
+                    logger.error("学习实时记录反序列化失败!");
+                    throw new BusinessException(this.getClass(), ResultConstants.SERIALIZE_ERROR);
+
+                }
+            }
+
+        }
+
+        return thPlatformStudentRespDTO;
+    }
+
+    public static void main(String[] args) {
+        Map<String,String> params = new HashMap<>();
+        params.put("idcard","652201198009174020");
+        String s = HttpClientUtil.doGet("https://app.lgb360.com/egress/xj/getStuDetail", params);
+        System.out.println(s);
+    }
+
 
 }

--
Gitblit v1.9.2