whycxzp
2021-11-03 62b5c458b9b95220e3078eb2d67c1be79fea8f13
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 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;
    }
}