From 79841a6a5ecd713a9f02d23552619cbba1c991ad Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期五, 06 三月 2026 17:42:40 +0800
Subject: [PATCH] fix:班次页面问题修复

---
 performance-server/src/main/java/com/ruoyi/performance/service/impl/PerformanceShiftServiceImpl.java |  258 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 150 insertions(+), 108 deletions(-)

diff --git a/performance-server/src/main/java/com/ruoyi/performance/service/impl/PerformanceShiftServiceImpl.java b/performance-server/src/main/java/com/ruoyi/performance/service/impl/PerformanceShiftServiceImpl.java
index 966317f..80f0230 100644
--- a/performance-server/src/main/java/com/ruoyi/performance/service/impl/PerformanceShiftServiceImpl.java
+++ b/performance-server/src/main/java/com/ruoyi/performance/service/impl/PerformanceShiftServiceImpl.java
@@ -10,6 +10,7 @@
 import com.ruoyi.common.core.domain.entity.User;
 import com.ruoyi.common.utils.JackSonUtil;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.performance.dto.PerformanceShiftAddDto;
 import com.ruoyi.performance.dto.PerformanceShiftMapDto;
 import com.ruoyi.performance.mapper.PerformanceShiftMapper;
@@ -20,6 +21,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
 import java.math.BigDecimal;
@@ -30,6 +32,8 @@
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -48,6 +52,10 @@
     @Autowired
     UserMapper userMapper;
 
+    private DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+    private DateTimeFormatter yyyyMMddHHmmss = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) {
@@ -55,9 +63,7 @@
         LocalDateTime startWeek = performanceShiftAddDto.getStartWeek();
         LocalDateTime endWeek = performanceShiftAddDto.getEndWeek();
 
-
-        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-        String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter);
+        String formattedDateTime = performanceShiftAddDto.getStartWeek().format(yyyyMMdd);
         String[] splitUserId = performanceShiftAddDto.getUserId().split(",");
         for (String userId : splitUserId) {
             //鍒ゆ柇鏄惁璺ㄦ湀
@@ -104,7 +110,7 @@
                 performanceShift.setShift(performanceShiftAddDto.getShift());
                 performanceShift.setUserId(Integer.valueOf(s));
                 performanceShift.setWorkTime(date);
-                String formatterDateTime = date.format(formatter);
+                String formatterDateTime = date.format(yyyyMMdd);
                 baseMapper.update(new PerformanceShift(), Wrappers.<PerformanceShift>lambdaUpdate()
                         .set(PerformanceShift::getShift, performanceShiftAddDto.getShift())
                         .eq(PerformanceShift::getUserId, s)
@@ -113,7 +119,7 @@
         }
     }
 
-    private List<PerformanceShift>   saveMonth (LocalDateTime week,String userId,List<PerformanceShift> list){
+    private List<PerformanceShift> saveMonth (LocalDateTime week,String userId,List<PerformanceShift> list){
         LocalDate firstDayOfMonth = week.toLocalDate().withDayOfMonth(1);
         LocalDate lastDayOfMonth = week.toLocalDate().with(TemporalAdjusters.lastDayOfMonth());
         List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay());
@@ -132,14 +138,14 @@
     }
 
     @Override
-    public Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) {
+    public Map<String, Object> performanceShift( String time, String userName, String laboratory) {
         //鏌ヨ褰撳墠鐧诲綍浜哄憳鐨勬灦鏋�
         Integer userId = SecurityUtils.getUserId().intValue();
         //鍒ゆ柇鍏ㄩ儴,涓汉,缁勭粐鐨勬潈闄�
         User user = userMapper.selectById(userId);//褰撳墠鐧诲綍鐨勪汉
         //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id
         String departLimsId = user.getDepartLimsId();
-        if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
+        if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.isEmpty()) {
             String[] split = departLimsId.split(",");
             //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙)
             String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1]));
@@ -147,96 +153,97 @@
                 laboratory = departLims;
             }
         }
