wangting
2024-12-25 9e18636bed4fc3fceec08ca25d6c7916d4d9a429
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
package com.vci.starter.web.util;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.vci.common.exception.VciExceptionTool;
import com.vci.corba.common.PLException;
import com.vci.starter.web.annotation.Id;
import com.vci.starter.web.annotation.VciBtmType;
import com.vci.starter.web.annotation.VciLinkType;
import com.vci.starter.web.enumpck.BooleanEnum;
import com.vci.starter.web.enumpck.UserSecretEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.starter.web.toolmodel.DateConverter;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
 
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
/**
 * 基础的工具类
 * @author weidy
 */
public class VciBaseUtil {
 
    /**
     * 获取异常信息,因为抛出的异常不同,获取错误信息的方式存在差异所以无法统一获取
     * 后续有其他异常需要获取,自行添加处理逻辑,
     * @param e
     * @return
     */
    public static String getExceptionMessage(Throwable e){
        String exceptionStr = VciExceptionTool.getExceptionStr(e);
        if(exceptionStr.contains("VciBaseException")){
            return e.getMessage();
        }else if(exceptionStr.contains("PLException")){
            return Arrays.stream(((PLException) e).messages).collect(Collectors.joining("\n"));
        }else {
            return e.getMessage();
        }
    }
 
    /**
     * 日志对象
     */
    private static Logger log = LoggerFactory.getLogger(VciBaseUtil.class);
 
    /**
     * 生成PK值,uuid在高并发的时候会重复,但是非互联网产品中,同一个数据库表中的主键出现重复的概率较小
     * 如果是互联网产品,需要将这个修改为redis中获取uuid
     * @return uuid的值
     */
    public static String getPk() {
        return UUID.randomUUID().toString();
    }
 
    /**
     * 雪花ID
     * @return
     */
    public static String getSnowflakePk() {
        return String.valueOf(getSnowflakePk(1,1));
    }
 
    public static  Long getSnowflakePk(long workerId,long dataCenterId){
        Snowflake snowflake = IdUtil.getSnowflake(workerId,dataCenterId);
        return snowflake.nextId();
    }
 
    /**
     * 字符串转数字
     * @param string 字符串
     * @return 数字
     */
    public static int getInt(String string) {
        int i = 0;
        if (string == null || "".equals(string.trim())) {
            return 0;
        }
        if(string.contains(".")){
            string = string.substring(0,string.indexOf("."));
        }
        try {
            i = Integer.parseInt(string);
        } catch (Exception e) {
            return 0;
        }
        return i;
    }
 
    /**
     * 把boolean型转化为数字
     * @param b 布尔
     * @return 数字
     */
    public static int getIntForBoolean(boolean b){
        if (b) {
            return 1;
        } else {
            return 0;
        }
    }
 
    /**
     * 在hibernate中将结果转化为数字
     * @param obj 结果的对象
     * @return 数字
     */
    public static int getIntFromHibernateResult(Object obj){
        if(obj == null){
            return 0;
        }
        if(obj instanceof BigDecimal){
            return ((BigDecimal)obj).intValue();
        }else if(obj instanceof BigInteger){
            return ((BigInteger)obj).intValue();
        }else if(obj instanceof Double){
            return ((Double)obj).intValue();
        }else if(obj instanceof Long){
            return ((Long)obj).intValue();
        }else if(obj instanceof Short){
            return ((Short)obj).intValue();
        }else if(obj instanceof Float){
            return ((Float)obj).intValue();
        }else if(obj instanceof String){
            try{
                return Integer.valueOf(obj.toString());
            }catch(Exception e){
                return 0;
            }
        }else{
            return 0;
        }
    }
 
    /**
     * 字符串转布尔型
     * @param s 字符串
     * @return true字符串返回boolean型的true,其余返回false
     */
    public static  boolean getBoolean(String s){
        if(BooleanEnum.TRUE.getValue().equals(s)){
            return true;
        }else{
            return false;
        }
    }
 
    /**
     * 根据字符串获取对应的二进制
     * @param s 字符
     * @return 二进制对象
     */
    public static byte getByte(String s) {
        byte b = 0;
        if (s == null) {
            return 0;
        }
        try {
            b = Byte.parseByte(s);
        } catch (Exception e) {
            return 0;
        }
        return b;
    }
 
    /**
     *  字符转short
     * @param s 字符串
     * @return short值
     */
    public static short getShort(String s) {
        short i = 0;
        if (s == null) {
            return 0;
        }
        try {
            i = Short.parseShort(s);
        } catch (Exception e) {
            return 0;
        }
        return i;
    }
 
    /**
     * 字符串转Long
     * @param s 字符串
     * @return long
     */
    public static long getLong(String s) {
        long l = 0;
        if (s == null) {
            return 0;
        }
        try {
            l = Long.parseLong(s);
        } catch (Exception e) {
            return 0;
        }
        return l;
    }
 
    /**
     * 字符串转浮点型
     * @param s 字符串
     * @return 浮点型
     */
    public static float getFloat(String s) {
        float f = 0;
        if (s == null) {
            return 0;
        }
        try {
            f = Float.parseFloat(s);
        } catch (Exception e) {
            return 0;
        }
        return f;
    }
 
    /**
     * 字符串转double型
     * @param s 字符串
     * @return double
     */
    public static double getDouble(String s) {
        double d = 0;
        if (isNull(s)) {
            return 0;
        }
        try {
            d = Double.parseDouble(s);
        } catch (Exception e) {
            return 0;
        }
        return d;
    }
 
 
 
    /**
     * 去除最前面的逗号,去除后面的逗号
     * @param s 字符串
     * @return 去除末尾逗号
     */
    public static String removeComma(String s){
        if(s == null || s.trim().length() == 0) {
            return s;
        }
        else{
            if(s.startsWith(",")) {
                s = s.substring(1, s.length());
            }
            if(s.endsWith(",")) {
                s = s.substring(0, s.length() - 1);
            }
            return s;
        }
    }
 
    /**
     * 去除最前面的spiltFilter,去除后面的spiltFilter
     * @param s 字符串
     * @param spiltFilter,分隔符
     * @return 去除末尾逗号
     */
    public static String removeComma(String s,String spiltFilter){
        if(s == null || s.trim().length() == 0) {
            return s;
        }
        else{
            if(s.startsWith(spiltFilter)) {
                s = s.substring(spiltFilter.length(), s.length());
            }
            if(s.endsWith(spiltFilter)) {
                s = s.substring(0, s.length() - spiltFilter.length());
            }
            return s;
        }
    }
 
 
    /**
     * 为sql中使用in时,提供转换,注意in里的值不能超过1000
     * @param s 字符串
     * @return 返回sql语句
     */
    public static String toInSql(String s){
        s= removeComma(s);
        if(s == null || s.trim().length() == 0) {
            return "";
        }
        String[] temp = s.split(",");
        return toInSql(temp);
    }
 
