广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
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
 
package cn.huge.module.grid.service;
 
import cn.huge.base.common.bo.R;
import cn.huge.base.common.utils.*;
import cn.huge.module.client.api.impl.CustClientImpl;
import cn.huge.module.cust.dto.CtUserDTO;
import cn.huge.module.file.utils.FileUtils;
import cn.huge.module.file.utils.FtpUtils;
import cn.huge.module.grid.domain.dto.GridCaseInfoDTO;
import cn.huge.module.grid.domain.dto.GridFileUploadDTO;
import cn.huge.module.grid.domain.dto.GridSysRoleDTO;
import cn.huge.module.grid.domain.po.GridEvent;
import cn.huge.module.grid.domain.po.GridEventRequest;
import cn.huge.module.grid.domain.vo.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.annotation.AccessType;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
 
@Slf4j
@Service
public class GridCaseDataService {
    @Value("${grid.url:http://219.137.166.84:8061}")
    private String gridUrl;
    @Value("${grid.username:mtxt0011}")
    private String userName;
    @Value("${grid.password:aek8CdcaM}")
    private String passWord;
    private String testUrl = "http://183.2.142.21:9007";
    @Autowired
    private GridUserService gridUserService;
    @Autowired
    private GridEventService gridEventService;
 
    @Autowired
    private CustClientImpl custClient;
 
    @Value("${grid.secret:BZb2hLCx05}")
    private String secret;
    @Value("${grid.passid:b08c0ec0-772d-caf8-5c9b-1f7d86295a95}")
    private String passid;
    public HashMap<String,String> initHeadVo() {
        long timestamp = System.currentTimeMillis()/1000;
        HashMap<String,String> headVo = new HashMap<>();
        headVo.put("x-rio-paasid",passid);
        headVo.put("x-rio-timestamp",timestamp+"");
        headVo.put("x-rio-nonce","mt");
        headVo.put("x-rio-signature", DigestUtils.sha256Hex(timestamp+secret+"mt"+timestamp));
        return headVo;
    }
 
