kimi
2020-05-27 c007f0ca1785db093d48f4846cda82fe8e955765
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
package com.highdatas.mdm.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.highdatas.mdm.entity.Flows;
import com.highdatas.mdm.entity.MaintainField;
import com.highdatas.mdm.mapper.FlowsMapper;
import com.highdatas.mdm.mapper.SysFieldMapper;
import com.highdatas.mdm.pojo.ActivitiBusinessType;
import com.highdatas.mdm.pojo.ActivitiStatus;
import com.highdatas.mdm.pojo.NextTaskUserInfo;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.service.act.IdentityService;
import com.highdatas.mdm.service.act.TaskService;
import com.highdatas.mdm.util.DbUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kimi
 * @since 2019-12-19
 */
@Service
@Slf4j
public class FlowsServiceImpl extends ServiceImpl<FlowsMapper, Flows> implements IFlowsService {
    @Autowired
    IMaintainFieldService maintainFieldService;
    @Autowired
    TaskService taskService;
    @Autowired
    SysFieldMapper fieldMapper;
    @Autowired
    IMasterModifiedService masterModifiedService;
    @Autowired
    IMaintainService maintainService;
    @Autowired
    IdentityService identityService;
    @Autowired
    ISysViewService viewService;
    @Autowired
    IMasterAuthorSubscribeService subscribeService;
    @Autowired
    ISysMenuService menuService;
 
    /**
     *
     * @description:  创建新字段版本
     * @param userId 用户id
     * @param maintainId 数据版本id
     * @param tableName 表名
     *
     * @return: maintainfielid 字段版本对象
     *
     */
    @Override
    public MaintainField createNowVerion(String tableName, String maintainId, String userId) {
        MaintainField nowMaintain = maintainFieldService.getNextMaintain(tableName, userId);
        // 搬运新版本字段
        String maintainParams;
        if (StringUtils.isEmpty(maintainId)) {
            maintainParams = "maintain_field_id is null and table_name = " + DbUtils.quotedStr(tableName);
        }else {
            maintainParams = "maintain_field_id = " + DbUtils.quotedStr(maintainId);
        }
 
        if (nowMaintain != null) {
            String maintainFieldId = DbUtils.quotedStr(nowMaintain.getId());
            fieldMapper.tansNewVersion(maintainFieldId, maintainParams);
        }
 
        return nowMaintain;
    }
    /**
     *
     * @description:  通过业务id获取审批状态
     * @param businessId 业务id
     * @return: status
     *
     */
    @Override
    public ActivitiStatus getStatusByBusinessId(String businessId) {
        Flows flows = selectOne(new EntityWrapper<Flows>().eq("business_id", businessId).orderBy("create_time desc"));
        if (flows == null){
            return null;
        }
        return flows.getStatus();
    }
    /**
     *
     * @description:  判断是否为下一节点审批人
     * @param flows 流程
     * @param userId 用户id
     * @return: status
     *
     */
    @Override
    public boolean isNextAudit(Flows flows, String userId) {
        NextTaskUserInfo nestTaskAssignee = taskService.getNestTaskAssignee(flows.getWorkflowId());
        if (nestTaskAssignee == null){
            return false;
        }
        List<String> userIdList = nestTaskAssignee.getUserIdList();
        if (userIdList.contains(userId)) {
            return true;
        }
 
        List<String> roleIdList = nestTaskAssignee.getRoleIdList();
        if (roleIdList == null || roleIdList.isEmpty()) {
            return false;
        }
 
        List<String> roleByUser = identityService.getRoleByUser(userId);
        if (roleByUser == null || roleByUser.isEmpty()) {
            return false;
        }
        long count = roleByUser.stream().filter(roleId -> roleIdList.contains(roleId)).count();
        if (count == 0) {
            return false;
        }else {
            return true;
        }
    }
 
    /**
     *
     * @description:  流程完成后的操作
     * @param flows 流程实例
     *
     */
 
    @Override
    public void aduitFinish(Flows flows) {
        // 新增线程
        new Thread(() -> {
            log.info("处理 生成版本后的操作");
            if (flows.getBusinessType().equals(ActivitiBusinessType.maintain)){
                String maintainId = flows.getBusinessId();
                log.info("flow-maintain:" + maintainId);
                masterModifiedService.dealFlow(maintainId, flows.getStatus());
                log.info("flow-masterModifiedService end");
                maintainService.dealFlow(maintainId, flows.getStatus());
                log.info("flow-maintainService end");
                viewService.dealFlow(maintainId, flows.getStatus());
                log.info("flow-viewService end");
                subscribeService.dealFlow(maintainId, flows.getStatus());
                log.info("flow-subscribeService end");
                menuService.dealFlow(maintainId, flows.getStatus(), flows.getUserId());
                log.info("flow-menuService end");
            }
            if (flows.getBusinessType().equals(ActivitiBusinessType.field)){
                String maintainId = flows.getBusinessId();
                maintainFieldService.dealFlow(maintainId, flows.getStatus());
 
            }
        }).start();
    }
}