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
package com.vci.web.controller;
 
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeVO;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.service.OsLinkTypeServiceI;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 链接类型的控制器
 * @author weidy
 * @date 2022-3-26
 */
@RequestMapping("/linkTypeController")
@RestController
public class OsLinkTypeController {
 
    /**
     * 链接类型
     */
    @Autowired
    private OsLinkTypeServiceI linkTypeService;
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 链接类型的列表
     * @param baseQueryObject 查询对象
     * @return 链接类型的显示对象
     */
    @GetMapping("/gridLinkType")
    public DataGrid<OsLinkTypeVO> gridLinkType(BaseQueryObject baseQueryObject){
        return linkTypeService.gridLinkType(baseQueryObject);
    }
 
    /**
     * 查询所有的链接类型名称,可用于属性池的连接类型选择时的对话框
     * @return 链接类型的显示对象
     */
    @GetMapping("/getAllLtName")
    @VciUnCheckRight
    public BaseResult getAllLtName(){
        try {
            return BaseResult.dataList(linkTypeService.getAllLtName());
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "链接类型列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 获取链接类型包含的属性
     * @param linkTypeOid 链接类型的主键
     * @param baseQueryObject 查询对象
     * @return 属性的信息
     */
    @GetMapping("/gridAttributeByLinkTypeOid")
    public DataGrid<OsLinkTypeAttributeVO> gridAttributeByLinkTypeOid(String linkTypeOid, BaseQueryObject baseQueryObject){
        if(StringUtils.isBlank(linkTypeOid)){
            return new DataGrid<OsLinkTypeAttributeVO>();
        }
        String attrId = baseQueryObject.getConditionMap().containsKey("name")?baseQueryObject.getConditionMap().get("name").replace("*",""):"";
        String attrName = baseQueryObject.getConditionMap().containsKey("label") ? baseQueryObject.getConditionMap().get("label").replace("*","") : "";
        OsLinkTypeVO linkTypeVO = linkTypeService.selectByOid(linkTypeOid);
        List<OsLinkTypeAttributeVO> boAttrs = linkTypeService.listAttributeByLinkId(linkTypeVO.getId());
        List<OsLinkTypeAttributeVO> attrList = boAttrs.stream().filter(s->{
            boolean usedFlag = true;
            if(StringUtils.isNotBlank(attrId) && !s.getId().contains(attrId)){
                usedFlag = false;
            }
            if(StringUtils.isNotBlank(attrName) && !s.getName().contains(attrName)){
                usedFlag = false;
            }
            return usedFlag;
        }).collect(Collectors.toList());
        DataGrid<OsLinkTypeAttributeVO> dataGrid = new DataGrid<OsLinkTypeAttributeVO>();
        dataGrid.setTotal(attrList.size());;
        dataGrid.setData(attrList);
        return dataGrid;
    }
 
    /**
     * 检查链接类型中关联的业务类型的属性有不同的内容
     * @param linkTypeOid 链接类型的主键
     * @return 差异的属性
     */
    @PostMapping("/checkAttributeTypeDifferent")
    public BaseResult<OsBtmTypeAttributeVO> checkAttributeTypeDifferent(String linkTypeOid){
        if(StringUtils.isBlank(linkTypeOid)){
            return BaseResult.success();
        }
        List<OsBtmTypeAttributeVO> attributeVOList = linkTypeService.checkAttributeTypeDifferent(linkTypeOid);
        if(!CollectionUtils.isEmpty(attributeVOList)) {
            BaseResult result = BaseResult.fail("有不同");
            result.setData(attributeVOList);
            return result;
        }else{
            return BaseResult.success();
        }
    }
}