ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.permission.controller;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.ImmutableList;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jnpf.base.*;
import jnpf.base.controller.SuperController;
import jnpf.base.entity.DictionaryDataEntity;
import jnpf.base.entity.SystemEntity;
import jnpf.base.vo.DownloadVO;
import jnpf.base.vo.ListVO;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.config.ConfigValueUtil;
import jnpf.constant.MsgCode;
import jnpf.constant.PermissionConst;
import jnpf.database.util.TenantDataSourceUtil;
import jnpf.exception.DataException;
import jnpf.file.util.ExcelTool;
import jnpf.flowable.TemplateApi;
import jnpf.flowable.enums.ExtraRuleEnum;
import jnpf.model.*;
import jnpf.model.tenant.AdminInfoVO;
import jnpf.model.tenant.TenantReSetPasswordForm;
import jnpf.model.tenant.TenantVO;
import jnpf.oauth.AuthApi;
import jnpf.permission.UserApi;
import jnpf.permission.constant.UserColumnMap;
import jnpf.permission.entity.*;
import jnpf.permission.model.SynThirdQyModel;
import jnpf.permission.model.SysThirdDeleteModel;
import jnpf.permission.model.SystemParamModel;
import jnpf.permission.model.check.CheckResult;
import jnpf.permission.model.position.PosConModel;
import jnpf.permission.model.position.PositionListVO;
import jnpf.permission.model.position.PositionVo;
import jnpf.permission.model.user.*;
import jnpf.permission.model.user.form.UserBatchForm;
import jnpf.permission.model.user.form.UserCrForm;
import jnpf.permission.model.user.form.UserResetPasswordForm;
import jnpf.permission.model.user.form.UserUpForm;
import jnpf.permission.model.user.mod.*;
import jnpf.permission.model.user.page.PageUser;
import jnpf.permission.model.user.page.PaginationUser;
import jnpf.permission.model.user.page.UserPagination;
import jnpf.permission.model.user.vo.*;
import jnpf.permission.rest.PullUserUtil;
import jnpf.permission.service.*;
import jnpf.permission.util.AuthPermUtil;
import jnpf.permission.util.PermissionUtil;
import jnpf.util.*;
import jnpf.util.enums.DictionaryDataEnum;
import jnpf.util.treeutil.SumTree;
import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
 
import static jnpf.util.Constants.ADMIN_KEY;
 
/**
 * 用户管理
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月26日 上午9:18
 */
@Tag(name = "用户管理", description = "Users")
@Slf4j
@RestController
@RequestMapping("/Users")
public class UserController extends SuperController<UserService, UserEntity> implements UserApi {
 
    @Autowired
    private CacheKeyUtil cacheKeyUtil;
    @Autowired
    private SynThirdInfoApi synThirdInfoApi;
    @Autowired
    private UserService userService;
    @Autowired
    private OrganizeService organizeService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private UserRelationService userRelationService;
    @Autowired
    private RoleRelationService roleRelationService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private PositionService positionService;
    @Autowired
    private GroupService groupService;
    @Autowired
    private TemplateApi templateApi;
    @Autowired
    private AuthApi authService;
    @Autowired
    private DictionaryDataApi dictionaryDataApi;
    @Autowired
    private ConfigValueUtil configValueUtil;
    @Autowired
    private SysConfigApi sysconfigApi;
    @Autowired
    private AuthPermUtil authPermUtil;
    @Autowired
    private SystemApi systemService;
 
