whycxzp
7 天以前 98d543674b46dcd169dcfbc1c856e9641a44bb64
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.constant.WorkflowEnum;
import com.whyc.dto.Response;
import com.whyc.mapper.*;
import com.whyc.pojo.db_user.User;
import com.whyc.pojo.web_site.WorkflowLink;
import com.whyc.pojo.web_site.WorkflowMain;
import com.whyc.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class WorkflowLinkService {
 
    @Resource
    private WorkflowLinkMapper mapper;
 
    @Autowired
    @Lazy
    private WorkflowMainService mainService;
 
 
    public void addBatch(List<WorkflowLink> links) {
        mapper.insertBatchSomeColumn(links);
    }
 
    public List<WorkflowLink> getWorkflowInfo(Integer mainId) {
        QueryWrapper<WorkflowLink> wrapper = Wrappers.query();
        wrapper.eq("main_id", mainId);
        return mapper.selectList(wrapper);
    }
 
    @Transactional
    public Response updateLink(WorkflowLink link) {
        //获取当前节点的记录
        WorkflowLink linkInDB = mapper.selectById(link.getId());
        User user = CommonUtil.getUser();
        Date now = new Date();
        //根据id.查询关联的主表
        WorkflowMain mainInDB = mainService.getById(linkInDB.getMainId());
        //查看申请流程类型
        switch (mainInDB.getType()) {
            case 1: { //设备维修申请
                //查看主表的状态
                //因为是单个链路节点,所以不需要判断是不是待处理,肯定只有1个节点. 审批通过或者驳回
                //if(main.getStatus() == WorkflowEnum.MAIN_STATUS_DEALING.getValue().intValue()){ //待处理,下一步是审批通过,待处理 或者驳回
                if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){
                    mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue());
                    mainService.updateById(mainInDB);
                }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){
                    mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue());
                    mainInDB.setEndReason(link.getDealRejectReason());
                    mainInDB.setEndTime(now);
                    mainService.updateById(mainInDB);
                    link.setDealAndClose(1);
                }
            }
            //设备入库申请
            case 2:
            //设备报废申请
            case 3:{
                if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){
                    mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue());
                    mainService.updateById(mainInDB);
                }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){
                    mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue());
                    mainInDB.setEndReason(link.getDealRejectReason());
                    mainInDB.setEndTime(now);
                    //检查是否有关联工单.如果有关联工单,关联工单状态重置为完结待处理,完成时间重置为空
                    if(mainInDB.getRelatedId() != null){
                        Integer relatedId = mainInDB.getRelatedId();
                        mainService.resetRepairStatus(relatedId,mainInDB.getQuantity());
                    }
                    mainService.updateById(mainInDB);
                    link.setDealAndClose(1);
                }
            }
 
        }
 
        link.setId(linkInDB.getId());
        link.setDealUserId(user.getId());
        link.setDealTime(now);
 
        mapper.updateById(link);
 
        return new Response().setII(1,"更新完成");
    }
 
    /**
     *
     * @param mainId 特定的单据
     * @param processLevel 特定的过程
     * @return 特定单据,特定过程,未完成的会签的数量
     */
    private int getLeftAssignNum(Integer mainId, String processLevel) {
        QueryWrapper<WorkflowLink> query = Wrappers.query();
        query.select("count(*) as id").eq("main_id",mainId).eq("process_level",processLevel).ne("status",WorkflowEnum.LINK_STATUS_PASS.getValue());
        return mapper.selectOne(query).getId();
    }
 
    /**
     * 更新节点,主节点不完结
     * @param link 参数id,status,dealReason或者dealRejectReason
     */
    private void updateLinkField(WorkflowLink link) {
        Date now = new Date();
        link.setDealTime(now);
        mapper.updateById(link);
    }
 
 
    public Map<Integer, Integer> getReceivedStatistics(int type, User user) {
        Map<Integer,Integer> statistics = new HashMap<>();
        statistics.put(1,0);
        statistics.put(6,0);
        statistics.put(58,0);
        List<WorkflowLink> links = mapper.getReceivedList(type,user);
        Map<Integer, List<WorkflowLink>> receivedListMap = links.stream().collect(Collectors.groupingBy(WorkflowLink::getStatus));
        Set<Integer> statusSet = receivedListMap.keySet();
        for (Integer status : statusSet) {
            if (status == 5 || status == 8) {
                statistics.put(58, statistics.get(58) + receivedListMap.get(status).size());
            } else {
                statistics.put(status, receivedListMap.get(status).size());
            }
        }
        return statistics;
    }
 
    /**
     *
     * 二次核容和隐患故障的统计
     *
     * 增加了全部 0
     * 0:全部
     * 1:审批中
     * 2:通过
     * 3:驳回
     *
     * status含义:1-待接单,6-待审核,58-已审核
     * @param type
     * @param user
     * @return
     */
    public Response getReceivedStatistics2(int type, User user) {
        Map<Integer,Integer> statistics = new HashMap<>();
        statistics.put(0,0);
        statistics.put(1,0);
        statistics.put(2,0);
        statistics.put(3,0);
        List<WorkflowLink> links = mapper.getReceivedList2(type,user);
        Map<Integer, List<WorkflowLink>> receivedListMap = links.stream().collect(Collectors.groupingBy(WorkflowLink::getStatus));
        Set<Integer> statusSet = receivedListMap.keySet();
        int sum = 0;
        for (Integer status : statusSet) {
            int size = receivedListMap.get(status).size();
            if (status == 1 || status == 6) { //审批中
                statistics.put(1, statistics.get(1) + size);
            } else if(status == 5){ //通过
                statistics.put(2, size);
            }else if(status == 8){ //驳回
                statistics.put(3,size);
            }
            sum+=size;
        }
        statistics.put(0,sum);
        return new Response().set(1,statistics);
    }
 
 
    public void add(WorkflowLink link) {
        mapper.insert(link);
    }
 
 
}