10 小时以前 571ccc18671ef45c6403496e8d99efec82168083
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
package com.ruoyi.staff.service.impl;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.staff.dto.PerformanceShiftAddDto;
import com.ruoyi.staff.dto.PerformanceShiftMapDto;
import com.ruoyi.staff.mapper.PersonalAttendanceLocationConfigMapper;
import com.ruoyi.staff.mapper.PersonalShiftMapper;
import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig;
import com.ruoyi.staff.pojo.PersonalShift;
import com.ruoyi.staff.service.PersonalShiftService;
import com.ruoyi.staff.utils.JackSonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;
 
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-03-05 03:52:19
 */
@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor
public class PersonalShiftServiceImpl extends ServiceImpl<PersonalShiftMapper, PersonalShift> implements PersonalShiftService {
 
    private final PersonalAttendanceLocationConfigMapper personalAttendanceLocationConfigMapper;
 
    @Override
    public int performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) {
        List<PersonalShift> list = new ArrayList<>();
        LocalDateTime startWeek = performanceShiftAddDto.getStartWeek();//开始日期
        LocalDateTime endWeek = performanceShiftAddDto.getEndWeek();//结束日期
 
 
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter);
        String[] splitUserId = performanceShiftAddDto.getStaffOnJobId().split(",");
        for (String userId : splitUserId) {
            //判断是否跨月
            boolean isMonth = startWeek.getMonthValue() != endWeek.getMonthValue();
            if (isMonth){
                //如果跨月,则两个月都判断一下看数据库是哪个月份的数据没有
                boolean exists1 = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery()
                        .eq(PersonalShift::getWorkTime, startWeek)
                        .eq(PersonalShift::getStaffOnJobId, userId));
                boolean exists2 = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery()
                        .eq(PersonalShift::getWorkTime, endWeek)
                        .eq(PersonalShift::getStaffOnJobId, userId));
                if (!exists1 && !exists2){
                    //两个月都不存在数据
                    list = saveMonth(performanceShiftAddDto.getStartWeek(), userId, list);
                    list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list);
                }else if (!exists1 && exists2){
                    //开始的月份不存在数据
                    list = saveMonth(performanceShiftAddDto.getStartWeek(), userId, list);
                }else if (exists1 && !exists2){
                    //结束的月份不存在数据
                    list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list);
                }
            }else {
                //不跨月
                boolean exists = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery()
                        .in(PersonalShift::getWorkTime, formattedDateTime)
                        .eq(PersonalShift::getStaffOnJobId, userId));
                // 如果不存在添加数据
                if (!exists) {
                    list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list);
                }
            }
        }
        if (!list.isEmpty()) {
           saveBatch(list);
            list.clear();
        }
        // 再次更新
        List<LocalDateTime> datesBetween = getLocalDateTimesBetween(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek());
        for (LocalDateTime date : datesBetween) {
            for (String s : splitUserId) {
                PersonalShift personalShift = new PersonalShift();
                personalShift.setPersonalAttendanceLocationConfigId(performanceShiftAddDto.getPersonalAttendanceLocationConfigId());
                personalShift.setStaffOnJobId(Long.valueOf(s));
                personalShift.setWorkTime(date);
                String formatterDateTime = date.format(formatter);
                baseMapper.update(new PersonalShift(), Wrappers.<PersonalShift>lambdaUpdate()
                        .set(PersonalShift::getPersonalAttendanceLocationConfigId, performanceShiftAddDto.getPersonalAttendanceLocationConfigId())
                        .eq(PersonalShift::getStaffOnJobId, s)
                        .eq(PersonalShift::getWorkTime, formatterDateTime));
            }
        }
        return 0;
    }
 
    @Override
    public Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, Integer sysDeptId) {
        IPage<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftPage(page, time, userName, sysDeptId);
        //查询所有班次(打卡规则)
        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null);
 
        // 获取当月时间范围
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatters);
        LocalDate firstDayOfMonth = localDateTime.toLocalDate().withDayOfMonth(1);
        LocalDate lastDayOfMonth = localDateTime.toLocalDate().with(TemporalAdjusters.lastDayOfMonth());
 
        // 收集所有员工ID
        List<Long> staffIds = mapIPage.getRecords().stream()
                .filter(dto -> dto.getUserId() != null)
                .map(dto -> Long.valueOf(dto.getUserId()))
                .distinct()
                .collect(Collectors.toList());
 
        // 查询当月审核通过的请假记录(从approval_instance的form_config解析)
        Map<Long, List<String>> staffHolidayMap = new HashMap<>();
        if (!staffIds.isEmpty()) {
            // 通过关联查询获取员工请假信息
            List<Map<String, Object>> holidayRecords = baseMapper.selectStaffHolidayDates(staffIds);
 
            // 构建员工-请假日期映射(从form_config JSON解析)
            for (Map<String, Object> record : holidayRecords) {
                Long staffId = ((Number) record.get("staff_id")).longValue();
                String formConfig = (String) record.get("form_config");
 
                if (formConfig != null && !formConfig.isEmpty()) {
                    try {
                        // 解析form_config JSON
                        Map<String, Object> formMap = JackSonUtil.unmarshal(formConfig, Map.class);
                        Object formPayloadObj = formMap.get("formPayload");
 
                        if (formPayloadObj instanceof Map) {
                            Map<String, Object> formPayload = (Map<String, Object>) formPayloadObj;
                            Object dateRangeObj = formPayload.get("00"); // 请假日期字段key为"00"
 
                            if (dateRangeObj instanceof List) {
                                List<String> dateRange = (List<String>) dateRangeObj;
                                if (dateRange.size() >= 2) {
                                    String startDateTime = dateRange.get(0);
                                    String endDateTime = dateRange.get(1);
 
                                    // 解析日期(格式:yyyy-MM-dd HH:mm:ss)
                                    LocalDate startDate = LocalDate.parse(startDateTime.substring(0, 10));
                                    LocalDate endDate = LocalDate.parse(endDateTime.substring(0, 10));
 
                                    // 过滤当月范围内的请假日期
                                    List<String> dates = getDatesBetween(startDate, endDate).stream()
                                            .filter(date -> {
                                                LocalDate d = LocalDate.parse(date);
                                                return !d.isBefore(firstDayOfMonth) && !d.isAfter(lastDayOfMonth);
                                            })
                                            .collect(Collectors.toList());
 
                                    if (!dates.isEmpty()) {
                                        staffHolidayMap.computeIfAbsent(staffId, k -> new ArrayList<>()).addAll(dates);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        // JSON解析失败,跳过此记录
                    }
                }
            }
        }
 
        for (PerformanceShiftMapDto i : mapIPage.getRecords()) {
            // 设置请假日期列表
            if (i.getUserId() != null) {
                Long staffId = Long.valueOf(i.getUserId());
                List<String> holidayDates = staffHolidayMap.getOrDefault(staffId, new ArrayList<>());
                i.setHolidayDates(holidayDates);
            }
 
            List<String> shiftTimes = StrUtil.split(i.getShiftTime(), ";");
            if(CollUtil.isEmpty(shiftTimes)){
                continue;
            }
            double totalAttendance = 0;//总出勤天数
            List<Map<String, Object>> map = new ArrayList<>();
            // 获取该员工的请假日期集合
            Set<String> holidayDateSet = new HashSet<>(i.getHolidayDates());
            // 分割日期
            for (String shiftTime : shiftTimes) {
                i.setShiftTime(null);
                Map<String, Object> hashMap = new HashMap<>();
                List<String> shiftTimeAndShift = StrUtil.split(shiftTime, ":");
                if(CollUtil.isEmpty(shiftTimeAndShift) || shiftTimeAndShift.size() != 3){
                    continue;
                }
                //排班详细数据
                hashMap.put("id", shiftTimeAndShift.get(2));
                hashMap.put("shift", shiftTimeAndShift.get(1));
                hashMap.put("time", shiftTimeAndShift.get(0));
 
                // 提取日期部分(格式:yyyy-MM-dd HH:mm:ss -> yyyy-MM-dd)
                String workTimeStr = shiftTimeAndShift.get(0);
                String workDate = workTimeStr.length() >= 10 ? workTimeStr.substring(0, 10) : workTimeStr;
 
                // 如果该日期有审核通过的请假记录,设置isHoliday为true,并将班次设为休息
                if (holidayDateSet.contains(workDate)) {
                    hashMap.put("isHoliday", true);
                    hashMap.put("shift", "休息");
                } else {
                    hashMap.put("isHoliday", false);
                }
 
                map.add(hashMap);
                i.setList(map);
 
                // 统计班次数据
                if (holidayDateSet.contains(workDate)) {
                    // 如果是请假日期,统计为休息(只统计一次)
                    if (!i.getMonthlyAttendance().containsKey("休息")){
                        i.getMonthlyAttendance().put("休息", 0);
                    }
                    i.getMonthlyAttendance().put("休息", new BigDecimal(i.getMonthlyAttendance().get("休息").toString()).add(new BigDecimal("1")));
                } else {
                    // 不是请假日期,统计原班次
                    for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                        if (!i.getMonthlyAttendance().containsKey(personalAttendanceLocationConfig.getShift())){
                            i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), 0);
                        }
                        if (personalAttendanceLocationConfig.getShift().equals(shiftTimeAndShift.get(1))) {
                            BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(personalAttendanceLocationConfig.getShift()).toString());
                            i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), bigDecimal.add(new BigDecimal("1")));
                        }
                    }
                    // 统计总出勤天数(早/中/晚/夜)都算出勤
                    if (shiftTimeAndShift.get(1).contains("早") ||
                        shiftTimeAndShift.get(1).contains("中") ||
                        shiftTimeAndShift.get(1).contains("晚") ||
                        shiftTimeAndShift.get(1).contains("夜")) {
                        i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1);
                    }
                }
            }
        }
        // 获取header时间
        List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay());
        List<Object> list1 = new ArrayList<>();
        for (LocalDateTime dateTime : localDateTimesBetween) {
            Map<Object, Object> hashMap = new HashMap<>();
            DateTime parse = DateUtil.parse(dateTime.format(formatter));
            hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1)));
            hashMap.put("headerTime", getWeek(dateTime.format(formatters)));
            list1.add(hashMap);
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("page", mapIPage);
        resultMap.put("headerList", list1);
        return resultMap;
    }
 
    /**
     * 获取两个日期之间的所有日期(格式:yyyy-MM-dd)
     * 注意:结束日期不包含在内(请假日期范围是开始日期到结束日期,不含结束日期)
     */
    private List<String> getDatesBetween(LocalDate startDate, LocalDate endDate) {
        List<String> dates = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate current = startDate;
        while (current.isBefore(endDate)) {
            dates.add(current.format(formatter));
            current = current.plusDays(1);
        }
        return dates;
    }
 
    @Override
    public void performanceShiftUpdate(PersonalShift personalShift) {
        baseMapper.update(new PersonalShift(), Wrappers.<PersonalShift>lambdaUpdate()
                .eq(PersonalShift::getId, personalShift.getId())
                .set(PersonalShift::getPersonalAttendanceLocationConfigId, personalShift.getPersonalAttendanceLocationConfigId()));
    }
 
    @Override
    public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, Integer sysDeptId) {
        IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, sysDeptId);
        //查询所有班次(打卡规则)
        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null);
        mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), personalAttendanceLocationConfigs));
        return mapYearIPage;
    }
 
    @Override
    public Map<Object, Object> exportToYearExcel(String time, String userName, Integer sysDeptId) throws Exception {
        Map<Object, Object> map = new HashMap<>();
        //查询所有班次(打卡规则)
        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null);
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将字符串时间转换为 LocalDateTime 类型时间
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatters);
        map.put("header", getYearHeader(localDateTime.getYear() + " 年", personalAttendanceLocationConfigs));
        List<Map<String, Object>> mapYearList = baseMapper.performanceShiftYearList(time, userName, sysDeptId);
        annualAttendanceProcessing(mapYearList, personalAttendanceLocationConfigs);
        List<List<Object>> lists = dataRequiredForProcessingIntoExcel(mapYearList, personalAttendanceLocationConfigs);
        map.put("data", lists);
        return map;
    }
 
    @Override
    public Map<Object, Object> exportToMonthExcel(String time, String userName, Integer sysDeptId) {
        //查询所有班次(打卡规则)
        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null);
        List<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftList(time, userName, sysDeptId);
        mapIPage.forEach(i -> {
            String[] shiftTimes = i.getShiftTime().split(";");
            double totalAttendance = 0;
            List<Map<String, Object>> map = new ArrayList<>();
            // 分割日期
            for (String shiftTime : shiftTimes) {
                Map<String, Object> hashMap = new HashMap<>();
                String[] shiftTimeAndShift = shiftTime.split(":");
                if(shiftTimeAndShift.length != 3){
                    continue;
                }
                for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                    if (!i.getMonthlyAttendance().containsKey(personalAttendanceLocationConfig.getShift())) {
                        i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), 0);
                    }
                    if (personalAttendanceLocationConfig.getShift().equals(shiftTimeAndShift[1])) {
                        BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(personalAttendanceLocationConfig.getShift()).toString());
                        i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), bigDecimal.add(new BigDecimal("1")));
                    }
                }
                //统计总出勤天数(早/中/晚/夜)都算出勤,其余都是休息
                if (shiftTimeAndShift[1].contains("早") ||
                        shiftTimeAndShift[1].contains("中") ||
                        shiftTimeAndShift[1].contains("晚") ||
                        shiftTimeAndShift[1].contains("夜")) {
                    i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1);
                }
                hashMap.put("id", shiftTimeAndShift[2]);
                hashMap.put("shift", shiftTimeAndShift[1]);
                hashMap.put("time", shiftTimeAndShift[0]);
                map.add(hashMap);
            }
            i.setList(map);
            i.setShiftTime(null);
        });
        Map<Object, Object> map = new HashMap<>();
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将字符串时间转换为 LocalDateTime 类型时间
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatters);
        map.put("header", getMonthHeader(localDateTime));
        List<List<Object>> lists = dataRequiredForProcessingIntoExcelMonth(mapIPage, personalAttendanceLocationConfigs);
        int maxSize = lists.stream()
                .mapToInt(List::size)
                .max()
                .orElse(0);
 
        for (List<Object> row : lists) {
            while (row.size() < maxSize) {
                row.add("-");
            }
        }
        map.put("data", lists);
        return map;
    }
 
    // 年分页与导出共同使用
    public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList,List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) {
        for (Map<String, Object> map : mapYearList) {
            Map<String, Object> resultMap = new LinkedHashMap<>();
            Map<String, Object> hashMapYear = new LinkedHashMap<>();
            double totalYearAttendance = 0;
            // 一年12个月
            for (int i = 1; i < 13; i++) {
                Map<String, Object> hashMapMonth = new LinkedHashMap<>();
                double totalMonthAttendance = 0;
                for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                    // 初始化赋值
                    if (!hashMapYear.containsKey(personalAttendanceLocationConfig.getShift())){
                        hashMapYear.put(personalAttendanceLocationConfig.getShift(), 0);
                    }
                    // 月
                    if (!ObjectUtils.isEmpty(map.get("month_str"))) {
                        String charArray = map.get("month_str").toString();
                        int count = countOccurrences(charArray, i + ":" + personalAttendanceLocationConfig.getShift());
                        hashMapMonth.put(personalAttendanceLocationConfig.getShift(), count);
                        hashMapYear.put(personalAttendanceLocationConfig.getShift(), new BigDecimal(hashMapYear.get(personalAttendanceLocationConfig.getShift()).toString()).add(new BigDecimal(count)));
                        // 早,中,夜,差
                        if (personalAttendanceLocationConfig.getShift().contains("早") ||
                                personalAttendanceLocationConfig.getShift().contains("中") ||
                                personalAttendanceLocationConfig.getShift().contains("晚") ||
                                personalAttendanceLocationConfig.getShift().contains("夜")) {
                            totalMonthAttendance += count;
                            totalYearAttendance += count;
                        }
                    }
                    // 空数据
                    else {
                        map.put("work_time", i);
                        hashMapMonth.put(personalAttendanceLocationConfig.getShift(), 0);
                    }
                }
                hashMapMonth.put("totalMonthAttendance", totalMonthAttendance);
                hashMapYear.put("totalYearAttendance", totalYearAttendance);
                resultMap.put(i + "", hashMapMonth);
            }
            map.remove("month_str");
            map.remove("year_str");
            map.put("year", hashMapYear);
            map.put("month", resultMap);
        }
        return mapYearList;
    }
 
    public static int countOccurrences(String str, String target) {
        int count = 0;
        int index = 0;
        while ((index = str.indexOf(target, index)) != -1) {
            count++;
            index += target.length();
        }
        return count;
    }
 
    public List<List<Object>> dataRequiredForProcessingIntoExcel(List<Map<String, Object>> list, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) throws Exception {
        List<List<Object>> data = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            List<Object> excelRowList = new ArrayList<>();
            excelRowList.add(i + 1);
            excelRowList.add(list.get(i).get("account"));
            excelRowList.add(list.get(i).get("name"));
            Map<String, Object> year = JackSonUtil.unmarshal(JackSonUtil.marshal(list.get(i).get("year")), Map.class);
            excelRowList.add(year.get("totalYearAttendance"));
            personalAttendanceLocationConfigs.forEach(j -> {
                excelRowList.add(year.get(j.getShift()));
            });
            Map<String, Map<String, Object>> month = JackSonUtil.unmarshal(JackSonUtil.marshal(list.get(i).get("month")), Map.class);
            for (int j = 1; j < 13; j++) {
                Object totalMonthAttendance = month.get(j + "").get("totalMonthAttendance");
                excelRowList.add(totalMonthAttendance);
                for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                        excelRowList.add(month.get(j + "").get(personalAttendanceLocationConfig.getShift()));
                }
            }
            data.add(excelRowList);
        }
        return data;
    }
 
 
    private List<PersonalShift>   saveMonth (LocalDateTime week,String userId,List<PersonalShift> list){
        LocalDate firstDayOfMonth = week.toLocalDate().withDayOfMonth(1);
        LocalDate lastDayOfMonth = week.toLocalDate().with(TemporalAdjusters.lastDayOfMonth());
        List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay());
        localDateTimesBetween.forEach(i -> {
            PersonalShift personalShift = new PersonalShift();
            personalShift.setStaffOnJobId(Long.valueOf(userId));
            personalShift.setWorkTime(i);
            list.add(personalShift);
            if (list.size() >= 1000) {
                saveBatch(list);
                list.clear();
            }
        });
        return list;
    }
 
    // 获取两个localDateTime的每一天
    public static List<LocalDateTime> getLocalDateTimesBetween(LocalDateTime start, LocalDateTime end) {
        List<LocalDateTime> localDateTimes = new ArrayList<>();
        LocalDate currentDate = start.toLocalDate();
        LocalDateTime currentLocalDateTime = start;
        while (!currentDate.isAfter(end.toLocalDate())) {
            localDateTimes.add(currentLocalDateTime);
            currentLocalDateTime = currentLocalDateTime.plusDays(1);
            currentDate = currentDate.plusDays(1);
        }
        return localDateTimes;
    }
 
    public static String getWeek(String dayStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = sdf.parse(dayStr);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            return day + " " + getWeekDay(dayOfWeek);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    public static String getWeekDay(int dayOfWeek) {
        switch (dayOfWeek) {
            case Calendar.MONDAY:
                return "周一";
            case Calendar.TUESDAY:
                return "周二";
            case Calendar.WEDNESDAY:
                return "周三";
            case Calendar.THURSDAY:
                return "周四";
            case Calendar.FRIDAY:
                return "周五";
            case Calendar.SATURDAY:
                return "周六";
            case Calendar.SUNDAY:
                return "周日";
            default:
                return "未知";
        }
    }
 
    /**
     * 返回表头
     * <p>
     * 外层List代表行内层 List代表列  相同的列数据会被主动合并
     * 构造双列表头
     *
     * @return List<List < String>>
     */
    private static List<List<String>> getYearHeader(String year, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) {
        List<List<String>> line = new ArrayList<>();
        line.add(Arrays.asList("考勤汇总", "序号", "序号"));
        line.add(Arrays.asList("考勤汇总", "工号", "工号"));
        line.add(Arrays.asList("考勤汇总", "姓名", "姓名"));
        line.add(Arrays.asList("出勤详情", year, "出勤"));
        // 年 header
        for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                line.add(Arrays.asList("考勤汇总", year, personalAttendanceLocationConfig.getShift()));
        }
        // 月header
        for (int i = 1; i < 13; i++) {
            line.add(Arrays.asList("出勤详情", i + " 月", "出勤"));
            for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                line.add(Arrays.asList("出勤详情", i + " 月", personalAttendanceLocationConfig.getShift()));
            }
        }
        return line;
    }
 
    private static List<List<String>> getMonthHeader(LocalDateTime localDateTimeYear) {
        String year = localDateTimeYear.getYear() + " 年人员班次";
        List<List<String>> line = new ArrayList<>();
        line.add(Arrays.asList(year, "序号", "序号", "序号"));
        line.add(Arrays.asList(year, "姓名", "姓名", "姓名"));
        line.add(Arrays.asList(year, "部门", "部门", "部门"));
        line.add(Arrays.asList(year, localDateTimeYear.getYear() + "", localDateTimeYear.getYear() + "", "出勤"));
        line.add(Arrays.asList(year, localDateTimeYear.getYear() + "", localDateTimeYear.getYear() + "","休"));
        line.add(Arrays.asList(year, "年", "年", "请假"));
        line.add(Arrays.asList(year, localDateTimeYear.getMonthValue() + "", localDateTimeYear.getMonthValue() + "", "早"));
        line.add(Arrays.asList(year, "月", "月", "中"));
        line.add(Arrays.asList(year, "", "", "夜"));
        line.add(Arrays.asList(year, "周次", "星期", "出差"));
        LocalDate firstDayOfMonth = localDateTimeYear.toLocalDate().withDayOfMonth(1);
        LocalDate lastDayOfMonth = localDateTimeYear.toLocalDate().with(TemporalAdjusters.lastDayOfMonth());
        List<LocalDateTime> timeList = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay());
        timeList.forEach(i -> {
            int dayOfYear = i.getDayOfMonth();
            Date from = Date.from(i.atZone(ZoneId.systemDefault()).toInstant());
            String weekDay = getWeekDay(i.getDayOfWeek().getValue());
            line.add(Arrays.asList(year, DateUtil.weekOfYear(DateUtil.offsetDay(from, 1)) + "", weekDay, dayOfYear + ""));
        });
        return line;
    }
 
    public List<List<Object>> dataRequiredForProcessingIntoExcelMonth(List<PerformanceShiftMapDto> list, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) {
        List<List<Object>> data = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            List<Object> excelRowList = new ArrayList<>();
            excelRowList.add(i + 1);
            excelRowList.add(list.get(i).getName());
            excelRowList.add(list.get(i).getDepartment());
            excelRowList.add(list.get(i).getMonthlyAttendance().get("totalAttendance"));
            excelRowList.add(list.get(i).getMonthlyAttendance().get("%休%")); // 休
            excelRowList.add(list.get(i).getMonthlyAttendance().get("%假%")); // 假
            excelRowList.add(list.get(i).getMonthlyAttendance().get("%早%")); // 早
            excelRowList.add(list.get(i).getMonthlyAttendance().get("%中%")); // 中
            excelRowList.add(list.get(i).getMonthlyAttendance().get("%夜%")); // 夜
            excelRowList.add(list.get(i).getMonthlyAttendance().get("%差%")); // 差
            for (Map<String, Object> o : list.get(i).getList()) {
                String enumLabel = "";
                for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                    if (personalAttendanceLocationConfig.getShift().equals(o.get("shift"))) {
                        enumLabel = personalAttendanceLocationConfig.getShift();
                    }
                }
                excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel);
            }
            data.add(excelRowList);
        }
        return data;
    }
 
}