shichongfu
2023-04-25 ce0b49552668d3331055e2b1a1447a743dc54939
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
package com.product.org.admin.service;
 
import com.product.admin.service.PublicService;
import com.product.admin.service.SelectPersonnelService;
 
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
 
import com.product.admin.service.UpdateLoginUserInfoService;
import com.product.common.lang.StringUtils;
import com.product.core.interceptor.support.DataValidateInterceptor;
import com.product.core.spring.context.SpringBeanUtil;
import com.product.email.service.SendEmailService;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.CoreConst;
import com.product.core.config.Global;
import org.apache.commons.lang3.RandomStringUtils;
import org.jsoup.helper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.product.org.admin.config.SystemCode;
import com.product.admin.service.CodeService;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.core.util.JsonUtil;
import com.product.module.sys.entity.SystemUser;
import com.product.module.sys.service.UserService;
import com.product.org.admin.config.CmnConst;
import com.product.org.admin.service.idel.IStaffManagerService;
import com.product.org.admin.util.SingletonUtil;
import com.product.util.BaseUtil;
 
 
/**
 * Copyright LX-BASE
 *
 * @Title: LX-BASE-
 * @Project: StaffManagerService
 * @Date: 2020-06-22 09:31
 * @Author: 杜洪波
 * @Description:员工管理
 */
@Component
public class StaffManagerService extends AbstractBaseService implements IStaffManagerService {
 
    @Autowired
    public BaseDao baseDao;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private CodeService codeService;
 
    @Autowired
    PermissionService permissionService;
 
    @Autowired
    private SendEmailService sendEmailService;
 
    @Autowired
    public CostCenterService costCenterService;
    @Autowired
    public QueryFilterService queryFilterService;
    @Autowired
    public TimeTaskChangeService timeTaskService;
    @Autowired
    private UpdateLoginUserInfoService updateLoginUserInfoService;
    @Autowired
    private SelectPersonnelService selectPersonnelService;
 
    /**
     * 获取当前用户上级领导userid
     *
     * @return
     * @throws BaseException
     */
    public String getLeaderUserId() throws BaseException {
        return getLeaderUserId(SpringMVCContextHolder.getCurrentUser().getUser_id());
    }
 
    /**
     * 获取上级领导user_id
     *
     * @param user_id user表id
     * @return
     * @throws BaseException
     */
    public String getLeaderUserId(Object user_id) throws BaseException {
        FieldSetEntity fse = baseDao.getFieldSetEntityBySQL("SELECT user_id FROM product_sys_staffs WHERE tricode = (SELECT direct_leader_code FROM product_sys_staffs " +
                "WHERE USER_ID=?)", new Object[]{user_id}, false);
        if (fse != null) {
            return fse.getString(CmnConst.USER_ID);
        }
        return null;
    }
 
    public DataTableEntity listStaffInfoV2(FieldSetEntity fse) throws BaseException {
        PublicService publicService = SpringBeanUtil.getBean("publicService", PublicService.class);
        fse.setTableName("product_sys_staff_user_v");
        return publicService.listTable(fse, true, 1, CmnConst.ORG_LEVEL_UUID, null);
    }
 
    /**
     * 员工信息列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity listStaffInfo(FieldSetEntity fse) throws BaseException {
        fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
        String dataFilter = permissionService.getDataFilter("a." + CmnConst.ORG_LEVEL_UUID);
        if (!StringUtils.isEmpty(dataFilter)) {
            dataFilter = " WHERE " + dataFilter;
        } else {
            dataFilter = "";
        }
        // 高级搜索
        String filter = queryFilterService.getQueryFilter(fse);
        if (!StringUtils.isEmpty(filter)) {
            if (dataFilter.length() > 0) {
                dataFilter += " and " + filter;
            } else {
                dataFilter = " where  " + filter;
            }
        }
 
        StringBuilder sql = new StringBuilder();
/*
        sql.append("select * from (");
        sql.append(" SELECT a.uuid uuid,b.uuid uuid1,c.uuid uuid2,d.uuid uuid3,e.uuid uuid4,f.uuid uuid5,a.staff_status,a.staff_avatar,b.user_id,b.user_account,b.STATUS,a.show_name,a.preferred_name,c.client_name,d.org_level_all,e.job_post_name,f.job_grade_name ");
        sql.append(" FROM product_sys_staffs a ");
        sql.append(" LEFT JOIN  product_sys_users b ON b.user_id=a.user_id ");
        sql.append(" LEFT JOIN product_sys_clients c ON c.uuid=a.client_uuid ");
        sql.append(" LEFT JOIN product_sys_org_levels d ON d.uuid=a.dept_uuid ");
        sql.append(" LEFT JOIN product_sys_job_posts e ON e.uuid=a.job_post_uuid ");
        sql.append(" LEFT JOIN product_sys_job_post_grades f ON f.uuid=a.job_post_grade_uuid ");
        sql.append(dataFilter);
        sql.append(" ) b");
*/
//        sql.append("select * from (");
        sql.append(" SELECT a.uuid uuid,b.uuid uuid1,c.uuid uuid2,d.uuid uuid3,a.staff_status,a.staff_avatar,a.show_name,a.preferred_name,b.user_id,b.user_account,b.status,c.org_level_all,d.job_post_name ");
        sql.append(" FROM product_sys_staffs a ");
        sql.append(" LEFT JOIN product_sys_users b ON b.user_id=a.user_id ");
        sql.append(" LEFT JOIN product_sys_org_levels c ON c.uuid=a.dept_uuid ");
        sql.append(" LEFT JOIN product_sys_job_posts d ON d.uuid=a.job_post_uuid ");
        sql.append(dataFilter);
//        sql.append(" ) b");
 