    public R<List<GridCaseInfoDTO>> getCaseDataList(boolean isRepeat, GridCaseDataVo gridCaseDataVo) {
        HashMap<String,String> headVo = initHeadVo();
        log.info("xsd:{}", JSON.toJSONString(gridCaseDataVo));
        log.info("xsd:{}", gridUrl + "/standard/eventform/queryOrgTodoEventList");
        String s = null;
        try {
            if (SpringContextUtil.checkDev()) {
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/casedata/get-case-list" + JSON.toJSONString(gridCaseDataVo));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/casedata/get-case-list", JSON.toJSONString(gridCaseDataVo), headVo, "utf-8");
            } else {
                s = HttpClientUtils.httpPostRaw(gridUrl + "/standard/eventform/queryOrgTodoEventList", JSON.toJSONString(gridCaseDataVo),headVo, "utf-8");
            }
        } catch (Exception e) {
            log.info("xsderror:{}", e);
            throw new RuntimeException(e);
        }
        log.info("xsd:{}", s);
        JSONObject object = JSONObject.parseObject(s);
        List<GridCaseInfoDTO> gridCaseInfoDTOS = new ArrayList<>();
        if (object.getInteger("code") != null && object.getInteger("code") == 0) {
            JSONObject data1 = object.getJSONObject("data");
            if(data1!=null){
                int total = data1.getIntValue("total");
                if (total > gridCaseDataVo.getPageSize() && isRepeat) {
                    JSONArray data = data1.getJSONArray("records");
                    gridCaseInfoDTOS = data.toJavaList(GridCaseInfoDTO.class);
                    gridCaseDataVo.setPage(2);
                    gridCaseDataVo.setPageSize(total - gridCaseDataVo.getPageSize());
                    R<List<GridCaseInfoDTO>> caseDataList = getCaseDataList(false, gridCaseDataVo);
                    if (caseDataList != null) {
                        gridCaseInfoDTOS.addAll(caseDataList.getData());
                    }
                } else {
                    JSONArray data = data1.getJSONArray("records");
                    gridCaseInfoDTOS = data.toJavaList(GridCaseInfoDTO.class);
 
                }
            }
            return R.ok(gridCaseInfoDTOS);
        } else {
            return R.fail("获取非警务数据信息失败");
        }
    }
 
    public R<String> uploadCaseNodeInfo(GridApprovalRecordVo gridApprovalRecord) {
        HashMap<String,String> headVo = initHeadVo();
        log.info("xsd:{}", JSON.toJSONString(gridApprovalRecord));
        log.info("xsd:{}", gridUrl + "/standard/eventform/doApproveWithoutFlow");
        String s = null;
        try {
            if (SpringContextUtil.checkDev()) {
                //记录请求参数
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/casedata/upload-node-info" + JSON.toJSONString(gridApprovalRecord));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/casedata/upload-node-info", JSON.toJSONString(gridApprovalRecord), headVo, "utf-8");
            } else {
                //记录请求参数
                s = HttpClientUtils.httpPostRaw(gridUrl + "/standard/eventform/doApproveWithoutFlow", JSON.toJSONString(gridApprovalRecord), headVo, "utf-8");
            }
        } catch (Exception e) {
            log.info("xsderror:{}", e);
            throw new RuntimeException(e);
        }
        log.info("xsd:{}", s);
        JSONObject object = JSONObject.parseObject(s);
        if (object.getInteger("code") != null && object.getInteger("code") == 0) {
            return R.ok("上传节点信息成功");
        } else {
            return R.fail("上传节点信息失败,失败原因:", s);
        }
    }
 
    public R<GridFileUploadDTO> uploadFileInfo(GridFileUploadVo gridFileUploadVo) throws IOException {
        HashMap<String,String> headVo = initHeadVo();
        FtpUtils ftpUtil = new FtpUtils();
        InputStream inputStream = ftpUtil.retrieveFileStream(gridFileUploadVo.getFilePath());
        GridFileUploadRequestVo.FileUpload fileUpload = new GridFileUploadRequestVo.FileUpload();
        fileUpload.setFileData(FileUtils.convertToBase64(inputStream));
        fileUpload.setFileSize(gridFileUploadVo.getFileSize());
        fileUpload.setFileName(gridFileUploadVo.getFileName());
        fileUpload.setOriginalFileName(gridFileUploadVo.getFileName());
        fileUpload.setType(gridFileUploadVo.getType());
        log.info("xsd:{}", JSON.toJSONString(fileUpload));
        log.info("xsd上传文件:{}", gridUrl + "/standard/attachment/upload");
        String s = null;
        try {
            if (SpringContextUtil.checkDev()) {
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/casedata/upload-file" + JSON.toJSONString(gridFileUploadVo));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/casedata/upload-file", JSON.toJSONString(gridFileUploadVo), headVo, "utf-8");
            } else {
                s = HttpClientUtils.httpPostRaw(gridUrl + "/standard/attachment/uploadBase64", JSON.toJSONString(fileUpload), headVo, "utf-8");
            }
            log.info("xsd:{}", s);
            JSONObject object = JSONObject.parseObject(s);
            if (object.getInteger("code") != null && object.getInteger("code") == 0) {
                GridFileUploadDTO data = object.getObject("data", GridFileUploadDTO.class);
                return R.ok(data);
            } else {
                return R.fail(s);
            }
        } catch (Exception e) {
            log.info("xsderror:{}", e);
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
 
    }
 
    public R<JSONObject> getCaseDetail(GridCaseDataDetailVo gridCaseDataVo) {
        HashMap<String,String> headVo = initHeadVo();
        log.info("xsd:{}", JSON.toJSONString(gridCaseDataVo));
        log.info("xsd:{}", gridUrl + "/event/queryEventDetail");
        String s = null;
        try {
            if (SpringContextUtil.checkDev()) {
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/casedata/get-case-list" + JSON.toJSONString(gridCaseDataVo));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/casedata/get-case-list", JSON.toJSONString(gridCaseDataVo), headVo, "utf-8");
            } else {
                s = HttpClientUtils.httpPostRaw(gridUrl + "/event/queryEventDetail", JSON.toJSONString(gridCaseDataVo), headVo, "utf-8");
            }
        } catch (Exception e) {
            log.info("xsderror:{}", e);
            throw new RuntimeException(e);
        }
        log.info("xsd:{}", s);
        JSONObject object = JSONObject.parseObject(s);
        if (object.getInteger("code") != null && object.getInteger("code") == 0) {
            JSONObject data1 = object.getJSONObject("data");
            return R.ok(data1);
        } else {
            return R.fail("获取非警务数据信息失败");
        }
    }
 
    public R<String> cancelCase(GridCaseIdVo gridCaseIdVo) {
        if(StringUtils.isNotBlank(gridCaseIdVo.getUserId())){
            CtUserDTO ctUserDTO = custClient.clientGetUserAll(gridCaseIdVo.getUserId());
            if(ObjectUtils.isNotEmpty(ctUserDTO)){
                if(StringUtils.isNotBlank(ctUserDTO.getIdcard())){
                    GridUserIdNumberVo gridUserIdNumberVo = new GridUserIdNumberVo();
                    gridUserIdNumberVo.setIdNumber(ctUserDTO.getIdcard());
                    R<GridUserVo> result = gridUserService.getUserByIdNumber(gridUserIdNumberVo);
                    if(R.SUCCESS == result.getCode()){
                        gridCaseIdVo.setUserId(result.getData().getId());
                        log.info("当前环节审批用户为: "+ gridCaseIdVo.getUserId());
                    }else{
                        gridCaseIdVo.setUserId("a9406a88c8234cda82452799bf6bd6cd");
                        log.info("当前环节审批用户为特殊用户,身份证找不到用户{},{}",ctUserDTO.getIdcard(),ctUserDTO.getTrueName());
                    }
                }else {
                    gridCaseIdVo.setUserId("a9406a88c8234cda82452799bf6bd6cd");
                    log.info("当前环节审批用户为特殊用户,找不到用户{}",gridCaseIdVo.getUserId());
                }
            }else{
                gridCaseIdVo.setUserId("a9406a88c8234cda82452799bf6bd6cd");
                log.info("当前环节审批用户为特殊用户,找不到用户{}",gridCaseIdVo.getUserId());
            }
        }else{
            gridCaseIdVo.setUserId("a9406a88c8234cda82452799bf6bd6cd");
            log.info("当前环节审批用户为特殊用户");
        }
        List<String> ids = gridCaseIdVo.getIds();
        List<String> realIds = new ArrayList<>();
        for(String id:ids){
            GridEvent eventByCaseId = gridEventService.getEventByCaseId(id);
            if(eventByCaseId!=null){
                realIds.add(eventByCaseId.getId());
            }
        }
        gridCaseIdVo.setIds(realIds);
        HashMap<String,String> headVo = initHeadVo();
        log.info("xsd:{}", JSON.toJSONString(gridCaseIdVo));
        log.info("xsd:{}", gridUrl + "/event/cancelEvent");
        String s = null;
        try {
            if (SpringContextUtil.checkDev()) {
                //记录请求参数
                log.info("xsdurl:{}", testUrl + "/api/thrid/grid/casedata/cancel-case" + JSON.toJSONString(gridCaseIdVo));
                s = HttpClientUtils.httpPostRaw(testUrl + "/api/thrid/grid/casedata/cancel-case", JSON.toJSONString(gridCaseIdVo), headVo, "utf-8");
            } else {
                //记录请求参数
                s = HttpClientUtils.httpPostRaw(gridUrl + "/event/cancelEvent", JSON.toJSONString(gridCaseIdVo), headVo, "utf-8");
            }
        } catch (Exception e) {
            log.info("xsderror:{}", e);
            throw new RuntimeException(e);
        }
        log.info("xsd:{}", s);
        JSONObject object = JSONObject.parseObject(s);
        if (object.getInteger("code") != null && object.getInteger("code") == 0) {
            return R.ok("拒收成功");
        } else {
            return R.fail("拒收失败,失败原因:", s);
        }
    }
}