yubo
2026-03-11 499460f9d26d5d08538de24680ab4c63735007f2
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
package cc.mrbird.febs.server.hr.service.impl;
 
import cc.mrbird.febs.common.core.constant.DicCode;
import cc.mrbird.febs.common.core.constant.ModuleCode;
import cc.mrbird.febs.common.core.entity.QueryRequest;
import cc.mrbird.febs.common.core.entity.constant.FebsConstant;
import cc.mrbird.febs.common.core.entity.constant.StringConstant;
import cc.mrbird.febs.common.core.entity.system.Dept;
import cc.mrbird.febs.common.core.entity.system.DicItem;
import cc.mrbird.febs.common.core.entity.system.Position;
import cc.mrbird.febs.common.core.entity.system.SysConfig;
import cc.mrbird.febs.common.core.utils.*;
import cc.mrbird.febs.common.redis.service.RedisService;
import cc.mrbird.febs.server.hr.entity.*;
import cc.mrbird.febs.server.hr.feign.IRemoteDeptService;
import cc.mrbird.febs.server.hr.feign.IRemoteDicItemService;
import cc.mrbird.febs.server.hr.feign.IRemotePositionService;
import cc.mrbird.febs.server.hr.feign.IRemoteUserService;
import cc.mrbird.febs.server.hr.mapper.*;
import cc.mrbird.febs.server.hr.properties.FebsServerHrProperties;
import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService;
import cc.mrbird.febs.server.hr.service.IEmpDimissionLogService;
import cc.mrbird.febs.server.hr.service.IEmpJobChangeService;
import cc.mrbird.febs.server.hr.util.PoiExportExcel;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
 
/**
 * name:EmpBaseinfo
 * package:cc.mrbird.febs.server.hr.controller
 * description:员工基本信息服务接口实现
 *
 * @author luoyibo
 * @date 2021-01-30 08:04:50
 * @since JDK1.8
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
class EmpBaseInfoServiceImpl extends ServiceImpl<EmpBaseInfoMapper, EmpBaseInfo> implements IEmpBaseInfoService {
    private final RedisService redisService;
    private final IRemoteUserService iRemoteUserService;
    private final EmpBaseInfoMapper empBaseInfoMapper;
    private final IEmpDimissionLogService dimissionLogService;
    private final IEmpJobChangeService jobChangeService;
    private final EmpContractInfoMapper empContractInfoMapper;
    private final FebsServerHrProperties properties;
    private final IRemoteDeptService remoteDeptService;
    private final EmpWorkExperienceMapper empWorkExperienceMapper;
    private final EmpPhysicalExamMapper empPhysicalExamMapper;
    private final EmpJobChangeMapper empJobChangeMapper;
    private final EmpLeaveInfoMapper empLeaveInfoMapper;
    private final EmpUnemploymentMapper empUnemploymentMapper;
    private final EmpDimissionAttendMapper empDimissionAttendMapper;
    private final EmpInsuranceMapper empInsuranceMapper;
    private final EmpAccidentCasesMapper empAccidentCasesMapper;
    private final EmpLaborTroubleMapper empLaborTroubleMapper;
    private final EmpBadRecordMapper empBadRecordMapper;
    private final EmpRemarkInfoMapper empRemarkInfoMapper;
    private final IRemoteDicItemService remoteDicItemService;
    private final EmpOccupationalMapper empOccupationalMapper;
    private final IRemotePositionService remotePositionService;
    private final EmpDimissionLogMapper empDimissionLogMapper;
    private final EmpOpenArchivesMapper empOpenArchivesMapper;
    private final EmpResignMapper empResignMapper;
 
    @Override
    public IPage<EmpBaseInfo> findEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
        return this.findZsEmpBaseInfos(request, empBaseInfo);
    }
 
    @Override
    public IPage<EmpBaseInfo> findZsEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "entryDate", FebsConstant.ORDER_ASC, true);
        IPage<EmpBaseInfo> iPage = empBaseInfoMapper.selectPageVo(page, createQueryWrapper(empBaseInfo));
        // 设置部门
        // List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
        List<EmpBaseInfo> list = iPage.getRecords();
        List<EmpBaseInfo> newList = new ArrayList<>();
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
        list.forEach(p -> {
            p.setSexName("1".equals(p.getSex()) ? "男" : "女");
            p.setArchivesStatusName("0".equals(p.getArchivesStatus()) ? "未移交" : "已移交");
            p.setEmpCardStatusName("0".equals(p.getEmpCardStatus()) ? "未发" : "已发");
            p.setHandbookStatusName("0".equals(p.getHandbookStatus()) ? "未发" : "已发");
            p.setEmpStatusName("0".equals(p.getEmpStatus()) ? "在职" : "离职");
            // 保险类型
            p.setInsuranceTypeName(dicItems.stream()
                    .filter(k -> DicCode.INSURANCETYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getInsuranceType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            // 员工类别
            p.setEmpTypeName(dicItems.stream()
                    .filter(k -> DicCode.EMPTYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEmpType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("正式工"));
            // 设置民族
            p.setNationName(dicItems.stream()
                    .filter(k -> DicCode.NATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("汉族"));
            // 设置政治面貌
            p.setPoliticsName(dicItems.stream()
                    .filter(k -> DicCode.PLITICAL.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getPolitics()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("群众"));
            // 设置婚姻状况
            p.setMarriageName(dicItems.stream()
                    .filter(k -> DicCode.MARRIAGE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getMarriage()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未婚"));
            // 设置学历
            p.setEducationName(dicItems.stream()
                    .filter(k -> DicCode.EDUCATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEducation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("无学历"));
            // 设置籍贯
            p.setNativePlaceName(dicItems.stream()
                    .filter(k -> DicCode.NATIVEPLACE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNativePlace()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            p.setEntryTypeName(dicItems.stream()
                    .filter(k -> DicCode.IN_OUT_TYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEntryType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse(""));
            p.setDimissionTypeName(dicItems.stream()
                    .filter(k -> DicCode.IN_OUT_TYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getDimissionType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse(""));
            p.setCertificateListName(getCertificateListName(p.getCertificateList(), dicItems));
        });
        // if (StringUtils.isNotBlank(empBaseInfo.getCertificateList())) {
        //     String[] certificates = empBaseInfo.getCertificateList().split(",");
        //     list.forEach(k -> {
        //         String[] dbCertificates = k.getCertificateList().split(",");
        //         for (String certificate : certificates) {
        //             if (Arrays.asList(dbCertificates).contains(certificate)) {
        //                 newList.add(k);
        //                 break;
        //             }
        //         }
        //     });
        //     iPage.setRecords(newList);
        // } else {
        //     iPage.setRecords(list);
        // }
        iPage.setRecords(list);
        return iPage;
    }
 
    @Override
    public List<EmpBaseInfo> findEmpBaseInfos(EmpBaseInfo empBaseInfo) {
        LambdaQueryWrapper<EmpBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EmpBaseInfo::getDelFlag, empBaseInfo.getDelFlag());
        return this.baseMapper.selectList(queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        EmpBaseInfo dbInfo = this.getEmpBaseInfo(empBaseInfo);
        Long empId = SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE);
        boolean saveDimissionLog = true;
        if (dbInfo == null) {
            empBaseInfo.setEmpId(empId);
            // saveDimissionLog = true;
        } else {
            empBaseInfo.setEmpId(dbInfo.getEmpId());
        }
        if (StrUtil.isNotBlank(empBaseInfo.getImagePath())) {
            String path = properties.getEmpBaseInfoPath() + empBaseInfo.getEmpId() + ".png";
            if (MyUtil.generateImage(empBaseInfo.getImagePath(), path)) {
                empBaseInfo.setImagePath(empBaseInfo.getEmpId() + ".png");
            }
            ;
        }
        empBaseInfo.setCreator(operatorId);
        empBaseInfo.setModifier(operatorId);
        this.saveOrUpdate(empBaseInfo);
 
        addEmpDimissLog(empBaseInfo, operatorId, empId);
    }
 
    /**
     * 增加员工后同步增加入职记录
     * <p>
     * date 2021-07-30 09:12
     *
     * @param empBaseInfo 员工信息
     * @param operatorId  操作员Id
     * @param empId       员工Id
     * @return void
     * @author: luoyibo
     */
    private void addEmpDimissLog(EmpBaseInfo empBaseInfo, String operatorId, Long empId) {
        EmpDimissionLog dimissionLog = new EmpDimissionLog();
        dimissionLog.setCloseId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
        dimissionLog.setEmpId(empId);
        dimissionLog.setEntryDate(empBaseInfo.getEntryDate());
        dimissionLog.setDimissionType("20");
        dimissionLog.setRemark(empBaseInfo.getRemark());
        dimissionLog.setDeptName(empBaseInfo.getAllDeptName());
        dimissionLog.setCreator(operatorId);
        dimissionLog.setModifier(operatorId);
 
        dimissionLogService.save(dimissionLog);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        if (StrUtil.isNotBlank(empBaseInfo.getImagePath()) && empBaseInfo.getImagePath().indexOf(",") > 0) {
            String path = properties.getEmpBaseInfoPath() + empBaseInfo.getEmpId() + ".png";
            if (MyUtil.generateImage(empBaseInfo.getImagePath(), path)) {
                empBaseInfo.setImagePath(empBaseInfo.getEmpId() + ".png");
            }
 
        }
        EmpBaseInfo dbData = this.getById(empBaseInfo.getEmpId());
        empBaseInfo.setCreateTime(dbData.getCreateTime());
        empBaseInfo.setCreator(dbData.getCreator());
        empBaseInfo.setDelFlag(dbData.getDelFlag());
        empBaseInfo.setModifyTime(new Date());
        empBaseInfo.setModifier(operatorId);
        if (StringUtils.isBlank(empBaseInfo.getImagePath())) {
            empBaseInfo.setImagePath(dbData.getImagePath());
        }
        if (StringUtils.isBlank(empBaseInfo.getAllDeptName())) {
            empBaseInfo.setAllDeptName(dbData.getAllDeptName());
        }
        this.saveOrUpdate(empBaseInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        LambdaQueryWrapper<EmpBaseInfo> wrapper = new LambdaQueryWrapper<>();
        // TODO 设置删除条件
        this.remove(wrapper);
    }
 
    /**
     * 根据Id批量逻辑删除记录
     * <p>
     * date 2021-01-28 10:48
     *
     * @param ids 待删除Id
     * @return void
     * @author: luoyibo
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void logicDelEmpBaseInfo(String ids) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        String[] str = ids.split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        empBaseInfoMapper.logicDeleteByIds(list, operatorId);
 
        // 同步删除关联数据
        // 不良记录
        empBadRecordMapper.logicDelByUserIds(list, operatorId);
        empAccidentCasesMapper.logicDelByUserIds(list, operatorId);
        empContractInfoMapper.logicDelByUserIds(list, operatorId);
        empDimissionAttendMapper.logicDelByUserIds(list, operatorId);
        empDimissionLogMapper.logicDelByUserIds(list, operatorId);
        empInsuranceMapper.logicDelByUserIds(list, operatorId);
        empJobChangeMapper.logicDelByUserIds(list, operatorId);
        empLaborTroubleMapper.logicDelByUserIds(list, operatorId);
        empLeaveInfoMapper.logicDelByUserIds(list, operatorId);
        empOccupationalMapper.logicDelByUserIds(list, operatorId);
        empOpenArchivesMapper.logicDelByUserIds(list, operatorId);
        empPhysicalExamMapper.logicDelByUserIds(list, operatorId);
        empRemarkInfoMapper.logicDelByUserIds(list, operatorId);
        empResignMapper.logicDelByUserIds(list, operatorId);
        empUnemploymentMapper.logicDelByUserIds(list, operatorId);
        empWorkExperienceMapper.logicDelByUserIds(list, operatorId);
    }
 
    /**
     * 设置员工部门名称
     * <p>
     * date 2021-02-02 21:43
     *
     * @param empBaseInfoList 人员信息列表
     * @return java.util.List<cc.mrbird.febs.server.hr.entity.EmpBaseInfo>
     * @author: luoyibo
     */
    private List<EmpBaseInfo> setDeptName(List<EmpBaseInfo> empBaseInfoList) {
        List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class);
        if (null == depts) {
            depts = remoteDeptService.setDeptRedis();
        }
        for (EmpBaseInfo empBaseInfo : empBaseInfoList) {
            // 设置部门
            empBaseInfo.setDeptName(depts.stream()
                    .filter(k -> k.getDeptId().equals(empBaseInfo.getDeptId()))
                    .findFirst()
                    .map(Dept::getDeptName)
                    .orElse(""));
            empBaseInfo.setAllDeptName(depts.stream()
                    .filter(k -> k.getDeptId().equals(empBaseInfo.getDeptId()))
                    .findFirst()
                    .map(Dept::getAllDeptName)
                    .orElse(""));
        }
        return empBaseInfoList;
    }
 
    @Override
    public boolean verifyEmpNumb(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb())
                .ne(EmpBaseInfo::getDelFlag, 1);
        if (empBaseInfo.getEmpId() != null) {
            queryWrapper.lambda().ne(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId());
        }
 
        return this.count(queryWrapper) > 0;
    }
 
    @Override
    public boolean momentToNormal(String ids) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        String[] str = ids.split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
