fuliqi
2023-12-16 3794effa1e9e78e82e81253d6a6d54ad6db89b7e
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
package com.ycl.service.caseHandler.impl;
 
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.JsonObject;
import com.ycl.common.constant.BaseCaseStatus;
import com.ycl.common.constant.StepName;
import com.ycl.common.dingding.DingCommon;
import com.ycl.controller.user.UmsAdminController;
import com.ycl.dto.caseHandler.DispatchInfoParam;
import com.ycl.entity.caseHandler.BaseCase;
import com.ycl.entity.caseHandler.DispatchInfo;
import com.ycl.entity.caseHandler.DisposeRecord;
import com.ycl.entity.caseHandler.WorkflowConfigStep;
import com.ycl.entity.user.UmsAdmin;
import com.ycl.exception.ApiException;
import com.ycl.mapper.caseHandler.BaseCaseMapper;
import com.ycl.mapper.caseHandler.DispatchInfoMapper;
import com.ycl.mapper.caseHandler.DisposeRecordMapper;
import com.ycl.mapper.caseHandler.WorkflowConfigStepMapper;
import com.ycl.service.caseHandler.IDispatchHandleService;
import com.ycl.service.user.UmsAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
 
/**
 * <p>
 * 调度处理 服务实现类
 * </p>
 *
 * @author mg
 * @since 2022-09-28
 */
@Service
@Transactional
@Slf4j
public class IDispatchHandleServiceImpl extends ServiceImpl<DispatchInfoMapper, DispatchInfo> implements IDispatchHandleService {
 
    @Resource
    BaseCaseMapper baseCaseMapper;
    @Resource
    DisposeRecordMapper disposeRecordMapper;
    @Resource
    WorkflowConfigStepMapper workflowConfigStepMapper;
    @Autowired
    DingCommon dingCommon;
    @Autowired
    UmsAdminService umsAdminService;
    @Override
    @Transactional
    public DispatchInfo dispatch(DispatchInfoParam dispatchInfoParam) {
        //新增调度信息
        DispatchInfo dispatchInfo = new DispatchInfo();
        BeanUtils.copyProperties(dispatchInfoParam, dispatchInfo);
        dispatchInfo.setCreateTime(new Date());
        baseMapper.insert(dispatchInfo);
        //修改案件状态为调度
        BaseCase baseCase = new BaseCase();
        baseCase.setId(dispatchInfoParam.getBaseCaseId());
        baseCase.setState(BaseCaseStatus.DISPATCH);
        baseCaseMapper.updateById(baseCase);
 
        QueryWrapper<WorkflowConfigStep> stepqurey = new QueryWrapper<>();
        stepqurey.eq("name", StepName.DISPATCH.getName());
        WorkflowConfigStep workflowConfigStep = workflowConfigStepMapper.selectOne(stepqurey);
 
        if (workflowConfigStep == null) {
            throw new ApiException("未查询到该流程环节");
        }
 
        UpdateWrapper<DisposeRecord> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("base_case_id", baseCase.getId()).eq("workflow_config_step_id", workflowConfigStep.getId());
 
        //修改调度记录
        DisposeRecord disposeRecord = new DisposeRecord();
        disposeRecord.setHandlerId(dispatchInfo.getCreateUser());
        disposeRecord.setResult(dispatchInfo.getDispatchOpinion());
        //调度已结束
        disposeRecord.setState(1);
        disposeRecord.setEndTime(LocalDateTime.now());
        disposeRecordMapper.update(disposeRecord, updateWrapper);
 
        QueryWrapper<WorkflowConfigStep> stepNextqurey = new QueryWrapper<>();
        stepNextqurey.eq("workflow_config_id", workflowConfigStep.getWorkflowConfigId());
        stepNextqurey.eq("seq", workflowConfigStep.getSeq() + 1);
        WorkflowConfigStep stepNext = workflowConfigStepMapper.selectOne(stepNextqurey);
 
        //添加下一步记录
        DisposeRecord stepNextRecord = new DisposeRecord();
        stepNextRecord.setBaseCaseId(baseCase.getId());
        stepNextRecord.setWorkflowConfigStepId(stepNext.getId());
        stepNextRecord.setStepName(stepNext.getName());
        stepNextRecord.setLimitTime(dispatchInfoParam.getDisposeDate());
        stepNextRecord.setHandlerId(dispatchInfoParam.getLawEnforcer());
        stepNextRecord.setHandlerRoleId(stepNext.getRoleId());
        //上传处置未结束
        stepNextRecord.setState(0);
        stepNextRecord.setStartTime(LocalDateTime.now());
        stepNextRecord.setCreateUser(dispatchInfo.getCreateUser());
        stepNextRecord.setCreateTime(LocalDateTime.now());
 
        disposeRecordMapper.insert(stepNextRecord);
        //发送钉钉工作通知消息
        log.info("发送一条工作通知");
        BaseCase baseCaseForCode = baseCaseMapper.selectById(dispatchInfoParam.getBaseCaseId());
        String baseCaseCode = baseCaseForCode.getCode();
        String text ="您有一条工作通知  \n  " +
                " 遂昌云执法:有待处理的任务  \n  " +
                "·您有1条待处理事件。事件编号:  \n  " +
                baseCaseCode;
        Long lawEnforcer = dispatchInfoParam.getLawEnforcer();
        UmsAdmin user = umsAdminService.getById(lawEnforcer);
        dingCommon.sendDingMsgStr(user.getAccountId()+"",text);
 
        return dispatchInfo;
    }
 
}