    @Operation(summary = "获取用户列表")
    @GetMapping
    public ActionResult<PageListVO<UserListVO>> getList(UserPagination pagination) {
        List<UserEntity> userList = userService.getList(pagination);
        List<UserListVO> list = new ArrayList<>();
        List<DictionaryDataEntity> dataServiceList4 = dictionaryDataApi.getListByCode(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId());
        Map<String, String> genderMap = dataServiceList4.stream().collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName));
        Map<String, String> positionMap = positionService.getPosFullNameMap();
        //责任人(有岗位信息时添加属性)
        String dutyUser = "" ;
        if (StringUtil.isNotEmpty(pagination.getPositionId())) {
            PositionEntity info = positionService.getInfo(pagination.getPositionId());
            if (info != null) dutyUser = info.getDutyUser();
        }
        for (UserEntity userEntity : userList) {
            UserListVO userVO = JsonUtil.getJsonToBean(userEntity, UserListVO.class);
            userVO.setFullName(userVO.getRealName() + "/" + userVO.getAccount());
            userVO.setHandoverMark(userEntity.getHandoverMark() == null ? 0 : userEntity.getHandoverMark());
            userVO.setHeadIcon(UploaderUtil.uploaderImg(userVO.getHeadIcon()));
            // 时间小于当前时间则判断已解锁
            if (userVO.getEnabledMark() != null && userVO.getEnabledMark() != 0) {
                if (Objects.nonNull(userEntity.getUnlockTime()) && userEntity.getUnlockTime().getTime() > System.currentTimeMillis()) {
                    userVO.setEnabledMark(2);
                } else if (Objects.nonNull(userEntity.getUnlockTime()) && userEntity.getUnlockTime().getTime() < System.currentTimeMillis()) {
                    userVO.setEnabledMark(1);
                }
            }
            userVO.setGender(genderMap.get(userEntity.getGender()));
            StringJoiner positionJoiner = new StringJoiner(",");
            StringJoiner organizeJoiner = new StringJoiner(",");
            List<UserRelationEntity> allPostion = userRelationService.getListByObjectType(userEntity.getId(), PermissionConst.POSITION);
            if (CollectionUtil.isNotEmpty(allPostion)) {
                for (UserRelationEntity item : allPostion) {
                    String posName = positionMap.get(item.getObjectId());
                    if (posName != null) {
                        positionJoiner.add(posName);
                        organizeJoiner.add(posName.substring(0, posName.lastIndexOf("/")));
                    }
 
                }
 
            }
            userVO.setPosition(positionJoiner.toString());
            userVO.setOrganize(organizeJoiner.toString());
            if (StringUtil.isNotEmpty(dutyUser) && dutyUser.equals(userEntity.getId())) {
                userVO.setIsDutyUser(1);
            }
            list.add(userVO);
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    @Operation(summary = "详情")
    @Parameters({
            @Parameter(name = "id", description = "用户id", required = true)
    })
    @SaCheckPermission("permission.user")
    @GetMapping("/{id}")
    public ActionResult<UserInfoVO> getInfo(@PathVariable("id") String id) throws DataException {
        UserEntity entity = userService.getInfo(id);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
 
        QueryWrapper<UserRelationEntity> roleQuery = new QueryWrapper<>();
        roleQuery.lambda().eq(UserRelationEntity::getUserId, id);
        roleQuery.lambda().eq(UserRelationEntity::getObjectType, PermissionConst.ROLE);
        List<String> roleIdList = new ArrayList<>();
        for (UserRelationEntity ure : userRelationService.list(roleQuery)) {
            roleIdList.add(ure.getObjectId());
        }
 
        entity.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
        // 得到组织树
        UserInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, UserInfoVO.class);
        vo.setRoleId(String.join(",", roleIdList));
 
 
        // 获取组织id数组
        QueryWrapper<UserRelationEntity> query = new QueryWrapper<>();
        query.lambda().eq(UserRelationEntity::getUserId, id);
        query.lambda().eq(UserRelationEntity::getObjectType, PermissionConst.ORGANIZE);
        List<String> organizeIds = new ArrayList<>();
        userRelationService.list(query).forEach(u -> {
            organizeIds.add(u.getObjectId());
        });
 
        // 岗位装配
        QueryWrapper<UserRelationEntity> positionQuery = new QueryWrapper<>();
        positionQuery.lambda().eq(UserRelationEntity::getUserId, id);
        positionQuery.lambda().eq(UserRelationEntity::getObjectType, PermissionConst.POSITION);
        String positionIds = "" ;
        for (UserRelationEntity ure : userRelationService.list(positionQuery)) {
            PositionEntity info = positionService.getInfo(ure.getObjectId());
            if (info != null) {
                positionIds = positionIds + "," + ure.getObjectId();
            }
        }
        if (!positionIds.isEmpty()) {
            vo.setPositionId(positionIds.substring(1));
        } else {
            vo.setPositionId(null);
        }
        // 设置分组id
        List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(entity.getId(), PermissionConst.GROUP);
        StringBuilder groupId = new StringBuilder();
        listByObjectType.stream().forEach(t -> groupId.append("," + t.getObjectId()));
        if (groupId.length() > 0) {
            vo.setGroupId(groupId.toString().replaceFirst(",", ""));
        }
        vo.setOrganizeIdTree(PermissionUtil.getOrgIdsTree(organizeIds, 1, organizeService));
        return ActionResult.success(vo);
    }
 
    @Operation(summary = "新建用户")
    @Parameters({
            @Parameter(name = "userCrForm", description = "表单参数", required = true)
    })
    @SaCheckPermission("permission.user")
    @PostMapping
    public ActionResult<String> create(@RequestBody @Valid UserCrForm userCrForm) throws Exception {
        UserEntity entity = JsonUtil.getJsonToBean(userCrForm, UserEntity.class);
        if (userService.isExistByAccount(userCrForm.getAccount())) {
            return ActionResult.fail(MsgCode.EXIST006.get());
        }
        if (StringUtil.isEmpty(entity.getGender())) {
            return ActionResult.fail(MsgCode.PS020.get());
        }
        userService.create(entity);
        String catchKey = cacheKeyUtil.getAllUser();
        if (redisUtil.exists(catchKey)) {
            redisUtil.remove(catchKey);
        }
        BaseSystemInfo sysInfo = sysconfigApi.getSysInfo(UserProvider.getUser().getTenantId());
        entity.setPassword(sysInfo.getNewUserDefaultPassword());
        PullUserUtil.syncUser(entity, "create", UserProvider.getUser().getTenantId());
        return ActionResult.success(MsgCode.SU001.get());
    }
 
    @Operation(summary = "修改用户")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true),
            @Parameter(name = "userUpForm", description = "表单参数", required = true)
    })
    @SaCheckPermission("permission.user")
    @PutMapping("/{id}")
    public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid UserUpForm userUpForm) throws Exception {
        UserEntity entity = JsonUtil.getJsonToBean(userUpForm, UserEntity.class);
        if (StringUtil.isEmpty(entity.getGender())) {
            return ActionResult.fail(MsgCode.PS020.get());
        }
        //将禁用的id加进数据
        UserEntity originUser = userService.getInfo(id);
        UserInfoVO infoVO = this.getInfo(id).getData();
        // 如果是管理员的话
        if ("1".equals(String.valueOf(originUser.getIsAdministrator()))) {
            UserInfo operatorUser = UserProvider.getUser();
            // 管理员可以修改自己,但是无法修改其他管理员
            if (operatorUser.getIsAdministrator()) {
                if (originUser.getEnabledMark() != 0 && entity.getEnabledMark() == 0) {
                    return ActionResult.fail(MsgCode.PS021.get());
                }
                if (!ADMIN_KEY.equals(userService.getInfo(operatorUser.getUserId()).getAccount())) {
                    if (!operatorUser.getUserId().equals(id)) {
                        return ActionResult.fail(MsgCode.PS022.get());
                    }
                }
            } else {
                return ActionResult.fail(MsgCode.PS023.get());
            }
        }
 
        if (!originUser.getAccount().equals(entity.getAccount())) {
            if (userService.isExistByAccount(entity.getAccount())) {
                return ActionResult.fail(MsgCode.EXIST001.get());
            }
        }
        // 如果账号被锁定
        if ("2".equals(String.valueOf(entity.getEnabledMark()))) {
            entity.setUnlockTime(null);
            entity.setLogErrorCount(0);
        }
        // 如果原来是锁定,现在不锁定,则置空错误次数
        if (originUser.getEnabledMark() == 2 && entity.getEnabledMark() == 1) {
            entity.setUnlockTime(null);
            entity.setLogErrorCount(0);
        }
        boolean flag = userService.update(id, entity);
        ThreadPoolExecutorUtil.getExecutor().execute(() -> {
            try {
                //修改用户之后判断是否需要同步到企业微信
                synThirdInfoApi.updateUserSysToQy(new SynThirdQyModel(false, entity, "", 1));
                //修改用户之后判断是否需要同步到钉钉
                synThirdInfoApi.updateUserSysToDing(new SynThirdQyModel(false, entity, "", 1));
            } catch (Exception e) {
                log.error("修改用户之后同步失败到企业微信或钉钉失败,异常: {}", e.getMessage());
            }
        });
        if (!flag) {
            return ActionResult.fail(MsgCode.FA002.get());
        }
        // 踢出在线的用户
        if (Objects.equals(entity.getEnabledMark(), 0)) {
            userService.logoutUser(MsgCode.LOG208.get(), ImmutableList.of(entity.getId()));
        } else if (Objects.equals(entity.getEnabledMark(), 2)) {
            userService.logoutUser(MsgCode.LOG209.get(), ImmutableList.of(entity.getId()));
        }
        PullUserUtil.syncUser(entity, "update", UserProvider.getUser().getTenantId());
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    @Operation(summary = "删除用户")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true)
    })
    @SaCheckPermission("permission.user")
    @DeleteMapping("/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        UserEntity entity = userService.getInfo(id);
        if (entity != null) {
            if ("1".equals(String.valueOf(entity.getIsAdministrator()))) {
                return ActionResult.fail(MsgCode.PS026.get());
            }
            //判断是否是部门主管
            if (!(organizeService.getList(false).stream().filter(t -> id.equals(t.getManagerId())).count() == 0)) {
                return ActionResult.fail(MsgCode.PS027.get());
            }
            String tenantId = StringUtil.isEmpty(UserProvider.getUser().getTenantId()) ? "" : UserProvider.getUser().getTenantId();
            String catchKey = tenantId + "allUser" ;
            if (redisUtil.exists(catchKey)) {
                redisUtil.remove(catchKey);
            }
 
            //删除之前进行判断
            List<UserRelationEntity> relationEntities = userRelationService.getListByUserId(id, PermissionConst.ORGANIZE);
            SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
            String dingDepartment = socialsConfig.getDingDepartment();
            String qyhDepartment = socialsConfig.getQyhDepartment();
            boolean dingChoice;
            boolean qyChoice;
            OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
            OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
            if (ObjectUtil.isNotEmpty(dingOrg)) {
                dingChoice = relationEntities.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
            } else {
                dingChoice = true;
            }
            if (ObjectUtil.isNotEmpty(qyQrg)) {
                qyChoice = relationEntities.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
            } else {
                qyChoice = true;
            }
            userService.delete(entity);
            ThreadPoolExecutorUtil.getExecutor().execute(() -> {
                try {
                    //删除用户之后判断是否需要同步到企业微信
                    if (!qyChoice){
                        synThirdInfoApi.deleteUserSysToQy(new SysThirdDeleteModel(false, id, ""));
                    }
 
                    //删除用户之后判断是否需要同步到钉钉
                    if (!dingChoice){
                        synThirdInfoApi.deleteUserSysToDing(new SysThirdDeleteModel(false, id, ""));
                    }
                } catch (Exception e) {
                    log.error("删除用户之后同步失败到企业微信或钉钉失败,异常:" + e.getMessage());
                }
            });
            userService.logoutUser(MsgCode.LOG207.get(), ImmutableList.of(entity.getId()));
            PullUserUtil.syncUser(entity, "delete", UserProvider.getUser().getTenantId());
            return ActionResult.success(MsgCode.SU003.get());
        }
        return ActionResult.fail(MsgCode.FA003.get());
    }
 
    //++++++++++++++++++++++批量操作start+++++++++++++++++++++++++
    @Operation(summary = "批量删除")
    @Parameters({
            @Parameter(name = "idList", description = "用户id列表", required = true)
    })
    @SaCheckPermission("permission.user")
    @PostMapping("/BatchDelete")
    public ActionResult BatchDelete(@RequestBody UserBatchForm form) {
        List<UserEntity> listByUserIds = userService.getListByUserIds(form.getIds());
        List<String> userIdList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(listByUserIds)) {
            List<String> collect = listByUserIds.stream().filter(t ->
                    !Objects.equals("1", t.getIsAdministrator())).map(UserEntity::getId).collect(Collectors.toList());
            userIdList.addAll(collect);
        } else {
            return ActionResult.fail(MsgCode.FA003.get());
        }
        if (CollectionUtil.isEmpty(userIdList)) {
            return ActionResult.fail(MsgCode.PS026.get());
        }
        if (redisUtil.exists(cacheKeyUtil.getAllUser())) {
            redisUtil.remove(cacheKeyUtil.getAllUser());
        }
        SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
        String dingDepartment = socialsConfig.getDingDepartment();
        String qyhDepartment = socialsConfig.getQyhDepartment();
 
        OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
        OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
        for (UserEntity userItem : listByUserIds) {
            if (userIdList.contains(userItem.getId())) {
                String id = userItem.getId();
                List<UserRelationEntity> relationEntities = userRelationService.getListByUserId(id, PermissionConst.ORGANIZE);
 
                boolean dingChoice;
                boolean qyChoice;
                if (ObjectUtil.isNotEmpty(dingOrg)) {
                    dingChoice = relationEntities.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
                } else {
                    dingChoice = true;
                }
                if (ObjectUtil.isNotEmpty(qyQrg)) {
                    qyChoice = relationEntities.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
                } else {
                    qyChoice = true;
                }
                ThreadPoolExecutorUtil.getExecutor().execute(() -> {
                    try {
                        //删除用户之后判断是否需要同步到企业微信
                        if (!qyChoice){
                            synThirdInfoApi.deleteUserSysToQy(new SysThirdDeleteModel(false, id, ""));
                        }
 
                        //删除用户之后判断是否需要同步到钉钉
                        if (!dingChoice){
                            synThirdInfoApi.deleteUserSysToDing(new SysThirdDeleteModel(false, id, ""));
                        }
 
                    } catch (Exception e) {
                        log.error("删除用户之后同步失败到企业微信或钉钉失败,异常:" + e.getMessage());
                    }
                });
                PullUserUtil.syncUser(userItem, "delete", UserProvider.getUser().getTenantId());
            }
        }
 
        userService.batchDelete(userIdList);
        userService.logoutUser(MsgCode.LOG207.get(), userIdList);
 
 
        return ActionResult.success(MsgCode.SU003.get());
    }
 
    @Operation(summary = "批量更新状态:锁定、禁用、删除")
    @Parameters({
            @Parameter(name = "idList", description = "用户id列表", required = true),
            @Parameter(name = "enableMark", description = "用户id列表", required = true)
    })
    @SaCheckPermission("permission.user")
    @PostMapping("/BatchUpdateState")
    public ActionResult<String> BatchUpdateState(@RequestBody UserBatchForm form) {
        if (CollectionUtil.isNotEmpty(form.getIds())) {
            List<UserEntity> listByUserIds = userService.getListByUserIds(form.getIds());
            if (CollectionUtil.isNotEmpty(listByUserIds)) {
                try {
                    for (UserEntity entity : listByUserIds) {
                        if (Objects.equals(entity.getIsAdministrator(), 1)) {
                            continue;
                        }
                        entity.setEnabledMark(form.getEnabledMark());
                        userService.update(entity.getId(), entity);
                        //禁用移除在线用户
                        if (Objects.equals(form.getEnabledMark(), 0)) {
                            userService.logoutUser(MsgCode.LOG208.get(), ImmutableList.of(entity.getId()));
                        } else if (Objects.equals(form.getEnabledMark(), 2)) {
                            userService.logoutUser(MsgCode.LOG209.get(), ImmutableList.of(entity.getId()));
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return ActionResult.success(MsgCode.SU005.get());
            }
        }
        return ActionResult.success(MsgCode.FA001.get());
    }
    //++++++++++++++++++++++批量操作end+++++++++++++++++++++++++
 
    /**
     * 获取用户列表
     *
     * @return ignore
     */
    @Operation(summary = "获取所有用户列表")
    @GetMapping("/All")
    public ActionResult<ListVO<UserAllVO>> getAllUsers(PaginationUser pagination) {
        List<UserEntity> list = userService.getList(pagination, null, false, false, null, null);
        List<UserAllVO> user = JsonUtil.getJsonToList(list, UserAllVO.class);
        ListVO<UserAllVO> vo = new ListVO<>();
        vo.setList(user);
        return ActionResult.success(vo);
    }
 
    /**
     * IM通讯获取用户接口
     *
     * @param pagination 分页参数
     * @return ignore
     */
    @Operation(summary = "IM通讯获取用户")
    @GetMapping("/ImUser")
    public ActionResult<PageListVO<ImUserListVo>> getAllImUserUsers(Pagination pagination) {
        PageUser pageUser = JsonUtil.getJsonToBean(pagination, PageUser.class);
        List<UserEntity> data = userService.getList(pageUser, true);
        List<ImUserListVo> list = new ArrayList<>();
        Map<String, OrganizeEntity> orgMaps = organizeService.getOrganizeName(data.stream().map(t -> t.getOrganizeId()).collect(Collectors.toList()), null, false, null);
        for (UserEntity entity : data) {
            ImUserListVo user = JsonUtil.getJsonToBean(entity, ImUserListVo.class);
            OrganizeEntity organize = orgMaps.get(entity.getOrganizeId());
            user.setDepartment(organize != null ? organize.getFullName() : "");
            user.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
            list.add(user);
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    /**
     * 获取用户下拉框列表
     *
     * @return ignore
     */
    @Operation(summary = "获取用户下拉框列表")
    @GetMapping("/Selector")
    public ActionResult<ListVO<UserSelectorVO>> selector() {
        Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
        List<OrganizeEntity> organizeData = new ArrayList<>(orgMaps.values());
        List<UserEntity> userData = userService.getList(true);
        List<UserSelectorModel> treeList = JsonUtil.getJsonToList(organizeData, UserSelectorModel.class);
        for (UserSelectorModel entity1 : treeList) {
            if ("department".equals(entity1.getType())) {
                entity1.setIcon(PermissionConst.DEPARTMENT_ICON);
            } else if ("company".equals(entity1.getType())) {
                entity1.setIcon(PermissionConst.COMPANY_ICON);
            }
        }
        for (UserEntity entity : userData) {
            UserSelectorModel treeModel = new UserSelectorModel();
            treeModel.setId(entity.getId());
            treeModel.setParentId(entity.getOrganizeId());
            treeModel.setFullName(entity.getRealName() + "/" + entity.getAccount());
            treeModel.setType("user");
            treeModel.setIcon(PermissionConst.USER_ICON);
            treeList.add(treeModel);
        }
        List<SumTree<UserSelectorModel>> trees = TreeDotUtils.convertListToTreeDot(treeList);
        List<UserSelectorVO> listvo = JsonUtil.getJsonToList(trees, UserSelectorVO.class);
        List<OrganizeEntity> entities = organizeData.stream().filter(
                t -> "-1".equals(t.getParentId())
        ).collect(Collectors.toList());
        Iterator<UserSelectorVO> iterator = listvo.iterator();
        while (iterator.hasNext()) {
            UserSelectorVO userSelectorVO = iterator.next();
            for (OrganizeEntity entity : entities) {
                if (entity.getId().equals(userSelectorVO.getParentId())) {
                    iterator.remove();//使用迭代器的删除方法删除
                }
            }
        }
        ListVO<UserSelectorVO> vo = new ListVO<>();
        vo.setList(listvo);
        return ActionResult.success(vo);
    }
 
    /**
     * 通过部门、岗位、用户、角色、分组id获取用户列表
     *
     * @param userConditionModel 用户选择模型
     * @return
     */
    @Operation(summary = "通过部门、岗位、用户、角色、分组id获取用户列表")
    @Parameters({
            @Parameter(name = "userConditionModel", description = "用户选择模型", required = true)
    })
    @PostMapping("/UserCondition")
    public ActionResult userCondition(@RequestBody UserConditionModel userConditionModel) {
        List<String> list = new ArrayList<>(16);
        if (userConditionModel.getDepartIds() != null) {
            list.addAll(userConditionModel.getDepartIds());
        }
        if (userConditionModel.getRoleIds() != null) {
            list.addAll(userConditionModel.getRoleIds());
        }
        if (userConditionModel.getPositionIds() != null) {
            list.addAll(userConditionModel.getPositionIds());
        }
        if (userConditionModel.getGroupIds() != null) {
            list.addAll(userConditionModel.getGroupIds());
        }
        if (list.size() == 0) {
            list = userRelationService.getListByObjectType(userConditionModel.getType()).stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
            if (PermissionConst.GROUP.equals(userConditionModel.getType())) {
                List<GroupEntity> groupList = groupService.getListByIds(list);
                list = groupList.stream().map(GroupEntity::getId).collect(Collectors.toList());
            }
            if (PermissionConst.ORGANIZE.equals(userConditionModel.getType())) {
                List<OrganizeEntity> orgList = organizeService.getOrgEntityList(list, true);
                list = orgList.stream().map(OrganizeEntity::getId).collect(Collectors.toList());
            }
            if (PermissionConst.ROLE.equals(userConditionModel.getType())) {
                List<RoleEntity> roleList = roleService.getListByIds(list, null, false);
                list = roleList.stream().filter(t -> t.getEnabledMark() == 1).map(RoleEntity::getId).collect(Collectors.toList());
            }
            if (PermissionConst.POSITION.equals(userConditionModel.getType())) {
                List<PositionEntity> positionList = positionService.getPosList(list);
                list = positionList.stream().filter(t -> t.getEnabledMark() == 1).map(PositionEntity::getId).collect(Collectors.toList());
            }
        }
        List<String> collect = userRelationService.getListByObjectIdAll(list).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
        if (userConditionModel.getUserIds() != null) {
            collect.addAll(userConditionModel.getUserIds());
        }
        collect = collect.stream().distinct().collect(Collectors.toList());
        List<UserEntity> userName = userService.getUserName(collect, userConditionModel.getPagination());
        List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(userName, UserIdListVo.class);
        Map<String, String> orgIdNameMaps = organizeService.getInfoList();
        jsonToList.forEach(t -> {
            t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
            t.setFullName(t.getRealName() + "/" + t.getAccount());
            List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(t.getId(), PermissionConst.ORGANIZE);
            List<String> orgId = listByUserId.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
            List<OrganizeEntity> organizeName = new ArrayList<>(organizeService.getOrganizeName(orgId, null, false, null).values());
            StringBuilder stringBuilder = new StringBuilder();
            organizeName.forEach(org -> {
                if (StringUtil.isNotEmpty(org.getOrganizeIdTree())) {
                    String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, org.getOrganizeIdTree(), "/");
                    stringBuilder.append(",");
                    stringBuilder.append(fullNameByOrgIdTree);
                }
            });
            if (stringBuilder.length() > 0) {
                t.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
            }
        });
        PaginationVO paginationVO = JsonUtil.getJsonToBean(userConditionModel.getPagination(), PaginationVO.class);
        return ActionResult.page(jsonToList, paginationVO);
    }
 
    /**
     * 获取用户下拉框列表
     *
     * @param organizeIdForm 组织id
     * @param pagination     分页模型
     * @return
     */
    @Operation(summary = "获取用户下拉框列表")
    @Parameters({
            @Parameter(name = "organizeId", description = "组织id", required = true),
            @Parameter(name = "pagination", description = "分页模型", required = true)
    })
    @PostMapping("/ImUser/Selector/{organizeId}")
    public ActionResult<?> imUserSelector(@PathVariable("organizeId") String organizeIdForm, @RequestBody Pagination pagination) {
        String organizeId = XSSEscape.escape(organizeIdForm);
        List<UserSelectorVO> jsonToList = new ArrayList<>();
        Map<String, String> orgIdNameMaps = organizeService.getInfoList();
        Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
        //判断是否搜索关键字
        if (StringUtil.isNotEmpty(pagination.getKeyword())) {
            //通过关键字查询
            PageUser pageUser = JsonUtil.getJsonToBean(pagination, PageUser.class);
            List<UserEntity> list = userService.getList(pageUser, false);
            //遍历用户给要返回的值插入值
            for (UserEntity entity : list) {
                UserSelectorVO vo = JsonUtil.getJsonToBean(entity, UserSelectorVO.class);
                vo.setParentId(entity.getOrganizeId());
                vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
                vo.setType("user");
                vo.setIcon(PermissionConst.USER_ICON);
                vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
                List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
                StringJoiner stringJoiner = new StringJoiner(",");
                listByUserId.forEach(t -> {
                    OrganizeEntity organizeEntity = orgMaps.get(t.getObjectId());
                    if (organizeEntity != null) {
                        String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
                        if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
                            stringJoiner.add(fullNameByOrgIdTree);
                        }
                    }
                });
                vo.setOrganize(stringJoiner.toString());
                vo.setHasChildren(false);
                vo.setIsLeaf(true);
                jsonToList.add(vo);
            }
            PaginationVO jsonToBean = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
            return ActionResult.page(jsonToList, jsonToBean);
        }
        //获取所有组织
        List<OrganizeEntity> collect = new ArrayList<>(orgMaps.values());
        //判断时候传入组织id
        //如果传入组织id,则取出对应的子集
        if (!"0".equals(organizeId)) {
            //通过组织查询部门及人员
            //单个组织
            OrganizeEntity organizeEntity = orgMaps.get(organizeId);
            if (organizeEntity != null) {
                //取出组织下的部门
                List<OrganizeEntity> collect1 = collect.stream().filter(t -> t.getParentId().equals(organizeEntity.getId())).collect(Collectors.toList());
                for (OrganizeEntity entitys : collect1) {
                    UserSelectorVO vo = JsonUtil.getJsonToBean(entitys, UserSelectorVO.class);
                    if ("department".equals(entitys.getCategory())) {
                        vo.setIcon(PermissionConst.DEPARTMENT_ICON);
                    } else if ("company".equals(entitys.getCategory())) {
                        vo.setIcon(PermissionConst.COMPANY_ICON);
                    }
                    vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entitys.getOrganizeIdTree(), "/"));
                    // 判断组织下是否有人
                    jsonToList.add(vo);
                    vo.setHasChildren(true);
                    vo.setIsLeaf(false);
                }
                //取出组织下的人员
                List<UserEntity> entityList = userService.getListByOrganizeId(organizeId, null);
                for (UserEntity entity : entityList) {
                    if ("0".equals(String.valueOf(entity.getEnabledMark()))) {
                        continue;
                    }
                    UserSelectorVO vo = JsonUtil.getJsonToBean(entity, UserSelectorVO.class);
                    vo.setParentId(organizeId);
                    vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
                    vo.setType("user");
                    vo.setIcon(PermissionConst.USER_ICON);
                    List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
                    StringBuilder stringBuilder = new StringBuilder();
                    listByUserId.forEach(t -> {
                        OrganizeEntity organizeEntity1 = orgMaps.get(t.getObjectId());
                        if (organizeEntity1 != null) {
                            String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity1.getOrganizeIdTree(), "/");
                            if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
                                stringBuilder.append("," + fullNameByOrgIdTree);
                            }
                        }
                    });
                    if (stringBuilder.length() > 0) {
                        vo.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
                    }
                    vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
                    vo.setHasChildren(false);
                    vo.setIsLeaf(true);
                    jsonToList.add(vo);
                }
            }
            ListVO<UserSelectorVO> vo = new ListVO<>();
            vo.setList(jsonToList);
            return ActionResult.success(vo);
        }
 
        //如果没有组织id,则取出所有组织
        jsonToList = JsonUtil.getJsonToList(collect.stream().filter(t -> "-1".equals(t.getParentId())).collect(Collectors.toList()), UserSelectorVO.class);
        //添加图标
        for (UserSelectorVO userSelectorVO : jsonToList) {
            userSelectorVO.setIcon(PermissionConst.COMPANY_ICON);
            userSelectorVO.setHasChildren(true);
            userSelectorVO.setIsLeaf(false);
            userSelectorVO.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, orgMaps.get(userSelectorVO.getId()).getOrganizeIdTree(), "/"));
        }
        ListVO<UserSelectorVO> vo = new ListVO<>();
        vo.setList(jsonToList);
        return ActionResult.success(vo);
    }
 
    @Operation(summary = "个人权限")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true),
    })
    @GetMapping("/Authorize")
    public ActionResult<UserAuthorizeVO> getAuthorize(UserAuthForm param) {
        return ActionResult.success(authPermUtil.getUserAuth(param));
    }
 
    @Operation(summary = "角色岗位权限列表")
    @GetMapping("/getAllPermission")
    public ActionResult<List<PositionVo>> getAllPermission(@RequestParam(value = "userId", required = false) String userId) {
        if (StringUtil.isEmpty(userId)) {
            userId = UserProvider.getUser().getUserId();
        }
        List<PositionVo> listRes = new ArrayList<>();
        listRes.add(new PositionVo("all", "全部权限"));
        //添加岗位
        List<String> posIds = userRelationService.getListByUserId(userId, PermissionConst.POSITION).stream().map(u -> u.getObjectId()).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(posIds)) {
            PositionVo pv = new PositionVo(PermissionConst.POSITION, "所属岗位");
            pv.setHasChildren(true);
            List<PositionVo> child = new ArrayList<>();
            Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
            List<PositionEntity> rList = positionService.getListByIds(posIds);
            for (PositionEntity item : rList) {
                PositionVo vo = JsonUtil.getJsonToBean(item, PositionVo.class);
                vo.setFullName(allOrgsTreeName.get(item.getOrganizeId()) + "/" + item.getFullName());
                vo.setType(PermissionConst.POSITION);
                child.add(vo);
            }
            pv.setChildren(child);
            listRes.add(pv);
        }
        //添加角色
        List<String> roleIds = roleRelationService.getListByObjectId(userId, PermissionConst.USER)
                .stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(roleIds)) {
            PositionVo pv = new PositionVo(PermissionConst.ROLE, "所属角色");
            pv.setHasChildren(true);
 
            List<PositionVo> child = new ArrayList<>();
            List<RoleEntity> rList = roleService.getListByIds(roleIds);
            for (RoleEntity item : rList) {
                PositionVo vo = JsonUtil.getJsonToBean(item, PositionVo.class);
                vo.setType(PermissionConst.ROLE);
                child.add(vo);
            }
            pv.setChildren(child);
            listRes.add(pv);
        }
        return ActionResult.success(listRes);
    }
 
    @Operation(summary = "用户获取岗位")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true),
    })
    @SaCheckPermission("permission.user")
    @GetMapping("/{id}/GetPosition")
    public ActionResult<List<PositionListVO>> GetPosition(@PathVariable("id") String id) {
        UserEntity entity = userService.getInfo(id);
        List<PositionListVO> list = new ArrayList<>();
        if (entity != null) {
            List<UserRelationEntity> relationList = userRelationService.getListByUserId(id, PermissionConst.POSITION);
            Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
            List<PositionEntity> positionList = positionService.getListByIds(relationList.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList()));
            for (PositionEntity item : positionList) {
                PositionListVO vo = JsonUtil.getJsonToBean(item, PositionListVO.class);
                vo.setOrgNameTree(allOrgsTreeName.get(item.getOrganizeId()) + "/" + item.getFullName());
                list.add(vo);
            }
        }
        return ActionResult.success(list);
    }
 
    @Operation(summary = "同岗位用户列表")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true),
    })
    @SaCheckPermission("permission.user")
    @GetMapping("/{id}/SelectorByUserPosId")
    public ActionResult<PageListVO<UserListVO>> SelectorByUserPosId(@PathVariable("id") String id, Pagination pagination) {
        UserEntity entity = userService.getInfo(id);
        PageUser pageUser = JsonUtil.getJsonToBean(pagination, PageUser.class);
        List<UserListVO> list = new ArrayList<>();
        if (entity != null) {
            List<UserRelationEntity> relationList = userRelationService.getListByUserId(id, PermissionConst.POSITION);
            List<String> posIds = relationList.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
            List<String> userIds = userRelationService.getListByObjectIdAll(posIds).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(userIds)) {
                pageUser.setIdList(userIds);
                List<UserEntity> userList = userService.getList(pageUser, true);
                for (UserEntity item : userList) {
                    UserListVO vo = JsonUtil.getJsonToBean(item, UserListVO.class);
                    vo.setFullName(item.getRealName() + "/" + item.getAccount());
                    vo.setHeadIcon(UploaderUtil.uploaderImg(item.getHeadIcon()));
                    list.add(vo);
                }
            }
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pageUser, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    @Operation(summary = "用户调整岗位")
    @Parameters({
            @Parameter(name = "id", description = "用户主键值", required = true)
    })
    @SaCheckPermission("permission.user")
    @PostMapping("/{id}/SetPosition")
    public ActionResult setPosition(@PathVariable("id") String id, @RequestBody UserBatchForm form) {
        UserEntity entity = userService.getInfo(id);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        if (Objects.equals(entity.getIsAdministrator(), 1)) {
            return ActionResult.success(MsgCode.PS023.get());
        }
 
        List<String> posIds = form.getIds();
        List<UserRelationEntity> relationList = userRelationService.getListByUserId(id, PermissionConst.POSITION);
        //直接打开不编辑保存不执行代码
        if (!posIds.isEmpty() && posIds.equals(relationList.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList()))) {
            return ActionResult.success(MsgCode.SU023.get());
        }
 
        List<PositionEntity> posList = positionService.getListByIds(posIds);
        //判断约束  -- 逐一判断,能成功的就添加res
        List<String> res = new ArrayList<>();
        Set<String> huchi = new HashSet<>();
        Set<String> xianjue = new HashSet<>();
        List<String> errList1 = new ArrayList<>();
        filterPos(posIds, posList, errList1, huchi, res, xianjue);
        //先决第一个判断不存在,再次判断后续有没有添加上先决的
        if (CollectionUtil.isNotEmpty(xianjue)) {
            filterXianJuePos(new ArrayList<>(xianjue), posList, errList1, res);
        }
        //只有出现约束异常就直接修改失败
        if (CollectionUtil.isNotEmpty(errList1)) {
            return ActionResult.fail(MsgCode.FA055.get(MsgCode.PS004.get()));
        }
 
        List<UserRelationEntity> orgList = userRelationService.getListByUserId(id, PermissionConst.ORGANIZE);
        //移除全部岗位、组织和用户得关系
        List<UserRelationEntity> deleteAll = new ArrayList<>();
        deleteAll.addAll(relationList);
        deleteAll.addAll(orgList);
 
        //删除之前进行判断
        SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
        String dingDepartment = socialsConfig.getDingDepartment();
        String qyhDepartment = socialsConfig.getQyhDepartment();
        boolean dingChoice;
        boolean qyChoice;
        OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
        OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
        if (ObjectUtil.isNotEmpty(dingOrg)) {
            dingChoice = deleteAll.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
        } else {
            dingChoice = true;
        }
        if (ObjectUtil.isNotEmpty(qyQrg)) {
            qyChoice = deleteAll.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
        } else {
            qyChoice = true;
        }
        for (UserRelationEntity relationEntity : deleteAll) {
            userRelationService.removeById(relationEntity);
        }
        ThreadPoolExecutorUtil.getExecutor().execute(() -> {
            try {
                //获取公司关联
                List<String> collect = deleteAll.stream()
                        .filter(t -> t.getObjectType().equals(PermissionConst.ORGANIZE))
                        .map(UserRelationEntity::getObjectId).collect(Collectors.toList());
                if (!qyChoice){
                    synThirdInfoApi.deleteUserSysToQy(new SysThirdDeleteModel(false, entity.getId(), ""));
                }
                if (!dingChoice){
                    synThirdInfoApi.deleteUserSysToDing(new SysThirdDeleteModel(false, entity.getId(), ""));
                }
 
 
 
            } catch (Exception e) {
                log.error("创建组织后同步失败到钉钉失败,异常:{}", e.getMessage());
            }
        });
        List<UserRelationEntity> addAll = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(res)) {
            for (String positionId : res) {
                PositionEntity info = posList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
                UserRelationEntity userRelation = new UserRelationEntity();
                userRelation.setObjectId(positionId);
                userRelation.setUserId(id);
                userRelation.setObjectType(PermissionConst.POSITION);
                addAll.add(userRelation);
                //岗位添加组织关系方便使用
                UserRelationEntity userOrgRelation = new UserRelationEntity();
                userOrgRelation.setObjectId(info.getOrganizeId());
                userOrgRelation.setUserId(id);
                userOrgRelation.setObjectType(PermissionConst.ORGANIZE);
                addAll.add(userOrgRelation);
            }
            userRelationService.save(addAll);
            ThreadPoolExecutorUtil.getExecutor().execute(() -> {
                try {
                    //获取公司关联
                    List<String> collect = addAll.stream()
                            .filter(t -> t.getObjectType().equals(PermissionConst.ORGANIZE))
                            .map(UserRelationEntity::getObjectId).collect(Collectors.toList());
                    synThirdInfoApi.createUserSysToQy(new SynThirdQyModel(false, entity, "", collect));
                    synThirdInfoApi.createUserSysToDing(new SynThirdQyModel(false, entity, "", collect));
 
 
                } catch (Exception e) {
                    log.error("创建组织后同步失败到企业微信或钉钉失败,异常:{}", e.getMessage());
                }
            });
            userService.delCurUser(MsgCode.PS010.get(), Collections.singletonList(id));
        }
        return ActionResult.success(MsgCode.SU023.get());
    }
 
    private void filterPos(List<String> posIds, List<PositionEntity> posList, List<String> errList1, Set<String> huchi, List<String> res, Set<String> xianjue) {
        for (String positionId : posIds) {
            List<String> errList2 = new ArrayList<>();
            PositionEntity info = posList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
            List<String> userIds = userRelationService.getListByObjectId(positionId, PermissionConst.POSITION)
                    .stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
            PosConModel posConModel = new PosConModel();
            if (Objects.equals(info.getIsCondition(), 1)) {
                posConModel = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
                posConModel.init();
            }
            //超出权限基数的截取
            if (posConModel.getNumFlag() && posConModel.getUserNum() < (1 + userIds.size())) {
                errList2.add(MsgCode.SYS135.get(MsgCode.PS004.get()));
            }
 
            //在已有岗位的互斥信息里
            if (huchi.contains(positionId)) {
                errList2.add(MsgCode.SYS137.get(MsgCode.PS004.get()));
            }
            //当前的岗位互斥信息-存在互斥岗位
            List<String> mutualExclusion = posConModel.getMutualExclusion();
            if (posConModel.getMutualExclusionFlag()) {
                //互斥
                List<String> collect = res.stream().filter(t -> mutualExclusion.contains(t)).collect(Collectors.toList());
                if (CollectionUtil.isNotEmpty(collect)) {
                    errList2.add(MsgCode.SYS137.get(MsgCode.PS004.get()));
                }
            }
            if (posConModel.getPrerequisiteFlag()) {
                //先决
                xianjue.add(positionId);
            }
            if (errList2.size() == 0) {
                res.add(positionId);
                if (CollectionUtil.isNotEmpty(mutualExclusion)) {
                    huchi.addAll(mutualExclusion);
                }
            } else {
                errList1.addAll(errList2);
            }
        }
    }
 
    private void filterXianJuePos(List<String> posIds, List<PositionEntity> posList, List<String> errList1, List<String> res) {
        for (String positionId : posIds) {
            List<String> errList2 = new ArrayList<>();
            PositionEntity info = posList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
            PosConModel posConModel = new PosConModel();
            if (Objects.equals(info.getIsCondition(), 1)) {
                posConModel = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
                posConModel.init();
            }
            if (posConModel.getPrerequisiteFlag() && !res.containsAll(posConModel.getPrerequisite())) {
                //先决
                errList2.add(MsgCode.SYS138.get(MsgCode.PS004.get()));
            }
            if (errList2.size() == 0) {
                res.add(positionId);
            } else {
                errList1.addAll(errList2);
            }
        }
    }
 
    @Operation(summary = "批量调整岗位")
    @SaCheckPermission("permission.user")
    @PostMapping("/SetPositionBatch")
    public ActionResult setPositionBatch(@RequestBody UserBatchForm form) {
        List<UserEntity> userList = userService.getListByUserIds(form.getUserIds());
        List<String> posIds = form.getIds();
        List<PositionEntity> positionList = positionService.getListByIds(posIds);
        if (CollectionUtil.isEmpty(userList)) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
 
 
        SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
        String dingDepartment = socialsConfig.getDingDepartment();
        String qyhDepartment = socialsConfig.getQyhDepartment();
        OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
        OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
        List<String> userIds = userList.stream().filter(t -> !Objects.equals(t.getIsAdministrator(), 1)).map(UserEntity::getId).collect(Collectors.toList());
        //再加
        List<String> addUserIds = new ArrayList<>();
        List<String> skipUserIds = new ArrayList<>();
        for (String userId : userIds) {
            List<UserRelationEntity> relationList = userRelationService.getListByObjectType(userId, null);
            //直接打开不编辑保存不执行代码
            if (posIds.size() > 0 && posIds.equals(relationList.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType()))
                    .map(UserRelationEntity::getObjectId).collect(Collectors.toList()))) {
                skipUserIds.add(userId);
                continue;
            }
 
            //判断约束
            List<String> res = new ArrayList<>();
            Set<String> huchi = new HashSet<>();
            Set<String> xianjue = new HashSet<>();
            List<String> errList1 = new ArrayList<>();
            filterPos(posIds, positionList, errList1, huchi, res, xianjue);
            //先决第一个判断不存在,再次判断后续有没有添加上先决的
            if (CollectionUtil.isNotEmpty(xianjue)) {
                filterXianJuePos(new ArrayList<>(xianjue), positionList, errList1, res);
            }
            //岗位有约束异常就不添加
            if (CollectionUtil.isNotEmpty(errList1)) {
                continue;
            }
            addUserIds.add(userId);
 
            List<UserRelationEntity> addAll = new ArrayList<>();
            for (String positionId : posIds) {
                PositionEntity info = positionList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
                UserRelationEntity userRelation = new UserRelationEntity();
                userRelation.setObjectId(info.getId());
                userRelation.setUserId(userId);
                userRelation.setObjectType(PermissionConst.POSITION);
                addAll.add(userRelation);
                //岗位添加组织关系方便使用
                UserRelationEntity userOrgRelation = new UserRelationEntity();
                userOrgRelation.setObjectId(info.getOrganizeId());
                userOrgRelation.setUserId(userId);
                userOrgRelation.setObjectType(PermissionConst.ORGANIZE);
                addAll.add(userOrgRelation);
            }
 
            //先删
            List<UserRelationEntity> deleteList = relationList.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType())
                    || PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
            //删除之前进行判断
 
            boolean dingChoice;
            boolean qyChoice;
 
            if (ObjectUtil.isNotEmpty(dingOrg)) {
                dingChoice = deleteList.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
            } else {
                dingChoice = true;
            }
            if (ObjectUtil.isNotEmpty(qyQrg)) {
                qyChoice = deleteList.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
            } else {
                qyChoice = true;
            }
 
            for (UserRelationEntity relationEntity : deleteList) {
                userRelationService.removeById(relationEntity);
            }
            try {
                List<String> collect = deleteList.stream()
                        .map(UserRelationEntity::getUserId)
                        .collect(Collectors.toList());
                if (!qyChoice){
                    synThirdInfoApi.deleteUserSysToQy(new SysThirdDeleteModel(false, collect, ""));
                }
                if (!dingChoice){
                    synThirdInfoApi.deleteUserSysToDing(new SysThirdDeleteModel(false, collect, ""));
                }
 
            } catch (Exception e) {
                log.error(e.getMessage());
            }
            userRelationService.save(addAll);
            try {
                Map<String, List<UserRelationEntity>> collect = addAll
                        .stream()
                        .filter(t -> t.getObjectType().equals(PermissionConst.POSITION))
                        .collect(Collectors.groupingBy(UserRelationEntity::getObjectId));
 
                for (String string : collect.keySet()) {
                    PositionEntity info = positionService.getInfo(string);
                    List<UserRelationEntity> userRelationEntities = collect.get(string);
                    List<String> userEntityIds = userRelationEntities.stream().map(UserRelationEntity::getUserId)
                            .collect(Collectors.toList());
                    List<UserEntity> userEntities = userService.getUserList(userEntityIds)
                            .stream().peek(t -> t.setOrganizeId(info.getOrganizeId()))
                            .collect(Collectors.toList());
                    synThirdInfoApi.createUserSysToQy(new SynThirdQyModel(false, userEntities, "", info.getId()));
                    synThirdInfoApi.createUserSysToDing(new SynThirdQyModel(false, userEntities, "", info.getId()));
                }
 
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }
 
        if (CollectionUtil.isNotEmpty(addUserIds)) {
            userService.delCurUser(MsgCode.PS010.get(), addUserIds);
        }
 
        if (addUserIds.size() == 0 && skipUserIds.size() == 0) {
            return ActionResult.fail(MsgCode.FA054.get());
        } else if (addUserIds.size() > 0 && addUserIds.size() != userIds.size()) {
            return ActionResult.success(MsgCode.SU024.get());
        }
        return ActionResult.success(MsgCode.SU023.get());
    }
 
    @Operation(summary = "修改用户密码")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true),
            @Parameter(name = "userResetPasswordForm", description = "修改密码模型", required = true)
    })
    @SaCheckPermission("permission.user")
    @PostMapping("/{id}/Actions/ResetPassword")
    public ActionResult<String> modifyPassword(@PathVariable("id") String id, @RequestBody @Valid UserResetPasswordForm userResetPasswordForm) {
        UserEntity entity = userService.getInfo(id);
        if (entity != null) {
            entity.setPassword(userResetPasswordForm.getUserPassword());
            userService.updatePassword(entity);
            userService.logoutUser(MsgCode.PS011.get(), ImmutableList.of(entity.getId()));
            entity.setPassword(userResetPasswordForm.getUserPassword());
            PullUserUtil.syncUser(entity, "modifyPassword", UserProvider.getUser().getTenantId());
            return ActionResult.success(MsgCode.SU005.get());
        }
        return ActionResult.success(MsgCode.FA001.get());
    }
 
    /**
     * 更新用户状态
     *
     * @param id 主键值
     * @return ignore
     */
    @Operation(summary = "更新用户状态")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true)
    })
    @SaCheckPermission("permission.user")
    @PutMapping("/{id}/Actions/State")
    public ActionResult<String> disable(@PathVariable("id") String id) throws Exception {
        UserEntity entity = userService.getInfo(id);
        if (entity != null) {
            if ("1".equals(String.valueOf(entity.getIsAdministrator()))) {
                return ActionResult.fail(MsgCode.PS029.get());
            }
            if (entity.getEnabledMark() != null) {
                if ("1".equals(String.valueOf(entity.getEnabledMark()))) {
                    entity.setEnabledMark(0);
                    userService.delCurUser(null, ImmutableList.of(entity.getId()));
                    userService.update(id, entity);
                } else {
                    entity.setEnabledMark(1);
                    userService.update(id, entity);
                }
            } else {
                entity.setEnabledMark(1);
                userService.update(id, entity);
            }
            return ActionResult.success(MsgCode.SU005.get());
        }
        return ActionResult.success(MsgCode.FA001.get());
    }
 
    /**
     * 解除锁定
     *
     * @param id 主键值
     * @return ignore
     */
    @Operation(summary = "解除锁定")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true)
    })
    @SaCheckPermission("permission.user")
    @PutMapping("/{id}/Actions/unlock")
    public ActionResult<String> unlock(@PathVariable("id") String id) throws Exception {
        UserEntity entity = userService.getInfo(id);
        if (entity != null) {
            // 状态变成正常
            entity.setEnabledMark(1);
            entity.setUnlockTime(null);
            entity.setLogErrorCount(0);
            entity.setId(id);
            userService.updateById(entity);
            return ActionResult.success(MsgCode.SU005.get());
        }
        return ActionResult.success(MsgCode.FA001.get());
    }
 
    /**
     * 获取用户基本信息
     *
     * @param userIdModel 用户id
     * @return ignore
     */
    @Operation(summary = "获取用户基本信息")
    @Parameters({
            @Parameter(name = "userIdModel", description = "用户id", required = true)
    })
    @PostMapping("/getUserList")
    public ActionResult<ListVO<UserIdListVo>> getUserList(@RequestBody UserIdModel userIdModel) {
        List<UserEntity> userName = userService.getUserName(userIdModel.getIds(), true);
        List<UserIdListVo> list = JsonUtil.getJsonToList(userName, UserIdListVo.class);
        List<UserRelationEntity> listByUserIds = userRelationService.getRelationByUserIds(list.stream().map(UserIdListVo::getId).collect(Collectors.toList()));
        Map<String, String> orgIdNameMaps = organizeService.getInfoList();
        for (UserIdListVo entity : list) {
            if (entity == null) {
                break;
            }
            entity.setFullName(entity.getRealName() + "/" + entity.getAccount());
            List<UserRelationEntity> listByUserId = listByUserIds.stream().filter(t -> t.getUserId().equals(entity.getId())).collect(Collectors.toList());
            StringBuilder stringBuilder = new StringBuilder();
            List<OrganizeEntity> orgEntityList = organizeService.getOrgEntityList(listByUserId.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList()), false);
            listByUserId.forEach(t -> {
                OrganizeEntity organizeEntity = orgEntityList.stream().filter(org -> org.getId().equals(t.getObjectId())).findFirst().orElse(null);
                if (organizeEntity != null) {
                    String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
                    if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
                        stringBuilder.append("," + fullNameByOrgIdTree);
                    }
                }
            });
            if (stringBuilder.length() > 0) {
                entity.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
            }
            entity.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
        }
        ListVO<UserIdListVo> listVO = new ListVO<>();
        listVO.setList(list);
        return ActionResult.success(listVO);
    }
 
    /**
     * 获取选中组织、岗位、角色、用户基本信息
     *
     * @param userIdModel 用户id
     * @return ignore
     */
    @Operation(summary = "获取选中组织、岗位、角色、用户基本信息")
    @Parameters({
            @Parameter(name = "userIdModel", description = "用户id", required = true)
    })
    @PostMapping("/getSelectedList")
    public ActionResult<ListVO<BaseInfoVo>> getSelectedList(@RequestBody UserIdModel userIdModel) {
        List<String> ids = userIdModel.getIds();
        List<BaseInfoVo> list = userService.selectedByIds(ids);
 
        ListVO<BaseInfoVo> listVO = new ListVO<>();
        listVO.setList(list);
        return ActionResult.success(listVO);
    }
 
 
    /**
     * 获取用户基本信息
     *
     * @param userIdModel 用户id
     * @return ignore
     */
    @Operation(summary = "获取选中用户基本信息")
    @Parameters({
            @Parameter(name = "userIdModel", description = "用户id", required = true)
    })
    @PostMapping("/getSelectedUserList")
    public ActionResult<PageListVO<BaseInfoVo>> getSelectedUserList(@RequestBody UserIdModelByPage userIdModel) {
        List<BaseInfoVo> jsonToList = userService.getObjList(userIdModel.getIds(), userIdModel);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(userIdModel, PaginationVO.class);
        return ActionResult.page(jsonToList, paginationVO);
 
    }
 
    /**
     * 获取组织下的人员
     *
     * @param page 页面信息
     * @return ignore
     */
    @Operation(summary = "获取组织下的人员")
    @GetMapping("/getOrganization")
    public ActionResult<List<UserIdListVo>> getOrganization(PageUser page) {
        String departmentId = page.getOrganizeId();
        // 判断是否获取当前组织下的人员
        if ("0".equals(departmentId)) {
            departmentId = UserProvider.getUser().getDepartmentId();
            // 为空则取组织id
            if (StringUtil.isEmpty(departmentId)) {
                departmentId = UserProvider.getUser().getOrganizeId();
            }
        }
        Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
        List<UserEntity> list = userService.getListByOrganizeId(departmentId, page.getKeyword());
        List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(list, UserIdListVo.class);
        Map<String, String> orgIdNameMaps = organizeService.getInfoList();
        List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(PermissionConst.ORGANIZE);
        jsonToList.forEach(t -> {
            t.setRealName(t.getRealName() + "/" + t.getAccount());
            t.setFullName(t.getRealName());
            List<String> collect = listByObjectType.stream().filter(userRelationEntity -> userRelationEntity.getUserId().equals(t.getId())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
            StringJoiner stringJoiner = new StringJoiner(",");
            collect.forEach(objectId -> {
                OrganizeEntity organizeEntity = orgMaps.get(objectId);
                if (organizeEntity != null) {
                    String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
                    if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
                        stringJoiner.add(fullNameByOrgIdTree);
                    }
                }
            });
            t.setOrganize(stringJoiner.toString());
            t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
        });
        return ActionResult.success(jsonToList);
    }
 
    /**
     * 获取人员,委托选人接口
     *
     * @param type       范围类型
     * @param pagination 参数
     */
    @Operation(summary = "获取人员")
    @GetMapping("/ReceiveUserList")
    public ActionResult receiveUserList(@RequestParam("type") Integer type, Pagination pagination) {
        UserInfo userInfo = UserProvider.getUser();
        UserEntity user = userService.getInfo(userInfo.getUserId());
        List<String> userId = new ArrayList<>();
        List<Integer> ruleList = ImmutableList.of(ExtraRuleEnum.organize.getCode(), ExtraRuleEnum.position.getCode(),
                ExtraRuleEnum.department.getCode());
        boolean isDepartmeng = false;
        if (ruleList.contains(type)) {
            List<String> positionList = new ArrayList<>();
            List<String> organizeList = new ArrayList<>();
            List<UserRelationEntity> userPositionList = userRelationService.getListByUserIdAll(ImmutableList.of(user.getId())).stream()
                    .filter(t -> PermissionConst.POSITION.equals(t.getObjectType())).collect(Collectors.toList());
            for (UserRelationEntity relation : userPositionList) {
                PositionEntity positionInfo = positionService.getInfo(relation.getObjectId());
                if (positionInfo != null) {
                    positionList.add(positionInfo.getId());
                    OrganizeEntity organizeInfo = organizeService.getInfo(positionInfo.getOrganizeId());
                    if (organizeInfo != null) {
                        organizeList.add(organizeInfo.getId());
                    }
                }
            }
 
            switch (ExtraRuleEnum.getByCode(type)) {
                case organize:
                    // 委托范围为同一部门,但委托人的所属组织是公司,无需选人
                    for (String organizeId : organizeList) {
                        OrganizeEntity organizeInfo = organizeService.getInfo(organizeId);
                        if (null != organizeInfo && Objects.equals(organizeInfo.getCategory(), PermissionConst.DEPARTMENT)) {
                            userId.addAll(userRelationService.getListByObjectIdAll(ImmutableList.of(organizeId)).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
                        }
                    }
                    break;
                case position:
                    for (String positionId : positionList) {
                        userId.addAll(userRelationService.getListByObjectIdAll(ImmutableList.of(positionId)).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
                    }
                    break;
                case department:
                    List<String> categoryList = ImmutableList.of("agency", "office");
                    int num = 0;
                    for (String organizeId : organizeList) {
                        OrganizeEntity organizeInfo = organizeService.getInfo(organizeId);
                        if (organizeInfo == null || categoryList.contains(organizeInfo.getCategory())) {
                            continue;
                        }
                        List<String> orgList = organizeService.getDepartmentAll(organizeId).stream().map(OrganizeEntity::getId).collect(Collectors.toList());
                        List<String> departmentAll = positionService.getListByOrgIds(orgList).stream().map(PositionEntity::getId).collect(Collectors.toList());
                        for (String id : departmentAll) {
                            userId.addAll(userRelationService.getListByObjectIdAll(ImmutableList.of(id)).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
                        }
                        num++;
                    }
                    isDepartmeng = num == 0;
                    break;
            }
        }
        List<UserEntity> list = isDepartmeng ? userService.getUserPage(pagination) : userService.getUserName(userId, pagination);
        List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(list, UserIdListVo.class);
        if (!jsonToList.isEmpty()) {
            List<String> userIdList = list.stream().map(UserEntity::getId).collect(Collectors.toList());
            List<UserRelationEntity> userRelationList = userRelationService.getRelationByUserIds(userIdList);
            Map<String, List<UserRelationEntity>> userMap = userRelationList.stream()
                    .filter(t -> PermissionConst.POSITION.equals(t.getObjectType())).collect(Collectors.groupingBy(UserRelationEntity::getUserId));
            jsonToList.forEach(t -> {
                t.setRealName(t.getRealName() + "/" + t.getAccount());
                t.setFullName(t.getRealName());
                t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
                List<UserRelationEntity> listByUserId = userMap.get(user.getId()) != null ? userMap.get(user.getId()) : new ArrayList<>();
                StringJoiner joiner = new StringJoiner(",");
                for (UserRelationEntity relation : listByUserId) {
                    StringJoiner name = new StringJoiner("/");
                    PositionEntity position = positionService.getInfo(relation.getObjectId());
                    if (position != null) {
                        OrganizeEntity organize = organizeService.getInfo(position.getOrganizeId());
                        if (organize != null) {
                            List<String> organizeIdTree = new ArrayList<>(Arrays.asList(organize.getOrganizeIdTree().split(",")));
                            List<OrganizeEntity> organizeList = organizeService.getOrganizeName(organizeIdTree);
                            for (String organizeId : organizeIdTree) {
                                OrganizeEntity entity = organizeList.stream().filter(e -> Objects.equals(e.getId(), organizeId)).findFirst().orElse(null);
                                if (entity != null) {
                                    name.add(entity.getFullName());
                                }
                            }
                        }
                        List<String> positionIdTree = new ArrayList<>(Arrays.asList(position.getPositionIdTree().split(",")));
                        List<PositionEntity> positionList = positionService.getPosList(positionIdTree);
                        for (String positionId : positionIdTree) {
                            PositionEntity entity = positionList.stream().filter(e -> Objects.equals(e.getId(), positionId)).findFirst().orElse(null);
                            if (entity != null) {
                                name.add(entity.getFullName());
                            }
                        }
                    }
                    joiner.add(name.toString());
                    t.setOrganize(joiner.toString());
                }
            });
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(jsonToList, paginationVO);
    }
 
    /**
     * 获取岗位人员
     *
     * @param page 页面信息
     * @return ignore
     */
    @Operation(summary = "获取岗位人员")
    @GetMapping("/GetUsersByPositionId")
    public ActionResult<List<UserByRoleVO>> getUsersByPositionId(UsersByPositionModel page) {
        List<UserByRoleVO> list = new ArrayList<>(1);
        String keyword = page.getKeyword();
        // 岗位id
        String positionId = page.getPositionId();
        // 得到关联的组织id
        PositionEntity positionEntity = positionService.getInfo(positionId);
        if (positionEntity != null) {
            UserByRoleVO vo = new UserByRoleVO();
            String organizeId = positionEntity.getOrganizeId();
            // 得到组织信息
            OrganizeEntity organizeEntity = organizeService.getInfo(organizeId);
            if (Objects.nonNull(organizeEntity)) {
                vo.setId(organizeEntity.getId());
                vo.setType(organizeEntity.getCategory());
                if ("department".equals(organizeEntity.getCategory())) {
                    vo.setIcon(PermissionConst.DEPARTMENT_ICON);
                } else {
                    vo.setIcon(PermissionConst.COMPANY_ICON);
                }
                vo.setEnabledMark(organizeEntity.getEnabledMark());
                Map<String, String> orgIdNameMaps = organizeService.getInfoList();
                // 组装组织名称
                String orgName = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
                vo.setFullName(orgName);
                // 赋予子集
                List<UserByRoleVO> userByRoleVOS = new ArrayList<>(16);
                List<UserEntity> lists = userService.getListByOrganizeId(organizeEntity.getId(), keyword);
                if (lists.size() > 0) {
                    vo.setHasChildren(true);
                    vo.setIsLeaf(false);
                    lists.stream().forEach(t -> {
                        UserByRoleVO userByRoleVO = new UserByRoleVO();
                        userByRoleVO.setParentId(organizeEntity.getId());
                        userByRoleVO.setId(t.getId());
                        userByRoleVO.setFullName(t.getRealName() + "/" + t.getAccount());
                        userByRoleVO.setEnabledMark(t.getEnabledMark());
                        userByRoleVO.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
                        userByRoleVO.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
                        userByRoleVO.setIsLeaf(true);
                        userByRoleVO.setHasChildren(false);
                        userByRoleVO.setIcon(PermissionConst.USER_ICON);
                        userByRoleVO.setType("user");
                        userByRoleVOS.add(userByRoleVO);
                    });
                    vo.setChildren(userByRoleVOS);
                } else {
                    vo.setHasChildren(false);
                    vo.setIsLeaf(true);
                    vo.setChildren(new ArrayList<>());
                }
                list.add(vo);
            }
        }
        return ActionResult.success(list);
    }
 
    /**
     * 获取我的下属(不取子集)
     *
     * @param page 页面信息
     * @return ignore
     */
    @Operation(summary = "获取我的下属(不取子集)")
    @Parameters({
            @Parameter(name = "page", description = "关键字", required = true)
    })
    @PostMapping("/getSubordinates")
    public ActionResult<List<UserIdListVo>> getSubordinates(@RequestBody Page page) {
        Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, false, null);
        List<UserEntity> list = userService.getListByManagerId(UserProvider.getUser().getUserId(), page.getKeyword());
        List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(list, UserIdListVo.class);
        Map<String, String> orgIdNameMaps = organizeService.getInfoList();
        jsonToList.forEach(t -> {
            t.setRealName(t.getRealName() + "/" + t.getAccount());
            t.setFullName(t.getRealName());
            List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(t.getId()).stream().filter(ur -> PermissionConst.ORGANIZE.equals(ur.getObjectType())).collect(Collectors.toList());
            StringJoiner stringJoiner = new StringJoiner(",");
            listByUserId.forEach(tt -> {
                OrganizeEntity organizeEntity = orgMaps.get(tt.getObjectId());
                if (organizeEntity != null) {
                    String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
                    if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
                        stringJoiner.add(fullNameByOrgIdTree);
                    }
                }
            });
            t.setOrganize(stringJoiner.toString());
            t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
        });
        return ActionResult.success(jsonToList);
    }
 
    /**
     * 获取默认当前值用户ID
     *
     * @param userConditionModel 参数
     * @return 执行结构
     * @throws DataException ignore
     */
    @Operation(summary = "获取默认当前值用户ID")
    @Parameters({
            @Parameter(name = "userConditionModel", description = "参数", required = true)
    })
    @PostMapping("/getDefaultCurrentValueUserId")
    public ActionResult<?> getDefaultCurrentValueUserId(@RequestBody UserConditionModel userConditionModel) throws DataException {
        String userId = userService.getDefaultCurrentValueUserId(userConditionModel);
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("userId", userId);
        return ActionResult.success(MsgCode.SU022.get(), dataMap);
    }
 
    /**
     * 工作交接
     *
     * @param workHandoverModel 模型
     * @return 执行结构
     */
    @Operation(summary = "工作交接")
    @SaCheckPermission("permission.user")
    @Parameters({
            @Parameter(name = "workHandoverModel", description = "模型", required = true)
    })
    @PostMapping("/workHandover")
    public ActionResult<?> workHandover(@RequestBody @Valid WorkHandoverModel workHandoverModel) {
        if (CollectionUtil.isEmpty(workHandoverModel.getAppList())
                && CollectionUtil.isEmpty(workHandoverModel.getFlowList())
                && CollectionUtil.isEmpty(workHandoverModel.getFlowTaskList())) {
            return ActionResult.fail(MsgCode.PS042.get());
        }
        // 开始交接就禁用用户
        UserEntity entity = userService.getInfo(workHandoverModel.getFromId());
        if (StringUtil.isEmpty(workHandoverModel.getHandoverUser())) {
            return ActionResult.fail(MsgCode.PS043.get());
        }
 
        List<SystemEntity> authListByUser = systemService.getAuthListByUser(workHandoverModel.getFromId(), false);
        List<FlowWorkModel> sysList = JsonUtil.getJsonToList(authListByUser, FlowWorkModel.class);
        Boolean isAppShow = CollectionUtil.isNotEmpty(sysList) ? true : false;
 
        if (isAppShow && StringUtil.isEmpty(workHandoverModel.getAppHandoverUser())) {
            return ActionResult.fail(MsgCode.PS044.get());
        }
 
        UserEntity entitys = userService.getInfo(workHandoverModel.getHandoverUser());
        if (entity == null || entitys == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        if (workHandoverModel.getFromId().equals(workHandoverModel.getHandoverUser()) || workHandoverModel.getFromId().equals(workHandoverModel.getAppHandoverUser())) {
            return ActionResult.fail(MsgCode.PS035.get());
        }
        if (ADMIN_KEY.equals(entitys.getAccount())) {
            return ActionResult.fail(MsgCode.PS034.get());
        }
        try {
            boolean flag = templateApi.flowWork(workHandoverModel);
            if (!flag) {
                return ActionResult.fail(MsgCode.FA101.get());
            }
            systemService.workHandover(workHandoverModel);
            entity.setHandoverMark(1);
            return ActionResult.success(MsgCode.PS033.get());
        } finally {
            userService.updateById(entity);
        }
    }
 
    /**
     * 获取用户工作详情
     *
     * @return 执行结构
     */
    @Operation(summary = "获取用户工作详情")
    @SaCheckPermission("permission.user")
    @Parameters({
            @Parameter(name = "userId", description = "主键", required = true)
    })
    @GetMapping("/getWorkByUser")
    public ActionResult<WorkHandoverVo> getWorkByUser(@RequestParam("fromId") String fromId) {
        FlowWorkListVO flowWorkListVO = templateApi.flowWork(fromId);
        if (flowWorkListVO == null) {
            log.error("用户:" + fromId + ",待办事宜及负责流程获取失败");
            flowWorkListVO = new FlowWorkListVO();
        }
        List<SystemEntity> authListByUser = systemService.getAuthListByUser(fromId, false);
//        authListByUser = authListByUser.stream().filter(t -> !Objects.equals(t.getIsMain(), 1) && (fromId.equals(t.getUserId())
//                || (StringUtil.isNotEmpty(t.getAuthorizeId()) && t.getAuthorizeId().contains(fromId)))).collect(Collectors.toList());
        List<FlowWorkModel> sysList = JsonUtil.getJsonToList(authListByUser, FlowWorkModel.class);
        Boolean isAppShow = CollectionUtil.isNotEmpty(sysList) ? true : false;
        WorkHandoverVo workHandoverVo = new WorkHandoverVo(flowWorkListVO.getFlow(), flowWorkListVO.getFlowTask(), sysList, isAppShow);
        return ActionResult.success(workHandoverVo);
    }
 
 
    // ----------------------------- 多租户调用
 
    /**
     * 重置管理员密码
     *
     * @param userResetPasswordForm 修改密码模型
     * @return ignore
     */
    @Operation(summary = "重置管理员密码")
    @Parameters({
            @Parameter(name = "userResetPasswordForm", description = "修改密码模型", required = true)
    })
    @PutMapping("/Tenant/ResetPassword")
    @NoDataSourceBind
    public ActionResult<String> resetPassword(@RequestBody @Valid TenantReSetPasswordForm userResetPasswordForm) {
        if (configValueUtil.isMultiTenancy()) {
            TenantDataSourceUtil.switchTenant(userResetPasswordForm.getTenantId());
        }
        UserEntity entity = userService.getUserByAccount(ADMIN_KEY);
        if (entity != null) {
            entity.setPassword(userResetPasswordForm.getUserPassword());
            userService.updatePassword(entity);
            userService.logoutUser(MsgCode.PS011.get(), ImmutableList.of(entity.getId()));
            entity.setPassword(userResetPasswordForm.getUserPassword());
            PullUserUtil.syncUser(entity, "modifyPassword", userResetPasswordForm.getTenantId());
            return ActionResult.success(MsgCode.SU005.get());
        }
        return ActionResult.fail(MsgCode.FA001.get());
    }
 
    /**
     * 获取用户信息
     *
     * @param tenantId 租户号
     * @return ignore
     */
    @Operation(summary = "获取用户信息")
    @Parameters({
            @Parameter(name = "tenantId", description = "租户号", required = true)
    })
    @NoDataSourceBind
    @GetMapping("/Tenant/AdminInfo")
    public AdminInfoVO adminInfo(@RequestParam("tenantId") String tenantId) throws DataException {
        if (configValueUtil.isMultiTenancy()) {
            TenantDataSourceUtil.switchTenant(tenantId);
        }
        UserEntity entity = userService.getUserByAccount(ADMIN_KEY);
        AdminInfoVO adminInfoVO = JsonUtil.getJsonToBean(entity, AdminInfoVO.class);
        return adminInfoVO;
    }
 
    /**
     * 修改管理员信息
     *
     * @param adminInfoVO 模型
     * @return ignore
     */
    @Operation(summary = "修改管理员信息")
    @Parameters({
            @Parameter(name = "adminInfoVO", description = "模型", required = true)
    })
    @NoDataSourceBind
    @PutMapping("/Tenant/UpdateAdminInfo")
    public ActionResult adminInfo(@RequestBody AdminInfoVO adminInfoVO) throws DataException {
        if (configValueUtil.isMultiTenancy()) {
            TenantDataSourceUtil.switchTenant(adminInfoVO.getTenantId());
        }
        UserEntity entity = userService.getUserByAccount(ADMIN_KEY);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        entity.setRealName(adminInfoVO.getRealName());
        entity.setMobilePhone(adminInfoVO.getMobilePhone());
        entity.setEmail(adminInfoVO.getEmail());
        userService.updateById(entity);
        ThreadPoolExecutorUtil.getExecutor().execute(() -> {
            try {
                //修改用户之后判断是否需要同步到企业微信
                synThirdInfoApi.updateUserSysToQy(new SynThirdQyModel(false, entity, ""));
                //修改用户之后判断是否需要同步到钉钉
                synThirdInfoApi.updateUserSysToDing(new SynThirdQyModel(false, entity, ""));
            } catch (Exception e) {
                log.error("修改用户之后同步失败到企业微信或钉钉失败,异常:{}", e.getMessage());
            }
        });
        // 删除在线的用户
        PullUserUtil.syncUser(entity, "update", adminInfoVO.getTenantId());
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    /**
     * 移除租户账号在线用户
     *
     * @param tenantId 租户号
     * @return ignore
     */
    @Operation(summary = "移除租户账号在线用户")
    @Parameters({
            @Parameter(name = "tenantId", description = "租户号", required = true)
    })
    @NoDataSourceBind
    @GetMapping("/Tenant/RemoveOnlineByTenantId")
    public void removeOnlineByTenantId(@RequestParam("tenantId") String tenantId) throws DataException {
        List<String> tokenList = new ArrayList<>();
        List<String> tokens = UserProvider.getLoginUserListToken();
        tokens.forEach(token -> {
            UserInfo userInfo = UserProvider.getUser(token);
            if (tenantId.equals(userInfo.getTenantId())) {
                tokenList.add(token);
            }
        });
        authService.kickoutByToken(tokenList.toArray(new String[0]), null, null);
    }
 
    //--------------------以下导入导出-----
 
    @Operation(summary = "模板下载")
    @SaCheckPermission("permission.user")
    @GetMapping("/TemplateDownload")
    public ActionResult<DownloadVO> TemplateDownload() {
        UserColumnMap columnMap = new UserColumnMap();
        String excelName = columnMap.getExcelName();
        Map<String, String> keyMap = columnMap.getColumnByType(0);
        List<ExcelColumnAttr> models = columnMap.getFieldsModel(false);
        List<Map<String, Object>> list = columnMap.getDefaultList();
        Map<String, String[]> optionMap = getOptionMap();
        ExcelModel excelModel = ExcelModel.builder().models(models).selectKey(new ArrayList<>(keyMap.keySet())).optionMap(optionMap).build();
        DownloadVO vo = ExcelTool.getImportTemplate(configValueUtil.getTemporaryFilePath(), excelName, keyMap, list, excelModel);
        return ActionResult.success(vo);
    }
 
    @Operation(summary = "上传导入Excel")
    @SaCheckPermission("permission.user")
    @PostMapping("/Uploader")
    public ActionResult<Object> Uploader() {
        return ExcelTool.uploader();
    }
 
    @Operation(summary = "导入预览")
    @SaCheckPermission("permission.user")
    @GetMapping("/ImportPreview")
    public ActionResult<Map<String, Object>> ImportPreview(String fileName) throws Exception {
        // 导入字段
        UserColumnMap columnMap = new UserColumnMap();
        Map<String, String> keyMap = columnMap.getColumnByType(0);
        Map<String, Object> headAndDataMap = ExcelTool.importPreview(configValueUtil.getTemporaryFilePath(), fileName, keyMap);
        return ActionResult.success(headAndDataMap);
    }
 
    /**
     * 导出异常报告
     *
     * @return
     */
    @Operation(summary = "导出异常报告")
    @SaCheckPermission("permission.user")
    @PostMapping("/ExportExceptionData")
    public ActionResult<DownloadVO> ExportExceptionData(@RequestBody ExcelImportForm visualImportModel) {
        String temporaryFilePath = configValueUtil.getTemporaryFilePath();
        List<Map<String, Object>> dataList = visualImportModel.getList();
        UserColumnMap columnMap = new UserColumnMap();
        String excelName = columnMap.getExcelName();
        Map<String, String> keyMap = columnMap.getColumnByType(0);
        List<ExcelColumnAttr> models = columnMap.getFieldsModel(true);
        ExcelModel excelModel = ExcelModel.builder().optionMap(getOptionMap()).models(models).build();
        DownloadVO vo = ExcelTool.exportExceptionReport(temporaryFilePath, excelName, keyMap, dataList, excelModel);
        return ActionResult.success(vo);
    }
 
    /**
     * 导入数据
     *
     * @return
     */
    @Operation(summary = "导入数据")
    @SaCheckPermission("permission.user")
    @PostMapping("/ImportData")
    public ActionResult<ExcelImportVO> ImportData(@RequestBody ExcelImportForm visualImportModel) throws Exception {
        List<Map<String, Object>> listData = new ArrayList<>();
        List<Map<String, Object>> headerRow = new ArrayList<>();
        if (visualImportModel.isType()) {
            ActionResult result = ImportPreview(visualImportModel.getFileName());
            if (result == null) {
                throw new Exception(MsgCode.FA018.get());
            }
            if (result.getCode() != 200) {
                throw new Exception(result.getMsg());
            }
            if (result.getData() instanceof Map) {
                Map<String, Object> data = (Map<String, Object>) result.getData();
                listData = (List<Map<String, Object>>) data.get("dataRow");
                headerRow = (List<Map<String, Object>>) data.get("headerRow");
            }
        } else {
            listData = visualImportModel.getList();
        }
        List<UserEntity> addList = new ArrayList<>();
        List<Map<String, Object>> failList = new ArrayList<>();
        // 对数据做校验
        this.validateImportData(listData, addList, failList);
 
        //正常数据插入
        for (UserEntity each : addList) {
            userService.create(each);
        }
        ExcelImportVO importModel = new ExcelImportVO();
        importModel.setSnum(addList.size());
        importModel.setFnum(failList.size());
        importModel.setResultType(failList.size() > 0 ? 1 : 0);
        importModel.setFailResult(failList);
        importModel.setHeaderRow(headerRow);
        return ActionResult.success(importModel);
    }
 
    /**
     * 导出Excel
     *
     * @return
     */
    @Operation(summary = "导出Excel")
    @SaCheckPermission("permission.user")
    @GetMapping("/ExportData")
    public ActionResult ExportData(PaginationUser pagination) throws IOException {
        if (StringUtil.isEmpty(pagination.getSelectKey())) {
            return ActionResult.fail(MsgCode.IMP011.get());
        }
 
        List<UserEntity> list = userService.getList(pagination, null, false, false, null, null);
        Map<String, String> roleIdAndNameMap = roleService.getList(false, PermissionConst.USER, null)
                .stream().collect(Collectors.toMap(RoleEntity::getId, t -> t.getFullName() + "/" + t.getEnCode()));
        Map<Object, String> posIdAndName = positionService.getPosEncodeAndName(true).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
        Map<Object, String> groupEncodeMap = groupService.getGroupEncodeMap(true).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
        Map<String, String> orgMap = organizeService.getAllOrgsTreeName(true);
        Map<Object, String> userNameMap = userService.getUserNameAndIdMap(true).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
        //性别
        Map<String, String> sexMap = dictionaryDataApi.getListByCode(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId())
                .stream().collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName));
        //职级
        Map<String, String> ranksMap = dictionaryDataApi.getListByCode(DictionaryDataEnum.RANK.getDictionaryTypeId())
                .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
        //民族
        Map<String, String> nationMap = dictionaryDataApi.getListByCode(DictionaryDataEnum.NATION.getDictionaryTypeId())
                .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
        //证件类型
        Map<String, String> certificatesTypeMap = dictionaryDataApi.getListByCode(DictionaryDataEnum.CERTIFICATE_TYPE.getDictionaryTypeId())
                .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
        //文化程度
        Map<String, String> educationMap = dictionaryDataApi.getListByCode(DictionaryDataEnum.EDUCATION.getDictionaryTypeId())
                .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
 
        List<RoleRelationEntity> roleRelationList = roleRelationService.getListByRoleId("", PermissionConst.USER);
        List<UserRelationEntity> userRelationList = userRelationService.getListByObjectType(PermissionConst.POSITION);
 
        List<Map<String, Object>> realList = new ArrayList<>();
        for (UserEntity entity : list) {
            entity.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
            //获取角色
            List<RoleRelationEntity> userRoleRelation = roleRelationList.stream().filter(t -> t.getObjectId().equals(entity.getId())).collect(Collectors.toList());
            List<String> roleIdList = new ArrayList<>();
            for (RoleRelationEntity ure : userRoleRelation) {
                if (StringUtil.isNotEmpty(roleIdAndNameMap.get(ure.getRoleId()))) {
                    roleIdList.add(roleIdAndNameMap.get(ure.getRoleId()));
                }
            }
            entity.setRoleId(String.join(",", roleIdList));
 
            // 岗位装配
            List<UserRelationEntity> userPosRelation = userRelationList.stream().filter(t -> t.getUserId().equals(entity.getId())).collect(Collectors.toList());
            List<String> positionIds = new ArrayList<>();
            for (UserRelationEntity ure : userPosRelation) {
                if (posIdAndName.containsKey(ure.getObjectId())) {
                    positionIds.add(posIdAndName.get(ure.getObjectId()));
                }
            }
            entity.setPositionId(String.join(",", positionIds));
 
            //性别
            entity.setGender(sexMap.get(entity.getGender()));
            entity.setRanks(ranksMap.get(entity.getRanks()));
            entity.setNation(nationMap.get(entity.getNation()));
            entity.setCertificatesType(certificatesTypeMap.get(entity.getCertificatesType()));
            entity.setEducation(educationMap.get(entity.getEducation()));
 
            Map<String, Object> obj = JsonUtil.entityToMap(entity);
            if (obj.get("enabledMark") != null) {
                String stateName = "" ;
                if (Objects.equals(obj.get("enabledMark"), 0)) {
                    stateName = "禁用" ;
                } else if (Objects.equals(obj.get("enabledMark"), 1)) {
                    stateName = "启用" ;
                } else if (Objects.equals(obj.get("enabledMark"), 2)) {
                    stateName = "锁定" ;
                }
                obj.put("enabledMark", stateName);
            }
            if (obj.get("birthday") != null) {
                obj.put("birthday", DateUtil.daFormat(Long.parseLong(obj.get("birthday").toString())));
            }
            if (obj.get("entryDate") != null) {
                obj.put("entryDate", DateUtil.daFormat(Long.parseLong(obj.get("entryDate").toString())));
            }
            realList.add(obj);
        }
        String[] keys = !StringUtil.isEmpty(pagination.getSelectKey()) ? pagination.getSelectKey() : new String[0];
        UserColumnMap columnMap = new UserColumnMap();
        String excelName = columnMap.getExcelName();
        List<ExcelColumnAttr> models = columnMap.getFieldsModel(false);
        Map<String, String> keyMap = columnMap.getColumnByType(null);
        ExcelModel excelModel = ExcelModel.builder().selectKey(Arrays.asList(keys)).models(models).build();
        DownloadVO vo = ExcelTool.creatModelExcel(configValueUtil.getTemporaryFilePath(), excelName, keyMap, realList, excelModel);
        return ActionResult.success(vo);
    }
 
    /**
     * 导入验证
     *
     * @param listData
     * @param addList
     * @param failList
     */
    private void validateImportData(List<Map<String, Object>> listData, List<UserEntity> addList, List<Map<String, Object>> failList) {
        UserColumnMap columnMap = new UserColumnMap();
        Map<String, String> keyMap = columnMap.getColumnByType(0);
        List<DictionaryDataEntity> sexList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId()).getData();
        Map<String, String> genderMap = sexList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getEnCode));
        List<DictionaryDataEntity> rankList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.RANK.getDictionaryTypeId()).getData();
        Map<String, String> ranksMap = rankList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
        List<DictionaryDataEntity> nationList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.NATION.getDictionaryTypeId()).getData();
        Map<String, String> nationMap = nationList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
        List<DictionaryDataEntity> certificateList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.CERTIFICATE_TYPE.getDictionaryTypeId()).getData();
        Map<String, String> certificateMap = certificateList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
        List<DictionaryDataEntity> educationList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.EDUCATION.getDictionaryTypeId()).getData();
        Map<String, String> educationMap = educationList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
        Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
        Map<String, Object> userNameMap = userService.getUserNameAndIdMap();
 
        List<PositionEntity> allPos = positionService.getList(true);
        Map<String, Object> posNameMap = positionService.getPosEncodeAndName(true);
        List<RoleEntity> allUserRole = roleService.getList(true, PermissionConst.USER, null);
        Map<String, String> roleMap = allUserRole.stream().collect(Collectors.toMap(t -> t.getFullName(), RoleEntity::getId));
        //所有岗位的用户列表
        List<UserRelationEntity> posAllUser = userRelationService.getListByObjectType(PermissionConst.POSITION);
        //所有用户角色的用户列表
        List<RoleRelationEntity> roleAllUser = roleRelationService.getListByRoleId("", PermissionConst.USER);
        //角色用户数量
        Map<String, Integer> roleIdUserNum = new HashMap<>();
 
        for (int i = 0, len = listData.size(); i < len; i++) {
            Map<String, Object> eachMap = listData.get(i);
            Map<String, Object> realMap = JsonUtil.getJsonToBean(eachMap, Map.class);
            StringJoiner errInfo = new StringJoiner(",");
 
            // 开启多租住的-判断用户额度
            String tenantId = UserProvider.getUser().getTenantId();
            if (StringUtil.isNotEmpty(tenantId)) {
                TenantVO cacheTenantInfo = TenantDataSourceUtil.getCacheTenantInfo(tenantId);
                long count = userService.count() + addList.size();
                if (cacheTenantInfo.getAccountNum() != 0 && cacheTenantInfo.getAccountNum() < count) {
                    eachMap.put("errorsInfo", MsgCode.PS009.get());
                    failList.add(eachMap);
                    continue;
                }
            }
 
            //组织多选id,用于查询角色和岗位
            StringJoiner organizeIds = new StringJoiner(",");
            for (String column : keyMap.keySet()) {
                Object valueObj = eachMap.get(column);
                String value = valueObj == null ? null : String.valueOf(valueObj);
                String columnName = keyMap.get(column);
                switch (column) {
                    case "gender":
                        if (StringUtil.isEmpty(value)) {
                            errInfo.add(columnName + "不能为空");
                            break;
                        }
                        if (genderMap.containsKey(valueObj.toString())) {
                            realMap.put("gender", genderMap.get(value));
                        } else {
                            errInfo.add("找不到该" + columnName + "值");
                        }
                        break;
                    case "ranks":
                        if (StringUtil.isNotEmpty(value)) {
                            if (ranksMap.containsKey(valueObj.toString())) {
                                realMap.put("ranks", ranksMap.get(value));
                            } else {
                                errInfo.add("找不到该" + columnName + "值");
                            }
                        }
                        break;
                    case "nation":
                        if (StringUtil.isNotEmpty(value)) {
                            if (nationMap.containsKey(valueObj.toString())) {
                                realMap.put("nation", nationMap.get(value));
                            } else {
                                errInfo.add("找不到该" + columnName + "值");
                            }
                        }
                        break;
                    case "certificatesType":
                        if (StringUtil.isNotEmpty(value)) {
                            if (certificateMap.containsKey(valueObj.toString())) {
                                realMap.put("certificatesType", certificateMap.get(value));
                            } else {
                                errInfo.add("找不到该" + columnName + "值");
                            }
                        }
                        break;
                    case "education":
                        if (StringUtil.isNotEmpty(value)) {
                            if (educationMap.containsKey(valueObj.toString())) {
                                realMap.put("education", educationMap.get(value));
                            } else {
                                errInfo.add("找不到该" + columnName + "值");
                            }
                        }
                        break;
                    case "account":
                        //账号
                        if (StringUtil.isEmpty(value)) {
                            errInfo.add(columnName + "不能为空");
                            break;
                        }
                        if (value.length() > 50) {
                            errInfo.add(columnName + "值超出最多输入字符限制");
                        }
                        //值不能含有特殊符号
                        if (!RegexUtils.checkSpecoalSymbols(value)) {
                            errInfo.add(columnName + "值不能含有特殊符号");
                        }
                        //库里重复
                        if (userService.isExistByAccount(value)) {
                            errInfo.add(columnName + "值已存在");
                            break;
                        }
                        //表格内重复
                        long enCodeCount = addList.stream().filter(t -> t.getAccount().equals(value)).count();
                        if (enCodeCount > 0) {
                            errInfo.add(columnName + "值已存在");
                            break;
                        }
                        break;
                    case "realName":
                        if (StringUtil.isEmpty(value)) {
                            errInfo.add(columnName + "不能为空");
                            break;
                        }
                        if (value.length() > 50) {
                            errInfo.add(columnName + "值超出最多输入字符限制");
                        }
                        //值不能含有特殊符号
                        if (!RegexUtils.checkSpecoalSymbols(value)) {
                            errInfo.add(columnName + "值不能含有特殊符号");
                        }
                        break;
                    case "positionId":
                        if (StringUtil.isNotEmpty(value)) {
                            List<String> posIds = new ArrayList<>();
                            List<String> posErrList = new ArrayList<>();
                            List<String> listName = Arrays.asList(value.split(","));
                            for (String item : listName) {
                                if (posNameMap.containsKey(item)) {
                                    posIds.add(posNameMap.get(item).toString());
                                } else {
                                    posErrList.add(item);
                                }
                            }
                            if (posErrList.size() > 0) {
                                if (listName.size() > 1) {
                                    errInfo.add("找不到该" + columnName + "(" + String.join("、", posErrList) + ")");
                                    break;
                                } else if (listName.size() == 1) {
                                    errInfo.add("找不到该" + columnName);
                                    break;
                                }
                            }
                            if (CollectionUtil.isNotEmpty(posIds)) {
                                //判断约束
                                for (String item : posIds) {
                                    PositionEntity info = allPos.stream().filter(t -> t.getId().equals(item)).findFirst().orElse(null);
                                    //库里岗位用户数
                                    List<UserRelationEntity> thisPosUsers = posAllUser.stream().filter(t -> t.getObjectId().equals(item)).collect(Collectors.toList());
                                    //表格里的岗位用户数
                                    List<UserEntity> excelUserList = addList.stream().filter(t -> t.getPositionId() != null && t.getPositionId().contains(item)).collect(Collectors.toList());
                                    Integer userNum = thisPosUsers.size() + excelUserList.size();
                                    if (Objects.equals(info.getIsCondition(), 1)) {
                                        PosConModel conModelP = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
                                        conModelP.init();
                                        if (conModelP.getMutualExclusionFlag() && conModelP.getMutualExclusion().stream().anyMatch(t -> posIds.contains(t))) {
                                            errInfo.add(info.getFullName() + "存在互斥岗位");
                                            break;
                                        }
                                        if (conModelP.getNumFlag() && userNum >= conModelP.getUserNum()) {
                                            errInfo.add(info.getFullName() + "岗位已达用户限制个数");
                                            break;
                                        }
                                        if (conModelP.getPrerequisiteFlag() && !posIds.containsAll(conModelP.getPrerequisite())) {
                                            errInfo.add(info.getFullName() + "存在先决岗位");
                                            break;
                                        }
                                    }
                                }
                                realMap.put("positionId", String.join(",", posIds));
                                Set<String> orgList = allPos.stream().filter(t -> posIds.contains(t.getId())).map(PositionEntity::getOrganizeId).collect(Collectors.toSet());
                                realMap.put("organizeId", String.join(",", orgList));
                                break;
                            }
                            break;
                        }
                        break;
                    case "roleId":
                        if (StringUtil.isNotEmpty(value)) {
                            List<String> roleIds = new ArrayList<>();
                            List<String> roleErrList = new ArrayList<>();
                            List<String> listName = Arrays.asList(value.split(","));
                            for (String item : listName) {
                                if (roleMap.containsKey(item)) {
                                    roleIds.add(roleMap.get(item));
                                } else {
                                    roleErrList.add(item);
                                }
                            }
                            if (roleErrList.size() > 0) {
                                if (listName.size() > 1) {
                                    errInfo.add("找不到该" + columnName + "(" + String.join("、", roleErrList) + ")");
                                    break;
                                } else if (listName.size() == 1) {
                                    errInfo.add("找不到该" + columnName);
                                    break;
                                }
                            }
                            if (CollectionUtil.isNotEmpty(roleIds)) {
                                //判断约束
                                for (String item : roleIds) {
                                    RoleEntity info = allUserRole.stream().filter(t -> t.getId().equals(item)).findFirst().orElse(null);
                                    List<RoleRelationEntity> thisRoleUsers = roleAllUser.stream().filter(t -> t.getRoleId().equals(item)).collect(Collectors.toList());
                                    //表格里的岗位用户数
                                    List<UserEntity> excelUserList = addList.stream().filter(t -> t.getRoleId() != null && t.getRoleId().contains(item)).collect(Collectors.toList());
                                    Integer userNum = thisRoleUsers.size() + excelUserList.size();
                                    if (Objects.equals(info.getIsCondition(), 1)) {
                                        PosConModel conModelP = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
                                        conModelP.init();
                                        if (conModelP.getMutualExclusionFlag() && conModelP.getMutualExclusion().stream().anyMatch(t -> roleIds.contains(t))) {
                                            errInfo.add(info.getFullName() + "存在互斥角色");
                                            break;
                                        }
                                        if (conModelP.getNumFlag() && userNum >= conModelP.getUserNum()) {
                                            errInfo.add(info.getFullName() + "角色已达用户限制个数");
                                            break;
                                        }
                                        if (conModelP.getPrerequisiteFlag() && !roleIds.containsAll(conModelP.getPrerequisite())) {
                                            errInfo.add(info.getFullName() + "存在先决角色");
                                            break;
                                        }
                                    }
                                }
                                realMap.put("roleId", String.join(",", roleIds));
                                break;
                            }
                        }
                        break;
                    case "entryDate":
                        if (StringUtil.isNotEmpty(value)) {
                            Date date = DateUtil.checkDate(value, "yyyy-MM-dd");
                            if (date == null) {
                                errInfo.add(columnName + "值不正确");
                                break;
                            }
                            realMap.put("entryDate", date);
                        }
                        break;
                    case "birthday":
                        if (StringUtil.isNotEmpty(value)) {
                            Date date = DateUtil.checkDate(value, "yyyy-MM-dd");
                            if (date == null) {
                                errInfo.add(columnName + "值不正确");
                                break;
                            }
                            realMap.put("birthday", date);
                        }
                        break;
                    case "sortCode":
                        if (StringUtil.isEmpty(value)) {
                            realMap.put("sortCode", 0);
                            break;
                        }
                        Long numValue = 0l;
                        try {
                            numValue = Long.parseLong(value);
                        } catch (Exception e) {
                            errInfo.add(columnName + "值不正确");
                            break;
                        }
                        if (numValue < 0) {
                            errInfo.add(columnName + "值不能小于0");
                            break;
                        }
                        if (numValue > 1000000) {
                            errInfo.add(columnName + "值不能大于999999");
                            break;
                        }
                        break;
                    case "enabledMark":
                        if (StringUtil.isEmpty(value)) {
                            errInfo.add(columnName + "不能为空");
                            break;
                        }
                        if ("启用".equals(value)) {
                            realMap.put("enabledMark", 1);
                        } else if ("禁用".equals(value)) {
                            realMap.put("enabledMark", 0);
                        } else if ("锁定".equals(value)) {
                            realMap.put("enabledMark", 2);
                        } else {
                            errInfo.add("找不到该" + columnName + "值");
                        }
                        break;
                    default:
                        break;
                }
 
            }
 
            if (errInfo.length() == 0) {
                UserEntity entity = JsonUtil.getJsonToBean(realMap, UserEntity.class);
                entity.setCreatorTime(new Date());
                addList.add(entity);
            } else {
                eachMap.put("errorsInfo", errInfo.toString());
                failList.add(eachMap);
            }
        }
    }
 
    private CheckResult checkOrganizeId(String organizeName, Map<String, Object> allOrgsTreeName) {
        for (String key : allOrgsTreeName.keySet()) {
            Object o = allOrgsTreeName.get(key);
            if (organizeName.equals(o.toString())) {
                String[] split = key.split(",");
                return new CheckResult(true, null, split[split.length - 1]);
            }
        }
        return new CheckResult(false, "所属组织不正确", null);
    }
 
    /**
     * 获取下拉框
     *
     * @return
     */
    private Map<String, String[]> getOptionMap() {
        Map<String, String[]> optionMap = new HashMap<>();
        //性别
        List<DictionaryDataEntity> sexList = dictionaryDataApi.getListByCode(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId());
        String[] gender = sexList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
        optionMap.put("gender", gender);
        //职级
        List<DictionaryDataEntity> ranksList = dictionaryDataApi.getListByCode(DictionaryDataEnum.RANK.getDictionaryTypeId());
        String[] ranks = ranksList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
        optionMap.put("ranks", ranks);
        //状态
        optionMap.put("enabledMark", new String[]{"启用", "禁用", "锁定"});
        //民族
        List<DictionaryDataEntity> nationList = dictionaryDataApi.getListByCode(DictionaryDataEnum.NATION.getDictionaryTypeId());
        String[] nation = nationList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
        optionMap.put("nation", nation);
        //证件类型
        List<DictionaryDataEntity> certificatesTypeList = dictionaryDataApi.getListByCode(DictionaryDataEnum.CERTIFICATE_TYPE.getDictionaryTypeId());
        String[] certificatesType = certificatesTypeList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
        optionMap.put("certificatesType", certificatesType);
        //文化程度
        List<DictionaryDataEntity> educationList = dictionaryDataApi.getListByCode(DictionaryDataEnum.EDUCATION.getDictionaryTypeId());
        String[] education = educationList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
        optionMap.put("education", education);
        return optionMap;
    }
 
 
    //以下接口调用-------------------------------------
    @Override
    @PostMapping("/getUserName")
    public List<UserEntity> getUserName(@RequestBody List<String> id) {
        return userService.getUserName(id);
    }
 
    @Override
    @PostMapping("/getUserNamePagination")
    public List<UserEntity> getUserNamePagination(@RequestBody UserModel userModel) {
        return userService.getUserName(userModel.getId(), userModel.getPagination());
    }
 
    @Override
    @GetMapping("/getListId")
    public List<String> getListId() {
        return userService.getListId();
    }
 
    @Override
    @NoDataSourceBind
    @PostMapping("/getInfoByAccount")
    public UserEntity getInfoByAccount(@RequestBody UserInfoModel userInfoModel) {
        //判断是否为多租户
        if (configValueUtil.isMultiTenancy()) {
            TenantDataSourceUtil.switchTenant(userInfoModel.getTenantId());
        }
        return userService.getUserByAccount(userInfoModel.getUserId());
    }
 
    @Override
    @NoDataSourceBind
    @PostMapping("/getInfoByUserId")
    public UserEntity getInfoByUserId(UserInfoModel userInfoModel) {
        //判断是否为多租户
        if (configValueUtil.isMultiTenancy()) {
            TenantDataSourceUtil.switchTenant(userInfoModel.getTenantId());
        }
        return userService.getInfo(userInfoModel.getUserId());
    }
 
    @Override
    @PostMapping("/updateById")
    @NoDataSourceBind
    public Boolean updateById(@RequestBody UserUpdateModel userUpdateModel) {
        //判断是否为多租户
        if (configValueUtil.isMultiTenancy()) {
            TenantDataSourceUtil.switchTenant(userUpdateModel.getTenantId());
        }
        return userService.updateById(userUpdateModel.getEntity());
    }
 
    @Override
    @GetMapping("/getInfoByAccount/{account}")
    public UserEntity getInfoByAccount(@PathVariable("account") String account) {
        return userService.getUserByAccount(account);
    }
 
    @Override
    @GetMapping("/getInfoById/{id}")
    public UserEntity getInfoById(@PathVariable("id") String id) {
        return userService.getInfo(id);
    }
 
    @Override
    @GetMapping("/getInfoByIdInMessage")
    public UserEntity getInfoByIdInMessage(@RequestParam("id") String id) {
        return userService.getInfo(id);
    }
 
    @Override
    @GetMapping("/getListByManagerId/{id}")
    public List<UserEntity> getListByManagerId(@PathVariable("id") String id) {
        return userService.getListByManagerId(id, null);
    }
 
    @Override
    @GetMapping("/getList")
    public List<UserEntity> getList(@RequestParam("enabledMark") boolean enabledMark) {
        return userService.getList(false);
    }
 
    @Override
    @GetMapping("/getAdminList")
    public List<UserEntity> getAdminList() {
        return userService.getAdminList();
    }
 
    @Override
    @PostMapping("/setAdminListByIds")
    public Boolean setAdminListByIds(@RequestBody List<String> adminIds) {
        return userService.setAdminListByIds(adminIds);
    }
 
    @Override
    @GetMapping("/getByRealName/{fullName}")
    public UserEntity getByRealName(@PathVariable("fullName") String fullName) {
        return userService.getByRealName(fullName);
    }
 
    @Override
    @PostMapping("/updateUserById")
    public Boolean updateUserById(@RequestBody UserEntity userEntity) {
        return userService.updateById(userEntity);
    }
 
    @Override
    @PostMapping("/update/{id}")
    public Boolean update(@PathVariable("id") String id, @RequestBody UserEntity entity) throws Exception {
        return userService.update(id, entity);
    }
 
    @Override
    @GetMapping("/getUserMap")
    public Map<String, Object> getUserMap(@RequestParam("type") String type) {
        return "id-fullName".equals(type) ? userService.getUserMap() : userService.getUserNameAndIdMap();
    }
 
    @Override
    @GetMapping("/getInfoByMobile/{mobile}")
    public UserEntity getInfoByMobile(@PathVariable("mobile") String mobile) {
        return userService.getUserByMobile(mobile);
    }
 
    @Override
    @PostMapping("/create")
    public Boolean create(@RequestBody UserEntity userEntity) throws Exception {
        return userService.create(userEntity);
    }
 
    @Override
    @PostMapping("/delete")
    public void delete(@RequestBody UserEntity userEntity) {
        userService.delete(userEntity);
    }
 
    @Override
    @PostMapping("/getUserIdList")
    public List<String> getUserIdList(@RequestBody List<String> userIds) {
        return userService.getUserIdList(userIds);
    }
 
    @Override
    @PostMapping("/selectedByIds")
    public List<BaseInfoVo> selectedByIds(@RequestBody List<String> ids) {
        return userService.selectedByIds(ids);
    }
 
    @Override
    @PostMapping("/getUserNameMark")
    public List<UserEntity> getUserNameMark(@RequestBody List<String> id) {
        return userService.getUserName(id, true);
    }
 
    @Override
    @PostMapping("/getObjList")
    public List<BaseInfoVo> getObjList(UserIdModelByPage userIdModel) {
        PaginationUser page = JsonUtil.getJsonToBean(userIdModel, PaginationUser.class);
        List<BaseInfoVo> jsonToList = userService.getObjList(userIdModel.getIds(), page);
        return jsonToList;
    }
 
    @Override
    @PostMapping("/getIdsByAccounts")
    public List<String> getIdsByAccounts(List<String> accounts) {
        List<String> list = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(accounts)) {
            for (String account : accounts) {
                UserEntity userByAccount = userService.getUserByAccount(account);
                if (userByAccount != null) {
                    list.add(userByAccount.getId());
                }
            }
        }
        return list;
    }
 
    @Override
    @PostMapping("/getUserPage")
    public List<UserEntity> getUserPage(@RequestBody Pagination pagination) {
        return userService.getUserPage(pagination);
    }
 
    @Override
    @PostMapping("/getSystemFieldValue")
    public Map<String, String> getSystemFieldValue(@RequestBody SystemParamModel model) {
        return userService.getSystemFieldValue(model);
    }
 
    @Override
    @PostMapping("/getListByOrgIds")
    public List<UserEntity> getListByOrgIds(@RequestBody List<String> collect) {
        return userService.getListBySyn(collect, "");
    }
 
    @Override
    @GetMapping("/getUserByMobile")
    public UserEntity getUserByMobile(@RequestParam String dingMobile) {
        return userService.getUserByMobile(dingMobile);
    }
 
 
    @Override
    @PostMapping("userPage")
    public List<UserEntity> page(@RequestBody UserSystemCountModel userSystemCountModel) {
        return userService.pageUser(userSystemCountModel);
    }
 
    @Override
    @GetMapping("/getUserObjectIdList")
    public UserRelationIds getUserObjectIdList(@RequestParam String userId) {
        return userService.getUserObjectIdList(userId);
    }
 
    @Override
    @PostMapping("/logoutUser")
    public Boolean logoutUser(@RequestParam("message") String message,@RequestBody List<String> userIds){
        return userService.logoutUser(message,userIds);
    }
}