ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
package com.vci.client.common.oq;
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
 
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
 
import com.vci.corba.query.data.KV;
import com.vci.omd.dataType.VTDataType;
import com.vci.omd.objects.OtherInfo;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.common.qt.object.ChildrenInfo;
import com.vci.common.qt.object.Condition;
import com.vci.common.qt.object.ConditionItem;
import com.vci.common.qt.object.Connector;
import com.vci.common.qt.object.LeafInfo;
import com.vci.common.qt.object.LeafValue;
import com.vci.common.qt.object.Operator;
import com.vci.common.qt.object.OrderInfo;
import com.vci.common.qt.object.PageInfo;
import com.vci.common.qt.object.QTConstants;
import com.vci.common.qt.object.QueryTemplate;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
 
 
public class OQTool {
 
    public static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    /**
     * 在根节点上循环增加qtNode
     * @param doc
     * @return
     */
    public static Element addDoc(Element rootNode , QueryTemplate qt){
        Element qtNode = rootNode.addElement(QTConstants.QUERYTEMPLATE);
        qtNode.addAttribute(QTConstants.ID, qt.getId());
        qtNode.addAttribute(QTConstants.TYPE, qt.getType());
        //设置clauseList
        List<String> clauseList = qt.getClauseList();
        String claValue = QTConstants.BLANK;
        for(int i = 0; i < clauseList.size(); i++){
            claValue += clauseList.get(i);
            if(i < clauseList.size() - 1){
                claValue += ",";
            }
        }
        Element claListNode = qtNode.addElement(QTConstants.CLAUSELIST);
        claListNode.setText(claValue);
        
        //设置查询的linkType
        String linkType = qt.getLinkType();
        Element ltNode = qtNode.addElement(QTConstants.LINKTYPE);
        if(linkType != null){
            ltNode.setText(linkType);
        }
        //设置查询的btmType
        String btmType = qt.getBtmType();
        Element btmNode = qtNode.addElement(QTConstants.BTMTYPE);
        if(btmType != null){
            btmNode.setText(btmType);
        }
        //查询业务对象时,是否查询子类型
        if(qt.getType().equals(QTConstants.TYPE_BTM)){
            boolean queryChildrenFlag = qt.isQueryChildren();
            Element queryChildrenFlagNode = qtNode.addElement(QTConstants.QUERYCHILDRENFLAG);
            queryChildrenFlagNode.setText(String.valueOf(queryChildrenFlag));
        }
        //是否查询是否包含下一级(链接查询)
        boolean isQueryIsLeaf = qt.isQueryISLeaf();
        Element queryIsLeafNode = qtNode.addElement(QTConstants.QUERYISLEAF);
        queryIsLeafNode.setText(String.valueOf(isQueryIsLeaf));
        //查询时是否加入权限,默认加权限
        boolean rightFlag = qt.isRightFlag();
        Element rightFlagNode = qtNode.addElement(QTConstants.RIGHTFlag);
        rightFlagNode.setText(String.valueOf(rightFlag));    
        
        //weidy@2018-06-19 增加密级控制
        boolean secretFlag = qt.isSecretFlag();
        Element secretFlagNode = qtNode.addElement(QTConstants.SECRETFLAG);
        secretFlagNode.setText(String.valueOf(secretFlag));//end weidy
        //设置版本版次信息
        int version = qt.getVersion();
        Element versionNode = qtNode.addElement(QTConstants.VERSION);
        versionNode.setText(String.valueOf(version));
        //设置链接查询的递归层次
        int levelRec = qt.getLevel();
        Element levelRecNode = qtNode.addElement(QTConstants.LEVELREC);
        levelRecNode.setText(String.valueOf(levelRec));
        //递归返回数据模式
        int recReturnMode = qt.getRecReturnMode();
        Element recReturnModeNode = qtNode.addElement(QTConstants.RECRETURNMODE);
        recReturnModeNode.setText(String.valueOf(recReturnMode));
        
        if(qt.getType().equals(QTConstants.TYPE_LINK)){
            //设置链接查询方向
            String direction = qt.getDirection();
            Element directionNode = qtNode.addElement(QTConstants.DIRECTION);
            directionNode.setText(direction);
        }
        //设置PageInfo
        PageInfo pageInfo = qt.getPageInfo();
        if(pageInfo != null){
            Element pageInfoNode = qtNode.addElement(QTConstants.PAGEINFO);
            Element pageNONode = pageInfoNode.addElement(QTConstants.PAGENO);
            int pageNO = pageInfo.getPageNO();
            pageNONode.setText(String.valueOf(pageNO));
            Element rowCountNode = pageInfoNode.addElement(QTConstants.ROWCOUNT);
            int rowCount = pageInfo.getRowCount();
            rowCountNode.setText(String.valueOf(rowCount));
        }
        //设置ORDER BY
        List<OrderInfo> orderInfoList = qt.getOrderInfoList();
        if(orderInfoList != null && orderInfoList.size() > 0){
            Element orderInfosNode = qtNode.addElement(QTConstants.ORDERINFOS);
            for(int i = 0; i < orderInfoList.size(); i++){
                OrderInfo o = orderInfoList.get(i);
                if(o == null){
                    continue;
                }
                Element orderInfoNode = orderInfosNode.addElement(QTConstants.ORDERINFO);
                String orderField = o.getOrderField();
                Element orderFieldNode = orderInfoNode.addElement(QTConstants.ORDERFIELD);
                orderFieldNode.setText(orderField == null ? QTConstants.BLANK : orderField);
                String orderMode = o.getOrderMode();
                Element orderModeNode = orderInfoNode.addElement(QTConstants.ORDERMODE);
                orderModeNode.setText(orderMode == null ? QTConstants.BLANK : orderMode);
                int level = o.getLevel();
                Element levelNode = orderInfoNode.addElement(QTConstants.LEVEL);
                levelNode.setText(String.valueOf(level));
            }
        }
        //设置Condition
        Condition condition = qt.getCondition();
        if(condition != null){
            Element conditionNode = qtNode.addElement(QTConstants.CONDITION);
            conditionNode.addAttribute(QTConstants.ROOTCINAME, condition.getRootCIName());
            Map<String, ConditionItem> ciMap = condition.getCIMap();
            if(ciMap != null){
                for(Iterator<String> i = ciMap.keySet().iterator(); i.hasNext();){
                    String ciId = i.next();
                    //设置conditionItem
                    ConditionItem cItem = ciMap.get(ciId);
                    Element cItemNode = conditionNode.addElement(QTConstants.CONDITIONITEM);
                    cItemNode.addAttribute(QTConstants.ID, cItem.getId());
                    //设置是否是叶子节点
                    boolean isLeaf = cItem.isLeaf();
                    Element leafFlagNode = cItemNode.addElement(QTConstants.LEAFFLAG);
                    leafFlagNode.setText(String.valueOf(cItem.isLeaf()));
                    //设置conditionItem的leafData
                    if(isLeaf){
                        LeafInfo leafInfo = cItem.getLeafInfo();
                        Element leafInfoNode = cItemNode.addElement(QTConstants.LEAFINFO);
                        Element clauseNode = leafInfoNode.addElement(QTConstants.CLAUSE);
                        clauseNode.setText(leafInfo.getClause());
                        Element operatorNode = leafInfoNode.addElement(QTConstants.OPERATOR);
                        String operator = leafInfo.getOperator();
                        /**
                         * 因<, <= 在xml中不能正确存储, 故将查询模板的<, <=存为LT, LTE;
                         * 从xml读取operator为LT, LTE时, 再转换成查询模板的<, <=.
                         * 将>, >= 做相同处理.
                         */
                        if(operator.equals(Operator.LT)){
                            operator = Operator.LTTEXT;
                        }else if(operator.equals(Operator.LTE)){
                            operator = Operator.LTETEXT;
                        }else if(operator.equals(Operator.GT)){
                            operator = Operator.GTTEXT;
                        }else if(operator.equals(Operator.GTE)){
                            operator = Operator.GTETEXT;
                        }
                        operatorNode.setText(operator);
                        //设置conditionItem的leafData的LDValue
                        LeafValue lDValue = leafInfo.getValue();
                        Element valueNode = leafInfoNode.addElement(QTConstants.VALUE);
                        Element ordinaryValueNode = valueNode.addElement(QTConstants.ORDINARYVALUE);
                        String ordinaryValue = lDValue.getOrdinaryValue();
                        if(ordinaryValue != null){
                            ordinaryValueNode.setText(ordinaryValue);
                        }
                        Element queryTemplateNode = valueNode.addElement(QTConstants.REFQT);
                        QueryTemplate refQt = lDValue.getQueryTemplate();
                        if(refQt != null){
                            addDoc(rootNode, refQt);
                            queryTemplateNode.setText(lDValue.getQueryTemplate().getId());
                        }
                    }else{
                        //设置conditionItem的childrenData
                        Element childrenInfoNode = cItemNode.addElement(QTConstants.CHILDRENINFO);
                        ChildrenInfo cdInfo = cItem.getChildrenInfo();
                        Element leftNode = childrenInfoNode.addElement(QTConstants.LEFT);
                        leftNode.setText(cdInfo.getLeftCIName());
                        Element rightNode = childrenInfoNode.addElement(QTConstants.RIGHT);
                        rightNode.setText(cdInfo.getRightCIName());
                        Element conncectorNode = childrenInfoNode.addElement(QTConstants.CONNECTOR);
                        conncectorNode.setText(cdInfo.getConnector());
                    }
                }
            }
            
        }
        
        return rootNode;
    }
    
