广州市综治平台后端
xusd
1 days ago 3feed5879e5a9b794862bf46d38c7f66cfe41d50
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
package cn.huge.module.cases.service;
 
import cn.huge.base.common.exception.ServiceException;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.IdUtils;
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.module.cases.domain.dto.FileRelateDTO;
import cn.huge.module.cases.domain.dto.FrontPageListDTO;
import cn.huge.module.cases.domain.dto.QuiltUnitDTO;
import cn.huge.module.cases.domain.po.CaseInfo;
import cn.huge.module.cases.domain.po.CaseInfoUnfold;
import cn.huge.module.cases.utils.TaskUsetimeUtils;
import cn.huge.module.client.api.impl.CustClientImpl;
import cn.huge.module.client.api.impl.SysClientImpl;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.cases.dao.mapper.CaseSuperviseMapper;
import cn.huge.module.cases.domain.po.CaseSupervise;
import cn.huge.module.cust.dto.CtUserDTO;
import cn.huge.module.sy.service.SyHolidayService;
import cn.huge.module.sys.constant.FileOwnerTypeBaseEnum;
import cn.huge.module.sys.constant.SyTimeEnum;
import cn.huge.module.sys.dto.FileIdInfoBaseDTO;
import cn.huge.module.sys.dto.FileIdTypeInfoBaseDTO;
import cn.huge.module.sys.dto.FileInfoBaseDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.annotation.PostConstruct;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @title: 纠纷督办信息表业务逻辑处理
 * @Description 纠纷督办信息表业务逻辑处理
 * @company hugeinfo
 * @author wangwh
 * @Time 2024-09-03 10:53:01
 * @version 1.0.0
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class CaseSuperviseService extends ServiceImpl<CaseSuperviseMapper, CaseSupervise>{
 
    @Autowired
    private CaseSuperviseMapper mapper;
 
    @Autowired
    private UtilsClientImpl utilsClient;
 
    @Autowired
    private CustClientImpl custClient;
 
    @Autowired
    private SysClientImpl sysClient;
 
    @Autowired
    private CaseInfoService caseInfoService;
 
    @Autowired
    private SyHolidayService syHolidayService;
 
    /**
    * 条件更新对象
    * @param entity 对象
    * @param terms 条件
    */
    public void updateCaseSuperviseTerms(CaseSupervise entity, Map<String, Object> terms){
        try{
            mapper.updateCaseSuperviseTerms(entity, terms);
        }catch (Exception e){
            log.error("[CaseSuperviseService.updateCaseSuperviseTerms]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.updateCaseSuperviseTerms", e);
        }
    }
 
    /**
    * 根据编号物理删除
    * @param id 查询条件集合
    */
    public void deleteCaseSupervise(String id){
        try{
            mapper.deleteCaseSupervise(id);
        }catch (Exception e){
            log.error("[CaseSuperviseService.deleteCaseSupervise]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.deleteCaseSupervise", e);
        }
    }
 
    /**
    * 按条件查询
    * @param terms 条件
    * @return List
    */
    public List<CaseSupervise> 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<CaseSupervise> pageQuery(PageRequest page, Map<String, Object> terms){
        long total = mapper.countTerms(terms);
        List<CaseSupervise> content = mapper.pageTerms(page, terms);
        return new PageImpl<CaseSupervise>(content, page, total);
    }
 
    /**
    * 新增或更新对象
    * @param caseSupervise 实体对象
    */
    public void saveCaseSupervise(CaseSupervise caseSupervise){
        try{
            Date nowDate = DateUtils.getNowDate();
            // 判断是否新增
            if (IdUtils.checkNewId(caseSupervise.getId())){
                caseSupervise.setId(utilsClient.getNewTimeId());
                caseSupervise.setCreateTime(nowDate);
            }
            caseSupervise.setUpdateTime(nowDate);
            this.saveOrUpdate(caseSupervise);
        }catch (Exception e){
            log.error("[CaseSuperviseService.saveCaseSupervise]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.saveCaseSupervise", e);
        }
    }
 
    /**
     * 添加督办
     * @param caseSupervise 实体对象
     */
    public void addCaseSupervise(CaseSupervise caseSupervise, String userId){
        try{
            List<QuiltUnitDTO> quiltUnitDTOList = caseSupervise.getQuiltUnitDTOList();
            Integer timeTerm = sysClient.getTimeLimitHour(SyTimeEnum.SY_TIME_5.getIndex());
            List<CaseSupervise> caseSuperviseList = new ArrayList<>();
            List<FileRelateDTO> fileRelateDTOList = sysClient.listFileRelateByOwnerId(caseSupervise.getId());
            int count = 0;
            List<FileRelateDTO> fileRelateDTOListNew = new ArrayList<>();
            for(QuiltUnitDTO quiltUnitDTO: quiltUnitDTOList){
                CaseSupervise caseSuperviseNew = new CaseSupervise();
                BeanUtils.copyProperties(caseSupervise, caseSuperviseNew);
                // 获取当前登录用户
                CtUserDTO loginUser = custClient.clientGetUserAll(userId);
                Date nowDate = DateUtils.getNowDate();
                caseSuperviseNew.setSupUserId(loginUser.getId());
                caseSuperviseNew.setSupUserName(loginUser.getTrueName());
                caseSuperviseNew.setSupUnitId(loginUser.getUnitId());
                caseSuperviseNew.setSupUnitName(loginUser.getUnitName());
                caseSuperviseNew.setSupTime(nowDate);
                caseSuperviseNew.setQuiltUnitId(quiltUnitDTO.getQuiltUnitId());
                caseSuperviseNew.setQuiltUnitName(quiltUnitDTO.getQuiltUnitName());
                caseSuperviseNew.setSupStatus(0);
                caseSuperviseNew.setCreateTime(nowDate);
                caseSuperviseNew.setUpdateTime(nowDate);
                caseSuperviseNew.setReplyTerm(timeTerm);
                //给每条督办添加附件信息
                if(0 != count){
                    String caseSupId = utilsClient.getNewTimeId();
                    caseSuperviseNew.setId(caseSupId);
                    for(FileRelateDTO fileRelateDTO: fileRelateDTOList){
                        String fileRealateId = utilsClient.getNewTimeSysId();
                        FileRelateDTO fileRelateDTONew = new FileRelateDTO();
                        BeanUtils.copyProperties(fileRelateDTO, fileRelateDTONew);
                        fileRelateDTONew.setOwnerId(caseSuperviseNew.getId());
                        fileRelateDTONew.setId(fileRealateId);
                        fileRelateDTOListNew.add(fileRelateDTONew);
                    }
                }
                caseSuperviseList.add(caseSuperviseNew);
                count++;
            }
            this.saveBatch(caseSuperviseList);
            if(CollectionUtils.isNotEmpty(fileRelateDTOListNew)){
                sysClient.saveFileRelateList(fileRelateDTOListNew);
            }
        }catch (Exception e){
            log.error("[CaseSuperviseService.saveCaseSupervise]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.saveCaseSupervise", e);
        }
    }
 
    /**
     * 批量添加督办
     * @param caseSuperviseList
     */
    public void addBatchCaseSupervise(List<CaseSupervise> caseSuperviseList, String userId){
        try{
            List<CaseSupervise> caseSuperviseListNew = new ArrayList<>();
            List<FileRelateDTO> fileRelateDTOListNew = new ArrayList<>();
            //查询附件
            List<FileRelateDTO> fileRelateDTOList = sysClient.listFileRelateByOwnerId(caseSuperviseList.get(0).getId());
            // 获取当前登录用户
            CtUserDTO loginUser = custClient.clientGetUserAll(userId);
            //查询任务时限
            Integer timeTerm = sysClient.getTimeLimitHour(SyTimeEnum.SY_TIME_5.getIndex());
            for(CaseSupervise caseSupervise: caseSuperviseList){
                List<QuiltUnitDTO> quiltUnitDTOList = caseSupervise.getQuiltUnitDTOList();
                int count = 0;
 
                for(QuiltUnitDTO quiltUnitDTO: quiltUnitDTOList){
                    CaseSupervise caseSuperviseNew = new CaseSupervise();
                    BeanUtils.copyProperties(caseSupervise, caseSuperviseNew);
                    Date nowDate = DateUtils.getNowDate();
                    caseSuperviseNew.setSupUserId(loginUser.getId());
                    caseSuperviseNew.setSupUserName(loginUser.getTrueName());
                    caseSuperviseNew.setSupUnitId(loginUser.getUnitId());
                    caseSuperviseNew.setSupUnitName(loginUser.getUnitName());
                    caseSuperviseNew.setSupTime(nowDate);
                    caseSuperviseNew.setQuiltUnitId(quiltUnitDTO.getQuiltUnitId());
                    caseSuperviseNew.setQuiltUnitName(quiltUnitDTO.getQuiltUnitName());
                    caseSuperviseNew.setSupStatus(0);
                    caseSuperviseNew.setCreateTime(nowDate);
                    caseSuperviseNew.setUpdateTime(nowDate);
                    caseSuperviseNew.setReplyTerm(timeTerm);
                    //给每条督办添加附件信息
                    if(0 != count){
                        String caseSupId = utilsClient.getNewTimeId();
                        caseSuperviseNew.setId(caseSupId);
                        for(FileRelateDTO fileRelateDTO: fileRelateDTOList){
                            String fileRealateId = utilsClient.getNewTimeSysId();
                            FileRelateDTO fileRelateDTONew = new FileRelateDTO();
                            BeanUtils.copyProperties(fileRelateDTO, fileRelateDTONew);
                            fileRelateDTONew.setOwnerId(caseSuperviseNew.getId());
                            fileRelateDTONew.setId(fileRealateId);
                            fileRelateDTOListNew.add(fileRelateDTONew);
                        }
                    }
                    caseSuperviseListNew.add(caseSuperviseNew);
                    count++;
                }
            }
 
            this.saveBatch(caseSuperviseListNew);
            if(CollectionUtils.isNotEmpty(fileRelateDTOListNew)){
                sysClient.saveFileRelateList(fileRelateDTOListNew);
            }
        }catch (Exception e){
            log.error("[CaseSuperviseService.saveCaseSupervise]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.saveCaseSupervise", e);
        }
    }
 
    /**
     * 回复督办
     * @param caseSupervise 对象
     */
    public void replyCaseSupervise(CaseSupervise caseSupervise, String userId){
        try{
            CaseSupervise caseSupervisePO = mapper.selectById(caseSupervise.getId());
            // 获取当前登录用户
            CtUserDTO loginUser = custClient.clientGetUserAll(userId);
            Date now = DateUtils.getNowDate();
            caseSupervise.setSupStatus(1);
            caseSupervise.setReplyUserId(loginUser.getId());
            caseSupervise.setReplyUserName(loginUser.getTrueName());
            caseSupervise.setReplyTime(now);
            caseSupervise.setUpdateTime(now);
            caseSupervise.setUsetimeHour(TaskUsetimeUtils.getUsetimeHour(caseSupervise.getReplyTime(), caseSupervisePO.getSupTime()));
            caseSupervise.setOvertimeStatus(TaskUsetimeUtils.getOvertimeStatus(caseSupervise.getReplyTime(), syHolidayService.getExpiryHour(caseSupervisePO.getSupTime(), caseSupervisePO.getReplyTerm())));
            caseSupervise.setOvertimeHour(TaskUsetimeUtils.getOvertimeHour(caseSupervise.getReplyTime(), syHolidayService.getExpiryHour(caseSupervisePO.getSupTime(), caseSupervisePO.getReplyTerm())));
            mapper.updateCaseSupervise(caseSupervise);
        }catch (Exception e){
            log.error("[CaseSuperviseService.replyCaseSupervise]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.replyCaseSupervise", e);
        }
    }
 
    /**
     * 流转办理-督办列表
     * @param caseId 事项Id
     */
    public Page<CaseSupervise> pageCaseSupervise(String caseId, PageRequest page, int supStatus, String userId, int type){
        try{
            CtUserDTO loginUser = custClient.clientGetUserAll(userId);
            String quiltUnitId = loginUser.getUnitId();
            Map<String, Object> terms = new HashMap<>();
            terms.put("caseId", caseId);
            terms.put("type", type);
            if(1 == type){
                terms.put("supStatus", supStatus);
                terms.put("quiltUnitId", quiltUnitId);
            }else if(2 == type){
                terms.put("supStatus", supStatus);
            }
            long countSuperviseList = mapper.countCaseSupervise(terms);
            List<CaseSupervise> caseSuperviseList = mapper.pageCaseSupervise(terms, page);
            CaseInfo caseInfo = new CaseInfo();
            if(CollectionUtils.isNotEmpty(caseSuperviseList)){
                if(1 != type){
 
                    QueryWrapper<CaseInfo>caseInfoQueryWrapper = new QueryWrapper<>();
                    caseInfoQueryWrapper.eq("id", caseId);
                    caseInfo = caseInfoService.getOne(caseInfoQueryWrapper);
                    for(CaseSupervise caseSupervise: caseSuperviseList){
                        if(ObjectUtils.isNotEmpty(caseSupervise.getSupTime()) && ObjectUtils.isNotEmpty(caseSupervise.getReplyTerm())){
                            caseSupervise.setTimeLimit(syHolidayService.getExpiryHour(caseSupervise.getSupTime(), caseSupervise.getReplyTerm()));
                        }
                        if(ObjectUtils.isNotEmpty(caseInfo)){
                            caseSupervise.setCaseGrade(caseInfo.getCaseLevel());
                        }
                    }
                }else{
                    Map<String, Object>map = new HashMap<>();
                    map.put("mainId", caseId);
                    map.put("ownerIds", "'" + caseSuperviseList.stream().map(CaseSupervise::getId).collect(Collectors.joining("','"))+ "'");
                    map.put("types", "'"+ FileOwnerTypeBaseEnum.OWNER_TYPE_506.getIndex()+ "','" +FileOwnerTypeBaseEnum.OWNER_TYPE_507.getIndex()+"'");
                    List<FileIdTypeInfoBaseDTO> fileIdTypeInfoBaseDTOList = sysClient.listIdTypeInfoByOwnerIdList(map);
                    for(CaseSupervise caseSupervise: caseSuperviseList){
                        for(FileIdTypeInfoBaseDTO fileIdTypeInfoBaseDTO: fileIdTypeInfoBaseDTOList){
                            if(caseSupervise.getId().equals(fileIdTypeInfoBaseDTO.getOwnerId())){
                                caseSupervise.setFileInfoList(fileIdTypeInfoBaseDTO.getFileList());
                            }
                        }
                    }
                }
            }
            return new PageImpl<CaseSupervise>(caseSuperviseList, page, countSuperviseList);
        }catch (Exception e){
            log.error("[CaseSuperviseService.pageReplied]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.pageReplied", e);
        }
    }
 
    /**
     * 首页-督办
     * @param page
     * @param terms
     */
    public Page<FrontPageListDTO> pageMyTaskDb(PageRequest page, Map<String, Object> terms){
        try{
            long countSuperviseList = mapper.countMyTaskDb(terms);
            List<FrontPageListDTO> caseSuperviseList = mapper.pageMyTaskDb(page, terms);
            return new PageImpl<FrontPageListDTO>(caseSuperviseList, page, countSuperviseList);
        }catch (Exception e){
            log.error("[CaseSuperviseService.pageReplied]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.pageReplied", e);
        }
    }
 
    /**
     * 查询督办数量
     * @param supStatus 回复状态
     * @param quiltUnitId 被督办组织编号
     * @return long
     */
    public long countCaseSuperviseList(Integer supStatus, String quiltUnitId){
        return mapper.countCaseSuperviseList(supStatus, quiltUnitId);
    }
 
    /**
     * 根据督办编号查询督办信息
     * @param id 督办编号
     * @return List
     */
    public CaseSupervise getById(String id){
        try {
            CaseSupervise caseSupervise = mapper.selectById(id);
            Map<String, Object> terms = new HashMap<>();
            terms.put("mainId", caseSupervise.getCaseId());
            terms.put("ownerIds", "'" + id + "'");
            List<FileIdTypeInfoBaseDTO> fileIdTypeInfoBaseDTOList = sysClient.listIdTypeInfoByOwnerIdList(terms);
            if(CollectionUtils.isNotEmpty(fileIdTypeInfoBaseDTOList)){
                caseSupervise.setFileInfoList(fileIdTypeInfoBaseDTOList.get(0).getFileList());
            }
            return caseSupervise;
        }catch (Exception e){
            log.error("[CaseSuperviseService.getById]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseSuperviseService.getById", e);
        }
 
    }
}