广州市综治平台后端
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
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.module.cases.domain.dto.RepeatCaseInfoDTO;
import cn.huge.module.cases.domain.po.*;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.cases.dao.mapper.CaseRepeatMapper;
import cn.huge.module.cust.dto.CtUserDTO;
import cn.huge.module.mediate.constant.CaseBaseConstsEnum;
import cn.huge.module.mediate.constant.CaseInfoProcessBaseConstsEnum;
import cn.huge.module.mediate.constant.CaseProcessBaseConstsEnum;
import cn.huge.module.mediate.constant.CaseStatusBaseConstsEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
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.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @title: dyh_case_repeat业务逻辑处理
 * @Description dyh_case_repeat业务逻辑处理
 * @company hugeinfo
 * @author liyj
 * @Time 2024-12-26 11:16:47
 * @version 1.0.0
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class CaseRepeatService extends ServiceImpl<CaseRepeatMapper, CaseRepeat>{
 
    @Autowired
    private CaseRepeatMapper mapper;
 
    @Autowired
    private UtilsClientImpl utilsClient;
    @Autowired
    private CaseInfoService caseInfoService;
    @Autowired
    private CaseInfoUnfoldService caseInfoUnfoldService;
    @Autowired
    private CasePersonService casePersonService;
    @Autowired
    private CaseAgentService caseAgentService;
 
    /**
    * 更新对象
    * @param entity 对象
    */
    public void updateCaseRepeat(CaseRepeat entity){
        try{
            mapper.updateCaseRepeat(entity);
        }catch (Exception e){
            log.error("[CaseRepeatService.updateCaseRepeat]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseRepeatService.updateCaseRepeat", e);
        }
    }
 
    /**
    * 条件更新对象
    * @param entity 对象
    * @param terms 条件
    */
    public void updateCaseRepeatTerms(CaseRepeat entity, Map<String, Object> terms){
        try{
            mapper.updateCaseRepeatTerms(entity, terms);
        }catch (Exception e){
            log.error("[CaseRepeatService.updateCaseRepeatTerms]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseRepeatService.updateCaseRepeatTerms", e);
        }
    }
 
    /**
    * 根据编号物理删除
    * @param id 查询条件集合
    */
    public void deleteCaseRepeat(String id){
        try{
            mapper.deleteCaseRepeat(id);
        }catch (Exception e){
            log.error("[CaseRepeatService.deleteCaseRepeat]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseRepeatService.deleteCaseRepeat", e);
        }
    }
 
    /**
    * 按条件查询
    * @param terms 条件
    * @return List
    */
    public List<CaseRepeat> 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<CaseRepeat> pageQuery(PageRequest page, Map<String, Object> terms){
        long total = mapper.countTerms(terms);
        List<CaseRepeat> content = mapper.pageTerms(page, terms);
        return new PageImpl<CaseRepeat>(content, page, total);
    }
 
    /**
    * 新增或更新对象
    * @param caseRepeat 实体对象
    */
    public void saveCaseRepeat(CaseRepeat caseRepeat){
        try{
            Date nowDate = DateUtils.getNowDate();
            // 判断是否新增
            if (IdUtils.checkNewId(caseRepeat.getId())){
                caseRepeat.setId(utilsClient.getNewTimeId());
                caseRepeat.setCreateTime(nowDate);
            }
            caseRepeat.setUpdateTime(nowDate);
            this.saveOrUpdate(caseRepeat);
        }catch (Exception e){
            log.error("[CaseRepeatService.saveCaseRepeat]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseRepeatService.saveCaseRepeat", e);
        }
    }
 
 
    /**
     * 创建重复记录
     * @param newCaseId 新案件编号
     * @param repeatCaseIdList 重复案件编号
     * @param loginUser 操作人
     */
    public void createRepeatCase(String newCaseId, List<String> repeatCaseIdList, CtUserDTO loginUser){
        try{
            // 查询主案件编号
            CaseInfo mainCaseInfo = null;
            if (repeatCaseIdList.size() == 1){
                mainCaseInfo = caseInfoService.getById(repeatCaseIdList.get(0));
            }else {
                QueryWrapper<CaseInfo> caseInfoQueryWrapper = new QueryWrapper<>();
                caseInfoQueryWrapper.select("id", "status", "status_name", "process", "process_name", "info_process", "info_process_name")
                        .in("id", repeatCaseIdList).orderByAsc("create_time");
                List<CaseInfo> caseInfoList = caseInfoService.list(caseInfoQueryWrapper);
                mainCaseInfo = caseInfoList.get(0);
            }
            // 创建重复记录
            CaseRepeat caseRepeat = new CaseRepeat();
            caseRepeat.setId(utilsClient.getNewTimeId());
            caseRepeat.setCaseId(newCaseId);
            caseRepeat.setCaseMainId(mainCaseInfo.getId());
            caseRepeat.setOperUserId(loginUser.getId());
            caseRepeat.setOperUserName(loginUser.getTrueName());
            caseRepeat.setCreateTime(DateUtils.getNowDate());
            caseRepeat.setUpdateTime(DateUtils.getNowDate());
            this.save(caseRepeat);
 
            // 更新新案件状态-与主案件状态一致
//            CaseInfo caseInfoPO = new CaseInfo();
//            caseInfoPO.setId(newCaseId);
//            caseInfoPO.setStatus(mainCaseInfo.getStatus());
//            caseInfoPO.setStatusName(mainCaseInfo.getStatusName());
//            caseInfoPO.setProcess(mainCaseInfo.getProcess());
//            caseInfoPO.setProcessName(mainCaseInfo.getProcessName());
//            caseInfoPO.setInfoProcess(mainCaseInfo.getInfoProcess());
//            caseInfoPO.setInfoProcessName(mainCaseInfo.getInfoProcessName());
//            caseInfoService.updateCaseInfo(caseInfoPO);
        }catch (Exception e){
            log.error("[CaseRepeatService.saveCaseRepeat]调用失败,异常信息:"+e, e);
            throw new ServiceException("CaseRepeatService.saveCaseRepeat", e);
        }
    }
 
    /**
     * 查询重复事项
     * @param caseId
     * @return
     */
    public List<RepeatCaseInfoDTO> listRepeatCase(String caseId){
        List<String> cseIdList = new ArrayList<>();
        QueryWrapper<CaseRepeat> caseRepeatQueryWrapper = new QueryWrapper<>();
        caseRepeatQueryWrapper.eq("case_main_id", caseId);
        List<CaseRepeat> caseRepeatList = mapper.selectList(caseRepeatQueryWrapper);
        // 判断是否是主案件
        if (CollectionUtils.isNotEmpty(caseRepeatList)){
            // 是主案件,获取重复案件编号
            for (CaseRepeat caseRepeat : caseRepeatList){
                cseIdList.add(caseRepeat.getCaseId());
            }
        }
        // 查询非主案件的重复案件,先查询主案件
        caseRepeatQueryWrapper.clear();
        caseRepeatQueryWrapper.select("case_main_id").eq("case_id", caseId).groupBy("case_main_id");
        List<CaseRepeat> mainCaseRepeatList = mapper.selectList(caseRepeatQueryWrapper);
        if (CollectionUtils.isNotEmpty(mainCaseRepeatList)) {
            caseRepeatList = new ArrayList<>();
            for (CaseRepeat mainCaseRepeat : mainCaseRepeatList) {
                // 获取主案件编号
                cseIdList.add(mainCaseRepeat.getCaseMainId());
                // 查询主案件的重复案件
                caseRepeatQueryWrapper.clear();
                caseRepeatQueryWrapper.eq("case_main_id", mainCaseRepeat.getCaseMainId());
                List<CaseRepeat> caseRepeats = mapper.selectList(caseRepeatQueryWrapper);
                caseRepeatList.addAll(caseRepeats);
            }
            // 过滤自己的重复案件
            for (CaseRepeat caseRepeat : caseRepeatList){
                // 获取其他重复案件
                if (!caseId.equals(caseRepeat.getCaseId())) {
                    cseIdList.add(caseRepeat.getCaseId());
                }
            }
        }
        // 封装重复案件信息
        List<RepeatCaseInfoDTO> repeatCaseInfoDTOList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(cseIdList)) {
            QueryWrapper<CaseInfo> caseInfoQueryWrapper = new QueryWrapper<>();
            caseInfoQueryWrapper.in("id", cseIdList);
            List<CaseInfo> caseInfoList = caseInfoService.list(caseInfoQueryWrapper);
            if (CollectionUtils.isNotEmpty(caseInfoList)) {
                for (CaseInfo caseInfo : caseInfoList) {
                    RepeatCaseInfoDTO repeatCaseInfoDTO = new RepeatCaseInfoDTO();
                    BeanUtils.copyProperties(caseInfo, repeatCaseInfoDTO);
                    repeatCaseInfoDTO.setDataSource(CaseBaseConstsEnum.getDataSourceByCanal(caseInfo.getCanal()).getIndex());
                    repeatCaseInfoDTO.setDataSourceName(CaseBaseConstsEnum.getDataSourceByCanal(caseInfo.getCanal()).getDes());
                    // 查询申请方、被申请方当事人信息
                    QueryWrapper<CasePerson> casePersonQueryWrapper = new QueryWrapper<>();
                    casePersonQueryWrapper.select("id", "per_type", "true_name", "orga_code", "certi_no").eq("case_id", caseInfo.getId());
                    List<CasePerson> casePersonList = casePersonService.list(casePersonQueryWrapper);
                    List<Object> plaintiffs = new ArrayList<>();
                    List<Object> defendants = new ArrayList<>();
                    for (CasePerson casePerson : casePersonList) {
                        if (CaseBaseConstsEnum.PERSON_TYPE_1.getIndex().equals(casePerson.getPerType())) {
                            plaintiffs.add(casePerson);
                            // 查询代理人信息
                            QueryWrapper<CaseAgent> caseAgentQueryWrapper = new QueryWrapper<>();
                            caseAgentQueryWrapper.select("id", "per_type", "true_name", "certi_no").like("person_id", casePerson.getId());
                            List<CaseAgent> caseAgentList = caseAgentService.list(caseAgentQueryWrapper);
                            if (CollectionUtils.isNotEmpty(caseAgentList)) {
                                for (CaseAgent caseAgent : caseAgentList) {
                                    plaintiffs.add(caseAgent);
                                }
                            }
 
                        } else if (CaseBaseConstsEnum.PERSON_TYPE_2.getIndex().equals(casePerson.getPerType())) {
                            defendants.add(casePerson);
                            // 查询代理人信息
                            QueryWrapper<CaseAgent> caseAgentQueryWrapper = new QueryWrapper<>();
                            caseAgentQueryWrapper.select("id", "per_type", "true_name", "certi_no").like("person_id", casePerson.getId());
                            List<CaseAgent> caseAgentList = caseAgentService.list(caseAgentQueryWrapper);
                            if (CollectionUtils.isNotEmpty(caseAgentList)) {
                                for (CaseAgent caseAgent : caseAgentList) {
                                    defendants.add(caseAgent);
                                }
                            }
                        }
                    }
                    repeatCaseInfoDTO.setPlaintiffs(plaintiffs);
                    repeatCaseInfoDTO.setDefendants(defendants);
                    // 查询承办/配合部门、经办人
                    CaseInfoUnfold caseInfoUnfold = caseInfoUnfoldService.getById(caseInfo.getId());
                    repeatCaseInfoDTO.setMediator(caseInfoUnfold.getMediator());
                    repeatCaseInfoDTO.setMediateUnitName(caseInfoUnfold.getMediateUnitName());
                    repeatCaseInfoDTO.setAssistUnitName(caseInfoUnfold.getAssistUnitName());
                    repeatCaseInfoDTOList.add(repeatCaseInfoDTO);
                }
            }
        }
        return repeatCaseInfoDTOList;
    }
 
    /**
     * 判断是否有重复案件
     * @param caseId
     * @return
     */
    public boolean checkRepeatCase(String caseId){
        List<String> cseIdList = new ArrayList<>();
        QueryWrapper<CaseRepeat> caseRepeatQueryWrapper = new QueryWrapper<>();
        caseRepeatQueryWrapper.eq("case_main_id", caseId).or().eq("case_id", caseId);
        int repeatCaseCount = mapper.selectCount(caseRepeatQueryWrapper);
        if (repeatCaseCount > 0){
            return true;
        }else {
            return false;
        }
    }
 
}