ludc
2024-12-05 a485f4494787001a2695863e239910c019a52246
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package com.vci.web.service.impl;
 
import com.vci.corba.common.PLException;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.pagemodel.OsAttributeVO;
import com.vci.pagemodel.OsBtmTypeVO;
import com.vci.pagemodel.OsLinkTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeVO;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.util.BeanUtilForVCI;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.service.WebAttributeServiceI;
import com.vci.web.service.WebBtmServiceI;
import com.vci.web.service.WebEnumServiceI;
import com.vci.web.service.WebLinkTypeServiceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description 链接类型服务
 * @Author dangsn
 * @Date 2024/11/28 11:42
 */
@Service
public class WebLinkTypeServiceImpl implements WebLinkTypeServiceI {
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
 
    /**
     * 平台的调用工具类
     */
    @Resource
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 业务类型服务
     */
    @Resource
    private WebBtmServiceI btmService;
 
    /**
     * 枚举的服务
     */
    @Resource
    private WebEnumServiceI enumService;
 
    /**
     * 属性的服务
     */
    @Resource
    private WebAttributeServiceI attributeService;
 
    /**
     * 查询所有的链接类型
     *
     * @return 链接类型对象
     */
    @Override
    @VciUnLog
    public List<OsLinkTypeVO> selectAllLink() {
        try {
            return linkTypeDO2VOs(Arrays.stream(platformClientUtil.getLinkTypeService().getLinkTypes()).collect(Collectors.toList()));
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
    }
 
    /**
     * 查询所有的业务类型映射
     *
     * @return key 是业务的英文名称的小写
     */
    @Override
    @VciUnLog
    public Map<String, OsLinkTypeVO> selectAllLinkMap() {
        return Optional.ofNullable(selectAllLink()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(), t->t,(o1, o2)->o1));
    }
 
    /**
     * 数据对象转换为显示对象
     *
     * @param linkTypes 数据对象
     * @return 显示对象
     */
    @Override
    public List<OsLinkTypeVO> linkTypeDO2VOs(Collection<LinkType> linkTypes) {
        List<OsLinkTypeVO> VOS = new ArrayList<>();
        Optional.ofNullable(linkTypes).orElseGet(()->new ArrayList<>()).stream().forEach(linkType -> {
            OsLinkTypeVO vo = linkTypeDO2VO(linkType);
            VOS.add(vo);
        });
        return VOS;
    }
 
    /**
     * 数据对象转换为显示对象
     *
     * @param linkType 数据对象
     * @return 显示对象
     */
    @Override
    public OsLinkTypeVO linkTypeDO2VO(LinkType linkType) {
        OsLinkTypeVO vo = new OsLinkTypeVO();
        if(linkType !=null){
            vo.setOid(linkType.oid);
            vo.setCreator(linkType.creator);
            vo.setLastModifier(linkType.modifier);
            try {
                vo.setCreateTime(VciDateUtil.long2Date(linkType.createTime));
                vo.setLastModifyTime(VciDateUtil.long2Date(linkType.modifyTime));
                vo.setTs(VciDateUtil.long2Date(linkType.ts));
            } catch (Exception e) {
                e.printStackTrace();
            }
            vo.setDescription(linkType.description);
            vo.setId(linkType.name);
            vo.setName(linkType.tag);
            vo.setFromBtmTypeVOS(btmService.listBtmByIds(Arrays.stream(linkType.btmItemsFrom).collect(Collectors.toSet())));
            if(!CollectionUtils.isEmpty(vo.getFromBtmTypeVOS())){
                vo.setFromBtmType(Arrays.stream(linkType.btmItemsFrom).collect(Collectors.joining(",")));
                vo.setFromBtmTypeName(vo.getFromBtmTypeVOS().stream().map(OsBtmTypeVO::getName).collect(Collectors.joining(",")));
            }
            vo.setToBtmTypeVOS(btmService.listBtmByIds(Arrays.stream(linkType.btmItemsTo).collect(Collectors.toSet())));
            if(!CollectionUtils.isEmpty(vo.getToBtmTypeVOS())){
                vo.setToBtmType(Arrays.stream(linkType.btmItemsTo).collect(Collectors.joining(",")));
                vo.setToBtmTypeName(vo.getToBtmTypeVOS().stream().map(OsBtmTypeVO::getName).collect(Collectors.joining(",")));
            }
            vo.setImplClass(linkType.implClass);
            vo.setShape(linkType.shape);
            List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(linkType.attributes).collect(Collectors.toList()));
            List<OsLinkTypeAttributeVO> linkTypeAttributeVOS = new ArrayList<>();
            Optional.ofNullable(attributeVOS).orElseGet(()->new ArrayList<>()).stream().forEach(attributeVO->{
                OsLinkTypeAttributeVO linkTypeAttributeVO = new OsLinkTypeAttributeVO();
                BeanUtilForVCI.convert(attributeVO,linkTypeAttributeVO);
                linkTypeAttributeVO.setPkLinkType(vo.getOid());
                if(StringUtils.isNotBlank(attributeVO.getBtmTypeId())){
                    linkTypeAttributeVO.setReferFlag(true);
                    linkTypeAttributeVO.setReferBtmTypeId(attributeVO.getBtmTypeId());
                }
                if(StringUtils.isNotBlank(attributeVO.getEnumId())){
                    linkTypeAttributeVO.setEnumFlag(true);
                    linkTypeAttributeVO.setEnumItemMap(enumService.getEnumValueMap(linkTypeAttributeVO.getEnumId()));
                }
                linkTypeAttributeVOS.add(linkTypeAttributeVO);
            });
            vo.setAttributes(linkTypeAttributeVOS);
        }
        return vo;
    }
}