ludc
2024-10-23 49f13be32b8c3a0742df021f13300f34d86c9b89
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
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
package com.vci.web.service.impl;
 
import com.vci.client.common.oq.OQTool;
import com.vci.common.qt.object.*;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.omd.qtm.QTInfo;
import com.vci.corba.query.ObjectQueryService;
import com.vci.corba.query.ObjectQueryServicePrx;
import com.vci.corba.query.data.BtmRefQueryOption;
import com.vci.corba.query.data.KV;
import com.vci.frameworkcore.compatibility.SmUserQueryServiceI;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.*;
import com.vci.starter.web.annotation.Column;
import com.vci.starter.web.constant.QueryOptionConstant;
import com.vci.starter.web.enumpck.BooleanEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.PageHelper;
import com.vci.starter.web.util.BeanUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.properties.WebProperties;
import com.vci.web.service.*;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 业务类型操作服务---只能在dao层调用,其他的服务不允许使用
 * 自动封装了平台相关的操作
 * @author weidy
 */
@Service
public class WebBoServiceImpl implements WebBoServiceI{
    
    /**
     * 枚举服务
     */
    @Autowired
    private OsEnumServiceI enumService;//枚举服务
    
    /**
     * 属性服务
     */
    @Autowired
    private OsAttributeServiceI attrService;//属性服务
 
    /**
     * 生命周期的服务
     */
    @Autowired
    private OsLifeCycleServiceI lifeService;//生命周期服务
 
    /**
     * 状态的服务
     */
    @Autowired
    private OsStatusServiceI statusService;
 
    /**
     * 用户查询服务
     */
    @Autowired
    private SmUserQueryServiceI userQueryService;
 
    /**
     * 链接类型服务
     */
    @Autowired
    private WebLoServiceI loService;
 
    /**
     * 配置信息
     */
    @Autowired
    private WebProperties webProperties;
    
    /**
     * 多语言前缀
     */
    private final String msgCodePrefix = "com.vci.web.boService.";
    
    /**
     * 日志对象
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 业务类型的服务
     */
    @Autowired
    private OsBtmServiceI btmService;
 
    /**
     * 版本规则的服务
     */
    @Autowired
    private OsRevisionRuleServiceI revisionRuleService;
 
    /**
     * 平台调用客户端
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 已经创建过的业务对象
     */
    private static Map<String, BusinessObject> hasCreatedCbos = new HashMap<String, BusinessObject>();
 
    /**
     * 业务对象默认属性
     */
    public static final Map<String,String> BO_BASE_FIELD_MAP = new HashMap<>();
 
    public WebBoServiceImpl(){
        List<Field> fields = WebUtil.getAllFieldForObj(BusinessObject.class);
        if(!CollectionUtils.isEmpty(fields)) {
            fields.stream().forEach(field -> {
                BO_BASE_FIELD_MAP.put(field.getName(),WebUtil.getCboAttrNameFromField(field,BusinessObject.class));
            });
        }
    }
 
    /**
     * 初始化业务类型
     * --第一次调用的时候会相对慢一下,后续获取就很快的
     * --注意在服务启动时才会清除缓存
     * --创建人默认为当前用户,如果需要修改,可以在获取后自行处理
     * @param btmName 业务类型的名称,会自动变成小写
     * @return 业务数据的对象
     * @throws VciBaseException 初始化出错的是会抛出异常
     */
    @Override
    public BusinessObject createCBOByBtmName(String btmName)
            throws VciBaseException {
        if(btmName!=null){
            btmName = btmName.trim().toLowerCase();
        }
        String userid = WebUtil.getCurrentUserId();
        if(!hasCreatedCbos.containsKey(btmName)){
            if(StringUtils.isEmpty(userid)){
                throw new VciBaseException(msgCodePrefix +"noHasUserid");
            }
            try {
//                ClientServiceProvider.getBOFService().initBusinessObject(btmName); 可以进行替换
                hasCreatedCbos.put(btmName, createBusinessObject(btmName));
            } catch (Exception e) {
                logger.error("创建业务类型对象",e);
                throw new VciBaseException(msgCodePrefix + "initBoError",new String[]{btmName});
            }
        }
        BusinessObject cbo = cloneBusinessObject(hasCreatedCbos.get(btmName));
        return cbo;
    }
 
    /**
     * 根据业务类型名称创建业务数据源对象
     * @param boName 业务类型名称
     * @return 业务数据对象
     */
    public BusinessObject createBusinessObject(String boName) throws PLException {
//        ClientServiceProvider.getBOFService().initBusinessObject(boName);
        OsBtmTypeVO btmTypeVO = btmService.getBtmById(boName);
        String userName = WebUtil.getCurrentUserId();
        BusinessObject bo = new BusinessObject();
        bo.oid = (new ObjectUtility()).getNewObjectID36();
        bo.revisionid = (new ObjectUtility()).getNewObjectID36();
        bo.nameoid = (new ObjectUtility()).getNewObjectID36();
        bo.btName = boName;
        bo.isLastR = true;
        bo.isFirstR = true;
        bo.isFirstV = true;
        bo.isLastV = true;
        bo.creator = userName;
        bo.createTime = System.currentTimeMillis();
        bo.modifier = userName;
        bo.modifyTime = System.currentTimeMillis();
        bo.revisionRule = btmTypeVO.getRevisionRuleId();
        bo.versionRule = String.valueOf(btmTypeVO.getVersionRule());
        if(StringUtils.isNotBlank(btmTypeVO.getRevisionRuleId())){
            OsRevisionRuleVO revisionRuleVO = revisionRuleService.getRevisionRuleById(btmTypeVO.getRevisionRuleId());
            bo.revisionValue = revisionRuleVO.getInitialValue();
        }
 
        bo.revisionSeq = (short) 1;
        bo.versionSeq = (short) 1;
        bo.versionValue = getVersionValue(WebUtil.getInt(btmTypeVO.getVersionRule()));
        bo.lctId = btmTypeVO.getLifeCycleId();
        if(StringUtils.isNotBlank(btmTypeVO.getLifeCycleId())){
            OsLifeCycleVO lifeCycleVO = lifeService.getLifeCycleById(btmTypeVO.getLifeCycleId());
            //todo 无法获取数据
            bo.lcStatus = lifeCycleVO == null ? "" : lifeCycleVO.getStartStatus();
        }
        bo.id = "";
        bo.name = "";
        bo.description = "";
        bo.owner = userName;
//        bo.setCheckinBy(userName);
        bo.fromVersion = "";
        this.initTypeAttributeValue(bo,btmTypeVO);
        return bo;
    }
 
    /**
     * 初始化业务类型的默认值
     * @param cbo 业务数据对象
     * @param btmTypeVO 业务类型的显示对象
     */
    private void initTypeAttributeValue(BusinessObject cbo,OsBtmTypeVO btmTypeVO) {
        Optional.ofNullable(btmTypeVO.getAttributes()).orElseGet(()->new ArrayList<>()).stream().forEach(attribute->{
            ObjectTool.setBOAttributeValue(cbo,attribute.getId(),attribute.getDefaultValue());
        });
    }
 
    /**
     * 获取版次的值
     * @param verRuleName 版次的规则
     * @return 版次的值,没有规则则为空
     */
    private String getVersionValue(int verRuleName) {
        if (verRuleName == 0) {
            return "1";
        } else if (verRuleName == 1) {
            return "a";
        } else if (verRuleName == 2) {
            return "0";
        }
        return "";
    }
 
    /**
     * 拷贝以前的业务数据
     * @param cbo 以前的业务数据对象
     * @return 拷贝后的对象
     */
    private  BusinessObject cloneBusinessObject(BusinessObject cbo){
        if(cbo !=null){
            BusinessObject businessObject = new BusinessObject();
            businessObject.oid = new ObjectUtility().getNewObjectID36();
            businessObject.revisionid = new ObjectUtility().getNewObjectID36();
            businessObject.nameoid = new ObjectUtility().getNewObjectID36();
            businessObject.btName = cbo.btName;
            businessObject.isLastR = cbo.isLastR;
            businessObject.isFirstR = cbo.isFirstR;
            businessObject.isLastV = cbo.isLastV;
            businessObject.isFirstV = cbo.isFirstV;
            businessObject.creator = WebUtil.getCurrentUserId();
            businessObject.createTime = System.currentTimeMillis();
            businessObject.modifier = cbo.modifier;
            businessObject.modifyTime = cbo.modifyTime;
            businessObject.revisionRule = cbo.revisionRule;
            businessObject.versionRule = cbo.versionRule;
            businessObject.revisionSeq = cbo.revisionSeq;
            businessObject.revisionValue = cbo.revisionValue;
            businessObject.versionSeq = cbo.versionSeq;
            businessObject.versionValue = cbo.versionValue;
            businessObject.lctId = cbo.lctId;
            businessObject.lcStatus = cbo.lcStatus;
            businessObject.ts = System.currentTimeMillis();
            businessObject.id = cbo.id;
            businessObject.name = cbo.name;
            businessObject.description = cbo.description;
            businessObject.owner = businessObject.creator;
            businessObject.fromVersion = cbo.fromVersion;
            if(cbo.newAttrValList !=null){
                businessObject.newAttrValList = clone(cbo.newAttrValList);
            }
            if(cbo.hisAttrValList !=null){
                businessObject.hisAttrValList = clone(cbo.hisAttrValList);
            }
            return businessObject;
        }else {
            return null;
        }
    }
 
    /**
     * 拷贝属性的值
     * @param newAttrValList 属性值对象数组
     * @return 拷贝后的新属性数组
     */
    private  AttributeValue[] clone(AttributeValue[] newAttrValList) {
        AttributeValue[] n = new AttributeValue[newAttrValList.length];
        for (int i = 0; i < newAttrValList.length; i++) {
            n[i] = new AttributeValue(newAttrValList[i].attrName,newAttrValList[i].attrVal);
        }
        return n;
    }
 
