广州市综治平台后端
xusd
yesterday e9de6064cc94d6bc63685c5e62046ff810b96dab
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package cn.huge.module.grid.service;
 
import cn.huge.base.common.bo.R;
import cn.huge.base.common.exception.ServiceException;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.HttpClientUtils;
import cn.huge.base.common.utils.IdUtils;
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.module.client.api.impl.CustClientImpl;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.cust.dto.CtUserDTO;
import cn.huge.module.file.domain.po.FileInfo;
import cn.huge.module.file.service.FileInfoService;
import cn.huge.module.grid.dao.mapper.GridEventMapper;
import cn.huge.module.grid.domain.dto.GridFileUploadDTO;
import cn.huge.module.grid.domain.dto.GridOrgDTO;
import cn.huge.module.grid.domain.po.GridEvent;
import cn.huge.module.grid.domain.vo.*;
import cn.huge.module.sys.dto.FileInfoBaseDTO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
 
/**
 * @author wangwh
 * @version 1.0.0
 * @title: dyh_th_grid_event业务逻辑处理
 * @Description dyh_th_grid_event业务逻辑处理
 * @company hugeinfo
 * @Time 2025-02-21 17:42:19
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class GridEventService extends ServiceImpl<GridEventMapper, GridEvent> {
 
    @Autowired
    private GridEventMapper mapper;
 
    @Autowired
    private UtilsClientImpl utilsClient;
 
    @Autowired
    private GridCaseTaskService gridCaseTaskService;
 
    @Autowired
    private GridCaseDataService gridCaseDataService;
 
    @Autowired
    private GridUserService gridUserService;
 
    @Autowired
    private CustClientImpl custClient;
 
    @Autowired
    private FileInfoService fileInfoService;
 
    @Value("${grid.url:http://219.137.166.84:8061}")
    private String gridUrl;
    @Value("${grid.username:mtxt0011}")
    private String userName;
    @Value("${grid.password}")
    private String passWord;
    @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;
    }
 
 
    /**
     * 更新对象
     *
     * @param entity 对象
     */
    public void updateGridEvent(GridEvent entity) {
        try {
            mapper.updateGridEvent(entity);
        } catch (Exception e) {
            log.error("[GridEventService.updateGridEvent]调用失败,异常信息:" + e, e);
            throw new ServiceException("GridEventService.updateGridEvent", e);
        }
    }
 
    /**
     * 条件更新对象
     *
     * @param entity 对象
     * @param terms  条件
     */
    public void updateGridEventTerms(GridEvent entity, Map<String, Object> terms) {
        try {
            mapper.updateGridEventTerms(entity, terms);
        } catch (Exception e) {
            log.error("[GridEventService.updateGridEventTerms]调用失败,异常信息:" + e, e);
            throw new ServiceException("GridEventService.updateGridEventTerms", e);
        }
    }
 
    /**
     * 根据编号物理删除
     *
     * @param id 查询条件集合
     */
    public void deleteGridEvent(String id) {
        try {
            mapper.deleteGridEvent(id);
        } catch (Exception e) {
            log.error("[GridEventService.deleteGridEvent]调用失败,异常信息:" + e, e);
            throw new ServiceException("GridEventService.deleteGridEvent", e);
        }
    }
 
    /**
     * 按条件查询
     *
     * @param terms 条件
     * @return List
     */
    public List<GridEvent> listTerms(Map<String, Object> terms) {
        return mapper.listTerms(terms);
    }
 
    /**
     * 按条件统计
     *
     * @param terms 条件
     * @return long
     */
    public long countTerms(Map<String, Object> terms) {
        return mapper.countTerms(terms);
    }
 
    /**
     * 按条件分页查询
     *
     * @param page  分页对象
     * @param terms 条件
     * @return Page
     */
    public Page<GridEvent> pageQuery(PageRequest page, Map<String, Object> terms) {
        long total = mapper.countTerms(terms);
        List<GridEvent> content = mapper.pageTerms(page, terms);
        return new PageImpl<GridEvent>(content, page, total);
    }
 
    /**
     * 新增或更新对象
     *
     * @param gridEvent 实体对象
     */
    public void saveGridEvent(GridEvent gridEvent) {
        try {
            Date nowDate = DateUtils.getNowDate();
            // 判断是否新增
            if (IdUtils.checkNewId(gridEvent.getId())) {
                gridEvent.setId(utilsClient.getNewTimeId());
                gridEvent.setCreateTime(nowDate);
            }
            gridEvent.setUpdateTime(nowDate);
            this.saveOrUpdate(gridEvent);
        } catch (Exception e) {
            log.error("[GridEventService.saveGridEvent]调用失败,异常信息:" + e, e);
            throw new ServiceException("GridEventService.saveGridEvent", e);
        }
    }
 
    public GridEvent getEventByCaseId(String caseId) {
        return mapper.getEventByCaseId(caseId);
    }
 
    /**
     * 同步矛纠工单的办理反馈信息
     *
     * @param saveEventFeedBackVo
     * @return
     */
    public R<Object> saveEventFeedback(SaveEventFeedBackVo saveEventFeedBackVo) {
        HashMap<String,String> headVo=  initHeadVo();
        try{
            //  传递过来的是子平台的id,需要转换为大平台的id
            String appOrgId = saveEventFeedBackVo.getAppOrgId();
 
            String appGridUnitId = null;
            if (StringUtils.isNotBlank(appOrgId)) {
                appGridUnitId = gridCaseTaskService.getGridUnitIdByUnitId(saveEventFeedBackVo.getAppOrgId());
                saveEventFeedBackVo.setAppOrgId(appGridUnitId);
                if (StringUtils.isBlank(appGridUnitId)) {
                    throw new Exception("矛纠工单的办理反馈信息的组织不存在");
                }
            }
//        else {
//            saveEventFeedBackVo.setAppOrgId(gridEvent.getSysOrgId());
//            saveEventFeedBackVo.setAppOrgName(gridEvent.getSysOrgName());
//        }
            log.info("当前环节组织:" + saveEventFeedBackVo.getAppOrgId());
 
            if (StringUtils.isNotBlank(saveEventFeedBackVo.getAppUserId())) {
                CtUserDTO ctUserDTO = custClient.clientGetUserAll(saveEventFeedBackVo.getAppUserId());
                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()) {
                            saveEventFeedBackVo.setAppUserId(result.getData().getId());
                            log.info("当前环节审批用户为: " + saveEventFeedBackVo.getAppUserId());
                        } else {
                            saveEventFeedBackVo.setAppUserId("a9406a88c8234cda82452799bf6bd6cd");
                            log.info("当前环节审批用户为特殊用户,身份证找不到用户{},{}", ctUserDTO.getIdcard(), ctUserDTO.getTrueName());
                        }
                    } else {
                        saveEventFeedBackVo.setAppUserId("a9406a88c8234cda82452799bf6bd6cd");
                        log.info("当前环节审批用户为特殊用户,找不到用户{}", saveEventFeedBackVo.getAppUserId());
                    }
                } else {
                    saveEventFeedBackVo.setAppUserId("a9406a88c8234cda82452799bf6bd6cd");
                    log.info("当前环节审批用户为特殊用户,找不到用户{}", saveEventFeedBackVo.getAppUserId());
                }
            } else {
                saveEventFeedBackVo.setAppUserId("a9406a88c8234cda82452799bf6bd6cd");
                log.info("矛纠工单的办理反馈信息的用户为特殊用户");
            }
 
            //  判断附件不为空
            List<FileInfoBaseDTO> fileInfoList = saveEventFeedBackVo.getFileInfoList();
            if (!CollectionUtils.isEmpty(fileInfoList)){
                List<GridFileRelatedVo> feedbackAttrInfos = new ArrayList<>();
                log.info("获取到矛纠工单的办理反馈信息的附件上传:" + fileInfoList.size());
                for (FileInfoBaseDTO fileInfoBaseDTO : fileInfoList) {
                    try {
                        GridFileUploadVo gridFileUploadVo = new GridFileUploadVo();
                        //  通过id获取文件信息
                        FileInfo fileInfo = fileInfoService.getById(fileInfoBaseDTO.getId());
 
                        gridFileUploadVo.setFileName(fileInfo.getFileName());
                        gridFileUploadVo.setFilePath(fileInfo.getFullPath());
                        gridFileUploadVo.setFileSize(fileInfo.getSize() != null ? fileInfo.getSize().longValue() : 0L);
                        gridFileUploadVo.setType(fileInfo.getSuffix());
                        R<GridFileUploadDTO> result = null;
                        //上传附件信息
                        result = gridCaseDataService.uploadFileInfo(gridFileUploadVo);
                        if (R.SUCCESS == result.getCode()) {
                            //获取上传结果,组成新的附件对象
                            GridFileUploadDTO gridFileUploadDTO = result.getData();
                            GridFileRelatedVo gridFileRelatedVo = new GridFileRelatedVo();
                            gridFileRelatedVo.setFileName(gridFileUploadDTO.getFileName());
                            gridFileRelatedVo.setFilePath(gridFileUploadDTO.getFilePath());
                            gridFileRelatedVo.setOriginalFileName(gridFileUploadDTO.getOriginalFileName());
                            gridFileRelatedVo.setFileSize(gridFileUploadDTO.getFileSize());
                            gridFileRelatedVo.setType("add");
                            gridFileRelatedVo.setFileType(gridFileUploadDTO.getFileType());
                            feedbackAttrInfos.add(gridFileRelatedVo);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        log.info("附件上传失败:" + fileInfoBaseDTO.getId());
                    }
                }
 
                //  上传完成后设置原附件列表为空
                saveEventFeedBackVo.setFileInfoList(null);
            }
 
 
            //  发起请求
            log.info("办理反馈信息-xsd:{}", JSON.toJSONString(saveEventFeedBackVo));
            log.info("办理反馈信息-xsd:{}", gridUrl + "/standard/eventform/saveFeedback");
            String s = null;
            try {
                s = HttpClientUtils.httpPostRaw(gridUrl + "/standard/eventform/saveFeedback", JSON.toJSONString(saveEventFeedBackVo), 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) {
                log.info("同步矛纠工单的办理反馈信息成功!");
                Object data = object.get("data");
                return R.ok(data);
            } else {
                log.info("同步矛纠工单的办理反馈信息失败,错误原因:" + object.getString("message"));
                return R.fail("同步矛纠工单的办理反馈信息失败");
            }
        }catch (Exception e){
            log.error("同步矛纠工单的办理反馈信息报错",e);
        }
        return R.fail("同步矛纠工单的办理反馈信息失败");
 
    }
}