田源
2025-01-16 404966637eda6881a0f17683c5aacc7c1c34aed8
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
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
package plm.portal.utility;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
 
import com.vci.corba.common.VCIError;
 
 
import plm.bs.bom.common.BusinessObject;
import plm.bs.bom.common.LinkObject;
import plm.corba.portal.PortalVI;
import plm.corba.qt.BOAndLO;
import plm.corba.qt.QTWrapper;
import plm.corba.refquery.RefPath;
import plm.oq.objectQuery.client.QTClient;
import plm.oq.objectQuery.common.Condition;
import plm.oq.objectQuery.common.Connector;
import plm.oq.objectQuery.common.OrderInfo;
import plm.oq.objectQuery.common.PageInfo;
import plm.oq.objectQuery.common.QTConstants;
import plm.oq.objectQuery.common.QueryTemplate;
import plm.portal.constants.QueryConditionConstants;
import plm.refquery.parser.ui.PLMReferenceQueryFacade;
 
public class DataModelProcessor implements IDataModelProcessor{
 
    /**
     * 根据输入参数自定义查询模板,根据自定义的查询模板获取符合条件的业务对象查询结果
     * @param btmName,业务类型名称
     * @param clauseList,返回的字段列表,暂时默认支持*
     * @param queryChildrenFlag,是否查询子业务类型的数据
     * @param rightFlag,是否根据数据授权过滤,true:进行数据授权过滤,false:不进行数据授权过滤
     * @param queryCondition,查询条件map,即需要附加到业务类型的查询语句的查询条件
     * @param version,1:当前版本当前版次;2代表当前版本最新版次;3:代表最新版本最新版次;4代表当前发布有效版
     * @param pageInfo,分页信息,不需要分页时将其设为null即可,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @param orderInfoList,排序信息,不需要是将其设置为null, 其包含三个属性:level:排序优先级,数越小越优先; orderField:排序字段名称;orderMode:属性ASC或DESC;
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    @Override
    public BusinessObject[] getBusinessObjectByCondition(String btmName, List<String> clauseList, boolean queryChildrenFlag, boolean rightFlag, 
            Map<String, String> queryCondition, int version, PageInfo pageInfo, List<OrderInfo> orderInfoList) throws VCIError {
            BusinessObject[] bos = null;
            try{
                QueryTemplate qt2 = new QueryTemplate();
                qt2.setId("btmQuery");
                qt2.setBtmType(btmName);
                qt2.setType("btm");
                clauseList = new ArrayList<String>();
                clauseList.add("*");
                qt2.setClauseList(clauseList);
                qt2.setQueryChildrenFlag(queryChildrenFlag);
                qt2.setRightFlag(rightFlag);
                qt2.setVersion(version);
                if (pageInfo != null && pageInfo.getPageNO() > 0 && pageInfo.getRowCount() > 0) {
                    qt2.setPageInfo(pageInfo);
                }
                if (orderInfoList != null && orderInfoList.size() > 0) {
                    qt2.setOrderInfoList(orderInfoList);
                }
                
                if (queryCondition != null && queryCondition.size() > 0) {
                    Condition cond = plm.oq.objectQuery.common.Tool.getCondition(queryCondition);
                    qt2.setCondition(cond);
                }
                bos = QTClient.getService().findBTMObjects(qt2.getId(),  plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
            }
            catch(VCIError vcie)
            {
                throw vcie;
            }
            catch(java.lang.Exception se)
            {
                VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
                throw vcierror;
            }
            return bos;
    }
    
    /**
     * 自定义查询模板,根据查询条件查询符合条件的链接类型查询结果
     * @param linkName,link名称
     * @param clauseList,返回的字段列表,暂时默认支持*
     * @param queryISLeaf,是否查询叶子节点,true代表查询,false代表不查询
     * @param rightFlag,是否根据数据授权过滤,true:进行数据授权过滤,false:不进行数据授权过滤
     * @param direction,查询方向,true代表正向查询,false代表反向查询
     * @param queryCondition,是否查询子业务类型的数据
     * @param version,1:当前版本当前版次;2代表当前版本最新版次;3:代表最新版本最新版次;4代表当前发布有效版
     * @param pageInfo,分页信息,不需要分页时将其设为null即可,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @param level,查询的层级,-1代表所有,其他数字代码查询的具体层数
     * @param orderInfoList,排序信息,不需要是将其设置为null, 其包含三个属性:level:排序优先级,数越小越优先; orderField:排序字段名称;orderMode:属性ASC或DESC;
     * @param recReturnMode,是否去重,true代表去重,false代表不去重
     * @param objId,源对象ID
     * @param btmType,查询目标对象的业务类型
     * @return
     * @throws VCIError
     */
    @Override
    public LinkObject[] getLinkObjectByCondition(String linkName, List<String> clauseList, boolean queryISLeaf, boolean rightFlag, boolean direction,
            Map<String, String> queryCondition, int version, PageInfo pageInfo, int level, List<OrderInfo> orderInfoList, boolean recReturnMode, String objId, String btmType) throws VCIError {
        LinkObject[] linkObjects = null;
        try
        {
            QueryTemplate qt2 = new QueryTemplate();
            qt2.setId("ltQuery");
            qt2.setLinkType(linkName);
            qt2.setType("link");
            clauseList = new ArrayList<String>();
            clauseList.add("*");
            qt2.setClauseList(clauseList);
            qt2.setQueryISLeaf(queryISLeaf);
            qt2.setRightFlag(rightFlag);
            
            if(direction){
                qt2.setDirection(QTConstants.DIRECTION_POSITIVE);
            }else{
                qt2.setDirection(QTConstants.DIRECTION_OPPOSITE);
            }
            if (pageInfo != null && pageInfo.getPageNO() > 0 && pageInfo.getRowCount() > 0) {
                qt2.setPageInfo(pageInfo);
            }
            if (orderInfoList != null && orderInfoList.size() > 0) {
                qt2.setOrderInfoList(orderInfoList);
            }
            if (queryCondition != null && queryCondition.size() > 0) {
                Condition cond = plm.oq.objectQuery.common.Tool.getConditionForLink(qt2.getDirection(), objId, btmType, queryCondition);
                qt2.setCondition(cond);
            }
            
            qt2.setVersion(version);
            qt2.setPageInfo(pageInfo);
            qt2.setLevel(level);
            if (recReturnMode) {
                qt2.setRecReturnMode(1);
            } else {
                qt2.setRecReturnMode(2);
            }
            
            linkObjects = QTClient.getService().findLTObjects(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return linkObjects;
    }
    
    /**
     * 自定义查询模板,根据查询条件查询符合条件的业务对象和链接类型查询结果
     * @param linkName,link名称
     * @param clauseList,返回的字段列表,暂时默认支持*
     * @param queryISLeaf,是否查询叶子节点,true代表查询,false代表不查询
     * @param rightFlag,是否根据数据授权过滤,true:进行数据授权过滤,false:不进行数据授权过滤
     * @param direction,查询方向,true代表正向查询,false代表反向查询
     * @param queryCondition,是否查询子业务类型的数据
     * @param version,1:当前版本当前版次;2代表当前版本最新版次;3:代表最新版本最新版次;4代表当前发布有效版
     * @param pageInfo,分页信息,不需要分页时将其设为null即可,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @param level,查询的层级,-1代表所有,其他数字代码查询的具体层数
     * @param orderInfoList,排序信息,不需要是将其设置为null, 其包含三个属性:level:排序优先级,数越小越优先; orderField:排序字段名称;orderMode:属性ASC或DESC;
     * @param recReturnMode,是否去重,true代表去重,false代表不去重
     * @param objId,源对象ID
     * @param btmType,查询目标对象的业务类型
     * @return
     * @throws VCIError
     */
    @Override
    public BOAndLO[] getBOLOsByCondition(String linkName, List<String> clauseList, boolean queryISLeaf, boolean rightFlag, boolean direction,
            Map<String, String> queryCondition, int version, PageInfo pageInfo, int level, List<OrderInfo> orderInfoList, boolean recReturnMode, String objId, String btmType) throws VCIError {
        BOAndLO[]  bolos = null;
        try
        {
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("ltQuery");
        qt2.setLinkType(linkName);
        qt2.setType("link");
        clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
        qt2.setQueryISLeaf(queryISLeaf);
        qt2.setRightFlag(rightFlag);
        
        if(direction){
            qt2.setDirection(QTConstants.DIRECTION_POSITIVE);
        }else{
            qt2.setDirection(QTConstants.DIRECTION_OPPOSITE);
        }
        if (pageInfo != null && pageInfo.getPageNO() > 0 && pageInfo.getRowCount() > 0) {
            qt2.setPageInfo(pageInfo);
        }
        if (orderInfoList != null && orderInfoList.size() > 0) {
            qt2.setOrderInfoList(orderInfoList);
        }
        if (queryCondition != null && queryCondition.size() > 0) {
            Condition cond = plm.oq.objectQuery.common.Tool.getConditionForLink(qt2.getDirection(), objId, btmType, queryCondition);
            qt2.setCondition(cond);
        }
        
        qt2.setVersion(version);
        qt2.setPageInfo(pageInfo);
        qt2.setLevel(level);
        if (recReturnMode) {
            qt2.setRecReturnMode(1);
        } else {
            qt2.setRecReturnMode(2);
        }
        
        bolos = QTClient.getService().getBOAndLOS(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML(), "");
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return bolos;
    }
    
    /**
     * 根据查询模板及附加条件查询业务对象
     * @param queryTemplate,查询模板名称
     * @param replaceMap,替换属性map
     * @param conditionMap,查询条件map
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    @Override
    public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError {
        BusinessObject[] v = null;
        try
        {
            QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo);
            v = QTClient.getService().findBTMObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return v;
    }
    
    /**
     * 根据查询模板及附加条件查询业务对象
     * @param queryTemplate,查询模板名称
     * @param replaceMap,替换属性map
     * @param conditionMap,查询条件map
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @param orderInfos: 排序信息
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    @Override
    public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError {
        BusinessObject[] v = null;
        try
        {
        QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo, orderInfos);
        v = QTClient.getService().findBTMObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return v;
    }
    
    /**
     * 根据查询模板查询符合要求的link对象
     * @param queryTemplate,查询模板
     * @param replaceMap,替换map,
     * @param conditionMap,附件的查询条件
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    @Override
    public LinkObject[] getLinkObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError {
        LinkObject[] linkObjects = null;
        try
        {
        QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo);
        linkObjects = QTClient.getService().findLTObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return linkObjects;
    }
    
    /**
     * 根据查询模板查询符合要求的业务对象和链接对象
     * @param queryTemplate,查询模板
     * @param replaceMap,替换map,
     * @param conditionMap,附件的查询条件
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    @Override
    public BOAndLO[] getBOLOsByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError {
        BOAndLO[] bolos = null;
        try
        {
        QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo);
        bolos = QTClient.getService().getBOAndLOS(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML(), "");
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return bolos;
    }
    
    /**
     * 根据查询模板查询符合要求的业务对象和链接对象
     * @param queryTemplate,查询模板
     * @param replaceMap,替换map,
     * @param conditionMap,附件的查询条件
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    @Override
    public BOAndLO[] getBOLOsByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError {
        BOAndLO[] bolos = null;
        try
        {
        QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo, orderInfos);
        bolos = QTClient.getService().getBOAndLOS(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML(), "");
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return bolos;
    }
    
    @Override
    public Map<String, String> getFormColumnMap(PortalVI formDef) {
        Map<String, String> colMap = new LinkedHashMap<String, String>();
        PRM sheetPrm = Tool.getPRM(formDef.prm);
        for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
            String key = sheetPrm.getPrmItemList().get(i).getItemField();
            colMap.put(key, sheetPrm.getPrmItemList().get(i).getItemName());
        }
        
        return colMap;
    }
    
    @Override
    public String getTableQueryTemplate(PRM prm) {
        return prm.getPrmItemList().get(0).getItemQtName();
    }
 
    @Override
    public Map<String, String> getSheetColumnMap(PortalVI formDef,
            String[] tableCol) {
        Map<String, String> colMap = new LinkedHashMap<String, String>();
        for (int i = 0; i < tableCol.length; i++) {
            String key = tableCol[i];
            String value = getSheetColumnName(key, formDef);
            colMap.put(tableCol[i], value);
        }
        
        return colMap;
    }
    
    /**
     * 根据主键获取对应的名称
     * 
     * @param key
     * @param formDef
     * @return
     */
    private String getSheetColumnName(String key, PortalVI formDef) {
        PRM sheetPrm = Tool.getPRM(formDef.prm);
        for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
            String ckey = sheetPrm.getPrmItemList().get(i).getItemField();
            if (ckey.equals(key)) {
                return sheetPrm.getPrmItemList().get(i).getItemName();
            }
        }
        return "";
    }
 
    @Override
    public String getSelectDisplayValue(String key, String value, List<String> selectValues) {
        for (int i = 0; i < selectValues.size(); i++) {
            String valueStr = selectValues.get(i);
            String ckey = valueStr.substring(0, valueStr.indexOf("{"));
            String cvalue = valueStr.substring(valueStr.indexOf("{") + 1, valueStr.indexOf("}"));
            if (value.equals(cvalue)) {
                return ckey;
            }
        }
        return value;
    }
 
    @Override
    public Map<String, PRMItem> getMultiFileCol(PortalVI formDef) {
        Map<String, PRMItem> multiFiles = new HashMap<String, PRMItem>();
        PRM sheetPrm = Tool.getPRM(formDef.prm);
        for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
            String key = sheetPrm.getPrmItemList().get(i).getItemField();
            if (sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.MULTIFILE)) {
                multiFiles.put(key, sheetPrm.getPrmItemList().get(i));
            }
        }
        return multiFiles;
    }
    