    /**
     * 注意s的长度不能超过一千
     * @param s 字符串
     * @return insql
     */
    public static String toInSql(String[] s){
        if(s != null && s.length >0){
            StringBuilder sb = new StringBuilder();
            if(s!=null&&s.length>0){
                for(int i = 0 ; i < s.length ; i ++){
                    if(s[i]!=null&&s[i].trim().length() >0 && !s[i].startsWith("'")) {
                        sb.append("'")
                                .append(s[i])
                                .append("',");
                    }
                }
            }
            return removeComma(sb.toString());
        }else{
            return "";
        }
    }
 
    /**
     * 支持in 里数据为1000以上的
     * @param field 字段名称
     * @param s 原字符串
     * @return 含in的SQL
     */
    public static String toInSql(String field, String s){
        if(StringUtils.isBlank(field) || StringUtils.isBlank(s)){
            return "";
        }
        return toInSql(field,removeComma(s).split(","),"");
    }
 
    /**
     * 支持in里数据1000以上
     * @param field 字段名称
     * @param s 原字符串
     * @return 含in的SQL
     */
    public static String toInSql(String field, String[] s){
        return toInSql(field,s,"in");
    }
 
    /**
     * 不等于
     */
    public static final String NOTIN="not in";
    /**
     * 支持not in
     * @param field 字段
     * @param s 字符串数组
     * @param operation 操作方式
     * @return insql
     */
    public static String toInSql(String field, String[] s, String operation){
        if(StringUtils.isBlank(field) || s == null || s.length == 0){
            return "";
        }else{
            StringBuilder sb = new StringBuilder();
            if(s!=null&&s.length>0){
                String andOr = "or";
                if(operation.trim().toLowerCase().equals(NOTIN)){
                    andOr = "and";
                }
                for(int i = 0 ; i < s.length ; i ++){
                    if(s[i]!=null&&s[i].trim().length() >0 && !s[i].startsWith("'")) {
                        if (i == 0) {
                            sb.append(field).append(" ").append(operation).append(" (");
                        }
                        if (i % 500 == 0 && i != 0) {
                            sb.append(" ").append(andOr).append(" ").append(field).append(" ").append(operation).append(" (");
                        }
                        sb.append("'").append(s[i]).append("'");
                        if (i % 500 != 499 && i != s.length - 1) {
                            sb.append(",");
                        }
                        if (i % 500 == 499 || i == s.length - 1) {
                            sb.append(") ");
                        }
                    }
                }
            }
            return sb.toString();
        }
    }
 
    /**
     * 数组转为逗号分隔的字符串  使用array2String
     * @param array 数组
     * @return 字符串
     */
    @Deprecated
    public static String arrayToString(String[] array){
        if(array!= null && array.length>0){
            StringBuilder sb = new StringBuilder();
            for(int i = 0 ; i < array.length; i ++){
                String record = array[i];
                if(StringUtils.isNotBlank(record)) {
                    sb.append(record)
                            .append(",");
 
                }
            }
            return removeComma(sb.toString());
        }
        return "";
    }
 
    /**
     * 将集合转换为字符串
     * @param collection 集合
     * @return 字符串
     */
    public static String collectionToString(Collection collection){
        if(!CollectionUtils.isEmpty(collection)){
            StringBuilder sb = new StringBuilder();
            Iterator it = collection.iterator();
            while(it.hasNext()){
                Object record = it.next();
                if(record !=null && (!(record instanceof String) ||  StringUtils.isNotBlank(((String) record)))){
                    sb.append(record.toString()).append(",");
                }
            }
            return removeComma(sb.toString());
        }
        return "";
    }
 
    /**
     * 首字母大写
     * @param s 字符串
     * @return 含大写的字符串
     */
    public static String toUpForFirst(String s){
        if(s== null || s.trim().length()==0) {
            return "";
        }
        String temp = s.substring(0, 1);
        temp = temp.toUpperCase();
        return temp + s.substring(1,s.length());
    }
 
    /**
     * 首字母小写
     * @param s 字符串
     * @return 含大写的字符串
     */
    public static String toLowForFirst(String s){
        if(s== null || s.trim().length()==0) {
            return "";
        }
        String temp = s.substring(0, 1);
        temp = temp.toLowerCase();
        return temp + s.substring(1,s.length());
    }
 
    /**
     * 字符串中某个字符出现的次数
     * @param s 字符串
     * @param findC 要找的字符
     * @return 截取后的字符串
     */
    public static int countOfString(String s, char findC) {
        Map<String, Integer> charMap = new HashMap<String, Integer>();
        char[] cs = s.toCharArray();
        for (char c : cs) {
            charMap.put(String.valueOf(c), (!charMap.containsKey(String.valueOf(c))? 1 : charMap.get(String.valueOf(c)) + 1));
        }
        return charMap.get(String.valueOf(findC));
    }
 
    /**
     * 带逗号的字符串转为list
     * @param s 字符串
     * @return 字符串列表
     */
    public static List<String> str2List(String s,String spilter){
        if (isNull(s)) {
            return null;
        } else {
            List<String> l = new ArrayList<String>();
            Collections.addAll(l,removeComma(s,spilter).split(spilter));
            return l;
        }
    }
 
    /**
     * 带逗号的字符串转为list
     * @param s 字符串
     * @return 字符串列表
     */
    public static List<String> str2List(String s){
        if (isNull(s)) {
            return null;
        } else {
            List<String> l = new ArrayList<String>();
            Collections.addAll(l,removeComma(s).split(","));
            return l;
        }
    }
 
    /**
     * 列表转为带逗号分隔的字符串
     * @param ls 字符串列表
     * @return 逗号分隔的字符串
     */
    public static String list2String(List<String> ls){
        if(ls == null || ls.size() == 0) {
            return "";
        }else{
            return ls.stream().collect(Collectors.joining(","));
        }
    }
 
    /**
     * 判断字符串是不是空,不判断trim
     * @param o 字符串
     * @return true表示空
     */
    public static boolean isNull(String o){
        return StringUtils.isEmpty(o);
    }
 
    /**
     * 判断不是空,不判断trim
     * @param o 字符串
     * @return true表示不为空
     */
    public static boolean isNotNull(String o){
        return !isNull(o);
    }
 
    /**
     * 判断字符串是不是空,去除trim
     * @param o 字符串
     * @return true表示为空,或者null,或"",或" "
     */
    public static boolean isNullOrNullString(String o){
        return StringUtils.isBlank(o);
    }
 
 
    /**
     * 字符串是否在数组中
     * @param arr 数组对象
     * @param s 字符串
     * @return 不区分大小写
     */
    public static boolean inArray(String[] arr, String s) {
        if(arr!=null && s != null){
            for(String a : arr){
                if(s.trim().equalsIgnoreCase(a)) {
                    return true;
                }
            }
        }
        return false;
    }
 
    /**
     * 是否在数组中
     * @param arr 数组对象
     * @param o 对象
     * @return true表示在数组中
     */
    public static boolean inArray(Object[] arr, Object o){
        if(arr!=null && o != null){
            for(Object a : arr){
                if(a.equals(o)){
                    return true;
                }
            }
        }
        return false;
    }
    /**
     * double取精度
     * @param value 值
     * @param scale 保留小数
     * @param roundingMode 尾数处理方法
     * @return 转换后的值
     */
    public static double round(double value, int scale,
                               int roundingMode) {
        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(scale, roundingMode);
        double d = bd.doubleValue();
        bd = null;
        return d;
    }
 