    /**
     * 前端的查询条件转换为平台需要的查询对象
     * @param conditionMap 查询条款
     * @return 查询对象
     */
    @Override
    public Condition getConditionByMap(Map<String, String> conditionMap){
        Condition mergeCondition = null;//组合后的查询条件
        if(conditionMap!=null && conditionMap.size() > 0){
            //先把所有的查询条件都转换为小写
            //然后开始逐个遍历,主要是对_start和_end这样的
            Iterator<String> itor = conditionMap.keySet().iterator();
            while(itor.hasNext()){
                String key = itor.next();
                String value = conditionMap.get(key);
                Condition condition = null;//本次的条件
                Map<String,String> thisConditionMap = new HashMap<String, String>();
                boolean isOr = false;
                if(WebUtil.isNotNull(value) && value.startsWith(QueryOptionConstant.OR)){
                    isOr = true;
                    value = value.substring(4);
                }
                if(key.indexOf("_start")>-1 || key.indexOf("_end")>-1){//介于....之间
                    if(key.indexOf("_start")>-1){
                        String attr = key.replace("_start", "");
                        thisConditionMap.put(attr, value);
                        condition = OQTool.getCondition(thisConditionMap);
                        if(conditionMap.containsKey(attr + "_end")){//如果没有结束,其实也是允许的;
                            Map<String,String> endConditonMap = new HashMap<String, String>();
                            endConditonMap.put(attr, conditionMap.get(attr + "_end"));
                            condition = OQTool.mergeCondition(condition, OQTool.getCondition(endConditonMap), Connector.AND);
                        }
                    }
                }else{
                    if(("creator".equalsIgnoreCase(key) || "lastmodifier".equalsIgnoreCase(key)) && StringUtils.isNotBlank(value)  ){
                        //说明是查询创建人和最后修改人
                        //模糊,等于,不等于,其余的不处理姓名
                        if(value.contains("*")) {
                            //说明是like
                            String userValue = value.replace("*", "%");
                            thisConditionMap.put(key, QueryOptionConstant.IN + "(select plusername from pluser where plusername like '" + userValue + "' or pltruename like '" + userValue + "')");
                        }else if(value.startsWith(QueryOptionConstant.NOTEQUAL)){
                            thisConditionMap.put(key, QueryOptionConstant.NOTIN + "(select plusername from pluser where plusername = '" + value + "' or pltruename = '" + value + "')");
                        }else if(value.startsWith(QueryOptionConstant.EQUAL)){
                            thisConditionMap.put(key, QueryOptionConstant.IN + "(select plusername from pluser where plusername = '" + value + "' or pltruename = '" + value + "')");
                        }else{
                            thisConditionMap.put(key, value);
                        }
                    }else {
                        thisConditionMap.put(key, value);
                    }
                    condition = OQTool.getCondition(thisConditionMap);
                }
                if(mergeCondition == null){
                    mergeCondition = condition;
                }else{
                    mergeCondition = OQTool.mergeCondition(mergeCondition, condition, isOr? Connector.OR:Connector.AND);
                }
            }
        }
        return mergeCondition;
    }
 
    /**
     * 根据属性来查询主键
     *
     * @param referInfo 业务类型.属性名
     * @param value     属性的值
     * @return 查询后的值
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public Map<String, String> queryOidByPropertie(String referInfo, List<String> value) throws VciBaseException {
        WebUtil.alertNotNull(referInfo,"参照信息",value,"参照的内容");
        if(referInfo.indexOf(".") < 0){
            throw  new VciBaseException("参照的信息必须是【业务类型.属性】这样的格式");
        }
        String btmName = referInfo.split("\\.")[0].trim().toLowerCase();
        String fieldName = referInfo.split("\\.")[1].trim().toLowerCase();
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put(fieldName,QueryOptionConstant.IN + "(" + WebUtil.toInSql(value.toArray(new String[0])) + ")");
        List<BusinessObject> cbos = queryCBO(btmName,conditionMap,null, Arrays.asList(new String[]{"oid",fieldName}));
 
        Map<String,String> data = new HashMap<String, String>();
        if(cbos!=null && cbos.size() > 0){
            for(BusinessObject cbo : cbos){
                data.put(ObjectTool.getBOAttributeValue(cbo,fieldName),cbo.oid);
            }
        }
        return data;
    }
 
    /**
     * 校验特定属性的值是否存在
     *
     * @param btmName      业务类型
     * @param columnName   列名称
     * @param columnValues 列的值
     * @return true表示存在这个值
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public boolean checkDataExsitByColumn(String btmName, String columnName, Collection<String> columnValues) throws VciBaseException {
        WebUtil.alertNotNull(btmName,"业务类型",columnName,"属性名称",columnValues,"属性" + columnName + "的值");
        Map<String,String> conditionMap = new HashMap<String, String>();
        Set<String> oidSet = new HashSet<String>();
        for(String oid : columnValues){
            if(StringUtils.isNotBlank(oid)){
                oidSet.add(oid);
            }
        }
        if(oidSet.size() == 0){
            throw new VciBaseException("属性" + columnName + "的值为空");
        }
        conditionMap.put(columnName,QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oidSet.toArray(new String[0])) + ")");
        List<BusinessObject> cbos = queryCBO(btmName,conditionMap,null,Arrays.asList(new String[]{columnName}));
        if(cbos !=null && cbos.size() >0){
            for(BusinessObject cbo : cbos){
                String oid = ObjectTool.getBOAttributeValue(cbo,columnName);
                if(oidSet.contains(oid)){
                    oidSet.remove(oid);
                }
            }
            if(oidSet.size()>0){
                throw new VciBaseException("属性" + columnName + "的值有" + oidSet.size() + "个不存在");
            }
            return true;
        }else{
            throw new VciBaseException("属性" + columnName + "的值全部不存在");
        }
    }
 
    /**
     * 校验特定属性的值是否存在
     *
     * @param btmName      业务类型
     * @param columnName   列名称
     * @param columnValues 列的值
     * @return
     * @throws VciBaseException
     */
    @Override
    public boolean checkDataExsitByColumn(String btmName, String columnName, String columnValues) throws VciBaseException {
        WebUtil.alertNotNull(columnValues,"属性" + columnName + "的值");
        return checkDataExsitByColumn(btmName,columnName,Arrays.asList(columnValues.split(",")));
    }
 
    /**
     * 根据查询条件来查询业务类型下的数据
     * @param btmType 业务类型的名称,会自动变成小写
     * @param conditionMap 查询条件,注意介于...之间使用xxx_start和xxx_end
     * @return 业务数据列表
     * @throws VciBaseException 查询出错的是抛出异常
     */
    @Override
    public List<BusinessObject> queryCBO(String btmType,
            Map<String, String> conditionMap) throws VciBaseException {
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        PageHelper ph = new PageHelper(-1);
        return queryCBO(btmType,conditionMap,ph,clauseList);
    }
 
    /**
     * 支持排序和分页的查询业务类型下的数据
     * @param btmType 业务类型的名称
     * @param conditionMap 查询条件,注意介于...之间使用xxx_start和xxx_end
     * @param ph 排序和分页
     * @return  业务数据列表
     * @throws VciBaseException 查询出错的是抛出异常
     */
    @Override
    public List<BusinessObject> queryCBO(String btmType,
            Map<String, String> conditionMap, PageHelper ph)
            throws VciBaseException {
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        return queryCBO(btmType,conditionMap,ph,clauseList);
    }
 
    /**
     * 使用查询方案来查询数据,返回CBO
     * @param btmType 业务类型名称
     * @param conditionMap 查询条件
     * @param ph 分页对象
     * @param  clauseList 查询字段
     * @return 业务数据列表
     * @throws VciBaseException 查询出错的是抛出异常
     */
    @Override
    public List<BusinessObject> queryCBO(String btmType,
            Map<String, String> conditionMap, PageHelper ph,
            List<String> clauseList) throws VciBaseException {
        QueryTemplate qt = new QueryTemplate();
        //基础设置
        qt.setId("queryBOHasPage");
        qt.setType(QTConstants.TYPE_BTM);
        qt.setBtmType(btmType.toLowerCase());
        return baseQueryCBO(qt, conditionMap, ph, clauseList);
    }
 
    /**
     * 设置是否过滤数据权限
     * @param qt 查询模板
     * @param conditionMap 查询条件
     */
    private void setRightValueToQueryTemplate(QueryTemplate qt,Map<String,String> conditionMap){
        boolean filterDataRight = webProperties.isDataRight();
        if(conditionMap == null){
            conditionMap = new HashMap<String, String>();
        }
        if(conditionMap.containsKey(QUERY_FILTER_DATARIGHT)){
            if(BooleanEnum.TRUE.getValue().equals(conditionMap.get(QUERY_FILTER_DATARIGHT).toLowerCase())){
                filterDataRight = true;
            }else{
                filterDataRight = false;
            }
            conditionMap.remove(QUERY_FILTER_DATARIGHT);
        }
        boolean filterSecret = webProperties.isSecretRight();
        if(conditionMap.containsKey(QUERY_FILTER_SECRET)){
            if(BooleanEnum.TRUE.getValue().equals(conditionMap.get(QUERY_FILTER_SECRET).toLowerCase())){
                filterSecret = true;
            }else{
                filterDataRight = false;
            }
            conditionMap.remove(QUERY_FILTER_SECRET);
        }
        qt.setRightFlag(filterDataRight);
        qt.setSecretFlag(filterSecret);
    }
 
    /**
     * 基础的查询方法
     * @param qt 查询模板
     * @param conditionMap 查询条件
     * @param ph 分页
     * @param clauseList 查询字段
     * @return 查询出来的值
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    private List<BusinessObject> baseQueryCBO(QueryTemplate qt,Map<String,String> conditionMap,PageHelper ph,List<String> clauseList) throws VciBaseException{
        List<BusinessObject> allCbos = new ArrayList<BusinessObject>();
        if(clauseList == null){
            clauseList = new ArrayList<String>();
            clauseList.add("*");
        }
        setRightValueToQueryTemplate(qt,conditionMap);//设置密级查询,和数据权限控制
        List<BtmRefQueryOption> refOpts = new ArrayList<BtmRefQueryOption>();
        List<String> enumAttrName = new ArrayList<String>();
        List<String> thisQueryAttr = new ArrayList<String>();
        if(clauseList!=null && clauseList.size()>0){
            for(String attrName : clauseList){
                if(attrName.indexOf(".")>-1){
                    String[] kvs = attrName.split("\\.");
                    int len = kvs.length;
                    if(len == 2){
                        // 一层参照 a.b
                        // 第二个参数给空,是此不处从属性中查其参数的业务类型,由下下专用掊中进行处理
                        BtmRefQueryOption refOpt = new BtmRefQueryOption(
                        kvs[0], "", new String[]{kvs[1]}
                        );
                        refOpts.add(refOpt);
                    } else if(len == 3){
                        // 二层参照 a.b.c
                        // TODO 需要支持两层参照
                    } else {
                        // 三层以的参照 a.b.c.d a.b.c.d.e
                        // TODO 需要支持三层以及以上的参照
                    }
                }else if(attrName.indexOf("_")>-1 
                        && !"lcStatus_text".toLowerCase().equalsIgnoreCase(attrName.toLowerCase())){
                    enumAttrName.add(attrName);
                }else{
                    thisQueryAttr.add(attrName);
                }
            }
        }
        if(thisQueryAttr.isEmpty()){
            thisQueryAttr.add("*");
        }
        //设置查询字段,这个必须是当前业务类型中的查询字段
        qt.setClauseList(thisQueryAttr);
        conditionMap = WebUtil.getNotNullMap(conditionMap);
        Condition condition = getConditionByMap(conditionMap);
        if(qt.getCondition() !=null) {
            qt.setCondition(OQTool.mergeCondition(qt.getCondition(), condition, Connector.AND));
        }else {
            qt.setCondition(condition);
        }
        qt.setLevel(-1);//对于业务类型来说没有作用
 
        //设置分页信息和排序
        setPageAndOrderToQT(qt,ph);
        try {
            ObjectQueryServicePrx qtService = platformClientUtil.getQueryService();
            if(qtService == null){
                logger.error("没有找到查询服务");
                throw new VciBaseException(msgCodePrefix+"qtServerNull", new String[]{});
            }
            ObjectQueryService.FindBTMObjectsV3Result bos = qtService.findBTMObjectsV3(qt.getId(), OQTool.qtTOXMl(qt).asXML(), refOpts.toArray(new BtmRefQueryOption[refOpts.size()]));
            if (bos != null && bos.count > 0) {
                for (BusinessObject bo : bos.returnValue) {
//                    BusinessObject cbo = new BusinessObject();
//                    cbo = bo;
                    queryEnumText(bo,enumAttrName);
                    allCbos.add(bo);
                }
                //因为修改了查询的方式,所以就不需要单独查询参照
            }
            queryLcStatus(allCbos);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        return allCbos;
    }
 
    public AttributeValue[] copyToAttributeValue(AttributeValue[] attributeValues){
        AttributeValue[] attributeValueList = new AttributeValue[attributeValues.length];
        for (int i = 0; i < attributeValues.length; i++) {
            AttributeValue newAttributeValue = new AttributeValue();
            newAttributeValue.attrName = attributeValues[i].attrName;
            newAttributeValue.attrVal = attributeValues[i].attrVal;
            attributeValueList[i] = newAttributeValue;
        }
        return attributeValueList;
    }
 
    /**
     * 拷贝分页和排序的设置到查询模板
     * @param qt 查询,模板
     * @param pageHelper 分页对象
     */
    @Override
    public void setPageAndOrderToQT(QueryTemplate qt,PageHelper pageHelper){
        if(pageHelper!=null){
            if(pageHelper.getLimit()>0){
                PageInfo pageInfo = new PageInfo();
                pageInfo.setPageNO(pageHelper.getPage());
                pageInfo.setRowCount(pageHelper.getLimit());
                qt.setPageInfo(pageInfo);
            }
            if(WebUtil.isNotNull(pageHelper.getSort()) && WebUtil.isNotNull(pageHelper.getOrder())){
                //设置了排序
                String[] sort = pageHelper.getSort().split(",");
                String[] order = pageHelper.getOrder().split(",");
                if(sort.length != order.length){
                    throw new VciBaseException(msgCodePrefix + "sortlengtherror",new Object[]{sort.length,order.length});
                }
                List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
                for(int i = 0 ; i < sort.length ;i++){
                    OrderInfo oi =  new OrderInfo();
                    oi.setOrderField(sort[i]);
                    oi.setOrderMode(order[i]);
                    oi.setLevel(sort.length -i);//值越大优先级越大,而排在数组的前面的优先级越大
                    orderInfoList.add(oi);
                }
                qt.setOrderInfoList(orderInfoList);
            }
        }
    }
    
