yuxc
2024-06-13 eb85010d75785fc759d398ab32f7ce588e388688
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
package com.vci.web.service.impl;
 
import com.vci.client.common.providers.ClientServiceProvider;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.btm.BizType;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.enumpck.BooleanEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.PageHelper;
import com.vci.starter.web.util.BeanUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.pageModel.*;
import com.vci.web.service.*;
import com.vci.web.util.ConcurrentDateFormat;
import com.vci.web.util.Func;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 业务类型服务
 * @author weidy
 * @date 2021-2-15
 */
@Service
public class OsBtmServiceImpl implements OsBtmServiceI {
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 平台的调用工具类
     */
    //@Autowired
    //private PlatformClientUtil platformClientUtil;
 
    /**
     * 属性的服务
     */
    @Autowired
    private OsAttributeServiceI attributeService;
 
    /**
     * 枚举的服务
     */
    @Autowired
    private OsEnumServiceI enumService;
 
    /**
     * 业务数据操作服务
     */
    @Autowired
    private WebBoServiceI boService;
 
    /**
     * 链接类型的服务
     */
    @Autowired(required = false)
    @Lazy
    private OsLinkTypeServiceI linkTypeService;
 
    /**
     * 加载自身
     */
    @Autowired(required = false)
    @Lazy
    private OsBtmServiceI self;
 