//        for (int i = 0, j = str.length; i < j; i++) {
//            EmpBaseInfo emp = this.getById(str[i]);
//            addEmpDimissLog(emp, operatorId, Long.valueOf(str[i]));
//        }
        return empBaseInfoMapper.momentToNormal(list, operatorId) > 0;
    }
 
    @Override
    public EmpBaseInfo getEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(empBaseInfo.getCertificateNumb())) {
            queryWrapper.lambda().eq(EmpBaseInfo::getCertificateNumb, empBaseInfo.getCertificateNumb());
        }
        return this.getOne(queryWrapper);
    }
 
    /**
     * 关闭员工档案
     * <p>
     * date 2021-02-18 12:54
     *
     * @param empDimissionLog
     * @return boolean
     * @author: luoyibo
     */
    @Override
    public boolean closeEmpArchives(EmpDimissionLog empDimissionLog) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        String[] str = empDimissionLog.getEmpIds().split(",");
        String[] empDeptNames = empDimissionLog.getDeptNames().split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        String[] strDate = empDimissionLog.getEntryDates().split(",");
 
        EmpDimissionLog dimissionLog = null;
        for (int i = 0, k = str.length; i < k; i++) {
            dimissionLog = new EmpDimissionLog();
            dimissionLog.setCloseId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
            dimissionLog.setEmpId(Long.parseLong(str[i]));
            dimissionLog.setEntryDate(DateUtil.parse(strDate[i], "yyyy-MM-dd"));
            dimissionLog.setDimissionDate(empDimissionLog.getDimissionDate());
            dimissionLog.setDimissionType(empDimissionLog.getDimissionType());
            dimissionLog.setRemark(empDimissionLog.getRemark());
            dimissionLog.setSelfLeaveDay(empDimissionLog.getSelfLeaveDay());
            dimissionLog.setReporter(empDimissionLog.getReporter());
            dimissionLog.setCreator(operatorId);
            dimissionLog.setModifier(operatorId);
            dimissionLog.setDeptName(empDeptNames[i]);
            dimissionLogService.save(dimissionLog);
        }
 
        if (StrUtil.isNotBlank(empDimissionLog.getAfterOperation())) {
            String[] strAfterOperation = empDimissionLog.getAfterOperation().split(",");
            int flag = 0;
            for (String s : strAfterOperation) {
                flag = flag + Integer.parseInt(s);
            }
            switch (flag) {
                case 1:
                    // 解除合同
                    empContractInfoMapper.terminateContract(new ArrayList<>(Arrays.asList(empDimissionLog.getEmpIds().split(StringConstant.COMMA))), operatorId);
                    break;
                case 2:
                    // 禁用账户
                    iRemoteUserService.updateStatus(empDimissionLog.getCertificateNumb());
                    break;
                case 3:
                    empContractInfoMapper.terminateContract(new ArrayList<>(Arrays.asList(empDimissionLog.getEmpIds().split(StringConstant.COMMA))), operatorId);
                    iRemoteUserService.updateStatus(empDimissionLog.getCertificateNumb());
                    break;
            }
        }
        return empBaseInfoMapper.closeEmpArchives(list, empDimissionLog.getDimissionType(), empDimissionLog.getDimissionDate(), empDimissionLog.getRemark(), operatorId) > 0;
    }
 
    /**
     * 员工岗位变更
     * <p>
     * date 2021-02-18 20:32
     *
     * @param empJobChange 1
     * @return boolean
     * @author: luoyibo
     */
    @Override
    public boolean changeEmpJob(EmpJobChange empJobChange) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        String[] str = empJobChange.getEmpIds().split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        String[] strName = empJobChange.getEmpNames().split(",");
        String[] strDeptName = empJobChange.getOldDeptNames().split(",");
        String[] strJobName = empJobChange.getOldJobNames().split(",");
 
        EmpJobChange saveChange = null;
 
        for (int i = 0, k = str.length; i < k; i++) {
            saveChange = new EmpJobChange();
            saveChange.setJobChangeId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
            saveChange.setEmpId(Long.parseLong(str[i]));
            saveChange.setEmpName(strName[i]);
            saveChange.setOldDeptName(strDeptName[i]);
            saveChange.setOldJobName(strJobName[i]);
            saveChange.setNewDeptName(empJobChange.getNewDeptName());
            saveChange.setAllDeptName(empJobChange.getAllDeptName());
            saveChange.setNewJobName(empJobChange.getNewJobName());
            saveChange.setChangeType(empJobChange.getChangeType());
            saveChange.setChangeDate(empJobChange.getChangeDate());
            saveChange.setChangeReason(empJobChange.getChangeReason());
            saveChange.setCreator(operatorId);
            saveChange.setModifier(operatorId);
 
            jobChangeService.save(saveChange);
 
        }
 
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("deptId", empJobChange.getDeptId());
        mapParams.put("deptName", empJobChange.getNewDeptName());
        mapParams.put("allDeptName", empJobChange.getAllDeptName());
        mapParams.put("jobId", empJobChange.getJobId());
        mapParams.put("jobName", empJobChange.getNewJobName());
        mapParams.put("operatorId", operatorId);
        return empBaseInfoMapper.changeEmpJob(list, mapParams) > 0;
    }
 
    /**
     * 导入员工
     *
     * @param listObject
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importEmpBaseInfo(List<List<Object>> listObject, List<String> returnList, List<DicItem> dicItems) {
        for (List<Object> list : listObject) {
            if (list.size() == 0) {
                continue;
            }
            if (this.count(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb, list.get(1).toString()).ne(EmpBaseInfo::getDelFlag, 1)) > 0) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}员工编号重复", listObject.indexOf(list) + 1, list.get(1).toString()));
                continue;
            }
            if (this.count(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getCertificateNumb, list.get(1).toString()).ne(EmpBaseInfo::getDelFlag, 1)) > 0) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}身份证号重复", listObject.indexOf(list) + 1, list.get(1).toString()));
                continue;
            }
            EmpBaseInfo empBaseInfo = new EmpBaseInfo();
            empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
            empBaseInfo.setArchivesNumb(list.get(0).toString());
            empBaseInfo.setEmpNumb(list.get(1).toString());
 
            List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class);
            if (null == depts) {
                depts = remoteDeptService.setDeptRedis();
            }
            if (null == depts) {
                depts = remoteDeptService.setDeptRedis();
            }
            empBaseInfo.setDeptName(list.get(2).toString());
            Dept dept = depts.stream().filter(d -> d.getDeptName().equals(list.get(2).toString())).findFirst().orElse(null);
            if (null == dept) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}部门不存在", listObject.indexOf(list) + 1, list.get(2).toString()));
                continue;
            }
 
            empBaseInfo.setAllDeptName(dept.getAllDeptName());
 
            empBaseInfo.setDeptId(dept.getDeptId());
            List<Position> positionList = CastUtil.castList(redisService.get("position"), Position.class);
            if (null == positionList) {
                positionList = remotePositionService.setPositionRedis();
                if (null == positionList) {
                    returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}获取岗位为空,请设置岗位", listObject.indexOf(list) + 1, list.get(3).toString()));
                    continue;
                }
            }
            Position position = positionList.stream().filter(d -> d.getPositionName().equals(list.get(3).toString())).findFirst().orElse(null);
            if (null == position) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}获取岗位为空", listObject.indexOf(list) + 1, list.get(3).toString()));
                continue;
            }
            empBaseInfo.setJobId(position.getPositionId());
            empBaseInfo.setJobName(list.get(3).toString());
            empBaseInfo.setEmpName(list.get(4).toString());
            try {
                if (StrUtil.isNotBlank(list.get(5).toString())) {
                    empBaseInfo.setCertificateNumb(list.get(5).toString());
                    if (IdcardUtil.isValidCard(list.get(5).toString())) {
                        empBaseInfo.setAge(IdcardUtil.getAgeByIdCard(list.get(5).toString()));
                        empBaseInfo.setBirthdate(IdcardUtil.getBirthDate(list.get(5).toString()));
                    }
                }
 
            } catch (Exception e) {
                log.error("导入人员身份证异常:{}", e);
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}检查身份证是否正确", listObject.indexOf(list) + 1, list.get(5).toString()));
                continue;
            }
 
 
            empBaseInfo.setSex("男".equals(list.get(6).toString()) ? "1" : "2");
 
            // 民族
            DicItem dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "nation") && StrUtil.equals(j.getDicItemName(), list.get(7).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setNation(dicItem.getDicItemCode());
            }
 
            // 婚姻状况
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "marriage") && StrUtil.equals(j.getDicItemName(), list.get(8).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setMarriage(dicItem.getDicItemCode());
            }
 
            if (StringUtils.isNotBlank(list.get(9).toString())) {
                empBaseInfo.setStature(Integer.valueOf(list.get(9).toString()));
            }
            // 政治面貌
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "plitical") && StrUtil.equals(j.getDicItemName(), list.get(10).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setPolitics(dicItem.getDicItemCode());
            }
 
            if (StringUtils.isNotBlank(list.get(11).toString())) {
                empBaseInfo.setEntryDate(DateUtil.parse(list.get(11).toString()));
            }
 
            // 最高学历
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "education") && StrUtil.equals(j.getDicItemName(), list.get(12).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEducation(dicItem.getDicItemCode());
            }
 
            if (StringUtils.isNotBlank(list.get(13).toString())) {
                empBaseInfo.setSeniority(list.get(13).toString());
            }
 
            // 籍贯
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "nativePlace") && StrUtil.equals(j.getDicItemName(), list.get(14).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setNativePlace(dicItem.getDicItemCode());
            }
 
            empBaseInfo.setCensusAddress(list.get(15).toString());
            empBaseInfo.setCurrentAddress(list.get(16).toString());
            // 员工类型
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "empType") && StrUtil.equals(j.getDicItemName(), list.get(17).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEmpType(dicItem.getDicItemCode());
            }
 
            empBaseInfo.setGuardNumb(list.get(18).toString());
            empBaseInfo.setReturnReceipt(list.get(19).toString());
            empBaseInfo.setTelePhone(list.get(20).toString());
            empBaseInfo.setIntroducer(list.get(21).toString());
            empBaseInfo.setBankName(list.get(22).toString());
            empBaseInfo.setBankNumb(list.get(23).toString());
            // 保险类型
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "insuranceType") && StrUtil.equals(j.getDicItemName(), list.get(24).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setInsuranceType(dicItem.getDicItemCode());
            }
 
            empBaseInfo.setSocialNumb(list.get(25).toString());
            empBaseInfo.setFamily(list.get(26).toString());
            empBaseInfo.setUrgencyPhone(list.get(27).toString());
            // 员工手册
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "handbookStatus") && StrUtil.equals(j.getDicItemName(), list.get(28).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setHandbookStatus(dicItem.getDicItemCode());
            }
 
            // 工作证
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "empCardStatus") && StrUtil.equals(j.getDicItemName(), list.get(29).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEmpCardStatus(dicItem.getDicItemCode());
            }
 
            // 相关证件
            List<DicItem> dicItemList = new ArrayList<>();
            String[] certificateList = list.get(30).toString().split(StringConstant.COMMA);
            if (null != certificateList) {
                for (String s : certificateList) {
                    dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "certificateList") && StrUtil.equals(j.getDicItemName(), s)).findFirst().orElse(null);
                    if (null != dicItem) {
                        dicItemList.add(dicItem);
                    }
                }
            }
 
            if (CollUtil.isNotEmpty(dicItemList)) {
                empBaseInfo.setCertificateList(dicItemList.stream().map(i -> i.getDicItemCode()).collect(Collectors.joining(StringConstant.COMMA)));
            }
 
 
            empBaseInfo.setDelFlag(2);
            // 入职类型
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "lztype") && StrUtil.equals(j.getDicItemName(), list.get(31).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEntryType(dicItem.getDicItemCode());
            }
            // 档案情况
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "archivesStatus") && StrUtil.equals(j.getDicItemName(), list.get(32).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setArchivesStatus(dicItem.getDicItemCode());
            }
            empBaseInfo.setEmpStatus("0");
            boolean saveResult = this.save(empBaseInfo);
            // 新入职员工需要增加一条入职记录
            this.addEmpDimissLog(empBaseInfo, "2", empBaseInfo.getEmpId());
        }
    }
 
    //    @Override
    public void getImage(String empId, HttpServletResponse response) throws Exception {
        EmpBaseInfo empBaseInfo = this.getById(empId);
        if (StrUtil.isBlank(empBaseInfo.getImagePath())) {
            return;
        }
        String path = properties.getEmpBaseInfoPath() + empBaseInfo.getImagePath();
        try (InputStream inputStream = new FileInputStream(path); OutputStream out = response.getOutputStream()) {
 
            // byte数组用于存放图片字节数据
            byte[] buff = new byte[inputStream.available()];
 
            inputStream.read(buff);
            inputStream.close();
 
            String contentType = empBaseInfo.getImagePath().substring(empBaseInfo.getImagePath().lastIndexOf(".") + 1);
            if (contentType.equals("tif")) {
                // 设置发送到客户端的响应内容类型
                response.setContentType("image/tiff");
            } else if (contentType.equals("bmp")) {
                response.setContentType("application/x-bmp");
            } else if (contentType.equals("jpg")) {
                response.setContentType("image/jpeg");
            } else if (contentType.equals("gif")) {
                response.setContentType("image/gif");
            } else {
                response.setContentType("image/png");
            }
            out.write(buff);
        }
    }
 
    @Override
    public IPage<EmpBaseInfo> baseInfoList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpBaseInfo> page = new Page<EmpBaseInfo>(new Long(pageNum), new Long(pageSize));
        IPage<EmpBaseInfo> iPage = null;
        List<SysConfig> sysConfig = this.baseMapper.sysConfig();
        String manOld = "";
        String womanOld = "";
        if (sysConfig.size() > 0) {
            manOld = sysConfig.get(0).getConfigValue();
            womanOld = sysConfig.get(1).getConfigValue();
        }
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        if ("1".equals(number)) { // 在职员工
            iPage = this.empBaseInfoMapper.zzbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("2".equals(number)) { // 新进员工
            iPage = this.empBaseInfoMapper.xjbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("3".equals(number)) { // 正式员工
            iPage = this.empBaseInfoMapper.zsbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("4".equals(number)) { // 临时员工
            iPage = this.empBaseInfoMapper.lsbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("5".equals(number)) { // 超龄员工
            iPage = this.empBaseInfoMapper.clbaseInfoList(page, index, btime, etime, name, manOld, womanOld, lists);
        } else if ("6".equals(number)) { // 离职员工总数
            iPage = this.empBaseInfoMapper.lzbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("7".equals(number)) { // 辞职申请人数
            iPage = this.empBaseInfoMapper.cjbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("8".equals(number) || "9".equals(number) || "10".equals(number)) { // 正常离职人数 ,自动离职人数 ,公司辞退人数
            iPage = this.empBaseInfoMapper.zcbaseInfoList(page, index, btime, etime, name, number, lists);
        } else if ("11".equals(number)) { // 身份证到期
            iPage = this.empBaseInfoMapper.sfzbaseInfoList(page, index, btime, etime, name, lists);
        }
        // 设置部门
        List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
        list.forEach(p -> {
            p.setSexName("1".equals(p.getSex()) ? "男" : "女");
            if (StringUtils.isNotBlank(p.getEmpType())) {
                p.setEmpTypeName("1".equals(p.getEmpType()) ? "正式工" : "临时工");
            }
            if (StringUtils.isNotBlank(p.getDimissionType())) {
                // if ("1".equals(p.getDimissionType())) {
                //     p.setDimissionTypeName("正常离职");
                // } else if ("2".equals(p.getDimissionType())) {
                //     p.setDimissionTypeName("自动离职");
                // } else if ("3".equals(p.getDimissionType())) {
                //     p.setDimissionTypeName("公司劝退");
                // } else if ("4".equals(p.getDimissionType())) {
                //     p.setDimissionTypeName("公司辞退");
                // } else if ("5".equals(p.getDimissionType())) {
                //     p.setDimissionTypeName("试用期内");
                // }
                p.setDimissionTypeName(dicItems.stream()
                        .filter(k -> DicCode.IN_OUT_TYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getDimissionType()))
                        .findFirst()
                        .map(DicItem::getDicItemName)
                        .orElse(""));
            }
            p.setInsuranceTypeName("1".equals(p.getInsuranceType()) ? "(深户)五险一档" : "(非深户)五险一档");
            p.setArchivesStatusName("0".equals(p.getArchivesStatus()) ? "未移交" : "已移交");
            // 设置民族
            p.setNationName(dicItems.stream()
                    .filter(k -> DicCode.NATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("汉族"));
            // 设置政治面貌
            p.setPoliticsName(dicItems.stream()
                    .filter(k -> DicCode.PLITICAL.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getPolitics()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("群众"));
            // 设置婚姻状况
            p.setMarriageName(dicItems.stream()
                    .filter(k -> DicCode.MARRIAGE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getMarriage()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未婚"));
            // 设置学历
            p.setEducationName(dicItems.stream()
                    .filter(k -> DicCode.EDUCATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEducation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("无学历"));
            // 设置籍贯
            p.setNativePlaceName(dicItems.stream()
                    .filter(k -> DicCode.NATIVEPLACE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNativePlace()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
        });
        iPage.setRecords(list);
        return iPage;
    }
 
    @Override
    public IPage<EmpBaseInfo> baseInfoHeList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpBaseInfo> page = new Page<EmpBaseInfo>(new Long(pageNum), new Long(pageSize));
        IPage<EmpBaseInfo> iPage = null;
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        if ("11".equals(number) || "13".equals(number) || "14".equals(number)) { // 有效合同   ,新签合同,续签合同
            iPage = this.empBaseInfoMapper.yxbaseInfoList(page, index, btime, etime, name, number, lists);
        } else if ("12".equals(number)) { // 到期合同
            iPage = this.empBaseInfoMapper.dqbaseInfoList(page, index, btime, etime, name, lists);
        } else if ("15".equals(number)) { // 解除合同
            iPage = this.empBaseInfoMapper.jcseInfoList(page, index, btime, etime, name, lists);
        }
        // 设置部门
        List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
        list.forEach(p -> {
            if ("1".equals(p.getContractStatus())) {
                p.setContractStatus("新签");
            } else if ("2".equals(p.getContractStatus())) {
                p.setContractStatus("续签");
            } else if ("3".equals(p.getContractStatus())) {
                p.setContractStatus("解除");
            } else if ("4".equals(p.getContractStatus())) {
                p.setContractStatus("到期");
            }
        });
        iPage.setRecords(list);
        return iPage;
    }
 
    @Override
    public IPage<EmpDimissionAttend> empBaseInfoCqList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpDimissionAttend> page = new Page<EmpDimissionAttend>(new Long(pageNum), new Long(pageSize));
        IPage<EmpDimissionAttend> iPage = null;
        // q出勤人数   员工加班   员工旷工
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoCqList(page, index, btime, etime, name, number, lists);
 
        return iPage;
    }
 
    @Override
    public IPage<EmpLeaveInfo> empBaseInfoQjList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpLeaveInfo> page = new Page<EmpLeaveInfo>(new Long(pageNum), new Long(pageSize));
        IPage<EmpLeaveInfo> iPage = null;
        // 员工请假
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoQjList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpPhysicalExam> empBaseInfoTjList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpPhysicalExam> page = new Page<EmpPhysicalExam>(new Long(pageNum), new Long(pageSize));
        IPage<EmpPhysicalExam> iPage = null;
        // 员工体检
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoTjList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpLaborTrouble> empBaseInfoLzList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpLaborTrouble> page = new Page<EmpLaborTrouble>(new Long(pageNum), new Long(pageSize));
        IPage<EmpLaborTrouble> iPage = null;
        // 劳资案件
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoLzList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpJobChange> empBaseInfoTgList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpJobChange> page = new Page<EmpJobChange>(new Long(pageNum), new Long(pageSize));
        IPage<EmpJobChange> iPage = null;
        // 调岗
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoTgList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpOccupational> empBaseInfoGsList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpOccupational> page = new Page<EmpOccupational>(new Long(pageNum), new Long(pageSize));
        IPage<EmpOccupational> iPage = null;
        // 工伤案件
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoGsList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpAccidentCases> empBaseInfoYwList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpAccidentCases> page = new Page<EmpAccidentCases>(new Long(pageNum), new Long(pageSize));
        IPage<EmpAccidentCases> iPage = null;
        // 意外险案件
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoYwList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpInsurance> empBaseInfoSbList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpInsurance> page = new Page<EmpInsurance>(new Long(pageNum), new Long(pageSize));
        IPage<EmpInsurance> iPage = null;
        // 社保
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoSbList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpUnemployment> empBaseInfoSyjList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpUnemployment> page = new Page<EmpUnemployment>(new Long(pageNum), new Long(pageSize));
        IPage<EmpUnemployment> iPage = null;
        // 失业金
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoSyjList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public IPage<EmpBadRecord> empBaseInfoBlList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
        Page<EmpBadRecord> page = new Page<EmpBadRecord>(new Long(pageNum), new Long(pageSize));
        IPage<EmpBadRecord> iPage = null;
        // 不良记录
        String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
        List<String> lists = Arrays.asList(split);
        iPage = this.empBaseInfoMapper.empBaseInfoBlList(page, index, btime, etime, name, number, lists);
        return iPage;
    }
 
    @Override
    public Map<String, Object> countBaseInfoList(String index, String btime, String etime) {
        List<SysConfig> sysConfig = this.baseMapper.sysConfig();
        String manOld = "";
        String womanOld = "";
        if (sysConfig.size() > 0) {
            manOld = sysConfig.get(0).getConfigValue();
            womanOld = sysConfig.get(1).getConfigValue();
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.in("t1.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA));
        // 在职员工,正式员工,临时员工,超龄员工
        Map<String, Object> stringObjectMap = this.baseMapper.countBaseInfoList(index, btime, etime, manOld, womanOld, queryWrapper);
        // 正常离职,自动离职,公司辞退    判断条件创建日期
        Map<String, Object> zclzObjectMap = this.baseMapper.countZcygBaseInfoList(index, btime, etime, queryWrapper);
        if (zclzObjectMap != null) {
            stringObjectMap.put("zclz", zclzObjectMap.get("zclz").toString());
            stringObjectMap.put("zdlz", zclzObjectMap.get("zdlz").toString());
            stringObjectMap.put("gsct", zclzObjectMap.get("gsct").toString());
        }
        // 新进员工      判断条件入职日期
        Integer xjygObjectMap = this.baseMapper.countXjygBaseInfoList(index, btime, etime, queryWrapper);
        if (xjygObjectMap != null) {
            stringObjectMap.put("xjyg", xjygObjectMap);
        }
 
        // 离职员工总数
        Integer empStatus = this.baseMapper.selectCountlz(new QueryWrapper<EmpBaseInfo>()
                .eq("t.delFlag", 0).eq("t.empStatus", 1)
                .in("t1.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA)));
        if (empStatus != null) {
            stringObjectMap.put("lzyg", empStatus);
        }
        // 解除合同        判断条件离职申请日期
        Map<String, Object> lzygObjectMap = this.baseMapper.countLzygBaseInfoList(index, btime, etime, queryWrapper);
        if (lzygObjectMap != null) {
            stringObjectMap.put("jcht", lzygObjectMap.get("jcht").toString());
        }
        // 辞职申请员工总数     判断条件辞职申请日期
        Integer czygObjectMap = this.baseMapper.countCzygBaseInfoList(index, btime, etime, queryWrapper);
        if (czygObjectMap != null) {
            stringObjectMap.put("czyg", czygObjectMap);
        }
        // 有效合同    判断条件合同签订日期
        Map<String, Object> yxhtObjectMap = this.baseMapper.countYxhtBaseInfoList(index, btime, etime, queryWrapper);
        if (yxhtObjectMap != null) {
            stringObjectMap.put("yxht", yxhtObjectMap.get("yxht").toString());
        }
        // 新签合同,续签合同    判断条件合同签订日期
        Map<String, Object> xqhtObjectMap = this.baseMapper.countXqhtBaseInfoList(index, btime, etime, queryWrapper);
        if (yxhtObjectMap != null) {
            stringObjectMap.put("xinqht", xqhtObjectMap.get("xinqht").toString());
            stringObjectMap.put("xqht", xqhtObjectMap.get("xqht").toString());
        }
        // 到期合同     判断条件合同结束时间
        Integer dqhtObjectMap = this.baseMapper.countDqhtBaseInfoList(index, btime, etime, queryWrapper);
        if (dqhtObjectMap != null) {
            stringObjectMap.put("dqht", dqhtObjectMap);
        }
 
        // 出勤人数,员工加班,员工旷工    判断条件考勤月份    本年,本月
        Map<String, Object> cqrsObjectMap = this.baseMapper.countCqrsBaseInfoList(index, btime, etime, queryWrapper);
        if (cqrsObjectMap != null) {
            stringObjectMap.put("cqrs", cqrsObjectMap.get("cqrs").toString());
            stringObjectMap.put("ygjb", cqrsObjectMap.get("ygjb").toString());
            stringObjectMap.put("ygkg", cqrsObjectMap.get("ygkg").toString());
        }
 
        // 员工请假     判断条件到岗时间
        Integer ygqjObjectMap = this.baseMapper.countYgqjBaseInfoList(index, btime, etime, queryWrapper);
        if (ygqjObjectMap != null) {
            stringObjectMap.put("ygqj", ygqjObjectMap);
        }
 
        // 劳资案件     判断条件仲裁日期
        Integer lzajObjectMap = this.baseMapper.countLzajBaseInfoList(index, btime, etime, queryWrapper);
        if (lzajObjectMap != null) {
            stringObjectMap.put("lzaj", lzajObjectMap);
        }
        // 工伤案件,意外险案件     判断条件受伤日期
        Map<String, Object> gsajObjectMap = this.baseMapper.countGsajBaseInfoList(index, btime, etime, queryWrapper);
        if (gsajObjectMap != null) {
            stringObjectMap.put("gsaj", gsajObjectMap.get("gsaj").toString());
            stringObjectMap.put("ywxaj", gsajObjectMap.get("ywxaj").toString());
        }
        // 社保申请     判断条件社保申请日期
        Integer sbsqObjectMap = this.baseMapper.countSbsqBaseInfoList(index, btime, etime, queryWrapper);
        if (sbsqObjectMap != null) {
            stringObjectMap.put("sbsq", sbsqObjectMap);
        }
        // 失业金领取     判断条件失业金申请日期
        Integer syjObjectMap = this.baseMapper.countSyjBaseInfoList(index, btime, etime, queryWrapper);
        if (syjObjectMap != null) {
            stringObjectMap.put("syj", syjObjectMap);
        }
        // 员工体检     判断条件体检日期
        Integer ygtjObjectMap = this.baseMapper.countYgtjBaseInfoList(index, btime, etime, queryWrapper);
        if (ygtjObjectMap != null) {
            stringObjectMap.put("ygtj", ygtjObjectMap);
        }
        // 身份证到期     判断条件身份证有效时间
        Integer sfzObjectMap = this.baseMapper.countSfzBaseInfoList(index, btime, etime, queryWrapper);
        if (sfzObjectMap != null) {
            stringObjectMap.put("sfz", sfzObjectMap);
        }
 
        // 员工调岗     判断条件身份证有效时间
        Integer ygtgObjectMap = this.baseMapper.countYgtgBaseInfoList(index, btime, etime, queryWrapper);
        if (ygtgObjectMap != null) {
            stringObjectMap.put("ygtg", ygtgObjectMap);
        }
 
        // 不良记录     判断条件身份证有效时间
        Integer bljlObjectMap = this.baseMapper.countBljlBaseInfoList(index, btime, etime, queryWrapper);
        if (bljlObjectMap != null) {
            stringObjectMap.put("bljl", bljlObjectMap);
        }
        // 试用提醒     判断条件试用期结束时间
        EmpBaseInfo empBaseInfo = new EmpBaseInfo();
        empBaseInfo.setTimeRange(Integer.valueOf(index));
        Long count = empBaseInfoMapper.selectAlertCount(
                createProbationAlertQueryWrapper(empBaseInfo)
        );
        if (count != null) {
            stringObjectMap.put("probationCount", count);
        }
 
        // 四险提醒     判断条件试用期结束时间
        empBaseInfo = new EmpBaseInfo();
        empBaseInfo.setTimeRange(Integer.valueOf(index));
        QueryRequest queryRequest = new QueryRequest();
        count = this.countInsuranceAlert(empBaseInfo, queryRequest);
        if (count != null) {
            stringObjectMap.put("insuranceCount", count);
        }
        //QueryRequest request
        return stringObjectMap;
    }
 
    /**
     * 检查是否是带条件查询
     * <p>
     * date 2021-02-26 13:49
     *
     * @param empBaseInfo 人员参数
     * @return boolean
     * @author: luoyibo
     */
    private boolean checkQueryCondition(EmpBaseInfo empBaseInfo) {
        int hasCondition = 0;
        if (StringUtils.isNotBlank(empBaseInfo.getEmpNumb())) {
            hasCondition = hasCondition | 1;
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpName())) {
            hasCondition = hasCondition | 1;
        }
        if (StringUtils.isNotBlank(empBaseInfo.getDeptName())) {
            hasCondition = hasCondition | 1;
        }
        if (StringUtils.isNotBlank(empBaseInfo.getCertificateNumb())) {
            hasCondition = hasCondition | 1;
        }
        return hasCondition == 1;
    }
 
    private QueryWrapper<EmpBaseInfo> createQueryWrapper(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        // 记录的状态,0-正常 1-删除 2-暂存
        if (StringUtils.isNotBlank(empBaseInfo.getDelFlag().toString())) {
            queryWrapper.eq("a.DelFlag", empBaseInfo.getDelFlag());
        } else {
            queryWrapper.eq("a.DelFlag", 0);
        }
        // 人员的状态,0-在职 1-离职 2-退休
        if (StringUtils.isNotBlank(empBaseInfo.getEmpStatus())) {
            queryWrapper.in("a.EmpStatus", empBaseInfo.getEmpStatus().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpCardStatus())) {
            queryWrapper.in("a.empCardStatus", empBaseInfo.getEmpCardStatus().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getHandbookStatus())) {
            queryWrapper.in("a.handBookStatus", empBaseInfo.getHandbookStatus().split(","));
        }
        // 关键词查询,是或的关系
        if (StringUtils.isNotBlank(empBaseInfo.getBaseKey())) {
            queryWrapper.and(p -> {
                p.like("a.EmpNumb", empBaseInfo.getBaseKey());
                p.or().like("a.allDeptName", empBaseInfo.getBaseKey());
                p.or().like("a.empName", empBaseInfo.getBaseKey());
                p.or().like("a.CertificateNumb", empBaseInfo.getBaseKey());
                p.or().like("a.archivesNumb", empBaseInfo.getBaseKey());
                p.or().like("a.stature", empBaseInfo.getBaseKey());
                p.or().like("a.seniority", empBaseInfo.getBaseKey());
                p.or().like("a.nativePlace", empBaseInfo.getBaseKey());
                p.or().like("a.censusAddress", empBaseInfo.getBaseKey());
                p.or().like("a.guardNumb", empBaseInfo.getBaseKey());
                p.or().like("a.telePhone", empBaseInfo.getBaseKey());
                p.or().like("a.socialNumb", empBaseInfo.getBaseKey());
                p.or().like("a.bankName", empBaseInfo.getBaseKey());
                p.or().like("a.bankNumb", empBaseInfo.getBaseKey());
                p.or().like("a.family", empBaseInfo.getBaseKey());
                p.or().like("a.certificateList", empBaseInfo.getBaseKey());
            });
        }
 
        if (StringUtils.isNotBlank(empBaseInfo.getEmpNumb())) {
            queryWrapper.like("a.EmpNumb", empBaseInfo.getEmpNumb());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpName())) {
            queryWrapper.like("a.EmpName", empBaseInfo.getEmpName());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getDeptName())) {
            queryWrapper.like("a.allDeptName", empBaseInfo.getDeptName());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getCertificateNumb())) {
            queryWrapper.like("a.CertificateNumb", empBaseInfo.getCertificateNumb());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEntryDateStr())) {
            queryWrapper.between("a.EntryDate", empBaseInfo.getEntryDateStr().split(",")[0], empBaseInfo.getEntryDateStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getDimissionDateStr())) {
            queryWrapper.between("a.DimissionDate", empBaseInfo.getDimissionDateStr().split(",")[0], empBaseInfo.getDimissionDateStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getSex())) {
            queryWrapper.in("a.Sex", empBaseInfo.getSex().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEducation())) {
            queryWrapper.in("a.Education", empBaseInfo.getEducation().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getPolitics())) {
            queryWrapper.in("a.Politics", empBaseInfo.getPolitics().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getAgeStr())) {
            String[] ages = empBaseInfo.getAgeStr().split(",");
            Consumer<QueryWrapper<EmpBaseInfo>> consumer = new Consumer<QueryWrapper<EmpBaseInfo>>() {
                @Override
                public void accept(QueryWrapper<EmpBaseInfo> wrapper) {
                    for (int i = 0; i < ages.length; i++) {
                        String ageBtn = ages[i];
                        wrapper.or().between("a.Age", ageBtn.split("-")[0], ageBtn.split("-")[1]);
                    }
                }
            };
            queryWrapper.and(consumer);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getArchivesStatus())) {
            queryWrapper.in("a.ArchivesStatus", empBaseInfo.getArchivesStatus().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getInsuranceType())) {
            queryWrapper.in("a.InsuranceType", empBaseInfo.getInsuranceType().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getHandbookStatus())) {
            queryWrapper.in("a.HandbookStatus", empBaseInfo.getHandbookStatus().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpCardStatus())) {
            queryWrapper.in("a.EmpCardStatus", empBaseInfo.getEmpCardStatus().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpType())) {
            queryWrapper.in("a.empType", empBaseInfo.getEmpType().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEntryType())) {
            queryWrapper.in("a.entryType", empBaseInfo.getEntryType().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getDimissionType())) {
            queryWrapper.in("a.dimissionType", empBaseInfo.getDimissionType().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getInOutType())) {
            queryWrapper.and(p -> {
                p.in("a.dimissionType", empBaseInfo.getInOutType().split(","));
                p.or().in("a.entryType", empBaseInfo.getInOutType().split(","));
            });
            // queryWrapper.in("a.dimissionType", empBaseInfo.getDimissionType().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getCertificateList())) {
            String[] certificates = empBaseInfo.getCertificateList().split(",");
            Consumer<QueryWrapper<EmpBaseInfo>> consumer = new Consumer<QueryWrapper<EmpBaseInfo>>() {
                @Override
                public void accept(QueryWrapper<EmpBaseInfo> wrapper) {
                    for (int i = 0; i < certificates.length; i++) {
                        String ageBtn = "|" + certificates[i] + "|";
                        wrapper.gt("LOCATE('" + ageBtn + "',CONCAT('|',replace( certificateList, ',', '|,|'),'|'))", 0);
                    }
                }
            };
            queryWrapper.and(consumer);
        }
        queryWrapper.in("c.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA));
        return queryWrapper;
    }
 
    @Override
    public EmpBaseInfo addInEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        EmpBaseInfo dbEmpInfo = this.getEmpBaseInfo(empBaseInfo);
        if (dbEmpInfo == null) {
            empBaseInfo.setDelFlag(0);
            this.createEmpBaseInfo(empBaseInfo);
            return null;
        } else {
            return dbEmpInfo;
        }
    }
 
    @Override
    public Long getEmpIdByEmpNumb(String empNumb) {
        try {
            return this.getOne(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb, empNumb).ne(EmpBaseInfo::getDelFlag, 1)).getEmpId();
        } catch (Exception e) {
            return null;
        }
 
    }
 
    @Override
    public EmpBaseInfo getEmpBaseInfoByEmpNumb(String empNumb) {
        try {
            return this.getOne(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb, empNumb).ne(EmpBaseInfo::getDelFlag, 1));
        } catch (Exception e) {
            return null;
        }
 
    }
 
    @Override
    public void exportEmpAll(HttpServletResponse response, EmpBaseInfo empBaseinfo) throws IOException {
        // 获取字典
        List<DicItem> dicItemList = remoteDicItemService.getAllDicitemsAll();
        Map<String, Object> map = new HashMap<>();
 
        List<Long> itemCode = dicItemList.stream().map(i -> i.getDicId()).distinct().collect(Collectors.toList());
        itemCode.stream().forEach(i -> {
            List<DicItem> dicItems = dicItemList.stream().filter(j -> j.getDicId().equals(i)).collect(Collectors.toList());
            Map<String, Object> itemMap = new HashMap<>();
            dicItems.stream().forEach(dicItem -> itemMap.put(dicItem.getDicItemCode(), dicItem.getDicItemName()));
            map.put(dicItems.get(0).getDicCode().toLowerCase(), itemMap);
        });
        List<String> sheetNames = new ArrayList<>();
        sheetNames.add("基本信息");
        // 基本信息
        QueryRequest request = new QueryRequest();
        request.setPageSize(25535);
        request.setPageNum(1);
        List<EmpBaseInfo> exportList = this.findZsEmpBaseInfos(request, empBaseinfo).getRecords();
        List<Map<String, Object>> listMapDicItem = new ArrayList();
        listMapDicItem.add(map);
        String exportField = "archivesNumb, deptName, jobName, empName, certificateNumb, certificateValidity, sexName, nationName, age, marriageName, stature, birthdate, politicsName, empTypeName, educationName, nativePlaceName, censusAddress, currentAddress, guardNumb, returnReceipt, archivesStatusName, bankName, bankNumb, telePhone, entryDate, InsuranceTypeName, socialNumb, introducer, seniority, empCardStatusName, certificateList, urgencyPhone, handbookStatusName, family, empStatusName, dimissionDate";
        List<Map<String, Object>> allList = PoiExportExcel.getDataList(exportField, exportList, null);
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        List<Long> empIds = exportList.stream().map(i -> i.getEmpId()).collect(Collectors.toList());
 
        // 工作经历
        IPage<EmpWorkExperience> workExperienceIPage = empWorkExperienceMapper.selectPageVo(page, new QueryWrapper<EmpWorkExperience>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (workExperienceIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpWorkExperience.class);
            List<Map<String, Object>> allListEmpWork = PoiExportExcel.getDataList(exportField, workExperienceIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpWork.get(0));
            sheetNames.add("工作经历");
        }
 
        // 体检信息
        IPage<EmpPhysicalExam> empPhysicalExamIPage = empPhysicalExamMapper.selectPageVo(page, new QueryWrapper<EmpPhysicalExam>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empPhysicalExamIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpWorkExperience.class);
            List<Map<String, Object>> allListEmpPhysical = PoiExportExcel.getDataList(exportField, empPhysicalExamIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpPhysical.get(0));
            sheetNames.add("体检信息");
        }
 
        // 调岗记录
        IPage<EmpJobChange> jobChangeIPage = empJobChangeMapper.selectPageVoBean(page, new QueryWrapper<EmpJobChange>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (jobChangeIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpJobChange.class);
            List<Map<String, Object>> allListjobChangeI = PoiExportExcel.getDataList(exportField, jobChangeIPage.getRecords(), listMapDicItem);
            allList.add(allListjobChangeI.get(0));
            sheetNames.add("调岗记录");
        }
 
        // 合同信息
        IPage<EmpContractInfo> empContractInfoIPage = empContractInfoMapper.selectPageVo(page, new QueryWrapper<EmpContractInfo>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empContractInfoIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpContractInfo.class);
            List<Map<String, Object>> allListEmpContractInfo = PoiExportExcel.getDataList(exportField, empContractInfoIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpContractInfo.get(0));
            sheetNames.add("合同信息");
        }
 
        // 入离职记录
        IPage<EmpDimissionAttend> empDimissionAttendIPage = empDimissionAttendMapper.selectPageVo(page, new QueryWrapper<EmpDimissionAttend>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empDimissionAttendIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpDimissionAttend.class);
            List<Map<String, Object>> allListEmpDimissionAtt = PoiExportExcel.getDataList(exportField, empDimissionAttendIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpDimissionAtt.get(0));
            sheetNames.add("入离职记录");
        }
 
        // 请假记录
        IPage<EmpLeaveInfo> empLeaveInfoIPage = empLeaveInfoMapper.selectPageVo(page, new QueryWrapper<EmpLeaveInfo>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empLeaveInfoIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpLeaveInfo.class);
            List<Map<String, Object>> allListEmpLoeaveInfo = PoiExportExcel.getDataList(exportField, empLeaveInfoIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpLoeaveInfo.get(0));
            sheetNames.add("请假记录");
        }
 
 
        // 失业金领取
        IPage<EmpUnemployment> empUnemploymentIPage = empUnemploymentMapper.selectPageVo(page, new QueryWrapper<EmpUnemployment>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empUnemploymentIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpUnemployment.class);
            List<Map<String, Object>> allListEmpUnemployment = PoiExportExcel.getDataList(exportField, empUnemploymentIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpUnemployment.get(0));
            sheetNames.add("失业金领取");
        }
 
        // 社保申请
        IPage<EmpInsurance> empInsuranceIPage = empInsuranceMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empInsuranceIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpInsurance.class);
            List<Map<String, Object>> allListEmpInsurance = PoiExportExcel.getDataList(exportField, empInsuranceIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpInsurance.get(0));
            sheetNames.add("社保申请");
        }
 
 
        // 意外险案件
        IPage<EmpAccidentCases> empAccidentCasesIPage = empAccidentCasesMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empAccidentCasesIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpAccidentCases.class);
            List<Map<String, Object>> allListEmpAccidentCases = PoiExportExcel.getDataList(exportField, empAccidentCasesIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpAccidentCases.get(0));
            sheetNames.add("意外险案件");
        }
 
        // 工伤案件
        IPage<EmpOccupational> empOccupationalIPage = empOccupationalMapper.selectPageVo(page, new QueryWrapper<EmpOccupational>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empOccupationalIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpOccupational.class);
            List<Map<String, Object>> allListEmpOccupational = PoiExportExcel.getDataList(exportField, empOccupationalIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpOccupational.get(0));
            sheetNames.add("工伤案件");
        }
 
        // 劳资案件
        IPage<EmpLaborTrouble> empLaborTroubleIPage = empLaborTroubleMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empLaborTroubleIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpLaborTrouble.class);
            List<Map<String, Object>> allListEmpLaborTrouble = PoiExportExcel.getDataList(exportField, empLaborTroubleIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpLaborTrouble.get(0));
            sheetNames.add("劳资案件");
        }
 
 
        // 不良记录
        IPage<EmpBadRecord> empBadRecordIPage = empBadRecordMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empBadRecordIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpBadRecord.class);
            List<Map<String, Object>> allListEmpBadRecord = PoiExportExcel.getDataList(exportField, empBadRecordIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpBadRecord.get(0));
            sheetNames.add("不良记录");
        }
 
 
        // 备注信息
        IPage<EmpRemarkInfo> empRemarkInfoIPage = empRemarkInfoMapper.selectPageVo(page, new QueryWrapper<EmpRemarkInfo>().in("a.empId", empIds).ne("a.delFlag", 1));
        if (empRemarkInfoIPage.getRecords().size() != 0) {
            exportField = FebsUtil.reflectAnnotation(EmpRemarkInfo.class);
            List<Map<String, Object>> allListEmpRemarkInfo = PoiExportExcel.getDataList(exportField, empRemarkInfoIPage.getRecords(), listMapDicItem);
            allList.add(allListEmpRemarkInfo.get(0));
            sheetNames.add("备注信息");
        }
 
 
        boolean result = PoiExportExcel.exportCommonExcelMultiSheet(response, "在职员工列表", allList, sheetNames);
    }
 
    @Override
    public boolean verifyCertificateNumb(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmpBaseInfo::getCertificateNumb, empBaseInfo.getCertificateNumb())
                .ne(EmpBaseInfo::getDelFlag, 1);
        ;
        if (empBaseInfo.getEmpId() != null) {
            queryWrapper.lambda().ne(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId());
        }
 
        return this.count(queryWrapper) > 0;
    }
 
    @Override
    public List<EmpBaseInfo> listAll(QueryWrapper<EmpBaseInfo> wrapper) {
        return this.baseMapper.listAll(wrapper);
    }
 
    private String getCertificateListName(String certificateList, List<DicItem> dicItems) {
        String tempName;
        List<String> nameList = new ArrayList<>();
        String[] tempList = certificateList.split(",");
        if (tempList.length > 0) {
            for (int i = 0, len = tempList.length; i < len; i++) {
                String tempValue = tempList[i];
                tempName = dicItems.stream()
                        .filter(k -> DicCode.CERTIFICATE_LIST.equals(k.getDicCode()) && k.getDicItemCode().equals(tempValue))
                        .findFirst()
                        .map(DicItem::getDicItemName)
                        .orElse(tempValue);
                nameList.add(tempName);
            }
            tempName = nameList.stream().collect(Collectors.joining(", "));
        } else {
            tempName = "";
        }
        return tempName;
    }
 
    @Override
    public boolean updateSeniority() {
        return empBaseInfoMapper.updateSeniority() > 0;
    }
 
    @Override
    public boolean updateDeptName() {
        return empBaseInfoMapper.updateDeptName() > 0;
    }
 
    @Override
    public boolean updateEmpAge(String userId) {
        List<EmpBaseInfo> empBaseInfoList = new ArrayList<>();
        if (StringUtils.isNotBlank(userId)) {
            EmpBaseInfo empBaseInfo = this.getById(userId);
            empBaseInfoList.add(empBaseInfo);
        } else {
            empBaseInfoList = this.list();
        }
        if (!empBaseInfoList.isEmpty()) {
            empBaseInfoList.parallelStream().forEach(p -> {
                p.setAge(DateUtil.ageOfNow(p.getBirthdate()));
                this.saveOrUpdate(p);
            });
        }
        return false;
    }
 
    @Override
    public void updateAnnualLeave(String userId) {
        EmpBaseInfo empBaseInfo = this.getById(userId);
        int holiday = calculateHoliday(empBaseInfo.getEntryDate());
        empBaseInfo.setAnnualLeave(holiday);
        baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
                .set(EmpBaseInfo::getAnnualLeave, holiday)
                .eq(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId()));
    }
 
    @Override
    public void updateAnnualLeave() {
        List<EmpBaseInfo> list = this.list();
        list.parallelStream().forEach(p -> {
            int holiday = calculateHoliday(p.getEntryDate());
            p.setAnnualLeave(holiday);
            baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
                    .set(EmpBaseInfo::getAnnualLeave, holiday)
                    .eq(EmpBaseInfo::getEmpId, p.getEmpId()));
        });
    }
 
    @Override
    public void updateEmpBaseKeyInfo() {
        List<EmpBaseInfo> list = this.list();
        list.parallelStream().forEach(p -> {
            int holiday = calculateHoliday(p.getEntryDate());
            int age = calculateAge(p.getBirthdate());
 
            baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
                    .set(EmpBaseInfo::getAnnualLeave, holiday)
                    .set(EmpBaseInfo::getAge, age)
                    .eq(EmpBaseInfo::getEmpId, p.getEmpId()));
        });
    }
 
    // region 员工社保档位提醒
    @Override
    public IPage<EmpBaseInfo> findInsuranceEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "insuranceType", FebsConstant.ORDER_DESC, true);
 
        // 使用优化后的方法查询社保档位提醒员工
        List<EmpBaseInfo> alertList = findInsuranceAlertList(empBaseInfo,request);
        // 手动分页
        int total = alertList.size();
        int start = (int) ((page.getCurrent() - 1) * page.getSize());
        int end = Math.min(start + (int) page.getSize(), total);
 
        List<EmpBaseInfo> pageList = start < total ? alertList.subList(start, end) : new ArrayList<>();
 
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
        pageList.forEach(item -> {
            item.setInsuranceTypeName(dicItems.stream()
                    .filter(k -> DicCode.INSURANCETYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getInsuranceType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            item.setSexName(dicItems.stream()
                    .filter(k -> DicCode.SEX.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getSex()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            item.setNativePlaceName(dicItems.stream()
                    .filter(k -> DicCode.NATIVEPLACE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getNativePlace()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            item.setEmpTypeName(dicItems.stream()
                    .filter(k -> DicCode.EMPTYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getEmpType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            item.setEducationName(dicItems.stream()
                    .filter(k -> DicCode.EDUCATION.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getEducation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
        });
        // 构建分页结果
        Page<EmpBaseInfo> resultPage = new Page<>(page.getCurrent(), page.getSize(), total);
        resultPage.setRecords(pageList);
        return resultPage;
    }
 
    @Override
    public Long countInsuranceAlert(EmpBaseInfo empBaseInfo, QueryRequest request) {
        return (long) findInsuranceAlertList(empBaseInfo,request).size();
    }
    /**
     * 查询社保档位提醒员工列表
     * 保险类型:6-(非深户) 四险二档 7-(非深户) 四险一档 10-外参 13-临时工意外险 14-甲方购买
     * 提醒年龄:男 48 岁,女 39 岁
     *
     * @param empBaseInfo 查询条件,timeRange 字段控制时间范围(0-当天 1-本周 2-本月 3-今年)
     * @return 符合条件的员工列表
     */
    private List<EmpBaseInfo> findInsuranceAlertList(EmpBaseInfo empBaseInfo, QueryRequest request) {
        // 1. 计算时间范围
        LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
        LocalDate startDate = dateRange[0];
        LocalDate endDate = dateRange[1];
 
        // 2. 获取提醒年龄配置
        int alertWomanAge = getRedisConfigWithDefault("insurance_alert_woman", 39);
        int alertManAge = getRedisConfigWithDefault("insurance_alert_man", 48);
 
        // 3. 获取排序参数
        String sortField = StringUtils.isNotBlank(request.getField()) ? request.getField() : "insuranceType";
        boolean isAsc = FebsConstant.ORDER_ASC.equals(request.getOrder());
 
        // 4. 查询符合条件的员工(仅做初步筛选)
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.DelFlag", "0")
                .eq("a.empStatus", "0")
                .in("a.insuranceType", "6", "7", "10", "13", "14")
                .isNotNull("a.birthdate")
                .isNotNull("a.sex");
        // 如果传入了性别条件,则添加性别筛选
        if (StringUtils.isNotBlank(empBaseInfo.getSex())) {
            queryWrapper.eq("a.sex", empBaseInfo.getSex());
        }
 
        // 如果传入了社保档位条件,则添加社保档位筛选
        if (StringUtils.isNotBlank(empBaseInfo.getInsuranceType())) {
            queryWrapper.eq("a.insuranceType", empBaseInfo.getInsuranceType());
        }
        // 添加排序条件
        queryWrapper.orderBy(true, isAsc, sortField);
        List<EmpBaseInfo> allList = this.baseMapper.listAll(queryWrapper);
 
        // 5. 精确筛选:计算每个员工的"生日 + 提醒年龄"日期,判断是否在时间范围内
        return allList.stream()
                .filter(emp -> {
                    if (emp.getBirthdate() == null || emp.getSex() == null) {
                        return false;
                    }
 
                    int alertAge = "1".equals(emp.getSex()) ? alertManAge : alertWomanAge;
                    LocalDate birthDate = emp.getBirthdate().toInstant()
                            .atZone(ZoneId.systemDefault())
                            .toLocalDate();
                    LocalDate alertDate = birthDate.plusYears(alertAge);
 
                    return !alertDate.isAfter(endDate);
                })
                .collect(Collectors.toList());
    }
    //#endregion
 
    @Override
    public IPage<EmpBaseInfo> findRetirementEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "birthDate", FebsConstant.ORDER_ASC, true);
 
        // 使用正向计算获取退休提醒列表
        List<EmpBaseInfo> alertList = findRetirementAlertList(empBaseInfo);
        
        // 手动分页
        int total = alertList.size();
        int start = (int) ((page.getCurrent() - 1) * page.getSize());
        int end = Math.min(start + (int) page.getSize(), total);
        
        List<EmpBaseInfo> pageList = start < total ? alertList.subList(start, end) : new ArrayList<>();
        
        // 设置字典名称
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
        pageList.forEach(item -> {
            item.setSexName(dicItems.stream()
                    .filter(k -> DicCode.SEX.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getSex()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
        });
        
        // 构建分页结果
        Page<EmpBaseInfo> resultPage = new Page<>(page.getCurrent(), page.getSize(), total);
        resultPage.setRecords(pageList);
        return resultPage;
    }
 
    @Override
    public IPage<EmpBaseInfo> findProbationEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "probationDate", FebsConstant.ORDER_ASC, true);
 
        IPage<EmpBaseInfo> iPage = empBaseInfoMapper.selectPageVo(page, createProbationAlertQueryWrapper(empBaseInfo));
        List<EmpBaseInfo> list = iPage.getRecords();
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
 
        list.forEach(item -> {
            item.setProbationStatusName(dicItems.stream()
                    .filter(k -> DicCode.PROBATIONS_TATUS.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getProbationStatus()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
            item.setInsuranceTypeName(dicItems.stream()
                    .filter(k -> DicCode.INSURANCETYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getInsuranceType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
        });
 
        iPage.setRecords(list);
        return iPage;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void probationEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
        LambdaUpdateWrapper<EmpBaseInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId())
                .set(EmpBaseInfo::getProbationDate, empBaseInfo.getProbationDate())
                .set(EmpBaseInfo::getProbationStatus, empBaseInfo.getProbationStatus())
                .set(EmpBaseInfo::getModifier, operatorId)
                .set(EmpBaseInfo::getModifyTime, new Date());
 
        this.update(updateWrapper);
        if (empBaseInfo.getProbationStatus().equals("2")) {
            // 如果是解骋,需要关闭员工档案
            EmpDimissionLog dimissionLog = new EmpDimissionLog();
            dimissionLog.setDimissionDate(empBaseInfo.getProbationDate());
            dimissionLog.setDimissionType("5");
            dimissionLog.setEmpIds(empBaseInfo.getEmpId().toString());
            dimissionLog.setEntryDates(DateUtil.format(empBaseInfo.getEntryDate(), "yyyy-MM-dd"));
            dimissionLog.setDeptNames(empBaseInfo.getDeptName());
            dimissionLog.setAfterOperation("1");
            this.closeEmpArchives(dimissionLog);
        }
    }
 
    /**
     * 根据设置的参数计算员工的年假
     *
     * @param date 入职日期
     * @return 年假天数
     */
    private int calculateHoliday(Date date) {
        int holiday = 0;
        int joinYear = DateUtil.ageOfNow(date);
        String configValue = redisService.get("annual_leave").toString();
        String[] values = StrUtil.split(configValue, "|");
        String[] condition = StrUtil.split(values[0], ",");
        String[] days = StrUtil.split(values[1], ",");
        if (condition.length == 2) {
            int one = Integer.parseInt(condition[0]);
            int two = Integer.parseInt(condition[1]);
            if (joinYear >= one && joinYear < two) {
                holiday = Integer.parseInt(days[0]);
            } else if (joinYear >= two) {
                holiday = Integer.parseInt(days[1]);
            }
        }
        return holiday;
    }
 
    private int calculateAge(Date date) {
        return DateUtil.ageOfNow(date);
    }
 
    private QueryWrapper<EmpBaseInfo> createInsuranceAlertQueryWrapper(EmpBaseInfo empBaseInfo) {
        String[] alertInsuranceTypes = {"6", "7", "10", "13", "14"};
 
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.DelFlag", "0");
        queryWrapper.eq("a.empStatus", "0");
        queryWrapper.in("a.insuranceType", (Object[]) alertInsuranceTypes);
 
        int alertWomanAge = getRedisConfigWithDefault("insurance_alert_woman", 39);
        int alertManAge = getRedisConfigWithDefault("insurance_alert_man", 48);
 
        queryWrapper.and(wrapper ->
                wrapper.and(inner -> inner.eq("a.sex", "1").ge("a.age", alertManAge))
                        .or(inner -> inner.eq("a.sex", "2").ge("a.age", alertWomanAge))
        );
 
 
        return queryWrapper;
    }
 
    private void buildAgeCondition(QueryWrapper<EmpBaseInfo> wrapper, int manAge, int womanAge) {
        wrapper.nested(inner -> inner
                .gt("a.age", manAge).eq("a.sex", "1")
        ).or().nested(inner -> inner
                .gt("a.age", womanAge).eq("a.sex", "2")
        );
    }
 
    private int getRedisConfigWithDefault(String key, int defaultValue) {
        try {
            Object value = redisService.get(key);
            if (value == null) {
                log.warn("Redis配置 [{}] 不存在,使用默认值:{}");
                return defaultValue;
            }
            return Integer.parseInt(value.toString());
        } catch (Exception e) {
            log.warn("Redis配置 [{}] 解析失败,使用默认值:{}");
            return defaultValue;
        }
    }
 
    /**
     * 查询退休提醒列表(正向计算)
     * 使用延迟退休计算逻辑:2025年1月起,男性每4个月延迟1个月,女性每2个月延迟1个月
     */
    public List<EmpBaseInfo> findRetirementAlertList(EmpBaseInfo empBaseInfo) {
        // 1. 计算目标时间范围
        LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
        LocalDate startDate = dateRange[0];
        LocalDate endDate = dateRange[1];
 
        // 2. 动态计算粗略出生日期范围
        // 最早出生:男性60岁+最大延迟3年+余量 = startDate - 63年 - 6个月
        LocalDate roughBirthStart = startDate.minusYears(63).minusMonths(6);
 
        // 最晚出生:女性50岁退休(最早退休)- 余量 = endDate - 50年 + 6个月
        // 解释:如果出生日期是 1975-01-01,女性法定退休是 2025-01-01,可能延迟几个月
        // 所以最晚出生日期应该比 endDate 早约 50年,再留点余量
        LocalDate roughBirthEnd = endDate.minusYears(50).plusYears(3); // 50岁+可能延迟3年
 
        // 3. 查询所有在职、未提醒的员工(动态粗略筛选)
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("DelFlag", 0)
                .eq("empStatus", "0")
                .eq("retirementReminded", 0)
                .ge("birthdate", roughBirthStart)
                .le("birthdate", roughBirthEnd);
 
        List<EmpBaseInfo> allList = this.baseMapper.selectList(queryWrapper);
 
        // 3. 逐个计算实际退休时间,筛选在范围内的
        return allList.stream()
                .filter(emp -> {
                    LocalDate actualRetirement = calculateActualRetirement(emp);
                    return actualRetirement != null
                            && !actualRetirement.isBefore(startDate)
                            && actualRetirement.isBefore(endDate);
                })
                .collect(Collectors.toList());
    }
 
    /**
     * 统计退休提醒数量(正向计算)
     */
    public Long countRetirementAlert(EmpBaseInfo empBaseInfo) {
        return (long) findRetirementAlertList(empBaseInfo).size();
    }
 
    /**
     * 计算员工的实际退休时间(正向计算)
     * 方案A:法定退休时间早于2025-01时,按法定年龄退休,不延迟
     */
    private LocalDate calculateActualRetirement(EmpBaseInfo emp) {
        if (emp.getBirthdate() == null || emp.getSex() == null) {
            return null;
        }
 
        LocalDate birthDate = emp.getBirthdate().toInstant()
                .atZone(java.time.ZoneId.systemDefault())
                .toLocalDate();
 
        // 法定退休年龄
        int legalAge = "1".equals(emp.getSex()) ? 60 : 50;
        // 延迟除数
        int delayDivisor = "1".equals(emp.getSex()) ? 4 : 2;
 
        // 法定退休时间
        LocalDate legalRetirement = birthDate.plusYears(legalAge);
 
        // 方案A:法定退休时间早于2025-01,按法定年龄退休
        LocalDate delayStart = LocalDate.of(2025, 1, 1);
        if (legalRetirement.isBefore(delayStart)) {
            return legalRetirement;
        }
 
        // 法定退休时间晚于等于2025-01,计算延迟
        long monthsBetween = ChronoUnit.MONTHS.between(delayStart, legalRetirement);
        long delayMonths = monthsBetween / delayDivisor;
 
        return legalRetirement.plusMonths(delayMonths);
    }
 
    /**
     * 根据时间范围类型计算开始和结束日期
     * @param timeRange 0-当天 1-本周 2-本月 3-今年
     * @return 包含开始日期和结束日期的数组 [startDate, endDate)
     */
    private LocalDate[] calculateDateRange(Integer timeRange) {
        if (timeRange == null) {
            timeRange = 2;
        }
 
        LocalDate now = LocalDate.now();
        LocalDate startDate;
        LocalDate endDate;
 
        switch (timeRange) {
            case 0: // 当天
                startDate = now;
                endDate = now.plusDays(1);
                break;
            case 1: // 本周(周一为开始)
                startDate = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
                endDate = startDate.plusWeeks(1);
                break;
            case 2: // 本月
                startDate = now.withDayOfMonth(1);
                endDate = startDate.plusMonths(1);
                break;
            case 3: // 今年
                startDate = now.withDayOfYear(1);
                endDate = startDate.plusYears(1);
                break;
            default:
                startDate = now.withDayOfMonth(1);
                endDate = startDate.plusMonths(1);
        }
 
        return new LocalDate[]{startDate, endDate};
    }
 
    private QueryWrapper<EmpBaseInfo> createProbationAlertQueryWrapper(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.DelFlag", 0)
                .eq("a.empStatus", "0");
 
        // 计算时间范围
        LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
 
        // 转正日期范围条件
        queryWrapper.ge("a.probationDate", dateRange[0])
                .lt("a.probationDate", dateRange[1]);
 
        // 转正状态条件:查询状态为 0 或 3 的员工
        queryWrapper.in("a.probationStatus", "0", "3");
 
        return queryWrapper;
    }
}