-        IPage<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftPage(page, time, userName, laboratory);
+//        List<SysDictData> shiftType = dictTypeService.selectDictDataByName("鐝绫诲瀷");
+        //鐝鏃堕棿鑼冨洿涓轰笂涓湀鐨�26鍙峰埌鏈湀鐨�25鍙�
+        LocalDateTime localDateTime = LocalDateTime.parse(time, yyyyMMddHHmmss);
+        LocalDate firstDayOfMonth = localDateTime.toLocalDate().minusMonths(1L).withDayOfMonth(26);
+        LocalDate lastDayOfMonth = localDateTime.toLocalDate().withDayOfMonth(25);
+        //浜哄憳鎺掔彮璇︽儏
+        List<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShift(firstDayOfMonth,lastDayOfMonth, userName, laboratory);
+        Map<Integer, List<PerformanceShiftMapDto>> groupByUserId = mapIPage.stream().collect(Collectors.groupingBy(PerformanceShiftMapDto::getUserId));
+        List<PerformanceShiftMapDto> newRecords = new ArrayList<>();
+        groupByUserId.keySet().forEach(key->{
+            PerformanceShiftMapDto shiftMapDto = new PerformanceShiftMapDto();
+            List<PerformanceShiftMapDto> shiftMapDtos = groupByUserId.get(key);
+            //缁熻鍚勭彮娆″ぉ鏁�
+            countShift(shiftMapDto.getMonthlyAttendance(),shiftMapDtos);
+            shiftMapDto.setList(shiftMapDtos);
 
-        List<SysDictData> shiftType = dictTypeService.selectDictDataByName("鐝绫诲瀷");
-        List<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYearPage(time, userName, laboratory);
-        mapIPage.getRecords().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("锛�");
-                for (SysDictData enums : shiftType) {
-                    if (!i.getMonthlyAttendance().containsKey(enums.getDictLabel())) {
-                        i.getMonthlyAttendance().put(enums.getDictLabel(), 0);
-                    }
-                    if (enums.getDictValue().equals(shiftTimeAndShift[1])) {
-                        BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(enums.getDictLabel()).toString());
-                        i.getMonthlyAttendance().put(enums.getDictLabel(), bigDecimal.add(new BigDecimal("1")));
-                    }
-                    // 鍗婏紝鍙﹀鍗婂ぉ绠楃粰鏃�
-                    if (shiftTimeAndShift[1].equals("5") && enums.getDictValue().equals("0")) {
-                        BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(enums.getDictLabel()).toString());
-                        i.getMonthlyAttendance().put(enums.getDictLabel(), bigDecimal.add(new BigDecimal("0.5")));
-                    }
-                }
-                // 鏃╋紝涓紝澶滐紝宸�
-                if (shiftTimeAndShift[1].equals("1") || shiftTimeAndShift[1].equals("2") || shiftTimeAndShift[1].equals("0") || shiftTimeAndShift[1].equals("6")) {
-                    i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1);
-                }
-                // 鍗�
-                if (shiftTimeAndShift[1].equals("5")) {
-                    i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 0.5);
-                }
-                hashMap.put("id", shiftTimeAndShift[2]);
-                hashMap.put("shift", shiftTimeAndShift[1]);
-                hashMap.put("time", shiftTimeAndShift[0]);
-                map.add(hashMap);
-            }
-            double totalYearAttendance = 0;
-            Map<String, Object> hashMap = new HashMap<>();
-            for (Map<String, Object> record : mapYearIPage) {
-                if (record.get("user_id").toString().equals(i.getUserId())) {
-                    for (SysDictData enums : shiftType) {
-                        if (!hashMap.containsKey(enums.getDictLabel())) {
-                            hashMap.put(enums.getDictLabel(), 0);
-                        }
-                        if (enums.getDictValue().equals(record.get("shift"))) {
-                            BigDecimal num = new BigDecimal(hashMap.get(enums.getDictLabel()).toString());
-                            hashMap.put(enums.getDictLabel(), num.add(new BigDecimal("1")));
-                        }
-                        // 鍗婏紝鍙﹀鍗婂ぉ绠楃粰鏃�
-                        if (record.get("shift").equals("5") && enums.getDictValue().equals("0")) {
-                            BigDecimal bigDecimal = new BigDecimal(hashMap.get(enums.getDictLabel()).toString());
-                            hashMap.put(enums.getDictLabel(), bigDecimal.add(new BigDecimal("0.5")));
-                        }
-                    }
-                    if (record.get("shift").equals("1") || record.get("shift").equals("2") || record.get("shift").equals("0") || record.get("shift").equals("6")) {
-                        hashMap.put("totalAttendance", totalYearAttendance += 1);
-                    }
-                    // 鍗�
-                    if (record.get("shift").equals("5")) {
-                        hashMap.put("totalAttendance", totalYearAttendance += 0.5);
-                    }
-                }
-            }
-            i.setSidebarAnnualAttendance(hashMap);
-            i.setList(map);
-            i.setShiftTime(null);
+            shiftMapDto.setUserName(shiftMapDtos.isEmpty()?"":shiftMapDtos.get(0).getUserName());
+            shiftMapDto.setUserId(key);
+            newRecords.add(shiftMapDto);
         });
