kimi
2020-03-24 b5636e416a2fe029f96aec6ddfd3489394925b15
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
package com.highdatas.mdm.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.mdm.entity.Flows;
import com.highdatas.mdm.entity.MaintainField;
import com.highdatas.mdm.entity.TUserRole;
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.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.highdatas.mdm.service.act.TaskService;
import com.highdatas.mdm.util.DbUtils;
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
public class FlowsServiceImpl extends ServiceImpl<FlowsMapper, Flows> implements IFlowsService {
    @Autowired
    IMaintainFieldService maintainFieldService;
    @Autowired
    TaskService taskService;
    @Autowired
    SysFieldMapper fieldMapper;
    @Autowired
    ITUserRoleService userRoleService;
    @Autowired
    IMasterModifiedService masterModifiedService;
    @Autowired
    IMaintainService maintainService;
 
    @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;
    }
 
    @Override
    public ActivitiStatus getStatusByBusinessId(String businessId) {
        Flows flows = selectOne(new EntityWrapper<Flows>().eq("business_id", businessId));
        if (flows == null){
            return null;
        }
        return flows.getStatus();
    }
 
    @Override
    public boolean isNextAudit(Flows flows, String userId) {
        NextTaskUserInfo nestTaskAssignee = taskService.getNestTaskAssignee(flows.getWorkflowId());
        if (nestTaskAssignee == null){
            return false;
        }
        String taskAssigneeUserId = nestTaskAssignee.getUserId();
        if (!StringUtils.isEmpty(taskAssigneeUserId)){
            return taskAssigneeUserId.equalsIgnoreCase(userId);
        }
        String roleId = nestTaskAssignee.getRoleId();
        if (StringUtils.isEmpty(roleId)) {
            return false;
        }
        List<TUserRole> userRoles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("role_id", roleId));
        long count = userRoles.stream().map(tUserRole -> tUserRole.getUserId()).filter(s -> s.equalsIgnoreCase(userId)).count();
        if (count == 0) {
            return false;
        }else {
            return true;
        }
    }
 
    @Override
    public void aduitFinish(Flows flows) {
        if (flows.getBusinessType().equals(ActivitiBusinessType.maintain)){
            String maintainId = flows.getBusinessId();
            masterModifiedService.dealFlow(maintainId, flows.getStatus());
            maintainService.dealFlow(maintainId, flows.getStatus());
        }
        if (flows.getBusinessType().equals(ActivitiBusinessType.field)){
            String maintainId = flows.getBusinessId();
            maintainFieldService.dealFlow(maintainId, flows.getStatus());
        }
    }
}