| | |
| | | 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); |
| | | } |
| | | } |