    /**
     * 取精度,四舍五入法
     * @param value 值
     * @param scale 比例
     * @return 转换后的值
     */
    public static double round(double value,int scale){
        return round(value,scale, BigDecimal.ROUND_HALF_UP);
    }
 
 
    /**
     * 判断邮件地址是否合法
     * @param string 字符串
     * @return true表示为邮件地址
     */
    public static boolean isEmail(String string) {
        if (StringUtils.isBlank(string)) {
            return false;
        }
        String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p;
        Matcher m;
        p = Pattern.compile(regEx1);
        m = p.matcher(string);
        if (m.matches()) {
            return true;
        }else {
            return false;
        }
    }
 
 
 
    /**
     * 判断是否为数字
     * @param s 字符串
     * @return true表示符合
     */
    public static boolean isNumber(String s){
        if(StringUtils.isNotBlank(s) && s.matches("\\d+\\.?\\d*")){
            return true;
        }else{
            return false;
        }
    }
 
    /**
     * 获取属性列表中得某个属性
     * @param fieldName 字段名称
     * @param fieldsList 字段的对象列表
     * @return 符合条件的属性对象
     */
    public static Field getFieldForObject(String fieldName, List<Field> fieldsList){
        if(StringUtils.isBlank(fieldName)){
            return null ;
        }
        if(fieldsList != null && fieldsList.size() > 0){
            for(Field field : fieldsList){
                if(field.getName().toLowerCase().equals(fieldName.toLowerCase())){
                    return field;
                }
            }
        }
        return null ;
    }
 
    /**
     * 获取字段的setter
     * @param c 类对象
     * @param fieldName 字段名称
     * @return 符合条件的对象
     */
    public static Method getSetmethod(Class c, String fieldName){
        if(c!=null&&StringUtils.isNotBlank(fieldName)){
            try {
                PropertyDescriptor pd = new PropertyDescriptor(fieldName, c);
                return pd.getWriteMethod();
            } catch (SecurityException e) {
                if(log.isErrorEnabled()){
                    log.error("获取getter出错",e);
                }
            } catch (IntrospectionException e) {
                if(log.isErrorEnabled()){
                    log.error("获取getter出错",e);
                }
            }
        }
        return null;
    }
 
    /**
     * 获取字段的getter
     * @param c 类对象
     * @param fieldName 属性名称
     * @return 符合条件的对象
     */
    public static Method getGetmethod(Class c, String fieldName){
        if(c!=null&&StringUtils.isNotBlank(fieldName)){
            try {
                PropertyDescriptor pd = new PropertyDescriptor(fieldName, c);
                return pd.getReadMethod();
            } catch (SecurityException e) {
                if(log.isErrorEnabled()){
                    log.error("获取getter出错",e);
                }
            } catch (IntrospectionException e) {
                if(log.isErrorEnabled()){
                    log.error("获取getter出错",e);
                }
            }
        }
        return null;
    }
 
    /**
     * 获取Column注解上的name的值
     * @param fieldAnnotaions 所有的注解对象
     * @return name的值
     */
    public static String getColumnAnnotaionNameValue(Annotation[] fieldAnnotaions){
        return getAnnotationValue("com.vci.starter.web.annotation.Column,javax.persistence.Column","name",fieldAnnotaions);
    }
 
    /**
     * 获取注解中的某个方法的值
     * @param annotationName 注解的名称
     * @param methodName 方法名称
     * @param fieldAnnotaions 注解的集合
     * @return 符合条件的值
     */
    public static String getAnnotationValue(String annotationName,String methodName,Annotation[] fieldAnnotaions){
        String[] annotaionNameArray = annotationName.split(",");
        for(Annotation annotation : fieldAnnotaions){
            String anname = annotation.annotationType().getName();
            if(inArray(annotaionNameArray,anname)){
                String name = null;
                try {
                    name = (String)annotation.getClass().getMethod(methodName).invoke(annotation);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                }
                return name;
            }
        }
        return null;
    }
 
    /**
     * 从对象上获取cbo里的值
     * @param field 字段对象
     * @param c 类对象
     * @return cbo中的值
     */
    public static String getCboAttrNameFromField(Field field, Class c){
        String clientBoAttrName = field.getName().toLowerCase();
        String name = null;
        if(!VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY &&( VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(clientBoAttrName)
                ||VciQueryWrapperForDO.REVISION_MANAGE_FIELD_MAP.containsKey(clientBoAttrName)
                ||VciQueryWrapperForDO.LIFECYCLE_MANAGE_FIELD_MAP.containsKey(clientBoAttrName)
                ||VciQueryWrapperForDO.LINK_TYPE_FIELD_MAP.containsKey(clientBoAttrName))){
            //是新平台,不用column注解上去获取名字
        }else {
            name = getColumnAnnotaionNameValue(field.getDeclaredAnnotations());
            if (StringUtils.isBlank(name)) {
                //找一下Get方法上..set方法上肯定是不支持的,
                Method getMethod = getGetmethod(c, field.getName());
                if (getMethod != null) {
                    name = getColumnAnnotaionNameValue(getMethod.getDeclaredAnnotations());
                }
                if (StringUtils.isBlank(name)) {
                    //参照或者是枚举的
                    name = getAnnotationValue("com.vci.starter.web.annotation.Transient", "referColumn", field.getDeclaredAnnotations());
                }
            }
        }
        if(StringUtils.isNotBlank(name)){
            clientBoAttrName = name;
        }
        return clientBoAttrName;
    }
 
    /**
     * 是否为基础类型
     * @param c 类对象
     * @return true表示基础类型
     */
    public  static boolean isBasicType(Class<?> c){
        if(c == null){
            return false;
        }
        if(c.isArray()){
            return isBasicType(c.getComponentType());
        }
        return ClassUtilForVCI.isPrimitive(c);
    }
 
    /**
     * 获取类中的字段映射
     * @param c 类对象
     * @return key为业务类型中的字段名称,value为类中的属性名称
     */
    public static Map<String/*业务类型中的字段*/,String/*对象上的属性*/> getFieldNameMap(Class c){
        Map<String,String> fieldMap = new HashMap<String, String>();
        List<Field> allField = getAllFieldForObj(c);
        if(allField!=null&&allField.size()>0){
            for(Field field : allField){
                if(!field.getName().equals("serialVersionUID")){
                    Class fieldTypeClass = field.getType();
                    if(isBasicType(fieldTypeClass)){
                        String referColumn =  getAnnotationValue("com.vci.starter.web.annotation.Transient","referColumn",field.getDeclaredAnnotations());
                        if (StringUtils.isNotBlank(referColumn)){
                            //说明不是持久化的属性,但是从平台中查询出来后可能得需要显示
                            fieldMap.put(referColumn, field.getName());
                        }else{
 
                            String clientBoAttrName = getCboAttrNameFromField(field,c);
                            fieldMap.put(clientBoAttrName, field.getName());
                        }
                    }else{
                        //不是基本类型的,那一定不是要的属性
                    }
                }
            }
        }
        return fieldMap;
    }
 
