广州市综治平台后端
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
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
package cn.huge.module.knowledge.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.client.api.impl.UtilsClientImpl;
import cn.huge.module.knowledge.dao.mapper.DyhCaseInfoMapper;
import cn.huge.module.knowledge.domain.dto.CaseYearCountDTO;
import cn.huge.module.knowledge.domain.dto.CategoryCountDTO;
import cn.huge.module.knowledge.domain.dto.DictionaryDTO;
import cn.huge.module.knowledge.domain.dto.DyhCaseInfoDTO;
import cn.huge.module.knowledge.domain.dto.DyhCaseDetailDTO;
import cn.huge.module.knowledge.domain.po.DyhCaseInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.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;
import java.util.HashMap;
 
/**
 * @title: 调解案件信息表业务逻辑处理
 * @Description 调解案件信息表业务逻辑处理
 * @company hugeinfo
 * @author huangh
 * @Time 2024-12-20 10:02:00
 * @version 1.0.0
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class DyhCaseInfoService extends ServiceImpl<DyhCaseInfoMapper, DyhCaseInfo>{
 
    @Autowired
    private DyhCaseInfoMapper mapper;
 
    @Autowired
    private UtilsClientImpl utilsClient;
 
    /**
     * 更新对象
     * @param entity 对象
     */
    public void updateDyhCaseInfo(DyhCaseInfo entity){
        try{
            mapper.updateDyhCaseInfo(entity);
        }catch (Exception e){
            log.error("[DyhCaseInfoService.updateDyhCaseInfo]调用失败,异常信息:"+e, e);
            throw new ServiceException("DyhCaseInfoService.updateDyhCaseInfo", e);
        }
    }
 
    /**
     * 条件更新对象
     * @param entity 对象
     * @param terms 条件
     */
    public void updateDyhCaseInfoTerms(DyhCaseInfo entity, Map<String, Object> terms){
        try{
            mapper.updateDyhCaseInfoTerms(entity, terms);
        }catch (Exception e){
            log.error("[DyhCaseInfoService.updateDyhCaseInfoTerms]调用失败,异常信息:"+e, e);
            throw new ServiceException("DyhCaseInfoService.updateDyhCaseInfoTerms", e);
        }
    }
 
    /**
     * 根据编号物理删除
     * @param id 查询条件集合
     */
    public void deleteDyhCaseInfo(String id){
        try{
            mapper.deleteDyhCaseInfo(id);
        }catch (Exception e){
            log.error("[DyhCaseInfoService.deleteDyhCaseInfo]调用失败,异常信息:"+e, e);
            throw new ServiceException("DyhCaseInfoService.deleteDyhCaseInfo", e);
        }
    }
 
    /**
     * 按条件查询
     * @param terms 条件
     * @return List
     */
    public List<DyhCaseInfo> listTerms(Map<String, Object> terms){
        return mapper.listTerms(terms);
    }
 
    /**
     * 按条件统计
     * @param terms 条件
     * @return long
     */
    public long countTerms(Map<String, Object> terms){
        return mapper.countTerms(terms);
    }
 
 
    /**
     * 各类别统计
     * @return List<CategoryCountDTO>
     */
    public List<DictionaryDTO> categoryCount(Map<String, Object> terms){
        try{
            DictionaryDTO yearCountDictionaryDTO = new DictionaryDTO();
            yearCountDictionaryDTO.setName("发生时间");
            yearCountDictionaryDTO.setChildren(new ArrayList<>());
            List<CategoryCountDTO> yearCount = this.yearCount(terms);
            for (CategoryCountDTO category : yearCount) {
                DictionaryDTO dictionary = new DictionaryDTO();
                BeanUtils.copyProperties(category, dictionary);
                yearCountDictionaryDTO.getChildren().add(dictionary);
            }
 
            DictionaryDTO areaCountDictionaryDTO = new DictionaryDTO();
            areaCountDictionaryDTO.setName("纠纷发生地");
            areaCountDictionaryDTO.setChildren(new ArrayList<>());
            List<CategoryCountDTO> areaCount = this.areaCount(terms);
            for (CategoryCountDTO category : areaCount) {
                DictionaryDTO dictionary = new DictionaryDTO();
                BeanUtils.copyProperties(category, dictionary);
                areaCountDictionaryDTO.getChildren().add(dictionary);
            }
            List<DictionaryDTO> categoryCount = new ArrayList<>();
            categoryCount.add(yearCountDictionaryDTO);
            categoryCount.add(areaCountDictionaryDTO);
            return categoryCount;
        }catch (Exception e){
            log.error("[CpwsCaseInfoService.categoryCount]调用失败,异常信息:"+e, e);
            throw new ServiceException("CpwsCaseInfoService.categoryCount", e);
        }
    }
 
    /**
     * 年份统计
     * @return List<CategoryCountDTO>
     */
    public List<CategoryCountDTO> yearCount(Map<String, Object> terms){
        try{
            return mapper.yearCount(terms);
        }catch (Exception e){
            log.error("[CpwsCaseInfoService.yearCount]调用失败,异常信息:"+e, e);
            throw new ServiceException("CpwsCaseInfoService.yearCount", e);
        }
 
    }
 
    /**
     * 根据编号查询案件描述和调解协议
     * @return List<CategoryCountDTO>
     */
    public DyhCaseInfo getDyhCaseById(String id){
        try{
            return mapper.getDyhCaseById(id);
        }catch (Exception e){
            log.error("[CpwsCaseInfoService.yearCount]调用失败,异常信息:"+e, e);
            throw new ServiceException("CpwsCaseInfoService.yearCount", e);
        }
    }
 
    /**
     * 区域统计
     * @return List<CategoryCountDTO>
     */
    public List<CategoryCountDTO> areaCount(Map<String, Object> terms){
        try{
            return mapper.areaCount(terms);
        }catch (Exception e){
            log.error("[CpwsCaseInfoService.yearCount]调用失败,异常信息:"+e, e);
            throw new ServiceException("CpwsCaseInfoService.yearCount", e);
        }
 
    }
 
    /**
     * 按条件分页查询
     * @param page 分页对象
     * @param terms 条件
     * @return Page
     */
    public Page<DyhCaseInfoDTO> pageQuery(PageRequest page, Map<String, Object> terms){
        long total = mapper.countTerms(terms);
        List<DyhCaseInfoDTO> content = mapper.pageTerms(page, terms);
        return new PageImpl<>(content, page, total);
    }
 
    /**
     * 新增或更新对象
     * @param dyhCaseInfo 实体对象
     */
    public void saveDyhCaseInfo(DyhCaseInfo dyhCaseInfo){
        try{
            Date nowDate = DateUtils.getNowDate();
            // 判断是否新增
            if (IdUtils.checkNewId(dyhCaseInfo.getId())){
                dyhCaseInfo.setId(utilsClient.getNewTimeId());
                dyhCaseInfo.setCreateTime(nowDate);
            }
            dyhCaseInfo.setUpdateTime(nowDate);
            this.saveOrUpdate(dyhCaseInfo);
        }catch (Exception e){
            log.error("[DyhCaseInfoService.saveDyhCaseInfo]调用失败,异常信息:"+e, e);
            throw new ServiceException("DyhCaseInfoService.saveDyhCaseInfo", e);
        }
    }
 
    /**
     * 获取案件详情信息(隐私化处理)
     * @param id 案件ID
     * @return DyhCaseDetailDTO
     */
    public DyhCaseDetailDTO getCaseDetail(String id) {
        try {
            DyhCaseDetailDTO caseDetail = mapper.getCaseDetail(id);
            if (caseDetail != null) {
                // 创建DyhCaseInfo对象用于隐私化处理
                DyhCaseInfo caseInfo = new DyhCaseInfo();
                BeanUtils.copyProperties(caseDetail, caseInfo);
                log.info("caseInfo:{}",caseInfo);
                // 进行隐私化处理
                DyhCaseInfo processedCase = privacyProcessing(caseInfo);
                log.info("processedCase:{}",processedCase);
                // 将处理后的结果复制回DTO
                BeanUtils.copyProperties(processedCase, caseDetail);
 
            }
            return caseDetail;
        } catch (Exception e) {
            log.error("[DyhCaseInfoService.getCaseDetail]调用失败,异常信息:"+e, e);
            throw new ServiceException("DyhCaseInfoService.getCaseDetail", e);
        }
    }
 
    /**
     * 根据ID查询案件标题(隐私化处理)
     * @param id 案件ID
     * @return DyhCaseInfo 仅包含id和caseTitle
     */
    public DyhCaseInfo getCaseTitleById(String id) {
        try {
            DyhCaseInfo caseInfo = mapper.getCaseTitleById(id);
            if (caseInfo != null) {
                DyhCaseInfo processedCase = privacyProcessing(caseInfo);
                // 只保留需要的字段
                caseInfo.setCaseTitle(processedCase.getCaseTitle());
 
            }
            return caseInfo;
        } catch (Exception e) {
            log.error("[DyhCaseInfoService.getCaseTitleById]调用失败,异常信息:"+e, e);
            throw new ServiceException("DyhCaseInfoService.getCaseTitleById", e);
        }
    }
 
    /**
     * 对案件信息中的姓名进行隐私化处理
     * @param caseInfo 案件信息对象
     * @return 处理后的案件信息对象
     */
    public DyhCaseInfo privacyProcessing(DyhCaseInfo caseInfo) {
        try {
            if (caseInfo == null) {
                return null;
            }
 
            // 处理原告和被告信息
            String plaintiffs = caseInfo.getPlaintiffs();
            String defendants = caseInfo.getDefendants();
 
            if (plaintiffs != null && !plaintiffs.isEmpty()) {
                String[] plaintiffArray = plaintiffs.split(",");
                String[] newPlaintiffs = new String[plaintiffArray.length];
                
                for (int i = 0; i < plaintiffArray.length; i++) {
                    newPlaintiffs[i] = processName(plaintiffArray[i]);
                }
                
                // 处理重名情况
                newPlaintiffs = handleDuplicateNames(newPlaintiffs);
                
                // 更新原告信息
                caseInfo.setPlaintiffs(String.join(",", newPlaintiffs));
                
                // 在案件描述和调解协议中替换姓名
                for (int i = 0; i < plaintiffArray.length; i++) {
                    String oldName = plaintiffArray[i];
                    String newName = newPlaintiffs[i];
                    
                    if (caseInfo.getCaseDes() != null) {
                        caseInfo.setCaseDes(caseInfo.getCaseDes().replace(oldName, newName));
                    }
                    if (caseInfo.getAgreeContent() != null) {
                        caseInfo.setAgreeContent(caseInfo.getAgreeContent().replace(oldName, newName));
                    }
                    if (caseInfo.getCaseTitle() != null) {
                        caseInfo.setCaseTitle(caseInfo.getCaseTitle().replace(oldName, newName));
                    }
                }
            }
 
            if (defendants != null && !defendants.isEmpty()) {
                String[] defendantArray = defendants.split(",");
                String[] newDefendants = new String[defendantArray.length];
                
                for (int i = 0; i < defendantArray.length; i++) {
                    newDefendants[i] = processName(defendantArray[i]);
                }
                
                // 处理重名情况
                newDefendants = handleDuplicateNames(newDefendants);
                
                // 更新被告信息
                caseInfo.setDefendants(String.join(",", newDefendants));
                
                // 在案件描述和调解协议中替换姓名
                for (int i = 0; i < defendantArray.length; i++) {
                    String oldName = defendantArray[i];
                    String newName = newDefendants[i];
                    
                    if (caseInfo.getCaseDes() != null) {
                        caseInfo.setCaseDes(caseInfo.getCaseDes().replace(oldName, newName));
                    }
                    if (caseInfo.getAgreeContent() != null) {
                        caseInfo.setAgreeContent(caseInfo.getAgreeContent().replace(oldName, newName));
                    }
                    if (caseInfo.getCaseTitle() != null) {
                        caseInfo.setCaseTitle(caseInfo.getCaseTitle().replace(oldName, newName));
                    }
                }
            }
 
            return caseInfo;
        } catch (Exception e) {
            log.error("[DyhCaseInfoService.privacyProcessing]隐私化处理失败,异常信息:" + e, e);
            throw new ServiceException("DyhCaseInfoService.privacyProcessing", e);
        }
    }
 
    /**
     * 处理单个姓名的隐私化
     * @param name 原始姓名
     * @return 隐私化后的姓名
     */
    private String processName(String name) {
        if (name == null || name.isEmpty()) {
            return name;
        }
        
        if (name.length() > 4) {
            return "某某" + name.substring(name.length() - 2);
        } else {
            return name.charAt(0) + "某" + name.charAt(name.length() - 1);
        }
    }
 
    /**
     * 处理重名情况
     * @param names 处理后的姓名数组
     * @return 处理重名后的姓名数组
     */
    private String[] handleDuplicateNames(String[] names) {
        Map<String, Integer> nameCount = new HashMap<>();
        String[] result = new String[names.length];
        
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            nameCount.put(name, nameCount.getOrDefault(name, 0) + 1);
            
            if (nameCount.get(name) > 1) {
                result[i] = name + (nameCount.get(name) - 1);
            } else {
                result[i] = name;
            }
        }
        
        return result;
    }
 
}