whyclxw
2025-05-08 ddf6daa3a1aa46b5797d3ad33b691bccb9129856
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.internal.$Gson$Preconditions;
import com.whyc.constant.RoleEnum;
import com.whyc.mapper.WorkflowActionMapper;
import com.whyc.pojo.WorkflowAction;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Service
public class WorkflowActionService {
 
    @Resource
    private WorkflowActionMapper mapper;
 
 
    public void add(WorkflowAction workflowAction) {
        List<WorkflowAction> actionList = new LinkedList<>();
        List<Integer> actionTypeList = workflowAction.getActionTypeList();
        actionTypeList.stream().forEach(actionType -> {
            WorkflowAction actionTemp = new WorkflowAction();
            actionTemp.setLinkType(workflowAction.getLinkType());
            actionTemp.setRoleType(workflowAction.getRoleType());
            actionTemp.setType(workflowAction.getType());
            actionTemp.setActionType(actionType);
 
            actionList.add(actionTemp);
        });
        mapper.insertBatchSomeColumn(actionList);
    }
 
    public void update(List<WorkflowAction> workflowActionList) {
        List<WorkflowAction> actionList = new LinkedList<>();
        workflowActionList.stream().forEach(workflowAction -> {
            //先删除
            UpdateWrapper<WorkflowAction> wrapper = Wrappers.update();
            wrapper.eq("type",workflowAction.getType())
                    .eq("link_type",workflowAction.getLinkType())
                    .eq("role_type",workflowAction.getRoleType());
            mapper.delete(wrapper);
            //再新增
            List<Integer> actionTypeList = workflowAction.getActionTypeList();
            actionTypeList.stream().forEach(actionType -> {
                WorkflowAction actionTemp = new WorkflowAction();
                actionTemp.setLinkType(workflowAction.getLinkType());
                actionTemp.setRoleType(workflowAction.getRoleType());
                actionTemp.setType(workflowAction.getType());
                actionTemp.setActionType(actionType);
 
                actionList.add(actionTemp);
            });
        });
 
        mapper.insertBatchSomeColumn(actionList);
    }
 
    public List<WorkflowAction> getActionTypeList4Link(Integer type, Integer linkType) {
        QueryWrapper<WorkflowAction> wrapper = Wrappers.query();
        wrapper.eq("type",type)
                .eq("link_type",linkType);
        //Map<Integer, List<WorkflowAction>> collect = mapper.selectList(wrapper).stream().collect(Collectors.groupingBy(WorkflowAction::getRoleType));
        return mapper.selectList(wrapper);
    }
 
    public List<WorkflowAction> getActionTypeList(Integer type, Integer status, int userRole) {
        QueryWrapper<WorkflowAction> wrapper = Wrappers.query();
        Integer linkType = null;
        Integer roleType = null;
        //Map<Integer, List<WorkflowAction>> collect = mapper.selectList(wrapper).stream().collect(Collectors.groupingBy(WorkflowAction::getRoleType));
        //表示处于1级节点
        if(status == 2 ||status ==3){
            linkType = 1;
        }
        else if(status ==4){ //表示处于2级节点
            linkType = 2;
        }
        //角色类型
        if(userRole == RoleEnum.ADMIN.getId()){
            roleType = 0;
        }
        else{
            roleType = 1;
        }
        wrapper.select("action_type")
                .eq("type",type)
                .eq("link_type",linkType)
                .eq("role_type",roleType);
        return mapper.selectList(wrapper);
    }
}