        DataTableEntity dtStaffInfo = baseDao.listTable(sql.toString(), null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
        dtStaffInfo.getMeta().addAliasTable(CmnConst.PRODUCT_SYS_STAFFS, "a");
        dtStaffInfo.getMeta().addAliasTable("product_sys_users", "b");
        dtStaffInfo.getMeta().addAliasTable("product_sys_org_levels", "c");
        dtStaffInfo.getMeta().addAliasTable("product_sys_job_posts", "d");
/*
        if (dtStaffInfo.getRows() > 0) {
            String sostoken = Global.getSystemConfig("upload.key", "");
            for (int i = 6; i < dtStaffInfo.getRows(); i++) {
                Map<Object, Object> av = new HashMap<Object, Object>();
                FieldSetEntity staff = dtStaffInfo.getFieldSetEntity(i);
                if (!StringUtils.isEmpty(staff.getString(CmnConst.STAFF_AVATAR))) {
                    FieldSetEntity atta = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS,
                            staff.getString(CmnConst.STAFF_AVATAR), false);
                    if (atta != null) {
                        av.put("path",
                                atta.getString("attachment_domain") + "/" + atta.getString("attachment_container") + "/"
                                        + atta.getString("module_uuid") + "/"
                                        + atta.getString(CmnConst.ATTACHMENT_TITLE) + sostoken);
                        av.put("name", atta.getString(CmnConst.ATTACHMENT_TITLE));
                        av.put("size", atta.getString("attachment_size"));
                        av.put("uuid", atta.getString("uuid"));
                        av.put(CmnConst.FIEL_NAME, atta.getString(CmnConst.FIEL_NAME));
                    } else {
                        av.put("path", "");
                        av.put("name", "");
                        av.put("size", "");
                        av.put("uuid", "");
                        av.put(CmnConst.FIEL_NAME, "");
                    }
                } else {
                    av.put("path", "");
                    av.put("name", "");
                    av.put("size", "");
                    av.put("uuid", "");
                    av.put(CmnConst.FIEL_NAME, "");
                }
                staff.setValue(CmnConst.STAFF_AVATAR, av);
            }
        }
*/
        // 查询为数据时,设置表名
        if (dtStaffInfo != null && dtStaffInfo.getTableName() == null && dtStaffInfo.getMeta() != null) {
            dtStaffInfo.getMeta().setTableName(new String[]{"a", "b", "c", "d"});
        }
        baseDao.loadPromptData(dtStaffInfo);
        return dtStaffInfo;
    }
 
 
    /**
     * 员工信息详情 v2
     *
     * @param user_id
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffInfoV2(String user_id) throws BaseException {
        return baseDao.getFieldSetEntityBySQL("select a.*,b.uuid user_uuid,b.user_name,b.user_account,'********' user_pwd,b.status FROM product_sys_users b join product_sys_staffs a on a.user_id=? and a.user_id=b.user_id", new Object[]{user_id}, false);
    }
 
    /**
     * 员工信息详情
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffInfo(String uuid) throws BaseException {
 
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.child_name,a.christian_name,a.client_uuid,a.cost_center_uuid,a.created_by,a.created_utc_datetime,a.dept_uuid,a.direct_leader_code, ");
        sql.append(" a.entry_datetime,a.family_name,a.given_name,a.is_dept_manage,a.is_org_admin,a.is_org_manager,a.job_post_grade_uuid,a.job_post_uuid, ");
        sql.append(" a.org_level_uuid,a.preferred_name,a.probation_end,a.role_uuids,a.show_name,a.staff_code,a.staff_email,a.staff_id,a.staff_image, ");
        sql.append(" a.staff_status,a.tricode,a.updated_by,a.updated_utc_datetime,a.user_id,a.uuid, ");
        sql.append(" b.status,d.gender, ");
        sql.append(" c.attachment_url,concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) staff_avatar  ");
        sql.append(" FROM product_sys_staffs a ");
        sql.append(" LEFT JOIN product_sys_users b ON a.user_id=b.user_id  ");
        sql.append(" LEFT JOIN product_sys_attachments c ON a.staff_avatar=c.uuid ");
        sql.append(" LEFT JOIN product_sys_staff_personal_info d ON a.uuid=d.staff_uuid ");
        sql.append(" where a.uuid=? ");
 
        String sostoken = Global.getSystemConfig("upload.key", "");
        FieldSetEntity fseStaff = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{sostoken, uuid}, false);
        baseDao.listInternationDataTable(fseStaff, null);
        return fseStaff;
    }
 
    /**
     * 员工新增 v2
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    @Override
    public String saveStaffInfo(FieldSetEntity fse) throws BaseException {
        FieldSetEntity fs;
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        // 用户账号
        String user_account = fse.getString(CmnConst.USER_ACCOUNT);
        fse.setValue("show_name", fse.getString(CmnConst.USER_NAME));
        fse.setValue(CmnConst.CLIENT_UUID, currentUser.getClient_uuid());
        if (StringUtils.isEmpty(fse.getString(CmnConst.CLIENT_UUID))) {
 
            fse.setValue(CmnConst.CLIENT_UUID, currentUser.getClient_uuid());
        }
        if (StringUtils.isEmpty(fse.getString(CmnConst.ORG_LEVEL_UUID))) {
            fse.setValue(CmnConst.ORG_LEVEL_UUID, currentUser.getOrg_level_uuid());
        }
        // 判断是否为新增
        if (StringUtils.isEmpty(fse.getString(CmnConst.USER_ID))) {
            if (StringUtils.isEmpty(user_account)) {
                // 账号为空
                throw new BaseException(SystemCode.USER_ACCOUNT_IS_EMPTY.getValue(), SystemCode.USER_ACCOUNT_IS_EMPTY.getText());
            }
            fs = baseDao.getFieldSetEntityBySQL("select user_account FROM product_sys_users where user_account=? limit 1", new Object[]{user_account}, false);
            if (fs != null && user_account.equals(fs.getString(user_account))) {
                // 账号已存在
                throw new BaseException(SystemCode.USER_ACCOUNT_EXIST.getValue(), SystemCode.USER_ACCOUNT_EXIST.getText());
            }
        }
 
        if (fse.getString(CmnConst.DIRECT_LEADER_CODE) == null) {
            fse.setValue(CmnConst.DIRECT_LEADER_CODE, "");
        }
        String user_id = fse.getString(CmnConst.USER_ID);
        //生成员工上下级编码
        String directLeaderTricode = fse.getString(CmnConst.DIRECT_LEADER_CODE);    //获取领导编码
        String leaderCode = null;
        if (StringUtils.isEmpty(directLeaderTricode)) {
            leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, "");
        } else {
            FieldSetEntity fseLeader = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "tricode=?", new Object[]{directLeaderTricode}, false);
            leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, fseLeader.getString(CmnConst.LEADER_TRICODE));
        }
        String preLeaderTricode = fse.getString(CmnConst.LEADER_TRICODE);
        fse.setValue(CmnConst.LEADER_TRICODE, leaderCode);
 
        // 更改下属的leader_tricode
        if (!StringUtils.isEmpty(preLeaderTricode) && !preLeaderTricode.equals(leaderCode)) {
            updateSubLeaderTricode(preLeaderTricode, leaderCode);
        }
 
        StringBuilder sql = new StringBuilder();
        sql.append("select user_id,dept_uuid,ifnull(direct_leader_code,'') direct_leader_code,uuid FROM product_sys_staffs ");
        sql.append(" where user_id= ? and (direct_leader_code = ? ");
        sql.append(" or dept_uuid = ?");
        sql.append(" )");
        // 领导编码
        String direct_leader_code = fse.getString(CmnConst.DIRECT_LEADER_CODE);
        FieldSetEntity tempFs = null;
        if (!StringUtils.isEmpty(user_id)) {
            // 修改员工查询上级领导或部门是否被改变
            tempFs = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{user_id, direct_leader_code, fse.getString(CmnConst.DEPT_UUID)}, false);
        }
        if (tempFs == null || StringUtils.isEmpty(tempFs.getUUID())) {
            if (tempFs == null || !fse.getString(CmnConst.DEPT_UUID).equals(tempFs.getString(CmnConst.DEPT_UUID))) {
                FieldSetEntity deptFieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, fse.getString(CmnConst.DEPT_UUID), false);
                String org_level_code = deptFieldSet.getString(CmnConst.ORG_LEVEL_CODE);
                //目前不允许改变部门
                String tricode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.TRICODE, org_level_code);
                fse.setValue(CmnConst.TRICODE, tricode);
            }
        }
        // 创建user表信息
        fs = new FieldSetEntity();
        fs.setTableName(CmnConst.PRODUCT_SYS_USERS);
        fs.setValue(CmnConst.USER_NAME, fse.getString(CmnConst.USER_NAME));
        fs.setValue("gender", fse.getString("sex"));
        fs.setValue("user_mobile_number", fse.getString("mobile_phone"));
        fs.setValue("date_birth", fse.getString("birth_date"));
        if (StringUtils.isEmpty(user_id)) {
            // 新增时才做操作
            fs.setValue(CmnConst.USER_ACCOUNT, user_account);
            fs.setValue(CmnConst.USER_PWD, userService.createPassWord(user_account, fse.getString(CmnConst.USER_PWD)));
        } else {
            String user_uuid = fse.getString("user_uuid");
            if (!StringUtils.isEmpty(user_uuid)) {
                user_uuid = fse.getString("user_uuid");
            } else {
                // 根据user_id 查询uuid
                FieldSetEntity temp = baseDao.getFieldSetEntityByFilter(fs.getTableName(), "user_id=?", new Object[]{user_id}, false);
                user_uuid = temp.getUUID();
                // 防止user表uuid 查询不到
                user_uuid.equals(user_uuid);
            }
            fs.setValue(CmnConst.UUID, user_uuid);
        }
        fs.setValue(CmnConst.STATUS, fse.getString(CmnConst.STATUS));
        fs.setValue("contact_address", fse.getString("contact_address"));
        fs.setValue("inside_phone", fse.getString("office_telephone"));
        fs.setValue("user_primary_email", fse.getString(CmnConst.STAFF_EMAIL));
        baseDao.saveFieldSetEntity(fs);
        if (StringUtils.isEmpty(user_id)) {
            fs = baseDao.getFieldSetEntity(fs.getTableName(), fs.getUUID(), false);
            user_id = fs.getString(CmnConst.USER_ID);
            fse.setValue(CmnConst.USER_ID, user_id);
        }
        // staff 表 员工状态 写死 为在职
        fse.setValue("staff_status", 3);
 
        // 标记leader_tricode已经更新
        fse.setCodeFieldUpdateFlat(CmnConst.LEADER_TRICODE, true);
 
        baseDao.saveFieldSetEntity(fse);
        fse.setValue("product_sys_users", fs);
        return user_id;
    }
 
    /**
     * 员工修改 v2
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Override
    public boolean updateStaffInfoV2(FieldSetEntity fse) throws BaseException {
        return false;
    }
 
    /**
     * 员工删除 v2
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    @Override
    public boolean deleteStaffInfoV2(String uuid) throws BaseException {
        return false;
    }
 
    /**
     * 员工新增
     *
     * @param fse
     * @return
     * @throws BaseException
     * @throws ParseException
     */
    @Transactional
    public String addStaffInfo(FieldSetEntity fse) throws BaseException, Exception {
 
        //罗鑫2021年3月1日 开始时间不能大于结束时间
        String entry_datetime = fse.getString("entry_datetime");
        if (BaseUtil.strIsNull(entry_datetime)) {
            throw new BaseException(SystemCode.SYSTEM_ENTRY_DATE_IS_NOTNULL.getValue(), SystemCode.SYSTEM_ENTRY_DATE_IS_NOTNULL.getText(), this.getClass(), "public String addStaffInfo(FieldSetEntity fse) throws BaseException, Exception");
        }
        String probation_end = fse.getString("probation_end");
        if (!BaseUtil.strIsNull(probation_end)) {
            if (BaseUtil.temporalComparison(entry_datetime, probation_end)) {
                throw new BaseException(SystemCode.SYSTEM_ENTRY_DATE_FAIL.getValue(), SystemCode.SYSTEM_ENTRY_DATE_FAIL.getText(), this.getClass(), "public String addStaffInfo(FieldSetEntity fse) throws BaseException, Exception");
            }
        }
        // 判断账号是否重复
        String user_account = fse.getString(CmnConst.STAFF_EMAIL);
        DataTableEntity dtUser = baseDao.listTable(CmnConst.PRODUCT_SYS_USERS, "user_account=?", new Object[]{user_account});
        if (!BaseUtil.dataTableIsEmpty(dtUser)) {
            throw new BaseException(SystemCode.SYSTEM_STAFF_ADD_FAIL_ACCOUNT_REPEAT.getValue(),
                    SystemCode.SYSTEM_STAFF_ADD_FAIL_ACCOUNT_REPEAT.getText(), this.getClass(), "addStaff");
        }
        // 随机生成8位密码
        String passWord = RandomStringUtils.randomAlphanumeric(8);
 
        // 加密默认密码
        String pwd = userService.createPassWord(fse.getString(CmnConst.STAFF_EMAIL), passWord);
 
        // 创建user表对象
        FieldSetEntity fseUser = new FieldSetEntity();
        FieldMetaEntity fmeMate = new FieldMetaEntity();
        fseUser.setMeta(fmeMate);
        fmeMate.setTableName(new Object[]{CmnConst.PRODUCT_SYS_USERS});
 
        // 填充user表必填数据
        fseUser.setValue("user_name", fse.getString("show_name")); // 密码
        fseUser.setValue(CmnConst.USER_ACCOUNT, fse.getString(CmnConst.STAFF_EMAIL)); // 登陆账号,邮箱
        fseUser.setValue(CmnConst.USER_PWD, pwd); // 密码
        fseUser.setValue(CmnConst.STATUS, 1); // 账号状态,启用
        fseUser.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 创建人
        fseUser.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); // 创建时间
        fseUser.setValue(CmnConst.IS_MANAGER, 0); // 默认不是管理员
        fseUser.setValue("user_primary_email", fse.getString(CmnConst.STAFF_EMAIL));// 邮箱
        fseUser.setValue("default_language", fse.getString("default_language")); // 默认语言
 
        // 创建user表信息
        String userUUid = baseDao.add(fseUser, false);
 