-        // 鑾峰彇header鏃堕棿
-        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-        // 灏嗗瓧绗︿覆鏃堕棿杞崲涓� LocalDateTime 绫诲瀷鏃堕棿
-        LocalDateTime localDateTime = LocalDateTime.parse(time, formatters);
-        LocalDate firstDayOfMonth = localDateTime.toLocalDate().withDayOfMonth(1);
-        LocalDate lastDayOfMonth = localDateTime.toLocalDate().with(TemporalAdjusters.lastDayOfMonth());
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("page", newRecords);
+        resultMap.put("headerList", getYearHeaderTimeList(firstDayOfMonth,lastDayOfMonth));
+        return resultMap;
+    }
+
+    /**
+     * 缁熻鐝
+     * @param targetMap  缁撴灉瀵硅薄
+     * @param shiftMapDtos 鐝鍒楄〃
+     */
+    private void countShift(Map<String,Object> targetMap,List<PerformanceShiftMapDto> shiftMapDtos){
+        //姹囨�绘棭鐝�佷腑鐝�佸鐝�佷紤鎭�佽鍋囥�佸嚭宸殑澶╂暟锛屼互鍙婃�诲嚭鍕ゅぉ鏁�
+        Map<String, List<PerformanceShiftMapDto>> groupByShift = shiftMapDtos.stream().collect(Collectors.groupingBy(PerformanceShift::getShift));
+        AtomicInteger morningShift = new AtomicInteger(0);//鏃╃彮
+        AtomicInteger swingShift = new AtomicInteger(0);//涓彮
+        AtomicInteger nightShift = new AtomicInteger(0);//鏅氱彮
+        AtomicInteger holidayShift = new AtomicInteger(0);//浼�
+        AtomicInteger leaveShift = new AtomicInteger(0);//璇峰亣
+        groupByShift.keySet().forEach(shiftKey->{
+            switch (shiftKey){
+                case "0"://鏃�12
+                case "2"://鏃╃彮8
+                case "6"://鏃�10
+                    morningShift.addAndGet(groupByShift.get(shiftKey).size());
+                    break;
+                case "3"://涓彮8
+                    swingShift.addAndGet(groupByShift.get(shiftKey).size());
+                    break;
+                case "1"://澶�12
+                case "4"://澶滅彮8
+                    nightShift.addAndGet(groupByShift.get(shiftKey).size());
+                    break;
+                case "5"://浼�
+                    holidayShift.addAndGet(groupByShift.get(shiftKey).size());
+                    break;
+                case "7"://浜�
+                case "8"://鐥�
+                case "9"://骞�
+                case "10"://濠�
+                case "11"://璋冧紤
+                case "12"://浜�
+                case "13"://涓�
+                    leaveShift.addAndGet(groupByShift.get(shiftKey).size());
+                    break;
+            }
+        });
+        targetMap.put("morningShift",morningShift.get());
+        targetMap.put("swingShift",swingShift.get());
+        targetMap.put("nightShift",nightShift.get());
+        targetMap.put("holidayShift",holidayShift.get());
+        targetMap.put("leaveShift",leaveShift.get());
+    }
+
+    /**
+     * 鐝鍒嗛〉鏌ヨ锛氳幏鍙栨湀搴︽棩鏈熻〃澶村垪琛�
+     * @param firstDayOfMonth
+     * @param lastDayOfMonth
+     * @return
+     */
+    private List<Object> getYearHeaderTimeList(LocalDate firstDayOfMonth,LocalDate lastDayOfMonth){
         List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay());
