xiejun
2024-09-04 ac3f3629a261770f573f27e5e23f7ec19d096c2a
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
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
package com.vci.server.framework.delegate;
 
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
 
import com.vci.corba.common.VCIError;
import com.vci.corba.framework.data.CombinationInfo;
import com.vci.corba.framework.data.CombinationValueInfo;
import com.vci.corba.framework.data.DeptInfo;
import com.vci.corba.framework.data.PasswordStrategyInfo;
import com.vci.corba.framework.data.RoleInfo;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.UserInfo;
import com.vci.corba.framework.data.UserLogonInfo;
import com.vci.corba.log.data.LogType;
import com.vci.server.base.delegate.BaseDelegate;
import com.vci.server.base.delegate.UserEntityDelegate;
import com.vci.server.base.utility.LogHelper;
import com.vci.server.base.utility.LogRecordUtil;
import com.vci.server.cache.OrgCacheProvider;
import com.vci.server.common.ThreeDES;
import com.vci.server.framework.Logon.SessionInfo;
import com.vci.server.framework.cache.DeptCacheUtil;
import com.vci.server.framework.cache.RoleCacheUtil;
import com.vci.server.framework.cache.UserCacheUtil;
import com.vci.server.framework.interfac.SingleLogonInterface;
import com.vci.server.framework.interfac.TokenLogonInterface;
import com.vci.server.framework.systemConfig.stafforgmanage.combination.Combination;
import com.vci.server.framework.systemConfig.stafforgmanage.combination.CombinationService;
import com.vci.server.framework.systemConfig.stafforgmanage.combination.CombinationValue;
import com.vci.server.framework.systemConfig.stafforgmanage.combination.CombinationValueService;
import com.vci.server.framework.systemConfig.stafforgmanage.dept.Department;
import com.vci.server.framework.systemConfig.stafforgmanage.dept.DepartmentService;
import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategy;
import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategyService;
import com.vci.server.framework.systemConfig.stafforgmanage.role.Role;
import com.vci.server.framework.systemConfig.stafforgmanage.role.RoleService;
import com.vci.server.framework.systemConfig.stafforgmanage.session.VciSessionInfoDAOImpl;
import com.vci.server.framework.systemConfig.stafforgmanage.session.VciSessionInfoDO;
import com.vci.server.framework.systemConfig.stafforgmanage.user.User;
import com.vci.server.framework.systemConfig.stafforgmanage.user.UserLogon;
import com.vci.server.framework.systemConfig.stafforgmanage.user.UserService;
import com.vci.server.framework.utils.ObjectConvert;
import com.vci.common.log.ServerWithLog4j;
import com.vci.common.utility.ObjectUtility;
 
/**
 * <p>
 * Title:RightManagementDelegate
 * </p>
 * <p>
 * Description: 基础模块服务端delegate
 * </p>
 * <p>
 * Copyright: Copyright (c) 2012
 * </p>
 * <p>
 * Company: VCI
 * </p>
 * 
 * @author wangxl
 * @time 2012-5-9
 * @version 1.0
 */
public class RightManagementDelegate extends BaseDelegate {
 
    public RightManagementDelegate() {
 
    }
 
    public RightManagementDelegate(UserEntityInfo userEntityInfo) {
        super(userEntityInfo);
    }
 
    public UserInfo getUserObjectByUserName(String userName) throws VCIError {
        return OrgCacheProvider.getUser(userName);
//        UserInfo res = new UserInfo();
//        try {
//            User user = new UserService().getUserObjectByUserName(userName);
//
//            if (user != null) {
//                res = ObjectConvert.changeUserToUserInfo(user);
//            }
//        } catch (Exception e) {
//            throw new VCIError("120406", new String[0]);
//        }
//
//        return res;
    }
 
