教育训练处考试制证系统后端
zhangf
2024-09-11 1a316551c8e46b793904090cfa84781bf77fef2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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 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.*;
import java.util.stream.Collectors;
 
@Service("ThStudyRecordManagerService")
public class ThStudyRecordManagerServiceImpl implements ThStudyRecordManagerService {
    private Logger logger = LoggerFactory.getLogger(ThStudyRecordManagerServiceImpl.class);
 
    @Autowired
    private ThStudyDetailService thStudyDetailService;
    @Autowired
    private ThStudyTrackService thStudyTrackService;
    @Autowired
    private ThStudyAuthService thStudyAuthService;
    @Autowired
    private ThCourseChapterService thCourseChapterService;;
    @Autowired
    private ThCourseService thCourseService;
    @Autowired
    private ThBatchService thBatchService;
    @Autowired
    private ThStudentService studentService;;
    @Autowired
    private ThAccessAddressService thAccessAddressService;
 
    @Override
    public List<ThStudyDetailVO> listByPage(ThStudyDetailQuery query) {
        query.setStartSize((query.getPageNum()-1)*query.getPageSize());
 
        List<ThStudyDetailVO> thStudyDetailVOS = thStudyDetailService.listByPage(query);
 
        if(!CollectionUtils.isEmpty(thStudyDetailVOS)){
            List<String> detailUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getUuid).collect(Collectors.toList());
            //获取认证记录
            List<ThStudyAuth> authList = thStudyAuthService.getByStudyDetaiUuids(detailUuids);
            //获取轨迹
            List<ThStudyTrack> trackList = thStudyTrackService.getListByStudyDetaiIds(detailUuids);
            //获取章节名称
            List<String> chapterUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getChapterUuid).collect(Collectors.toList());
            List<ThCourseChapter> chapterList = thCourseChapterService.getChapterNameByUuids(chapterUuids);
            //获取课程名称
            List<String> courseUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getCourseUuid).collect(Collectors.toList());
            List<ThCourse> courseList = thCourseService.getCourseNameByUuids(courseUuids);
            //获取批次名称
            List<String> batchUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getBatchUuid).collect(Collectors.toList());
            List<ThBatch> batchList = thBatchService.getBatchNameByUuids(batchUuids);
            //学生信息
            List<String> idcards = thStudyDetailVOS.stream().map(ThStudyDetailVO::getIdcard).collect(Collectors.toList());
            List<ThStudent> studentList = studentService.getNameByIdcards(idcards);
            for(ThStudyDetailVO thStudyDetailVO : thStudyDetailVOS){
                thStudyDetailVO.setDurationDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getDuration()));
                thStudyDetailVO.setStartPositionDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getStartPosition()));
                thStudyDetailVO.setFinishPositionDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getFinishPosition()));
                List<ThStudyAuthVO> thStudyAuthVOList = authList.stream().filter(a -> a.getStudyDetailUuid().equals(thStudyDetailVO.getUuid()))
                        .map(a -> {
                            ThStudyAuthVO thStudyAuthVO = new ThStudyAuthVO();
                            BeanUtils.copyProperties(a, thStudyAuthVO);
                            thStudyAuthVO.setAuthPostionDesc(ConvertTimeUtils.convertTimeToString(a.getAuthPosition()));
                            return thStudyAuthVO;
                        }).collect(Collectors.toList());
 
                List<ThStudyTrackVO> trackVOList = trackList.stream().filter(t -> t.getStudyDetailUuid().equals(thStudyDetailVO.getUuid()))
                        .map(t -> {
                            ThStudyTrackVO thStudyTrackVO = new ThStudyTrackVO();
                            BeanUtils.copyProperties(t, thStudyTrackVO);
                            thStudyTrackVO.setTimeIntervalDesc(ConvertTimeUtils.convertTimeToString(t.getTimeInterval()));
                            return thStudyTrackVO;
                        }).collect(Collectors.toList());
                thStudyDetailVO.setAuthList(thStudyAuthVOList);
                thStudyDetailVO.setTrackList(trackVOList);
                List<ThCourseChapter> chapterSelectList = chapterList.stream().filter(chapter -> chapter.getUuid().equals(thStudyDetailVO.getChapterUuid())).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(chapterSelectList)){
                    thStudyDetailVO.setChapterName(chapterSelectList.get(0).getChapterName());
                }
                List<ThCourse> courseSelectList = courseList.stream().filter(c -> c.getUuid().equals(thStudyDetailVO.getCourseUuid())).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(courseSelectList)){
                    thStudyDetailVO.setCourseName(courseSelectList.get(0).getCourseName());
                }
                List<ThBatch> batchSelectList = batchList.stream().filter(b -> b.getUuid().equals(thStudyDetailVO.getBatchUuid())).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(batchSelectList)){
                    thStudyDetailVO.setBatchName(batchSelectList.get(0).getBatchName());
                }
                List<ThStudent> studentSelectList = studentList.stream().filter(thStudent -> thStudent.getIdcard().equals(thStudyDetailVO.getIdcard())).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(studentSelectList)){
                    thStudyDetailVO.setName(studentSelectList.get(0).getName());
                }
 
            }
        }
        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);
 
        ReturnVO<String> returnVo = JSONObject.parseObject(json, new TypeReference<ReturnVO<String>>() {});
        if(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());
            }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);
    }
 
 
}