forked from gzzfw/backEnd/gz-dyh

zhouxiantao
2024-09-24 516b72eb08a931d97dcfaf154d1761e6b4ec7b28
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package cn.huge.module.client.api.impl;
 
import cn.huge.base.common.bo.ReturnBO;
import cn.huge.base.common.constant.ReturnConsts;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.module.cases.domain.dto.FileRelateDTO;
import cn.huge.module.client.api.SysClient;
import cn.huge.module.sys.constant.TimeUnitConsts;
import cn.huge.module.sys.dto.*;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
/**
 * @title: 系统公共服务微服务调用接口
 * @description: 系统公共服务微服务调用接口
 * @company: hugeinfo
 * @author: liyj
 * @time: 2021-11-05 16:51:48
 * @version: 1.0.0
 */
@Slf4j
@Component
public class SysClientImpl {
 
    private SysClient sysClient;
 
    @Autowired
    public SysClientImpl(SysClient sysClient) {
        this.sysClient = sysClient;
    }
 
    /**
     * ObjectMapper工具类
     */
    private ObjectMapper objectMapper = new ObjectMapper();
 
    /**
     * 附件中心-根据多个所属编号查询附件并根据先根据ownerId再根据附件类型分组
     * @param term 所属业务编号
     * @return List
     */
    public List<FileIdTypeInfoBaseDTO> listIdTypeInfoByOwnerIdList(Map<String, Object> term){
        List<FileIdTypeInfoBaseDTO> fileIdTypeInfoBaseDTOList = new ArrayList<>();
        try{
            ReturnBO returnBo = sysClient.listTypeInfoByOwnerIdList(term);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    List<LinkedHashMap> list = (List<LinkedHashMap>) returnBo.getData();
                    for (LinkedHashMap map : list) {
                        FileIdTypeInfoBaseDTO fileIdTypeInfoBaseDTO = JSON.parseObject(JSON.toJSONString(map), FileIdTypeInfoBaseDTO.class);
                        fileIdTypeInfoBaseDTOList.add(fileIdTypeInfoBaseDTO);
                    }
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.listIdTypeInfoByOwnerIdList]调用异常:"+e, e);
        }
        return fileIdTypeInfoBaseDTOList;
    }
 
    /**
     * 附件中心-根据业务编号查询固定格式所有附件
     * @param term 所属业务编号
     * @return List
     */
    public List<FileIdInfoBaseDTO> listIdInfoByOwnerIdList(Map<String, Object> term){
        List<FileIdInfoBaseDTO> fileIdInfoBaseDTOList = new ArrayList<>();
        try{
            ReturnBO returnBo = sysClient.listInfoByOwnerIdList(term);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    List<LinkedHashMap> list = (List<LinkedHashMap>) returnBo.getData();
                    for (LinkedHashMap map : list) {
                        FileIdInfoBaseDTO fileIdInfoBaseDTO = JSON.parseObject(JSON.toJSONString(map), FileIdInfoBaseDTO.class);
                        fileIdInfoBaseDTOList.add(fileIdInfoBaseDTO);
                    }
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.listIdInfoByOwnerIdList]调用异常:"+e, e);
        }
        return fileIdInfoBaseDTOList;
    }
 
    /**
     * 获取时限
     * @param limitType  时限类型
     * @return List
     */
    public Integer getTimeLimitHour(String limitType){
        int timeTerm = 0;
        try{
            ReturnBO returnBo = sysClient.getExpireTime(limitType);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    SyTimeLimitDTO syTimeLimitDTO = objectMapper.convertValue(returnBo.getData(), SyTimeLimitDTO.class);
                    if (ObjectUtils.isNotEmpty(syTimeLimitDTO)){
                        if (ObjectUtils.isNotEmpty(syTimeLimitDTO)){
                            if (TimeUnitConsts.TIME_UNIT_1.equals(syTimeLimitDTO.getTermUnit())){
                                timeTerm = syTimeLimitDTO.getTimeTerm()*24*365;
                            }
                            if (TimeUnitConsts.TIME_UNIT_2.equals(syTimeLimitDTO.getTermUnit())){
                                timeTerm = syTimeLimitDTO.getTimeTerm()*24*30;
                            }
                            if (TimeUnitConsts.TIME_UNIT_3.equals(syTimeLimitDTO.getTermUnit())){
                                timeTerm = syTimeLimitDTO.getTimeTerm()*24;
                            }
                            if (TimeUnitConsts.TIME_UNIT_4.equals(syTimeLimitDTO.getTermUnit())){
                                timeTerm = syTimeLimitDTO.getTimeTerm();
                            }
                            if (TimeUnitConsts.TIME_UNIT_5.equals(syTimeLimitDTO.getTermUnit())){
                                timeTerm = syTimeLimitDTO.getTimeTerm()/60;
                            }
                        }
                    }
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.listIdInfoByOwnerIdList]调用异常:"+e, e);
        }
        return timeTerm;
    }
 
    /**
     * 获取时限
     * @url {ctx}/api/web/syTimeLimit/getExpireTime
     * @param computeTime
     * @param limitType
     * @return
     */
    public Date getExpireTime(Date computeTime, String limitType){
        Date expireTime = null;
        try{
            ReturnBO returnBo = sysClient.getExpireTime(limitType);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    SyTimeLimitDTO syTimeLimitDTO = objectMapper.convertValue(returnBo.getData(), SyTimeLimitDTO.class);
                    if (ObjectUtils.isNotEmpty(syTimeLimitDTO)){
                        if (ObjectUtils.isNotEmpty(syTimeLimitDTO)){
                            if (TimeUnitConsts.TIME_UNIT_1.equals(syTimeLimitDTO.getTermUnit())){
                                expireTime = DateUtils.addYear(computeTime, syTimeLimitDTO.getTimeTerm());
                            }
                            if (TimeUnitConsts.TIME_UNIT_2.equals(syTimeLimitDTO.getTermUnit())){
                                expireTime = DateUtils.addMonth(computeTime, syTimeLimitDTO.getTimeTerm());
                            }
                            if (TimeUnitConsts.TIME_UNIT_3.equals(syTimeLimitDTO.getTermUnit())){
                                expireTime = DateUtils.addDay(computeTime, syTimeLimitDTO.getTimeTerm());
                            }
                            if (TimeUnitConsts.TIME_UNIT_4.equals(syTimeLimitDTO.getTermUnit())){
                                expireTime = DateUtils.addHour(computeTime, syTimeLimitDTO.getTimeTerm());
                            }
                            if (TimeUnitConsts.TIME_UNIT_5.equals(syTimeLimitDTO.getTermUnit())){
                                expireTime = DateUtils.addMonth(computeTime, syTimeLimitDTO.getTimeTerm());
                            }
                        }
                    }
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.getExpireTime]调用异常:"+e, e);
        }
        return expireTime;
    }
 
    /**
     * 根据条件删除附件关系
     * @param fileTypeTermsDTO 条件
     * @return Object
     */
    public void removeFileRelate(FileTypeTermsDTO fileTypeTermsDTO) {
        try {
            ReturnBO returnBo = sysClient.removeFileRelate(fileTypeTermsDTO);
            if (ReturnConsts.OK != returnBo.getCode()){
                log.error("Client外服务接口[SysClientImpl.removeFileRelate]请求异常:" + returnBo.getMsg(), returnBo.getMsg());
            }
        } catch (Exception e) {
            log.error("service方法[SysClientImpl.removeFileRelate]请求异常:"+e, e);
        }
    }
 
    /**
     * 根据百度地图经纬度获取街道
     * @url {ctx}/api/client/syRegion/getTownByBaiduiLngLat
     * @param lng 经度
     * @param lat 维度
     * @return
     */
    public QueAddrBaseDTO getQueAddrByBaiduiLngLat(String lng, String lat){
        QueAddrBaseDTO queAddrBaseDTO = new QueAddrBaseDTO();
        try{
            ReturnBO returnBo = sysClient.getQueAddrByBaiduiLngLat(lng, lat);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    queAddrBaseDTO = objectMapper.convertValue(returnBo.getData(), QueAddrBaseDTO.class);
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.getQueAddrByBaiduiLngLat]调用异常:"+e, e);
        }
        return queAddrBaseDTO;
    }
 
    /**
     * 根据关系编号查询附件关系信息
     * @param ownerId 附件关系编号
     * @return List
     */
    public List<FileRelateDTO> listFileRelateByOwnerId(String ownerId){
        List<FileRelateDTO> fileRelateDTOList = new ArrayList<>();
        try{
            ReturnBO returnBo = sysClient.listFileRelateByOwnerId(ownerId);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    List<LinkedHashMap> list = (List<LinkedHashMap>) returnBo.getData();
                    for (LinkedHashMap map : list) {
                        FileRelateDTO fileRelateDTO = JSON.parseObject(JSON.toJSONString(map), FileRelateDTO.class);
                        fileRelateDTOList.add(fileRelateDTO);
                    }
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.listFileRelateByOwnerId]调用异常:"+e, e);
        }
        return fileRelateDTOList;
    }
 
    /**
     * 插入多条附件关系记录
     * @param fileRelateList 附件关系
     * @return Object
     */
    public void saveFileRelateList(List<FileRelateDTO> fileRelateList) {
        try {
            ReturnBO returnBo = sysClient.saveFileRelateList(fileRelateList);
            if (ReturnConsts.OK != returnBo.getCode()){
                log.error("Client外服务接口[SysClientImpl.saveFileRelateList]请求异常:" + returnBo.getMsg(), returnBo.getMsg());
            }
        } catch (Exception e) {
            log.error("service方法[SysClientImpl.saveFileRelateList]请求异常:"+e, e);
        }
    }
 
    public List<QueAreaDTO> listByParentId(String parentId){
        List<QueAreaDTO> queAreaDTOList = new ArrayList<>();
        try{
            ReturnBO returnBo = sysClient.listByParentId(parentId);
            if (ReturnConsts.OK == returnBo.getCode()){
                if (ObjectUtils.isNotEmpty(returnBo.getData())){
                    List<LinkedHashMap> list = (List<LinkedHashMap>) returnBo.getData();
                    for (LinkedHashMap map : list) {
                        QueAreaDTO queAreaDTO = JSON.parseObject(JSON.toJSONString(map), QueAreaDTO.class);
                        queAreaDTOList.add(queAreaDTO);
                    }
                }
            }
        }catch (Exception e){
            log.error("service方法[SysClientImpl.listFileRelateByOwnerId]调用异常:"+e, e);
        }
        return queAreaDTOList;
    }
 
}