ludc
2024-10-30 0888cf078640e6db9fba2b7fcaa29f449e017371
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
package com.vci.web.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.vci.client.common.oq.OQTool;
import com.vci.common.qt.object.*;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.query.ObjectQueryService;
import com.vci.corba.query.data.BOAndLO;
import com.vci.omd.utils.ObjectTool;
import com.vci.starter.web.constant.QueryOptionConstant;
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.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.properties.WebProperties;
import com.vci.web.query.UILinkTypeDataQuery;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.service.WebLoServiceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.omg.CORBA.IntHolder;
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 java.util.*;
import java.util.stream.Collectors;
 
/***
 * 链接类型查询
 * @author weidy
 *
 */
@Service
public class WebLoServiceImpl implements WebLoServiceI {
 
    /**
     * 多语言前缀
     */
    private final String msgCodePrefix = "com.vci.web.loService.";
 
    /**
     * 日志对象
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
 
    @Autowired
    private WebBoServiceI boService;
 
    @Autowired
    private WebProperties webProperties;
 
    /**
     * 平台调用客户端
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 链接对象默认属性
     */
    public static final Map<String,String> LO_BASE_FIELD_MAP = new HashMap<>();
 
    public WebLoServiceImpl(){
        LO_BASE_FIELD_MAP.put("oid","oid");
        LO_BASE_FIELD_MAP.put("creator","creator");
        LO_BASE_FIELD_MAP.put("createTime","createTime");
        LO_BASE_FIELD_MAP.put("lastModifier","lastModifier");
        LO_BASE_FIELD_MAP.put("lastModifyTime","lastModifyTime");
        LO_BASE_FIELD_MAP.put("fromOid","f_oid");
        LO_BASE_FIELD_MAP.put("fromRevisionOid","f_revisionoid");
        LO_BASE_FIELD_MAP.put("fromNameOid","f_nameoid");
        LO_BASE_FIELD_MAP.put("fromBTMName","f_btwname");
        LO_BASE_FIELD_MAP.put("toRevisionOid","t_revisionoid");
        LO_BASE_FIELD_MAP.put("toNameOid","t_nameoid");
        LO_BASE_FIELD_MAP.put("toBTMName","t_btwname");
        LO_BASE_FIELD_MAP.put("toOid","t_oid");
        LO_BASE_FIELD_MAP.put("ts","ts");
        LO_BASE_FIELD_MAP.put("linkTypeName","linkTypeName");
    }
 
 
    @Override
    public List<LinkObject> queryCLO(String linkType,
                                           Map<String, String> conditionMap) throws VciBaseException {
        return queryCLO(linkType, "", 1, conditionMap);
    }
 
    @Override
    public List<BusinessObject> queryLinkCbo(String linkType,
                                             String toBtmname, Map<String, String> conditionMap)
            throws VciBaseException {
        return queryLinkCbo(linkType, toBtmname, 1, conditionMap);
    }
 
    @Override
    public List<LinkObject> queryCLO(String linkType, String toBtmName,
            int level, Map<String, String> conditionMap) throws VciBaseException {
        return queryCLO(linkType, toBtmName, level, false, conditionMap);
    }
 
    @Override
    public List<LinkObject> queryCLO(String linkType, String toBtmName,
            int level, boolean isDirection,Map<String, String> conditionMap) throws VciBaseException {
        return queryCLO(linkType,toBtmName,level,isDirection,conditionMap,new PageHelper(-1));
    }
 