    @Override
    public Map<String, PRMItem> getFileCol(PortalVI formDef) {
        Map<String, PRMItem> files = new HashMap<String, PRMItem>();
        PRM sheetPrm = Tool.getPRM(formDef.prm);
        for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
            String key = sheetPrm.getPrmItemList().get(i).getItemField();
            if (sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.MULTIFILE)
                    || sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase("file")) {
                files.put(key, sheetPrm.getPrmItemList().get(i));
            }
        }
        return files;
    }
 
    @Override
    public Map<String, PRMItem> getCustomCol(PortalVI formDef) {
        Map<String, PRMItem> customCols = new HashMap<String, PRMItem>();
        PRM sheetPrm = Tool.getPRM(formDef.prm);
        for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
            String key = sheetPrm.getPrmItemList().get(i).getItemField();
            if (sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.CUSTOM)) {
                customCols.put(key, sheetPrm.getPrmItemList().get(i));
            }
        }
        
        return customCols;
    }
 
    @Override
    public Map<String, List<String>> getReferenceCol(Map<String, String> queryCol) {
        Map<String, List<String>> referenceKeyMap = new HashMap<String, List<String>>(); //引用首字段Map
        Iterator<String> itor =  queryCol.keySet().iterator();
        while (itor.hasNext()) {
            String key = itor.next();
            String[] keyArray = key.split("\\.");
            if (keyArray.length > 1) {
                List<String> refList = null;
                if (referenceKeyMap.get(keyArray[0]) == null) {
                    refList = new ArrayList<String>();
                } else {
                    refList = referenceKeyMap.get(keyArray[0]);
                }
                refList.add(key);
                referenceKeyMap.put(keyArray[0], refList);
            }
        }
        
        return referenceKeyMap;
    }
 
 
    @Override
    public String getFormQueryTemplate(PRM prm) {
        return prm.getFormQtName();
    }
    
    public static void main(String[] args) {
        DataModelProcessor p = new DataModelProcessor();
//        String queryTemplate = "ProductQueryPartsTemplate";
        Map<String, String> replaceMap = new HashMap<String, String>();
        replaceMap.put("name_oid", "A389B604-5483-ABA1-D8D8-FA29DFC373DD");
        replaceMap.put("_TRAINSITIONOID", "81FAB5BF-969F-C549-BF80-88BC27B044FB");
        replaceMap.put("ISLASTR", "1");
        replaceMap.put("f_oid", "81FAB5BF-969F-C549-BF80-88BC27B044FB");
        replaceMap.put("ISLASTV", "1");
        replaceMap.put("type", "Parts");
        
        Map<String, String> queryCondition = new HashMap<String, String>();
        queryCondition.put("id", "CP-001");
        try {
//            LinkObject[] los = p.getLinkObjectByQueryTemplate(queryTemplate, replaceMap);
            BusinessObject[] bos = p.getBusinessObjectByCondition("part", null, true, false, queryCondition, 1, null, null);
            System.out.println(bos.length);
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    @Override
    public int getObjectCountByTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError {
        int count = 0;
        try
        {
            QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap);
            count = QTClient.getService().findTotalCount(qt_.getId(),plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return count;
    }
    
    @Override
    public LinkObject[] getLinkObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError {
        LinkObject[] linkObjects = null;
        
        try
        {
        QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap);
        linkObjects = QTClient.getService().findLTObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return linkObjects;
    }
 
    @Override
    public LinkObject[] getLinkObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap) throws VCIError, DocumentException {
        LinkObject[] linkObjects = null;
        try{
        QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
        QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
        PageInfo pageInfo = null;
        if(replaceMap.containsKey(QueryConditionConstants.PAGESIZE) && replaceMap.containsKey(QueryConditionConstants.PAGENO)){
            int pageSize = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGESIZE));
            int pageNO = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGENO));
            replaceMap.remove(QueryConditionConstants.PAGESIZE);
            replaceMap.remove(QueryConditionConstants.PAGENO);
            pageInfo = new PageInfo();
            pageInfo.setPageNO(pageNO);
            pageInfo.setRowCount(pageSize);
        }
        QueryTemplate qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
        if(pageInfo != null){
            qt_.setPageInfo(pageInfo);
        }
        linkObjects = QTClient.getService().findLTObjects(qt.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return linkObjects;
    }
    
    @Override
    public LinkObject[] getLinkObjectByCondition(Map<String, String> conditions, boolean direction) throws VCIError {
        if (conditions == null || conditions.size() == 0) {
            return null;
        }
        LinkObject[] linkObjects = null;
        try
        {
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("ltQuery");
        qt2.setLinkType(conditions.get(QueryConditionConstants.LO_TYPE));
        qt2.setType("link");
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
        String queryType = conditions.get(QueryConditionConstants.BO_TYPE);
        String fromOrToOid = conditions.get(QueryConditionConstants.FROM_OR_TO_OID);
        conditions.remove(QueryConditionConstants.BO_TYPE);
        conditions.remove(QueryConditionConstants.LO_TYPE);
        conditions.remove(QueryConditionConstants.FROM_OR_TO_OID);
        if(direction){
            qt2.setDirection(QTConstants.DIRECTION_POSITIVE);
        }else{
            qt2.setDirection(QTConstants.DIRECTION_OPPOSITE);
        }
        if(conditions.containsKey(QueryConditionConstants.PAGESIZE) && conditions.containsKey(QueryConditionConstants.PAGENO)){
            int pageSize = Integer.valueOf(conditions.get(QueryConditionConstants.PAGESIZE));
            int pageNO = Integer.valueOf(conditions.get(QueryConditionConstants.PAGENO));
            conditions.remove(QueryConditionConstants.PAGESIZE);
            conditions.remove(QueryConditionConstants.PAGENO);
            PageInfo pageInfo = new PageInfo();
            pageInfo.setPageNO(pageNO);
            pageInfo.setRowCount(pageSize);
            qt2.setPageInfo(pageInfo);
        }
        Condition cond = plm.oq.objectQuery.common.Tool.getConditionForLink(qt2.getDirection(), fromOrToOid, queryType, conditions);
        qt2.setCondition(cond);
        
        linkObjects = QTClient.getService().findLTObjects(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return linkObjects;
    }
    
    @Override
    public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError, DocumentException {
        BusinessObject[] v = null;
        try
        {
        QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap);
        v = QTClient.getService().findBTMObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return v;
    }
    
    /**
     * 根据传递的参数构建新的查询模版
     * @param queryTemplate
     * @param replaceMap
     * @param conditionMap
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
    private QueryTemplate getCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError, DocumentException {
        QueryTemplate qt_ = null;
        try
        {
        QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
        QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
        PageInfo pageInfo = null;
        if(replaceMap.containsKey(QueryConditionConstants.PAGESIZE) && replaceMap.containsKey(QueryConditionConstants.PAGENO)){
            int pageSize = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGESIZE));
            int pageNO = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGENO));
            replaceMap.remove(QueryConditionConstants.PAGESIZE);
            replaceMap.remove(QueryConditionConstants.PAGENO);
            pageInfo = new PageInfo();
            pageInfo.setPageNO(pageNO);
            pageInfo.setRowCount(pageSize);
        }
        qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
        if (conditionMap != null && conditionMap.size() > 0) {
            Condition condition = plm.oq.objectQuery.common.Tool.getCondition(conditionMap);
            Condition mergeCondition = plm.oq.objectQuery.common.Tool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
            qt_.setCondition(mergeCondition);
        }
        if(pageInfo != null){
            qt_.setPageInfo(pageInfo);
        }
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return qt_;
    }
    
    /**
     *  根据传递的参数构建新的查询模版
     * @param queryTemplate, 查询模板
     * @param replaceMap,替换map
     * @param conditionMap,查询条件
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @return
     * @throws VCIError
     * @throws DocumentException
     */
     QueryTemplate getCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError, DocumentException {
        QueryTemplate qt_ = null;
         try
        {
         QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
        QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
        qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
        if (conditionMap != null && conditionMap.size() > 0) {
            Condition condition = plm.oq.objectQuery.common.Tool.getCondition(conditionMap);
            Condition mergeCondition = plm.oq.objectQuery.common.Tool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
            qt_.setCondition(mergeCondition);
        }
        if(pageInfo != null){
            qt_.setPageInfo(pageInfo);
        }
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return qt_;
    }
     
    /**
     * 根据传递的参数构建新的查询模版
     * 
     * @param queryTemplate, 查询模板
     * @param replaceMap,替换map
     * @param conditionMap,查询条件
     * @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
     * @param orderInfos: 排序信息
     * @return
     * @throws VCIError
     * @throws DocumentException
     */ 
    private QueryTemplate getCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError, DocumentException {
        QueryTemplate qt_ = null;
        try
        {
        QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
        QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
        qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
        if (conditionMap != null && conditionMap.size() > 0) {
            Condition condition = plm.oq.objectQuery.common.Tool.getCondition(conditionMap);
            Condition mergeCondition = plm.oq.objectQuery.common.Tool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
            qt_.setCondition(mergeCondition);
        }
        if(pageInfo != null){
            qt_.setPageInfo(pageInfo);
        }
        if(orderInfos != null){
            qt_.setOrderInfoList(orderInfos);
        }
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return qt_;    
    }
    
    @Override
    public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap) throws VCIError, DocumentException {
        BusinessObject[] v = null;
        try
        {
        QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
        if (replaceMap != null && replaceMap.size() > 0){
            QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
            PageInfo pageInfo = null;
            if(replaceMap.containsKey(QueryConditionConstants.PAGESIZE) && replaceMap.containsKey(QueryConditionConstants.PAGENO)){
                int pageSize = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGESIZE));
                int pageNO = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGENO));
                replaceMap.remove(QueryConditionConstants.PAGESIZE);
                replaceMap.remove(QueryConditionConstants.PAGENO);
                pageInfo = new PageInfo();
                pageInfo.setPageNO(pageNO);
                pageInfo.setRowCount(pageSize);
            }
            QueryTemplate qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
            if(pageInfo != null){
                qt_.setPageInfo(pageInfo);
            }
            v = QTClient.getService().findBTMObjects(qt.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
        } else {
            v = QTClient.getService().findBTMObjects(wrapper.qtName, wrapper.qtText);
        }
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return v;
    }
    
    @Override
    public BusinessObject[] getBusinessObjectByCondition(Map<String, String> conditions) throws VCIError {
        BusinessObject[] bos = null;
        try
        {
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("btmQuery");
        qt2.setBtmType(conditions.get(QueryConditionConstants.BO_TYPE));
        qt2.setType("btm");
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
        conditions.remove(QueryConditionConstants.BO_TYPE);
        if(conditions.containsKey(QueryConditionConstants.PAGESIZE) && conditions.containsKey(QueryConditionConstants.PAGENO)){
            int pageSize = Integer.valueOf(conditions.get(QueryConditionConstants.PAGESIZE));
            int pageNO = Integer.valueOf(conditions.get(QueryConditionConstants.PAGENO));
            conditions.remove(QueryConditionConstants.PAGESIZE);
            conditions.remove(QueryConditionConstants.PAGENO);
            PageInfo pageInfo = new PageInfo();
            pageInfo.setPageNO(pageNO);
            pageInfo.setRowCount(pageSize);
            qt2.setPageInfo(pageInfo);
        }
        Condition cond = plm.oq.objectQuery.common.Tool.getCondition(conditions);
        qt2.setCondition(cond);
        bos = QTClient.getService().findBTMObjects(qt2.getId(),  plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
        }
        catch(VCIError vcie)
        {
            throw vcie;
        }
        catch(java.lang.Exception se)
        {
            VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
            throw vcierror;
        }
        return bos;
    }
    
    @Override
    public Map<String, String> getQueryBusinessObjectCondition(String type, Map<String, Map<String, String>> rowRefMap, Map<String, List<String>> referenceKeyMap) {
        Map<String, String> queryMap = new LinkedHashMap<String, String>();
        Iterator<String> itor = rowRefMap.keySet().iterator();
        boolean isFirstRow = true;
        
        while (itor.hasNext()) {
            String key = itor.next();
            Map<String, String> instanceMap = rowRefMap.get(key);
            Iterator<String> citor = instanceMap.keySet().iterator();
            while (citor.hasNext()) {
                String ckey = citor.next();
                String cVal = instanceMap.get(ckey);
                if (cVal == null) {
                    cVal = "";
                }
                List<String> list = referenceKeyMap.get(ckey);
                if (list == null || list.size() == 0) {
                    continue;
                }
                if (isFirstRow) {
                    queryMap.put(ckey, type + "." + ckey + "=" + cVal);
                } else {
                    queryMap.put(ckey, queryMap.get(ckey) + "," + cVal); 
                }
                for (int i = 0; i < list.size(); i++) {
                    if (isFirstRow) {
                        queryMap.put(list.get(i), type + "." + list.get(i) + "=" + cVal);
                    } else {
                        queryMap.put(list.get(i), queryMap.get(list.get(i)) + "," + cVal); 
                    }
                }
            }
            isFirstRow = false;
        }
        itor = queryMap.keySet().iterator();
        ArrayList<String> emptyValKey = new ArrayList<String>();
        while (itor.hasNext()) {
            String key = itor.next();
            String value = queryMap.get(key);
            String[] values = value.split("=");
            if (values.length == 1) {
                emptyValKey.add(key);
            } else {
                int repeatTime = computerStrAppearTimes(values[1], ",");
                if (values[1].length() == repeatTime) {
                    emptyValKey.add(key);
                } else if (values[1].lastIndexOf(",") + 1 == values[1].length()) {
                    value = connectStr(values[1].split(","), ",");
                    queryMap.put(key, new StringBuffer(values[0]).append("=").append(value).toString());
                }
            }
        }
        for (int i = 0; i < emptyValKey.size(); i++) {
            queryMap.remove(emptyValKey.get(i));
        }
        return queryMap;
    }
    
    private int computerStrAppearTimes(String source, String str) {
        if (source == null || source.length() == 0) {
            return 0;
        }
        int sLen = source.length();
        String des = source.replaceAll(str, "##");
        int dLen = des.length();
        return dLen - sLen;
    }
    
    private String connectStr(String[] values, String split) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < values.length; i++) {
            if (i != 0) {
                buffer.append(split);
            }
            buffer.append(values[i]);
        }
        return buffer.toString();
    }
    
    @Override
    public Map<String, String> getQueryLinkObjectCondition(String linkType, Map<String, String> rowKeyMap, Map<String, String> rowRefMap, Map<String, List<String>> referenceKeyMap) {
        Map<String, String> queryMap = new LinkedHashMap<String, String>();
        Iterator<String> itor = rowKeyMap.keySet().iterator();
        boolean isFirstRow = true;
        
        while (itor.hasNext()) {
            String rowKey = itor.next();
            String id = rowKeyMap.get(rowKey);
            String key = rowRefMap.get(id);
            List<String> list = referenceKeyMap.get(key);
            if (list == null || list.size() == 0) {
                continue;
            }
            
            if (isFirstRow) {
                queryMap.put(key, linkType + "." + key + "=" + id);
            } else {
                queryMap.put(key, queryMap.get(key) + "," + id); 
            }
            
            for (int i = 0; i < list.size(); i++) {
                if (isFirstRow) {
                    queryMap.put(list.get(i), linkType + "." + list.get(i) + "=" + id); 
                } else {
                    queryMap.put(list.get(i), queryMap.get(list.get(i)) + "," + id); 
                }
            }
            isFirstRow = false;
        }
        return queryMap;
    }
    
    @Override
    public RefPath[] queryReference(Map<String, String> map, String typeName) {
        PLMReferenceQueryFacade facade = new PLMReferenceQueryFacade();
        try {
            List<String> queryList = new ArrayList<String>();
            Iterator<String> itor = map.keySet().iterator();
            while(itor.hasNext()) {
                queryList.add(map.get(itor.next()));
            }
            RefPath[] refPath = facade.query(queryList.toArray(new String[queryList.size()]), typeName);
            return refPath;
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @Override
    public RefPath[] queryReference(Map<String, String> map, String[] typeNames) {
        PLMReferenceQueryFacade facade = new PLMReferenceQueryFacade();
        try {
            List<String> queryList = new ArrayList<String>();
            Iterator<String> itor = map.keySet().iterator();
            while(itor.hasNext()) {
                queryList.add(map.get(itor.next()));
            }
            RefPath[] refPath = facade.query(queryList.toArray(new String[queryList.size()]), typeNames);
            return refPath;
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return null;
    }
}