    /**
     * 将查询模板结构转化成查询模板text
     * @param qt
     * @return
     */
    public static String getQTTextByQT(QueryTemplate qt){
        return qtTOXMl(qt).asXML();
    }
    
    /**
     * 将查询模板, 以及其关联的查询模板
     * @param qt
     * @return
     */
    public static Document qtTOXMl(QueryTemplate qt){
        Document document = DocumentHelper.createDocument();
        Element rootNode = document.addElement(QTConstants.DATA);
        addDoc(rootNode, qt);
        return document;
    }
    
//    public static void writeXml(Document document, String xmlPath_){
//        try {
//            Writer fileWriter = new FileWriter(xmlPath_);
//            OutputFormat format = OutputFormat.createCompactFormat();
//            format.setEncoding("utf-8");
//            format.setIndent(true);
//            format.setNewlines(true);
//            XMLWriter xmlWriter = new XMLWriter(fileWriter, format);
//            xmlWriter.write(document);
//            xmlWriter.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
    
    /**
     * 将查询模板text转化成查询模板结构
     * @param qtName : 查询模板name
     * @param qtText : 查询模板text
     * @return
     * @throws DocumentException 
     * @throws VCIError 
     */
    public static QueryTemplate getQTByQTText(String qtName, String qtText) throws VCIError, DocumentException{
        return getQTByDoc(DocumentHelper.parseText(qtText), qtName);
    }
    
    
    /**
     * 根据Document, Document中的模板名获取查询模板
     * @throws VCIError 
     */
    public static QueryTemplate getQTByDoc(Document doc, String name) throws VCIError{
        QueryTemplate qt = new QueryTemplate();
        
        Element rootNode = doc.getRootElement();
        List<Element> qtNodes = rootNode.elements(QTConstants.QUERYTEMPLATE);
        for(Iterator<Element> i = qtNodes.iterator(); i.hasNext();){
            Element qtNode = i.next();
            if(qtNode.attributeValue(QTConstants.ID).equals(name)){
                //设置Id
                qt.setId(name);
                String type = qtNode.attributeValue(QTConstants.TYPE);
                if(type == null || 
                        (!type.equals(QTConstants.TYPE_BTM) && !type.equals(QTConstants.TYPE_LINK))){
                    throw new VCIError("P0010QT-00011", new String[]{"没有正确设置查询模板的类型"});
                }else{
                    qt.setType(type);
                }
                //设置clauseList
                List<String> clauseList = new ArrayList<String>();
                String[] clauses = qtNode.elementText(QTConstants.CLAUSELIST).split(",");
                for(int k = 0; k < clauses.length; k++){
                    clauseList.add(clauses[k]);
                }
                qt.setClauseList(clauseList);
                //设置查询的linkType
                String linkType = qtNode.elementText(QTConstants.LINKTYPE);
                qt.setLinkType(linkType == null ? QTConstants.BLANK : linkType);
                //设置查询的btmType
                String btmType = qtNode.elementText(QTConstants.BTMTYPE);
                qt.setBtmType(btmType == null ? QTConstants.BLANK : btmType);
                if(qt.getType().equals(QTConstants.TYPE_BTM)){
                    //是否查询业务类型的子类型
                    String queryChildrenFlag = qtNode.elementText(QTConstants.QUERYCHILDRENFLAG);
                    qt.setQueryChildrenFlag(Boolean.valueOf(queryChildrenFlag));
                }
                //是否查询是否包含下一级(链接查询)
                String queryIsLeaf = qtNode.elementText(QTConstants.QUERYISLEAF);
                if(queryIsLeaf == null || queryIsLeaf.equals("")){
                    queryIsLeaf = String.valueOf(Boolean.FALSE);
                }
                qt.setQueryISLeaf(Boolean.valueOf(queryIsLeaf));
                //查询时是否加入权限,默认加权限
                String rightFlag = qtNode.elementText(QTConstants.RIGHTFlag);
                if(rightFlag == null || rightFlag.equals("")){
                    rightFlag = String.valueOf(Boolean.TRUE);
                }
                qt.setRightFlag(Boolean.valueOf(rightFlag));
                //weidy@2018-06-19 增加密级控制
                String secretFlag = qtNode.elementText(QTConstants.SECRETFLAG);
                if(secretFlag == null || secretFlag.equals("")){
                    secretFlag = String.valueOf(Boolean.TRUE);
                }
                qt.setSecretFlag(Boolean.valueOf(secretFlag));
                //设置版本版次信息
                String versionStr = qtNode.elementText(QTConstants.VERSION);
                int version = Integer.valueOf(versionStr == null ? "0" : versionStr);
                qt.setVersion(version);
                
                //设置链接查询递归的层次
                String levelRecStr = qtNode.elementText(QTConstants.LEVELREC);
                int levelRec = Integer.valueOf(levelRecStr == null ? "1" : levelRecStr);
                qt.setLevel(levelRec);
                
                //递归返回数据模式
                String recReturnModeStr = qtNode.elementText(QTConstants.RECRETURNMODE);
                int recReturnMode = Integer.valueOf(recReturnModeStr == null ? "1" : recReturnModeStr);
                qt.setRecReturnMode(recReturnMode);
                
                //设置链接查询方向
                if(qt.getType().equals(QTConstants.TYPE_LINK)){
                    String direction = qtNode.elementText(QTConstants.DIRECTION);
                    if(direction == null || 
                            (!direction.equals(QTConstants.DIRECTION_POSITIVE) && !direction.equals(QTConstants.DIRECTION_OPPOSITE))){
                        qt.setDirection(QTConstants.DIRECTION_POSITIVE);
                    }else{
                        qt.setDirection(direction);
                    }
                }
                //设置PageInfo
                Element pageInfoNode = qtNode.element(QTConstants.PAGEINFO);
                if(pageInfoNode != null && pageInfoNode.element(QTConstants.PAGENO) != null && pageInfoNode.element(QTConstants.ROWCOUNT) != null){
                    PageInfo pageInfo = new PageInfo();
                    String pageNO = pageInfoNode.element(QTConstants.PAGENO).getText();
                    String rowCount = pageInfoNode.element(QTConstants.ROWCOUNT).getText();
                    if(pageNO != null && !pageNO.equals("")){
                        pageInfo.setPageNO(Integer.parseInt(pageNO));
                    }
                    if(rowCount != null && !rowCount.equals("")){
                        pageInfo.setRowCount(Integer.parseInt(rowCount));
                    }
                    qt.setPageInfo(pageInfo);
                }
                //设置orderInfoList
                Element orderInfosNode = qtNode.element(QTConstants.ORDERINFOS);
                if(orderInfosNode != null && orderInfosNode.elements(QTConstants.ORDERINFO) != null){
                    List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
                    List<Element> orderInfoNodes = orderInfosNode.elements(QTConstants.ORDERINFO);
                    for(Iterator<Element> ite = orderInfoNodes.iterator(); ite.hasNext();){
                        Element orderInfoNode = ite.next();
                        if(orderInfoNode.element(QTConstants.ORDERFIELD) != null && orderInfoNode.element(QTConstants.ORDERMODE) != null
                                && orderInfoNode.element(QTConstants.LEVEL) != null){
                            OrderInfo obj = new OrderInfo();
                            obj.setOrderField(orderInfoNode.elementText((QTConstants.ORDERFIELD)));
                            obj.setOrderMode(orderInfoNode.elementText((QTConstants.ORDERMODE)));
                            if(orderInfoNode.elementText((QTConstants.LEVEL)) != null && !orderInfoNode.elementText((QTConstants.LEVEL)).equals("")){
                                obj.setLevel(Integer.valueOf(orderInfoNode.elementText((QTConstants.LEVEL))));
                            }
                            orderInfoList.add(obj);
                        }
                    }
                    qt.setOrderInfoList(orderInfoList);
                }
                Element conditionNode = qtNode.element(QTConstants.CONDITION);
                //设置condition
                if(conditionNode != null && !conditionNode.attributeValue(QTConstants.ROOTCINAME).equals(QTConstants.BLANK)){
                    Condition condition = new Condition();
                    qt.setCondition(condition);
                    condition.setRootCIName(conditionNode.attributeValue(QTConstants.ROOTCINAME));
                    HashMap<String, ConditionItem> cIMap = new HashMap<String, ConditionItem>();
                    condition.setCIMap(cIMap);
                    List<Element> ciNodes = conditionNode.elements(QTConstants.CONDITIONITEM);
                    for(Iterator<Element> ite = ciNodes.iterator(); ite.hasNext();){
                        Element ciNode = ite.next();
                        //设置conditionItem
                        ConditionItem conditionItem = new ConditionItem();
                        conditionItem.setId(ciNode.attributeValue(QTConstants.ID));
                        conditionItem.setLeafFlag(Boolean.valueOf(ciNode.elementText(QTConstants.LEAFFLAG)));
                        
                        //设置conditionItem的leafInfo
                        Element ldNode = ciNode.element(QTConstants.LEAFINFO);
                        if(ldNode != null && ldNode.element(QTConstants.CLAUSE) != null){
                            LeafInfo leafData = new LeafInfo();
                            conditionItem.setLeafInfo(leafData);
                            leafData.setClause(ldNode.elementText(QTConstants.CLAUSE));
                            String operator = ldNode.elementText(QTConstants.OPERATOR);
                            /**
                             * 因<, <= 在xml中不能正确存储, 故将查询模板的<, <=存为LT, LTE;
                             * 从xml读取operator为LT, LTE时, 再转换成查询模板的<, <=.
                             * 将>, >= 做相同处理.
                             */
                            if(operator.equals(Operator.LTTEXT)){
                                operator = Operator.LT;
                            }else if(operator.equals(Operator.LTETEXT)){
                                operator = Operator.LTE;
                            }else if(operator.equals(Operator.GTTEXT)){
                                operator = Operator.GT;
                            }else if(operator.equals(Operator.GTETEXT)){
                                operator = Operator.GTE;
                            }
                            leafData.setOperator(operator);
                            //设置conditionItem的leafData的LDValue
                            Element valueNode = ldNode.element(QTConstants.VALUE);
                            LeafValue ldValue = new LeafValue();
                            leafData.setValue(ldValue);
                            ldValue.setOrdinaryValue(valueNode.elementText(QTConstants.ORDINARYVALUE));
                            String qtName = valueNode.elementText(QTConstants.REFQT);
                            if(qtName != null && !qtName.equals(QTConstants.BLANK)){
                                ldValue.setQueryTemplate(getQTByDoc(doc, qtName));
                            }
                        }
                        
                        //设置conditionItem的childrenInfo
                        Element cdNode = ciNode.element(QTConstants.CHILDRENINFO);
                        if(cdNode != null){
                            ChildrenInfo cdData = new ChildrenInfo();
                            conditionItem.setChildrenInfo(cdData);
                            cdData.setLeftCIName(cdNode.elementText((QTConstants.LEFT)));
                            cdData.setRightCIName(cdNode.elementText((QTConstants.RIGHT)));
                            cdData.setConnector(cdNode.elementText((QTConstants.CONNECTOR)));
                        }
                        
                        cIMap.put(conditionItem.getId(), conditionItem);
                    }
                }
            }
        }
        return qt;
    }
    