    /**
     * 通过token验证登录,token的解密根据企业提供的算法进行自定义
     * 
     * @param token
     * @return
     * @throws VCIError
     */
    public UserInfo loginByToken(String token) throws VCIError {
        String tokenClass = new SystemCfgDelegate().getConfigValue("tokenLogonClass");
 
        UserInfo res = new UserInfo();
        try {
            if (tokenClass != null && !tokenClass.equals("")) {
                Class<?> cls = Class.forName(tokenClass);
                if (cls == null)
                    return new UserInfo();
 
                TokenLogonInterface logon = (TokenLogonInterface) cls.getConstructor().newInstance();
                if (logon == null)
                    return new UserInfo();
 
                String userName = logon.verifyToken(token);
                if (userName == null || userName.isEmpty()) {
                    return new UserInfo();
                }
 
                res = fetchUserInfoByName(userName);
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120406", new String[0]);
        } catch (Throwable e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120406", new String[0]);
        }
 
        return res;
    }
 
    /**
     * <p>
     * Description: 验证用户登录
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-21
     * @param userName
     * @param password
     * @return
     * @throws VCIError
     */
    public UserInfo checkLogin(String userName, String password) throws VCIError {
        UserInfo res = new UserInfo();
        try {
            //if (!isSuperUser(userName)) {
            String logonClass = new SystemCfgDelegate().getConfigValue("logonClass");
            if (logonClass != null && !logonClass.equals("")) {
                Class<?> cls = Class.forName(logonClass);
                SingleLogonInterface logon = (SingleLogonInterface) cls.getConstructor().newInstance();
                boolean rs = logon.verifyUserExist(userName, password);
                if (rs == true) {
                    res = fetchUserInfoByName(userName);
                }
                return res;
            } else {
//                ThreeDES des = new ThreeDES();// 实例化一个对�?
//                des.getKey("daliantan0v0");// 生成密匙
//                password = des.getEncString(password);
            }
            //}
//            User user = new UserService().checkLogin(userName, password);
//            if (user != null) {
//                res = ObjectConvert.changeUserToUserInfo(user);
//
//                // LogRecordUtil.writeLog(userEntity, "登陆", "登陆成功", LogType.Login, "");
//            }
                
            UserInfo ui = fetchUserInfoByName(userName);
            if (ui != null && ui.status == 0 && ui.pwd.equals(password)) {
                res = ui;
                LogRecordUtil.saveLoginLog(true, "登陆成功", userEntityInfo);
            } else {
                //System.out.println("===========用户=" + res.userName + "; 状态=" + res.status);
                // else
                LogRecordUtil.saveLogoutLog("登陆失败", userEntityInfo);
            }
 
        } catch (Exception e) {
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120406", new String[0]);
        } catch (Throwable e) {
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120406", new String[0]);
        }
 
        return res;
    }
 
    /**
     * 校验是否可以登录,并且返回token的信息
     * 
     * @param userName      用户名
     * @param password      密码
     * @param checkPassword 是否校验密码
     * @return token的信息
     */
//    public String checkLoginForToken(LoginInfoDTO loginDTO) throws VCIError {
//        if (StringUtils.isBlank(loginDTO.getUserId())) {
//            throw new VCIError("用户名为空", new String[0]);
//        }
//        if (loginDTO.isCheckPassword() && StringUtils.isBlank(loginDTO.getPassword())) {
//            throw new VCIError("密码为空", new String[0]);
//        }
//        try {
//            boolean success = false;
//            if (!isSuperUser(loginDTO.getUserId())) {
//                String logonClass = new SystemCfgDelegate().getConfigValue("logonClass");
//                if (logonClass != null && !logonClass.equals("")) {
//                    Class<?> cls = Class.forName(logonClass);
//                    SingleLogonInterface logon = (SingleLogonInterface) cls.getConstructor().newInstance();
//                    success = logon.verifyUserExist(loginDTO.getUserId(), loginDTO.getPassword());
//                } else {
//                    if (loginDTO.isCheckPassword()) {
//                        ThreeDES des = new ThreeDES();// 实例化一个对�?
//                        des.getKey("daliantan0v0");// 生成密匙
//                        loginDTO.setPassword(des.getEncString(loginDTO.getPassword()));
//                    }
//                }
//            }
//            if (!success) {
//                User user = null;
//                PasswordStrategy pwdStrategy = null;
//                if (loginDTO.isCheckPassword()) {
//                    user = new UserService().checkLogin(loginDTO.getUserId(), loginDTO.getPassword());
//                } else {
//                    // 单点登录的时候
//                    user = new UserService().getUserObjectByUserName(loginDTO.getUserId());
//                }
//                if (user == null || StringUtils.isBlank(user.getId())) {
//                    if (loginDTO.isCheckPassword()) {
//                        // 要记录密码错误次数
//                        user = new UserService().getUserObjectByUserName(loginDTO.getUserId());
//                        if (user == null || StringUtils.isBlank(user.getId())) {
//                            throw new VCIError("用户名不存在", new String[0]);
//                        }
//                        pwdStrategy = new PasswordStrategyService().getPasswordObjByUserId(user.getId());
//                        if (pwdStrategy == null) {
//                            throw new VCIError("密码安全策略为空", new String[0]);
//                        }
//                        // 查询用户错误信息的信息
//                        updateLogonInfo(loginDTO.getUserId().trim(), false);
//                    }
//                    throw new VCIError("用户的密码不正确", new String[0]);
//                }
//                // 查询密码安全策略
//                if (pwdStrategy == null) {
//                    pwdStrategy = new PasswordStrategyService().getPasswordObjByUserId(user.getId());
//                }
//                if (pwdStrategy == null) {
//                    throw new VCIError("密码安全策略为空", new String[0]);
//                }
//                // 看看用户是否被锁定着的
//                if (!"0".equals(user.getStatus())) {
//                    throw new VCIError("用户已经停用", new String[0]);
//                }
//                // 通过登录信息看看现在是否已经超过要求了
//                UserService userSrv = new UserService();
//                UserLogon userLogon = userSrv.getUserLogonObj(user.getId());
//                if (userLogon.getPlWrongNum() >= pwdStrategy.getRetryTime()) {
//                    throw new VCIError("用户已经停用", new String[0]);
//                }
//                // 密码正确的时候,需要更新密码错误的次数
//                userLogon.setPlWrongNum((short)0);
//
//                SessionInfo sessionInfo = new SessionInfo();
//                // 拷贝信息到
//                copyUser2SessionInfo(user, sessionInfo, loginDTO.getLangCode());
//                copyRequest2SessionInfo(loginDTO, sessionInfo);
//                // 查询所有的角色
//                RoleInfo[] roleInfos = fetchRoleInfoByUserId(user.getId());
//
//                if (roleInfos != null && roleInfos.length > 0) {
//                    Map<String, String> roleOidNameMap = new HashMap<String, String>();
//                    for (RoleInfo role : roleInfos) {
//                        roleOidNameMap.put(role.id, role.name);
//                    }
//                    sessionInfo.setRolesName(roleOidNameMap);
//
//                } else {
//                    sessionInfo.setRolesName(new HashMap<String, String>());
//                }
//                List<RoleRight> roleRights = new RoleRightService()
//                        .getFunctionRoleRightByUserName(loginDTO.getUserId());
//                if (roleRights != null && roleRights.size() > 0) {
//
//                    List<String> functionOidList = new ArrayList<String>();
//                    for (RoleRight roleRight : roleRights) {
//                        functionOidList.add(roleRight.getFuncId());
//                    }
//                    sessionInfo.setFunctionOids(functionOidList);
//                } else {
//                    sessionInfo.setFunctionOids(new ArrayList<String>());
//                }
//
//                // 检查是否该修改密码
//                if (!loginDTO.isSso() && loginDTO.isCheckPassword()) {
//                    // 最后修改时间+ 失效时间,大于等于当前日期,则需要马上修改密码
//                    Timestamp lastUpdateTime = user.getPwdUpdateTime();
//                    if (lastUpdateTime == null) {
//                        // 重来没有登录过
//                        sessionInfo.setMustChangePassword(true);
//                        sessionInfo.setPasswordTips("您是首次登录系统,请修改密码");
//                    }
//                    int remindDay = pwdStrategy.getOverdueDay() - pwdStrategy.getRemideDay();
//                    long oneDay = 24 * 60 * 60 * 1000;
//                    Long needRemindTime = lastUpdateTime.getTime() + remindDay * oneDay;
//                    Long invalidTime = lastUpdateTime.getTime() + pwdStrategy.getOverdueDay() * oneDay;
//                    Long currentTime = System.currentTimeMillis();
//                    if (currentTime > needRemindTime && currentTime < invalidTime) {
//                        Long balanceTime = invalidTime - currentTime;
//                        Long balanceDay = ((balanceTime - balanceTime % oneDay) / oneDay) + 1;
//                        sessionInfo.setPasswordTips("您的密码还有" + balanceDay + "天过期");
//                    }
//                    if (currentTime >= invalidTime) {
//                        sessionInfo.setMustChangePassword(true);
//                        sessionInfo.setPasswordTips("您的密码已经过期,请立即修改");
//                    }
//                }
//
//                userLogon.setPlLogonTime(Timestamp.valueOf(System.currentTimeMillis() + ""));
//                ThreeDES des = new ThreeDES();// 实例化一个对�?
//                des.getKey(UUID.randomUUID().toString());// 生成密匙
//                sessionInfo.setToken(des.getEncString(user.getId()));
//                updateLogonInfo(loginDTO.getUserId().trim(), true);
//                VciSessionInfoDO sessionInfoDO = new VciSessionInfoDO();
//                sessionInfoDO.setToken(sessionInfo.getToken());
//                sessionInfoDO.setLastRequestTime(System.currentTimeMillis());
//                sessionInfoDO.setUserId(loginDTO.getUserId());
//                sessionInfoDO.setJsonString(JSON.toJSONString(sessionInfo));
//                sessionInfoDao.save(sessionInfoDO);
//                return sessionInfo.getToken();
//            }
//            // else
//            // LogRecordUtil.writeLog(userEntity, "登陆", "登陆失败", LogType.Login, "");
//
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//            throw new VCIError("120406", new String[0]);
//        } catch (Throwable e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//            throw new VCIError("120406", new String[0]);
//        }
//        return null;
//    }
 
    /**
     * 拷贝用户的信息到 会话信息
     * 
     * @param user        用户对象
     * @param sessionInfo 会话对象
     * @param langCode    语言编码
     */
    private void copyUser2SessionInfo(User user, SessionInfo sessionInfo, String langCode) {
        sessionInfo.setUserOid(user.getId());
        sessionInfo.setUserId(user.getUserName());
        sessionInfo.setUserName(user.getTrueName());
        sessionInfo.setUsertype(user.getUserType() + "");
        sessionInfo.setUsertypeText("");
        sessionInfo.setUserSecret(user.getSecretGrade() == null ? "" : (user.getSecretGrade() + ""));
        sessionInfo.setUserSecretText("");
        sessionInfo.setSex("");
        sessionInfo.setSexText("");
        // sessionInfo.setPhotoUrl(user.getPhoto());
        sessionInfo.setLanguage("");
        if (StringUtils.isNotBlank(langCode)) {
            // 传递了要显示的语言
            sessionInfo.setLanguage(langCode);
        }
        DeptInfo deptInfo = null;
        try {
            deptInfo = fetchDeptByUserId(user.getId());
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        // sessionInfo.setPersonOid(user.getPkPerson());
        // sessionInfo.setPersonName(user.getPkPersonName());
        if (deptInfo != null) {
            sessionInfo.setDeptOid(deptInfo.id);
            sessionInfo.setDeptName(deptInfo.name);
        }
        // sessionInfo.setDutyOid(user.getPkDuty());
        // sessionInfo.setDutyName(user.getPkDutyName());
        sessionInfo.setEmail(user.getEmail());
        // sessionInfo.setPhoneNo(user.getTel());
        // sessionInfo.setRtxNo(user.getRtxNo());
        // sessionInfo.setIMId(user.getIMNo());
        sessionInfo.setPortalId(user.getId());
 
//        sessionInfo.setWorkNo(user.getWorkNo());
//        sessionInfo.setWorkTypeOid(user.getPkWorkType());
//        sessionInfo.setWorkTypeName(user.getPkWorkTypeText());
    }
 
    /**
     * 拷贝请求的信息到会话信息中
     * 
     * @param clientInfo  请求信息
     * @param sessionInfo 会话信息
     */
//    private void copyRequest2SessionInfo(LoginInfoDTO loginInfoDTO, SessionInfo sessionInfo) {
//        sessionInfo.setIp(loginInfoDTO.getIpAddress());
//        // ip的地址在controller里设置
//        sessionInfo.setOs(loginInfoDTO.getOsVersion());
//        sessionInfo.setBrowser(loginInfoDTO.getBrowserVersion());
//        sessionInfo.setSso(loginInfoDTO.isSso());
//        sessionInfo.setSsoServiceName(loginInfoDTO.getSsoSystemName());
//    }
 
    /**
     * 判断用户是否为超级用户
     * 
     * @param userName
     * @return
     */
    private boolean isSuperUser(String userName) {
        try {
            SystemCfgDelegate conf = new SystemCfgDelegate();
            String userNameAdmin = conf.getConfigValue("user.admin");
            String userNameDeveloper = conf.getConfigValue("user.developer");
            String userNameRoot = conf.getConfigValue("user.rooter");
            if (userName.equals(userNameAdmin) || userName.equals(userNameDeveloper) || userName.equals(userNameRoot)) {
                return true;
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return false;
    }
 
    /**
     * <p>
     * Description: 验证用户登录
     * </p>
     * 
     * @param userName
     * @param password
     * @return
     * @throws VCIError
     */
    public UserInfo checkLoginForBS(String userName, String password) throws VCIError {
        return checkLogin(userName, password);
    }
 
    /**
     * <p>
     * Description:用于验证角色是否被引�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @return
     * @throws VCIError
     */
    public int checkRoleIsquotedCount(String id) throws VCIError {
        int count = 0;
        try {
            count = new RoleService().checkRoleIsquotedCount(id);
        } catch (Exception e) {
            throw new VCIError("120307", new String[0]);
        }
        return count;
    }
 
    /**
     * <p>
     * Description: 获取所有部�?/p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @return
     * @throws VCIError
     */
    public DeptInfo[] fetchDepartmentInfo() throws VCIError {
        return OrgCacheProvider.getDepts();
//        List<Department> list = null;
//        try {
//            list = new DepartmentService().getDepartmentList();
//        } catch (Exception e) {
//            throw new VCIError("120101", new String[0]);
//        }
//        return changeDepartmentToDepartmentInfos(list);
    }
 
    public DeptInfo[] fetchDeptByUserNames(String[] userNames) throws VCIError {
        List<Department> list = null;
        try {
            list = new DepartmentService().fetchDeptByUserNames(userNames);
        } catch (Exception e) {
            throw new VCIError("120101", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    /**
     * <p>
     * Description:根据Id获取部门
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @return
     * @throws VCIError
     */
    public DeptInfo fetchDepartmentInfoById(String id) throws VCIError {
        return OrgCacheProvider.getDepartment(id);
//        Department depart = null;
//        try {
//            depart = new DepartmentService().selectDepartmentById(id);
//        } catch (Exception e) {
//            throw new VCIError("120104", new String[0]);
//        }
//        return ObjectConvert.changeDepartmentToDepartmentInfo(depart);
    }
 
    public DeptInfo fetchManageDept(String rmTypeId) throws VCIError {
        DeptInfo info = new DeptInfo();
        Department depart = null;
        try {
            depart = new DepartmentService().fetchManageDept(rmTypeId);
            if (depart != null) {
                info = ObjectConvert.changeDepartmentToDepartmentInfo(depart);
            }
        } catch (Exception e) {
            throw new VCIError("120104", new String[0]);
        }
        return info;
    }
 
    public DeptInfo fetchManageOfMaterialsDept(String rmTypeId) throws VCIError {
        DeptInfo info = new DeptInfo();
        Department depart = null;
        try {
            depart = new DepartmentService().fetchManageOfMaterialsDept(rmTypeId);
            if (depart != null) {
                info = ObjectConvert.changeDepartmentToDepartmentInfo(depart);
            }
        } catch (Exception e) {
            throw new VCIError("120104", new String[0]);
        }
        return info;
    }
 
    public DeptInfo fetchDeptByUserId(String userId) throws VCIError {
        Department depart = null;
        DeptInfo info = new DeptInfo();
        try {
            depart = new DepartmentService().fetchDeptByUserId(userId);
            if (depart != null) {
                info = ObjectConvert.changeDepartmentToDepartmentInfo(depart);
            }
        } catch (Exception e) {
            throw new VCIError("120104", new String[0]);
        }
        return info;
 
    }
 
    public DeptInfo fetchDeptByDeptName(String deptName) throws VCIError {
        Department depart = null;
        DeptInfo info = new DeptInfo();
        try {
            depart = new DepartmentService().selectDepartmentByName(deptName);
            if (depart != null) {
                info = ObjectConvert.changeDepartmentToDepartmentInfo(depart);
            }
        } catch (Exception e) {
            throw new VCIError("120104", new String[0]);
        }
        return info;
 
    }
 
    public DeptInfo fetchDeptByParentIdAndName(String parentId, String deptName) throws VCIError {
        Department depart = null;
        DeptInfo info = new DeptInfo();
        try {
            depart = new DepartmentService().fetchDeptByParentIdAndName(parentId, deptName);
            if (depart != null) {
                info = ObjectConvert.changeDepartmentToDepartmentInfo(depart);
            }
        } catch (Exception e) {
            throw new VCIError("120104", new String[0]);
        }
        return info;
 
    }
 
    /**
     * <p>
     * Description:获取根节点部�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @return
     * @throws VCIError
     */
    public DeptInfo[] fetchDepartmentInfoRoot() throws VCIError {
        List<?> list = null;
        try {
            list = new DepartmentService().getDepartmentListByFilter(true, "");
            Collections.sort(list, new DeptNameComparator());
        } catch (Exception e) {
            throw new VCIError("120105", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    /**
     * <p>
     * Description: 返回下级部门
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param prtoid
     * @return
     * @throws VCIError
     */
    public DeptInfo[] fetchDepartmentInfoByParentId(String prtoid) throws VCIError {
        List<?> list = null;
        try {
            list = new DepartmentService().getDepartmentListByFilter(false, prtoid);
        } catch (Exception e) {
            throw new VCIError("120106", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    /**
     * <p>
     * Description:根据Id返回部门及其子部�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @return
     * @throws VCIError
     */
    public DeptInfo[] fetchDepartmentInfosById(String id) throws VCIError {
        List<?> list = null;
        try {
            list = new DepartmentService().getDepartmentListById(id);
        } catch (Exception e) {
            throw new VCIError("120107", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    public DeptInfo[] fetchDepartmentInfosBySonId(String id) throws VCIError {
        List<?> list = null;
        try {
            list = new DepartmentService().getDepartmentListBySonId(id);
        } catch (Exception e) {
            throw new VCIError("120107", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    public RoleInfo fetchRoleInfoById(String roleId) throws VCIError {
        return OrgCacheProvider.getRole(roleId);
//        Role role = new RoleService().selectRole(roleId);
//        return ObjectConvert.changeRoleToRoleInfo(role);
    }
 
    public RoleInfo fetchRoleByName(String name) throws VCIError {
        return OrgCacheProvider.getRoleByName(name);
//        Role role = new RoleService().selectRoleByName(name);
//        return ObjectConvert.changeRoleToRoleInfo(role);
    }
 
    /**
     * <p>
     * Description:获取所有角�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @return
     * @throws VCIError
     */
    public RoleInfo[] fetchRoleInfo() throws VCIError {
        return OrgCacheProvider.getRoles();
//        List<Role> list = null;
//        try {
//            list = new RoleService().getRoleList();
//        } catch (Exception e) {
//            throw new VCIError("120301", new String[0]);
//        }
//        int size = list.size();
//        RoleInfo[] roleInfo = new RoleInfo[size];
//        for (int i = 0; i < size; i++) {
//            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo(list.get(i));
//        }
//        return roleInfo;
    }
 
    /**
     * <p>
     * Description:根据类型获取角色
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param type
     * @return
     * @throws VCIError
     */
    public RoleInfo[] fetchRoleInfoByType(int type) throws VCIError {
        List<?> list = null;
        try {
            list = new RoleService().getRoleListByType(type);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i));
        }
        return roleInfo;
    }
 
    /**
     * <p>
     * Description:根据角色类型获取角色
     * </p>
     * 
     * @author liujw
     * @time 2013-5-20
     * @param type
     * @return
     * @throws VCIError
     */
    public RoleInfo[] fetchRoleInfoByRoleType(int type) throws VCIError {
        List<?> list = null;
        try {
            list = new RoleService().getRoleByRoleType(type);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i));
        }
        return roleInfo;
    }
 
    /**
     * 设备送检角色查询
     * 
     * @param type
     * @return
     * @throws VCIError
     */
    public RoleInfo[] getRoleListByTypeForMeasure(int type) throws VCIError {
        List<?> list = null;
        try {
            list = new RoleService().getRoleListByTypeForMeasure(type);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i));
        }
        return roleInfo;
    }
 
    /**
     * <p>
     * Description: 获取用户的角�?/p>
     * 
     * @author wangxl
     * @time 2012-5-11
     * @param userId
     * @return
     * @throws VCIError
     */
    public RoleInfo[] fetchRoleInfoByUserId(String userId) throws VCIError {
        List<?> list = null;
        try {
            list = new RoleService().getRoleListByUserId(userId);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i));
        }
        return roleInfo;
    }
 
    public RoleInfo[] fetchRoleInfoByUserName(String userName) throws VCIError {
        List<?> list = null;
        try {
            list = new RoleService().getRoleListByUserName(userName);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i));
        }
        return roleInfo;
    }
 
    public RoleInfo[] fetchRoleInfoByUserType(String userType) throws VCIError {
        List<?> list = null;
        try {
            list = new RoleService().getRoleListByUserType(userType);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo((Role)list.get(i));
        }
        return roleInfo;
    }
 
    @SuppressWarnings("unchecked")
    public RoleInfo[] fetchRoleInfoByUserName(int pageNo, int pageSize, String userName) throws VCIError {
        List<Role> list = null;
        try {
            list = new RoleService().getRoleListByUserName(pageNo, pageSize, userName);
        } catch (Exception e) {
            throw new VCIError("120302", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo(list.get(i));
        }
        return roleInfo;
    }
 
    public int getRoleTotalByUserName(String userName) throws VCIError {
        int total = 0;
        try {
            total = new RoleService().getRoleTotalByUserName(userName);
        } catch (Exception e) {
            throw new VCIError("120308", new String[0]);
        }
        return total;
    }
 
    /**
     * <p>
     * Description:获取所有人�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @return
     * @throws VCIError
     */
    //@SuppressWarnings("unchecked")
    public UserInfo[] fetchUserInfo() throws VCIError {
        return OrgCacheProvider.getUsers();
//        List<User> list = null;
//        try {
//            list = new UserService().getUserList();
//        } catch (Exception e) {
//            throw new VCIError("120401", new String[0]);
//        }
//        int size = list.size();
//        UserInfo[] userInfo = new UserInfo[size];
//        for (int i = 0; i < size; i++) {
//            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
//        }
//        return userInfo;
    }
 
    /**
     * <p>
     * Description:获取除admin,developer,三员外的所有普通人�?
     * </p>
     * 
     * @author liujw
     * @time 2013-5-7
     * @return
     * @throws VCIError
     */
    //@SuppressWarnings("unchecked")
    public UserInfo[] fetchUserInfoWithOutSanYuan() throws VCIError {
        List<?> list = null;
        try {
            list = new UserService().getUserListWithOutSanYuan();
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i));
        }
        return userInfo;
    }
 
    /**
     * <p>
     * Description:根据条件查询人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param name
     * @param userName
     * @param companyId
     * @param roleId
     * @param userType
     * @param empNo
     * @return
     * @throws VCIError
     */
    public UserInfo[] fetchUserInfoByCondition(String searchName, String searchUserName, String deptId, String roleId,
            String userName, int pageNo, int pageSize) throws VCIError {
        List<?> list = null;
        try {
            
            boolean bSuper = isSuperUser(userName);
            
            //System.out.print("=============bSuper=" + bSuper);
            
            list = new UserService().getUserListByCondition(searchName, searchUserName, deptId, roleId, userName,
                    pageNo, pageSize, !bSuper);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i));
        }
        return userInfo;
    }
 
    // add by caill start 2016.9.26
    public UserInfo[] fetchUserInfoByConditionUnited(String searchName, String searchUserName, String deptId,
            String roleId, String userName, int pageNo, int pageSize) throws VCIError {
        List<?> list = null;
        try {
            boolean bSuper = isSuperUser(userName);
 
            list = new UserService().getUserListByConditionUnited(searchName, searchUserName, deptId, roleId, userName,
                    pageNo, pageSize, !bSuper);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i));
        }
        return userInfo;
    }
    // add by caill end
 
    public int getUserTotalByCondition(String searchName, String searchUserName, String deptId, String roleId,
            String userName) throws VCIError {
        int total = 0;
        try {
            total = new UserService().getUserTotalByCondition(searchName, searchUserName, deptId, roleId, userName,
                    false);
        } catch (Exception e) {
            throw new VCIError("120413", new String[0]);
        }
        return total;
    }
 
    /**
     * <p>
     * Description:根据类型获取人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param type
     * @return
     * @throws VCIError
     */
    public UserInfo[] fetchUserInfoByType(int type) throws VCIError {
        List<?> list = null;
        try {
            list = new UserService().getUserListByType(type);
        } catch (Exception e) {
            throw new VCIError("120402", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo((User)list.get(i));
        }
        return userInfo;
    }
 
    /**
     * <p>
     * Description:根据用户名查找人�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param userName
     * @return
     * @throws VCIError
     */
    public UserInfo fetchUserInfoByName(String userName) throws VCIError {
        return OrgCacheProvider.getUser(userName);
//        UserInfo res = new UserInfo();
//        try {
//            User user = new UserService().selectUserByName(userName);
//            if (user == null) {
//                user = new User();
//            }
//            res = ObjectConvert.changeUserToUserInfo(user);
//
//        } catch (Exception e) {
//            throw new VCIError("120401", new String[0]);
//        }
//        return res;
    }
 
    /**
     * <p>
     * Description: 根据角色和类型查找人�?/p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param roleId
     * @param type
     * @return
     * @throws VCIError
     */
    public UserInfo[] fetchUserInfoByRoleId(String roleId, int type) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().fetchUserInfoByRoleId(roleId, type);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
    public UserInfo[] fetchUsersByRoleId(String roleId) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().fetchUsersByRoleId(roleId);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
    public UserInfo[] fetchUserInfoByDeptAndRole(String[] deptIds, String[] roleIds) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().fetchUserInfoByDeptAndRole(deptIds, roleIds);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
    /**
     * <p>
     * Description: 根据角色Id获取人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-11
     * @param roleId
     * @return
     */
    public UserInfo[] selectUserByRoleId(String roleId) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().selectUserByRoleId(roleId);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
    /**
     * <p>
     * Description:保存人员与文件柜的关�?
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-11
     * @param roleId
     * @param userIds
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
//    public boolean savePvolumeUser(String pvolumeId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError {
//        boolean rs = true;
//        UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
//        try {
//            PvolumeService pvolumeService = new PvolumeService();
//            UserService userService = new UserService();
//            UserEntityDelegate.setUserEntityToService(pvolumeService, userEntityInfo);
//            rs = pvolumeService.savePvolumUser(pvolumeId, userIds);
//            StringBuilder log = null;
//            Pvolume pvolume = pvolumeService.selectPvolume(pvolumeId);
//            for (String id : userIds) {
//                log = new StringBuilder();
//                log.append(pvolume.getLogInfo() + "->");
//                log.append("用户名:");
//                User user = (User) userService.getUserInfoList(id).get(0);
//                log.append("[" + user.getUserName() + "]");
//                LogRecordUtil.writeLog(userEntity, "向文件柜分配成员", "成功", log.toString(), LogType.General,
//                        pvolume.getId());
//            }
//        } catch (Exception e) {
//            throw new VCIError("120306", new String[0]);
//        }
//
//        return rs;
//    }
 
    /**
     * <p>
     * Description:保存人员与角色的关系
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-11
     * @param roleId
     * @param userIds
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean saveRight(String roleId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        //UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            RoleService roleService = new RoleService();
            UserService userService = new UserService();
 
//            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo);
 
            List<?> lstUser = userService.fetchUserInfoByRoleId(roleId, 1);
            rs = roleService.saveRight(roleId, userIds);
 
            Role role = roleService.selectRole(roleId);
 
            // List<String> lstUserID = Arrays.asList(userIds);
            List<String> lstUserID = new ArrayList<String>();
            for (String id : userIds) {
                lstUserID.add(id);
            }
            List<User> lstDel = new ArrayList<User>();
            for (int i = 0; i < lstUser.size(); i++) {
                User user = (User) lstUser.get(i);
                if (lstUserID.contains(user.getId()))
                    lstUserID.remove(user.getId());
                else
                    lstDel.add(user);
            }
 
            StringBuilder log = null;
            // 增加的人员
            for (String id : lstUserID) {
                log = new StringBuilder();
                log.append(role.getLogInfo() + "->[增加用户]->");
                // log.append("用户:");
                User user = (User) userService.getUserInfoList(id).get(0);
                log.append("[" + user.getUserName() + "(" + user.getTrueName() + ")]");
                LogRecordUtil.writeLog(userEntityInfo, "角色增加成员", "成功", log.toString(), LogType.General, role.getId());
            }
 
            // 删除的人员
            for (User u : lstDel) {
                log = new StringBuilder();
                log.append(role.getLogInfo() + "->[减少用户]->");
                // log.append("用户:");
                log.append("[" + u.getUserName() + "(" + u.getTrueName() + ")]");
                LogRecordUtil.writeLog(userEntityInfo, "角色减少成员", "成功", log.toString(), LogType.General, role.getId());
            }
 
//            for(String id : userIds){
//                log = new StringBuilder();
//                log.append(role.getLogInfo()+"->");
//                log.append("用户名:");
//                User user = (User)userService.getUserInfoList(id).get(0);
//                log.append("["+user.getUserName()+"]");
//                LogRecordUtil.writeLog(userEntity, "向角色分配成员", log.toString(), LogType.General, role.getId());
//            }
            // LogRecordUtil.writeLog(userEntity, "向角色分配成员", role.getLogInfo() + ",角色发生变化",
            // LogType.General, role.getId());
        } catch (Exception e) {
            throw new VCIError("120306", new String[0]);
        }
 
        return rs;
    }
 
    /**
     * 保存三员与成员之间的关系
     * 
     * @param roleId
     * @param userIds
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean saveSpecialRole(String roleId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            RoleService roleService = new RoleService();
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo);
 
            List<?> lstUser = userService.fetchUserInfoByRoleId(roleId, 1);
 
            rs = roleService.saveSpecialRole(roleId, userIds);
 
            Role role = roleService.selectRole(roleId);
 
            // List<String> lstUserID = Arrays.asList(userIds);
            List<String> lstUserID = Arrays.asList(userIds);// ArrayList<String>();
 
            List<User> lstDel = new ArrayList<User>();
            for (int i = 0; i < lstUser.size(); i++) {
                User user = (User) lstUser.get(i);
                if (lstUserID.contains(user.getId()))
                    lstUserID.remove(user.getId());
            }
 
            StringBuilder log = null;
            // 增加的人员
            for (String id : lstUserID) {
                log = new StringBuilder();
                log.append(role.getLogInfo() + "->[增加用户]->");
                // log.append("用户:");
                User user = (User) userService.getUserInfoList(id).get(0);
                log.append("[" + user.getUserName() + "(" + user.getTrueName() + ")]");
                LogRecordUtil.writeLog(userEntityInfo, "角色增加成员", "成功", log.toString(), LogType.General, role.getId());
            }
 
 
//            for(String id : userIds){
//                log = new StringBuilder();
//                log.append(role.getLogInfo()+"->");
//                log.append("用户名:");
//                User user = (User)userService.getUserInfoList(id).get(0);
//                log.append("["+user.getUserName()+"]");
//                LogRecordUtil.writeLog(userEntity, "角色分配成员", log.toString(), LogType.General,role.getId());
//            }
        } catch (Exception e) {
            throw new VCIError("120306", new String[0]);
        }
 
        return rs;
    }
 
    /**
     * <p>
     * Description:保存部门和人员的关系
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-15
     * @param deptId
     * @param userIds
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean saveRighForDept(String deptId, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            DepartmentService deptService = new DepartmentService();
 
            UserService userService = new UserService();
            List<?> lstUser = userService.getUserByDeptId(deptId);
 
            UserEntityDelegate.setUserEntityToService(deptService, userEntityInfo);
            rs = deptService.saveRight(deptId, userIds);
            // Department depart = deptService.selectDepartmentById(deptId);
 
            List<String> lstUserID = new ArrayList<String>();
            for (String id : userIds) {
                lstUserID.add(id);
            }
 
            List<User> lstDel = new ArrayList<User>();
            for (int i = 0; i < lstUser.size(); i++) {
                User user = (User) lstUser.get(i);
                if (lstUserID.contains(user.getId()))
                    lstUserID.remove(user.getId());
                else
                    lstDel.add(user);
            }
 
            String deptPath = this.getDepartmentPath(deptId);
 
            StringBuilder log = null;
            // 增加的人员
            for (String id : lstUserID) {
                log = new StringBuilder();
                log.append("[").append(deptPath).append("]->[增加用户]->");
                // log.append("用户:");
                User user = (User) userService.getUserInfoList(id).get(0);
                log.append("[" + user.getUserName() + "(" + user.getTrueName() + ")]");
                LogRecordUtil.writeLog(userEntityInfo, "部门增加成员", "成功", log.toString(), LogType.General, deptId);
            }
 
            // 删除的人员
            for (User u : lstDel) {
                log = new StringBuilder();
                log.append("[").append(deptPath).append("]->[减少用户]->");
                // log.append("用户:");
                log.append("[" + u.getUserName() + "(" + u.getTrueName() + ")]");
                LogRecordUtil.writeLog(userEntityInfo, "部门减少成员", "成功", log.toString(), LogType.General, deptId);
            }
        } catch (Exception e) {
            throw new VCIError("120111", new String[0]);
        }
 
        return rs;
    }
 
    public boolean saveRights(String[] roleIds, String[] userIds, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            RoleService roleService = new RoleService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
 
            StringBuilder log = null;
 
            for (String userId : userIds) {
                log = new StringBuilder();
                log.append("用户名:");
                rs = userService.saveRights(roleIds, userId);
                List list = userService.getUserInfoList(userId);
                if (list != null) {
                    log.append(((User) list.get(0)).getUserName() + "");
                }
                log.append("->");
                for (String roleId : roleIds) {
                    Role role = roleService.selectRole(roleId);
                    LogRecordUtil.writeLog(userEntityInfo, "成员分配角色", "成功", log.toString() + "[" + role.getName() + "]",
                            LogType.General, "角色ID:" + roleId + " 用户ID:" + userId);
                }
            }
 
        } catch (Exception e) {
            throw new VCIError("120111", new String[0]);
        }
 
        return rs;
    }
 
    public boolean saveUserDept(String[] userIds, String deptId, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            DepartmentService departmentService = new DepartmentService();
 
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
 
            StringBuilder log = null;
            // Department dept = departmentService.selectDepartmentById(deptId);
 
            String deptPath = getDepartmentPath(deptId);
            log = new StringBuilder();
            for (String userId : userIds) {
                log.setLength(0);
 
                List<?> list = userService.getUserInfoList(userId);
                if (list != null && list.size() >= 1) {
                    Department old = departmentService.fetchDeptByUserId(userId);
                    if (old != null && old.getId().equalsIgnoreCase(deptId))
                        continue;
 
                    User user = (User) list.get(0);
                    rs = userService.saveUserDept(userId, deptId);
 
                    log.append("用户").append("[" + user.getUserName() + "(" + user.getTrueName() + ")]:");
 
                    if (old != null) {
                        log.append("[" + getDepartmentPath(old.getId()) + "]->");
                    }
                    log.append("[").append(deptPath).append("]");
                    // log.append("["+user.getUserName()+"]");
                }
                LogRecordUtil.writeLog(userEntityInfo, "用户分配部门", "成功", log.toString(), LogType.General,
                        "部门ID:" + deptId + " 用户id:" + userId);
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120111", new String[0]);
        }
 
        return rs;
    }
 
    /**
     * 获取指定部门的全路径
     * 
     * @param deptId
     * @return
     */
    private String getDepartmentPath(String deptId) {
        StringBuilder sbDepName = new StringBuilder();
        try {
            DeptInfo[] depts = fetchDepartmentInfosBySonId(deptId);
 
            for (int i = depts.length - 1; i >= 0; i--) {
                if (sbDepName.length() > 0)
                    sbDepName.append("-");
                sbDepName.append(depts[i].name);
            }
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
 
        return sbDepName.toString();
    }
 
    /**
     * <p>
     * Description: 保存部门
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param departmentInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public String saveDepartment(DeptInfo departmentInfo, UserEntityInfo userEntityInfo) throws VCIError {
        Department department = ObjectConvert.changeDepartmentInfoToDepartment(departmentInfo);
        if (StringUtils.isBlank(department.getId())) {
            String id = ObjectUtility.getNewObjectID36();
            department.setId(id);
        }
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            DepartmentService departmentService = new DepartmentService();
            UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo);
            departmentService.saveDepartment(department);
            // LogRecordUtil.writeLog(userEntity, "添加", department.getLogInfo(),
            // LogType.General,department.getId());
            
            DeptCacheUtil.getInstance().setObject(departmentInfo);
 
            String log = String.format("添加部门:%s [%s]", department.getName(), LogHelper.toNewLogString(department));
            LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", log, LogType.General, department.getId());
        } catch (Exception e) {
            throw new VCIError("120109", new String[0]);
        }
        return department.getId();
    }
 
    /**
     * 批量保存部门信息
     * 
     * @param deptInfo,部门信息
     * @param userEntityInfo,用户信息
     * @return
     * @throws VCIError
     */
    public boolean batchSaveDepart(DeptInfo[] deptInfos, UserEntityInfo userEntityInfo) throws VCIError {
        Department[] depts = new Department[deptInfos.length];
        for (int i = 0; i < deptInfos.length; i++) {
            depts[i] = ObjectConvert.changeDepartmentInfoToDepartment(deptInfos[i]);
        }
 
        try {
            DepartmentService departmentService = new DepartmentService();
            UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo);
            departmentService.batchSaveDepart(depts);
            
            for (DeptInfo dept : deptInfos) {
                DeptCacheUtil.getInstance().setObject(dept);
            }
        } catch (Throwable e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120112", new String[0]);
        }
 
        return true;
    }
 
    /**
     * <p>
     * Description:保存角色
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param roleInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public String saveRole(RoleInfo roleInfo, UserEntityInfo userEntityInfo) throws VCIError {
        Role role = ObjectConvert.changeRoleInfoToRole(roleInfo);
        String id = ObjectUtility.getNewObjectID36();
        role.setId(id);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            RoleService roleService = new RoleService();
            UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo);
            roleService.saveRole(role);
            
            RoleCacheUtil.getInstance().setObject(role);
 
            String log = String.format("添加角色:%s [%s]", role.getName(), LogHelper.toNewLogString(role));
            LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", log, LogType.General, role.getId());
 
            // LogRecordUtil.writeLog(userEntity, "添加", role.getLogInfo(),
            // LogType.General,role.getId());
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120304", new String[0]);
        }
        return id;
    }
 
    /**
     * <p>
     * Description:根据Id获取角色
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @return
     */
    public RoleInfo selectRole(String id) {
        RoleService roleService = new RoleService();
        Role role = roleService.selectRole(id);
        return ObjectConvert.changeRoleToRoleInfo(role);
    }
 
    /**
     * <p>
     * Description: 保存人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param userInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public String saveUser(UserInfo userInfo, UserEntityInfo userEntityInfo) throws VCIError {
        User user = ObjectConvert.changeUserInfoToUser(userInfo);
        String id = "";
        if (user.getId() == null || user.getId().equals("")) {
            id = ObjectUtility.getNewObjectID36();
            user.setId(id);
        } else {
            id = user.getId();
        }
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
            userService.saveUser(user);
            
            UserCacheUtil.getInstance().setObject(userInfo);
 
            String log = String.format("添加用户:%s [%s]", user.getUserName(), LogHelper.toNewLogString(user));
            LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", log, LogType.General, user.getId());
 
            // LogRecordUtil.writeLog(userEntity, "添加", user.getLogInfo(),
            // LogType.General,user.getId());
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120404", new String[0]);
        }
        return id;
    }
 
    /**
     * <p>
     * Description: 修改部门
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param deptInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean updateDepartment(DeptInfo deptInfo, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        Department departmentAfter = ObjectConvert.changeDepartmentInfoToDepartment(deptInfo);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            DepartmentService departmentService = new DepartmentService();
            UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo);
            Department departBefore = departmentService.selectDepartmentById(departmentAfter.getId());
//            StringBuilder logres = new StringBuilder();
//            logres.append("更新前:"+departBefore.getLogInfo());
//            logres.append(" 更新后:"+departmentAfter.getLogInfo());
            String log = "";
            log = String.format("更改部门:%s; %s", departmentAfter.getName(),
                    LogHelper.toUpdataLogString(departBefore, departmentAfter));
 
            rs = departmentService.updateDepartment(departmentAfter);
            
            DeptCacheUtil.getInstance().setObject(deptInfo);
 
            if (rs)
                LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log, LogType.General, departmentAfter.getId());
            else
                LogRecordUtil.writeLog(userEntityInfo, "更新", "失败", log, LogType.General, departmentAfter.getId());
 
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120110", new String[0]);
        }
        return rs;
    }
 
    /**
     * <p>
     * Description:修改角色
     * </p>
     * 
     * @author wangxlou
     * @time 2012-5-10
     * @param roleInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean updateRole(RoleInfo roleInfo, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        Role role = ObjectConvert.changeRoleInfoToRole(roleInfo);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            RoleService roleService = new RoleService();
            UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo);
            Role roleBefroe = roleService.selectRole(role.getId());
 
            String log = "";
            log = String.format("更改角色:%s; %s", role.getName(), LogHelper.toUpdataLogString(roleBefroe, role));
 
            rs = roleService.updateRole(role);
            
            RoleCacheUtil.getInstance().setObject(roleInfo);
 
//            StringBuilder log = new StringBuilder();
//            log.append("更新前:"+roleBefroe.getLogInfo());
//            log.append(" 更新后:"+role.getLogInfo());
            LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log, LogType.General, role.getId());
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120305", new String[0]);
        }
        return rs;
    }
 
    /**
     * <p>
     * Description:修改人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param userInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean saveOrUpdateUser(UserInfo userInfo, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        User user = ObjectConvert.changeUserInfoToUser(userInfo);
        try {
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
            User sysUser = userService.selectUserByName(userInfo.userName);
            if (sysUser == null) {
                String id = ObjectUtility.getNewObjectID36();
                user.setId(id);
                userService.saveUser(user);
            } else {
                user.setId(sysUser.getId());
                userService.updateUser(user);
            }
            
            UserCacheUtil.getInstance().setObject(userInfo);
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120405", new String[0]);
        }
        return rs;
    }
 
    /**
     * <p>
     * Description:修改人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param userInfo
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean updateUser(UserInfo userInfo, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        User user = ObjectConvert.changeUserInfoToUser(userInfo);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
            User userBefroe = userService.getUserObjectByoid(user.getId());
            String log = "";
            log = String.format("更改用户:%s;%s", user.getUserName(), LogHelper.toUpdataLogString(userBefroe, user));
//            log.append("更新前:"+userBefroe.getLogInfo());
//            log.append(" 更新后:"+user.getLogInfo());
            userService.updateUser(user);
            
            UserCacheUtil.getInstance().setObject(userInfo);
            LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log, LogType.General, user.getId());
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120405", new String[0]);
        }
        return rs;
    }
 
 
 
    public String checkPasswordStrategyByUserId(String userId, String password) throws VCIError {
        try {
            PasswordStrategyInfo psi = fetchPasswordStrategyByUserId(userId);
 
            if (psi == null)
                return "没有配置密码策略";
            
            return checkPasswordStrategy(psi, password);
 
        } catch (Exception e) {
            throw new VCIError("检查密码策略符合性异常", new String[] {e.getMessage()});
        }
    }
    
    public String modifyUserPassword(String idUser, String oldPW, String newPW, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        String error = "";
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
            User user = userService.getUserObjectByoid(idUser);
            
            if (StringUtils.isEmpty(user.getId())) {
                error = String.format("用户ID无效:", idUser);
                LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", error, LogType.General, user.getId());
                return error;
            }
            
            ThreeDES des = new ThreeDES();// 实例化一个对�?
            des.getKey("daliantan0v0");// 生成密匙
            
            String log = "更改密码";
            oldPW = des.getEncString(oldPW);
            if (!user.getPassword().equals(oldPW)) {
                error = String.format("更改[%s]密码失败,输入旧密码不正确!", user.getUserName());
                LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", error, LogType.General, user.getId());
                return error;
                //throw new VCIError("120405", new String[] {"旧密码输入不正确!"});
            }
            
            error = checkPasswordStrategyByUserId(idUser, newPW);
            
            if (!StringUtils.isEmpty(error)) {
                LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", "更改用户密码:" + user.getUserName() + "; " + error, LogType.General, user.getId());
                return error;
            }
            
            String desPwd = des.getEncString(newPW);
            
            rs = userService.chanageUserPassword(idUser, desPwd);
            if (!rs) {
                
                error = "修改用户密码失败";
                LogRecordUtil.writeLog(userEntityInfo, "修改密码", "失败", "更改用户密码:%s" + user.getUserName() +"; " +  error, LogType.General, user.getId());
                return error;
            }
            
            user.setPassword(desPwd);
            UserCacheUtil.getInstance().setObject(user);
            
            log = String.format("更改用户密码:%s", user.getUserName());
 
            LogRecordUtil.writeLog(userEntityInfo, "修改密码", "成功", log, LogType.General, user.getId());
        } catch (VCIError e) {
            throw e;
        } catch (Exception e) {
            throw new VCIError("120405", new String[0]);
        }
        return "";
    }
    
    private String checkPasswordStrategy(PasswordStrategyInfo psi, String pw) throws VCIError {
        //int cts = psi.charTypes;
        long temp = psi.requiredType;
        long cts = temp & 0x0000ffff;
        long pasLen = psi.passwordLen; //最小长度
        long pasMaxLen = psi.passwordMaxLen;//最大长度
        //int requiredType = psi.requiredType; // 必填种类
        long requiredType = (temp >> 16) & 0x0000ffff; // 必填种类
        String names= "";
        
        if ((cts & 0x01) == 0x01) {
            names += "数字,";
        } 
        if ((cts & 0x02) == 0x02) {
            names += "小写字母,";
        } 
        if ((cts & 0x04) == 0x04) {
            names += "大写字母,";
        } 
        if ((cts & 0x08) == 0x08) {
            names += "符号,";
        }
        
        if (names.length() > 1)
            names = names.substring(0, names.length() - 1);
 
        String error = "密码必须中必须含有【"+names+"】中的【"+requiredType+"】种密码组合方式,且密码长度必须在【" + pasLen + "-" + pasMaxLen + "】范围内。";
 
        if (pw.length() < psi.passwordLen || pw.length() > psi.passwordMaxLen) {
            return error;
        }
        
        // 校验密码长度是否符合密码策略的最小长度
        if(pw.length() < pasLen){
            error = "密码长度不能小于"+pasLen+",且密码必须包含‘"+names+"’中的"+requiredType+"种组合! 请重新输入密码!";
            return error;
        }
        // 校验密码长度是否符合密码策略的最大长度
        if(pw.length() > pasMaxLen){
            error = "密码长度不能大于"+pasMaxLen+",且密码必须包含‘"+names+"’中的"+requiredType+"种组合! 请重新输入密码!";
            return error;
        }
        
        // 校验密码包含的字符是否符合密码策略限定的字符类型
        String symbol = "[ _`~!@#$%^&*()-+={[}]|\\'\":;,.<>/?";
        int[] types = new int[4];
        types[0] = 0;
        types[1] = 0;
        types[2] = 0;
        types[3] = 0;
        
        boolean coincident = true;
        for (int i = 0 ; i < pw.length() ;i ++){
            char c = pw.charAt(i);
            if (Character.isDigit(c)) {
                if ((cts & 0x01) != 0x01) {
                    coincident = false;
                    break;
                } else {
                    types[0] = 1;
                }
            }
            else if (Character.isLowerCase(c)) {
                if ((cts & 0x02) != 0x02) {
                    coincident = false;
                    break;
                } else {
                    types[1] = 1;
                }
            }
            else if (Character.isUpperCase(c)) {
                if ((cts & 0x04) != 0x04) {
                    coincident = false;
                    break;
                } else {
                    types[2] = 1;
                }
            }
            else if (symbol.indexOf(c) > -1) {
                if ((cts & 0x08) != 0x08) {
                    coincident = false;
                    break;
                } else {
                    types[3] = 1;
                }
            }
        }
        
        // 校验密码包含的字符种类是否符合密码策略要求的包含字符种类数
        int typeCount = 0;
        for (int i : types) {
            if (i == 1)
                typeCount++;
        }
 
        if (typeCount < requiredType) {
            error = "密码必须包含["+names+"]中的"+requiredType+"种类型,请重新输入密码!";
            return error;
        }
 
        if (!coincident){
            error = "您输入的密码不正确,密码必须中必须含有‘"+names+"’中的"+requiredType+"种密码组合方式,\n" +
                    "或密码组合方式取值范围中不含有您输入的字符,请确认!";
            return error;
        }
        
        return "";
    }
 
    /**
     * <p>
     * Description:删除部门
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean deleteDepartment(String[] id, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // List<Department> list = new ArrayList<Department>();
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            DepartmentService departmentService = new DepartmentService();
            UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo);
            int size = id.length;
            LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
            for (int i = 0; i < size; i++) {
                Department department = departmentService.selectDepartmentById(id[i]);
                map.put(department.getLogInfo(), department.getId());
                // list =
                departmentService.deleteDepartment(id[i]);
                
                DeptCacheUtil.getInstance().delObject(id[i]);
            }
            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String deptId = it.next();
                LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", deptId, LogType.General, map.get(deptId));
            }
 
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120108", new String[0]);
        }
        return rs;
    }
 
    public boolean updateDeptParentId(String id, String parentId, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            DepartmentService departmentService = new DepartmentService();
            UserEntityDelegate.setUserEntityToService(departmentService, userEntityInfo);
            
            DeptInfo dept = OrgCacheProvider.getDepartment(parentId);
            dept.parentId = parentId;
            
            rs = departmentService.updateDeptParentId(id, parentId);
            
            DeptCacheUtil.getInstance().setObject(dept);
            
            if (rs) {
                LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", parentId, LogType.General, id);
            }
 
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120110", new String[0]);
        }
        return rs;
    }
 
    /**
     * <p>
     * Description: 删除角色
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean deleteRole(String[] ids, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            RoleService roleService = new RoleService();
            UserEntityDelegate.setUserEntityToService(roleService, userEntityInfo);
            LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
            for (String id : ids) {
                Role role = roleService.selectRole(id);
                map.put(role.getId(), role.getLogInfo());
            }
            rs = roleService.deleteRoleByMQL(ids);
            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String id = it.next();
                RoleCacheUtil.getInstance().delObject(id);
                
                LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", map.get(id), LogType.General, id);
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120303", new String[0]);
        }
 
        return rs;
    }
 
    /**
     * <p>
     * Description: 删除人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param id
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean deleteUser(String[] ids, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
            int size = ids.length;
            LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
            for (int i = 0; i < size; i++) {
                User user = (User) userService.getUserInfoList(ids[i]).get(0);
                map.put(user.getId(), user.getLogInfo());
                rs = userService.deleteUser(ids[i]);
                UserCacheUtil.getInstance().delObjectById(ids[i]);
                userService.deleteRights(ids[i]);
            }
            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String id = it.next();
                LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", map.get(id), LogType.General, id);
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120403", new String[0]);
        }
        return rs;
    }
 
    /**
     * <p>
     * Description: 停用/启用
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-14
     * @param id
     * @param flag
     * @param userEntityInfo
     * @return
     * @throws VCIError
     */
    public boolean stopUsers(String[] id, boolean flag, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
            int size = id.length;
            StringBuilder log = null;
            for (int i = 0; i < size; i++) {
                log = new StringBuilder();
                log.append("用户名:");
                User user = (User) userService.getUserInfoList(id[i]).get(0);
                log.append(user.getLogInfo());
                rs = userService.stopUsers(id[i], flag);
                user.setStatus(flag ? (short)1 : (short)0);
                UserCacheUtil.getInstance().setObject(user);
                
                LogRecordUtil.writeLog(userEntityInfo, "停用、启用", rs ? "成功" : "失败", log.toString(), LogType.General, user.getId());
            }
 
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120412", new String[0]);
        }
        return rs;
    }
 
    /**
     * <p>
     * Description:根据部门ID获取人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-11
     * @param deptId
     * @return
     * @throws VCIError
     */
    public UserInfo[] getUserByDeptId(String deptId) throws VCIError {
        List<User> list = new ArrayList<User>();
        try {
            list = new UserService().getUserByDeptId(deptId);
        } catch (Exception e) {
            throw new VCIError("120411", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
 
        return userInfo;
    }
 
    /**
     * 
     * <p>
     * 获取该型号下的型号总师:
     * </p>
     * 
     * @time 2013-3-28
     * @param modelId 型号ID
     * @return
     * @throws VCIError
     */
    public UserInfo[] fetchUserInfoByModelId(String modelId) throws VCIError {
        List<User> list = new ArrayList<User>();
        try {
            list = new UserService().fetchUserInfoByModelId(modelId);
        } catch (Exception e) {
            throw new VCIError("120411", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
 
        return userInfo;
    }
 
    /**
     * 通过型号获取型号总师
     * <p>
     * Description:
     * </p>
     * 
     * @author wangxl
     * @time 2013-3-30
     * @param model
     * @return
     * @throws VCIError
     */
    public UserInfo[] fetchUserInfoByModel(String model) throws VCIError {
        List<User> list = new ArrayList<User>();
        try {
            list = new UserService().fetchUserInfoByModel(model);
        } catch (Exception e) {
            throw new VCIError("120411", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
 
        return userInfo;
    }
 
    public PasswordStrategyInfo[] fetchAllPasswordStrategy() throws VCIError {
        List<PasswordStrategy> list = new ArrayList<PasswordStrategy>();
        try {
            list = new PasswordStrategyService().getPasswordStrategyList();
        } catch (Exception e) {
            throw new VCIError("555555", new String[0]);
        }
        int size = list.size();
        PasswordStrategyInfo[] infos = new PasswordStrategyInfo[size];
        for (int i = 0; i < size; i++) {
            infos[i] = ObjectConvert.changePasswordStrategyToInfo(list.get(i));
        }
        return infos;
    }
 
    public PasswordStrategyInfo[] fetchAllPasswordStrategy(int pageNo, int pageSize) throws VCIError {
        List<PasswordStrategy> list = new ArrayList<PasswordStrategy>();
        try {
            list = new PasswordStrategyService().getPasswordStrategyList(pageNo, pageSize);
        } catch (Exception e) {
            throw new VCIError("555555", new String[0]);
        }
        int size = list.size();
        PasswordStrategyInfo[] infos = new PasswordStrategyInfo[size];
        for (int i = 0; i < size; i++) {
            infos[i] = ObjectConvert.changePasswordStrategyToInfo(list.get(i));
        }
        return infos;
    }
 
    public int getPasswordStrategyTotal() throws VCIError {
        int count = 0;
        try {
            count = new PasswordStrategyService().getPasswordStrategyTotal();
        } catch (Exception e) {
            throw new VCIError("555572", new String[0]);
        }
        return count;
    }
 
    public boolean savePasswordStrategy(PasswordStrategyInfo info, //String[] combinationIds,
            UserEntityInfo userEntityInfo) throws VCIError {
        boolean res = false;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            PasswordStrategyService srv = new PasswordStrategyService();
            UserEntityDelegate.setUserEntityToService(srv, userEntityInfo);
            PasswordStrategy passwordStrategy = ObjectConvert.changePassStrategyInfoToEntity(info);
            res = srv.savePasswordStrategy(passwordStrategy);
            LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", passwordStrategy.getLogInfo(), LogType.General,
                    passwordStrategy.getId());
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("555556", new String[0]);
        }
 
        return res;
    }
 
    public boolean editPasswordStrategy(PasswordStrategyInfo info, UserEntityInfo userEntityInfo) throws VCIError {
        boolean res = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            PasswordStrategyService srv = new PasswordStrategyService();
            UserEntityDelegate.setUserEntityToService(srv, userEntityInfo);
            PasswordStrategy passwordStrategy = ObjectConvert.changePassStrategyInfoToEntity(info);
            PasswordStrategy passwordStrategyBefore = (PasswordStrategy) srv
                    .getPasswordObjById(passwordStrategy.getId()).get(0);
 
            StringBuilder log = new StringBuilder();
            log.append("更新前:" + passwordStrategyBefore.getLogInfo());
            log.append(" 更新后:" + passwordStrategy.getLogInfo());
 
            res = srv.updatePasswordStrategy(passwordStrategy);
 
            LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log.toString(), LogType.General,
                    passwordStrategyBefore.getId());
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("555557", new String[0]);
        }
        return res;
    }
 
    public boolean deletePasswordStrategy(String[] ids, UserEntityInfo userEntityInfo) throws VCIError {
        boolean res = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            PasswordStrategyService srv = new PasswordStrategyService();
            UserEntityDelegate.setUserEntityToService(srv, userEntityInfo);
            LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
            for (String id : ids) {
                PasswordStrategy pass = (PasswordStrategy) srv.getPasswordObjById(id).get(0);
                map.put(pass.getLogInfo(), pass.getId());
                res = srv.deletePasswordStrategyById(id);
            }
            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String logKey = it.next();
                LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", logKey, LogType.General, map.get(logKey));
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("555558", new String[0]);
        }
        return res;
    }
 
    public int checkPasswordStrategyIsquotedCount(String id) throws VCIError {
        int count = 0;
        try {
            count = new PasswordStrategyService().checkPasswordStrategyIsquotedCount(id);
        } catch (Exception e) {
            throw new VCIError("555565", new String[0]);
        }
        return count;
    }
 
    public PasswordStrategyInfo fetchPasswordStrategyByUserId(String userId) throws VCIError {
        PasswordStrategyInfo info = new PasswordStrategyInfo();
        PasswordStrategy entity;
        try {
            entity = new PasswordStrategyService().getPasswordObjByUserId(userId);
        } catch (Exception e) {
            throw new VCIError("555555", new String[0]);
        }
        if (entity != null) {
            info = ObjectConvert.changePasswordStrategyToInfo(entity);
        }
        return info;
    }
 
    public boolean saveUserPasswordStrateg(String[] userIds, String passwordStrategId, UserEntityInfo userEntityInfo)
            throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userService = new UserService();
            PasswordStrategyService srv = new PasswordStrategyService();
            UserEntityDelegate.setUserEntityToService(userService, userEntityInfo);
 
            List list = srv.getPasswordObjById(passwordStrategId);
            PasswordStrategy passwordStrategy = (PasswordStrategy) list.get(0);
 
            StringBuilder log = null;
            for (String userId : userIds) {
                log = new StringBuilder();
                log.append("用户名:");
                User user = (User) userService.getUserInfoList(userId).get(0);
                log.append("[" + user.getUserName() + "]");
                rs = userService.saveUserPasswordStrateg(userId, passwordStrategId);
                log.append("->");
                log.append(passwordStrategy.getLogInfo());
                LogRecordUtil.writeLog(userEntityInfo, "为成员分配密码策略", "成功", log.toString(), LogType.General,
                        userId + "密码策略ID:" + passwordStrategId);
            }
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("555567", new String[0]);
        }
 
        return rs;
    }
 
    public UserLogonInfo fetchUserLogonObj(String userId) throws VCIError {
        UserLogonInfo res = new UserLogonInfo();
        UserLogon userLogon = null;
        try {
            UserService userSrv = new UserService();
            userLogon = userSrv.getUserLogonObj(userId);
            if (userLogon == null) {
                res = new UserLogonInfo();
                res.pluserOid = userId;
                res.plWrongNum = 0;
                //SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.fff");// 设置日期格式
                res.plLogonTime = System.currentTimeMillis();
            } else {
                res = ObjectConvert.changeUserLogonToUserLogonInfo(userLogon);
            }
 
        } catch (Exception ex) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(ex);
            throw new VCIError("555568", new String[0]);
        }
        return res;
    }
 
    public long getSystemTime() throws VCIError {
        long sysTime = 0;
        try {
            UserService userSrv = new UserService();
            sysTime = userSrv.getSystemTime();
        } catch (Exception ex) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(ex);
            throw new VCIError("555569", new String[0]);
        }
        return sysTime;
    }
 
    public void updateLogonInfo(String userId, boolean flag) throws VCIError {
        try {
            UserService userSrv = new UserService();
            userSrv.updateLogonInfo(userId, flag);
        } catch (Exception ex) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(ex);
            throw new VCIError("555570", new String[0]);
        }
    }
 