        // 获取user_id
        String user_id = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_USERS, userUUid, false).getString(CmnConst.USER_ID);
 
        fse.setValue(CmnConst.USER_ID, user_id); // 关联user表uuid
 
        // 根据部门uuid生成员工编码,关联客户
        String deptUUid = fse.getString(CmnConst.DEPT_UUID);
        FieldSetEntity fseOrgLevel = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, deptUUid, false);
        if (fseOrgLevel == null) {
            throw new BaseException(SystemCode.SYSTEM_STAFFS_ADD_FAIL.getValue(),
                    SystemCode.SYSTEM_STAFFS_ADD_FAIL.getText(), this.getClass(), "addStaff");
        }
 
        // 获取部门编码和客户uuid
        String clientUUid = fseOrgLevel.getString(CmnConst.CLIENT_UUID);
 
        // 生成员工编码
        String staffCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.TRICODE, fseOrgLevel.getString(CmnConst.ORG_LEVEL_CODE));
 
        //生成员工上下级编码
        String directLeaderTricode = fse.getString(CmnConst.DIRECT_LEADER_CODE);    //获取领导编码
        String leaderCode = null;
        if (StringUtils.isEmpty(directLeaderTricode)) {
            leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, "");
        } else {
            FieldSetEntity fseLeader = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "tricode=?", new Object[]{directLeaderTricode}, false);
            leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, fseLeader.getString(CmnConst.LEADER_TRICODE));
        }
 
        fse.setValue(CmnConst.LEADER_TRICODE, leaderCode);
        fse.setValue(CmnConst.TRICODE, staffCode); // 员工编码
        fse.setValue(CmnConst.CLIENT_UUID, clientUUid);// 客户uuid
        fse.setValue(CmnConst.IS_ORG_ADMIN, 0); // 默认不为单位管理员
        fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 创建人
        fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); // 创建时间
        //杜洪波  2020-01-25 14:59:00   将show_name同步到preferred_name
        DataTableEntity dtPerferredName = fse.getSubDataTable("show_name");
        if (dtPerferredName != null) {
            DataTableEntity copyName = dtPerferredName.clones();
            copyName.getMeta().setTableName(new String[]{"preferred_name"});
            fse.addSubDataTable(copyName);
        }
 
        //员工状态判断
        timeMatch(entry_datetime, probation_end, fse);
        fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
        // 创建staff表信息
        String staffUUid = baseDao.add(fse, true);
 
 
        //判断是否准备转正,添加转正单
        if (fse.getInteger("staff_status") == 2) {
            timeTaskService.autoCreateApplicationForm(staffUUid, (new SimpleDateFormat("yyyy-MM-dd")).parse(entry_datetime), (new SimpleDateFormat("yyyy-MM-dd")).parse(probation_end));
        }
 
        // 员工系统属性处理
        String property_group_uuid = fse.getString(CmnConst.STAFF_PROPERTY_MASTER_UUID);
        if (!StringUtils.isEmpty(property_group_uuid)) {
            DataTableEntity dtSysPropertyDefalut = baseDao.listTable(
                    CmnConst.PRODUCT_SYS_STAFF_PROPERTY_GROUP_DEFALUT_VALUE, "staff_property_group_uuid=?",
                    new Object[]{property_group_uuid},
                    new String[]{CmnConst.STAFF_PROPERTY_MASTER_UUID, CmnConst.STAFF_PROPERTY_MASTER_CODE,
                            CmnConst.VALUE, "effective_utc_datetime", "org_level_uuid"});
            if (dtSysPropertyDefalut != null && dtSysPropertyDefalut.getRows() > 0) {
                FieldMetaEntity fseMate = dtSysPropertyDefalut.getMeta();
                fseMate.setTableName(new String[]{CmnConst.PRODUCT_SYS_STAFF_PROPERTY});
                dtSysPropertyDefalut.setMeta(fseMate);
                for (int i = 0; i < dtSysPropertyDefalut.getRows(); i++) {
                    FieldSetEntity fseSysPropertyDefault = dtSysPropertyDefalut.getFieldSetEntity(i);
                    fseSysPropertyDefault.getMeta().setTableName(new String[]{CmnConst.PRODUCT_SYS_STAFF_PROPERTY});
                    fseSysPropertyDefault.setValue(CmnConst.STAFF_UUID, user_id);
                }
                baseDao.add(dtSysPropertyDefalut);
            }
        }
 
 
        // 新增人员成本中心
        if (!StringUtils.isEmpty(fse.getString(CmnConst.COST_CENTER_UUID))) {
            costCenterService.addStaffCostCenter(user_id, fse.getString(CmnConst.COST_CENTER_UUID), entry_datetime);
        }
 
        // 生成员工就业信息
        FieldSetEntity fse_staff_employment_info = new FieldSetEntity();
        FieldMetaEntity fseMate = new FieldMetaEntity();
        fseMate.setTableName(new Object[]{CmnConst.PRODUCT_SYS_STAFF_EMPLOYMENT_INFO});
        fse_staff_employment_info.setMeta(fseMate);
        fse_staff_employment_info.setValue("first_employment_date", entry_datetime);    //第一次加入公司日期
        fse_staff_employment_info.setValue("employment_date", entry_datetime);            //加入公司日期
        fse_staff_employment_info.setValue(CmnConst.PROBATION_END_DATE, probation_end);    //试用结束日期
        fse_staff_employment_info.setValue(CmnConst.STAFF_UUID, staffUUid);                //员工表uuid
        baseDao.add(fse_staff_employment_info);
 
        //生成员工个人信息
        FieldSetEntity fse_staff_personal_info = new FieldSetEntity();
        fseMate.setTableName(new Object[]{CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO});
        fse_staff_personal_info.setMeta(fseMate);
        fse_staff_personal_info.setValue(CmnConst.STAFF_UUID, staffUUid);
        fse_staff_personal_info.setValue("gender", fse.getString("gender"));
        baseDao.add(fse_staff_personal_info);
 
        //代码逻辑配置
        timeTaskService.executeServiceChange(fse, CmnConst.PRODUCT_SYS_STAFFS);
 
 
        // 新增员工发送邮件
        // 邮件内容
        String login_url = URLEncoder.encode(Global.getSystemConfig("resetpwd.lxelogin_url", ""));//获取配置的员工登录页面
        FieldSetEntity nfs = new FieldSetEntity();
        nfs.setTableName("staffEmailContent");
        nfs.setValue("login_url", login_url);// 登录页面
        nfs.setValue("user_account", user_account);// 用户名
        nfs.setValue("passWord", passWord);// 密码
 
        String resultInfo = sendEmailService.parseMailTemplate(com.product.admin.config.CmnConst.NEW_EMPLOYEE_ACTIVATION, nfs);
        if (SystemCode.SYSTEM_OPERATION_SUCCESS.getText().equals(resultInfo)) {
            // luoxin 2020年12月25日 18:25:47
            selectPersonnelService.updataGruopContent(fse.getString(CmnConst.DEPT_UUID), fse.getString("job_post_uuid"), staffUUid);
            return staffUUid;
        } else {
            throw new BaseException(SystemCode.SYSTEM_MAIL_SEND_FAIL.getValue(),
                    SystemCode.SYSTEM_MAIL_SEND_FAIL.getText(), this.getClass(), "sendPasswordResetEmail");
        }
    }
 
 
    /**
     * 新增员工,状态验证
     *
     * @param entry_datetime 入职日期
     * @param probation_end  试用结束日期
     * @param fse
     * @return
     * @throws ParseException
     */
    public void timeMatch(String entry_datetime, String probation_end, FieldSetEntity fse) throws Exception {
 
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
        Date entryTime = sd.parse(entry_datetime);
        Date probationTime = sd.parse(probation_end);
        Date currentTime = new Date();
 
        if (entry_datetime.equals(probation_end)) {    //判断入职日期与试用结束日期是否相等
            if (entryTime.compareTo(currentTime) > 0) {
                fse.setValue("staff_status", 0); // 员工状态 0:准备入职
            } else {
                fse.setValue("staff_status", 2); // 员工状态 2:准备转正
            }
        } else {
            if (entryTime.compareTo(currentTime) > 0) {
                fse.setValue("staff_status", 0); // 员工状态 0:准备入职
            } else if (entryTime.compareTo(currentTime) < 0 && probationTime.compareTo(currentTime) > 0) {
                fse.setValue("staff_status", 1); // 员工状态 1:试用
            } else {
                fse.setValue("staff_status", 2); // 员工状态 2:准备转正
            }
        }
    }
 
 
    /**
     * 员工编码重复验证
     *
     * @param staff_code
     * @return
     * @throws BaseException
     */
    public boolean staffCodeValitation(String staff_code) throws BaseException {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        if (currentUser != null) {
            FieldSetEntity fse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "staff_code=? and org_level_uuid=?", new Object[]{staff_code, currentUser.getOrg_level_uuid()}, false);
            if (fse == null) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
 
    /**
     * 员工修改 1.不涉及部门修改,部门修改走员工变更
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean updateStaffInfo(FieldSetEntity fse) throws BaseException {
        boolean flag = true;
        // 修改保存不操作员工头像字段 2021年1月21日10:55:01 xupengcheng 避免查询详情时用同一字段返回url前端再提交回来保存
        fse.remove(CmnConst.STAFF_AVATAR);
        // 修改user表信息
        int user_id = fse.getInteger(CmnConst.USER_ID);
        FieldSetEntity fseUser = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?",
                new Object[]{user_id}, false);
        if (fseUser == null) {
            throw new BaseException(SystemCode.SYSTEM_STAFF_UPDATE_FAIL_USER_NO_EXIST.getValue(),
                    SystemCode.SYSTEM_STAFF_UPDATE_FAIL_USER_NO_EXIST.getText(), this.getClass(), "updateStaffInfo");
        }
        if ("1".equals(fse.getString(CmnConst.STATUS)) && "0".equals(fseUser.getString(CmnConst.STATUS))) {
            fseUser.setValue("login_fail_num", null);
            fseUser.setValue("locked_expire_time", null);
        }
        fseUser.setValue(CmnConst.STATUS, fse.getString(CmnConst.STATUS)); // 修改登录账户状态
        baseDao.update(fseUser);
 
        // 获取员工原信息
        FieldSetEntity originStaffInfo = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, fse.getUUID(), false);
 
        // 成本中心处理
        // 1.原不存在,现不存在,不处理
        // 2.原不存在,现存在,新增成本中心映射
        // 3.原存在,现不存在,删除成本中心映射
        // 4.原存在,现存在,修改成本中心映射
/*
        String origin_cost_center = originStaffInfo.getString(CmnConst.COST_CENTER_UUID);
        String new_cost_center = fse.getString(CmnConst.COST_CENTER_UUID);
        if (!new_cost_center.equals(origin_cost_center)) {
            if (!StringUtils.isEmpty(new_cost_center)) { // 杜洪波 updateTime 2020-12-17 09:48:00
                if (!StringUtils.isEmpty(origin_cost_center)) {
                    costCenterService.updateStaffCostCenter(user_id + "", new_cost_center, new Date());
                } else {
                    costCenterService.addStaffCostCenter(user_id + "", new_cost_center, new Date());
                }
            } else {
                if (!StringUtils.isEmpty(origin_cost_center)) {
                    costCenterService.deleteStaffCostCenter(user_id + "");
                }
            }
        }
*/
        // 处理文件删除
        if (!StringUtils.isEmpty(fse.getString("del"))) {
            String[] dels = fse.getString("del").split(",");
            for (int i = 0; i < dels.length; i++) {
                baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, "uuid=?", new String[]{dels[i]});
            }
        }