    /***
     * 链接查询,支持限定某端的业务类型,限定层级,排序,反向,查询条件,但是不支持枚举和参照字段的显示
     * @param linkType 链接类型名称
     * @param toBtmName 另一端的业务类型
     * @param level 查询层级
     * @param isDirection 是否反向
     * @param conditionMap 查询条件,注意f_oid需要在其中,或者from端的其他属性
     * @param ph 排序和分页,链接一般不建议分页
     */
    @Override
    public List<LinkObject> queryCLO(String linkType, String toBtmName,
            int level, boolean isDirection,Map<String, String> conditionMap,PageHelper ph) throws VciBaseException {
        List<LinkObject> rtnOBJs = new ArrayList<LinkObject>();
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryLO");
        qt.setType(QTConstants.TYPE_LINK);
        qt.setLinkType(linkType.toLowerCase());
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        qt.setDirection(isDirection?"opposite":"positive");
        qt.setLevel(level);
        conditionMap = WebUtil.getNotNullMap(conditionMap);
        if(WebUtil.isNotNull(toBtmName)){
            toBtmName = toBtmName.toLowerCase().trim();
            if(toBtmName.indexOf(",")>-1){
                toBtmName = QueryOptionConstant.IN + "(" + WebUtil.getInt(toBtmName) + ")";
            }
        }
        if(isDirection && WebUtil.isNotNull(toBtmName)){
            conditionMap.put("f_btwname", toBtmName.toLowerCase().trim());
        }else if(!isDirection && WebUtil.isNotNull(toBtmName)){
            conditionMap.put("t_btwname", toBtmName.toLowerCase().trim());
        }
        qt.setRightFlag(webProperties.isDataRight());
        //设置分页信息和排序
        if(ph!=null){
            if(ph.getLimit()>0){
                PageInfo pageInfo = new PageInfo();
                pageInfo.setPageNO(ph.getPage());
                pageInfo.setRowCount(ph.getLimit());
                qt.setPageInfo(pageInfo);
            }
            if(WebUtil.isNotNull(ph.getSort()) && WebUtil.isNotNull(ph.getOrder())){
                //设置了排序
                String[] sort = ph.getSort().split(",");
                String[] order = ph.getOrder().split(",");
                if(sort.length != order.length){
                    throw new VciBaseException(msgCodePrefix + ".sortlengtherror",new Object[]{sort.length,order.length});
                }
                List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
                for(int i = 0 ; i < sort.length ;i++){
                    OrderInfo oi =  new OrderInfo();
                    oi.setOrderField(sort[i]);
                    oi.setOrderMode(order[i]);
                    oi.setLevel(sort.length -i);//值越大优先级越大,而排在数组的前面的优先级越大
                    orderInfoList.add(oi);
                }
                qt.setOrderInfoList(orderInfoList);
            }
        }
        Condition condition = boService.getConditionByMap(conditionMap);
        qt.setCondition(condition);
        try {
            LinkObject[] bos = platformClientUtil.getQueryService().findLTObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML());
            if (bos != null && bos.length > 0) {
                for (LinkObject bo : bos) {
                    LinkObject clo = new LinkObject();
                    clo = bo;
 
                    rtnOBJs.add(clo);
                }
                return rtnOBJs;
            }
        } catch (PLException e) {
            logger.error(e.code,e);
            throw WebUtil.getVciBaseException(e);
        }
        return rtnOBJs;
    }
 
 
    @Override
    public List<BusinessObject> queryLinkCbo(String linkType,
            String toBtmname, int level, Map<String, String> conditionMap)
            throws VciBaseException {
        return queryLinkCbo(linkType, toBtmname, level, false, conditionMap);
    }
 
    @Override
    public List<BusinessObject> queryLinkCbo(String linkType,
            String toBtmName, int level,boolean isDirection, Map<String, String> conditionMap)
            throws VciBaseException {
        List<BusinessObject> rtnOBJs = new ArrayList<BusinessObject>();
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryLO");
        qt.setType(QTConstants.TYPE_LINK);
        qt.setBtmType(linkType.toLowerCase());
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        qt.setDirection(isDirection?"opposite":"positive");
        qt.setLevel(level);
        conditionMap = WebUtil.getNotNullMap(conditionMap);
        if(isDirection && WebUtil.isNotNull(toBtmName)){
            conditionMap.put("f_btmname", toBtmName.toLowerCase().trim());
        }else if(!isDirection && WebUtil.isNotNull(toBtmName)){
            conditionMap.put("t_btmname", toBtmName.toLowerCase().trim());
        }
        Condition condition = boService.getConditionByMap(conditionMap);
        qt.setCondition(condition);
        try {
            String btmOid = "";
            if(isDirection && conditionMap.containsKey("t_oid")){
                btmOid = conditionMap.get("t_oid");
            }else if(!isDirection && conditionMap.containsKey("f_oid")){
                btmOid = conditionMap.get("f_oid");
            }
            BOAndLO[] bos = platformClientUtil.getQueryService().getBOAndLOS(qt.getId(), OQTool.qtTOXMl(qt).asXML(),btmOid);
            if (bos != null && bos.length > 0) {
                for (BOAndLO blo : bos) {
                    BusinessObject cbo = new BusinessObject();
                    cbo = blo.bo;
                    rtnOBJs.add(cbo);
                }
                return rtnOBJs;
            }
        } catch (PLException e) {
//            logger.error(e.error_code,e);
//            throw WebUtil.getVciBaseException(e);
        }
        return rtnOBJs;
    }
