广州市综治平台后端
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
package cn.huge.module.casedisp.service;
 
import cn.huge.base.common.exception.ServiceException;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.module.casedisp.constant.DispRuleConstsEnum;
import cn.huge.module.casedisp.domain.dto.ZzzxUnitDTO;
import cn.huge.module.casedisp.domain.po.CaseDisp;
import cn.huge.module.casedisp.domain.po.DispNormCause;
import cn.huge.module.casedisp.domain.po.DispRule;
import cn.huge.module.client.api.impl.CustClientImpl;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.constant.BaseConsts;
import cn.huge.module.cust.constant.UserBaseConsts;
import cn.huge.module.cust.dto.CtUnitDTO;
import cn.huge.module.disp.constant.DispBaseConsts;
import cn.huge.module.disp.constant.DispBaseConstsEnum;
import cn.huge.module.disp.dto.CaseDispBaseDTO;
import cn.huge.module.disp.dto.DispCaseBaseDTO;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import java.util.stream.Collectors;
 
 
/**
 * @author liyj
 * @version 1.0.0
 * @title: 系统逻辑处理
 * @Description 系统逻辑处理
 * @company hugeinfo
 * @Time 2022-11-20 15:32:09
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class SysDispService {
 
    @Autowired
    private CaseDispService caseDispService;
    @Autowired
    private DispRuleService dispRuleService;
    @Autowired
    private DispNormCauseService dispNormCauseService;
 
    @Autowired
    private UtilsClientImpl utilsClient;
    @Autowired
    private CustClientImpl custClient;
 
    /**
     * 系统自动调度
     *
     * @param dispCaseBaseDTO
     */
    public CaseDispBaseDTO sysDisp(DispCaseBaseDTO dispCaseBaseDTO) {
        try {
            CaseDisp caseDisp = null;
            if (StringUtils.isNotEmpty(dispCaseBaseDTO.getWantUnitId()) ||
                    StringUtils.isNotEmpty(dispCaseBaseDTO.getWantUserId())) {
                caseDisp = this.sysWantDisp(dispCaseBaseDTO);
            } else {
                caseDisp = this.sysRuleDisp(dispCaseBaseDTO);
            }
            CaseDispBaseDTO caseDispBaseDTO = new CaseDispBaseDTO();
            BeanUtils.copyProperties(caseDisp, caseDispBaseDTO);
            return caseDispBaseDTO;
        } catch (Exception e) {
            log.error("service方法[SysDispService.sysDisp]调用失败,异常信息:" + e, e);
            throw new ServiceException("SysDispService.sysDisp", e);
        }
    }
 
    /**
     * 系统自动调度-意向调解调度
     *
     * @param dispCaseBaseDTO
     * @return CaseSignBaseDTO
     */
    public CaseDisp sysWantDisp(DispCaseBaseDTO dispCaseBaseDTO) {
        try {
            Date nowDate = DateUtils.getNowDate();
            //封装初始化对象
            CaseDisp caseDisp = new CaseDisp();
            caseDisp.setId(utilsClient.getNewTimeId());
            caseDisp.setCaseId(dispCaseBaseDTO.getCaseId());
            caseDisp.setDispWay(DispBaseConsts.DISP_WAY_1);
            caseDisp.setDispType(DispBaseConstsEnum.DISP_TYPE_1.getIndex());
            caseDisp.setDispTypeName(DispBaseConstsEnum.DISP_TYPE_1.getDes());
            caseDisp.setDispContent("系统自动流转");
            caseDisp.setHandleUserName("系统派单");
            caseDisp.setDispTime(nowDate);
            caseDisp.setDispStatus(DispBaseConsts.DISP_STATUS_1);
            caseDisp.setCustId(dispCaseBaseDTO.getCustId());
            caseDisp.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
            caseDisp.setCreateTime(nowDate);
            caseDisp.setUpdateTime(nowDate);
            // 调度给意向调解员
            if (StringUtils.isNotEmpty(dispCaseBaseDTO.getWantUserId())) {
                caseDisp.setTargetType(DispBaseConstsEnum.TARGET_TYPE_2.getIndex());
                caseDisp.setTargetTypeName(DispBaseConstsEnum.TARGET_TYPE_2.getDes());
                caseDisp.setTargetId(dispCaseBaseDTO.getWantUserId());
                caseDisp.setTargetName(dispCaseBaseDTO.getWantUserName());
            } else {
                caseDisp.setTargetType(DispBaseConstsEnum.TARGET_TYPE_1.getIndex());
                caseDisp.setTargetTypeName(DispBaseConstsEnum.TARGET_TYPE_1.getDes());
                caseDisp.setTargetId(dispCaseBaseDTO.getWantUnitId());
                caseDisp.setTargetName(dispCaseBaseDTO.getWantUnitName());
                CtUnitDTO ctUnitDTO = custClient.getUnitById(dispCaseBaseDTO.getWantUnitId());
                caseDisp.setTargetUnitGrade(ctUnitDTO.getUnitGrade());
                caseDisp.setTargetUnitType(ctUnitDTO.getUnitType());
            }
            caseDispService.save(caseDisp);
            return caseDisp;
        } catch (Exception e) {
            log.error("service方法[SysDispService.wantDisp]调用失败,异常信息:" + e, e);
            throw new ServiceException("SysDispService.wantDisp", e);
        }
    }
 
    /**
     * 系统自动调度-自定义调度规则调度
     *
     * @param dispCaseBaseDTO
     */
    public CaseDisp sysRuleDisp(DispCaseBaseDTO dispCaseBaseDTO) {
        try {
            String targetUnitId = null;
            String targetUnitName = null;
            // 默认是调度到最高级是镇街级
            int highTargetLevel = UserBaseConsts.UNIT_GRADE_2;
            if (StringUtils.isNotEmpty(dispCaseBaseDTO.getQueRoad())) {
                highTargetLevel = UserBaseConsts.UNIT_GRADE_3;
            }
            if (dispCaseBaseDTO.getIsQu() == 1) {
                highTargetLevel = UserBaseConsts.UNIT_GRADE_2;
            }
            List<DispRule> dispRuleList = dispRuleService.listEffectiveRuleAsc();
            if (CollectionUtils.isNotEmpty(dispRuleList)) {
                for (DispRule dispRule : dispRuleList) {
                    // 第一步,问题属地调度
//                    if (DispRuleConstsEnum.DISP_NORM_TYPE_1.getIndex().equals(dispRule.getNormType())){
//                        highTargetLevel = dispRule.getHighTargetLevel();
//                    }
                    // 第二步,纠纷类型调度
                    if (DispRuleConstsEnum.DISP_NORM_TYPE_2.getIndex().equals(dispRule.getNormType())) {
                        List<DispNormCause> dispNormCauseList = dispNormCauseService.listByCaseTypeGeLevel(dispCaseBaseDTO.getCaseType(), highTargetLevel);
                        if (CollectionUtils.isNotEmpty(dispNormCauseList)) {
                            targetUnitId = dispNormCauseList.get(0).getTargetUnitId();
                            targetUnitName = dispNormCauseList.get(0).getTargetUnitName();
                        }
                    }
                }
            }
            // 保存调度结果
            Date nowDate = DateUtils.getNowDate();
            CaseDisp caseDisp = new CaseDisp();
            caseDisp.setId(utilsClient.getNewTimeId());
            caseDisp.setCaseId(dispCaseBaseDTO.getCaseId());
            caseDisp.setDispWay(DispBaseConsts.DISP_WAY_1);
            caseDisp.setDispType(DispBaseConstsEnum.DISP_TYPE_1.getIndex());
            caseDisp.setDispTypeName(DispBaseConstsEnum.DISP_TYPE_1.getDes());
            caseDisp.setDispTime(nowDate);
            caseDisp.setCustId(dispCaseBaseDTO.getCustId());
            caseDisp.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
            caseDisp.setCreateTime(nowDate);
            caseDisp.setUpdateTime(nowDate);
            // 系统调度成功
            if (StringUtils.isNotEmpty(targetUnitId)) {
                caseDisp.setDispContent("系统自动流转,派单至" + targetUnitName + "。");
                caseDisp.setHandleUserName("系统派单");
                caseDisp.setDispStatus(DispBaseConsts.DISP_STATUS_1);
                // 调度给调解组织
                caseDisp.setTargetType(DispBaseConstsEnum.TARGET_TYPE_1.getIndex());
                caseDisp.setTargetTypeName(DispBaseConstsEnum.TARGET_TYPE_1.getDes());
                caseDisp.setTargetId(targetUnitId);
                caseDisp.setTargetName(targetUnitName);
            } else {
                // 调度失败
                caseDisp.setDispContent("系统自动流转失败,派单至综治中心进行人工交办。");
                caseDisp.setHandleUserName("系统派单");
                caseDisp.setDispStatus(DispBaseConsts.DISP_STATUS_2);
                // 默认流转到对应综治中心处理
                Map<String, Object> terms = Maps.newHashMap();
                // 镇街综治中心
                if (UserBaseConsts.UNIT_GRADE_3 == highTargetLevel) {
                    terms.put("road", dispCaseBaseDTO.getQueRoad());
                }
                // 区综治中心
                if (UserBaseConsts.UNIT_GRADE_2 == highTargetLevel) {
                    terms.put("area", dispCaseBaseDTO.getQueArea());
                }
                // 市综治中心
                if (UserBaseConsts.UNIT_GRADE_1 == highTargetLevel) {
                    terms.put("city", dispCaseBaseDTO.getQueCity());
                }
                ZzzxUnitDTO zzzxUnitDTO = dispNormCauseService.getZzzxUnitByTerms(terms);
                caseDisp.setTargetType(DispBaseConstsEnum.TARGET_TYPE_1.getIndex());
                caseDisp.setTargetTypeName(DispBaseConstsEnum.TARGET_TYPE_1.getDes());
                caseDisp.setTargetId(zzzxUnitDTO.getUnitId());
                caseDisp.setTargetName(zzzxUnitDTO.getUnitName());
                caseDisp.setTargetUnitGrade(zzzxUnitDTO.getUnitGrade());
                caseDisp.setTargetUnitType(zzzxUnitDTO.getUnitType());
            }
            caseDispService.save(caseDisp);
            return caseDisp;
        } catch (Exception e) {
            log.error("service方法[SysDispService.sysRuleDisp]调用失败,异常信息:" + e, e);
            throw new ServiceException("SysDispService.sysRuleDisp", e);
        }
    }
 
 
}