    /**
     * Array ----> ArrayList
     * @param array
     * @return
     */
//    public static List<String> arrayToList(String[] array){
//        List<String> list = new ArrayList<String>();
//        for(int i = 0; i < array.length; i++){
//            list.add(array[i]);
//        }
//        return list;
//    }
    
    /**
     * convert array to String append with ','.
     * @param array
     * @return
     */
//    public static String arrayToString(String[] array){
//        String str = QTConstants.BLANK;
//        if(array == null){
//            return str;
//        }
//        for(int i = 0; i < array.length; i++){
//            str += array[i];
//            if(i < array.length - 1){
//                str += ",";
//            }
//        }
//        return str;
//    }
    
    /**
     * 检查查询模板是否合法, 合法返回OK, 非法返回详细信息
     * 1. 检查查询条件的值数据类型是否正确
     * @param qt
     * @return
     */
    public static String checkQT(QueryTemplate qt){
        String ok = "OK";
        if(qt == null){
            return ok;
        }
        Condition condition = qt.getCondition();
        if(condition == null){
            return ok;
        }
        Map<String, ConditionItem> ciMap = condition.getCIMap();
        if(ciMap == null){
            return ok;
        }
        //1.检查查询条件的值数据类型是否正确
        Iterator<String> iterator = ciMap.keySet().iterator();
        while(iterator.hasNext()){
            String ciName = iterator.next();
            ConditionItem ci = ciMap.get(ciName);
            if(ci.isLeaf()){
                LeafInfo leafInfo = ci.getLeafInfo();
                String attName = leafInfo.getClause();
                if(attName.contains(".")){
                    attName = attName.substring(attName.lastIndexOf(".") + 1, attName.length());
                }
                QueryTemplate refQT = leafInfo.getValue().getQueryTemplate();
                String value = leafInfo.getValue().getOrdinaryValue();
                if(value != null){
                    //#---#预置参数
                    if(!value.startsWith("#") || !value.endsWith("#")){
                        String dataType = getAbItemDataType(attName);
                        boolean flag = checkDataType(dataType, value);
                        if(!flag){
                            return attName + "数据类型应为: " + dataType;
                        }
                    }
                }else if(refQT != null){
                    checkQT(refQT);
                }
                
            }
        }
        return ok;
    }
    