//
//    @Override
//    public Map<String, BusinessObject> queryLinkedCbo(LinkObject[] lo,
//            boolean isDirection) throws VciBaseException {
//        LinkObject[] clos = new LinkObject[lo.length];
//        for(int i =0 ; i < lo.length; i ++){
//            LinkObject clo = new LinkObject();
//            clo = lo[i];
//            clos[i] = clo;
//        }
//        return queryLinkedCbo(clos,isDirection);
//    }
 
    @Override
    public Map<String, BusinessObject> queryLinkedCbo(List los,
            boolean isDirection) throws VciBaseException {
        return queryLinkedCbo(los,isDirection,new ArrayList<String>());
    }
 
    @Override
    public Map<String, BusinessObject> queryLinkedCbo(List los,
            boolean isDirection,List<String> queryColumn) throws VciBaseException {
        LinkObject[] clos = new LinkObject[los.size()];
        for(int i = 0 ; i < los.size(); i ++){
            Object o = los.get(i);
            LinkObject clo = new LinkObject();
            if(o instanceof LinkObject){
                clo = (LinkObject)o;
            }else if(o instanceof LinkObject){
                clo = (LinkObject)o;
            }
            clos[i] = clo;
        }
        return queryLinkedCbo(clos,isDirection,queryColumn);
    }
 
    @Override
    public Map<String, BusinessObject> queryLinkedCbo(
            LinkObject[] clol, boolean isDirection) throws VciBaseException {
        return queryLinkedCbo(clol,isDirection,new ArrayList<String>());
    }
    /*****
     *
     */
    @Override
    public Map<String, BusinessObject> queryLinkedCbo(
            LinkObject[] clol, boolean isDirection,List<String> queryColumn) throws VciBaseException{
        Map<String/*t_oid或者f_oid*/,String/*oid*/> linkBoOidMap = new HashMap<String, String>();
        Map<String,String> btmTypeOidMap = new HashMap<String, String>();
        for(int i = 0 ; i < clol.length; i ++){
            LinkObject clo = clol[i];
            if(clo!=null){
                String btmType = "";
                String btmOid = "";
                if(isDirection){
                    linkBoOidMap.put(clo.toOid,clo.oid);
                    btmType = clo.toBTName.toLowerCase().trim();
                    btmOid = clo.toOid;
                }else{
                    linkBoOidMap.put(clo.fromOid,clo.oid);
                    btmType = clo.fromBTName.toLowerCase().trim();
                    btmOid = clo.fromOid;
                }
                String oids = "";
                if(btmTypeOidMap.containsKey(btmType)){
                    oids = btmTypeOidMap.get(btmType);
                }
                oids += "'" + btmOid + "',";
                btmTypeOidMap.put(btmType, oids);
            }
        }
        Map<String,BusinessObject> linkedCboMap = new HashMap<>();
        Iterator<String> it = btmTypeOidMap.keySet().iterator();
        while(it.hasNext()){
            String btmType = it.next();
            String oids = btmTypeOidMap.get(btmType);
            List<String> clauseList = new ArrayList<String>();
            if(queryColumn!=null && queryColumn.size()>0){
                for(String s : queryColumn){
                    if(s.toLowerCase().indexOf("${" + btmType + "}")>-1 || s.toLowerCase().indexOf("${")<0){
                        clauseList.add(s);
                    }
                }
            }else{
                clauseList.add("*");
            }
            Map<String,String> conditionMap = new HashMap<>();
            conditionMap.put("oid",oids);
            List<BusinessObject> allCbo = boService.queryCBO(btmType, conditionMap,new PageHelper(-1),clauseList);
            if(allCbo.size()>0){
                for(BusinessObject cbo : allCbo){
                    String linkOid = linkBoOidMap.get(cbo.oid);
                    linkedCboMap.put(linkOid, cbo);
                }
            }
        }
        return linkedCboMap;
    }
 
    @Override
    public List<Map> clos2Map(List<LinkObject> clos) throws VciBaseException {
        List<Map> allMap = new ArrayList<Map>();
        for(LinkObject clo : clos){
            allMap.add(clo2Map(clo));
        }
        return allMap;
    }
 
    @Override
    public Map clo2Map(LinkObject clo) throws VciBaseException {
        Map<String,String> map = new HashMap<String, String>();
        WebUtil.copyValueToMapFromClos(clo, map);
        return map;
    }
 
    @Override
    public List<LinkObject> map2Clos(List<Map> map) throws VciBaseException {
        List<LinkObject> allClo = new ArrayList<LinkObject>();
        for(Map m : map){
            allClo.add(map2Clo(m));
        }
        return allClo;
    }
 
    @Override
    public LinkObject map2Clo(Map map) throws VciBaseException {
        LinkObject clo = new LinkObject();
        WebUtil.copyValueToCloFromMap(clo, map);
        return clo;
    }
 
    /**
     * 保存链接类型对象
     *
     * @param clos 保存的业务类型对象
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<LinkObject> saveLinkObjects(List<LinkObject> clos) throws VciBaseException {
        if(clos == null || clos.size()  == 0){
            throw new VciBaseException("没有要保存的业务类型数据");
        }
        List<LinkObject> linkObjects = new ArrayList<LinkObject>();
        for(LinkObject clo : clos){
            //需要看看基本的信息是否有
            if(StringUtils.isBlank(clo.ltName)){
                throw new VciBaseException("链接类型的名称为空");
            }
            if(StringUtils.isBlank(clo.oid)){
                clo.oid = (new ObjectUtility()).getNewObjectID36();
            }
            if(StringUtils.isBlank(clo.creator)){
                clo.creator = WebUtil.getCurrentUserId();
            }
            if(clo.createTime == 0){
                clo.createTime = VciDateUtil.getNowTime();
            }
            if(StringUtils.isBlank(clo.modifier)){
                clo.modifier = clo.creator;
            }
            if(clo.modifyTime == 0){
                clo.modifyTime = clo.createTime;
            }
            if(clo.ts == 0){
                clo.ts = clo.createTime;
            }
            linkObjects.add(clo);
        }
        try {
            LinkObject[] savedLinkObject = platformClientUtil.getBOFactoryService().batchCreateLinkObject(linkObjects.toArray(new LinkObject[0]));
            List<LinkObject> savedListLinkObject = new ArrayList<LinkObject>();
            if(savedLinkObject != null && savedLinkObject.length > 0){
                for(LinkObject linkObject : savedLinkObject){
                    LinkObject clo = new LinkObject();
                    clo = linkObject;
                    savedListLinkObject.add(clo);
                }
            }
            return savedListLinkObject;
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
    }
 
    /**
     * 创建连接类型
     *
     * @param loName
     * @return
     * @throws VciBaseException
     */
    @Override
    public LinkObject createLinkObject(String loName) throws VciBaseException {
        WebUtil.alertNotNull(loName,"链接");
        return null;
        //todo 在平台里面需要传入对象,现在是字符串,需要看平台如何处理
//            return loOperation.createLinkObject(loName,WebUtil.getCurrentUserId());
    }
 
    /**
     * 拷贝链接类型
     *
     * @param clo 链接类型对象
     * @return
     * @throws VciBaseException
     */
    @Override
    public LinkObject cloneLinkObject(LinkObject clo) throws VciBaseException {
        LinkObject newClo = new LinkObject();
        String JSONString = JSONObject.toJSONStringWithDateFormat(clo,VciDateUtil.DateTimeMillFormat,SerializerFeature.WriteDateUseDateFormat);
        LinkObject lo = JSONObject.parseObject(JSONString,LinkObject.class);
        if(lo.newAttrValList == null) {
            lo.newAttrValList = new AttributeValue[0];
        }
        if(lo.hisAttrValList == null) {
            lo.hisAttrValList =  new AttributeValue[0];
        }
        newClo = lo;
        newClo.oid = (new ObjectUtility()).getNewObjectID36();
        newClo.creator = WebUtil.getCurrentUserId();
        newClo.createTime = VciDateUtil.getNowTime();
        newClo.modifier = newClo.creator;
        newClo.modifyTime = newClo.createTime;
        newClo.ts = newClo.createTime;
        return  newClo;
    }
 
    /**
     * 删除链接类型
     *
     * @param clos 链接类型的内容
     * @throws VciBaseException
     */
    @Override
    public void deleteLinkObjects(List<LinkObject> clos) throws VciBaseException {
        if(clos!=null){
            try {
                platformClientUtil.getBOFactoryService().batchDeleteLinkObject(clos.toArray(new LinkObject[0]));
            } catch (PLException vciError) {
                throw  WebUtil.getVciBaseException(vciError);
            }
        }
    }
 
    /**
     * @param clos
     * @return
     * @throws VciBaseException
     */
    @Override
    public void updateLinkObject(List<LinkObject> clos) throws VciBaseException {
        if(clos!=null){
            try {
                platformClientUtil.getBOFactoryService().batchUpdateLinkObject(clos.toArray(new LinkObject[0]));
            } catch (PLException vciError) {
                throw  WebUtil.getVciBaseException(vciError);
            }
        }
    }
 
    /**
     * 查询链接类型和业务类型
     *
     * @param linkTypeDataQuery 查询对象
     * @return 链接类型和关联的to端
     */
    @Override
    public List<com.vci.corba.query.data.BOAndLO> queryCLOAndBOBySchema(UILinkTypeDataQuery linkTypeDataQuery) {
        VciBaseUtil.alertNotNull(linkTypeDataQuery,"链接类型查询对象",linkTypeDataQuery.getQueryTemplateName(),"查询模板的名称");
        QueryTemplate qt =boService.getQtByName(linkTypeDataQuery.getQueryTemplateName(),linkTypeDataQuery.getReplaceMap());
        return queryCLOAndBOByQueryTemplate(qt,linkTypeDataQuery);
    }
 
    /**
     * 使用查询模板查询
     * @param qt 查询模板
     * @param linkTypeDataQuery 链接类型的查询对象
     * @return 链接类型和业务类型
     */
    private List<com.vci.corba.query.data.BOAndLO> queryCLOAndBOByQueryTemplate(QueryTemplate qt,UILinkTypeDataQuery linkTypeDataQuery){
        if(StringUtils.isNotBlank(linkTypeDataQuery.getToBtmType()) && StringUtils.isBlank(qt.getBtmType())) {
            qt.setBtmType(linkTypeDataQuery.getToBtmType());
        }
        if(linkTypeDataQuery.getClauseList()!=null){
            qt.setClauseList(linkTypeDataQuery.getClauseList().stream().collect(Collectors.toList()));
        }else {
            List<String> clauseList = new ArrayList<String>();
            clauseList.add("*");
            qt.setClauseList(clauseList);
        }
        if(!"opposite".equals(qt.getDirection())) {
            qt.setDirection(linkTypeDataQuery.isDirection() ? "opposite" : "positive");
        }
        if(linkTypeDataQuery.getLevel()>0){
            qt.setLevel(linkTypeDataQuery.getLevel());
        }else{
            if(linkTypeDataQuery.isQueryAllLevel()){
                qt.setLevel(-1);
            }else{
                qt.setLevel(1);
            }
        }
 
        Map<String,String> conditionMap = WebUtil.getNotNullMap(linkTypeDataQuery.getConditionMap());
        if(StringUtils.isBlank(linkTypeDataQuery.getQueryTemplateName())) {
            if (linkTypeDataQuery.isDirection() && StringUtils.isNotBlank(linkTypeDataQuery.getToBtmType())) {
                if (linkTypeDataQuery.getToBtmType().contains(",")) {
                    conditionMap.put("f_btwname", QueryOptionConstant.IN + "(" + VciBaseUtil.str2List(linkTypeDataQuery.getToBtmType()) + ")");
                } else {
                    conditionMap.put("f_btwname", linkTypeDataQuery.getToBtmType().trim());
                }
            } else if (!linkTypeDataQuery.isDirection() && StringUtils.isNotBlank(linkTypeDataQuery.getToBtmType())) {
                if (linkTypeDataQuery.getToBtmType().contains(",")) {
                    conditionMap.put("t_btwname", QueryOptionConstant.IN + "(" + VciBaseUtil.str2List(linkTypeDataQuery.getToBtmType()) + ")");
                } else {
                    conditionMap.put("t_btwname", linkTypeDataQuery.getToBtmType().trim());
                }
            }
        }
        Condition condition = boService.getConditionByMap(conditionMap);
        if(qt.getCondition() !=null) {
            qt.setCondition(OQTool.mergeCondition(qt.getCondition(), condition, Connector.AND));
        }else {
            qt.setCondition(condition);
        }
        boService.setPageAndOrderToQT(qt,linkTypeDataQuery.getPageHelper());
        try {
            com.vci.corba.query.data.BOAndLO[] bos = platformClientUtil.getQueryService().getBOAndLOS(qt.getId(), OQTool.qtTOXMl(qt).asXML(),linkTypeDataQuery.getParentOid()==null?"":linkTypeDataQuery.getParentOid());
            return Arrays.stream(bos).collect(Collectors.toList());
        } catch (PLException e) {
//            logger.error(e.error_code,e);
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 使用链接类型的名称查询 链接类型的to端的业务类型
     * @param linkTypeDataQuery 查询的对象
     * @return 链接对象和to端业务对象
     */
    @Override
    public List<com.vci.corba.query.data.BOAndLO> queryCLOAndBoByLinkType(UILinkTypeDataQuery linkTypeDataQuery){
        VciBaseUtil.alertNotNull(linkTypeDataQuery,"链接类型查询对象",linkTypeDataQuery.getLinkType(),"链接类型的名称");
        QueryTemplate qt = null;
        if(StringUtils.isBlank(linkTypeDataQuery.getQueryTemplateName())){
            qt = new QueryTemplate();
            //基础设置
            qt.setId("queryLinkAndBo");
            qt.setType(QTConstants.TYPE_LINK);
            qt.setLinkType(linkTypeDataQuery.getLinkType());
        }else{
            qt = boService.getQtByName(linkTypeDataQuery.getQueryTemplateName(),linkTypeDataQuery.getReplaceMap());
        }
 
        return queryCLOAndBOByQueryTemplate(qt,linkTypeDataQuery);
    }
 
    private boolean isEnumAttr(String s){
        return s.indexOf("_")>-1
                && !"lcStatus_text".toLowerCase().equalsIgnoreCase(s.toLowerCase()) && !s.toLowerCase().startsWith("t_") && !s.toLowerCase().startsWith("f_");
    }
 
    /**
     * 查询列表
     *
     * @param linkTypeDataQuery 查询的对象
     * @return 列表的数据
     */
    @Override
    public DataGrid queryGridByScheme(UILinkTypeDataQuery linkTypeDataQuery) {
        VciBaseUtil.alertNotNull(linkTypeDataQuery,"链接类型查询对象");
        QueryTemplate qt =null;
        if(StringUtils.isBlank(linkTypeDataQuery.getQueryTemplateName())){
            qt = new QueryTemplate();
            //基础设置
            qt.setId("queryLinkAndBos");
            qt.setType(QTConstants.TYPE_LINK);
            qt.setLinkType(linkTypeDataQuery.getLinkType());
        }else{
            qt = boService.getQtByName(linkTypeDataQuery.getQueryTemplateName(),linkTypeDataQuery.getReplaceMap());
            linkTypeDataQuery.setLinkType(qt.getLinkType());
        }
        if(!"opposite".equals(qt.getDirection())) {
            qt.setDirection(linkTypeDataQuery.isDirection() ? "opposite" : "positive");
        }
        if(linkTypeDataQuery.getLevel()>0){
            qt.setLevel(linkTypeDataQuery.getLevel());
        }else{
            if(linkTypeDataQuery.isQueryAllLevel()){
                qt.setLevel(-1);
            }else{
                qt.setLevel(1);
            }
        }
        List<String> referFields = new ArrayList<>();
        List<String> enumFields = new ArrayList<>();
        if(!CollectionUtils.isEmpty(linkTypeDataQuery.getClauseList())){
            referFields = linkTypeDataQuery.getClauseList().stream().filter(s->s.toLowerCase().startsWith("f_oid.") || s.toLowerCase().startsWith("t_oid.")).collect(Collectors.toList());
            enumFields = linkTypeDataQuery.getClauseList().stream().filter(s->isEnumAttr(s)).collect(Collectors.toList());
            List<String> finalReferFields = referFields;
            List<String> finalEnumFields1 = enumFields;
            qt.setClauseList(linkTypeDataQuery.getClauseList().stream().filter(s->!finalReferFields.contains(s) && !finalEnumFields1.contains(s)).collect(Collectors.toList()));
        }else {
            List<String> clauseList = new ArrayList<String>();
            clauseList.add("*");
            qt.setClauseList(clauseList);
        }
        if(!CollectionUtils.isEmpty(qt.getClauseList())){
            List<String> clauseUpList = new ArrayList<>();
            qt.getClauseList().stream().forEach(field->{
                clauseUpList.add(field.toUpperCase());
            });
            qt.setClauseList(clauseUpList);
        }
 
        Map<String,String> conditionMap = WebUtil.getNotNullMap(linkTypeDataQuery.getConditionMap());
        if(linkTypeDataQuery.isDirection() && StringUtils.isNotBlank(linkTypeDataQuery.getToBtmType())){
            if(linkTypeDataQuery.getToBtmType().contains(",")){
                conditionMap.put("f_btwname", QueryOptionConstant.IN + "(" + VciBaseUtil.str2List(linkTypeDataQuery.getToBtmType()) + ")");
            }else{
                conditionMap.put("f_btwname", linkTypeDataQuery.getToBtmType().trim());
            }
        }else if(!linkTypeDataQuery.isDirection() && StringUtils.isNotBlank(linkTypeDataQuery.getToBtmType())){
            if(linkTypeDataQuery.getToBtmType().contains(",")){
                conditionMap.put("t_btwname", QueryOptionConstant.IN + "(" + VciBaseUtil.str2List(linkTypeDataQuery.getToBtmType()) + ")");
            }else{
                conditionMap.put("t_btwname", linkTypeDataQuery.getToBtmType().trim());
            }
        }
        Condition condition = boService.getConditionByMap(conditionMap);
        if(qt.getCondition() !=null) {
            qt.setCondition(OQTool.mergeCondition(qt.getCondition(), condition, Connector.AND));
        }else {
            qt.setCondition(condition);
        }
        boService.setPageAndOrderToQT(qt,linkTypeDataQuery.getPageHelper());
        DataGrid dataGrid = new DataGrid();
        Map<String,List<String>> fromBtmOidsMap = new HashMap<>();
        Map<String,List<String>> toBtmOidsMap = new HashMap<>();
        try {
            IntHolder totalHolder = new IntHolder();
            ObjectQueryService.FindLTObjectsV2Result linkObjects = platformClientUtil.getQueryService().findLTObjectsV2(qt.getId(), OQTool.qtTOXMl(qt).asXML());
 
 
            List<Map<String,String>> data = new ArrayList<>();
            List<String> finalEnumFields = enumFields;
            final Integer[] total = {totalHolder.value};
            Arrays.stream(linkObjects.returnValue).forEach(lo->{
                LinkObject clo = new LinkObject();
                clo = lo;
                Map<String, String> map = new HashMap<>();
                boService.queryEnumText(null,clo, finalEnumFields);
                WebUtil.copyValueToMapFromClos(clo,map);
                List<String> fromOids = fromBtmOidsMap.getOrDefault(lo.fromBTName, new ArrayList<>());
                fromOids.add(lo.fromOid);
                fromBtmOidsMap.put(lo.fromBTName,fromOids);
 
                List<String> toOids = toBtmOidsMap.getOrDefault(lo.toBTName, new ArrayList<>());
                toOids.add(lo.toOid);
                toBtmOidsMap.put(lo.toBTName,toOids);
                data.add(map);
                if(total[0] == 0){
                    total[0] = VciBaseUtil.getInt(map.getOrDefault(QTConstants.COUNT_OVER_ALIAS.toLowerCase(),"0"));
                }
            });
            dataGrid.setData(data);
            dataGrid.setTotal(total[0]);
        } catch (PLException e) {
//            logger.error(e.error_code,e);
            throw WebUtil.getVciBaseException(e);
        }
        if(!CollectionUtils.isEmpty(referFields) && dataGrid.getTotal()>0){
            List<String> fromFields = referFields.stream().filter(s -> s.toLowerCase().startsWith("f_oid.")).collect(Collectors.toList());
            List<String> toFields = referFields.stream().filter(s -> s.toLowerCase().startsWith("t_oid.")).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(fromBtmOidsMap) && !CollectionUtils.isEmpty(fromFields)){
                List<String> fromFieldsFix = new ArrayList<>();
                fromFields.stream().forEach(field->{
                    fromFieldsFix.add(field.substring("f_oid.".length()));
                });
                fromBtmOidsMap.forEach((btm,oids)->{
                    //分页不要超过1000
                    Map<String,String> boConditionMap =new HashMap<>();
                    boConditionMap.put("oid",QueryOptionConstant.IN + "(" + WebUtil.toInSql(oids.toArray(new String[0])) + ")");
                    List<BusinessObject> cbos = boService.queryCBO(btm, boConditionMap, null, fromFieldsFix);
                    if(!CollectionUtils.isEmpty(cbos)){
                        cbos.stream().forEach(cbo->{
                            dataGrid.getData().forEach(data->{
                                Map<String, String> map = (Map<String, String>) data;
                                if(map.getOrDefault("f_oid","").equals(cbo.oid)){
                                    fromFieldsFix.stream().forEach(fromField->{
                                        map.put("f_oid." + fromField, ObjectTool.getBOAttributeValue(cbo,fromField));
                                    });
                                }
                            });
                        });
                    }
                });
            }
            if(!CollectionUtils.isEmpty(toBtmOidsMap) && !CollectionUtils.isEmpty(toFields)){
                List<String> toFieldsFix = new ArrayList<>();
                toFields.stream().forEach(field->{
                    toFieldsFix.add(field.substring("t_oid.".length()));
                });
                toBtmOidsMap.forEach((btm,oids)->{
                    //分页不要超过1000
                    Map<String,String> boConditionMap =new HashMap<>();
                    boConditionMap.put("oid",QueryOptionConstant.IN + "(" + WebUtil.toInSql(oids.toArray(new String[0])) + ")");
                    List<BusinessObject> cbos = boService.queryCBO(btm, boConditionMap, null, toFieldsFix);
                    if(!CollectionUtils.isEmpty(cbos)){
                        cbos.stream().forEach(cbo->{
                            dataGrid.getData().forEach(data->{
                                Map<String, String> map = (Map<String, String>) data;
                                if(map.getOrDefault("t_oid","").equals(cbo.oid)){
                                    toFieldsFix.stream().forEach(toField->{
                                        map.put("t_oid." + toField,ObjectTool.getBOAttributeValue(cbo,toField));
                                    });
                                }
                            });
                        });
                    }
                });
            }
        }
        return dataGrid;
    }
 
    /**
     * 链接类型查询数量
     *
     * @param linkType     链接类型
     * @param conditionMap 查询条件
     * @return 个数
     */
    @Override
    public Integer queryCount(String linkType, Map<String, String> conditionMap) {
        return queryCount(linkType,conditionMap,false,1);
    }
 
    /**
     * 链接类型查询数量
     *
     * @param linkType     链接类型
     * @param conditionMap 查询条件
     * @param isDirection 是否反向
     * @param level 层级
     * @return 个数
     */
    @Override
    public Integer queryCount(String linkType,Map<String,String> conditionMap,boolean isDirection,Integer level){
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryLO");
        qt.setType(QTConstants.TYPE_LINK);
        qt.setLinkType(linkType.toLowerCase());
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        qt.setDirection(isDirection?"opposite":"positive");
        qt.setLevel(level);
        conditionMap = WebUtil.getNotNullMap(conditionMap);
        qt.setRightFlag(webProperties.isDataRight());
        //设置分页信息和排序
        Condition condition = boService.getConditionByMap(conditionMap);
        qt.setCondition(condition);
        try {
            return Math.toIntExact(platformClientUtil.getQueryService().findTotalCount(qt.getId(), OQTool.qtTOXMl(qt).asXML()));
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
    }
 
}