whycxzp
2023-03-28 aaa2e601eb2a6806e761d4424fcaaf43a95fdcfd
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
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.whyc.dto.WorkflowPropertyDTO;
import com.whyc.dto.WorkflowPropertyDTO2;
import com.whyc.mapper.WorkflowPropertyMapper;
import com.whyc.pojo.WorkflowProperty;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import javax.swing.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Service
public class WorkflowPropertyService {
 
    @Resource
    private WorkflowPropertyMapper mapper;
 
    public void add(WorkflowPropertyDTO propertyDTO) {
        List<WorkflowProperty> propertyList = new LinkedList<>();
        //数据格式整理
        List<WorkflowPropertyDTO.Role> roleList = propertyDTO.getRoleList();
        roleList.stream().forEach(role -> {
            WorkflowProperty temp = new WorkflowProperty();
            temp.setLinkName(propertyDTO.getLinkName());
            temp.setLinkType(propertyDTO.getLinkType());
            temp.setRoleName(role.getName());
            temp.setRoleType(role.getType());
            temp.setType(propertyDTO.getType());
            propertyList.add(temp);
        });
 
        mapper.insertBatchSomeColumn(propertyList);
 
    }
 
    public void update(WorkflowPropertyDTO propertyDTO) {
        List<WorkflowProperty> propertyList = new LinkedList<>();
        //数据格式整理
        List<WorkflowPropertyDTO.Role> roleList = propertyDTO.getRoleList();
        roleList.stream().forEach(role -> {
            WorkflowProperty temp = new WorkflowProperty();
            temp.setLinkName(propertyDTO.getLinkName());
            temp.setLinkType(propertyDTO.getLinkType());
            temp.setRoleName(role.getName());
            temp.setRoleType(role.getType());
            temp.setType(propertyDTO.getType());
            propertyList.add(temp);
        });
 
        //先删除type && linkType对应的记录
        UpdateWrapper<WorkflowProperty> wrapper = Wrappers.update();
        wrapper.eq("type",propertyDTO.getType()).eq("link_type",propertyDTO.getLinkType());
        mapper.delete(wrapper);
        //再新增记录
        mapper.insertBatchSomeColumn(propertyList);
 
    }
 
    public List<WorkflowPropertyDTO> getPropertyList() {
        List<WorkflowPropertyDTO> propertyDTOList = new LinkedList<>();
        List<WorkflowPropertyDTO2> propertyList =  mapper.getPropertyList();
        propertyList.stream().forEach(property -> {
            String[] linkTypes = property.getLinkType().split(",");
            String[] linkNames = property.getLinkName().split(",");
            String[] roleTypes = property.getRoleType().split(",");
            String[] roleNames = property.getRoleName().split(",");
            Integer type = property.getType();
            for (int i = 0; i < linkNames.length; i++) {
                boolean match = false;
                for (WorkflowPropertyDTO workflowPropertyDTO : propertyDTOList) {
                    if (workflowPropertyDTO.getType().intValue()==type && workflowPropertyDTO.getLinkType() == Integer.parseInt(linkTypes[i])){
                        WorkflowPropertyDTO dto4j = workflowPropertyDTO;
 
                        List<WorkflowPropertyDTO.Role> roleList = dto4j.getRoleList();
 
                        WorkflowPropertyDTO.Role role = new WorkflowPropertyDTO.Role();
                        role.setType(Integer.parseInt(roleTypes[i]));
                        role.setName(roleNames[i]);
 
                        roleList.add(role);
 
                        dto4j.setRoleList(roleList);
 
                        propertyDTOList.remove(workflowPropertyDTO);
                        propertyDTOList.add(dto4j);
                        match = true;
                        break;
                    }
                }
                if(!match) {
                    WorkflowPropertyDTO dto4type2 = new WorkflowPropertyDTO();
                    dto4type2.setLinkType(Integer.parseInt(linkTypes[i]));
                    dto4type2.setLinkName(linkNames[i]);
                    WorkflowPropertyDTO.Role role = new WorkflowPropertyDTO.Role();
                    role.setType(Integer.parseInt(roleTypes[i]));
                    role.setName(roleNames[i]);
                    List<WorkflowPropertyDTO.Role> roleList = dto4type2.getRoleList();
                    if (roleList == null) {
                        roleList = new LinkedList<>();
                    }
                    roleList.add(role);
                    dto4type2.setRoleList(roleList);
                    dto4type2.setType(type);
                    propertyDTOList.add(dto4type2);
                }
            }
 
        });
        return propertyDTOList;
    }
 
    public void delete(Integer type, Integer linkType) {
        UpdateWrapper<WorkflowProperty> wrapper = Wrappers.update();
        wrapper.eq("type",type).eq("link_type",linkType);
        mapper.delete(wrapper);
    }
 
    public List<WorkflowProperty> getLinkInfo(Integer type) {
        QueryWrapper<WorkflowProperty> wrapper = Wrappers.query();
        wrapper.select("link_type","link_name").eq("type",type).orderByAsc("link_type");
        return mapper.selectList(wrapper);
    }
 
    public List<WorkflowProperty> getRoleInfo(Integer type,Integer linkType) {
        QueryWrapper<WorkflowProperty> wrapper = Wrappers.query();
        wrapper.select("role_type","role_name").eq("type",type).eq("link_type",linkType).orderByAsc("role_type");
        return mapper.selectList(wrapper);
    }
}