    /**
     * 从对象上获取属性的值
     * @param fieldName 属性名
     * @param sourceObject 对象
     * @return 属性的值
     */
    public static Object getValueFromField(String fieldName, Object sourceObject){
        if(StringUtils.isNotBlank(fieldName)){
            try {
                Method getMethod = getGetmethod(sourceObject.getClass(), fieldName);
                if(getMethod !=null){
                    return getMethod.invoke(sourceObject);
                }else{
                    //说明没有设置getter,比如BO和LO对象这种
                    Field field = getFieldForObject(fieldName, sourceObject);
                    if(field !=null){
                        field.setAccessible(true);
                        return field.get(sourceObject);
                    }
                }
            } catch (SecurityException e) {
                if(log.isErrorEnabled()){
                    log.error("从属性上获取值",e);
                }
            } catch (IllegalAccessException e) {
                if(log.isErrorEnabled()){
                    log.error("从属性上获取值",e);
                }
            } catch (IllegalArgumentException e) {
                if(log.isErrorEnabled()){
                    log.error("从属性上获取值",e);
                }
            } catch (InvocationTargetException e) {
                if(log.isErrorEnabled()){
                    log.error("从属性上获取值",e);
                }
            }
        }
        return null;
    }
 
 
    /**
     * 将属性值赋值到对象上
     * @param fieldName 属性名
     * @param obj 对象
     * @param value 属性值
     */
    public static void setValueForField(String fieldName, Object obj, String value){
        try{
            Field field = getFieldForObject(fieldName,obj);
            if(field!=null){
                setValueForField(field,obj,value);
            }
        }catch (Exception e) {
            if(log.isErrorEnabled()) {
                log.error("设置属性的值出错了错误",e);
            }
        }
    }
 
    /**
     * 将属性值赋值到对象上
     * @param field 属性对象
     * @param obj 对象
     * @param value 属性值
     */
    public static void setValueForField(Field field,Object obj, String value){
        try {
            if (field != null && StringUtils.isNotBlank(value)) {
                field.setAccessible(true);
                Method setMethod = getSetmethod(field.getDeclaringClass(), field.getName());
                Class type = field.getType();
                //从平台读取到的值不会为null,为空时为"";所以不处理空值
                Object valueObj = null;
                if (type.equals(int.class) || type.equals(Integer.class)) {
                    valueObj = VciBaseUtil.getInt(value);
                } else if (type.equals(float.class) || type.equals(Float.class)) {
                    valueObj = VciBaseUtil.getFloat(value);
                } else if (type.equals(long.class) || type.equals(Long.class)) {
                    valueObj = VciBaseUtil.getLong(value);
 
                } else if (type.equals(Double.class) || type.equals(double.class)) {
                     valueObj = VciBaseUtil.getDouble(value);
                    //从平台中查询出来就不用处理精度了,因为平台会自行处理
                } else if (type.equals(Date.class)) {
                    DateConverter dateConverter = new DateConverter();
                    dateConverter.setAsText(value);
                    valueObj = dateConverter.getValue();
                } else if (type.equals(String.class)) {
                    valueObj = value;
                } else {
                    valueObj = value;
                    if (log.isErrorEnabled()) {
                        log.error("不支持的类型" + type.toString());
                    }
                }
                if (setMethod != null) {
                    setMethod.invoke(obj, valueObj);
                } else {
                    field.set(obj, valueObj);
                }
            }
        }catch (Throwable e){
            if(log.isErrorEnabled()) {
                log.error("设置属性的值出错了错误",e);
            }
        }
    }
 
    /**
     * 调用属性的setter赋值
     * @param field 属性对象
     * @param obj 要赋值的对象
     * @param value 值
     */
    public  static void setValueForMethod(Field field, Object obj , Object value){
        try {
            if (field != null) {
                field.setAccessible(true);
                Method setMethod = getSetmethod(field.getDeclaringClass(), field.getName());
                setMethod.invoke(obj, value);
            }
        }catch (Exception e){
            log.error("反射调用方法出现了错误,",e);
        }
    }
 
    /**
     * 把object对象转化为字符串
     * @param obj 对象
     * @return 字符串
     */
    public static String getStringValueFromObject(Object obj){
        if(obj == null){
            return "";
        }else{
            if(obj instanceof Integer || obj instanceof Float || obj instanceof Long || obj instanceof Double){
                if(obj instanceof  Double){
                    Double aDouble = (Double) obj;
                    if(aDouble!=null&& aDouble%1==0){
                        return String.valueOf(aDouble.intValue());
                    }
                }
                return String.valueOf(obj);
            }else if(obj instanceof Date){
                return VciDateUtil.date2Str((Date)obj, VciDateUtil.DateTimeMillFormat);
            }else{
                return obj.toString();
            }
        }
    }
 
    /**
     * 提示参数为空
     * @param s 相关的参数,两两组合,第一个为参数的对象,第二个为显示的名称
     * @throws VciBaseException 如果参数为空的时候会抛出异常
     */
    public static void alertNotNull(Object... s) throws VciBaseException {
        if(s!=null && s.length>0){
            for(int i = 0 ; i < s.length ; i ++){
                Object obj = s[i];
                String param = "";
                try{
                    i++;
                    param = s[i].toString();
                }catch(Exception e){
 
                }
                if(obj==null){
                    throw new VciBaseException("参数[{0}]不能为空",new String[]{param});
                }else {
                    if(obj instanceof Collection){
                        if(CollectionUtils.isEmpty((Collection)obj)){
                            throw new VciBaseException("参数[{0}]不能为空",new String[]{param});
                        }
                    }else{
                        if(StringUtils.isBlank(obj.toString())){
                            throw new VciBaseException("参数[{0}]不能为空",new String[]{param});
                        }
                    }
                }
            }
        }
    }
 
    /**
     * 提示集合里的参数为空,(2020-09被废弃,请直接使用alertNotNull方法)
     * @param param 提示信息
     * @param collections 集合
     * @throws VciBaseException 参数为空的时候会抛出异常
     */
    @Deprecated
    public static void alertCollectionNotNull(String param, Collection collections) throws VciBaseException{
        if(CollectionUtils.isEmpty(collections)){
            throw new VciBaseException("参数{0}不能为空",new String[]{param});
        }
    }
 
    /**
     * oracle in 查询不能超过1000,转换一下集合
     * 由于SQL语句1000个可能很长,超过oracle10g,所以牺牲性能分配为500个数组
     * @param list 需要转换的列表内容
     * @return 分组后的list
     */
    public static <T> List<List<T>> switchListForOracleIn(List<T> list) {
        List<List<T>> listHasList = new ArrayList<List<T>>();
        if(list == null){
            return listHasList;
        }
        List<T> newList = new ArrayList<T>();
        for(Object obj : list){
            //为了让list还可以添加内容,因为使用sublist后,list不能再Add了
            newList.add((T)obj);
        }
        int muti = 1;
        if(newList.size() >500){
            int balance = newList.size()%500;
            muti = (newList.size() - balance)/500 + (balance == 0?0:1);
        }
        for(int i = 0 ; i < muti; i ++){
            int start = i*500;
            int end = start + 500;
            if(i == muti-1 || end >newList.size() ){
                end = newList.size();
            }
            List subList = newList.subList(start,end);
            listHasList.add(subList);
        }
        return listHasList;
    }
 