-        List<Object> list1 = new ArrayList<>();
+        List<Object> list = new ArrayList<>();
         for (LocalDateTime dateTime : localDateTimesBetween) {
             Map<Object, Object> hashMap = new HashMap<>();
-            DateTime parse = DateUtil.parse(dateTime.format(formatter));
+            DateTime parse = DateUtil.parse(dateTime.format(yyyyMMdd));
             hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1)));
-            hashMap.put("headerTime", getWeek(dateTime.format(formatters)));
-            list1.add(hashMap);
+            hashMap.put("headerTime", getWeek(dateTime.format(yyyyMMddHHmmss)));
+            list.add(hashMap);
         }
-        Map<String, Object> resultMap = new HashMap<>();
-        resultMap.put("page", mapIPage);
-        resultMap.put("headerList", list1);
-        return resultMap;
+        return list;
     }
 
     @Override
@@ -247,14 +254,14 @@
     }
 
     @Override
-    public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, String laboratory) {
+    public List<Map<String, Object>> performanceShiftPageYear(String time, String userName, String laboratory) {
         //鏌ヨ褰撳墠鐧诲綍浜哄憳鐨勬灦鏋�
         Integer userId = SecurityUtils.getUserId().intValue();
         //鍒ゆ柇鍏ㄩ儴,涓汉,缁勭粐鐨勬潈闄�
         User user = userMapper.selectById(userId);//褰撳墠鐧诲綍鐨勪汉
         //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id
         String departLimsId = user.getDepartLimsId();
-        if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
+        if (StringUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
             String[] split = departLimsId.split(",");
             //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙)
             String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1]));
@@ -262,10 +269,39 @@
                 laboratory = departLims;
             }
         }
