From d74c28c6f826c9d9e61612b4bc589b0774feb82a Mon Sep 17 00:00:00 2001
From: Crunchy <3114200645@qq.com>
Date: 星期五, 10 五月 2024 13:30:09 +0800
Subject: [PATCH] 2024-5-9 绩效管理-班次后端开发调整年份完成

---
 performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java |  147 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 136 insertions(+), 11 deletions(-)

diff --git a/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java b/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java
index 0b49c0c..b0f4c58 100644
--- a/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java
+++ b/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java
@@ -3,6 +3,7 @@
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -23,6 +24,7 @@
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -91,7 +93,7 @@
     }
 
     @Override
-    public IPage<PerformanceShiftMapDto> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) {
+    public Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) {
         IPage<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftPage(page, time, userName, laboratory);
         List<Enums> shiftType = enumService.selectEnumByCategory("鐝绫诲瀷");
         List<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYearPage(time, userName, laboratory);
@@ -117,10 +119,7 @@
                 }
                 hashMap.put("id", shiftTimeAndShift[2]);
                 hashMap.put("shift", shiftTimeAndShift[1]);
-                DateTime parse = DateUtil.parse(shiftTimeAndShift[0]);
-                hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1)));
                 hashMap.put("time", shiftTimeAndShift[0]);
-                hashMap.put("headerTime", getWeek(shiftTimeAndShift[0]));
                 map.add(hashMap);
             }
             int totalYearAttendance = 0;
@@ -145,17 +144,118 @@
             i.setList(map);
             i.setShiftTime(null);
         });
-        return mapIPage;
+        // 鑾峰彇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());
+        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;
     }
 
     @Override
-    public void performanceShiftUpdate(String shift, Integer id) {
-        PerformanceShift performanceShift = new PerformanceShift();
-        performanceShift.setId(id);
-        performanceShift.setShift(shift);
+    public void performanceShiftUpdate(PerformanceShift performanceShift) {
         baseMapper.update(new PerformanceShift(), Wrappers.<PerformanceShift>lambdaUpdate()
-                .eq(PerformanceShift::getId, id)
-                .set(PerformanceShift::getShift, shift));
+                .eq(PerformanceShift::getId, performanceShift.getId())
+                .set(PerformanceShift::getShift, performanceShift.getShift()));
+    }
+
+    @Override
+    public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, String laboratory) {
+        IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, laboratory);
+        List<Enums> shiftType = enumService.selectEnumByCategory("鐝绫诲瀷");
+        mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), shiftType));
+        return mapYearIPage;
+    }
+
+    // 骞村垎椤典笌瀵煎嚭鍏卞悓浣跨敤
+    public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList, List<Enums> shiftType){
+        for (Map<String, Object> map : mapYearList) {
+            Map<String, Object> resultMap = new HashMap<>();
+            Map<String, Object> hashMapYear = new LinkedHashMap<>();
+            int totalYearAttendance = 0;
+            // 涓�骞�12涓湀
+            for (int i = 1; i < 13; i++) {
+                Map<String, Object> hashMapMonth = new LinkedHashMap<>();
+                int totalMonthAttendance = 0;
+                for (Enums enums : shiftType) {
+                    if (!hashMapYear.containsKey(enums.getLabel())) {
+                        hashMapYear.put(enums.getLabel(), 0);
+                    }
+                    // 鏈�
+                    if (ObjectUtils.isNotEmpty(map.get("month_str")) && map.get("work_time").equals(i)) {
+                        String charArray = map.get("month_str").toString();
+                        int count = countOccurrences(charArray, i + "锛�" + enums.getValue());
+                        hashMapMonth.put(enums.getLabel(), count);
+                        hashMapYear.put(enums.getLabel(), Integer.parseInt(hashMapYear.get(enums.getLabel()).toString()) + count );
+                        if (enums.getValue().equals("0") || enums.getValue().equals("1") || enums.getValue().equals("2")) {
+                            totalMonthAttendance += count;
+                            totalYearAttendance += count;
+                        }
+                    }
+                    // 绌烘暟鎹�
+                    else {
+                        map.put("work_time", i);
+                        hashMapMonth.put(enums.getLabel(), 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 void dataRequiredForProcessingIntoExcel(List<Map<String, Object>> list){
+        Map<Object, List<Map<String, Object>>> userId = list.stream().collect(Collectors.groupingBy(i -> i.get("user_id")));
+        userId.forEach((k, v) -> {
+            System.out.println(k);
+            System.out.println("=============");
+            System.out.println(v);
+        });
+    }
+
+    @Override
+    public Map<Object, Object> exportToExcel(String time, String userName, String laboratory) {
+        Map<Object, Object> map = new HashMap<>();
+        List<Enums> shiftType = enumService.selectEnumByCategory("鐝绫诲瀷");
+        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        // 灏嗗瓧绗︿覆鏃堕棿杞崲涓� LocalDateTime 绫诲瀷鏃堕棿
+        LocalDateTime localDateTime = LocalDateTime.parse(time, formatters);
+        map.put("header", getHeader(localDateTime.getYear() + " 骞�", shiftType));
+        List<Map<String, Object>> mapYearList = baseMapper.performanceShiftYearList(time, userName, laboratory);
+        annualAttendanceProcessing(mapYearList, shiftType);
+        dataRequiredForProcessingIntoExcel(mapYearList);
+        map.put("data", mapYearList);
+        return map;
     }
 
     // 鑾峰彇涓や釜localDateTime鐨勬瘡涓�澶�
@@ -206,4 +306,29 @@
                 return "鏈煡";
         }
     }
+
+    /**
+     * 杩斿洖琛ㄥご
+     *
+     * 澶栧眰List浠h〃琛屽唴灞� List浠h〃鍒�  鐩稿悓鐨勫垪鏁版嵁浼氳涓诲姩鍚堝苟
+     * 鏋勯�犲弻鍒楄〃澶�
+     * @return List<List<String>>
+     */
+    private static List<List<String>> getHeader(String month, List<Enums> enums){
+        List<List<String>> line = new ArrayList<>();
+        line.add(Arrays.asList("鑰冨嫟姹囨��", "搴忓彿", "搴忓彿"));
+        line.add(Arrays.asList("鑰冨嫟姹囨��", "宸ュ彿", "宸ュ彿"));
+        line.add(Arrays.asList("鑰冨嫟姹囨��", "濮撳悕", "濮撳悕"));
+        // 骞� header
+        for (Enums anEnum : enums) {
+            line.add(Arrays.asList("鑰冨嫟姹囨��", month, anEnum.getLabel()));
+        }
+        // 鏈坔eader
+        for (int i = 1; i < 13; i++) {
+            for (Enums anEnum : enums) {
+                line.add(Arrays.asList("鍑哄嫟璇︽儏", i + " 鏈�", anEnum.getLabel()));
+            }
+        }
+        return line;
+    }
 }

--
Gitblit v1.9.3