/*        
        DataTableEntity dtPerferredName = fse.getSubDataTable("show_name");
        DataTableEntity copyName = dtPerferredName.clones();
        for (int i = 0; i < copyName.getRows(); i++) {
            copyName.getFieldSetEntity(i).remove(CmnConst.UUID);
        }
        copyName.getMeta().setTableName(new String[]{"preferred_name"});
        fse.addSubDataTable(copyName);
 
        baseDao.delete(CmnConst.PRODUCT_SYS_LANGUAGE_CONT_VALUES, "table_name=.PRODUCT_SYS_staffs' AND field_name='preferred_name' AND data_uuid=?", new Object[]{fse.getUUID()});
 
        fse.remove("entry_datetime");
        fse.remove("probation_end");
*/
        //上级领导变化
        String originLeaderTricode = originStaffInfo.getString(CmnConst.DIRECT_LEADER_CODE);
        String newLeaderTricode = fse.getString(CmnConst.DIRECT_LEADER_CODE);
        if (!StringUtils.isEmpty(newLeaderTricode) && !originLeaderTricode.equals(newLeaderTricode)) {
            FieldSetEntity fseNewLeader = null;        //新领导
            String newLeaderCode = "";
            String originLeaderCode = fse.getString(CmnConst.LEADER_TRICODE);
            if (!StringUtils.isEmpty(originLeaderTricode) && StringUtils.isEmpty(newLeaderTricode)) {    //上级领导 有-->无
                newLeaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, "");
            } else {    //上级领导 无-->有 或  旧-->新
                fseNewLeader = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "tricode=?", new Object[]{newLeaderTricode}, false);
                newLeaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, fseNewLeader.getString(CmnConst.LEADER_TRICODE));
            }
            fse.setValue(CmnConst.LEADER_TRICODE, newLeaderCode);
            changeSubLeaderTricode(originLeaderCode, newLeaderCode);
        }
        // 修改staff表信息
        flag = baseDao.update(fse);
        // luoxin 2020年12月25日 18:25:47
        selectPersonnelService.updataGruopContent(fse.getString(CmnConst.DEPT_UUID), fse.getString("job_post_uuid"),
                fse.getString("uuid"));
        // xu pengcheng updateTime 2020年11月28日14:39:06 修改员工更新员工信息
        updateLoginUserInfoService.updateUserInfoByUserId(user_id, 2, false);
        return flag;
    }
 
    /**
     * 变更后代leader_tricode编码
     *
     * @param oldLeaderCode
     * @param newLeaderCode
     */
    public void changeSubLeaderTricode(String oldLeaderCode, String newLeaderCode) {
        StringBuilder sql = new StringBuilder();
        sql.append(" UPDATE product_sys_staffs ");
        sql.append(" SET leader_tricode=concat(replace(substring(leader_tricode,1,locate(?,leader_tricode)+length(?)),?,?),substring(leader_tricode,locate(?,leader_tricode)+length(?)+1)) ");
        sql.append(" WHERE leader_tricode LIKE ? ");
        baseDao.executeUpdate(sql.toString(), new Object[]{oldLeaderCode, oldLeaderCode, oldLeaderCode, newLeaderCode, oldLeaderCode, oldLeaderCode, oldLeaderCode + "%"});
        DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, "tricode");
    }
 
    /**
     * 变更后代leader_tricode编码 6c 2022年3月21日 16:42:31
     * @param preLeaderTricode
     * @param newLeaderTricode
     */
    private void updateSubLeaderTricode(String preLeaderTricode, String newLeaderTricode) {
        StringBuilder sql = new StringBuilder(128);
        sql.append("update product_sys_staffs set leader_tricode=concat(?,substring(leader_tricode,length(?)+1)) where leader_tricode like concat(?,'%') and leader_tricode<>?");
        baseDao.executeUpdate(sql.toString(), new Object[]{newLeaderTricode, preLeaderTricode, preLeaderTricode, preLeaderTricode});
        DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE);
    }
 
    /**
     * 员工账号冻结
     *
     * @param user_id 登录用户user_id
     * @return
     * @throws BaseException
     */
    public boolean staffFreezAccount(String user_id) throws BaseException {
        boolean flag = true;
 
        // 查找对应user表信息
        FieldSetEntity fseUser = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?", new Object[]{user_id}, false);
        if (fseUser == null) {
            throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(),
                    SystemCode.SYSTEM_USER_INFO_NO_EXIST.getText(), this.getClass(), "staffFreezAccount");
        }
        fseUser.setValue(CmnConst.STATUS, 0);
        flag = baseDao.update(fseUser);
        return flag;
    }
 
    /**
     * 员工账号解冻
     *
     * @param user_id 登录用户user_id
     * @return
     * @throws BaseException
     */
    public boolean staffFreeAccount(String user_id) throws BaseException {
        boolean flag = true;
 
        // 查找对应user表信息
        FieldSetEntity fseUser = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?",
                new Object[]{user_id}, false);
        if (fseUser == null) {
            throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(),
                    SystemCode.SYSTEM_USER_INFO_NO_EXIST.getText(), this.getClass(), "staffFreezAccount");
        }
        fseUser.setValue(CmnConst.STATUS, 1);
        flag = baseDao.update(fseUser);
        return flag;
    }
 
    /**
     * 员工删除
     *
     * @param uuid 员工uuid
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean deleteStaffInfo(String uuid) throws BaseException {
 
        // 处理地址
        baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_ADDRESS, "staff_uuid=?", new String[]{uuid});
 
        // 处理个人信息
        baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO, "staff_uuid=?", new String[]{uuid});
 
        // 处理银行信息
        baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_BANK_ACCOUNT, "staff_uuid=?", new Object[]{uuid});
 
        // 处理就业信息
        baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_EMPLOYMENT_INFO, "staff_uuid=?", new Object[]{uuid});
 
        // 处理联系人
        baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_EMERGENCY_CONTACT_INFO, "staff_uuid=?", new Object[]{uuid});
 
        // 处理绑定成本中心
        baseDao.delete("product_sys_staff_cost_center", "staff_uuid=?", new String[]{uuid});
 
        // 处理员工文件信息
        FieldSetEntity staff = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, uuid, false);
        if (staff != null && !StringUtils.isEmpty(staff.getString("staff_image"))) {
            String[] staff_images = staff.getString("staff_image").split(",");
            if (staff_images.length > 0) {
                for (int i = 0; i < staff_images.length; i++) {
                    baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new Object[]{staff_images[i]});
                }
            }
        }
 
        // 删除完成
        return baseDao.delete(CmnConst.PRODUCT_SYS_STAFFS, "uuid=?", new String[]{uuid});
    }
 
    /**
     * 员工重置密码
     *
     * @param user_id 登录用户user_id
     * @return
     * @throws BaseException
     */
    public boolean resetPassword(String user_id) throws BaseException {
        FieldSetEntity fse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?", new Object[]{user_id}, false);
        if (fse == null) {
            throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_USER_INFO_NO_EXIST.getText(), this.getClass(), "resetPassword");
        }
        // 后端配置,重置密码模工=mail,则随机生成8位密码,发送到邮件,否则是默认初始密码
        String passWord =com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL.equals(Global.getSystemConfig(com.product.admin.config.CmnConst.RESET_PWD_MODEL,com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL))? 
                RandomStringUtils.randomAlphanumeric(8):Global.getSystemConfig(com.product.admin.config.CmnConst.INITIAL_PWD, null);
 
        // 加密默认密码
        String pwd = userService.createPassWord(fse.getString(CmnConst.USER_ACCOUNT), passWord);
        fse.setValue(CmnConst.USER_PWD, pwd);
        if(com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL.equals(Global.getSystemConfig(com.product.admin.config.CmnConst.RESET_PWD_MODEL,com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL))) {
            // 密码重置成功发送邮件(无模板,暂未调用)
            String login_url = URLEncoder.encode(Global.getSystemConfig("resetpwd.lxlogin_url", ""));
            FieldSetEntity nfs = new FieldSetEntity();
            nfs.setTableName(com.product.admin.config.CmnConst.STAFF_EMAIL_CONTENT);
            nfs.setValue(com.product.admin.config.CmnConst.LOGIN_URL,login_url);// 登录页面
            nfs.setValue(CmnConst.USER_ACCOUNT, fse.getString(CmnConst.USER_ACCOUNT));// 用户名
            nfs.setValue(com.product.admin.config.CmnConst.PASS_WORD, passWord);// 随机新密码
            nfs.setValue(com.product.admin.config.CmnConst.USER_PRIMARY_EMAIL, fse.getString(com.product.admin.config.CmnConst.USER_PRIMARY_EMAIL));// 接受邮件邮箱地址
            sendEmailService.parseMailTemplate(com.product.admin.config.CmnConst.PLATFORM_ADMINISTRATOR_RESET_PASSWORD_EMAIL, nfs);
        }
        return baseDao.update(fse);
    }
 
    /**
     * 新增或修改员工个人信息,地址信息
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean staffPersonalAndAddress(FieldSetEntity fse) throws BaseException {
        DataTableEntity dtStaffPersonalInfo = fse.getSubDataTable(CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO);
        if (dtStaffPersonalInfo != null) {
            String brithTime = dtStaffPersonalInfo.getFieldSetEntity(0).getString("date_of_brith");
            if (StringUtils.isEmpty(brithTime)) { // 杜洪波 updateTime 2020-12-17 09:48:00
                dtStaffPersonalInfo.getFieldSetEntity(0).setValue("date_of_brith", null);
            }
        }
        return baseDao.update(fse, true);
    }
 
    /**
     * 新增或修改员工就业信息
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean staffEmploymentInfo(FieldSetEntity fse) throws BaseException {
        boolean flag = true;
        if (StringUtils.isEmpty(fse.getString(CmnConst.UUID))) { // 新增
            fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
            fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
            String uuid = baseDao.add(fse);
            if (StringUtils.isEmpty(uuid)) {
                return false;
            }
        } else { // 修改
            fse.remove(CmnConst.CREATED_BY);
            fse.remove(CmnConst.CREATED_UTC_DATETIME);
            fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
            fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
            flag = baseDao.update(fse);
            if (!flag) {
                throw new BaseException(SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getValue(),
                        SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getText(), this.getClass(),
                        "staffEmploymentInfo");
            }
            String employment_date = fse.getString("employment_date");
 
            FieldSetEntity fseStaff = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, fse.getString(CmnConst.STAFF_UUID), false);
            if (fseStaff == null) {
                throw new BaseException(SystemCode.SYSTEM_STAFFS_FIND_FAIL.getValue(), SystemCode.SYSTEM_STAFFS_FIND_FAIL.getText(), this.getClass(), "staffEmploymentInfo");
            }
            String user_id = fseStaff.getString(CmnConst.USER_ID);
 
            FieldSetEntity fs = baseDao.getFieldSetEntityByFilter("product_sys_staff_cost_center", "staff_uuid=?",
                    new String[]{user_id}, false);
            if (fs != null) {
                fs.setValue("effective_start_date", employment_date);
                fs.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
                fs.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
                flag = baseDao.update(fs);
                if (!flag) {
                    throw new BaseException(SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getValue(),
                            SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getText(), this.getClass(),
                            "staffEmploymentInfo");
                }
            }
        }
        return flag;
    }
 
    /**
     * 新增或修改人员银行信息
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean staffBankInfo(FieldSetEntity fse) throws BaseException {
        return baseDao.update(fse);
    }
 
    /**
     * 新增或修改紧急联系人信息
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean staffEmergencyContactInfo(FieldSetEntity fse) throws BaseException {
        return baseDao.update(fse);
    }
 
    /**
     * 员工属性列表
     *
     * @param uuid 员工uuid
     * @return
     * @throws BaseException
     */
    public JSONObject listStaffProperty(String staff_uuid, String user_id) throws BaseException {
 
        // 获取员工属性
        DataTableEntity dtStaffProperty = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFF_PROPERTY, " staff_uuid=? ",
                new Object[]{user_id});
        if (dtStaffProperty == null || dtStaffProperty.getRows() == 0) {
 
            // 生成员工属性
            DataTableEntity dtStaffMaster = baseDao.listTable("product_sys_staff_property_master", null, new Object[]{},
                    new Object[]{"uuid", CmnConst.STAFF_PROPERTY_MASTER_CODE, CmnConst.PROMPT_NAME});
 
            // 获取员工所属单位
            FieldSetEntity fseStaffInfo = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, staff_uuid, false);
            String org_level_uuid = fseStaffInfo.getString(CmnConst.ORG_LEVEL_UUID);
 
            DataTableEntity dtNew = new DataTableEntity();
            FieldMetaEntity fseMate = new FieldMetaEntity();
            fseMate.setTableName(new Object[]{"product_sys_staff_property"});
            for (int i = 0; i < dtStaffMaster.getRows(); i++) {
                FieldSetEntity fseMaster = dtStaffMaster.getFieldSetEntity(i);
                FieldSetEntity fseNew = new FieldSetEntity();
                fseNew.setMeta(fseMate);
                fseNew.setValue(CmnConst.STAFF_UUID, user_id);
                fseNew.setValue(CmnConst.STAFF_PROPERTY_MASTER_UUID, fseMaster.getString("uuid"));
                fseNew.setValue(CmnConst.STAFF_PROPERTY_MASTER_CODE,
                        fseMaster.getString(CmnConst.STAFF_PROPERTY_MASTER_CODE));
                fseNew.setValue(CmnConst.ORG_LEVEL_UUID, org_level_uuid);
                dtNew.addFieldSetEntity(fseNew);
            }
            if (!BaseUtil.dataTableIsEmpty(dtNew)) {
                baseDao.add(dtNew);
            }
        }
 
        JSONObject jsonStaffProperty = new JSONObject();
        StringBuilder sqlCommon = new StringBuilder();
 
        sqlCommon.append(" SELECT ");
        sqlCommon.append(
                " d.staff_property_id,d.uuid,d.staff_uuid,e.uuid staff_property_master_uuid,e.staff_property_master_code,d.value,d.effective_utc_datetime,d.org_level_uuid,e.uuid, ");
        sqlCommon.append(" e.staff_property_master_name,e.prompt_name ");
        sqlCommon.append(" FROM ( ");
 
        sqlCommon.append(" SELECT ");
        sqlCommon.append(
                " a.staff_property_id,a.uuid,a.staff_uuid,a.staff_property_master_uuid,a.staff_property_master_code,a.value,a.effective_utc_datetime,a.org_level_uuid, ");
        sqlCommon.append(
                " CASE WHEN LOCATE( '|', a.staff_property_master_code) THEN REVERSE(SUBSTR(REVERSE(a.staff_property_master_code) FROM INSTR(REVERSE( a.staff_property_master_code ), '|' ) + 1 )) END AS parent_code ");
        sqlCommon.append(" FROM product_sys_staff_property AS a,( ");
        sqlCommon.append(" SELECT ");
        sqlCommon.append(" staff_property_master_uuid,MAX(effective_utc_datetime) AS effective_utc_datetime ");
        sqlCommon.append(" FROM product_sys_staff_property ");
        sqlCommon.append(" WHERE effective_utc_datetime <= NOW() AND staff_uuid = ? ");
        sqlCommon.append(" GROUP BY staff_property_master_uuid ");
        sqlCommon.append(" ) AS c ");
        sqlCommon.append(
                " WHERE a.staff_property_master_uuid = c.staff_property_master_uuid AND a.effective_utc_datetime = c.effective_utc_datetime AND a.staff_uuid = ? ");
 
        sqlCommon.append(" UNION ALL ");
 
        sqlCommon.append(" SELECT ");
        sqlCommon.append(
                " a.staff_property_id,a.uuid,a.staff_uuid,a.staff_property_master_uuid,a.staff_property_master_code,'',a.effective_utc_datetime,a.org_level_uuid, ");
        sqlCommon.append(
                " CASE WHEN LOCATE( '|', a.staff_property_master_code) THEN REVERSE(SUBSTR(REVERSE(a.staff_property_master_code) FROM INSTR(REVERSE( a.staff_property_master_code ), '|' ) + 1 )) END AS parent_code ");
        sqlCommon.append(" FROM product_sys_staff_property AS a,( ");
        sqlCommon.append(" SELECT ");
        sqlCommon.append(" staff_property_master_uuid,MIN(effective_utc_datetime) AS effective_utc_datetime ");
        sqlCommon.append(" FROM product_sys_staff_property ");
        sqlCommon.append(" WHERE staff_uuid= ? ");
        sqlCommon.append(" GROUP BY staff_property_master_uuid ");
        sqlCommon.append(" HAVING MIN(effective_utc_datetime) > NOW() ");
        sqlCommon.append(" ) AS c ");
        sqlCommon.append(
                " WHERE a.staff_property_master_uuid = c.staff_property_master_uuid AND a.effective_utc_datetime = c.effective_utc_datetime AND a.staff_uuid = ? ");
 
        sqlCommon.append(" UNION ALL ");
 
        sqlCommon.append(" SELECT ");
        sqlCommon.append(
                " a.staff_property_id,a.uuid,a.staff_uuid,a.staff_property_master_uuid,a.staff_property_master_code,'',a.effective_utc_datetime,a.org_level_uuid, ");
        sqlCommon.append(
                " CASE WHEN LOCATE( '|', a.staff_property_master_code) THEN REVERSE(SUBSTR(REVERSE(a.staff_property_master_code) FROM INSTR(REVERSE( a.staff_property_master_code ), '|' ) + 1 )) END AS parent_code ");
        sqlCommon.append(" FROM product_sys_staff_property AS a,( ");
        sqlCommon.append(" SELECT ");
        sqlCommon.append(" staff_property_master_uuid,staff_property_master_code ");
        sqlCommon.append(" FROM product_sys_staff_property ");
        sqlCommon.append(" WHERE staff_uuid= ? AND effective_utc_datetime IS NULL AND value IS NULL ");
        sqlCommon.append(" ) AS c ");
        sqlCommon.append(" WHERE a.staff_property_master_uuid = c.staff_property_master_uuid AND a.staff_uuid = ? ");
 
        sqlCommon.append(" ) AS d ");
        sqlCommon.append(
                " RIGHT JOIN product_sys_staff_property_master AS e ON d.staff_property_master_uuid = e.uuid AND d.staff_property_master_code=e.staff_property_master_code "); // 杜洪波
        // updateTime
        // 2020-01-06
        // 11:40:00
        // 属性显示异常
 
        String sqlParent = sqlCommon + " WHERE d.parent_code IS NULL ORDER BY e.sequence";
        String sqlSub = sqlCommon + " WHERE d.parent_code IS NOT NULL ORDER BY e.sequence";
 
        // 根属性
        DataTableEntity dtParent = baseDao.listInternationDataTable(baseDao.listTable(sqlParent.toString(),
                new Object[]{user_id, user_id, user_id, user_id, user_id, user_id}), null);
        // 子属性
        DataTableEntity dtSub = baseDao.listInternationDataTable(baseDao.listTable(sqlSub.toString(),
                new Object[]{user_id, user_id, user_id, user_id, user_id, user_id}), null);
 
        if (dtParent.getRows() > 0) {
            // 装载属性
            JSONArray json = sysPropertyGroup(dtParent, dtSub);
            jsonStaffProperty.put(CmnConst.PRODUCT_SYS_STAFF_PROPERTY, json);
        }
        return jsonStaffProperty;
    }
 
    /**
     * 员工属性详情
     *
     * @param staff_uuid  员工uuid
     * @param master_uuid 属性uuid
     * @return
     * @throws BaseException
     */
    public DataTableEntity findStaffProperty(String staff_uuid, String master_uuid) throws BaseException {
        String sql = "select a.*,b.prompt_name FROM product_sys_staff_property a LEFT JOIN product_sys_staff_property_master b ON a.staff_property_master_code=b.staff_property_master_code where staff_uuid=? and staff_property_master_uuid=? ";
        return baseDao.listTable(sql, new Object[]{staff_uuid, master_uuid});
    }
 
    /**
     * 员工属性组修改
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean updateStaffProperty(FieldSetEntity fse) throws BaseException {
        DataTableEntity dtStaffProperty = fse.getSubDataTable(CmnConst.PRODUCT_SYS_STAFF_PROPERTY);
        if (dtStaffProperty != null && dtStaffProperty.getRows() > 0) {
            int delCount = 0;
            int rowCount = dtStaffProperty.getRows();
            for (int i = 0; i < rowCount; i++) {
                FieldSetEntity fseDefaultProperty = dtStaffProperty.getFieldSetEntity(i);
                String doMethod = fseDefaultProperty.getString("~type~");
                if (doMethod != null && "del".equals(doMethod)) {
                    delCount++;
                }
            }
            if (delCount == rowCount) {
                FieldSetEntity fseSaveDefaultProperty = dtStaffProperty.getFieldSetEntity(0);
                baseDao.executeUpdate(
                        "update product_sys_staff_property set effective_utc_datetime = NULL,value=NULL where uuid=?",
                        new Object[]{fseSaveDefaultProperty.getUUID()});
                dtStaffProperty.removeFieldSetEntity(0);
            }
            if (dtStaffProperty.getRows() == 0) {
                return true;
            } else {
                return baseDao.update(dtStaffProperty);
            }
        } else {
            return true;
        }
    }
 
    /**
     * 员工个人信息详情
     *
     * @param staff_uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffPersonalInfo(String staff_uuid) throws BaseException {
        FieldSetEntity fseStaffPersonal = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO,
                "staff_uuid=?", new Object[]{staff_uuid}, false);
        if (fseStaffPersonal == null) {
            return null;
        }
        String sql = "select *,case when effective_start_date<now() then 0 else 1 end as status FROM product_sys_staff_address where staff_uuid=?";
        DataTableEntity dtStaffAddress = baseDao.listTable(sql, new Object[]{staff_uuid});
        Map<String, DataTableEntity> mapStaffAddress = new HashMap<String, DataTableEntity>();
        mapStaffAddress.put(CmnConst.PRODUCT_SYS_STAFF_ADDRESS, dtStaffAddress);
        if (!mapStaffAddress.isEmpty()) {
            fseStaffPersonal.setSubData(mapStaffAddress);
        }
        return fseStaffPersonal;
    }
 
    /**
     * 员工地址详情
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffAddressInfo(String uuid) throws BaseException {
        return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_ADDRESS, uuid, false);
    }
 
    /**
     * 员工就业信息详情
     *
     * @param staff_uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffEmploymentInfo(String staff_uuid) throws BaseException {
        return baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFF_EMPLOYMENT_INFO, "staff_uuid=?",
                new Object[]{staff_uuid}, false);
    }
 
    /**
     * 员工银行信息列表
     *
     * @param staff_uuid
     * @return
     * @throws BaseException
     */
    public DataTableEntity listStaffBankInfo(String staff_uuid) throws BaseException {
        return baseDao.listTable(CmnConst.PRODUCT_SYS_STAFF_BANK_ACCOUNT, "staff_uuid=?", new Object[]{staff_uuid});
    }
 
    /**
     * 员工银行详情
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffBankInfo(String uuid) throws BaseException {
        return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_BANK_ACCOUNT, uuid, false);
    }
 
    /**
     * 员工紧急联系人列表
     *
     * @param staff_uuid
     * @return
     * @throws BaseException
     */
    public DataTableEntity listStaffEmergencyContactInfo(String staff_uuid) throws BaseException {
        return baseDao.listTable(CmnConst.PRODUCT_SYS_STAFF_EMERGENCY_CONTACT_INFO, "staff_uuid=?",
                new Object[]{staff_uuid});
    }
 
    /**
     * 员工紧急联系人详情
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffEmergencyContactInfo(String uuid) throws BaseException {
        return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_EMERGENCY_CONTACT_INFO, uuid, false);
    }
 
    /**
     * 员工属性封装
     *
     * @param dataParent 根属性
     * @param dataSub    子属性
     * @return
     * @throws BaseException
     */
    public JSONArray sysPropertyGroup(DataTableEntity dataParent, DataTableEntity dataSub) throws BaseException {
        JSONArray propertyArray = new JSONArray();
        // 遍历根属性
        for (int i = 0; i < dataParent.getRows(); i++) {
            JSONObject sysProperty = new JSONObject();
            FieldSetEntity fs = dataParent.getFieldSetEntity(i);
            if (!StringUtils.isEmpty(fs.getString(CmnConst.STAFF_PROPERTY_MASTER_CODE))) { // 杜洪波 updateTime 2020-12-17
                // 09:48:00
                sysProperty.put(CmnConst.DATA_TYPE, dataParent.getString(i, CmnConst.DATA_TYPE)); // 数据类型
                sysProperty.put(CmnConst.VALUE, dataParent.getString(i, CmnConst.VALUE)); // 默认值
                sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_UUID,
                        dataParent.getString(i, CmnConst.STAFF_PROPERTY_MASTER_UUID)); // uuid
                sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_CODE,
                        dataParent.getString(i, CmnConst.STAFF_PROPERTY_MASTER_CODE)); // 编码code
                sysProperty.put(CmnConst.PARENT_CODE, dataParent.getString(i, CmnConst.PARENT_CODE)); // 父级编码code
                sysProperty.put(CmnConst.PROMPT_NAME, dataParent.getString(i, CmnConst.PROMPT_NAME)); // 参照名
                sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_NAME,
                        getPropertyNameLanguage(fs.getSubDataTable(CmnConst.STAFF_PROPERTY_MASTER_NAME))); // 属性名称
 
                // 获取当前根属性的子属性
                JSONArray moduleChild = sysPropertyGroupSub(dataSub, fs.getString(CmnConst.STAFF_PROPERTY_MASTER_CODE));
                sysProperty.put("children", moduleChild);
                propertyArray.add(sysProperty);
            }
        }
        return propertyArray;
    }
 
    /**
     * 员工子属性封装
     *
     * @param data
     * @param tricode_parent 父级属性节点编码
     * @return
     * @throws BaseException
     */
    public JSONArray sysPropertyGroupSub(DataTableEntity dataSub, String tricode_parent) throws BaseException {
        JSONArray propertyArray = new JSONArray();
        // 遍历子属性
        for (int i = 0; i < dataSub.getRows(); i++) {
            JSONObject sysProperty = new JSONObject();
            FieldSetEntity fs = dataSub.getFieldSetEntity(i);
            // 匹配子属性
            if (tricode_parent.equals(dataSub.getString(i, CmnConst.PARENT_CODE))) {
                // 装载属性
                sysProperty.put(CmnConst.DATA_TYPE, dataSub.getString(i, CmnConst.DATA_TYPE)); // 数据类型
                sysProperty.put(CmnConst.VALUE, dataSub.getString(i, CmnConst.VALUE));
                sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_UUID,
                        dataSub.getString(i, CmnConst.STAFF_PROPERTY_MASTER_UUID)); // uuid
                sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_CODE,
                        dataSub.getString(i, CmnConst.STAFF_PROPERTY_MASTER_CODE)); // 属性编码
                sysProperty.put(CmnConst.PARENT_CODE, dataSub.getString(i, CmnConst.PARENT_CODE)); // 父级属性编码
                sysProperty.put(CmnConst.PROMPT_NAME, dataSub.getString(i, CmnConst.PROMPT_NAME)); // 参照名
                sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_NAME,
                        getPropertyNameLanguage(fs.getSubDataTable(CmnConst.STAFF_PROPERTY_MASTER_NAME))); // 属性名称
 
                JSONArray jsonSub = sysPropertyGroupSub(dataSub,
                        dataSub.getString(i, CmnConst.STAFF_PROPERTY_MASTER_CODE));
                if (!jsonSub.isEmpty()) {
                    sysProperty.put("children", jsonSub);
                }
                propertyArray.add(sysProperty);
            }
        }
        return propertyArray;
    }
 
    /**
     * 封装系统属性名称国际化
     *
     * @return
     * @throws BaseException
     */
    public List<JSONObject> getPropertyNameLanguage(DataTableEntity dtPropertyLanguage) throws BaseException {
 
        List<JSONObject> listPropertyName = new ArrayList<JSONObject>();
 
        if (dtPropertyLanguage != null && dtPropertyLanguage.getRows() > 0) {
 
            // 遍历获取语言代码和国际化值
            FieldMetaEntity meta = dtPropertyLanguage.getMeta();
            Object[] fields12 = meta.getFields();
            List<Object> asList = new ArrayList<>();
            asList.addAll(Arrays.asList(fields12));
            Iterator<Object> iterator = asList.iterator();
            for (int i = 0; i < dtPropertyLanguage.getRows(); i++) {
                while (iterator.hasNext()) {
                    Object next = iterator.next();
                    if (!next.toString().equals("uuid") && !next.toString().equals("language_code")) {
                        String string = dtPropertyLanguage.getString(i, next.toString());
                        if (!StringUtils.isEmpty(string)) {
                            JSONObject propertyName = new JSONObject();
                            propertyName.put(next.toString(), string);
                            listPropertyName.add(propertyName);
                            iterator.remove();
                            break;
                        }
                    } else {
                        iterator.remove();
                    }
                }
            }
        }
        return listPropertyName;
    }
 
    /**
     * 获取指定人员的所有直接下属
     *
     * @param staffUuid
     */
    public DataTableEntity loadDirectSubordinate(String staffUuid) throws BaseException {
        if (StringUtil.isBlank(staffUuid)) {
            return null;
        }
        return baseDao.listTable(
                "select * FROM product_sys_staffs where direct_leader_code=(select tricode FROM product_sys_staffs where uuid=? ) and direct_leader_code is not null",
                new String[]{staffUuid});
    }
 
    /**
     * 获取指定人员的所有直接下属
     *
     * @param user_id用户id
     */
    public DataTableEntity loadDirectSubordinate(int user_id) throws BaseException {
        return baseDao.listTable(
                "select * FROM product_sys_staffs where direct_leader_code=(select tricode FROM product_sys_staffs where user_id=? ) and direct_leader_code is not null",
                new Object[]{user_id});
    }
 
    /**
     * 获取指定人员的所有直接下属
     *
     * @param staffUuid
     */
    public DataTableEntity loadAllSubordinate(String staffUuid) throws BaseException {
        if (StringUtil.isBlank(staffUuid)) {
            return null;
        }
        FieldSetEntity fs = baseDao.getFieldSetEntity("product_sys_staffs", staffUuid, false);
        return loadAllSubordinate(fs);
    }
 
    /**
     * 获取指定人员的所有下属
     *
     * @param user_id用户id
     */
    public DataTableEntity loadAllSubordinate(int user_id) throws BaseException {
        FieldSetEntity fs = baseDao.getFieldSetEntityByFilter("product_sys_staffs", "user_id=?", new Object[]{user_id}, false);
        return loadAllSubordinate(fs);
    }
 
    /**
     * 获取指定人员的所有下属
     *
     * @param fs staff
     */
    public DataTableEntity loadAllSubordinate(FieldSetEntity fs) throws BaseException {
        if (fs == null || StringUtils.isEmpty(fs.getString(CmnConst.LEADER_TRICODE))) {
            return null;
        }
//        DataTableEntity c=baseDao.listTable("select getChildrenOrg('"+fs.getString(CmnConst.TRICODE)+"') a", new String[] {});
        String sql = "select tricode uuid FROM product_sys_staffs where leader_tricode like ? AND leader_tricode !=?";
        DataTableEntity c = baseDao.listTable(sql, new Object[]{fs.getString(CmnConst.LEADER_TRICODE) + "%", fs.getString(CmnConst.LEADER_TRICODE)});
        Object[] uuid = c.getUuids();
        if (c != null && c.getRows() > 0 && uuid != null) {
//            String b=c.getString(0,"a");
            String b = org.apache.commons.lang3.StringUtils.join(uuid, ",");
            Object vs[] = BaseUtil.buildQuestionMarkFilter(" tricode ", " in ", b);
            if (vs != null && vs.length > 1 && vs[1] != null) {
                String filter = vs[0].toString();
                List<String> paras = (List<String>) vs[1];
                return baseDao.listTable("product_sys_staffs", filter, paras.toArray());
            }
        }
        return null;
    }
 
    /**
     * 根据 staffUUID获取人员的直属领导
     *
     * @param staffUuid 员工uuid
     * @throws BaseException 通用查询错误
     * @return"product_sys_staffs的记录,没有查到则为null
     */
    public FieldSetEntity loadStaffLeader(String staffUuid) throws BaseException {
 
        if (!StringUtil.isBlank(staffUuid)) {
            String sql = "select * FROM product_sys_staffs where tricode=(select DISTINCT direct_leader_code FROM product_sys_staffs where uuid=?  and direct_leader_code is not null )";
            DataTableEntity dt = baseDao.listTable(sql, new String[]{staffUuid});
            if (dt.getRows() > 0) {
                return dt.getFieldSetEntity(0);
            }
        }
        return null;
    }
 
    /**
     * 获取人员的直属领导
     *
     * @param userid"product_sys_user表id
     * @throws BaseException 通用查询错误
     * @return"product_sys_staffs的记录,没有查到则为null
     */
    public FieldSetEntity loadStaffLeader(Integer userid) throws BaseException {
        if (userid != null) {
            String sql = "select * FROM product_sys_staffs where tricode=(select DISTINCT direct_leader_code FROM product_sys_staffs where user_id=? and direct_leader_code is not null )";
            DataTableEntity dt = baseDao.listTable(sql, new Integer[]{userid});
            if (dt.getRows() > 0) {
                return dt.getFieldSetEntity(0);
            }
        }
        return null;
    }
 
    /**
     * 员工信息列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity findStaffByCondition(FieldSetEntity fse) throws BaseException {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.uuid, ");
        sql.append(" b.uuid, ");
        sql.append(" c.uuid, ");
        sql.append(" d.uuid, ");
        sql.append(" e.uuid, ");
        sql.append(" f.uuid, ");
        sql.append(" a.user_id, ");
        sql.append(" a.show_name, ");
        sql.append(" a.staff_code, ");
        sql.append(" a.staff_email, ");
        sql.append(" a.staff_status, ");
        sql.append(" ");
        sql.append(" a.christian_name, ");
        sql.append(" a.role_uuids, ");
        sql.append(" a.org_level_uuid, ");
        sql.append(" a.dept_uuid, ");
        sql.append(" a.staff_id, ");
        sql.append(" a.job_post_uuid, ");
        sql.append(" a.job_post_grade_uuid, ");
        sql.append(
                " (select uuid FROM product_sys_staffs where tricode=a.direct_leader_code AND tricode !=NULL) direct_leader_code, ");
        sql.append(" a.cost_center_uuid, ");
        sql.append(" a.entry_datetime, ");
        sql.append(" b.org_level_all org_level, ");
        sql.append(" h.org_level_all client_and_org, ");
        sql.append(" h.org_level_name dept_name, ");
        sql.append(" c.STATUS, ");
        sql.append(" d.job_post_name,e.job_grade_name, ");
        sql.append(" f.client_name,b.org_level_all");
        sql.append(
                " ,concat(g.attachment_domain,'/',g.attachment_container,'/',g.module_uuid,'/',g.attachment_title,?) staff_avatar ");
        sql.append(" FROM ");
        sql.append(" product_sys_staffs AS a ");
        sql.append(" LEFT JOIN product_sys_org_levels b ON a.org_level_uuid = b.uuid ");
        sql.append(" LEFT JOIN product_sys_org_levels h ON a.dept_uuid = h.uuid ");
        sql.append(" LEFT JOIN product_sys_users c ON a.user_id = c.user_id ");
        sql.append(" LEFT JOIN product_sys_job_posts d ON a.job_post_uuid = d.uuid ");
        sql.append(" LEFT JOIN product_sys_job_post_grades e ON a.job_post_grade_uuid = e.uuid ");
        sql.append(" LEFT JOIN product_sys_clients f ON a.client_uuid = f.uuid ");
        sql.append(" LEFT JOIN product_sys_attachments g ON g.uuid = a.staff_avatar ");
        sql.append(
                " WHERE (a.org_level_uuid =? or ?=(SELECT uuid FROM product_sys_org_levels WHERE uuid='00000000-0000-0000-0000-000000000000'))");
 
        String org_level_uuid = fse.getString(CmnConst.ORG_LEVEL_UUID);
        List<Object> params = new ArrayList<>();
        params.add(Global.getSystemConfig("upload.key", ""));
        params.add(org_level_uuid);
        params.add(org_level_uuid);
        // luoxin 2020年12月14日 17:13:24 修改in 查询条件
        if (!StringUtils.isEmpty(fse.getObject(CmnConst.FILTER))) { // 杜洪波 updateTime 2020-12-17 09:48:00
            sql = sql.append("and staff_status in(?");
            Object[] condition = fse.getString(CmnConst.FILTER).split(",");
            for (int i = 1; i < condition.length; i++) {
                sql.append(" ,?");
            }
            sql.append(")");
            params.addAll(Arrays.asList(condition));
        }
        if (!StringUtils.isEmpty(fse.getString("notfilter"))) { // 杜洪波 updateTime 2020-12-17 09:48:00
            String notfilter = fse.getString("notfilter");
            String[] notfilterArr = notfilter.split(",");
            sql.append(" and a.uuid not in (");
            List<String> list = new ArrayList<String>();
            for (int i = 0; i < notfilterArr.length; i++) {
                list.add("?");
                params.add(notfilterArr[i]);
            }
            String join = StringUtils.join(list.toArray(), ",");
            sql.append(join);
            sql.append(")");
        }
        String key = fse.getString("key");
        String value = fse.getString("value");
        if (!(StringUtils.isEmpty(key) || StringUtils.isEmpty(value))) {
            String[] valueArray = value.split(",");
            if (!StringUtils.isArrayEmpty(valueArray)) {
                sql.append(" OR ").append(BaseUtil.buildQuestionMarkFilter("a." + key, valueArray.length, true));
                params.addAll(Arrays.asList(valueArray));
            }
        }
        DataTableEntity dt = baseDao.listTable(sql.toString(), params.toArray());
        dt.getMeta().addAliasField("product_sys_staffs.show_name", "show_name");
        dt.getMeta().addAliasField("product_sys_job_posts.job_post_name", "job_post_name");
        dt.getMeta().addAliasField("product_sys_job_post_grades.job_grade_name", "job_grade_name");
        dt.getMeta().addAliasField("product_sys_clients.client_name", "client_name");
        dt.getMeta().addAliasField("product_sys_org_levels.org_level_all", CmnConst.ORG_LEVEL_ALL);
 
        return baseDao.listInternationDataTable(dt, null);
        // staff_avatar
//        String sostoken = Global.getSystemConfig("upload.key", "");
//        if (listStaffInfo.getRows() > 0) {
//            for (int i = 0; i < listStaffInfo.getRows(); i++) {
//                FieldSetEntity staff = listStaffInfo.getFieldSetEntity(i);
//                if (!StringUtils.isEmpty(staff.getString(CmnConst.STAFF_AVATAR))) {
//                    FieldSetEntity staff_avatar=baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ATTACHMENTS, "uuid=?", new String[]{staff.getString(CmnConst.STAFF_AVATAR)}, false);
//                    Map<Object,Object> avatar = new HashMap<Object,Object>();
//                    avatar.put("path", staff_avatar.getString("attachment_domain") + "/"
//                            + staff_avatar.getString("attachment_container") + "/"
//                            + staff_avatar.getString("module_uuid") + "/"
//                            + staff_avatar.getString(CmnConst.ATTACHMENT_TITLE) + sostoken);
//                    avatar.put("name", staff_avatar.getString(CmnConst.ATTACHMENT_TITLE));
//                    avatar.put("size", staff_avatar.getString("attachment_size"));
//                    avatar.put("uuid", staff_avatar.getString("uuid"));
//                    avatar.put(CmnConst.FIEL_NAME, staff_avatar.getString(CmnConst.FIEL_NAME));
//                    staff.setValue(CmnConst.STAFF_AVATAR,avatar);
//                } else {
//                    Map<Object,Object> avatar = new HashMap<Object,Object>();
//                    avatar.put("path", "");
//                    avatar.put("name", "");
//                    avatar.put("size", "");
//                    avatar.put("uuid", "");
//                    avatar.put(CmnConst.FIEL_NAME, "");
//                    staff.setValue(CmnConst.STAFF_AVATAR,avatar);
//                }
//            }
//        }
//
//        return listStaffInfo;
    }
 
    /**
     * 根据staff_uuid获取员工上司和角色
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity findStaffBossAndRole(FieldSetEntity fse) throws BaseException {
 
        String filter = fse.getString(CmnConst.FILTER);
 
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.uuid uuid, ");
        sql.append(" b.uuid uuid1, ");
        sql.append(" c.uuid uuid2, ");
        sql.append(" d.uuid uuid3, ");
        sql.append(" e.uuid uuid4, ");
        sql.append(" f.uuid uuid5, ");
        sql.append(" a.user_id, ");
        sql.append(" a.show_name, ");
        sql.append(" a.staff_code, ");
        sql.append(" a.client_uuid, ");
        sql.append(" a.org_level_uuid, ");
        sql.append(" a.dept_uuid, ");
        sql.append(" a.job_post_uuid, ");
        sql.append(" a.job_post_grade_uuid, ");
 
        if (!StringUtils.isEmpty(filter) && (filter.indexOf("-update") > -1 || filter.indexOf("add") > -1)) { // 杜洪波
            // updateTime
            // 2020-12-17
            // 09:48:00
            sql.append(" a.role_uuids, ");
            sql.append(" a.direct_leader_code, ");
            sql.append(" a.cost_center_uuid, ");
        }
 
        sql.append(" c.STATUS ");
 
        sql.append(" FROM ");
        sql.append(" product_sys_staffs AS a ");
        sql.append(" LEFT JOIN product_sys_org_levels b ON a.org_level_uuid = b.uuid ");
        sql.append(" LEFT JOIN product_sys_users c ON a.user_id = c.user_id ");
        sql.append(" LEFT JOIN product_sys_job_posts d ON a.job_post_uuid = d.uuid ");
        sql.append(" LEFT JOIN product_sys_job_post_grades e ON a.job_post_grade_uuid = e.uuid ");
        sql.append(" LEFT JOIN product_sys_clients f ON a.client_uuid = f.uuid ");
 
        String org_level_uuid = fse.getString(CmnConst.ORG_LEVEL_UUID);
 
        sql.append(" WHERE (a.org_level_uuid ='" + org_level_uuid + "' or '" + org_level_uuid
                + "'=(SELECT uuid FROM product_sys_org_levels WHERE uuid='00000000-0000-0000-0000-000000000000'))");
 
        if (!StringUtils.isEmpty(filter)) { // 杜洪波 updateTime 2020-12-17 09:48:00
            sql.append(sqlFilter(filter));
        }
 
        DataTableEntity listStaffInfo = baseDao.listTable(sql.toString(), new String[]{});
        if (listStaffInfo != null && listStaffInfo.getRows() > 0) {
            baseDao.listInternationDataTable(listStaffInfo, null);
            baseDao.loadPromptData(listStaffInfo);
        }
        return listStaffInfo;
    }
 
    public FieldSetEntity findStaffDataByUUID(String staff_uuid) throws BaseException {
        return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, staff_uuid, false);
    }
 
    /**
     * 通用查询过滤条件
     *
     * @param filter
     * @return
     */
    public String sqlFilter(String filter) {
 
        // 杜洪波 2020年12月15日 16:52:09
        if ("StaffDimission-add".equals(filter)) {
            filter = " and a.staff_status in (0,1,2,3) and a.uuid not in (select apply_staff_uuid FROM product_sys_staff_termination where (result_status=1 or result_status=0))";
        } else if ("StaffChange-add".equals(filter)) {
            filter = " and a.staff_status in (0,1,2,3) and a.uuid not in (select staff_uuid FROM product_sys_staff_movement where (result_status=0 or result_status=1))";
        } else if (filter.contains("StaffDimission-update") || filter.contains("StaffChange-update")) {
            filter = " and a.uuid = '" + filter.substring(filter.lastIndexOf("&") + 1, filter.length()) + "'";
        } else if ("SelectPersonnel-TheDeparture".equals(filter)) {
            filter = " and a.staff_status in (0,1,2,3,4,5)";
        } else {
            filter = "";
        }
        return filter;
    }
 
    /**
     * 员工头像修改
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean uploadStaffavatar(FieldSetEntity fse) throws BaseException {
 
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        if (currentUser != null) {
            int user_id = currentUser.getUser_id();
 
            baseDao.executeUpdate("UPDATE product_sys_users SET thumbnail_img=? WHERE user_id=?", new Object[]{fse.getString(CmnConst.THUMBNSIL_IMG), user_id});
 
            FieldSetEntity fseStaff = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "user_id=?", new Object[]{user_id}, false);
            if (fseStaff != null) {
                baseDao.executeUpdate("UPDATE product_sys_staffs SET staff_avatar=? WHERE user_id=?", new Object[]{fse.getString(CmnConst.THUMBNSIL_IMG), user_id});
            }
        } else {
            throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), this.getClass(), "uploadStaffavatar");
        }
 
        if (!StringUtils.isEmpty(fse.getString("del"))) {
            String[] dels = fse.getString("del").split(",");
            if (dels.length > 0) {
                for (int i = 0; i < dels.length; i++) {
                    baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new Object[]{dels[i]});
                }
            }
        }
        return true;
    }
 
    /**
     * 获取公司所有部门+所有人员+搜索
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public List<Map<Object, Object>> listCompanyStaffs(FieldSetEntity fse, Object client_type, Object language_code)
            throws BaseException {
        // 查询所有指定组织机构下的组织机构
        DataTableEntity coms = baseDao.listTable(
                "select * FROM product_sys_org_levels  where org_level_code like CONCAT((select org_level_code FROM product_sys_org_levels where uuid=?),'%') order by org_level_code",
                new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)});
        if (coms == null || coms.getRows() == 0) {
            return new ArrayList<Map<Object, Object>>();
        }
        // 国际化
        baseDao.listInternationDataTable(coms,
                CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
        // 查询所有指定组织机构下的所有人员
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.uuid, ");
        sql.append(" user_id staff_id, ");
        sql.append(" tricode, ");
        sql.append(" preferred_name, ");
        sql.append(
                " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) ");
        sql.append(" staff_avatar, ");
        sql.append(" a.client_uuid, ");
        sql.append(" a.org_level_uuid, ");
        sql.append(" a.dept_uuid, ");
        sql.append(" a.staff_code, ");
        sql.append(" job_post_uuid, ");
        sql.append(" staff_status, ");
        sql.append(" job_post_name, ");
        sql.append(" b.uuid uuid1 ");
        sql.append(" FROM ");
        sql.append(" product_sys_staffs a ");
        sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid ");
        sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid ");
        sql.append(" WHERE ");
        sql.append(" staff_status <= 5 ");
        sql.append(
                " AND tricode LIKE CONCAT( ( SELECT org_level_code FROM product_sys_org_levels WHERE uuid = ? ), '%' ) ");
        DataTableEntity staffs = baseDao.listTable(sql.toString(),
                new Object[]{Global.getSystemConfig("upload.key", ""), fse.getString(CmnConst.ORG_LEVEL_UUID)});
        if (staffs != null && staffs.getRows() > 0) {
            staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1");
            // 国际化
            baseDao.listInternationDataTable(staffs,
                    CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
        }
        return convertOrgStaffInternation(coms, staffs);
    }
 
    /**
     * 获取当前人的可代理人
     *
     * @param fse
     * @param userUuid      指定用户
     * @param functionUuid  指定功能
     * @param client_type   客户端类型
     * @param language_code 语言编码
     * @return
     * @throws BaseException
     */
    public List<Map<Object, Object>> listAgentStaffs(FieldSetEntity fse, String staffUuid, String functionUuid, Object client_type, Object language_code)
            throws BaseException {
        // 查询所有指定组织机构下的所有人员
        StringBuilder sql = new StringBuilder();
        DataTableEntity staffs = new DataTableEntity();
        if (!StringUtils.isEmpty(staffUuid)) {
            if (CmnConst.STAFF_TYPE_PRINCIPAL.equals(fse.getString(CmnConst.STAFF_TYPE))) //被代理人员
            {
                sql.append(" SELECT distinct a.on_behalf_staff_uuid FROM product_sys_apply_on_behalf a left join product_sys_apply_on_behalf_details b on a.uuid=b.apply_on_behalf_uuid where  concat(',',b.on_behalf_staff_uuid,',') like ? and now() BETWEEN a.effective_utc_start_date and a.effective_utc_end_date");
                staffUuid = "%," + staffUuid + ",%";
            } else {
                //代理人员
                sql.append(" SELECT distinct b.on_behalf_staff_uuid FROM product_sys_apply_on_behalf a left join product_sys_apply_on_behalf_details b on a.uuid=b.apply_on_behalf_uuid where  a.on_behalf_staff_uuid=? and now() BETWEEN a.effective_utc_start_date and a.effective_utc_end_date");
            }
            Object ps[] = new Object[]{staffUuid};
            if (!StringUtils.isEmpty(functionUuid)) {
                Object vs[] = BaseUtil.buildQuestionMarkFilter(" function_uuid ", " in ", functionUuid);
                if (vs != null && vs.length > 1 && vs[1] != null) {
                    String filter = vs[0].toString();
                    List<String> paras = (List<String>) vs[1];
                    if (!StringUtils.isEmpty(filter) && paras.size() > 0) {
                        sql.append(" and ").append(filter);
                        paras.add(0, staffUuid);
                        ps = paras.toArray();
                    }
                }
            }
            staffs = baseDao.listTable(sql.toString(), ps);
            StringBuilder v = new StringBuilder();
            for (int i = 0; i < staffs.getRows(); i++) {
                if (v.length() > 0) {
                    v.append(",");
                }
                v.append(staffs.getString(i, "on_behalf_staff_uuid"));
            }
            Object vs[] = BaseUtil.buildQuestionMarkFilter(" a.uuid ", " in ", v.toString());
            if (vs != null && vs.length > 1 && vs[1] != null) {
                String filter = vs[0].toString();
                List<String> paras = (List<String>) vs[1];
                if (!StringUtils.isEmpty(filter) && paras.size() > 0) {
                    // 查询所有指定组织机构下的所有人员
                    sql = new StringBuilder();
                    sql.append(" SELECT ");
                    sql.append(" a.uuid, ");
                    sql.append(" user_id staff_id, ");
                    sql.append(" tricode, ");
                    sql.append(" preferred_name, ");
                    sql.append(
                            " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) ");
                    sql.append(" staff_avatar, ");
                    sql.append(" a.client_uuid, ");
                    sql.append(" a.org_level_uuid, ");
                    sql.append(" a.staff_code, ");
                    sql.append(" a.dept_uuid, ");
                    sql.append(" job_post_uuid, ");
                    sql.append(" staff_status, ");
                    sql.append(" job_post_name, ");
                    sql.append(" b.uuid uuid1 ");
                    sql.append(" FROM ");
                    sql.append(" product_sys_staffs a ");
                    sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid ");
                    sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid ");
                    sql.append(" WHERE ");
                    sql.append(" staff_status <= 5 ");
                    sql.append(" and ").append(filter);
                    paras.add(0, Global.getSystemConfig("upload.key", ""));
                    staffs = baseDao.listTable(sql.toString(), paras.toArray());
                }
            }
        }
        Map<String, String> org_level_uuids = new HashMap<>();
        List<String> uuids = new ArrayList<>();
        StringBuilder b = new StringBuilder();
        if (staffs != null && staffs.getRows() > 0) {
            staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1");
            // 国际化
            baseDao.listInternationDataTable(staffs,
                    CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
            b.append(" uuid in (");
            for (int i = 0; i < staffs.getRows(); i++) {
                if (org_level_uuids.get(staffs.getString(i, "dept_uuid")) == null) {
                    org_level_uuids.put(staffs.getString(i, "dept_uuid"), staffs.getString(i, "dept_uuid"));
                    if (uuids.size() > 0) {
                        b.append(",");
                    }
                    b.append("?");
                    uuids.add(staffs.getString(i, "dept_uuid"));
                }
            }
            b.append(")");
        }
        DataTableEntity coms = null;
        if (!uuids.isEmpty()) {
            // 查询所有指定组织机构下的组织机构
            coms = baseDao.listTable("product_sys_org_levels", b.toString(), uuids.toArray());
            // 国际化
            baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
        }
        if (coms == null || coms.getRows() == 0) {
            return new ArrayList<>();
        } else {
            Map<String, String> code = new HashMap<>();
            for (int i = 0; i < coms.getRows(); i++) {
                getParentCode(coms.getString(i, "org_level_code"), code);
            }
            b.delete(0, b.length());
            for (Object key : code.keySet()) {
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append("?");
            }
            b.insert(0, " org_level_code in (");
            b.append(")");
            coms = baseDao.listTable("product_sys_org_levels", b.toString(), code.keySet().toArray());
        }
        return convertOrgStaffInternation(coms, staffs);
    }
 
    /**
     * 获取当前人的直接下属
     *
     * @param fse
     * @param userUuid      指定用户
     * @param functionUuid  指定功能
     * @param client_type   客户端类型
     * @param language_code 语言编码
     * @return
     * @throws BaseException
     */
    public List<Map<Object, Object>> listDirectSubordinateStaffs(String staffUuid, Object client_type, Object language_code)
            throws BaseException {
        // 查询所有指定组织机构下的所有人员
        StringBuilder sql = new StringBuilder();
        DataTableEntity staffs = new DataTableEntity();
        if (!StringUtils.isEmpty(staffUuid)) {
            // 查询所有指定组织机构下的所有人员
            sql = new StringBuilder();
            sql.append(" SELECT ");
            sql.append(" a.uuid, ");
            sql.append(" user_id staff_id, ");
            sql.append(" tricode, ");
            sql.append(" preferred_name, ");
            sql.append(
                    " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) ");
            sql.append(" staff_avatar, ");
            sql.append(" a.client_uuid, ");
            sql.append(" a.org_level_uuid, ");
            sql.append(" a.dept_uuid, ");
            sql.append(" a.staff_code, ");
            sql.append(" job_post_uuid, ");
            sql.append(" staff_status, ");
            sql.append(" job_post_name, ");
            sql.append(" b.uuid uuid1 ");
            sql.append(" FROM ");
            sql.append(" product_sys_staffs a ");
            sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid ");
            sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid ");
            sql.append(" WHERE ");
            sql.append(" staff_status <= 5 ");
            sql.append(" and a.direct_leader_code=(select tricode FROM product_sys_staffs where uuid=? ) and a.direct_leader_code is not null ");
            staffs = baseDao.listTable(sql.toString(), new Object[]{Global.getSystemConfig("upload.key", ""), staffUuid});
        }
        Map<String, String> org_level_uuids = new HashMap<>();
        List<String> uuids = new ArrayList<>();
        StringBuilder b = new StringBuilder();
        if (staffs != null && staffs.getRows() > 0) {
            staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1");
            // 国际化
            baseDao.listInternationDataTable(staffs,
                    CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
            b.append(" uuid in (");
            for (int i = 0; i < staffs.getRows(); i++) {
                if (org_level_uuids.get(staffs.getString(i, "org_level_uuid")) == null) {
                    org_level_uuids.put(staffs.getString(i, "org_level_uuid"), staffs.getString(i, "org_level_uuid"));
                    if (uuids.size() > 0) {
                        b.append(",");
                    }
                    b.append("?");
                    uuids.add(staffs.getString(i, "org_level_uuid"));
                }
                if (org_level_uuids.get(staffs.getString(i, "dept_uuid")) == null) {
                    org_level_uuids.put(staffs.getString(i, "dept_uuid"), staffs.getString(i, "dept_uuid"));
                    if (uuids.size() > 0) {
                        b.append(",");
                    }
                    b.append("?");
                    uuids.add(staffs.getString(i, "dept_uuid"));
                }
            }
            b.append(")");
        }
        DataTableEntity coms = null;
        if (!uuids.isEmpty()) {
            // 查询所有指定组织机构下的组织机构
            coms = baseDao.listTable("product_sys_org_levels", b.toString(), uuids.toArray());
            // 国际化
            baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
        }
        if (coms == null || coms.getRows() == 0) {
            return new ArrayList<>();
        } else {
            Map<String, String> code = new HashMap<>();
            for (int i = 0; i < coms.getRows(); i++) {
                getParentCode(coms.getString(i, "org_level_code"), code);
            }
            b.delete(0, b.length());
            for (Object key : code.keySet()) {
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append("?");
            }
            b.insert(0, " org_level_code in (");
            b.append(")");
            coms = baseDao.listTable("product_sys_org_levels", b.toString(), code.keySet().toArray());
        }
        return convertOrgStaffInternation(coms, staffs);
    }
 
    /**
     * 获取当前人的所有下属
     *
     * @param fse
     * @param userUuid      指定用户
     * @param functionUuid  指定功能
     * @param client_type   客户端类型
     * @param language_code 语言编码
     * @return
     * @throws BaseException
     */
    public List<Map<Object, Object>> listAllSubordinateStaffs(String staffCode, Object client_type, Object language_code)
            throws BaseException {
        // 查询所有指定组织机构下的所有人员
        StringBuilder sql = new StringBuilder();
 
        DataTableEntity staffs = new DataTableEntity();
        if (!StringUtils.isEmpty(staffCode)) {
            sql.append("select tricode uuid FROM product_sys_staffs where leader_tricode like '");
            sql.append(staffCode);
            sql.append("%'");
            sql.append(" AND leader_tricode !=?");
            DataTableEntity c = baseDao.listTable(sql.toString(), new String[]{staffCode});
            String b = staffCode;
            Object[] uuid = c.getUuids();
            if (c != null && c.getRows() > 0 && uuid != null) {
                b = org.apache.commons.lang3.StringUtils.join(uuid, ",");
            }
            Object vs[] = BaseUtil.buildQuestionMarkFilter(" a.tricode ", " in ", b);
            if (vs != null && vs.length > 1 && vs[1] != null) {
                String filter = vs[0].toString();
                List<String> paras = (List<String>) vs[1];
 
                // 查询所有指定组织机构下的所有人员
                sql = new StringBuilder();
                sql.append(" SELECT ");
                sql.append(" a.uuid, ");
                sql.append(" user_id staff_id, ");
                sql.append(" tricode, ");
                sql.append(" preferred_name, ");
                sql.append(
                        " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) ");
                sql.append(" staff_avatar, ");
                sql.append(" a.client_uuid, ");
                sql.append(" a.org_level_uuid, ");
                sql.append(" a.dept_uuid, ");
                sql.append(" job_post_uuid, ");
                sql.append(" a.staff_code, ");
                sql.append(" staff_status, ");
                sql.append(" job_post_name, ");
                sql.append(" b.uuid uuid1 ");
                sql.append(" FROM ");
                sql.append(" product_sys_staffs a ");
                sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid ");
                sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid ");
                sql.append(" WHERE ");
                sql.append(" staff_status <= 5 ");
                sql.append(" and a.tricode <>? ");
                sql.append(" and ").append(filter);
                paras.add(0, staffCode);
                paras.add(0, Global.getSystemConfig("upload.key", ""));
                staffs = baseDao.listTable(sql.toString(), paras.toArray());
            }
        }
        Map<String, String> org_level_uuids = new HashMap<>();
        List<String> uuids = new ArrayList<>();
        StringBuilder b = new StringBuilder();
        if (staffs != null && staffs.getRows() > 0) {
            staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1");
            // 国际化
            baseDao.listInternationDataTable(staffs,
                    CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
            b.append(" uuid in (");
            for (int i = 0; i < staffs.getRows(); i++) {
                if (org_level_uuids.get(staffs.getString(i, "org_level_uuid")) == null) {
                    org_level_uuids.put(staffs.getString(i, "org_level_uuid"), staffs.getString(i, "org_level_uuid"));
                    if (uuids.size() > 0) {
                        b.append(",");
                    }
                    b.append("?");
                    uuids.add(staffs.getString(i, "org_level_uuid"));
                }
                if (org_level_uuids.get(staffs.getString(i, "dept_uuid")) == null) {
                    org_level_uuids.put(staffs.getString(i, "dept_uuid"), staffs.getString(i, "dept_uuid"));
                    if (uuids.size() > 0) {
                        b.append(",");
                    }
                    b.append("?");
                    uuids.add(staffs.getString(i, "dept_uuid"));
                }
            }
            b.append(")");
        }
        DataTableEntity coms = null;
        if (!uuids.isEmpty()) {
            // 查询所有指定组织机构下的组织机构
            coms = baseDao.listTable("product_sys_org_levels", b.toString(), uuids.toArray());
            // 国际化
            baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString());
        }
        if (coms == null || coms.getRows() == 0) {
            return new ArrayList<>();
        } else {
            Map<String, String> code = new HashMap<>();
            for (int i = 0; i < coms.getRows(); i++) {
                getParentCode(coms.getString(i, "org_level_code"), code);
            }
            b.delete(0, b.length());
            for (Object key : code.keySet()) {
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append("?");
            }
            b.insert(0, " org_level_code in (");
            b.append(")");
            coms = baseDao.listTable("product_sys_org_levels", b.toString(), code.keySet().toArray());
        }
        return convertOrgStaffInternation(coms, staffs);
    }
 
    /**
     * 菜单国际化转换
     *
     * @param orgs   组织机构
     * @param staffs 人员
     * @return
     */
    private List<Map<Object, Object>> convertOrgStaffInternation(DataTableEntity orgs, DataTableEntity staffs)
            throws BaseException {
        List<Map<Object, Object>> org_staff = new ArrayList<>();
        // 封装上下级菜单
        Map<Object, Map<Object, Object>> parent_org = new HashMap<>();
        // 封装部门
        Map<Object, Map<Object, Object>> parent_dept = new HashMap<>();
        if (orgs != null && orgs.getRows() > 0) {
            for (int j = 0; j < orgs.getRows(); j++) {
                FieldSetEntity org = orgs.getFieldSetEntity(j);
                Map<Object, Object> o = JsonUtil.parseJsonFieldSetToMap(org);
                String pcode = org.getString("org_level_code_parent");
                if (StringUtils.isEmpty(pcode) || parent_org.get(pcode) == null) {
                    org_staff.add(o);
                } else {// 上级菜单
                    Map<Object, Object> pm = parent_org.get(pcode);
                    Object subs = pm.get("son_org");
                    List<Map<Object, Object>> submenus = null;
                    if (subs == null) {
                        submenus = new ArrayList<>();
                        pm.put("son_org", submenus);
                    } else {
                        submenus = (List<Map<Object, Object>>) subs;
                    }
                    submenus.add(o);
                }
                parent_org.put(org.getString("org_level_code"), o);
                if (org.getInteger("org_level_type") == 1) {
                    parent_dept.put(org.getString("uuid"), o);
                }
            }
        }
        if (staffs != null && staffs.getRows() > 0) {
            for (int j = 0; j < staffs.getRows(); j++) {
                FieldSetEntity staff = staffs.getFieldSetEntity(j);
                Map<Object, Object> o = JsonUtil.parseJsonFieldSetToMap(staff);
                String dept_uuid = staff.getString("dept_uuid");
                if (parent_dept.get(dept_uuid) != null) {
                    // 部门
                    Map<Object, Object> pm = parent_dept.get(dept_uuid);
                    Object subs = pm.get("staff");
                    List<Map<Object, Object>> submenus = null;
                    if (subs == null) {
                        submenus = new ArrayList<>();
                        pm.put("staff", submenus);
                    } else {
                        submenus = (List<Map<Object, Object>>) subs;
                    }
                    submenus.add(o);
                }
            }
        }
        return org_staff;
    }
 
    /**
     * 员工信息详情(移动端)
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findStaffInfoByMobile() throws BaseException {
 
        String uuid = null;
 
        FieldSetEntity fseCurrentStaff = SpringMVCContextHolder.getCurrentUser().getCurrentStaff();
        if (fseCurrentStaff != null) {
            uuid = fseCurrentStaff.getUUID();
        } else {
            throw new BaseException(SystemCode.SYSTEM_STAFF_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_STAFF_INFO_NO_EXIST.getText(), this.getClass(), "findStaffInfoByMobile");
        }
 
 
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.child_name,a.christian_name,a.client_uuid,a.cost_center_uuid,a.created_by,a.created_utc_datetime,a.dept_uuid,a.direct_leader_code, ");
        sql.append(" a.entry_datetime,a.family_name,a.given_name,a.is_dept_manage,a.is_org_admin,a.is_org_manager,a.job_post_grade_uuid,a.job_post_uuid, ");
        sql.append(" a.org_level_uuid,a.preferred_name,a.probation_end,a.role_uuids,a.show_name,a.staff_code,a.staff_email,a.staff_id,a.staff_image, ");
        sql.append(" a.staff_status,a.tricode,a.updated_by,a.updated_utc_datetime,a.user_id,a.uuid, ");
        sql.append(" b.status, ");
        sql.append(" c.attachment_url,concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) staff_avatar  ");
        sql.append(" FROM product_sys_staffs a ");
        sql.append(" LEFT JOIN product_sys_users b ON a.user_id=b.user_id  ");
        sql.append(" LEFT JOIN product_sys_attachments c ON a.staff_avatar=c.uuid where a.uuid=? ");
 
        String sostoken = Global.getSystemConfig("upload.key", "");
        FieldSetEntity fseStaff = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{sostoken, uuid}, false);
        baseDao.listInternationDataTable(fseStaff, null);
        return fseStaff;
    }
 
    private void getParentCode(String code, Map<String, String> newCode) {
        String cs[] = code.split("-");
        List<String> codes = new ArrayList<>();
        codes.add(cs[0]);
        newCode.put(cs[0], cs[0]);
        for (int i = 1; i < cs.length; i++) {
            codes.add(codes.get(i - 1) + "-" + cs[i]);
            newCode.put(codes.get(i - 1) + "-" + cs[i], codes.get(i - 1) + "-" + cs[i]);
        }
    }
 
    /**
     * 初始化员工leader_tricode数据
     *
     * @return
     * @throws Ez
     */
    public void initStaffLeaderTricode() throws Exception {
        System.out.println(new Date());
        //获取所有无上级领导员工
        DataTableEntity dtStaffInfo = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, "direct_leader_code is null or direct_leader_code =''");
        if (!BaseUtil.dataTableIsEmpty(dtStaffInfo)) {
            String virtualCode = "000";
            for (int i = 0; i < dtStaffInfo.getRows(); i++) {
                FieldSetEntity fseStaffInfo = dtStaffInfo.getFieldSetEntity(i);
                fseStaffInfo.remove("show_name");
                fseStaffInfo.remove("family_name");
                fseStaffInfo.remove("given_name");
                fseStaffInfo.remove("christian_name");
                fseStaffInfo.remove("child_name");
                fseStaffInfo.remove("preferred_name");
 
                String leader_tricode = "";
                if (i == 0) {
                    leader_tricode = virtualCode;
                } else {
                    leader_tricode = SingletonUtil.makeSameLevelCode(virtualCode);
                    virtualCode = leader_tricode;
                }
 
                fseStaffInfo.setValue(CmnConst.LEADER_TRICODE, leader_tricode);
                //Fri Apr 16 03:55:34 UTC 2021
//                baseDao.update(fseStaffInfo);
//                DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE);
//                Thread.currentThread().sleep(4000);
                createStaffLeaderTricode(fseStaffInfo.getString(CmnConst.TRICODE), leader_tricode);
            }
            baseDao.update(dtStaffInfo);
            DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE);
        }
        System.out.println(new Date());
    }
 
    /**
     * 自动创建下级员工leader_tricode数据
     *
     * @param tricode
     * @param leader_tricode
     */
    public void createStaffLeaderTricode(String tricode, String leader_tricode) {
        DataTableEntity dtSubStaffInfo = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, "direct_leader_code=?", new Object[]{tricode});
        if (!BaseUtil.dataTableIsEmpty(dtSubStaffInfo)) {
            String virtualCode = leader_tricode + "-000";
            for (int i = 0; i < dtSubStaffInfo.getRows(); i++) {
                FieldSetEntity fseSubStaffInfo = dtSubStaffInfo.getFieldSetEntity(i);
                fseSubStaffInfo.remove("show_name");
                fseSubStaffInfo.remove("family_name");
                fseSubStaffInfo.remove("given_name");
                fseSubStaffInfo.remove("christian_name");
                fseSubStaffInfo.remove("child_name");
                fseSubStaffInfo.remove("preferred_name");
 
                String sub_leader_tricode = "";
                if (i == 0) {
                    sub_leader_tricode = virtualCode;
                } else {
                    sub_leader_tricode = SingletonUtil.makeSameLevelCode(virtualCode);
                    virtualCode = sub_leader_tricode;
                }
 
                fseSubStaffInfo.setValue(CmnConst.LEADER_TRICODE, sub_leader_tricode);
//                baseDao.update(fseSubStaffInfo);
                createStaffLeaderTricode(fseSubStaffInfo.getString(CmnConst.TRICODE), sub_leader_tricode);
            }
            baseDao.update(dtSubStaffInfo);
        }
    }
}