    public void deblock(String[] ids, UserEntityInfo userEntityInfo) throws VCIError {
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            UserService userSrv = new UserService();
            UserEntityDelegate.setUserEntityToService(userSrv, userEntityInfo);
            userSrv.deblock(ids);
            for (String userId : ids) {
                User user = (User) userSrv.getUserObjectByoid(userId);
                // LogRecordUtil.writeLog(userEntity, "账户解锁", "["+user.getLogInfo()+"]",
                // LogType.General, userId);
 
                // add by caill 2016.9.13
                LogRecordUtil.writeLog(userEntityInfo, "解锁用户", "解锁成功", "[" + user.getLogInfo() + "]",
                        LogType.UnlockUser, userId);
            }
        } catch (Exception ex) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(ex);
            throw new VCIError("555571", new String[0]);
        }
    }
 
//    /**
//     * 简单记录系统登入、登出日�?
//     * <p>
//     * Description:
//     * </p>
//     * 
//     * @author wangxl
//     * @time 2012-12-27
//     * @param message
//     * @param userEntityInfo
//     * @throws VCIError
//     */
//    public void savelog(String message, UserEntityInfo userEntityInfo) throws VCIError {
//        userEntityInfo.modules = "登录模块";// add by liujw
//        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
//        User user = ObjectConvert.changeUserInfoToUser(fetchUserInfoByName(userEntity.getUserName()));
//        LogRecordUtil.writeLog(userEntityInfo, message, "登录成功", message,
//                "登入".equals(message) ? LogType.Login : LogType.Logout, user.getId());
//    }
//
//    public void saveLogV2(String result, String message, String type, int logTypeIntVal, String dataObjOid,
//            UserEntityInfo userEntityInfo) throws VCIError {
//        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
//        LogType logType = LogType.getByIntVal(logTypeIntVal);
//        LogRecordUtil.writeLog(userEntityInfo, type, result, message, logType, dataObjOid);
//    }
//
//    public void savelogfail(String message, UserEntityInfo userEntityInfo) throws VCIError {
//        userEntityInfo.modules = "登录模块";
//        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
//        User user = ObjectConvert.changeUserInfoToUser(fetchUserInfoByName(userEntity.getUserName()));
//        LogRecordUtil.writeLog(userEntityInfo, "登入", "登录失败", message, LogType.Login, user.getId());
//    }
//
//    // add by caill start 2016.9.13简单记录用户被锁定的日志
//    public void blocklog(String userId, UserEntityInfo userEntityInfo) throws VCIError {
//        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
//        User user = ObjectConvert.changeUserInfoToUser(fetchUserInfoByName(userEntity.getUserName()));
//        LogRecordUtil.writeLog(userEntityInfo, LogType.LockUser.getLabel(), "用户锁定", 
//                "[" + user.getLogInfo() + "]" + "在连续输入多次密码错误后导致账户被锁定", LogType.LockUser, userId);
//    }
 
    /**
     * 获取所有密码组合方�?
     * <p>
     * Description:
     * </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     * @return
     * @throws VCIError
     */
    @SuppressWarnings("unchecked")
    public CombinationInfo[] fetchAllCombinations() throws VCIError {
        List<Combination> list = null;
        try {
            list = new CombinationService().getAllList();
        } catch (Exception e) {
            throw new VCIError("120501", new String[0]);
        }
        int size = list.size();
        CombinationInfo[] info = new CombinationInfo[size];
        for (int i = 0; i < size; i++) {
            info[i] = changeCombinationToInfo(list.get(i));
        }
        return info;
    }
 
    /**
     * 分页查询组合方式
     * <p>
     * Description:
     * </p>
     * 
     * @author llb
     * @time 2013-1-4
     * @return
     * @throws VCIError
     */
    @SuppressWarnings("unchecked")
    public CombinationInfo[] fetchCombinationsToPage(int pageIndex, int pageSize) throws VCIError {
        List<Combination> list = null;
        try {
            list = new CombinationService().fetchCombinationsToPage(pageIndex, pageSize);
        } catch (Exception e) {
            throw new VCIError("120501", new String[0]);
        }
        int size = list.size();
        CombinationInfo[] info = new CombinationInfo[size];
        for (int i = 0; i < size; i++) {
            info[i] = changeCombinationToInfo(list.get(i));
        }
        return info;
    }
 
    public String saveCombination(CombinationInfo info, UserEntityInfo userEntityInfo) throws VCIError {
        Combination comb = changeCombinationInfoToCombination(info);
        String id = ObjectUtility.getNewObjectID36();
        comb.setId(id);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            CombinationService service = new CombinationService();
            UserEntityDelegate.setUserEntityToService(service, userEntityInfo);
            service.saveCombination(comb);
            LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", comb.getLogInfo(), LogType.General, comb.getId());
        } catch (Exception e) {
            throw new VCIError("120502", new String[0]);
        }
        return id;
    }
 
    public boolean updateCombination(CombinationInfo info, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        Combination comb = changeCombinationInfoToCombination(info);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            CombinationService service = new CombinationService();
            UserEntityDelegate.setUserEntityToService(service, userEntityInfo);
            Combination combinationBefore = (Combination) service.getCombinationsObjById(comb.getId()).get(0);
            rs = service.updateCombination(comb);
            StringBuilder log = new StringBuilder();
            log.append("更新前:" + combinationBefore.getLogInfo());
            log.append(" 更新后:" + comb.getLogInfo());
            LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log.toString(), LogType.General, comb.getId());
        } catch (Exception e) {
            throw new VCIError("120503", new String[0]);
        }
        return rs;
    }
 
    public boolean deleteCombination(String[] id, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            CombinationService service = new CombinationService();
            UserEntityDelegate.setUserEntityToService(service, userEntityInfo);
            LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
            for (String Id : id) {
                Combination combin = (Combination) service.getCombinationsObjById(Id).get(0);
                map.put(combin.getLogInfo(), combin.getId());
            }
            rs = service.deleteCombinationByMQL(id);
            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String logKey = it.next();
                LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", logKey, LogType.General, map.get(logKey));
            }
        } catch (Exception e) {
            throw new VCIError("120504", new String[0]);
        }
 
        return rs;
    }
 
    @SuppressWarnings("unchecked")
    public CombinationValueInfo[] fetchCombinationValuesByParentId(String parentId) throws VCIError {
        List<CombinationValue> list = null;
        try {
            list = new CombinationValueService().getCombinationValuesByParentId(parentId);
        } catch (Exception e) {
            throw new VCIError("120505", new String[0]);
        }
        int size = list.size();
        CombinationValueInfo[] info = new CombinationValueInfo[size];
        for (int i = 0; i < size; i++) {
            info[i] = changeCombinationValueToInfo(list.get(i));
        }
        return info;
    }
 
    @SuppressWarnings("unchecked")
    public String saveCombinationValue(CombinationValueInfo[] valueInfos, UserEntityInfo userEntityInfo)
            throws VCIError {
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        CombinationValueService service = new CombinationValueService();
        int length = valueInfos.length;
 
        for (int i = 0; i < length; i++) {
            List<CombinationValue> combVal = service.getCombValByClsfIdAndVal(valueInfos[i].parentId,
                    valueInfos[i].value);
            if (combVal.size() > 0) {
                throw new VCIError("120507 ", new String[] { "" });
            }
        }
        try {
            CombinationValue[] combinationValues = new CombinationValue[length];
            for (int i = 0; i < length; i++) {
                String id = ObjectUtility.getNewObjectID36();
                combinationValues[i] = changeCombinationValueInfoToVal(valueInfos[i]);
                combinationValues[i].setId(id);
            }
 
            UserEntityDelegate.setUserEntityToService(service, userEntityInfo);
            service.saveCombinationValue(combinationValues);
 
            for (CombinationValue value : combinationValues) {
                LogRecordUtil.writeLog(userEntityInfo, "添加", "成功", value.getLogInfo(), LogType.General, value.getId());
            }
            ;
 
        } catch (Exception e) {
            throw new VCIError("120506", new String[0]);
        }
 
        return "";
    }
 
    public boolean updateCombinationValue(CombinationValueInfo valueInfo, UserEntityInfo userEntityInfo)
            throws VCIError {
        boolean rs = true;
        CombinationValue combVal = changeCombinationValueInfoToVal(valueInfo);
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        CombinationValueService service = new CombinationValueService();
 
        // add by liujw
        List<CombinationValue> combValSame = service.getCombValByClsfIdAndVal(valueInfo.parentId, valueInfo.value);
        if (combValSame.size() > 0) {
            throw new VCIError("120507 ", new String[] { "" });
        }
 
        try {
 
            UserEntityDelegate.setUserEntityToService(service, userEntityInfo);
            CombinationValue combinationValueBefroe = (CombinationValue) service
                    .getCombinationValueObjById(combVal.getId()).get(0);
            StringBuilder log = new StringBuilder();
            log.append("更新前:" + combinationValueBefroe.getLogInfo());
            log.append(" 更新后:" + combVal.getLogInfo());
            rs = service.updateCombinationValue(combVal);
            LogRecordUtil.writeLog(userEntityInfo, "更新", "成功", log.toString(), LogType.General, combVal.getId());
        } catch (Exception e) {
            throw new VCIError("120508", new String[0]);
        }
        return rs;
    }
 
    public boolean deletCombinationValues(String[] id, UserEntityInfo userEntityInfo) throws VCIError {
        boolean rs = true;
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        try {
            CombinationValueService service = new CombinationValueService();
            CombinationService combinService = new CombinationService();
            Combination combin = null;
            UserEntityDelegate.setUserEntityToService(service, userEntityInfo);
 
            StringBuilder log = new StringBuilder();
            StringBuilder combinIds = new StringBuilder();
            StringBuilder valuesIds = new StringBuilder();
            combinIds.append("密码组合方式ID:");
            valuesIds.append("值ID: ");
            for (String ID : id) {
                List list = service.getCombinationValueObjById(ID);
                if (list.size() > 0) {
                    CombinationValue value = (CombinationValue) list.get(0);
                    if (combin == null) {
                        combin = (Combination) combinService.getCombinationsObjById(value.getParentId()).get(0);
                        log.append(combin.getLogInfo() + "->");
                        combinIds.append(combin.getId());
                    }
                    log.append(value.getLogInfo() + " ");
                    valuesIds.append(value.getId() + " ");
                }
            }
            rs = service.deleteCombinationValueByMQL(id);
            LogRecordUtil.writeLog(userEntityInfo, "删除", "成功", log.toString(), LogType.General,
                    combinIds.toString() + valuesIds.toString());
        } catch (Exception e) {
            e.printStackTrace();
            throw new VCIError("120509", new String[0]);
        }
 
        return rs;
    }
 
    @SuppressWarnings("unchecked")
    public CombinationInfo[] fetchCombinationsByPstId(String pstId) throws VCIError {
        List<Combination> list = null;
        try {
            list = new CombinationService().fetchCombinationsByPstId(pstId);
        } catch (Exception e) {
            throw new VCIError("120501", new String[0]);
        }
        int size = list.size();
        CombinationInfo[] info = new CombinationInfo[size];
        for (int i = 0; i < size; i++) {
            info[i] = changeCombinationToInfo(list.get(i));
        }
        return info;
    }
 
    /**
     * 验证密码组合方式是否被密码策略引�?
     * <p>
     * Description:
     * </p>
     * 
     * @author wangxl
     * @time 2013-1-4
     * @param id
     * @return
     * @throws VCIError
     */
    public int checkCombinationIsquotedCount(String combinationd) throws VCIError {
        int count = 0;
        try {
            count = new CombinationService().checkCombinationIsquotedCount(combinationd);
        } catch (Exception e) {
            throw new VCIError("120510", new String[0]);
        }
        return count;
    }
 
    private CombinationValueInfo changeCombinationValueToInfo(CombinationValue combValue) {
        CombinationValueInfo info = new CombinationValueInfo();
        info.id = combValue.getId();
        info.parentId = combValue.getParentId();
        info.value = combValue.getValue();
        return info;
    }
 
    private CombinationValue changeCombinationValueInfoToVal(CombinationValueInfo info) {
        CombinationValue val = new CombinationValue();
        val.setId(info.id == "" ? null : info.id);
        val.setParentId(info.parentId == "" ? null : info.parentId);
        val.setValue(info.value == "" ? null : info.value);
        return val;
    }
 
    private CombinationInfo changeCombinationToInfo(Combination comb) {
        CombinationInfo info = new CombinationInfo();
        info.id = comb.getId();
        info.name = comb.getName() == null ? "" : comb.getName();
        info.description = comb.getDesc() == null ? "" : comb.getDesc();
        info.createTime = comb.getCreateTime() == null ? System.currentTimeMillis() : comb.getCreateTime().getTime();
        info.createUser = comb.getCreateUser() == null ? "" : comb.getCreateUser();
        info.updateTime = comb.getUpdateTime() == null ? System.currentTimeMillis() : comb.getUpdateTime().getTime();
        info.updateUser = comb.getUpdateUser() == null ? "" : comb.getUpdateUser();
        info.grantor = comb.getGrantor() == null ? "" : comb.getGrantor();
        return info;
    }
 
    public Combination changeCombinationInfoToCombination(CombinationInfo info) {
        Combination comb = new Combination();
        comb.setId(info.id == "" ? null : info.id);
        comb.setDesc(info.description == "" ? null : info.description);
        comb.setName(info.name == "" ? null : info.name);
        comb.setCreateTime(info.createTime == 0 ? new java.sql.Timestamp(System.currentTimeMillis()) : new java.sql.Timestamp(info.createTime));
        comb.setCreateUser(info.createUser == "" ? null : info.createUser);
        comb.setUpdateTime(info.updateTime == 0 ? new java.sql.Timestamp(System.currentTimeMillis()) : new java.sql.Timestamp(info.createTime));
        comb.setUpdateUser(info.updateUser == "" ? null : info.updateUser);
        comb.setGrantor(info.grantor == "" ? null : info.grantor);
        return comb;
    }
 
    public DeptInfo[] changeDepartmentToDepartmentInfos(List<?> list) {
        int size = list.size();
        DeptInfo[] departmentInfo = new DeptInfo[size];
        for (int i = 0; i < size; i++) {
            departmentInfo[i] = ObjectConvert.changeDepartmentToDepartmentInfo((Department)list.get(i));
        }
        return departmentInfo;
    }
 
    /**
     * <p>
     * Description: 根据部门唯一编码和部门名称获取部门信�?/p>
     * 
     * @author sunbo
     * @time 2013-3-26
     * @param 部门编码
     * @param 部门名称
     * @return
     * @throws VCIError
     */
    public DeptInfo fetchDeptByNum(String num) throws VCIError {
 
        List<Department> list = null;
        try {
            list = new DepartmentService().fetchDeptByNum(num);
        } catch (Exception e) {
            throw new VCIError("120101", new String[0]);
        }
        int size = list.size();
        DeptInfo deptInfo = new DeptInfo();
        if (size > 0) {
            deptInfo = ObjectConvert.changeDepartmentToDepartmentInfo(list.get(0));
        }
        return deptInfo;
 
    }
 
 
 
    /**
     * <p>
     * Description: 根据文件柜和类型查找人员
     * </p>
     * 
     * @author wangxl
     * @time 2012-5-10
     * @param roleId
     * @param type
     * @return
     * @throws VCIError
     */
    public UserInfo[] fetchUserInfoByPvolumeId(String pvolumeId, int type) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().fetchUserInfoByPvolumeId(pvolumeId, type);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
    static class DeptNameComparator implements Comparator<Object> {
        private final Collator collator = Collator.getInstance();
 
        @Override
        public int compare(Object arg0, Object arg1) {
            Department di1 = (Department) arg0;
            Department di2 = (Department) arg1;
            return collator.compare(di1.getName(), di2.getName());
        }
 
    }
 
    /**
     * 简单记录一般操作日志
     * 
     * @author liyp
     * @time 2016-9-27
     * @param message
     * @param userEntityInfo
     * @throws VCIError
     */
    public void savelogGeneralOperation(String result, String message, UserEntityInfo userEntityInfo, String dataId, String plType)
            throws VCIError {
        // UserEntity userEntity = ObjectConvert.changeUserEntityInfoToUserEntity(userEntityInfo);
        LogRecordUtil.writeLog(userEntityInfo, plType, result, message, LogType.General, dataId);
    }
 
    /****
     * 查询条件
     * 
     * @param otherFiterString
     * @return
     * @throws VCIError
     */
    public DeptInfo[] fetchDepartmentInfoByIds(String[] ids) throws VCIError {
        return OrgCacheProvider.getDepts(ids);
//        List<Department> list = null;
//        try {
//            list = new DepartmentService().fetchDepartmentInfoByIds(otherFiterString);
//        } catch (Exception e) {
//            throw new VCIError("120107", new String[0]);
//        }
//        return changeDepartmentToDepartmentInfos(list);
 
    }
 
    public DeptInfo[] fetchChildrenDeptByParentOid(String prtoid, boolean iscontains, String otherFiterString)
            throws VCIError {
        List<Department> list = null;
        try {
            list = new DepartmentService().fetchChildrenDeptByParentOid(prtoid, iscontains, otherFiterString);
        } catch (Exception e) {
            throw new VCIError("120106", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    public DeptInfo[] gridDeptDataGrids(String filter, int pageNo, int pageSize) throws VCIError {
        List<Department> list = null;
        try {
            list = new DepartmentService().gridDeptDataGrids(filter, pageNo, pageSize);
        } catch (Exception e) {
            throw new VCIError("120107", new String[0]);
        }
        return changeDepartmentToDepartmentInfos(list);
    }
 
    public int gridDeptDataGridsCount(String filter) throws VCIError {
        int count = 0;
        try {
            count = new DepartmentService().gridDeptDataGridsCount(filter);
        } catch (Exception e) {
            throw new VCIError("120307", new String[0]);
        }
        return count;
    }
 
    public RoleInfo[] queryRoleInfos(String filter, int pageNo, int pageSize) throws VCIError {
        List<Role> list = null;
        try {
            list = new RoleService().queryRoleInfos(filter, pageNo, pageSize);
        } catch (Exception e) {
            throw new VCIError("120301", new String[0]);
        }
        int size = list.size();
        RoleInfo[] roleInfo = new RoleInfo[size];
        for (int i = 0; i < size; i++) {
            roleInfo[i] = ObjectConvert.changeRoleToRoleInfo(list.get(i));
        }
        return roleInfo;
    }
 
    public int queryRoleInfosCount(String filter) throws VCIError {
 
        int count = 0;
        try {
            count = new RoleService().queryRoleInfosCount(filter);
        } catch (Exception e) {
            throw new VCIError("120307", new String[0]);
        }
        return count;
    }
 
    public UserInfo[] fetchUserInfoByFilterString(String filterString, int pageNo, int pageSize) throws VCIError {
        // TODO Auto-generated method stub
        List<User> list = null;
        try {
            list = new UserService().fetchUserInfoByFilterString(filterString, pageNo, pageSize);
            int size = list.size();
            UserInfo[] userInfos = new UserInfo[size];
            for (int i = 0; i < size; i++) {
                userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
            }
            return userInfos;
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
    }
 
    public int fetchUserInfoByFilterStringCount(String filterString) throws VCIError {
        try {
            return new UserService().fetchUserInfoByFilterStringCount(filterString);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
    }
 
    public UserInfo[] fetchUserInfosByFilterStringsql(String filterString) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().fetchUserInfosByFilterStringsql(filterString);
            int size = list.size();
            UserInfo[] userInfos = new UserInfo[size];
            for (int i = 0; i < size; i++) {
                userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
            }
            return userInfos;
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
 
    }
 
    public UserInfo[] fetchUserInfoByNames(String[] userNames) throws VCIError {
        return OrgCacheProvider.getUsers(userNames);
//        List<User> list = null;
//        try {
//            list = new UserService().fetchUserInfoByNames(userNames);
//            int size = list.size();
//            UserInfo[] userInfos = new UserInfo[size];
//            for (int i = 0; i < size; i++) {
//                userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
//            }
//            return userInfos;
//        } catch (Exception e) {
//            throw new VCIError("120401", new String[0]);
//        }
    }
 
    public UserInfo getUserObjectByoid(String userOid) throws VCIError {
        UserInfo res = new UserInfo();
        try {
            User user = new UserService().getUserObjectByoid(userOid);
            if (user == null) {
                user = new User();
            }
            res = ObjectConvert.changeUserToUserInfo(user);
 
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        return res;
 
    }
 
    public UserInfo[] getUserObjectByoids(String[] userOids) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().getUserObjectByoids(userOids);
            int size = list.size();
            UserInfo[] userInfos = new UserInfo[size];
            for (int i = 0; i < size; i++) {
                userInfos[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
            }
            return userInfos;
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
    }
 
    public String getSessionInfo(String token) {
        VciSessionInfoDAOImpl sessionDao = new VciSessionInfoDAOImpl();
        VciSessionInfoDO sessionInfoDO = sessionDao.getById(token);
        if (sessionInfoDO != null) {
            return sessionInfoDO.getJsonString();
        }
        return "";
    }
 
    public UserInfo[] fetchNormalUserInfoByConditionUnited(String searchName, String searchUserName, String deptId,
            String roleId, String userName, int pageNo, int pageSize) throws VCIError {
        List<User> list = null;
        try {
            list = new UserService().getUserListByConditionUnited(searchName, searchUserName, deptId, roleId, userName,
                    pageNo, pageSize, true);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
    public int getNormalUserTotalByCondition(String searchName, String searchUserName, String deptId, String roleId,
            String userName) throws VCIError {
        int total = 0;
        try {
            boolean bSuper = isSuperUser(userName);
            
            //System.out.print("=============bSuper=" + bSuper);
 
            total = new UserService().getUserTotalByCondition(searchName, searchUserName, deptId, roleId, userName,
                    !bSuper);
        } catch (Exception e) {
            throw new VCIError("120413", new String[0]);
        }
        return total;
    }
 
    public UserInfo[] fetchNormalUserInfoByCondition(String searchName, String searchUserName, String deptId,
            String roleId, String userName, int pageNo, int pageSize) throws VCIError {
        List<User> list = null;
        try {
            boolean bSuper = isSuperUser(userName);
            
            list = new UserService().getUserListByCondition(searchName, searchUserName, deptId, roleId, userName,
                    pageNo, pageSize, !bSuper);
        } catch (Exception e) {
            throw new VCIError("120401", new String[0]);
        }
        int size = list.size();
        UserInfo[] userInfo = new UserInfo[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = ObjectConvert.changeUserToUserInfo(list.get(i));
        }
        return userInfo;
    }
 
}