    /**
     * 查询所有的业务类型
     *
     * @return 业务类型对象
     */
    @Override
    @VciUnLog
    public List<OsBtmTypeVO> selectAllBtm() {
        try {
            // return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getAllBtmItem("")).collect(Collectors.toList()));
//            return btmDO2VOs(Arrays.stream(ServiceProvider.getOMDService().getBTMService().getAllBtmItem("")).collect(Collectors.toList()));
            return btmDO2VOs(Arrays.stream(ClientServiceProvider.getOMDService().getBTMService().getBizTypes("")).collect(Collectors.toList()));
        }  catch (PLException e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 查询所有的业务类型映射
     *
     * @return key 是业务的英文名称的小写
     */
    @Override
    @VciUnLog
    public Map<String, OsBtmTypeVO> selectAllBtmMap() {
        return Optional.ofNullable(self.selectAllBtm()).orElseGet(()->new ArrayList<OsBtmTypeVO>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(), t->t,(o1,o2)->o1));
    }
 
    /**
     * 数据对象转换为显示对象
     *
     * @param btmItems 数据对象
     * @return 显示对象
     */
    @Override
    public List<OsBtmTypeVO> btmDO2VOs(Collection<BizType> btmItems) {
        List<OsBtmTypeVO> VOS = new ArrayList<>();
        Optional.ofNullable(btmItems).orElseGet(()->new ArrayList<>()).stream().forEach(btmItem -> {
            OsBtmTypeVO vo = btmDO2VO(btmItem);
            VOS.add(vo);
        });
        return VOS;
    }
 
    /**
     * 数据对象转换为显示对象
     *
     * @param btmItem 数据对象
     * @return 显示对象
     */
    @Override
    public OsBtmTypeVO btmDO2VO(BizType btmItem) {
        OsBtmTypeVO vo = new OsBtmTypeVO();
        if(btmItem !=null){
            vo.setOid(btmItem.oid);
            vo.setCreator(btmItem.creator);
            vo.setLastModifier(btmItem.modifier);
            try {
                // btmItem.createTime拿到的是时间戳,但是这儿要的是例如2017-12-27 09:32:20.034这样的格式,所以不调用这个方法,改调用其他方法
                //vo.setCreateTime(VciDateUtil.str2Date(String.valueOf(btmItem.createTime),VciDateUtil.DateTimeFormat));
                vo.setCreateTime(Func.parse(btmItem.createTime, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
                vo.setLastModifyTime( Func.parse(btmItem.modifyTime, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
                vo.setTs(Func.parse(btmItem.ts, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
            } catch (Exception e) {
                e.printStackTrace();
            }
            vo.setDescription(btmItem.description);
            vo.setId(btmItem.name);
             vo.setName(btmItem.label);
            vo.setLifeCycleId(btmItem.lifeCycle);
            vo.setAbstractFlag(btmItem.isAbstract);
            vo.setImplClass(btmItem.implClass);
            vo.setShape(btmItem.shape);
            vo.setRevisionRuleId(btmItem.revRuleName);
            vo.setTableName(VciBaseUtil.getTableName(vo.getId()));
            vo.setInputRevisionFlag(btmItem.revInput);
            if(StringUtils.isNotBlank(vo.getRevisionRuleId()) || vo.isInputRevisionFlag()){
                vo.setRevisionFlag(true);
            }
            vo.setVersionRule(String.valueOf(btmItem.verRuleName));
            vo.setSubLifeCycleId(Arrays.stream(btmItem.lifeCycles).collect(Collectors.joining(",")));
            List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(btmItem.apNameArray).collect(Collectors.toList()));
            List<OsBtmTypeAttributeVO> btmTypeAttributeVOS = new ArrayList<>();
            Optional.ofNullable(attributeVOS).orElseGet(()->new ArrayList<>()).stream().forEach(attributeVO->{
                OsBtmTypeAttributeVO btmTypeAttributeVO = new OsBtmTypeAttributeVO();
                BeanUtil.convert(attributeVO,btmTypeAttributeVO);
                btmTypeAttributeVO.setPkBtmType(vo.getOid());
                btmTypeAttributeVO.setBtmTypeId(vo.getId());
                btmTypeAttributeVO.setAttrDataType(attributeVO.getAttributeDataType());
                btmTypeAttributeVO.setAttributeLength(attributeVO.getAttrLength());
                btmTypeAttributeVO.setDefaultValue(attributeVO.getDefaultValue());
                if("secretgrade".equalsIgnoreCase(attributeVO.getId())){
                    vo.setSecretFlag(true);
                }
                if(StringUtils.isNotBlank(attributeVO.getBtmTypeId())){
                    btmTypeAttributeVO.setReferFlag(true);
                    btmTypeAttributeVO.setReferBtmTypeId(attributeVO.getBtmTypeId());
                }
                if(StringUtils.isNotBlank(attributeVO.getEnumId())){
                    btmTypeAttributeVO.setEnumFlag(true);
                    btmTypeAttributeVO.setEnumItemMap(enumService.getEnumValueMap(btmTypeAttributeVO.getEnumId()));
                }
                btmTypeAttributeVOS.add(btmTypeAttributeVO);
            });
            vo.setAttributes(btmTypeAttributeVOS);
        }
        return vo;
    }
 
    /**
     * 使用编号获取业务类型
     *
     * @param btmIds 编号
     * @return 业务类型
     */
    @Override
    public List<OsBtmTypeVO> listBtmByIds(Collection<String> btmIds) {
        if(CollectionUtils.isEmpty(btmIds)){
            return null;
        }
        Map<String, OsBtmTypeVO> btmTypeVOMap = self.selectAllBtmMap();
        List<OsBtmTypeVO> btmTypeVOS = new ArrayList<>();
        btmIds.stream().forEach(id->{
            if(btmTypeVOMap.containsKey(id.toLowerCase())){
                btmTypeVOS.add(btmTypeVOMap.get(id.toLowerCase()));
            }
        });
        return btmTypeVOS;
    }
 
    /**
     * 使用编号获取业务类型
     *
     * @param id 编号
     * @return 业务类型
     */
    @Override
    public OsBtmTypeVO getBtmById(String id) {
        if(StringUtils.isBlank(id)){
            return null;
        }
        return self.selectAllBtmMap().getOrDefault(id.toLowerCase(),null);
    }
 
    /**
     * 获取业务类型的在哪个属性中使用
     *
     * @param btmName 业务类型
     * @return 引用的信息
     */
    @Override
    public List<OsUsedAttributeVO> listBtmUsedInfo(String btmName) {
        return listBtmUsedInfo(btmName,false);
    }
 
    /**
     * 获取业务类型的在哪个属性中使用
     *
     * @param btmId 业务类型
     * @param hasLink 是否包含链接类型中
     * @return 引用的信息
     */
    @Override
    public List<OsUsedAttributeVO> listBtmUsedInfo(String btmId, boolean hasLink){
        VciBaseUtil.alertNotNull(btmId,"业务类型的名称");
        List<OsAttributeVO> allReferThisBtmAttributes = Optional.ofNullable(attributeService.selectAllAttribute()).orElseGet(()->new ArrayList<>()).stream().filter(s->btmId.equalsIgnoreCase(s.getBtmTypeId())).collect(Collectors.toList());
        if(CollectionUtils.isEmpty(allReferThisBtmAttributes)){
            return null;
        }
        //根据这些属性,找它使用的业务类型
        List<OsUsedAttributeVO> usedInfos= new ArrayList<>();
        List<OsBtmTypeVO> btmTypeVOMap = self.selectAllBtmMap().values().stream().collect(Collectors.toList());
        List<OsLinkTypeVO> linkTypeVOS = linkTypeService.selectAllLinkMap().values().stream().collect(Collectors.toList());
        allReferThisBtmAttributes.stream().forEach(attribute->{
            //其他的业务类型包含了这个属性的
            List<OsBtmTypeVO> usedBtms = btmTypeVOMap.stream().filter(btmTypeVO -> !CollectionUtils.isEmpty(btmTypeVO.getAttributes()) && btmTypeVO.getAttributes().stream().anyMatch(s -> attribute.getId().equalsIgnoreCase(s.getId()))).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(usedBtms)){
                usedBtms.stream().forEach(btm->{
                    btm.getAttributes().stream().filter(s->attribute.getId().equalsIgnoreCase(s.getId())).forEach(attrInBtm->{
                        OsUsedAttributeVO usedAttributeVO = new OsUsedAttributeVO();
                        usedAttributeVO.setId(attrInBtm.getId());
                        usedAttributeVO.setName(attrInBtm.getName());
                        usedAttributeVO.setPkBtmType(btm.getId());
                        usedAttributeVO.setBusinessType(BooleanEnum.TRUE.getValue());
                        usedInfos.add(usedAttributeVO);
                    });
                });
            }
            if(hasLink){
                List<OsLinkTypeVO> usedLinks = linkTypeVOS.stream().filter(linkTypeVO -> !CollectionUtils.isEmpty(linkTypeVO.getAttributes()) &&linkTypeVO.getAttributes().stream().anyMatch(s->attribute.getId().equalsIgnoreCase(s.getId())) ).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(usedLinks)){
                    usedLinks.stream().forEach(link->{
                        link.getAttributes().stream().filter(s->attribute.getId().equalsIgnoreCase(s.getId())).forEach(attrInBtm->{
                            OsUsedAttributeVO usedAttributeVO = new OsUsedAttributeVO();
                            usedAttributeVO.setId(attrInBtm.getId());
                            usedAttributeVO.setName(attrInBtm.getName());
                            usedAttributeVO.setPkBtmType(link.getId());
                            usedAttributeVO.setBusinessType(BooleanEnum.FASLE.getValue());
                            usedInfos.add(usedAttributeVO);
                        });
                    });
                }
            }
        });
        return usedInfos;
    }
 
    /**
     * 根据业务类型获取包含的属性--不包含基础属性
     *
     * @param btmId 业务类型的编号
     * @return 属性的内容
     */
    @Override
    public List<OsBtmTypeAttributeVO> listAttributeByBtmId(String btmId) {
        VciBaseUtil.alertNotNull(btmId,"业务类型的编号");
        OsBtmTypeVO btmTypeVO = getBtmById(btmId);
        List<OsBtmTypeAttributeVO> attributes = btmTypeVO.getAttributes();
        if(attributes == null){
            attributes = new ArrayList<>();
        }
        return attributes.stream().sorted(((o1, o2) -> o1.getId().toLowerCase(Locale.ROOT).compareTo(o2.getId().toLowerCase(Locale.ROOT)))).collect(Collectors.toList());
    }
 
    /**
     * 根据业务类型获取包含的属性--包含基础属性
     *
     * @param btmId 业务类型的编号
     * @return 属性的内容
     */
    @Override
    public List<OsBtmTypeAttributeVO> listAttributeByBtmIdHasDefault(String btmId) {
        List<OsBtmTypeAttributeVO> attrVOs = listAttributeByBtmId(btmId);
        if(attrVOs == null){
            attrVOs = new ArrayList<>();
        }
        if(!CollectionUtils.isEmpty(attributeService.getDefaultAttributeVOs())) {
            List<OsBtmTypeAttributeVO> finalAttrVOs = attrVOs;
            attributeService.getDefaultAttributeVOs().stream().forEach(attr->{
                OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
                BeanUtil.convert(attr, attributeVO);
                attributeVO.setAttrDataType(attr.getAttributeDataType());
                attributeVO.setAttributeLength(attr.getAttrLength());
                attributeVO.setReferBtmTypeId(attr.getBtmTypeId());
                attributeVO.setReferBtmTypeName(attr.getBtmTypeName());
                finalAttrVOs.add(attributeVO);
            });
            attrVOs = finalAttrVOs;
        }
        return attrVOs;
    }
 
    /**
     * 清除缓存
     */
    @Override
    public void clearCache() {
 
    }
 
    /**
     * 参照业务类型
     *
     * @param conditionMap 查询条件
     * @param pageHelper   分页的对象
     * @return 业务类型的信息
     */
    @Override
    public DataGrid<OsBtmTypeVO> referDataGrid(Map<String, String> conditionMap, PageHelper pageHelper) {
        DataGrid<OsBtmTypeVO> dataGrid = queryObjectServiceInfoBySql(conditionMap, pageHelper, "plbtmtype",OsBtmTypeVO.class,((data, obj) -> {
            obj.setTableName(VciBaseUtil.getTableName(obj.getId()));
        }));
        return dataGrid;
    }
 
    /**
     * 使用主键查询
     *
     * @param oid 主键
     * @return 业务类型
     */
    @Override
    public OsBtmTypeVO selectByOid(String oid) {
        List<OsBtmTypeVO> btmTypeVOS = self.selectAllBtmMap().values().stream().collect(Collectors.toList());
        return Optional.ofNullable(btmTypeVOS).orElseGet(()->new ArrayList<>()).stream().filter(s->s.getOid().equalsIgnoreCase(oid)).findFirst().orElseGet(()->null);
    }
 
    /**
     * 使用编号获取枚举的名称
     *
     * @param id 枚举的英文
     * @return 枚举的名称
     */
    @Override
    public String getNameById(String id) {
        OsBtmTypeVO btmTypeVO = getBtmById(id);
        if(btmTypeVO == null){
            throw new VciBaseException("业务类型[{0}]在系统里不存在",new String[]{id});
        }
        return btmTypeVO.getName();
    }
 
    /**
     * 根据业务类型和链接类型生成ER图
     *
     * @param btmId 业务类型主键
     */
    @Override
    public OsERVO createERDiagram(String btmId) {
        VciBaseUtil.alertNotNull(btmId, "业务类型编号");
        OsBtmTypeVO btmTypeVO = getBtmById(btmId);
        List<OsERNodeVO> nodeVOList = new ArrayList<>();
        List<OsERRelationVO> relationVOList = new ArrayList<>();
        //看当前这个业务类型,参照了其他的哪些业务类型 .我们不显示引用当前业务类型的业务类型
        splicingBtmType2Json(nodeVOList, relationVOList, btmTypeVO,true);
        loadAllLinkTypeByBtmType(nodeVOList, relationVOList, btmTypeVO);
        OsERVO osERVO = new OsERVO();
        osERVO.setTabViewList(nodeVOList);
        osERVO.setTabRelViewList(relationVOList);
        return osERVO;
    }
 
    /**
     * 获取使用这个业务类型的E-R图
     *
     * @param btmId 业务类型编号
     * @return 执行结果
     */
    @Override
    public OsERVO createERUsed(String btmId) {
        VciBaseUtil.alertNotNull(btmId, "业务类型编号");
        OsBtmTypeVO btmTypeVO = getBtmById(btmId);
        //获取使用当前类型的属性
        List<OsUsedAttributeVO> usedAttributeVOS = listBtmUsedInfo(btmTypeVO.getId());
        List<OsERNodeVO> nodeVOList = new ArrayList<>();
        List<OsERRelationVO> relationVOList = new ArrayList<>();
        splicingBtmType2Json(nodeVOList, relationVOList, btmTypeVO,false);
        if(!CollectionUtils.isEmpty(usedAttributeVOS)){
            usedAttributeVOS.stream().forEach(usedAttr->{
                //业务类型和链接类型都有可能
                if(BooleanEnum.TRUE.getValue().equalsIgnoreCase(usedAttr.getBusinessType())){
                    //业务类型
                    OsBtmTypeVO linkBtmVO = self.selectAllBtmMap().get(usedAttr.getPkBtmType().toLowerCase(Locale.ROOT));
                    splicingBtmType2Json(nodeVOList, relationVOList, linkBtmVO,false);
                    OsERRelationVO relationVO = new OsERRelationVO();
                    relationVO.setTo(btmTypeVO.getId() + " " + btmTypeVO.getName());
                    relationVO.setFrom(linkBtmVO.getId() + " " + linkBtmVO.getName());
                    relationVO.setToText("引用");
                    relationVOList.add(relationVO);
                }else{
                    //是链接类型
                    OsLinkTypeVO linkTypeVO = linkTypeService.selectAllLinkMap().get(usedAttr.getPkBtmType().toLowerCase(Locale.ROOT));
                    List<OsLinkTypeVO> linkTypeVOList = new ArrayList<>();
                    linkTypeVOList.add(linkTypeVO);
                    splicingLinkType2Json(nodeVOList, relationVOList,linkTypeVOList,btmTypeVO,true);
                }
            });
        }
        OsERVO ervo = new OsERVO();
        ervo.setTabViewList(nodeVOList);
        ervo.setTabRelViewList(relationVOList);
        return ervo;
    }
 
    /**
     * 将业务类型拼接json
     *
     * @param nodeVOList  对象节点的信息
     * @param relationVOList  关系的信息
     * @param btmTypeVO 业务类型显示对象
     * @param hasRefer 包含参照
     */
    private void splicingBtmType2Json(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList, OsBtmTypeVO btmTypeVO,boolean hasRefer) {
        OsERNodeVO nodeVO = new OsERNodeVO();
        nodeVO.setKey(btmTypeVO.getId() + " " + btmTypeVO.getName());
        List<OsERNodePropertyVO> itemList = new ArrayList<>();
        btmTypeVO.getAttributes().forEach(attribute -> {
            OsERNodePropertyVO nodePropertyVO = new OsERNodePropertyVO();
            nodePropertyVO.setName(attribute.getId() + " " + attribute.getName());
            nodePropertyVO.setKey("oid".equals(attribute.getId().toLowerCase()));
            if(StringUtils.isNotBlank(attribute.getReferBtmTypeId())){
                //参照的属性,设置为黄色
                nodePropertyVO.setColor("#FEDD32FF");
            }else{
                nodePropertyVO.setColor("#000");
            }
            itemList.add(nodePropertyVO);
            //判断参照
            if(hasRefer) {
                selectReferenceBtmType(attribute, btmTypeVO, nodeVOList, relationVOList);
            }
        });
        nodeVO.setItems(itemList);
        nodeVOList.add(nodeVO);
    }
 
    /**
     * 判断业务类型的属性是不是参照类型,并将参照添加到ER图中
     *
     * @param attribute     业务类型属性
     * @param nodeVOList  节点信息
     * @param btmTypeVO 业务类型
     * @param relationVOList 关系信息
     */
    private void selectReferenceBtmType(OsBtmTypeAttributeVO attribute, OsBtmTypeVO btmTypeVO,
                                        List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) {
        if (StringUtils.isNotBlank(attribute.getReferBtmTypeId())) {
            //是参照类型的
            OsBtmTypeVO referenceBtmType = getBtmById(attribute.getReferBtmTypeId());
            List<OsBtmTypeAttributeVO> referenceBtmAttributes = referenceBtmType.getAttributes();
            //向表json中添加
            OsERNodeVO nodeVO = new OsERNodeVO();
            nodeVO.setKey(referenceBtmType.getId() + " " + referenceBtmType.getName());
 
            List<OsERNodePropertyVO> items = new ArrayList<>();
            if(referenceBtmType.getId().equalsIgnoreCase(btmTypeVO.getId())){
                //参照自己的内容
                OsERRelationVO relationVO = new OsERRelationVO();
                relationVO.setTo(referenceBtmType.getId() + " " + referenceBtmType.getName());
                relationVO.setFrom(btmTypeVO.getId() + " " + btmTypeVO.getName());
                relationVO.setToText("自参照");
                relationVOList.add(relationVO);
            }else {
                referenceBtmAttributes.forEach(attr -> {
                    OsERNodePropertyVO nodePropertyVO = new OsERNodePropertyVO();
                    nodePropertyVO.setName(attr.getId() + " " + attr.getName());
                    nodePropertyVO.setKey("oid".equals(attr.getId().toLowerCase()));
                    nodePropertyVO.setColor("#000");
                    items.add(nodePropertyVO);
                });
                nodeVO.setItems(items);
                nodeVOList.add(nodeVO);
                //关系
                OsERRelationVO relationVO = new OsERRelationVO();
                relationVO.setTo(referenceBtmType.getId() + " " + referenceBtmType.getName());
                relationVO.setFrom(btmTypeVO.getId() + " " + btmTypeVO.getName());
                relationVO.setToText("参照");
                relationVOList.add(relationVO);
            }
        }
    }
 
    /**
     * 加载业务类型所关联的链接类型
     *
     * @param nodeVOList  节点信息
     * @param relationVOList 关系的信息
     * @param btmTypeVO    业务类型
     */
    private void loadAllLinkTypeByBtmType(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList, OsBtmTypeVO btmTypeVO) {
        Map<String, OsLinkTypeVO> linkTypeVOMap = linkTypeService.selectAllLinkMap();
        Collection<OsLinkTypeVO> linkTypeVOS = linkTypeVOMap.values();
        Set<OsLinkTypeVO> fromLinkTypeVOList = linkTypeVOS.stream().filter(link ->
            Arrays.stream(link.getFromBtmType().split(",")).anyMatch(s->s.equalsIgnoreCase(btmTypeVO.getId()))
        ).collect(Collectors.toSet());
        Set<OsLinkTypeVO> toLinkTypeList = linkTypeVOS.stream().filter(link ->
                Arrays.stream(link.getToBtmType().split(",")).anyMatch(s->s.equalsIgnoreCase(btmTypeVO.getId()))).collect(Collectors.toSet());
        List<OsLinkTypeVO> linkTypeVOList = new ArrayList<>();
        linkTypeVOList.addAll(fromLinkTypeVOList);
        linkTypeVOList.addAll(toLinkTypeList);
        if (!CollectionUtils.isEmpty(linkTypeVOList)) {
            splicingLinkType2Json(nodeVOList, relationVOList,linkTypeVOList,btmTypeVO,false);
        }
 
    }
 
    /**
     * 将链接类型拼接成json
     *
     * @param nodeVOList  节点信息
     * @param relationVOList  关系信息
     * @param linkTypeVOs 链接类型
     * @param btmTypeVO 业务类型的显示对象
     * @param used 是否为被使用
     */
    private void splicingLinkType2Json(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList,
                                       List<OsLinkTypeVO> linkTypeVOs,OsBtmTypeVO btmTypeVO,boolean used) {
        linkTypeVOs.forEach(link -> {
            List<OsLinkTypeAttributeVO> attributeList = link.getAttributes();
            OsERNodeVO nodeVO= new OsERNodeVO();
            nodeVO.setKey(link.getId() + " " + link.getName());
            List<OsERNodePropertyVO> items = new ArrayList<>();
            attributeList.forEach(attr -> {
                OsERNodePropertyVO nodePropertyVO = new OsERNodePropertyVO();
                nodePropertyVO.setName(attr.getId() + " " + attr.getName());
                nodePropertyVO.setKey("oid".equals(attr.getId().toLowerCase()));
                if(StringUtils.isNotBlank(attr.getReferBtmTypeId())) {
                    nodePropertyVO.setColor("#FEDD32FF");
                }else {
                    nodePropertyVO.setColor("#1c446f");
                }
                items.add(nodePropertyVO);
                //判断参照
                if(!used) {
                    selectReferenceLinkType(attr, link, nodeVOList, relationVOList);
                }
            });
            nodeVO.setItems(items);
            //链接类型和业务类型加关系
            OsERRelationVO relationVO = new OsERRelationVO();
            relationVO.setFrom(link.getId() + " " + link.getName());
            relationVO.setTo(btmTypeVO.getId() + " " + btmTypeVO.getName());
 
            nodeVOList.add(nodeVO);
 
            if(used){
                relationVO.setText("被引用");
            }
            //如果当前的from端,那么就显示to端的
            //如果当前的是to端的,那么就显示from端的内容
            if(Arrays.stream(link.getFromBtmType().split(",")).anyMatch(s->s.equalsIgnoreCase(btmTypeVO.getId()))){
                //这个是from端
               if(!used) {
                   relationVO.setToText("from端");
               }
                //找这个链接类型的to端的业务类型
               link.getToBtmTypeVOS().stream().forEach(toBtm->{
                    splicingBtmType2JsonForLink(nodeVOList,relationVOList,link,toBtm,true);
               });
            }else{
                if(!used) {
                    relationVO.setToText("to端");
                }
                link.getFromBtmTypeVOS().stream().forEach(fromBtm->{
                    splicingBtmType2JsonForLink(nodeVOList,relationVOList,link,fromBtm,false);
                });
            }
            relationVOList.add(relationVO);
        });
    }
 
    /**
     * 链接类型关键的业务类型
     * @param nodeVOList 对象列表
     * @param relationVOList 关联关系列表
     * @param link 链接类型
     * @param btmTypeVO 业务类型
     * @param to 是否为to端
     */
    private void splicingBtmType2JsonForLink(List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList, OsLinkTypeVO link, OsBtmTypeVO btmTypeVO, boolean to) {
        OsERNodeVO nodeVO = new OsERNodeVO();
        nodeVO.setKey(btmTypeVO.getId() + " " + btmTypeVO.getName());
        List<OsERNodePropertyVO> itemList = new ArrayList<>();
        btmTypeVO.getAttributes().forEach(attribute -> {
            OsERNodePropertyVO items = new OsERNodePropertyVO();
            items.setName(attribute.getId() + " " + attribute.getName());
            items.setKey("oid".equals(attribute.getId().toLowerCase()));
            items.setColor("#000");
            itemList.add(items);
            //不加参照判断了
        });
        nodeVO.setItems(itemList);
        OsERRelationVO relationVO = new OsERRelationVO();
        relationVO.setFrom(link.getId() + " " + link.getName());
        relationVO.setTo(btmTypeVO.getId() + " " + btmTypeVO.getName());
        relationVO.setToText(to?"to端":"from端");
        relationVOList.add(relationVO);
        nodeVOList.add(nodeVO);
    }
 
    /**
     * 判断链接类型的属性是不是参照类型,并将参照添加到ER图中
     *
     * @param attr          链接类型的属性
     * @param linkTypeVO 链接类型的内容
     * @param nodeVOList 节点对象
     * @param relationVOList 关系对象
     */
    private void selectReferenceLinkType(OsLinkTypeAttributeVO attr, OsLinkTypeVO linkTypeVO,List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) {
        if (StringUtils.isNotBlank(attr.getReferBtmTypeId())) {
            //是参照类型的
            OsBtmTypeVO referenceBtmType = getBtmById(attr.getReferBtmTypeId());
            List<OsBtmTypeAttributeVO> attributeList = referenceBtmType.getAttributes();
            //向表json中添加
            OsERNodeVO nodeVO = new OsERNodeVO();
            nodeVO.setKey(referenceBtmType.getId() + " " + referenceBtmType.getName());
            List<OsERNodePropertyVO> items = new ArrayList<>();
            attributeList.forEach(attribute -> {
                OsERNodePropertyVO item = new OsERNodePropertyVO();
                item.setName(attribute.getId() + " " + attribute.getName());
                item.setKey("oid".equals(attribute.getId().toLowerCase()));
                item.setColor("#000");
                items.add(item);
            });
            nodeVO.setItems(items);
            nodeVOList.add(nodeVO);
            //向关系json中添加
            OsERRelationVO relationVO = new OsERRelationVO();
            relationVO.setTo(referenceBtmType.getId() + " " + referenceBtmType.getName());
            relationVO.setFrom(linkTypeVO.getId() + " " + linkTypeVO.getName());
            relationVO.setToText("参照");
            relationVOList.add(relationVO);
        }
    }
 
}