-        IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, laboratory);
-        List<SysDictData> shiftType = dictTypeService.selectDictDataByName("鐝绫诲瀷");
-        mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), shiftType));
-        return mapYearIPage;
+//        List<SysDictData> shiftType = dictTypeService.selectDictDataByName("鐝绫诲瀷");
+        List<PerformanceShiftMapDto> shiftYearList = baseMapper.performanceShiftYear(time, userName, laboratory);
+        //鎸変汉鍛樺垎缁勶紝缁熻姣忎釜浜虹殑骞村害鐝
+        Map<Integer, List<PerformanceShiftMapDto>> groupByUserId = shiftYearList.stream().collect(Collectors.groupingBy(PerformanceShift::getUserId));
+        List<Map<String,Object>> returnList = new ArrayList<>();
+        groupByUserId.keySet().forEach(userIdKey->{
+            //鎸夋湀浠藉垎缁勶紝缁熻姣忎釜鏈堢殑鐝璇︽儏
+            Map<String, Object> returnMap = new HashMap<>();
+            List<PerformanceShiftMapDto> shiftMapDtos = groupByUserId.get(userIdKey);
+            Map<String, Object> sidebarAnnualAttendance = new HashMap<>();
+            countShift(sidebarAnnualAttendance,shiftMapDtos);//骞村害鐝缁熻
+            List<Map<String,Object>> monthlyAttendance = new ArrayList<>();
+            if(!shiftMapDtos.isEmpty()){
+                returnMap.put("userName",shiftMapDtos.get(0).getUserName());
+                returnMap.put("userId",shiftMapDtos.get(0).getUserId());
+                Map<Integer, List<PerformanceShiftMapDto>> groupByMonthNum = shiftMapDtos.stream().collect(Collectors.groupingBy(PerformanceShiftMapDto::getMonthNum));
+                //閬嶅巻12涓湀鐨勭彮娆′俊鎭�
+                for (int i = 1; i <= 12; i++) {
+                    List<PerformanceShiftMapDto> monthShiftDtos = groupByMonthNum.get(i);
+                    Map<String, Object> monthlyAttendanceMap = new HashMap<>();
+                    if(CollectionUtils.isEmpty(monthShiftDtos)){
+                        countShift(monthlyAttendanceMap,new ArrayList<>());//鏈堝害鐝缁熻
+                    }else{
+                        countShift(monthlyAttendanceMap,monthShiftDtos);//鏈堝害鐝缁熻
+                    }
+                    monthlyAttendance.add(monthlyAttendanceMap);
+                }
+                returnMap.put("monthlyAttendance",monthlyAttendance);
+                returnMap.put("sidebarAnnualAttendance",sidebarAnnualAttendance);
+            }
+            returnList.add(returnMap);
+        });
+        return returnList;
     }
 
     // 骞村垎椤典笌瀵煎嚭鍏卞悓浣跨敤
@@ -409,12 +445,13 @@
                 if (shiftTimeAndShift[1].equals("5")) {
                     i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 0.5);
                 }
-                hashMap.put("id", shiftTimeAndShift[2]);
+                hashMap.put("id", shiftTimeAndShift[3]);
                 hashMap.put("shift", shiftTimeAndShift[1]);
                 hashMap.put("time", shiftTimeAndShift[0]);
+                hashMap.put("annotationText", shiftTimeAndShift[2]);
                 map.add(hashMap);
             }
-            i.setList(map);
+//            i.setList(map);
             i.setShiftTime(null);
         });
         Map<Object, Object> map = new HashMap<>();
@@ -425,6 +462,11 @@
         List<List<Object>> lists = dataRequiredForProcessingIntoExcelMonth(mapIPage, shiftType);
         map.put("data", lists);
         return map;
+    }
+
+    @Override
+    public boolean editAnnotationText(PerformanceShift performanceShift) {
+        return this.updateById(performanceShift);
     }
 
     // 鑾峰彇涓や釜localDateTime鐨勬瘡涓�澶�
@@ -538,7 +580,7 @@
         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).getUserName());
             excelRowList.add(list.get(i).getDepartment());
             excelRowList.add(list.get(i).getMonthlyAttendance().get("totalAttendance"));
             excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(3).getDictLabel())); // 浼�
@@ -547,15 +589,15 @@
             excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(1).getDictLabel())); // 涓�
             excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(2).getDictLabel())); // 澶�
             excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(6).getDictLabel())); // 宸�
-            for (Map<String, Object> o : list.get(i).getList()) {
-                String enumLabel = "";
-                for (SysDictData anEnum : enums) {
-                    if (anEnum.getDictValue().equals(o.get("shift"))) {
-                        enumLabel = anEnum.getDictLabel();
-                    }
-                }
-                excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel);
-            }
+//            for (Map<String, Object> o : list.get(i).getList()) {
+//                String enumLabel = "";
+//                for (SysDictData anEnum : enums) {
+//                    if (anEnum.getDictValue().equals(o.get("shift"))) {
+//                        enumLabel = anEnum.getDictLabel();
+//                    }
+//                }
+//                excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel);
+//            }
             data.add(excelRowList);
         }
         return data;

--
Gitblit v1.9.3