    /**
     * oracle in 查询不能超过1000,转换一下集合
     * 由于SQL语句1000个可能很长,超过oracle10g,所以牺牲性能分配为500个数组
     * @param list 需要转换的列表内容
     * @return 分组后的list
     */
    public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> list) {
       return switchCollectionForOracleIn(list,500);
    }
 
    /**
     * 转换集合的大小,这个用在feign调用的时候,不要在sql查询的时候使用
     * @param collection 需要转换的列表内容
     * @param preSize 每个分组的大小
     * @return 分组后的list
     */
    public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> collection,int preSize) {
        Collection<Collection<T>> listHasList = new ArrayList<>();
        if(collection == null){
            return listHasList;
        }
        List<T> newList = new ArrayList<T>();
        for(Object obj : collection){
            //为了让list还可以添加内容,因为使用sublist后,list不能再Add了
            newList.add((T)obj);
        }
        int muti = 1;
        if(newList.size() >preSize){
            int balance = newList.size()%preSize;
            muti = (newList.size() - balance)/preSize + (balance == 0?0:1);
        }
        for(int i = 0 ; i < muti; i ++){
            int start = i*preSize;
            int end = start + preSize;
            if(i == muti-1 || end >newList.size() ){
                end = newList.size();
            }
            List subList = newList.subList(start,end);
            listHasList.add(subList);
        }
        return listHasList;
    }
 
    /**
     * oracle in 查询不能超过1000,转换一下集合。注意这个顺序可能会发生变化
     * 由于SQL语句1000个可能很长,超过oracle10g,所以牺牲性能分配为500个数组
     * @param set set集合
     * @return 转换后的set
     * @throws VciBaseException
     */
    public static <T> Set<Set<T>> switchSetForOracleIn(Set<T> set){
        Set<Set<T>> listHasList = new HashSet<Set<T>>();
        if(set == null){
            return listHasList;
        }
        int muti = 1;
        if(set.size() >500){
            int balance = set.size()%500;
            muti = (set.size() - balance)/500 + (balance == 0?0:1);
        }
        List list = new ArrayList();
        //为了保证以前的引用关系,不是有转数组的方法
        Iterator it = set.iterator();
        while(it.hasNext()){
            list.add(it.next());
        }
        for(int i = 0 ; i < muti; i ++){
            int start = i*500;
            int end = start + 500;
            if(i == muti-1 || end >set.size() ){
                end = set.size();
            }
            List subList = list.subList(start,end);
            Set subSet = new HashSet();
            for(Object obj : subList){
                subSet.add(obj);
            }
            listHasList.add(subSet);
        }
        return listHasList;
    }
 
    /**
     * oracle in 查询不能超过1000,转换一下集合,注意这个顺序可能会发生变化
     * 由于SQL语句1000个可能很长,超过oracle10g,所以牺牲性能分配为500个数组
     * @param vector vector集合
     * @return 转换后的迭代器
     * @throws VciBaseException
     */
    public static <T> Vector<Vector<T>> switchVectorForOracleIn(Vector<T> vector) {
        Vector<Vector<T>> listHasList = new Vector<Vector<T>>();
        if(vector == null){
            return listHasList;
        }
        int muti = 1;
        if(vector.size() >500){
            int balance = vector.size()%500;
            muti = (vector.size() - balance)/500 + (balance == 0?0:1);
        }
        List list = new ArrayList();
        //为了保证以前的引用关系,不是有转数组的方法
        Iterator it = vector.iterator();
        while(it.hasNext()){
            list.add(it.next());
        }
        for(int i = 0 ; i < muti; i ++){
            int start = i*500;
            int end = start + 500;
            if(i == muti-1 || end >vector.size() ){
                end = vector.size();
            }
            List subList = list.subList(start,end);
            Vector subSet = new Vector();
            for(Object obj : subList){
                subSet.add(obj);
            }
            listHasList.add(subSet);
        }
        return listHasList;
    }
 
    /**
     * 获取当前用户的用户名
     * @return 当前用户的用户名
     */
    public static String getCurrentUserId( ){
        SessionInfo s = getCurrentUserSessionInfoNotException();
        if(s !=null){
            return s.getUserId();
        }else{
            return  "";
        }
    }
 
    /**
     * 获取当前用户的主键
     * @return 当前用户的主键
     */
    public static String getCurrentUserOid(){
        SessionInfo s = getCurrentUserSessionInfoNotException();
        if(s !=null){
            return s.getUserOid();
        }else{
            return  "";
        }
    }
 
    /**
     * json字符串转为对象
     * @param jsonString json字符串
     * @param beanClass 对象类型
     * @return java对象
     */
    public static <T> T jsonString2JavaBean(String jsonString, Class<T> beanClass){
        return (T) JSONObject.parseObject(jsonString,  beanClass);
    }
 
    /**
     * 判断字符串是否为空,为空则添加默认值
     * @param str 字符串
     * @param defaultValue 默认值
     */
    public static void ifNullSetDefautl(String str, String defaultValue) {
        if(isNull(str)) {
            str = defaultValue;
        }
    }
 
    /**
     * 从json字符串中获取第一个对象
     * @param jsonString json字符串
     * @param beanClass 对象类型
     * @return java对象
     * @throws Exception
     */
    public static <T> T getFristObjectFromJson(String jsonString, Class<T> beanClass){
        if(!isNull(jsonString)) {
            return JSONObject.parseArray(jsonString, beanClass).get(0);
        }else {
            return null;
        }
    }
 
    /**
     * 获取当前线程中的用户对象
     * @return 会话信息
     * @throws VciBaseException 如果没有登录会抛出异常
     */
    public static SessionInfo getCurrentUserSessionInfo() throws VciBaseException {
        SessionInfo si= getCurrentUserSessionInfoNotException();
        if(si==null){
            throw new VciBaseException("noLogin",new String[]{"没有当前用户信息"});
        }
        return si;
    }
 
    /**
     * 获取当前线程中的用户对象
     * @return 会话对象
     */
    public static SessionInfo getCurrentUserSessionInfoNotException() {
        return WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
    }
 
    /**
     * 设置当前线程中的用户对象
     * @param sessionInfo 用户对象
     */
    public static void setCurrentUserSessionInfo(SessionInfo sessionInfo){
        WebThreadLocalUtil.setCurrentUserSessionInfoInThread(sessionInfo);
    }
 
    /**
     * 是否查询总数
     * @return true表示查询
     */
    public static boolean isQueryTotal(){
        String needQueryTotal = WebThreadLocalUtil.getNeedQueryTotalInThread();
        if("false".equalsIgnoreCase(needQueryTotal)){
            return false;
        }else{
            return true;
        }
    }
 
    /**
     * 将对象转换为字符串出来
     * @return json字符串
     */
    public static String getJSONStringWithDateFormat(Object obj){
        return JSONObject.toJSONStringWithDateFormat(obj, VciDateUtil.DateTimeMillFormat, SerializerFeature.WriteDateUseDateFormat);
    }
 
    /**
     * 对象转换为map
     * @param o 对象
     * @return map对象
     */
    public static Map<String,Object> objectToMap(Object o) {
        Map<String,Object> map = new HashMap<String,Object>();
        if(o!=null) {
            String jsonString = JSONObject.toJSONStringWithDateFormat(o, VciDateUtil.DateTimeMillFormat, SerializerFeature.WriteDateUseDateFormat);
            if(StringUtils.isNotBlank(jsonString)) {
                JSONObject jsonObject = JSONObject.parseObject(jsonString);
                if(jsonObject!=null){
                    for(String key : jsonObject.keySet()){
                        map.put(key,jsonObject.get(key));
                    }
                }
            }
        }
        return map;
    }
 
    /**
     * 对象转换为map,值为字符串
     * @param o 对象
     * @return map对象
     */
    public static Map<String,String> objectToMapString(Object o){
        Map<String,String> map = new HashMap<String,String>();
        if(o!=null) {
            String jsonString = JSONObject.toJSONStringWithDateFormat(o, VciDateUtil.DateTimeMillFormat, SerializerFeature.WriteDateUseDateFormat);
            if(StringUtils.isNotBlank(jsonString)) {
                JSONObject jsonObject = JSONObject.parseObject(jsonString);
                if(jsonObject!=null){
                    for(String key : jsonObject.keySet()){
                        map.put(key,jsonObject.getString(key));
                    }
                }
            }
        }
        return map;
    }
 
 
    /**
     * 属性值是否为空
     * @param obj 对象
     * @param f 属性对象
     * @return true不是空
     */
    public static boolean isNotNullForField(Object obj, Field f){
        if(!"serialVersionUID".equalsIgnoreCase(f.getName()) &&!"DEFAULT_INITIAL_CAPACITY".equalsIgnoreCase(f.getName())&&null!=obj && !isNullOrNullString(obj.toString())) {
            return true;
        } else {
            return false;
        }
    }
 
 
    /**
     * 数组转换为String
     * @param array 数组对象
     * @param spiltFiter 分隔符
     * @return 逗号链接的字符串
     */
    public static String array2String(String[] array,String spiltFiter) {
        if(null == array || array.length == 0) {
            return "";
        } else{
            String ss = "";
            for(String s : array){
                ss += s + spiltFiter;
                //1.8可以
            }
            return removeComma(ss,spiltFiter);
        }
    }
    /**
     * 数组转换为String
     * @param array 数组对象
     * @return 逗号链接的字符串
     */
    public static String array2String(String[] array) {
        if(null == array || array.length == 0) {
            return "";
        } else{
            String ss = "";
            for(String s : array){
                ss += s + ",";
                //1.8可以
            }
            return removeComma(ss);
        }
    }
 
    /**
     * 对象转换为字符串
     * @param obj 对象
     * @return 字符串
     */
    public static String getString(Object obj){
        if(obj == null) {
            return "";
        }
        if(obj instanceof Date) {
            return VciDateUtil.date2Str((Date) obj, VciDateUtil.DateTimeFormat);
        }
        return String.valueOf(obj);
    }
 
    /**
     * 拷贝值到map
     * @param source 原对象
     * @param target 目标对象
     * @param copyField 要拷贝的属性值
     */
    public static void copyValueForMap(Map source, Map target, String[] copyField){
        Map<String,String> copyFieldMap = new HashMap<String,String>();
        for(String field : copyField) {
            copyFieldMap.put(field, field);
        }
        copyValueForMap(source,target,copyFieldMap);
    }
    /**
     * 为map拷贝值
     * @param source 源对象
     * @param target 目标对象
     * @param copyField key为目标对象里的字段,
     */
    public static void copyValueForMap(Map source, Map target, Map<String,String> copyField){
        try{
            Iterator<String> it = copyField.keySet().iterator();
            while(it.hasNext()){
                String field = it.next();
                target.put(field, source.get(copyField.get(field)));
            }
        }catch(Exception e){
 
        }
    }
 
    /**
     * 从映射对象中获取double的值
     * @param field 字段名称
     * @param record 映射对象
     * @return double类型的值,不存在时返回null
     */
    public static Double getDoubleFromMap(String field,
                                          Map<String, Object> record) {
        if(isNullOrNullString(field) || record == null || !record.containsKey(field)) {
            return null;
        }else{
            Object v = record.get(field);
            if(v instanceof BigDecimal){
                return ((BigDecimal)v).doubleValue();
            }else if(v instanceof Double){
                return ((Double)v).doubleValue();
            }
            else{
                return getDouble((String)v);
            }
        }
    }
 
    /**
     * 从映射对象中获取某个key的字符串类型值
     * @param key 键
     * @param data 映射对象
     * @return string类型的值,不存在时返回""
     */
    public static String getDataByKey(String key, Map<String,Object> data){
        String value = "";
        if(data.containsKey(key)) {
            value = (String) data.get(key);
        }
        if(value == null) {
            value = "";
        }
        return value;
    }
 
    /**
     * 获取不是空值的映射,且key是小写
     * @param map 获取不包含空值的映射对象
     * @return 不包含空值的映射对象
     */
    public static Map getNotNullMap(Map map){
        if(map == null){
            return new HashMap();
        }
        Iterator it = map.keySet().iterator();
        Map unNullMap = new HashMap();
        while(it.hasNext()){
            Object key = it.next();
            String newKey = key.toString().toLowerCase();
            Object value = map.get(key);
            if(value !=null){
                if(value instanceof String && isNotNull(value.toString())){
                    unNullMap.put(newKey, value);
                }else if(!(value instanceof String)){
                    unNullMap.put(newKey, value);
                }
            }
        }
        return unNullMap;
    }
 
    /**
     * 获取对象中的所有属性,包括其继承的属性
     * @param c 对象所属的类
     * @return 所有的字段
     */
    public static List<Field> getAllFieldForObj(Class c){
        List<Field> allField = new ArrayList<Field>();
        Set<String> fieldNameSet = new HashSet<>();
        for(Class<?> classz = c; classz != Object.class ; classz = classz.getSuperclass() ){
            Field[] thisClassField = classz.getDeclaredFields();
            for(Field field : thisClassField){
                if(!field.getName().equals("serialVersionUID")){
                    String fieldLowerName = field.getName().toLowerCase();
                    if(!fieldNameSet.contains(fieldLowerName)){
                        fieldNameSet.add(fieldLowerName);
                        allField.add(field);
                    }
                }
            }
        }
        return allField;
    }
 
    /**
     * 获取对象的主键
     * @param c 对象所属的类
     * @return 属性对象
     */
    public static Field getPkFieldForObj(Class c){
        List<Field> allField = getAllFieldForObj(c);
        if(allField!=null&&allField.size()>0){
            for(Field field : allField){
                if(field.isAnnotationPresent(Id.class)){
                    return  field;
                }
            }
            //如果没找到,那就找oid
            for(Field field : allField){
                if(field.getName().toLowerCase().equalsIgnoreCase("oid")){
                    return  field;
                }
            }
        }
        return null;
    }
 
    /**
     * 获取ts的字段
     * @param c 对象所属的类
     * @return 时间戳的属性对象
     */
    public static Field getTsField(Class c){
        List<Field> allField = getAllFieldForObj(c);
        if(allField!=null&&allField.size()>0){
            for(Field field : allField){
                if(field.getName().equals("ts")){
                    return  field;
                }
            }
        }
        return null;
    }
 
    /**
     * 根据名称获取字段
     * @param fieldName 属性的名称
     * @param obj 数据对象
     * @return 属性对象
     */
    public static Field getFieldForObject(String fieldName, Object obj){
        if(obj == null){
            return null;
        }
        return getFieldForObject(fieldName,obj.getClass());
    }
 
    /**
     * 根据属性名称获取属性的对象
     * @param fieldName 属性名称
     * @param c 对象所属类
     * @return 属性对象
     */
    public static Field getFieldForObject (String fieldName, Class c){
        List<Field> allField = getAllFieldForObj(c);
        if(allField!=null&&allField.size()>0){
            for(Field field : allField){
                if(field.getName().toLowerCase().equalsIgnoreCase(fieldName.toLowerCase())){
                    return  field;
                }
            }
        }
        return null;
    }
 
    /**
     * 获取字段的setter
     * @param c 对象所属类
     * @param field 属性对象
     * @return set的方法
     */
    public static Method getSetmethod(Class c, Field field){
        return getSetmethod(c,field.getName());
    }
 
    /**
     * 获取字段的getter
     * @param c 对象所属类
     * @param field 属性对象
     * @return get方法
     */
    public static Method getGetmethod(Class c, Field field){
        return getGetmethod(c,field.getName());
    }
 
    /**
     * 根据方法的名字获取方法的对象
     * @param classObj 所属的类
     * @param methodName 方法的名称
     * @return 方法的对象
     */
    public static Method getMethodByName(Class<?> classObj,String methodName){
        VciBaseUtil.alertNotNull(classObj,"获取方法的对象所属的类",methodName,"方法的名字");
        Method[] methods = classObj.getMethods();
        List<Method> sameMethods = Arrays.stream(methods).filter(method -> method.getName().equalsIgnoreCase(methodName)).collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(sameMethods)){
            return sameMethods.get(0);
        }else{
            return null;
        }
    }
 
    /**
     * 将whereSql里的内容转化到查询map里
     * @param whereSql 查询语句sql
     * @return map对象,key是查询条件,value是条件值
     */
    public static Map<String,String> whereSql2Map(
            String whereSql) {
        Map<String,String> map = new HashMap<String, String>();
        if(isNotNull(whereSql)){
            String[] selects = whereSql.split("and");
            if(selects!=null&&selects.length>0){
                for(String s : selects){
                    s = s.trim();
                    map.put(s.substring(0,s.indexOf(" ")).trim(), s.substring(s.indexOf(" ") +1).trim());
                }
            }
        }
        return map;
    }
 
    /**
     * 获取随机的文件名称
     * @param prefix 前缀
     * @return 文件名称
     */
    public synchronized static String getRoundFilename(String prefix) {
        if(prefix == null) {
            prefix = "";
        }
        return prefix + System.currentTimeMillis();
    }
 
    private static String localIp = null;
 
    /**
     * 获取本机地址,不是客户端电脑的ip,是当前服务所在的ip
     * @return 本机地址,如果没有则未127.0.0.1
     */
    public static String getLocalIp(){
        if(localIp == null){
            try {
                InetAddress inetAddress = getLocalHostLANAddress();
                if (inetAddress == null) {
                    localIp = "127.0.0.1";
                } else {
                    localIp = inetAddress.getHostAddress();
                }
            }catch (Exception e){
                localIp = "127.0.0.1";
            }
        }
        return localIp;
    }
 
    /**
     * 从网络接口上获取ip地址
     * @return IP接口对象
     * @throws Exception 查询出错时会抛出异常
     */
    private static InetAddress getLocalHostLANAddress() throws Exception {
        try {
            InetAddress candidateAddress = null;
            // 遍历所有的网络接口
            for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements(); ) {
                NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
                // 在所有的接口下再遍历IP
                for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements(); ) {
                    InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
                    if (!inetAddr.isLoopbackAddress()) {// 排除loopback类型地址
                        if (inetAddr.isSiteLocalAddress()) {
                            // 如果是site-local地址,就是它了
                            return inetAddr;
                        } else if (candidateAddress == null) {
                            // site-local类型的地址未被发现,先记录候选地址
                            candidateAddress = inetAddr;
                        }
                    }
                }
            }
            if (candidateAddress != null) {
                return candidateAddress;
            }
            // 如果没有发现 non-loopback地址.只能用最次选的方案
            InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
            return jdkSuppliedAddress;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     * 获取当前用户的密级
     * @return 如果用户没有登录,返回非密
     */
    public static Integer getCurrentUserSecret() {
        SessionInfo currentUserSession = getCurrentUserSessionInfoNotException();
        if(currentUserSession != null){
            return getInt(currentUserSession.getUserSecret());
        }else{
            return UserSecretEnum.NONE.getValue();
        }
    }
 
    /**
     * 获取项目运行时的路径,在开发环境里的地址是到target文件夹
     * @return 项目运行的环境地址,开发环境为target所在的地址
     */
    public static String getProjectPath(){
        String path = "";
        try {
            String jarFilePath = ResourceUtils.getURL("classpath:").getPath();
            if(jarFilePath.contains("!")){
                path = new File(jarFilePath).getParentFile().getParentFile().getParent();
            }else {
                path = new File(jarFilePath).getParent();
            }
        }catch (IOException e){
            throw new VciBaseException("获取当前服务所在的文件夹出现了错误");
        }
        if(path.startsWith("file:\\")){
            path = path.substring(6);
        }
        return path;
    }
 
    /**
     * 从数据对象上获取业务类型的名称
     * @param modelClass 数据对象所属的类
     * @return 如果存在注解就获取注解上的名称,否则获取类的名称
     */
    public static String getBtmTypeNameFromDO(Class<?> modelClass){
        if(modelClass.isAnnotationPresent(VciBtmType.class)){
            VciBtmType btmType = modelClass.getDeclaredAnnotation(VciBtmType.class);
            if(btmType != null){
                return btmType.name();
            }
        }
        String name = modelClass.getSimpleName();
        if(name.endsWith("DO")){
            name = name.substring(0,name.length()-2);
        }
        return name;
    }
 
    /**
     * 从数据对象上获取链接类型的名称
     * @param modelClass 数据对象所属的类
     * @return 如果存在注解就获取注解上的名称,否则获取类的名称
     */
    public static String getLinkTypeNameFromDO(Class<?> modelClass){
        if(modelClass.isAnnotationPresent(VciLinkType.class)){
            VciLinkType linkType = modelClass.getDeclaredAnnotation(VciLinkType.class);
            if(linkType !=null){
                return linkType.name();
            }
        }
        String name = modelClass.getSimpleName();
        if(name.endsWith("DO")){
            name = name.substring(0,name.length()-2);
        }
        return name;
    }
 
    /**
     * 根据业务类型获取表格名称
     * @param btmname 业务类型,并且不能是视图
     * @return 数据库表格名称
     */
    public static String getTableName(String btmname) {
        return (VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY?"pbt_":"vcibt_") + btmname.trim().toLowerCase();
    }
 
    /**
     * 根据链接类型获取表格名称
     * @param linkName 链接类型
     * @return 数据库表格名称
     */
    public static String getLinkTableName(String linkName){
        return (VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY?"plt_":"vcilt_")+ linkName.trim().toLowerCase();
    }
 
    /**
     * 是否不是系统隐藏属性
     * @param fieldName 属性的名称
     * @return true表示不是隐藏
     */
    public static boolean isNotHiddenField(String fieldName){
        if("id".equalsIgnoreCase(fieldName) || "name".equalsIgnoreCase(fieldName) || "description".equalsIgnoreCase(fieldName)){
            return true;
        }
        if(VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(fieldName.toLowerCase())){
            return false;
        }
        if(VciQueryWrapperForDO.REVISION_MANAGE_FIELD_MAP.containsKey(fieldName.toLowerCase())){
            return false;
        }
        return true;
    }
 
    /**
     * 利用反射将map集合封装成bean对象
     * @param map map集合
     * @param clazz map集合所映射的bean对象
     * @return 映射对象
     */
    public static <T> T mapToBean(Map<String, String> map, Class<T> clazz) throws Exception {
        if(!CollectionUtils.isEmpty(map)){
            Map<String,String> dataMap = new ConcurrentHashMap<>();
            List<Field> allFieldForObj = getAllFieldForObj(clazz);
            allFieldForObj.parallelStream().forEach(field->{
                String key = map.keySet().stream().filter(s -> s.equalsIgnoreCase(field.getName())).findFirst().orElseGet(() -> null);
                if(StringUtils.isNotBlank(key)){
                    dataMap.put(field.getName(),map.get(key));
                }
            });
            return BeanUtil.toBeanIgnoreCase(dataMap, clazz, true);
        }
        return null;
    }
 
    /**
     * 使用freemarker替换值
     * @param freemarker 表达式
     * @param replaceMap 使用替换的数据源
     * @return 替换后的值
     */
    public static String replaceByFreeMarker(String freemarker,Map<String,Object> replaceMap){
        if(StringUtils.isBlank(freemarker)){
            return "";
        }
        freemarker = freemarker.replace("root.${","${").replace("sourceData.${","${");
        //先配置
        Configuration configuration = new Configuration(Configuration.VERSION_2_3_23);
        StringTemplateLoader templateLoader = new StringTemplateLoader();
        configuration.setTemplateLoader(templateLoader);
        configuration.setDefaultEncoding("UTF-8");
        try {
            Template template = new Template("temp",freemarker,configuration);
            StringWriter stringWriter = new StringWriter();
            template.process(replaceMap, stringWriter);
            return stringWriter.toString();
        } catch (IOException | TemplateException e) {
            throw new VciBaseException(e.getLocalizedMessage(),new String[0],e);
        }
    }
 
    /**
     * url的内容转换为参数
     * @param url 路径
     * @return 参数的格式
     */
    public static Map<String,String> getParamsByUrl(String url){
        if(StringUtils.isBlank(url)){
            return new HashMap<>();
        }
        String[] array = url.split("&");
        Map<String,String> params = new HashMap<>();
        for(String temp : array){
            if(temp.contains("=")){
                String[] keyValues = temp.split("=");
                params.put(keyValues[0],keyValues[1]);
            }else{
                params.put(temp,"");
            }
        }
        return params;
    }
 
    /**
     * 字符是否为中文
     * Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS : 4E00-9FBF:CJK 统一表意符号
     Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS :F900-FAFF:CJK 兼容象形文字
     Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A :3400-4DBF:CJK 统一表意符号扩展 A
     Character.UnicodeBlock.GENERAL_PUNCTUATION :2000-206F:常用标点
     Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION :3000-303F:CJK 符号和标点
     Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS :FF00-FFEF:半角及全角形式
     * @param c 字符
     * @return true 是中文
     * */
    public static boolean isChinese(char c){
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if(ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                ||ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                ||ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                ||ub == Character.UnicodeBlock.GENERAL_PUNCTUATION  // GENERAL_PUNCTUATION 判断中文的“号
                ||ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION     // CJK_SYMBOLS_AND_PUNCTUATION 判断中文的。号
                ||ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS    // HALFWIDTH_AND_FULLWIDTH_FORMS 判断中文的,号
        ) {
            return true;
        }
        return false;
    }
 
    /**
     * map不区分大小写判断
     * @param map 数据
     * @param key key
     * @return true表示存在
     */
    public static boolean containsKeyUnCaseForMap(Map map,String key){
        if(!CollectionUtils.isEmpty(map)){
            final boolean[] finded = {false};
            map.forEach((k,value)->{
                if(k instanceof String && k.toString().toLowerCase(Locale.ROOT).equalsIgnoreCase(key)){
                    finded[0] = true;
                    return;
                }
            });
            return finded[0];
        }
        return false;
    }
 
    /**
     * 是否为中文
     * @param str 字符串
     * @return true表示有中文
     */
    public static boolean isChinese(String str){
        char[] ch =  str.toCharArray();
        for (char c : ch) {
            if(isChinese(c)) {
                return true;
            }
        }
        return false;
    }
 
    /**
     * 全角转半角
     * @param input 转换前
     * @return 转换后
     */
    public static String toDBC(String input){
        if(StringUtils.isBlank(input)){
            return input;
        }
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if(c[i] == '\u3000'){
                c[i] = ' ';
            }else if(c[i] > '\uFF00' && c[i] < '\uFF5F'){
                c[i] = (char) (c[i]-65248);
            }
        }
        return new String(c);
    }
 
    /**
     * 半角转全角
     * @param input 转换前
     * @return 转换后
     */
    public static String toSBC(String input){
        if(StringUtils.isBlank(input)){
            return input;
        }
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if(c[i] == '\u3000'){
                c[i] = ' ';
            }else if(c[i] > '\uFF00' && c[i] < '\uFF5F'){
                c[i] = (char) (c[i] + 65248);
            }
        }
        return new String(c);
    }
 
    /**
     * 将string集合转为stirng数组
     * @param strCollection string集合
     * @return string数组
     */
    public static String[] collection2StrArr(Collection<String> strCollection){
        String[] strArr = new String[strCollection.size()];
        strCollection.toArray(strArr);
        return strArr;
    }
}