    /**
     * 获取所有的枚举属性
     * @param allAttrMap 所有的属性
     * @return 获取属性中的枚举属性
     */
    private List<String> getEnumAttrName(Map<String,String> allAttrMap){
        List<String> enumAttrName = new ArrayList<String>();
        if(allAttrMap!=null && allAttrMap.size() > 0){
            for(String attr : allAttrMap.keySet()){
                if(attr.indexOf("_")>-1 
                        && !"lcStatus_text".toLowerCase().equalsIgnoreCase(attr)){
                    enumAttrName.add(attr);
                }
            }
        }
        return enumAttrName;
    }
    
    /**
     * 获取引用的属性---只支持一级参照
     * @param allAttrMap 所有的属性
     * @return 枚举属性
     */
    private Map<String,String> getReferAttrName(Map<String,String> allAttrMap){
        Map<String,String> referAttrName = new HashMap<String,String>();
        if(allAttrMap!=null && allAttrMap.size() > 0){
            for(String attr : allAttrMap.keySet()){
                if(attr.indexOf(".")>-1){
                    referAttrName.put(attr,allAttrMap.get(attr));
                }
            }
        }
        return referAttrName;
    }
    
    /**
     * 查询生命周期的值
     * @param cbos 业务对象
     */
    private void queryLcStatus(List<BusinessObject> cbos){
        if(!CollectionUtils.isEmpty(cbos)){
 
            Map<String, OsStatusVO> statusVOMap = statusService.selectAllStatusMap();
            cbos.stream().forEach(cbo->{
                try{
                    ObjectTool.setBOAttributeValue(cbo,"lcStatus_text", statusVOMap.getOrDefault(cbo.lcStatus,new OsStatusVO()).getName());
                }catch(Exception e){
                    logger.error("获取生命周期中状态的显示文本出错",e);
                }
            });
        }
    }
    
    /**
     * 查询业务对象上的枚举值
     * @param cbo 业务对象
     * @param enumAttrName 枚举属性的值
     * @throws VciBaseException
     */
    private void queryEnumText(BusinessObject cbo,List<String> enumAttrName) throws VciBaseException{
        queryEnumText(cbo,null,enumAttrName);
    }
 
    /**
     * 查询枚举的信息
     * @param cbo 业务数据
     * @param clo 链接属性
     * @param enumAttrName 枚举的名称
     * @throws VciBaseException 查询枚举出错的时候会抛出异常
     */
    @Override
    public void queryEnumText(BusinessObject cbo, LinkObject clo, List<String> enumAttrName) throws VciBaseException{
        if(enumAttrName.size()>0){//查询枚举
            for(String enumAttr:enumAttrName){//格式为   code_field  code是枚举的编码,field是当前业务类型存储枚举值的字段
                if(enumAttr.toLowerCase().equals("creator_name")){
                    //创建人的名称
                    String creator = "";
                    if(cbo!=null){
                        creator = cbo.creator;
                    }else{
                        creator = clo.creator;
                    }
                    if(StringUtils.isNotBlank(creator)){
                        String userTrueName = userQueryService.getUserNameByUserId(creator);
                        setValueToCboOrClo(cbo,clo,"creator_name",userTrueName);
                    }
                }else if(enumAttr.toLowerCase().equals("lastmodifier_name")){
                    //最后修改人名称
                    String modifier = "";
                    if(cbo!=null){
                        modifier = cbo.modifier;
                    }else{
                        modifier = clo.modifier;
                    }
                    if(StringUtils.isNotBlank(modifier)){
                        String userTrueName = userQueryService.getUserNameByUserId(modifier);
                        setValueToCboOrClo(cbo,clo,"lastmodifier_name",userTrueName);
                    }
                }else if(enumAttr.toLowerCase().endsWith("${user_name}")){
                    String usernameField = enumAttr.toLowerCase();
                    String fields= usernameField.replace("${user_name}","");
                    if(fields.contains("_")){
                        String valueField = "";
                        valueField = fields.split("_")[0];
                        String value = ObjectTool.getBOAttributeValue(cbo,valueField);;
                        if(StringUtils.isNotBlank(value)){
                            String userTrueName = userQueryService.getUserNameByUserId(value);
                            setValueToCboOrClo(cbo,clo,enumAttr,userTrueName);
                        }
                    }
                }else {
                    String[] tempArray = enumAttr.split("_");
                    String enumCode = tempArray[0];//枚举编码
                    if (tempArray.length > 1) {
                        //从枚举中获取值
                        String valueFieldName = tempArray[1];
                        String comboxField = "";
                        if(valueFieldName.contains("#")){
                            valueFieldName = tempArray[1].split("#")[0];
                            comboxField = tempArray[1].split("#")[1];
                        }
                        String enumKey = "";
                        if (cbo != null) {
                            enumKey = ObjectTool.getBOAttributeValue(cbo,valueFieldName);
                        } else if (clo != null) {
                            enumKey = ObjectTool.getLOAttributeValue(clo,valueFieldName);
                        }
                        String enumText = "";
                        if (WebUtil.isNotNull(enumKey)) {
                            enumText = enumService.getValue(enumCode, enumKey);
                        }
                        if(StringUtils.isNotBlank(comboxField)){
                            setValueToCboOrClo(cbo, clo, comboxField, enumText);
                        }else {
                            setValueToCboOrClo(cbo, clo, enumAttr.toLowerCase(), enumText);
                        }
                    }
                }
            }
        }
    }
 
    /**
     * 为业务类型设置值
     * @param cbo 业务类型
     * @param clo 链接类型
     * @param attr 属性名
     * @param value 值
     */
    private void setValueToCboOrClo(BusinessObject cbo,LinkObject clo,String attr,String value){
        try {
            if (cbo != null) {
                ObjectTool.setBOAttributeValue(cbo, attr, value);
            }else{
                setAttributeValueForClo(clo,attr, value);
            }
        } catch (Exception e) {
            logger.error("setValueToCboOrClo",e);
        }
    }
 