    /**
     * 记录树的结构
     * @return
     */
    public static Document parseTreeToDoc(JTree tree){
        if(tree == null){
            return null;
        }
        Document doc = DocumentHelper.createDocument();
        Element root = doc.addElement("root");
        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree.getModel().getRoot();
        root.setText((String)rootNode.getUserObject());
        Enumeration<DefaultMutableTreeNode> children = rootNode.children();
        while(children.hasMoreElements()){
            DefaultMutableTreeNode childNode = children.nextElement();
            Element child = root.addElement("child");
            child.setText((String)childNode.getUserObject());
            if(childNode.children().hasMoreElements()){
                addElement(child, childNode);
            }
        }
        
        return doc;
    }
    
    /**
     * 将树的节点迭代增加到doc
     * @param element
     * @param node
     */
    public static void addElement(Element element, DefaultMutableTreeNode node){
        Enumeration<DefaultMutableTreeNode> children = node.children();
        while(children.hasMoreElements()){
            DefaultMutableTreeNode childNode = children.nextElement();
            Element child = element.addElement("child");
            child.setText((String)childNode.getUserObject());
            if(childNode.children().hasMoreElements()){
                addElement(child, childNode);
            }
        }
    }
    
    /**
     * 将doc转化成树
     * @param doc
     * @return
     */
    public static JTree parseDocToTree(Document doc){
        if(doc == null){
            return null;
        }
        
        Element root = doc.getRootElement();
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(root.getText().trim());
        JTree tree = new JTree(rootNode);;
        List<Element> children = root.elements();
        for(Iterator<Element> i = children.iterator(); i.hasNext();){
            Element child = i.next();
            DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child.getText().trim());
            rootNode.add(childNode);
            if(child.elements().size() > 0){
                addDefaultMutableTreeNode(childNode, child);
            }
        }
        return tree;
    }
    
    /**
     * 将doc的element迭代增加到treeNode
     * @param node
     * @param element
     */
    public static void addDefaultMutableTreeNode(DefaultMutableTreeNode node, Element element){
        List<Element> children = element.elements();
        for(Iterator<Element> i = children.iterator(); i.hasNext();){
            Element child = i.next();
            DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child.getText().trim());
            node.add(childNode);
            if(child.elements().size() > 0){
                addDefaultMutableTreeNode(childNode, child);
            }
        }
    }
    
    /**
     * 将查询模板中查询条件的值参数, 替换为map中给定的值
     * @param qt
     * @param map
     * @throws VCIError 
     */
    public static QueryTemplate replaceQTValues(QueryTemplate qt, Map<String, String> map) throws VCIError{
        try{
            if(qt == null || map == null){
                return qt;
            }
            Condition condition = qt.getCondition();
            if(condition == null){
                return qt; 
            }
            Map<String, ConditionItem> ciMap = condition.getCIMap();
            if(ciMap == null){
                return qt;
            }
            for(Iterator<String> i = ciMap.keySet().iterator(); i.hasNext();){
                String ciId = i.next();
                ConditionItem ci = ciMap.get(ciId);
                //当ConditionItem是叶子结点, 并且值参数在map中时, 替换。
                if(ci.isLeaf()){
                    LeafInfo lInfo = ci.getLeafInfo();
                    String value = lInfo.getValue().getOrdinaryValue();
                    if(value != null && !value.equals("")){
                        if(map.containsKey(value)){
                            String value_ = map.get(value);
                            lInfo.getValue().setOrdinaryValue(value_);
                        //替换自定义查询(非嵌套)in (select oid from ff where #val1# #val2# )
                        }else if(value.contains("#")){
                            while(value.contains("#")){
                                int start = value.indexOf('#');
                                int end = value.indexOf('#', start + 1);
                                String key = value.substring(start + 1, end);
                                String val = map.get(key);
                                value = value.replace('#' + key + '#', val == null ? "null" : val);
                            }
                            lInfo.getValue().setOrdinaryValue(value);
                        } 
                        // add by xchao 2017.12.14 begin
                        // replaceMap 处理增强
                        // 当查询模板中有类似如: oid in (select oid from platformbtm_xxx where oid not in('${oid}'))
                        // 如果此时replaceMap中只有 key=${oid},value=xxx 时,也能正常解析
                        // 此时解析出的条件就是 oid in (select oid from platformbtm_xxx where oid not in('xxx'))
//                        value = lInfo.getValue().getOrdinaryValue();
//                        Iterator<Entry<String, String>> entrys = map.entrySet().iterator();
//                        while(entrys.hasNext()){
//                            Entry<String, String> entry = entrys.next();
//                            String key = entry.getKey();
//                            String kval = entry.getValue();
//                            value = value.replace(key, kval);
//                        }
//                        lInfo.getValue().setOrdinaryValue(value);
                        // add by xchao 2017.12.14 end
                    }else{
                        QueryTemplate refQT = lInfo.getValue().getQueryTemplate();
                        QueryTemplate refQT_ = replaceQTValues(refQT, map);
                        lInfo.getValue().setQueryTemplate(refQT_);
                    }
                }
            }
            return qt;
        }catch(Throwable e){
            e.printStackTrace();
            throw new VCIError("P0010QT-00008", new String[]{e.getMessage()});
        }
    }
    
    /**
     * 获取属性的数据类型, 属性: 业务类型和链接类型的系统属性, 属性池属性
     * @param abUpperName
     * @return
     */
    public static String getAbItemDataType(String abName){
        String dataType = "VTString";
        if(abName == null || abName.equals("")){
            return dataType;
        }
        if(abName.contains(".")){
            abName = abName.substring(abName.lastIndexOf(".") + 1);
        }
//        String abUpperName = abName.toUpperCase();
//        //系统属性
//        if(abUpperName.equals("OID") || abUpperName.equals("REVISIONOID") || abUpperName.equals("NAMEOID") || abUpperName.equals("BTMNAME")
//                || abUpperName.equals("CREATOR") || abUpperName.equals("LASTMODIFIER") || abUpperName.equals("REVISIONRULE")
//                || abUpperName.equals("VERSIONRULE") || abUpperName.equals("REVISIONVALUE") || abUpperName.equals("VERSIONVALUE")
//                || abUpperName.equals("LCTID") || abUpperName.equals("LCSTATUS")
//                || abUpperName.equals("ID") || abUpperName.equals("NAME") || abUpperName.equals("DESCRIPTION") 
//                || abUpperName.equals("OWNER") || abUpperName.equals("CHECKINBY") 
//                || abUpperName.equals("CHECKOUTBY") || abUpperName.equals("COPYFROMVERSION")
//                || abUpperName.equals("ISLASTR") || abUpperName.equals("ISFIRSTR")
//                || abUpperName.equals("ISLASTV") || abUpperName.equals("ISFIRSTV") 
//                || abUpperName.equals("F_OID") || abUpperName.equals("F_REVISIONOID") || abUpperName.equals("F_NAMEOID")
//                || abUpperName.equals("F_BTMNAME") || abUpperName.equals("T_OID") || abUpperName.equals("T_REVISIONOID")
//                || abUpperName.equals("T_NAMEOID") || abUpperName.equals("T_BTMNAME") || abUpperName.equals("F_OID")
//                || abUpperName.equals("F_BTWNAME") || abUpperName.equals("T_BTWNAME")){
//            dataType = "VTString";
//        }else if(abUpperName.equals("REVISIONSEQ") || abUpperName.equals("VERSIONSEQ")){
//            dataType = "VTInteger";
//        }else if(abUpperName.equals("CREATETIME") || abUpperName.equals("LASTMODIFYTIME")
//                || abUpperName.equals("TS") || abUpperName.equals("CHECKINTIME") || abUpperName.equals("CHECKOUTTIME")){
//            dataType = "VTDateTime";
//        //属性池中属性
//        }else{
//            dataType = ApProvider.getInstance().getAbItemDataType(abName);
//        }
        
        try {
            dataType = ServiceProvider.getOMDService().getAttributeService().getAttribItemDataType(abName);
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 
        return dataType;
    }
    
    /**
     * 把key, Value 封装成查询模板的Condition
     * @param map
     * @return
     */
    public static Condition getCondition(Map<String, String> map){
        Condition cond = new Condition();
        Map<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
        Iterator<String> ite = map.keySet().iterator();
        List<ConditionItem> list = new ArrayList<ConditionItem>();
        int idFlag = 1;
        while(ite.hasNext()){
            String key = ite.next();
            String value = map.get(key);
            if(value == null || value.equals("")){
                continue;
            }
            List<ConditionItem> list_ = getCIList(key, value, idFlag);
            if(list.size() > 0){
                ConditionItem lCI = list.get(list.size() - 1);
                ConditionItem rCI = list_.get(list_.size() - 1);
                list.addAll(list_);
                idFlag = idFlag + list_.size();
                ConditionItem pCI = new ConditionItem();
                pCI.setId("ci" + idFlag);
                pCI.setLeafFlag(false);
                pCI.setLeafInfo(null);
                ChildrenInfo cInfo = new ChildrenInfo();
                cInfo.setLeftCIName(lCI.getId());
                cInfo.setConnector(Connector.AND);
                cInfo.setRightCIName(rCI.getId());
                pCI.setChildrenInfo(cInfo);
                list.add(pCI);
                idFlag++;
            }else{
                list.addAll(list_);
                idFlag = idFlag + list_.size();
            }
        }
        
        for(int i = 0; i < list.size(); i++){
            ConditionItem ci = list.get(i);
            ciMap.put(ci.getId(), ci);
        }
        if(list.size() > 0){
            ConditionItem rootCI = list.get(list.size() - 1);
            cond.setRootCIName(rootCI.getId());
            cond.setCIMap(ciMap);
            return cond;
        }else{
            return null;
        }
    }
    
    /**
     * 根据value中包含的AND/OR解析出conditionItem组
     * @param key
     * @param value
     * @param idFlag
     * @return
     */
    public static List<ConditionItem> getCIList(String key, String value, int idFlag){
        List<ConditionItem> list = new ArrayList<ConditionItem>();
        String connector = Connector.AND;
        while(value.length() > 0){
            int indexAnd = value.indexOf("\\AND");
            int indexOr = value.indexOf("\\OR");
            ConditionItem ci = new ConditionItem();
            if(indexAnd > 0 || indexOr > 0){
                String nextConnector = Connector.AND;
                String value_ = null;
                if((indexAnd > 0 && indexAnd < indexOr) || indexOr < 0){
                    value_ = value.substring(0, indexAnd);
                    nextConnector = Connector.AND;
                    value = value.substring(indexAnd + 4);
                }else{
                    value_ = value.substring(0, indexOr);
                    nextConnector = Connector.OR;
                    value = value.substring(indexOr + 3);
                }
                ci = getConditionItem(key, value_, idFlag);
                if(list.size() > 0){
                    ConditionItem lCI = list.get(list.size() - 1);
                    list.add(ci);
                    idFlag++;
                    ConditionItem pCI = new ConditionItem();
                    pCI.setId("ci" + idFlag);
                    pCI.setLeafFlag(false);
                    pCI.setLeafInfo(null);
                    ChildrenInfo cInfo = new ChildrenInfo();
                    cInfo.setLeftCIName(lCI.getId());
                    cInfo.setConnector(connector);
                    cInfo.setRightCIName(ci.getId());
                    pCI.setChildrenInfo(cInfo);
                    list.add(pCI);
                    idFlag++;
                }else{
                    list.add(ci);
                    idFlag++;
                }
                connector = nextConnector;
            }else{
                ci = getConditionItem(key, value, idFlag);
                if(list.size() > 0){
                    ConditionItem lCI = list.get(list.size() - 1);
                    list.add(ci);
                    idFlag++;
                    ConditionItem pCI = new ConditionItem();
                    pCI.setId("ci" + idFlag);
                    pCI.setLeafFlag(false);
                    pCI.setLeafInfo(null);
                    ChildrenInfo cInfo = new ChildrenInfo();
                    cInfo.setLeftCIName(lCI.getId());
                    cInfo.setConnector(connector);
                    cInfo.setRightCIName(ci.getId());
                    pCI.setChildrenInfo(cInfo);
                    list.add(pCI);
                    idFlag++;
                }else{
                    list.add(ci);
                    idFlag++;
                }
                value = "";
            }
        }
        return list;
    }
    
    /**
     * 将原子value(不包含and/or)解析成单个ConditionItem
     * @param key
     * @param value
     * @param idFlag
     * @return
     */
    private static ConditionItem getConditionItem(String key, String value, int idFlag){
        ConditionItem ci = new ConditionItem();
        ci.setId("ci" + idFlag);
        ci.setChildrenInfo(null);
        ci.setLeafFlag(true);
        LeafInfo lInfo = new LeafInfo();
        String operator = null;
        
        if(value.startsWith("\\NOTLIKE")){
            operator = Operator.NOTLIKE;
            value = value.substring(8);
        }else if (value.startsWith(Operator.STAR) || value.endsWith(Operator.STAR)) {
            operator = Operator.LIKE;
        }else if (value.startsWith(Operator.UNEQUAL)) {
            operator = Operator.UNEQUAL;
            value = value.substring(2);
        }else if(value.startsWith(Operator.GT)){    //add by caill 2016.4.7 为操作添加“大于”的判断 并在此判断中添加“大于等于”的判断
            operator = Operator.GT;
            if(value.startsWith(Operator.GTE)){
                operator = Operator.GTE;
                value = value.substring(2);
            }else{
                value = value.substring(1);
            }
            
        }else if(value.startsWith(Operator.LT)){    //add by caill 2016.4.7 为操作添加“小于”的判断 并在此判断中添加“小于等于”的判断
            operator = Operator.LT;
            if(value.startsWith(Operator.LTE)){
                operator = Operator.LTE;
                value = value.substring(2);
            }else{
                value = value.substring(1);
            }
        }/*else if(value.startsWith(Operator.LTE)){
            operator = Operator.LTE;
            value = value.substring(2);
        }else if(value.startsWith(Operator.GTE)){
            operator = Operator.GTE;
            value = value.substring(2);
        }*/else if(value.startsWith("\\IN")){
            operator = Operator.IN;
            value = value.substring(3);
        }else if(value.startsWith("\\NOTIN")){
            operator = Operator.NOTIN;
            value = value.substring(6);
        }else {
            operator = Operator.EQUAL;
        }
        lInfo.setOperator(operator);
        if(key.toUpperCase().contains("T_OID.") || key.toUpperCase().contains("F_OID.")){
            //去掉T_OID.或者F_OID.
            String clause_ = key.substring(6);
            //属性为参照属性
            if(clause_.contains(".")){
                int fpIndex = clause_.indexOf(".");
                String refAbName = key.substring(0, fpIndex + 6);
                key = key.substring(fpIndex + 6 + 1);
                lInfo.setClause(refAbName);
                //去掉T_OID.或者F_OID.
                refAbName = refAbName.substring(6);
                lInfo.setOperator(Operator.IN);
                QueryTemplate qt = getRefQT(refAbName, key, operator, value);
                LeafValue lValue = new LeafValue();
                lValue.setQueryTemplate(qt);
                lInfo.setValue(lValue);
            //属性为非参照属性
            }else{
                lInfo.setClause(key);
                LeafValue lValue = new LeafValue();
                lInfo.setValue(lValue);
                lValue.setOrdinaryValue(value);
            }
        }else{
            //属性为参照属性
            if(key.contains(".")){
                int fpIndex = key.indexOf(".");
                String refAbName = key.substring(0, fpIndex);
                key = key.substring(fpIndex + 1);
                lInfo.setClause(refAbName);
                lInfo.setOperator(Operator.IN);
                QueryTemplate qt = getRefQT(refAbName, key, operator, value);
                LeafValue lValue = new LeafValue();
                lValue.setQueryTemplate(qt);
                lInfo.setValue(lValue);
            //属性为非参照属性
            }else{
                lInfo.setClause(key);
                LeafValue lValue = new LeafValue();
                lInfo.setValue(lValue);
                lValue.setOrdinaryValue(value);
            }
        }
        ci.setLeafInfo(lInfo);
        return ci;
    }
    
    /**
     * 获取参照的查询模板
     * @param refAbName: 参照属性名
     * @param clause: 属性参照的业务类型中的属性
     * @param operator
     * @param ordinaryValue
     * @return
     */
    private static QueryTemplate getRefQT(String refAbName, String clause,
            String operator, String ordinaryValue) {
        QueryTemplate qt = new QueryTemplate();
        try {
            List<String> clauseList = new ArrayList<String>();
            clauseList.add("OID");
            qt.setClauseList(clauseList);
            AttribItem refAb;
            refAb = ServiceProvider.getOMDService().getAttributeService().getAttribItemByName(refAbName);
            OtherInfo otherInfo = OtherInfo.getOtherInfoByText(refAb.other);
            int refFlag = otherInfo.getRefFlag();
            String type = otherInfo.getRefTypeName();
            if (refFlag == 0) {
                qt.setType(QTConstants.TYPE_BTM);
                qt.setBtmType(type);
            } else if (refFlag == 1) {
                qt.setType(QTConstants.TYPE_LINK);
                qt.setLinkType(type);
            }
            Condition condition = new Condition();
            qt.setCondition(condition);
            condition.setRootCIName("ci1");
            HashMap<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
            condition.setCIMap(ciMap);
            ConditionItem ci = new ConditionItem();
            ci.setId("ci1");
            ciMap.put(ci.getId(), ci);
            ci.setLeafFlag(true);
            LeafInfo leafInfo = new LeafInfo();
            if (clause.contains(".")) {
                int fpIndex = clause.indexOf(".");
                String refAbName_ = clause.substring(0, fpIndex);
                clause = clause.substring(fpIndex + 1);
                leafInfo.setClause(refAbName_);
                leafInfo.setOperator(Operator.IN);
                QueryTemplate qt_ = getRefQT(refAbName_, clause, operator, ordinaryValue);
                LeafValue lValue = new LeafValue();
                lValue.setQueryTemplate(qt_);
                leafInfo.setValue(lValue);
                qt.setId("qt_" + refAbName + "_" + refAbName_);
            } else {
                leafInfo.setClause(clause);
                leafInfo.setOperator(operator);
                LeafValue lValue = new LeafValue();
                lValue.setOrdinaryValue(ordinaryValue);
                leafInfo.setValue(lValue);
                qt.setId("qt_" + refAbName + "_" + clause);
            }
            ci.setLeafInfo(leafInfo);
            condition.setCIMap(ciMap);
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return qt;
    }
    
    /**
     * 
     * @param direction
     * @param oid
     * @param btmType
     * @param map
     * @return
     */
    public static Condition getConditionForLink(String direction, String oid, String btmType, Map<String, String> map){
        Condition cond = new Condition();
        cond.setRootCIName("ci3");
        Map<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
        if(direction.equals(QTConstants.DIRECTION_POSITIVE)){
            ConditionItem ci1 = new ConditionItem();
            ci1.setId("ci1");
            ci1.setChildrenInfo(null);
            ci1.setLeafFlag(true);
            LeafInfo lInfo = new LeafInfo();
            lInfo.setClause("f_oid");
            lInfo.setOperator(Operator.EQUAL);
            LeafValue lValue = new LeafValue();
            lValue.setOrdinaryValue(oid);
            lInfo.setValue(lValue);
            ci1.setLeafInfo(lInfo);
            ciMap.put(ci1.getId(), ci1);
            
            ConditionItem ci2 = new ConditionItem();
            ci2.setId("ci2");
            ci2.setChildrenInfo(null);
            ci2.setLeafFlag(true);
            LeafInfo lInfo2 = new LeafInfo();
            lInfo2.setClause("t_nameOId");
            lInfo2.setOperator(Operator.IN);
            LeafValue lValue2 = new LeafValue();
            //参照查询模板
            QueryTemplate refQT = new QueryTemplate();
            lValue2.setQueryTemplate(refQT);
            refQT.setId("refQT");
            refQT.setBtmType(btmType);
            refQT.setType(QTConstants.TYPE_BTM);
            List<String> list = new ArrayList<String>();
            list.add("nameOId");
            refQT.setClauseList(list);
            Condition cond2 = getCondition(map);
            refQT.setCondition(cond2);
            lInfo2.setValue(lValue2);
            ci2.setLeafInfo(lInfo2);
            ciMap.put(ci2.getId(), ci2);
            
            ConditionItem ci3 = new ConditionItem();
            ci3.setId("ci3");
            ci3.setLeafFlag(false);
            ci3.setLeafInfo(null);
            ChildrenInfo cInfo = new ChildrenInfo();
            ci3.setChildrenInfo(cInfo);
            cInfo.setLeftCIName(ci1.getId());
            cInfo.setConnector(Connector.AND);
            cInfo.setRightCIName(ci2.getId());
            ciMap.put(ci3.getId(), ci3);
        }else if(direction.equals(QTConstants.DIRECTION_OPPOSITE)){
            ConditionItem ci1 = new ConditionItem();
            ci1.setId("ci1");
            ci1.setChildrenInfo(null);
            ci1.setLeafFlag(true);
            LeafInfo lInfo = new LeafInfo();
            lInfo.setClause("t_oid");
            lInfo.setOperator(Operator.EQUAL);
            LeafValue lValue = new LeafValue();
            lValue.setOrdinaryValue(oid);
            lInfo.setValue(lValue);
            ci1.setLeafInfo(lInfo);
            ciMap.put(ci1.getId(), ci1);
            
            ConditionItem ci2 = new ConditionItem();
            ci2.setId("ci2");
            ci2.setChildrenInfo(null);
            ci2.setLeafFlag(true);
            LeafInfo lInfo2 = new LeafInfo();
            lInfo2.setClause("f_oid");
            lInfo2.setOperator(Operator.IN);
            LeafValue lValue2 = new LeafValue();
            //参照查询模板
            QueryTemplate refQT = new QueryTemplate();
            lValue2.setQueryTemplate(refQT);
            refQT.setId("refQT");
            refQT.setBtmType(btmType);
            refQT.setType(QTConstants.TYPE_BTM);
            List<String> list = new ArrayList<String>();
            list.add("oid");
            refQT.setClauseList(list);
            Condition cond2 = getCondition(map);
            refQT.setCondition(cond2);
            lInfo2.setValue(lValue2);
            ci2.setLeafInfo(lInfo2);
            ciMap.put(ci2.getId(), ci2);
            
            ConditionItem ci3 = new ConditionItem();
            ci3.setId("ci3");
            ci3.setLeafFlag(false);
            ci3.setLeafInfo(null);
            ChildrenInfo cInfo = new ChildrenInfo();
            ci3.setChildrenInfo(cInfo);
            cInfo.setLeftCIName(ci1.getId());
            cInfo.setConnector(Connector.AND);
            cInfo.setRightCIName(ci2.getId());
            ciMap.put(ci3.getId(), ci3);
        }
        cond.setCIMap(ciMap);
        return cond;
    }
    
    /**
     * 合并Condition
     * 1.将con2中conditionItem的ID和非叶子结点的左右id都加上con1.size
     * 2.con1->con<-con2
     * @param con1
     * @param con2
     * @param AND/OR
     */
    public static Condition mergeCondition(Condition con1, Condition con2, String connector){
        if(connector == null){
            return null;
        }
        if(!connector.equalsIgnoreCase(Connector.AND) &&
                !connector.equalsIgnoreCase(Connector.OR)){
            return null;
        }
        if(con1 == null || con1.getCIMap() == null || con1.getCIMap().keySet().size() == 0){
            return con2;
        }
        if(con2 == null || con2.getCIMap() == null || con2.getCIMap().keySet().size() == 0){
            return con1;
        }
        Condition con = new Condition();
        Map<String, ConditionItem> ciMap = con1.getCIMap();
        int size = ciMap.keySet().size();
        Map<String, ConditionItem> ciMap2 = con2.getCIMap();
        for(Iterator<String> i = ciMap2.keySet().iterator(); i.hasNext();){
            String ciId = i.next();
            ConditionItem ci = ciMap2.get(ciId);
            int id = Integer.valueOf(ciId.substring(2)) + size;
            ci.setId("ci" + id);
            
            if(!ci.isLeaf()){
                ChildrenInfo cInfo = ci.getChildrenInfo();
                String lCI = cInfo.getLeftCIName();
                id = Integer.valueOf(lCI.substring(2)) + size;
                cInfo.setLeftCIName("ci" + id);
                String rCI = cInfo.getRightCIName();
                id = Integer.valueOf(rCI.substring(2)) + size;
                cInfo.setRightCIName("ci" + id);
            }
            
            ciMap.put(ci.getId(), ci);
        }
        
        ConditionItem rootCI = new ConditionItem();
        rootCI.setId("ci" + (ciMap.keySet().size() + 1));
        rootCI.setLeafFlag(false);
        
        ChildrenInfo cInfo_ = new ChildrenInfo();
        cInfo_.setLeftCIName(con1.getRootCIName());
        String rightCI = con2.getRootCIName();
        int id_ = Integer.valueOf(rightCI.substring(2)) + size;
        cInfo_.setRightCIName("ci" + id_);
        cInfo_.setConnector(connector);
        rootCI.setChildrenInfo(cInfo_);
        
        ciMap.put(rootCI.getId(), rootCI);
        
        con.setCIMap(ciMap);
        con.setRootCIName(rootCI.getId());
        return con;
    }
    
    /**
     * 为每一个子节点的ConditinItem中LeafInfo的Clause加上str前缀
     * F_OID./T_OID.
     * @param con
     * @param str
     * @return
     */
    public static Condition conditionWrapper(Condition con, String str){
        Map<String, ConditionItem> ciMap = con.getCIMap();
        for(Iterator<String> i = ciMap.keySet().iterator(); i.hasNext();){
            String ciId = i.next();
            ConditionItem ci = ciMap.get(ciId);
            if(ci.isLeaf()){
                LeafInfo lInfo = ci.getLeafInfo();
                String clause = str + lInfo.getClause();
                lInfo.setClause(clause);
            }
        }
        return con;
    }
    
    /**
     * 克隆list
     * Object cloneable
     * @param list
     * @return
     */
    public static List<OrderInfo> cloneOrderInfoList(List<OrderInfo> list){
        List<OrderInfo> clone = new ArrayList<OrderInfo>();
        if(list == null){
            return clone;
        }
        for(OrderInfo o : list){
            clone.add(o.clone());
        }
        return clone;
    }
    
//    /**
//     * 获取链接类型TO端业务类型视图名
//     * @param ltName
//     * @return
//     */
//    public static String getToViewName(String ltName){
//        return ltName + _TV;
//    }
//    
//    /**
//     * 获取链接类型From端业务类型视图名
//     * @param ltName
//     * @return
//     */
//    public static String getFromViewName(String ltName){
//        return ltName + _FV;
//    }
//    
//    /**
//     * 获取业务类型视图名
//     * @param ltName
//     * @return
//     */
//    public static String getBtViewName(String btName){
//        return btName + _V;
//    }
    
    /**
     * 获取创建链接类型TO端业务类型视图的sql
     * @param ltName
     * @return
     */
//    public static String getBTSViewSql(String[] btNames, String viewName){
//        if(btNames.length < 1){
//            return "";
//        }
//        StringBuilder stb = new StringBuilder("create or replace view ");
//        try {
//            Set<String> allAttrName = getUserAttrNameSet(btNames);
//            Map<String, StringBuilder> sqlMap = getBTSqlMap(allAttrName, btNames);
//            stb.append(viewName);
//            stb.append(" as ");
//            for(String btName : sqlMap.keySet()){
//                stb.append(sqlMap.get(btName));
//                stb.append(" union all ");
//            }
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//        return stb.substring(0, stb.lastIndexOf(" union all "));
//    }
    
    /**
     * 获取业务类型属性总集合
     * @param btNames
     * @return
     */
    private static Set<String> getUserAttrNameSet(String[] btNames){
        Set<String> set = new LinkedHashSet<String>();
        try{
            for(String btName : btNames){
                String[] abNames = ServiceProvider.getOMDService().getBTMService().getBtmApNameArray(btName);
                for(String abName : abNames){
                    set.add(abName);
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return set;
    }
    
    /**
     * 获取各个业务类型查询属性总集合的sql
     * 当业务业务类型中不包含某个属性attrA时, '' as attrA
     * @param allAttrName
     * @param btNames
     * @return
     */
//    private static Map<String, StringBuilder> getBTSqlMap(Set<String> allAttrName,
//            String[] btNames) {
//        //记录业务类型和与其对应的属性列表
//        Map<String, List<String>> btAttrMap = new HashMap<String, List<String>>();
//        //记录业务类型和与其对应的查询sql
//        Map<String, StringBuilder> btSqlMap = new HashMap<String, StringBuilder>();
//        //modify by weidy@2021-11-15,在沈飞的发现一个现象是,拆分了的视图可能某个字段全部为null,这样多个视图链接到一起的时候,会出现类型不一致问题
//        String[] sysAbItems = OmdTools.getBtSysANames();
//        String querySysAttrSql = "select " + arrayToString(sysAbItems);
//        for(String btName : btNames){
//            try {
//                String[] abNames;
//                abNames = ServiceProvider.getOMDService().getBTMService().getBtmApNameArray(btName);
//                btAttrMap.put(btName, arrayToList(abNames));
//                btSqlMap.put(btName, new StringBuilder(querySysAttrSql));
//            } catch (VCIError e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//             
//        }
//        
//        Map<String, String> mapAttrNull = new HashMap<String, String>();
//        
//        for(String attrName : allAttrName){
//            for(String btName : btNames){
//                btSqlMap.get(btName).append(",");
//                if(btAttrMap.get(btName).contains(attrName)){
//                    btSqlMap.get(btName).append(attrName);
//                }else{
//                    String attrNull = "";
//                    
//                    if (mapAttrNull.containsKey(attrName)) {
//                        attrNull = mapAttrNull.get(attrName);
//                    } else {
//                        attrNull = CreateAttrNull(attrName);
//                        mapAttrNull.put(attrName, attrNull);
//                    }
//                    btSqlMap.get(btName).append(attrNull);
//                }
//            }
//        }
//        
//        for(String btName : btNames){
//            btSqlMap.get(btName).append(" from " + OmdTools.getBTTableName(btName));
//        }
//        return btSqlMap;
//    }
    
    /**
     * 创建null AS 指定类型属性
     * @param attrName
     * @return
     */
//    private static String CreateAttrNull(String attrName) {
//        try {
//
//            AttPoolServicePrx attrService = ServiceProvider.getOMDService().getAttributeService();
//
//            AttribItem ai = attrService.getAttribItemByName(attrName);
//
//            String vtType = ai.vtDataType;
//            int length = 50;
//            String lengthStr = getOtherValueByType(ai.other, "length");
//
//            if ((lengthStr != null) && (!lengthStr.equals(""))) {
//                length = Integer.valueOf(lengthStr).intValue();
//            }
//
//            String sqlType = "";
//
//            if (VTDataType.VTSTRING.equalsIgnoreCase(vtType)) {
//                sqlType = "VARCHAR2(" + length + ")";
//            } else if (VTDataType.VTLONG.equalsIgnoreCase(vtType) || VTDataType.VTINTEGER.equalsIgnoreCase(vtType)) {
//                sqlType = "NUMBER";
//            } else if (VTDataType.VTDOUBLE.equalsIgnoreCase(vtType)) {
//                sqlType = "NUMBER";
//            } else if (VTDataType.VTBOOLEAN.equalsIgnoreCase(vtType)) {
//                sqlType = "VARCHAR2(8)";
//            } else if (VTDataType.VTIMAGE.equalsIgnoreCase(vtType)) {
//                sqlType = "VARCHAR2(255)";
//            } else if (VTDataType.VTDATE.equalsIgnoreCase(vtType)) {
//                sqlType = "DATE";
//            } else if (VTDataType.VTDATETIME.equalsIgnoreCase(vtType) || VTDataType.VTTIME.equalsIgnoreCase(vtType)) {
//                sqlType = "TIMESTAMP";
//            } else if (VTDataType.VTFILEPATH.equalsIgnoreCase(vtType) || VTDataType.VTNOTE.equalsIgnoreCase(vtType)) {
//                sqlType = "VARCHAR2(255)";
//            } else if (VTDataType.VTCLOB.equalsIgnoreCase(vtType)) {
//                sqlType = "CLOB";
//            } else {
//                sqlType = "VARCHAR2(" + length + ")";
//            }
//
//            // btSqlMap.get(btName).append("cast(null as " + sqlType + " ) as " + attrName);
//            String attrNull = "cast(null as " + sqlType + " ) as " + attrName;
//
//            return attrNull;
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//
//        return "";
//    }
    
    public static String getOtherValueByType(String other, String type) {
        String[] otherArray = other.split(";");
        for (int i = 0; i < otherArray.length; i++) {
            String otherValue = otherArray[i];
            if (otherValue.contains(type)) {
                return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
            }
        }
        return null;
    }
 
    /**
     * 视图cols 
     * viewName.col as col2
     * @param ltName
     * @return
     */
//    public static List<String> getViewColsWithAlias(String[] btNames, String viewName) {
//        List<String> cols = new ArrayList<String>();
//        String[] sysAbItems = OmdTools.getBtSysANames();
//        for(String sysAbItem : sysAbItems){
//            cols.add(viewName + "." + sysAbItem + " AS " + sysAbItem + "2");
//        }
//        Set<String> userAttrNameSet = getUserAttrNameSet(btNames);
//        for(String userAttrName : userAttrNameSet){
//            cols.add(viewName + "." + userAttrName + " AS " + userAttrName + "2");
//        }
//        return cols;
//    }
//    
    
    /**
     * 获取查询条件的 值 
     * @param con
     * @param key
     * @return
     */
//    public static String getConditionItemVlaue(Condition con, String key){
//        if(con == null){
//            return null;
//        }
//        Map<String, ConditionItem> ciMap = con.getCIMap();
//        for(String ciId : ciMap.keySet()){
//            ConditionItem ci = ciMap.get(ciId);
//            if(ci.isLeaf()){
//                LeafInfo leafInfo = ci.getLeafInfo();
//                String clause = leafInfo.getClause();
//                if(clause.equalsIgnoreCase(key)){
//                    return leafInfo.getValue().getOrdinaryValue();
//                }
//            }
//        }
//        return null;
//    }
    
    /**
     * 根据leafInfo获取属性名和条件值,
     * 当有参照时, 加上参照路径
     * @param leafInfo
     * @return
     */
    public static Map<String, String> getClauseAndValue(LeafInfo leafInfo){
        Map<String, String> map = new HashMap<String, String>();
        String attName = leafInfo.getClause();
        QueryTemplate refQt = leafInfo.getValue().getQueryTemplate();
        //add by zhangweiwei 2014/12/09 start
        String value = null;
        if(refQt != null){
            List<String>  clauselist = refQt.getClauseList();
            String attr = clauselist.get(0);
            value = refQt.getId()+";"+attr;
        }else{
            value = leafInfo.getValue().getOrdinaryValue();
        }
        map.put("value", value);
        if(refQt != null&&refQt.getId().startsWith("qt_")){
            while(refQt != null){
                Condition cond = refQt.getCondition();
                if(cond != null){
                    ConditionItem ci = cond.getCIMap().get(cond.getRootCIName());
                    leafInfo = ci.getLeafInfo();
                    attName += "." + leafInfo.getClause();
                    refQt = leafInfo.getValue().getQueryTemplate();
                }else{
                    break;
                }
            }
        }
        map.put("clause", attName);
        //add by zhangweiwei 2014/12/09 end
        return map;
    }
    
    /**
     * 为提高使用效率, 将KV[][]转化成List
     * @param array2D
     * @return
     */
    public static List<Map<String, String>> parseKVArray2D(KV[][] array2D){
        List<Map<String, String>> list = new ArrayList<Map<String,String>>(array2D.length);
        for(KV[] array : array2D){
            Map<String, String> map = new HashMap<String, String>(array.length);
            for(KV kv : array){
                map.put(kv.key, kv.value);
            }
            list.add(map);
        }
        return list;
    }
    
 
    /**
     * 检查属性类型与属性值是否匹配
     * @param vtType
     * @param value
     * @return
     */
    private static boolean checkDataType(String vtType, String value){
        
        if(vtType.equals(VTDataType.VTSTRING)){
            try{
                String.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }else if(vtType.equals(VTDataType.VTINTEGER)){
            try{
                Integer.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }else if(vtType.equals(VTDataType.VTLONG)){
            try{
                Long.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }else if(vtType.equals(VTDataType.VTDOUBLE)){
            try{
                Double.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }
    
        return true;
    }
 
}