    /**
     * 给链接类型设置属性
     * @param clo 链接类型
     * @param attributeName 属性的名称
     * @param attributeValue 属性的值
     */
    @Override
    public void setAttributeValueForClo(LinkObject clo, String attributeName, String attributeValue) {
        AttributeValue[] attrValues = clo.newAttrValList;
        ArrayList<AttributeValue> attrValList = new ArrayList();
        AttributeValue attrVal;
        int i;
        if (attrValues != null && attrValues.length > 0) {
            AttributeValue[] var9 = attrValues;
            i = attrValues.length;
 
            for (int var7 = 0; var7 < i; ++var7) {
                attrVal = var9[var7];
                attrValList.add(attrVal);
            }
        }
 
        attrVal = null;
        boolean isExist = false;
 
        for (i = 0; i < attrValList.size(); ++i) {
            attrVal = (AttributeValue) attrValList.get(i);
            if (attrVal.attrName.toUpperCase().equals(attributeName.toUpperCase())) {
                attrVal.attrVal = attributeValue;
                isExist = true;
                break;
            }
        }
 
        if (!isExist) {
            attrVal = new AttributeValue();
            attrVal.attrName = attributeName.toUpperCase();
            attrVal.attrVal = attributeValue;
            attrValList.add(attrVal);
        }
 
        clo.newAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]);
    }
 
 
    /**
     * 查询链接类型中的枚举属性的对应值
     * @param clo 链接类型
     * @param enumAttrName 枚举属性
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    private void queryEnumTextClo(LinkObject clo,List<String> enumAttrName) throws VciBaseException{
        queryEnumText(null,clo,enumAttrName);
    }
 
    /**
     * 使用查询方案来查询数据,返回CBO,支持分页
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案里的变量值
     * @return 业务类型
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public List<BusinessObject> queryCBOByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap)
            throws VciBaseException {
        PageHelper ph = new PageHelper(-1);
        return queryCBOByScheme(queryScheme,conditionMap,replaceMap,ph);
    }
 
 
    /**
     *  使用查询方案来查询数据,返回CBO,支持自定义查询字段,包括参照和枚举;参照字段使用xxx.yy;枚举字段使用xxx_enumCode
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案里的变量值
     * @param ph 分页和排序
     * @return 业务数据
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public List<BusinessObject> queryCBOByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap,
            PageHelper ph) throws VciBaseException {
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        return queryCBOByScheme(queryScheme,conditionMap,replaceMap,ph,clauseList);
    }
 
    /**
     * 使用名字获取查询模板
     * @param name 名称
     * @param replaceMap 源数据
     * @return 查询模板
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public QueryTemplate getQtByName(String name, Map<String, String> replaceMap) throws VciBaseException{
        QueryTemplate qt = null;
        try{
            VciBaseUtil.alertNotNull(name,"查询模板的名称");
            QTInfo wrapper = platformClientUtil.getQTDService().getQT(name);
            qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), name);
            //因为之前平台的Tool.replaceQTValues 没有处理 ${xxx}。, 为了忽略大小写,我们这里单独处理 weidy@2021-3-10
            //我们转换为小写
            Condition condition = qt.getCondition();
            Map<String,String> replaceLowMap = new HashMap<>();
            if(condition !=null && condition.getCIMap()!=null){
                // Map<String, String> systemVarValueMap = VciSystemVarConstants.getSystemVarValueMap();
                if(!CollectionUtils.isEmpty(replaceMap)){
                    replaceMap.forEach((key,value)->{
                        replaceLowMap.put(key.toLowerCase(),value);
                    });
                }
                Map<String, ConditionItem> ciMap = condition.getCIMap();
                ciMap.forEach((ciId,ci)->{
                    if(ci.isLeaf()) {
                        LeafInfo lInfo = ci.getLeafInfo();
                        String value = lInfo.getValue().getOrdinaryValue();
                        if(StringUtils.isNotBlank(value)){
                            if(value.contains("#")){
                                //系统变量.支持一个
                                //lInfo.getValue().setOrdinaryValue(systemVarValueMap.getOrDefault(value.toUpperCase(),""));
                            }else if(value.contains("${")){
                                //有${xxxx}的方式
                                if(!CollectionUtils.isEmpty(replaceLowMap)) {
                                    try {
                                        lInfo.getValue().setOrdinaryValue(VciBaseUtil.replaceByFreeMarker(value, replaceLowMap));
                                    }catch (Throwable e){
                                        logger.error("可能配置有问题,在转换freemarker表达式的时候,没有找到对应的值,目前表达式为{}",new String[]{value},e);
                                    }
                                }
                            }else if(replaceLowMap.containsKey(value.toLowerCase())){
                                lInfo.getValue().setOrdinaryValue(replaceLowMap.get(value.toLowerCase()));
                            }
                        }
                    }
                });
            }
        }catch(PLException e){
            logger.error(e.code,e);
            throw WebUtil.getVciBaseException(e);
        } catch (DocumentException e) {
            logger.error("查询模板转换",e);
            throw new VciBaseException(this.msgCodePrefix + "qtError", new Object[]{name});
        }
        return qt;
    }
 
    /**
     * 根据查询模板来查询数据
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案里的变量值
     * @param ph 分页和排序
     * @param clauseList 查询字段
     * @return 业务数据列表
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public List<BusinessObject> queryCBOByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap,
            PageHelper ph, List<String> clauseList) throws VciBaseException {
        QueryTemplate qt = getQtByName(queryScheme,replaceMap);
        return baseQueryCBO(qt,conditionMap,ph,clauseList);
    }
 
    /**
     * 查询个数
     * @param qt 查询模板
     * @param conditionMap 查询条件
     * @return 个数
     * @throws VciBaseException 查询出错会抛出异常
     */
    private int baseQueryCount(QueryTemplate qt,Map<String, String> conditionMap) throws VciBaseException{
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        setRightValueToQueryTemplate(qt,conditionMap);//设置密级查询,和数据权限控制
        conditionMap = WebUtil.getNotNullMap(conditionMap);
        Condition condition = getConditionByMap(conditionMap);
        if(qt.getCondition() !=null) {
            qt.setCondition(OQTool.mergeCondition(qt.getCondition(), condition, Connector.AND));
        }else {
            qt.setCondition(condition);
        }
        long count = 0;
        try{
            count = platformClientUtil.getQueryService().findTotalCount(qt.getId(), OQTool.qtTOXMl(qt).asXML());
        }catch (PLException e) {
            logger.error(e.code,e);
            throw WebUtil.getVciBaseException(e);
        } 
        return (int) count;
    }
 
    /**
     * 查询个数
     * @param btmType 业务类型名称
     * @param conditionMap 查询条件
     * @return 个数
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public int queryCount(String btmType, Map<String, String> conditionMap)
            throws VciBaseException {
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryBOCount");
        if(btmType.endsWith("_link")){
            qt.setType(QTConstants.TYPE_LINK);
        }else{
            qt.setType(QTConstants.TYPE_BTM);
        }
        qt.setBtmType(btmType.toLowerCase());
        return baseQueryCount(qt,conditionMap);
    }
    /**
     * 使用sql查询个数,最终的字段必须是count
     * @param sql 查询的sql
     * @param conditionMap 查询条件
     * @return 个数,
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public int queryCountBySql(String sql,Map<String,String> conditionMap) throws VciBaseException{
        WebUtil.alertNotNull(sql,"sql语句");
        AttributeValue[] ava = null;
        if(conditionMap!=null&&!conditionMap.isEmpty()){
            ava = new AttributeValue[conditionMap.size()];
            Iterator<String> it = conditionMap.keySet().iterator();
            int i = 0 ;
            while(it.hasNext()){
                String key = it.next();
                String value = conditionMap.get(key);
                if(value == null){
                    value = "";
                }
                AttributeValue av = new AttributeValue(key, value);
                ava[i] = av;
                i++;
            }
        }else{
            ava = new AttributeValue[0];
        }
        try {
            String[][] results = platformClientUtil.getBOFactoryService().getSqlQueryResult(sql, ava);
            if(results!=null && results.length>0 && results[0] != null && results[0].length>0){
                return WebUtil.getInt(results[0][0]);
            }
        } catch (PLException e) {
            throw new RuntimeException(e);
        }
        return 0;
    }
 
    /**
     * 根据方案查询个数
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案里的变量值
     * @return 个数
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public int queryCountByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap)
            throws VciBaseException {
        QueryTemplate qt = getQtByName(queryScheme,replaceMap);
        return baseQueryCount(qt,conditionMap);
    }
 
     /**
     * 使用对象里的查询方案来查询数量
     * @param c 对象所属类
     * @param conditionMap 查询条件
     * @return 数量
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public int queryCount(Class c, Map<String, String> conditionMap)
            throws VciBaseException {
        return queryCount(WebUtil.getBtmTypeByObject(c), conditionMap);
    }
 
    /**
     * 根据sql语句来查询内容 --sql不能是select * 或者 select t.* 
     * @param sql 为了防止SQL注入,值必须在sql语句里以:xxx格式,如 id =:idvalue,然后在conditionMap中添加建为idvalue的格式
     * @param conditionMap 查询条件,必须与sql里对应
     * @return CBO
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public List<BusinessObject> queryBySql(String sql,
            Map<String, String> conditionMap) throws VciBaseException {
        List<Map> allData = queryBySqlForMap(sql,conditionMap);
        if(allData == null || allData.size() == 0){
            return new ArrayList<BusinessObject>();
        }else{
            return map2Cbos(allData);
        }
    }
 
    /**
     * 只用sql语句查询,这个和queryBySql区别是,特殊的sql(如包含有函数的)可以用这个方法,但是有sql注入风险
     * @param sql sql语句,查询条件必须自行在其中处理完成
     * @return CBO
     * @throws VciBaseException 查询出错活抛出异常
     */
    @Override
    public List<BusinessObject> queryByOnlySql(String sql) throws VciBaseException{
        List<Map> allData = queryByOnlySqlForMap(sql);
        if(allData == null || allData.size() == 0){
            return new ArrayList<BusinessObject>();
        }else{
            return map2Cbos(allData);
        }
    }
 
    /**
     * 只用sql语句查询,这个和queryBySqlForMap区别是,特殊的sql(如包含有函数的)可以用这个方法,但是有sql注入风险
     * @param sql sql语句,查询条件必须自行在其中处理完成
     * @return 数据映射
     * @throws VciBaseException 查询出错活抛出异常
     */
    @Override
    public List<Map> queryByOnlySqlForMap(String sql) throws VciBaseException{
        if(StringUtils.isBlank(sql)){
            return new ArrayList<>();
        }
        List<Map> dataList = new ArrayList<>();
        try {
            KV[][] kvs = platformClientUtil.getQueryService().queryBySql(sql);
            if(kvs!=null && kvs.length>0){
                for (int i = 0; i < kvs.length; i++) {
                    Map<String,String> data = new HashMap<>();
                    KV[] kv = kvs[i];
                    if(kv!=null && kv.length >0){
                        for (int j = 0; j < kv.length; j++) {
                            KV kv1 = kv[j];
                            data.put(kv1.key,kv1.value);
                        }
                    }
                    dataList.add(data);
                }
            }
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        return dataList;
    }
 
    /**
     * 使用sql语句查询后转换为对象
     * @param sql sql语句
     * @param tClass 对象的类
     * @param <T> 泛型
     * @return 数据的列表
     * @throws VciBaseException 查询和转换出错会抛出异常
     */
    @Override
    public <T> List<T> queryByOnlySqlForObj(String sql, Class<T> tClass) throws VciBaseException{
        List<Map> allData = queryByOnlySqlForMap(sql);
        //需要转换一下cbo的那个属性
        Map<String/**业务类型中的字段*/, String/**属性里的字段**/> fieldNameMap = WebUtil.getFieldNameMap(tClass);
        List<T> dataList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(allData)){
            allData.stream().forEach(data->{
                Map thisData = new HashMap();
                if(!CollectionUtils.isEmpty(data)){
                    data.forEach((key,value)->{
                        thisData.put(fieldNameMap.getOrDefault(((String)key).toLowerCase(Locale.ROOT), (String) key),value);
                    });
                }
                try {
                    Object o = VciBaseUtil.mapToBean(thisData, tClass);
                    dataList.add((T)o);
                } catch (Exception e) {
                    if(logger.isErrorEnabled()){
                        logger.error("转换错误",e);
                    }
                }
            });
        }
        return dataList;
    }
 
     /**
     * 根据sql语句来查询内容,返回Map----sql不能是select * 或者 select t.* 
     * @param sql 为了防止SQL注入,值必须在sql语句里以:xxx格式,如 id =:idvalue,然后在conditionMap中添加建为idvalue的格式
     * @param conditionMap  查询条件,必须与sql里对应
     * @return 业务数据的映射
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public List<Map> queryBySqlForMap(String sql,
            Map<String, String> conditionMap) throws VciBaseException {
        return queryBySqlForMap(sql,conditionMap,null);
    }
 
    /**
     * 和上个方法一样,多传了查询字段 selectKeys
     * @param sql sql语句
     * @param conditionMap 查询条件
     * @param selectKeys 查询的字段
     * @return 数据
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public List<Map> queryBySqlForMap(String sql,Map<String, String> conditionMap, String[] selectKeys) throws VciBaseException {
 
        if(WebUtil.isNull(sql) || sql.toLowerCase(Locale.ROOT).indexOf("select") <0 || sql.toLowerCase(Locale.ROOT).indexOf("from") < 0){
            throw new VciBaseException(msgCodePrefix + "sqlError",new String[]{sql});
        }
 
        //处理大写FROM,平台查询会报错
        if(sql.contains(" FROM ")){
            sql = sql.replaceAll(" FROM "," from ");
        }
 
        AttributeValue[] ava = null;
        if(conditionMap!=null&&!conditionMap.isEmpty()){
            ava = new AttributeValue[conditionMap.size()];
            Iterator<String> it = conditionMap.keySet().iterator();
            int i = 0 ;
            while(it.hasNext()){
                String key = it.next();
                String value = conditionMap.get(key);
                if(value == null){
                    value = "";
                }
                AttributeValue av = new AttributeValue(key, value);
                ava[i] = av;
                i++;
            }
        }else{
            ava = new AttributeValue[0];
        }
        try {
            String[][] results =platformClientUtil.getSqlQueryService(sql, ava);
            if(results.length>0){
                if(selectKeys==null) {
                    String selectSql = sql.substring(sql.toLowerCase(Locale.ROOT).indexOf("select") + 6, sql.toLowerCase(Locale.ROOT).indexOf(" from")).trim();
                    selectKeys = selectSql.split(",");
                }
                List<Map> allData = new ArrayList<Map>();
                for(int i = 0 ; i < results.length ;i ++){
                    String[] values = results[i];
                    Map<String,String> map = new HashMap<String, String>();
                    for(int j = 0 ; j < selectKeys.length; j ++){
                        String field = selectKeys[j];
                        if(WebUtil.isNotNull(field)){
                            //field = field.toLowerCase().trim();
                            //有可能有as的情况  或者空格 或者有.的情况
                            //必须优先处理as和空格的情况,最后处理.
                            if(field.indexOf(" as ")>-1){
                                field = field.substring(field.lastIndexOf(" as ") + 4);
                            }else if(field.indexOf(" ")>-1){
                                field =field.substring(field.lastIndexOf(" ") + 1);
                            }else if(field.indexOf(".")>-1){
                                field = field.substring(field.lastIndexOf(".") + 1);
                            }
                            //获取值
                            String value = "";
                            if(values.length>j){
                                value = values[j] == null?"":values[j];
                            }
                            map.put(field, value);
                        }
                    }
                    allData.add(map);
                }
                return allData;
            }else{
                return new ArrayList<Map>();
            }
        } catch (PLException e) {
//            logger.error(e.error_code,e);
            throw WebUtil.getVciBaseException(e);
        }
    }
 
 
     /**
     * 查询数据,返回对象,对象的字段上可以设置参照和枚举
     * @param c 对象所属类
     * @param conditionMap 查询条件
     * @return 业务数据对象
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public <T> List<T> queryObject(Class<T> c, Map<String, String> conditionMap)
            throws VciBaseException {
        return queryObject(c,conditionMap,new PageHelper(-1));
    }
 
     /**
     * 查询数据,返回对象,支持分页
     * @param c 对象所属类
     * @param conditionMap 查询条件
     * @param ph 分页组件
     * @return 业务数据对象
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public <T> List<T> queryObject(Class<T> c,
            Map<String, String> conditionMap, PageHelper ph)
            throws VciBaseException {
        //直接从对象里去查询业务类型的名称
        swapConditionMap(c,conditionMap);
        //获取要查询的所有的列
        Map<String,String> allFieldAttrMap = WebUtil.getFieldNameMap(c);
        if(!allFieldAttrMap.containsKey("lctid")){
            allFieldAttrMap.put("lctid","lctid");
        }
        List<String> queryAttr = new ArrayList<String>();
        Iterator<String> it = allFieldAttrMap.keySet().iterator();
        while(it.hasNext()){
            queryAttr.add(it.next());
        }
        for(String columnName:queryAttr){
            String fieldName = allFieldAttrMap.get(columnName);
            allFieldAttrMap.remove(columnName);
            allFieldAttrMap.put(columnName.toLowerCase(),fieldName);
        }
        List<T> allObject = new ArrayList<T>();
        List<BusinessObject> allCbos = queryCBO(WebUtil.getBtmTypeByObject(c), conditionMap, ph, allFieldAttrMap.keySet().stream().collect(Collectors.toList()));//执行查询
        List<String> oids = new ArrayList<String>();
        
        if(allCbos!=null&&allCbos.size()>0){
            for(BusinessObject cbo : allCbos){
                T obj  = null;
                try {
                    obj = c.newInstance();
                    WebUtil.copyValueToObjectFromCbos(cbo, obj,allFieldAttrMap);//为了少去查询一次字段
                } catch (InstantiationException e) {
                    
                } catch (IllegalAccessException e) {
                }
                if(obj !=null){
                    oids.add(cbo.oid);
                    allObject.add(obj);
                }
            }
        }
        return allObject;
    }
 
    /**
     * 转换查询条件
     * @param c 对象类
     * @param conditionMap 查询条件
     * @throws VciBaseException 转换出错
     */
    private void swapConditionMap(Class c ,Map<String,String> conditionMap) throws VciBaseException{
        WebUtil.alertNotNull(c,"对象所属类");
        if(conditionMap == null){
            conditionMap = new HashMap<String, String>();
        }
        conditionMap = WebUtil.getNotNullMap(conditionMap);
        //对于是参照字段的,也要检查conditionMap里面是否有,有的话需要替换成xxx.yy这种格式
        try{
            if(conditionMap.size()>0){
                Map<String,String> fieldMap = WebUtil.getFieldNameMap(c);
                Iterator<String> it = fieldMap.keySet().iterator();
                while(it.hasNext()){
                    String attrName = it.next();
                    if(attrName.indexOf(".")>-1){
                        //说明是参照的
                        String fieldName = fieldMap.get(attrName).toLowerCase();
                        if(conditionMap.containsKey(fieldName)){
                            String value = conditionMap.get(fieldName);
                            conditionMap.remove(fieldName);
                            conditionMap.put(attrName, value);
                        }
                    }
                }
            }
        }catch(Throwable e){
            if(logger.isErrorEnabled()){
                logger.error("转换条件出错",e);
            }
        }
    }
 
     /**
     * 使用查询方案来查询数据,返回对象,支持分页
     * @param queryScheme 查询方案
     * @param c 对象所属类
     * @param conditionMap 查询条件
     * @param ph 分页组件
     * @return 业务对象
     * @throws VciBaseException  查询出错会抛出异常
     */
    @Override
    public <T> List<T> queryObjectByScheme(String queryScheme, Class<T> c,
            Map<String, String> conditionMap, PageHelper ph)
            throws VciBaseException {
        return queryObjectByScheme(queryScheme,c,conditionMap,ph,null);
    }
 
     /**
     * 使用查询方案来查询数据,返回对象,支持分页
     * @param queryScheme 查询方案
     * @param c 对象所属类
     * @param conditionMap 查询条件
     * @param ph 分页组件
     * @param replaceMap 替换查询方案中的变量值
     * @return 数据对象
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public <T> List<T> queryObjectByScheme(String queryScheme, Class<T> c,
            Map<String, String> conditionMap, PageHelper ph,
            Map<String, String> replaceMap) throws VciBaseException {
        WebUtil.alertNotNull(queryScheme,"查询方案");
        //直接从对象里去查询业务类型的名称
        swapConditionMap(c,conditionMap);
        //获取要查询的所有的列
        Map<String,String> allFieldAttrMap = WebUtil.getFieldNameMap(c);
        List<String> queryAttr = new ArrayList<String>();
        Iterator<String> it = allFieldAttrMap.keySet().iterator();
        while(it.hasNext()){
            queryAttr.add(it.next());
        }
        for(String columnName:queryAttr){
            String fieldName = allFieldAttrMap.get(columnName);
            allFieldAttrMap.remove(columnName);
            allFieldAttrMap.put(columnName.toLowerCase(),fieldName);
        }
        List<T> allObject = new ArrayList<T>();
        List<BusinessObject> allCbos = queryCBOByScheme(queryScheme, conditionMap, replaceMap,ph, allFieldAttrMap.keySet().stream().collect(Collectors.toList()));
        List<String> oids = new ArrayList<String>();
        if(allCbos!=null&&allCbos.size()>0){
            for(BusinessObject cbo : allCbos){
                T obj  = null;
                try {
                    obj = c.newInstance();
                    WebUtil.copyValueToObjectFromCbos(cbo, obj,allFieldAttrMap);//为了少去查询一次字段
                } catch (InstantiationException e) {
                    
                } catch (IllegalAccessException e) {
                }
                if(obj !=null){
                    oids.add(cbo.oid);
                    allObject.add(obj);
                }
            }
        }
        return allObject;
    }
 
    /**
     * 保存数据,可以在request中设置是否持久化
     *
     * @param obj 要保存的对象
     * @return 保存后包含的数据对象
     * @throws VciBaseException 添加出错会抛出异常
     */
    @Override
    public <T> BatchCBO addSave(T obj) throws VciBaseException {
        List<T> list = new ArrayList<T>();
        list.add(obj);
        return batchAddSave(list);
    }
 
    /**
     * 值加到查询条件的map里
     * @param field 属性名字
     * @param value 属性值
     * @return 查询条件的map
     */
    public Map<String, String> getOneQuery(String field, String value) {
        return this.getOneQuery(field, value, "");
    }
 
    /**
     *  值加到查询条件的map里
     * @param field 属性名字
     * @param value 属性值
     * @param options 操作符
     * @return 查询条件的map
     */
    public Map<String, String> getOneQuery(String field, String value, String options) {
        Map<String, String> conditionMap = new HashMap();
        options = WebUtil.isNull(options) ? "" : (options.indexOf("\\") > -1 ? options.toUpperCase() : "\\" + options.toUpperCase());
        conditionMap.put(field, options + value);
        return conditionMap;
    }
 
    /**
     * 设置值到业务数据对象上
     * @param obj 对象的值
     * @param btmType 业务类型的名称
     * @param cbo 业务数据对象
     * @param isEdit 是否为编辑
     * @throws VciBaseException 设置出错会抛出异常
     */
    private void setValueToCbo(Object obj,String btmType,BusinessObject cbo ,boolean isEdit) throws VciBaseException{
        Field pkField = WebUtil.getPkFieldForObj(obj.getClass());
        if(pkField == null){
            throw new VciBaseException("{0}类中没有定义主键属性",new Object[]{obj.getClass()});
        }
        //主键
        Object pkValue = WebUtil.getValueFromField(pkField.getName(), obj);
        if(pkValue == null || (pkValue instanceof String && WebUtil.isNull(pkValue.toString()))){
            WebUtil.setValueToField(pkField.getName(), obj, cbo.oid);
            pkValue = cbo.oid;
        }else{
            cbo.oid = pkValue.toString();
        }
        //进行非空,长度,重复的校验。。校验通过的赋值
        Map<String,String> fieldMap = WebUtil.getFieldNameMap(obj.getClass());
        Iterator<String> it = fieldMap.keySet().iterator();
        while(it.hasNext()){
            String attrName = it.next();
            String fieldName = fieldMap.get(attrName);
            attrName = attrName.toLowerCase();
            if(attrName.indexOf(".")<0 && attrName.indexOf("_")<0 && !attrName.toLowerCase().equalsIgnoreCase("lcstatus_text") && !attrName.toLowerCase().equals("lcstatustext")){//不是参照的属性才能赋值
                Field thisField = WebUtil.getFieldForObject(fieldName, obj);
                String value = WebUtil.getValueFromFieldForCbo(thisField, obj);
 
                if(thisField.isAnnotationPresent(Column.class)){
                    //需要校验重复和为空.而且配置了Column的
                    Column column = (Column)thisField.getAnnotation(Column.class);
                    String columnText = column.columnDefinition();
                    columnText = StringUtils.isNotBlank(columnText)?columnText:fieldName;
                    //四个默认属性不判断非空
                    boolean is4 = false;//是不是4个属性
                    String[] defaultFieldName_notChecks = {"creator","lastModifier","ts","oid","createTime"};
                    //判断fieldName不是
                    for (String defaultFieldName_notCheck:defaultFieldName_notChecks){
                        if(defaultFieldName_notCheck.equals(fieldName)){
                            is4 = true;
                        }
                    }
                    if(!is4) {//不是4个属性才判断非空
                        //判断非空
                        if (!column.nullable() && WebUtil.isNull(value)) {
                            throw new VciBaseException("{0}字段不能为空", new Object[]{columnText});
                        }
                    }
 
                    value = value==null?"":value;
                    if(column.length()>0 && value.length()> column.length()){//长度
                        throw new VciBaseException("{0}字段的长度太长,要求{1},实际{2}", new Object[]{columnText,column.length(),value.length()});
                    }
                    if(!thisField.equals(pkField) && column.unique()){
                        //说明不能重复,那么就需要查询一下
                        Map<String,String> queryRepeatMap = getOneQuery(attrName, value);
                        if(isEdit){
                            queryRepeatMap.put("oid", QueryOptionConstant.NOTEQUAL + cbo.oid);
                        }
                        if(queryCount(btmType, queryRepeatMap)>0){
                            throw new VciBaseException("{0}字段的值{1}在系统中已经存在", new Object[]{columnText,value});
                        }
                    }
                }
                if(value==null){
                    continue;
                }
                if(isEdit && checkUnAttrUnEdit(attrName)){
                    //编辑的时候,TS和OID不能设置.因为平台那接口设置了就会报错
                }else {
                    //需要判断是否默认的属性,如果是默认属性,则使用对象的赋值的方式
                    if (WebUtil.isDefaultField(fieldName) && WebUtil.inArray(new String[]{"id", "name", "description","lcstatus","revisionvalue","versionvalue"}, fieldName.toLowerCase())) {
                        WebUtil.setValueToField(fieldName, cbo, value);
                        ObjectTool.setBOAttributeValue(cbo, attrName.toLowerCase(), value);
                    } else {
                        ObjectTool.setBOAttributeValue(cbo, attrName.toLowerCase(), value);
                    }
                }
            }
        }
    }
 
    /**
     * 批量保存数据,可以在request里设置不持久化
     * @param list 要保存的数据对象列表
     * @return 需要创建的CBO,CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException 报错出错会抛出异常
     */
    @Override
    public <T> BatchCBO batchAddSave(List<T> list)
            throws VciBaseException {
        if(list==null){
            throw new VciBaseException(VciBaseException.paramNull);
        }
        Set<BusinessObject> allCbos = new HashSet<BusinessObject>();
        for(T obj : list){
            //需要处理默认值
            Field pkField = WebUtil.getPkFieldForObj(obj.getClass());
            if(pkField == null){
                throw new VciBaseException("{0}对象中没有设置主键的属性",new Object[]{obj.getClass()});
            }
            String btmType = WebUtil.getBtmTypeByObject(obj.getClass());
            BusinessObject cbo = createCBOByBtmName(btmType);
            setValueToCbo(obj,btmType,cbo,false);
            allCbos.add(cbo);
        }
        //因为使用了平台,事务没办法统一,所以只能是在服务调用服务之间的时候,返回要保存的数据;
        BatchCBO batchCbo = new BatchCBO();
        batchCbo.setCreateCbos(allCbos);
        if(allCbos.size()>0 && WebUtil.isPersistence()){
            if(logger.isInfoEnabled()) {
                logger.info("执行了持久化");
            }
            persistenceBatch(batchCbo);
        }
        return batchCbo;
    }
 
    /**
     * 修改数据,可以在request里设置不持久化
     *
     * @param obj 修改数据对象
     * @return 需要创建的CBO, CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException 修改出错会抛出异常
     */
    @Override
    public <T> BatchCBO editSave(T obj) throws VciBaseException {
        List<Object> list = new ArrayList<Object>();
        list.add(obj);
        return batchEditSave(list);
    }
 
 
    /**
     * 批量修改数据,可以在request里设置不持久化
     * @param list 要保存的数据对象列表
     * @return 需要创建的CBO,CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException 修改出错会抛出异常
     */
    @Override
    public <T> BatchCBO batchEditSave(List<T> list)
            throws VciBaseException {
        if(list==null){
            throw new VciBaseException(VciBaseException.paramNull);
        }
        Set<BusinessObject> allUpdateCbos = new HashSet<BusinessObject>();
        Set<BusinessObject> allDeleteCbos = new HashSet<BusinessObject>();
        Set<BusinessObject> allAddCbos = new HashSet<BusinessObject>();
        Map<String,String> btmOidsMap = new HashMap<String, String>();
        for(T obj : list){
            String btmType = WebUtil.getBtmTypeByObject(obj.getClass());
            String tempOids = "";
            if(btmOidsMap.containsKey(btmType)){
                tempOids = btmOidsMap.get(btmType);
            }
            
            Field pkField = WebUtil.getPkFieldForObj(obj.getClass());
            if(pkField == null){
                throw new VciBaseException("{0}对象中没有设置主键的属性",new Object[]{obj.getClass()});
            }
            //主键
            Object pkValue = WebUtil.getValueFromField(pkField.getName(), obj);
            if(pkValue == null || (pkValue instanceof String && WebUtil.isNull(pkValue.toString()))){
            }else{
                tempOids += "'" + pkValue.toString() + "',";
            }
            btmOidsMap.put(btmType, tempOids);
        }
        List<BusinessObject> needUpdateCbos = new ArrayList<BusinessObject>();
        Iterator<String> it = btmOidsMap.keySet().iterator();
        while(it.hasNext()){
            String btmType = it.next();
            String oids = WebUtil.removeComma(btmOidsMap.get(btmType));
            Map<String,String> conditionMap = new HashMap<String, String>();
            conditionMap.put("oid", QueryOptionConstant.IN +"(" + oids + ")");
            needUpdateCbos.addAll(queryCBO(btmType, conditionMap));
        }
        //需要先从后台查询
        for(T obj : list){
            //需要处理默认值
            Field pkField = WebUtil.getPkFieldForObj(obj.getClass());
            if(pkField == null){
                throw new VciBaseException("{0}对象中没有设置主键的属性",new Object[]{obj.getClass()});
            }
            //主键
            Object pkValue = WebUtil.getValueFromField(pkField.getName(), obj);
            BusinessObject cbo = null;
            if(pkValue == null || (pkValue instanceof String && WebUtil.isNull(pkValue.toString()))){
                continue;
            }else{
                for(BusinessObject tempCbo : needUpdateCbos){
                    if(tempCbo.oid.equalsIgnoreCase(pkValue.toString().trim())){
                        cbo = tempCbo;
                        break;
                    }
                }
            }
            String btmType = WebUtil.getBtmTypeByObject(obj.getClass());
            //拷贝之前先清除已经有的值
            cbo.newAttrValList = new AttributeValue[0];
            setValueToCbo(obj,btmType,cbo,true);
            allUpdateCbos.add(cbo);
        }
        BatchCBO batchCbo = new BatchCBO();
        batchCbo.setCreateCbos(allAddCbos);
        batchCbo.setUpdateCbos(allUpdateCbos);
        batchCbo.setDeleteCbos(allDeleteCbos);
        //因为使用了平台,事务没办法统一,所以只能是在服务调用服务之间的时候,返回要保存的数据;
        if(WebUtil.isPersistence()){
            persistenceBatch(batchCbo);
        }
        return batchCbo;
    }
 
    /**
     * 删除数据,可以在request里设置不持久化
     *
     * @param obj 删除数据对象
     * @return 需要创建的CBO, CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException 删除出错会抛出异常
     */
    @Override
    public <T> BatchCBO delete(T obj) throws VciBaseException {
        return delete(obj,true);
    }
    @Override
    public <T> BatchCBO delete(T obj,boolean checkRefered) throws VciBaseException{
        List<T> list = new ArrayList<T>();
        list.add(obj);
        return batchDelete(list,checkRefered);
    }
 
 
    /**
     * 批量删除数据,可以在request里设置不持久化
     * @param list 需要删除数据对象列表
     * @return 需要创建的CBO,CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException  删除出错会抛出异常
     */
    @Override
    public <T> BatchCBO batchDelete(List<T> list)
            throws VciBaseException {
        return batchDelete(list,true);
    }
 
    /**
     * 批量删除
     * @param list 需要删除数据对象列表
     * @param checkRefered 是否删除引用的数据
     * @param <T> 类型
     * @return 受影响的行数
     * @throws VciBaseException 执行出错会抛出异常
     */
    @Override
    public <T> BatchCBO batchDelete(List<T> list,boolean checkRefered) throws VciBaseException{
        if(list==null){
            throw new VciBaseException(VciBaseException.paramNull);
        }
        Set<BusinessObject> allDeleteCbos = new HashSet<BusinessObject>();
        Map<String,List<BusinessObject>> btmBos = new HashMap<String, List<BusinessObject>>();
        for(Object obj : list){
            //有可能不属于同一个业务类型下
            Field pkField = WebUtil.getPkFieldForObj(obj.getClass());
            if(pkField == null){
                throw new VciBaseException("{0}对象中没有设置主键的属性",new Object[]{obj.getClass()});
            }
            String btmType = WebUtil.getBtmTypeByObject(obj.getClass());
            String pkValue = WebUtil.getValueFromFieldForCbo(pkField, obj);
            //所以这里也是直接查询的单个'
            List<BusinessObject> deleteCbos = queryCBO(btmType, getOneQuery(
                    WebUtil.getCboAttrNameFromField(pkField, obj.getClass()), pkValue));
            if(deleteCbos!=null){
                allDeleteCbos.addAll(deleteCbos);
                if(!btmBos.containsKey(btmType)){
                    btmBos.put(btmType, deleteCbos);
                }else{
                    btmBos.get(btmType).addAll(deleteCbos);
                }
            }
        }
 
        //不执行验证,是true才检查,默认不检查
        if(checkRefered) {
            checkCanDelete(btmBos);
        }
 
        BatchCBO batchCbo = new BatchCBO();
        batchCbo.setDeleteCbos(allDeleteCbos);
        if(allDeleteCbos.size()>0 && WebUtil.isPersistence()){
            persistenceBatch(batchCbo);
        }
        return batchCbo;
    }
 
    /**
     * 校验是否可以删除
     * @param btmBos 业务数据
     * @throws VciBaseException 被引用的时候会抛出异常
     */
    private void checkCanDelete(Map<String,List<BusinessObject>> btmBos) throws VciBaseException{
        //查找表是否被其他的属性引用
        if(!btmBos.isEmpty()){
            Iterator<String> it = btmBos.keySet().iterator();
            while(it.hasNext()){
                //每一个业务类型找一次引用字段
                String btmType = it.next();
                List<OsUsedAttributeVO> usedAttrVOs = btmService.listBtmUsedInfo(btmType);
 
                Map<String, List<OsUsedAttributeVO>> allReferAttr = Optional.ofNullable(usedAttrVOs).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.groupingBy(s -> s.getPkBtmType()));
                List<BusinessObject> thisBtmTypeBo = btmBos.get(btmType);
                if(thisBtmTypeBo.size()== 0){
                    return;
                }
                String oids = "";
                for(BusinessObject cbo : thisBtmTypeBo){
                    oids += "'" + cbo.oid + "',";
                }
                oids = WebUtil.removeComma(oids);
                if(!allReferAttr.isEmpty()){
                    Iterator<String> atIt = allReferAttr.keySet().iterator();
                    while(atIt.hasNext()){
                        String referBtmType = atIt.next();//拥有参照当前业务类型的属性所在业务类型
                        List<OsUsedAttributeVO> allAttr = allReferAttr.get(referBtmType);//该业务类型中所有的引用当前业务类型的
                        Map<String,String> conditionMap = new HashMap<String, String>();
                        for(OsUsedAttributeVO attr : allAttr){
                            conditionMap.put(attr.getId(),QueryOptionConstant.IN +"(" + oids + ")");//平台所有的引用都是oid
                        }
                        if(queryCount(referBtmType, conditionMap)>0){
                            throw new VciBaseException(msgCodePrefix + "refered", new String[]{referBtmType});
                        }
                    }
                }
            }
        }
    }
 
    /**
     * 根据查询条件来删除数据
     * @param c 删除数据对象所属类
     * @param conditionMap 查询条件
     * @return 需要创建的CBO,CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException 删除出错会抛出异常
     */
    @Override
    public <T> BatchCBO deleteByCondition(Class<T> c,
            Map<String, String> conditionMap) throws VciBaseException {
        swapConditionMap(c,conditionMap);
        String btmType = WebUtil.getBtmTypeByObject(c);
        return deleteByCondition(btmType,conditionMap);
    }
 
     /**
     * 根据查询条件来删除数据
     * @param btmType 业务类型名称
     * @param conditionMap 查询条件
     * @return 需要创建的CBO,CLO;需要修改的CBO,CLO;需要删除的CBO,CLO
     * @throws VciBaseException 删除出错会抛出异常
     */
    @Override
    public <T> BatchCBO deleteByCondition(String btmType,
            Map<String, String> conditionMap) throws VciBaseException {
        if(conditionMap == null){
            conditionMap = new HashMap<String, String>();
        }
        conditionMap.put(QUERY_FILTER_SECRET,BooleanEnum.FASLE.getValue());//查询的时候不能查询密级
        List<BusinessObject> allCbos = queryCBO(btmType, conditionMap);
        BatchCBO batchCbo = new BatchCBO();
        if(allCbos.size()>0){
            Map<String,List<BusinessObject>> btmBos = new HashMap<String, List<BusinessObject>>();
            btmBos.put(btmType, allCbos);
            checkCanDelete(btmBos);
            Set<BusinessObject> allDeleteCbos = new HashSet<BusinessObject>();
            allDeleteCbos.addAll(allCbos);
            batchCbo.setDeleteCbos(allDeleteCbos);
        }
        if(allCbos.size()>0 && WebUtil.isPersistence()){
            persistenceBatch(batchCbo);
        }
        return batchCbo;
    }
 
     /**
     * 通过sql语句来删除---不到万不得已不用使用这个方法
     * @param sql 防止SQL注入,值必须使用:xxx方式,如id=:idvalue,并在conditionMap里放置idvalue为key的数据
     * @param conditionMap 查询条件
     * @return 删除的数据量
     * @throws VciBaseException 删除出错会抛出异常
     */
    @Override
    public BatchCBO deleteBySql(String sql, Map<String, String> conditionMap)
            throws VciBaseException {
        //很遗憾,平台不支持使用sql来删除
        //所有我们需要先查询出来,然后校验是否可以删除
        sql = sql.replace("delete", "select oid,btmname ");
        if(sql.toLowerCase().indexOf(" from ") < 0){
            throw new VciBaseException(msgCodePrefix + "sqlError",new String[]{sql});
        }
        BatchCBO batchCbo = new BatchCBO();
        String selectSql = sql.substring(0,sql.toLowerCase().indexOf(" from "));
        String fromSql = sql.substring(sql.toLowerCase().indexOf(" from "));
        if(selectSql.toLowerCase().indexOf("btmname")<0){
            selectSql += ",btmname ";
        }
        sql = selectSql + fromSql;
        List<BusinessObject> allDelete =queryBySql(sql, conditionMap);
        if(allDelete.size() == 0){
            return batchCbo;//没有删除任何数据
        }
        //找btmType;
        String btmType = ObjectTool.getBOAttributeValue(allDelete.get(0),"btmName");
        Map<String,List<BusinessObject>> btmBos = new HashMap<String, List<BusinessObject>>();
        btmBos.put(btmType, allDelete);
        checkCanDelete(btmBos);
        Set<BusinessObject> allDeleteCbos = new HashSet<BusinessObject>();
        //我们需要从后台查询整个的内容才可以执行删除,
        String oids = "";
        for(BusinessObject cbo : allDelete){
            oids  += "'" + cbo.oid + "',";
        }
        conditionMap.clear();
        conditionMap.put("oid", QueryOptionConstant.IN + "(" + WebUtil.removeComma(oids) + ")");
        List<BusinessObject> inDbCbos = queryCBO(btmType, conditionMap);
        
        allDeleteCbos.addAll(inDbCbos);
        batchCbo.setDeleteCbos(allDeleteCbos);
        if(allDeleteCbos.size()>0 && WebUtil.isPersistence()){
            persistenceBatch(batchCbo);
        }
        return batchCbo;
    }
 
    /**
     * 检验是否为最新的-
     * @param obj 数据对象,里面必须包括主键和ts字段
     * @return 相等时为true
     * @throws VciBaseException 不符合要求会抛出异常
     */
    @Override
    public boolean checkTs(Object obj) throws VciBaseException {
        Field pkField = WebUtil.getPkFieldForObj(obj.getClass());
        if(pkField == null){
            throw new VciBaseException("{0}对象中没有设置主键的属性",new Object[]{obj.getClass()});
        }
        String pkValue = WebUtil.getValueFromFieldForCbo(pkField, obj);
        Field tsField = WebUtil.getTsField(obj.getClass());
        if(tsField == null){
            throw new VciBaseException("{0}对象中没有TS字段",new Object[]{obj.getClass()});
        }
        String ts = WebUtil.getValueFromFieldForCbo(tsField, obj);
        Map<String,String> conditionMap = getOneQuery("oid", pkValue);
        List<String> causeList = new ArrayList<>();
        causeList.add("ts");
        List<BusinessObject> cbos = queryCBO(WebUtil.getBtmTypeByObject(obj.getClass()), conditionMap,new PageHelper(-1),causeList);
        if(CollectionUtils.isEmpty(cbos)){
            return false;
        }
        if(ts.contains(".")){
            ts = ts.substring(0,ts.lastIndexOf("."));
        }
        return cbos.get(0).ts == Long.valueOf(ts);
    }
 
    /**
     * 根据业务类型来查询列表数据;
     * @param btmType 业务类型名称
     * @param conditionMap 查询条件
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByBo(String btmType,
                                  Map<String, String> conditionMap) throws VciBaseException {
        return queryGridByBo(btmType,conditionMap,new PageHelper(-1,true));
    }
 
      
     /**
     * 根据业务类型来查询列表数据;可以在pageHelper中设置是否查询总数
     * @param btmType 业务类型名称
     * @param conditionMap 查询条件
     * @param ph 分页和排序组件
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByBo(String btmType,
            Map<String, String> conditionMap, PageHelper ph)
            throws VciBaseException {
        return queryGridByBo(btmType,conditionMap,ph,null);
    }
 
    /**
     * 根据业务类型来查询列表数据;可以设置要查询的字段,包括参照和枚举字段;可以在pageHelper中设置是否查询总数
     * @param btmType 业务类型名称
     * @param conditionMap 查询条件
     * @param ph 分页和排序组件
     * @param clauseList 列表数据,数据是Map形式的,
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByBo(String btmType,
            Map<String, String> conditionMap, PageHelper ph,
            List<String> clauseList) throws VciBaseException {
        if(ph == null){
            ph = new PageHelper(-1);
            ph.setQueryTotal(true);
        }
        List<BusinessObject> allCbos = queryCBO(btmType, conditionMap, ph, clauseList);
        DataGrid dg = new DataGrid();
        if(allCbos.size()>0){
            List<Map> mapList = cbos2Map(allCbos);
            dg.setData(mapList);
            //肯定是当前分页有值,才会有总数
            if(ph.isQueryTotal()){
                dg.setTotal(queryCount(btmType, conditionMap));
            }
        }
        dg.setLimit(ph.getLimit());
        dg.setPage(ph.getPage());
        return dg;
    }
 
    /**
     * 根据查询方案来查询列表数据;
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByScheme(String queryScheme,
            Map<String, String> conditionMap) throws VciBaseException {
        return queryGridByScheme(queryScheme,conditionMap,null);
    }
 
    /**
     * 根据查询方案来查询列表数据;
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案的变量值
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap)
            throws VciBaseException {
        return queryGridByScheme(queryScheme,conditionMap,replaceMap,new PageHelper(-1,true),null);
    }
 
 
     /**
     * 根据查询方案来查询列表数据;可以在pageHelper中设置是否查询总数,pageHelper的优先级最大;
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案的变量值
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap,
            PageHelper ph) throws VciBaseException {
        return queryGridByScheme(queryScheme,conditionMap,replaceMap,ph,null);
    }
 
    /**
     * 根据查询方案来查询列表数据,可以自定义查询的列,包括参照和枚举
     * @param queryScheme 查询方案
     * @param conditionMap 查询条件
     * @param replaceMap 替换查询方案的变量值
     * @param ph 分页和排序字段
     * @param clauseList 查询的列,参照使用xx.yy;枚举使用xx_enumCode;
     * @return 列表数据,数据是Map形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridByScheme(String queryScheme,
            Map<String, String> conditionMap, Map<String, String> replaceMap,
            PageHelper ph, List<String> clauseList) throws VciBaseException {
        if(ph == null){
            ph = new PageHelper(-1,true);
        }
        List<BusinessObject> allCbos = queryCBOByScheme(queryScheme, conditionMap,replaceMap, ph, clauseList);
        DataGrid dg = new DataGrid();
        if(allCbos.size()>0){
            List<Map> mapList = cbos2Map(allCbos);
            dg.setData(mapList);
            //肯定是当前分页有值,才会有总数
            if(ph.isQueryTotal()){
                dg.setTotal(queryCountByScheme(queryScheme, conditionMap, replaceMap));
            }
        }
        dg.setLimit(ph.getLimit());
        dg.setPage(ph.getPage());
        return dg;
    }
 
    /**
     * 查询对象的列表数据 
     * @param c 查询对象所属类
     * @param conditionMap 查询条件
     * @return 列表数据,数据是对象形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridClass(Class c, Map<String, String> conditionMap)
            throws VciBaseException {
        return queryGridClass(c,conditionMap,new PageHelper(-1,true));
    }
    
    /**
     * 查询对象的列表数据
     * @param c 查询对象所属类
     * @param conditionMap 查询条件
     * @param ph 分页和排序字段,可以设置是否查询总数
     * @return 列表数据,数据是对象形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridClass(Class c, Map<String, String> conditionMap,
            PageHelper ph) throws VciBaseException {
        if(ph == null){
            ph = new PageHelper(-1,true);
        }
        List allObjs = queryObject(c, conditionMap, ph);
        DataGrid dg = new DataGrid();
        if(allObjs.size()>0){
            dg.setData(allObjs);
            //肯定是当前分页有值,才会有总数
            if(ph.isQueryTotal()){
                dg.setTotal(queryCount(c, conditionMap));
            }
        }
        dg.setLimit(ph.getLimit());
        dg.setPage(ph.getPage());
        return dg;
    }
 
    /**
     * 通过查询方案查询对象的列表数据
     * @param queryScheme 查询方案
     * @param c 查询对象所属类
     * @param conditionMap 查询条件
     * @return 列表数据,数据是对象形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridClassByScheme(String queryScheme, Class c,
            Map<String, String> conditionMap,Map<String,String> replaceMap) throws VciBaseException {
        return queryGridClassByScheme(queryScheme,c,conditionMap,replaceMap,new PageHelper(-1,true));
    }
    
    /**
     * 通过查询方案查询对象的列表数据
     * @param queryScheme 查询方案
     * @param c 查询对象所属类
     * @param conditionMap 查询条件
     * @param ph 分页和排序字段,可以设置是否查询总数
     * @return 列表数据,数据是对象形式的,包含分页信息
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public DataGrid queryGridClassByScheme(String queryScheme, Class c,
            Map<String, String> conditionMap, Map<String,String> replaceMap,PageHelper ph)
            throws VciBaseException {
        if(ph == null){
            ph = new PageHelper(-1,true);
        }
        List allObjs = queryObjectByScheme(queryScheme, c, conditionMap, ph, replaceMap);
        DataGrid dg = new DataGrid();
        if(allObjs.size()>0){
            dg.setData(allObjs);
            //肯定是当前分页有值,才会有总数
            if(ph.isQueryTotal()){
                dg.setTotal(queryCountByScheme(queryScheme, conditionMap, replaceMap));
            }
        }
        dg.setLimit(ph.getLimit());
        dg.setPage(ph.getPage());
        return dg;
    }
 
    /**
     * BusinessObject 转为HashMap
     * @param cbos CBOS
     * @return map
     * @throws VciBaseException 转换出错会抛出异常
     */
    @Override
    public List<Map> cbos2Map(List<BusinessObject> cbos)
            throws VciBaseException {
        List<Map> mapList = new ArrayList<Map>();
        for(BusinessObject cbo : cbos){
            mapList.add(cbo2Map(cbo));
        }
        return mapList;
    }
 
    /**
     * BusinessObject 转为HashMap
     * @param cbo 业务数据对象
     * @return map
     * @throws VciBaseException 转换出错会抛出异常
     */
    @Override
    public Map cbo2Map(BusinessObject cbo) throws VciBaseException {
        Map<String,String> map = new HashMap<String, String>();
        WebUtil.copyValueToMapFromCbos(cbo, map);
        return map;
    }
 
 
    /**
     * map转为BusinessObject
     * @param mapList  map列表
     * @return 业务数据列表
     * @throws VciBaseException 转换出错会抛出异常
     */
    @Override
    public List<BusinessObject> map2Cbos(List<Map> mapList)
            throws VciBaseException {
        List<BusinessObject> cboList = new ArrayList<BusinessObject>();
        for(Map map : mapList){
            cboList.add(map2Cbo(map));
        }
        return cboList;
    }
 
     
    /**
     * map转为BusinessObject
     * @param map map
     * @return 业务数据
     * @throws VciBaseException 转换出错会抛出异常
     */
    @Override
    public BusinessObject map2Cbo(Map map) throws VciBaseException {
        BusinessObject cbo = new BusinessObject();
        WebUtil.copyValueToCboFromMap(cbo, map);
        return cbo;
    }
 
    /**
     * 批量保存业务类型和链接类型的信息
     * @param batchCbos 批量数据容器
     * @throws VciBaseException 保存出错
     */
    @Override
    public void persistenceBatch(BatchCBO batchCbos) throws VciBaseException {
        persistenceBatch(batchCbos,false);
    }
 
    /**
     * 批量保存业务类型和链接类型的信息---只有确保数据容器里有参照字段,枚举字段等内容的时候,才调用这个方法,因为这个方法性能低下
     * @param batchCbos 批量数据容器
     * @param isCheckReferColumn 是否校验是否含有参照字段
     * @throws VciBaseException 保存出错
     */
    @Override
    public void persistenceBatch(BatchCBO batchCbos, boolean isCheckReferColumn)
            throws VciBaseException {
        if(batchCbos == null ){
            return;
        }
        if(isCheckReferColumn){
            deleteReferAttrInCbo(batchCbos.getCreateCbos());
            deleteReferAttrInCbo(batchCbos.getUpdateCbos());
            deleteReferAttrInCbo(batchCbos.getDeleteCbos());
        }
        try {
            platformClientUtil.getBOFactoryService().batchCUDBOLO(cboArray2Bo(batchCbos.getCreateCboArray()),
                    cloArray2Lo(batchCbos.getCreateCloArray()),
                    cboArray2Bo(batchCbos.getUpdateCboArray()),
                    cloArray2Lo(batchCbos.getUpdateCloArray()),
                    cboArray2Bo(batchCbos.getDeleteCboArray()), cloArray2Lo(batchCbos.getDeleteCloArray()));
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 转换为cbo
     * @param cbos 客户端对象
     * @return 业务对象
     */
    private BusinessObject[] cboArray2Bo(BusinessObject[] cbos){
        if(cbos == null ||cbos.length == 0){
            return new BusinessObject[0];
        }
        BusinessObject[] bos = new BusinessObject[cbos.length];
        for(int i = 0; i < cbos.length; i++){
            bos[i] = cbos[i];
        }
        return bos;
    }
 
    /**
     * 转换clob
     * @param clos 客户端对象
     * @return 业务对象
     */
    private LinkObject[] cloArray2Lo(LinkObject[] clos){
        if(clos == null ||clos.length == 0){
            return new LinkObject[0];
        }
        LinkObject[] bos = new LinkObject[clos.length];
        for(int i = 0; i < clos.length; i++){
            bos[i] = clos[i];
        }
        return bos;
    }
 
    /**
     * 删除枚举和参照的属性
     * @param cbos 业务数据
     */
    private void deleteReferAttrInCbo(Set<BusinessObject> cbos){
        if(cbos !=null){
            for(BusinessObject cbo : cbos){
                BusinessObject bo = cbo;
                List<AttributeValue> newAttr = new ArrayList<AttributeValue>();
                if (bo.newAttrValList != null) {
                    for (int i = 0; i < bo.newAttrValList.length; ++i) {
                        AttributeValue av = bo.newAttrValList[i];
                        if (WebUtil.isNormalAttr(av.attrName)) {
                            if(av.attrVal == null){
                                av.attrVal = "";
                            }
                            newAttr.add(av);
                        }
                    }
                }
                bo.newAttrValList = newAttr.toArray(new AttributeValue[0]);
                cbo = bo;
            }
        }
    }
 
    /**
     * 使用主键获取对象
     * @param oid 主键
     * @param doClass 数据对象
     * @return 数据对象
     * @throws VciBaseException 参数为空,数据对象不存在会抛出异常
     */
    @Override
    public <T> T selectByOid(String oid, Class<T> doClass)
            throws VciBaseException {
        VciBaseUtil.alertNotNull(oid,"主键");
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("oid", oid.trim());
        conditionMap.put(QUERY_FILTER_SECRET,BooleanEnum.FASLE.getValue());
        conditionMap.put(QUERY_FILTER_DATARIGHT,BooleanEnum.FASLE.getValue());
        List<T> list = queryObject(doClass, conditionMap);
        if(CollectionUtils.isEmpty(list)){
            throw new VciBaseException("数据在系统中不存在{0}",new String[]{oid});
        }
        return list.get(0);
    }
 
    /**
     * 使用主键获取对象
     *
     * @param oid     主键
     * @param btmName 业务类型的名称
     * @return cbo
     * @throws VciBaseException 参数为空,数据不存在会抛出异常
     */
    @Override
    public BusinessObject selectCBOByOid(String oid, String btmName) throws VciBaseException {
        VciBaseUtil.alertNotNull(oid,"主键",btmName,"业务类型");
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("oid", oid.trim());
        List<BusinessObject> cbos = queryCBO(btmName, conditionMap);
        if(CollectionUtils.isEmpty(cbos)){
            throw new VciBaseException("数据在系统中不存在{0}",new String[]{oid});
        }
        return cbos.get(0);
    }
 
    /**
     * 使用主键集合获取对象
     * @param oidCollection 主键集合
     * @param doClass 数据对象的类
     * @return 数据对象, 为空的时候列表为空,不是Null
     * @throws VciBaseException 参数为空,查询出错会抛出异常
     */
    @Override
    public <T> List<T> selectByOidCollection(Collection<String> oidCollection,
            Class<T> doClass) throws VciBaseException {
        VciBaseUtil.alertNotNull(oidCollection,"主键集合");
        Collection<Collection<String>> oidCollections = WebUtil.switchCollectionForOracleIn(oidCollection);
        List<T> doList = new ArrayList<T>();
 
        for(Collection<String> oids: oidCollections){
            Map<String,String> conditionMap = new HashMap<String, String>();
            conditionMap.put("oid",QueryOptionConstant.IN + "(" + WebUtil.toInSql(oids.toArray(new String[0])) + ")");
            List<T> list = queryObject(doClass, conditionMap);
            if(CollectionUtils.isEmpty(list)){
                throw new VciBaseException("{0}条数据在系统中不存在",new String[]{String.valueOf(oids.size())});
            }
            doList.addAll(list);
        }
        return doList;
    }
 
    /**
     * 使用主键集合获取对象
     *
     * @param oidCollection 主键集合
     * @param btmName       业务类型的名称
     * @return 业务数据的集合
     * @throws VciBaseException 参数为空,查询出错会抛出异常
     */
    @Override
    public List<BusinessObject> selectCBOByOidCollection(Collection<String> oidCollection, String btmName) throws VciBaseException {
        VciBaseUtil.alertNotNull(oidCollection,"主键集合",btmName,"业务类型");
        Collection<Collection<String>> oidCollections = WebUtil.switchCollectionForOracleIn(oidCollection);
        List<BusinessObject> doList = new ArrayList<BusinessObject>();
 
        for(Collection<String> oids: oidCollections){
            Map<String,String> conditionMap = new HashMap<String, String>();
            conditionMap.put("oid",QueryOptionConstant.IN + "(" + WebUtil.toInSql(oids.toArray(new String[0])) + ")");
            List<BusinessObject> list = queryCBO(btmName, conditionMap);
            if(CollectionUtils.isEmpty(list)){
                throw new VciBaseException("{0}条数据在系统中不存在",new String[]{String.valueOf(oids.size())});
            }
            doList.addAll(list);
        }
        return doList;
    }
 
    /**
     * 使用新的查询封装器来查询
     *
     * @param queryWrapper 查询封装器
     * @param doClass           对象的所属类
     * @return 数据
     * @throws VciBaseException 查询出错的会抛出异常
     */
    @Override
    public <T> List<T> selectByQueryWrapper(VciQueryWrapperForDO queryWrapper, Class<T> doClass) throws VciBaseException {
        String sql= queryWrapper.getSelectFieldSql() + " from " + queryWrapper.getTableName() + " " + queryWrapper.getTableNick() + queryWrapper.getLinkTableSql() ;
        String whereSql = queryWrapper.getWhereSql();
        if(StringUtils.isNotBlank(whereSql)){
            sql += " where " + whereSql;
        }
        return queryByOnlySqlForObj(sql,doClass);
    }
 
    /**
     * 使用新的查询封装器来查询总数
     *
     * @param queryWrapper 查询封装器
     * @param doClass           对象的所属类
     * @return 数据
     * @throws VciBaseException 查询出错的会抛出异常
     */
    @Override
    public <T> int countByQueryWrapper(VciQueryWrapperForDO queryWrapper, Class<T> doClass) throws VciBaseException {
        VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null,doClass);
        BeanUtil.convert(queryWrapper,queryWrapperForDO);
        queryWrapperForDO.clearPage();
        queryWrapperForDO.wrapperSql();
        String sql= queryWrapperForDO.getSelectFieldSql() + " from " + queryWrapperForDO.getTableName() + " " + queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() ;
        String whereSql = queryWrapperForDO.getWhereSql();
        if(StringUtils.isNotBlank(whereSql)){
            sql += " where " + whereSql;
        }
        return queryCountBySql("select count(*) from (" +sql + ")",null);
    }
 
}