From 723705c43f6e87e9f31e4c18eee1c163c14139bb Mon Sep 17 00:00:00 2001 From: Crunchy <3114200645@qq.com> Date: 星期五, 10 五月 2024 16:55:48 +0800 Subject: [PATCH] 2024-5-10 绩效管理-班次-文件导出 --- performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java | 42 ++++++++++++++++++++++++++++++------------ 1 files changed, 30 insertions(+), 12 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 b0f4c58..dde83c3 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 @@ -14,6 +14,7 @@ import com.yuanchu.mom.pojo.PerformanceShift; import com.yuanchu.mom.service.EnumService; import com.yuanchu.mom.service.PerformanceShiftService; +import com.yuanchu.mom.utils.JackSonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,7 +25,6 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAdjusters; import java.util.*; -import java.util.stream.Collectors; /** * <p> @@ -184,7 +184,7 @@ // 骞村垎椤典笌瀵煎嚭鍏卞悓浣跨敤 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> resultMap = new LinkedHashMap<>(); Map<String, Object> hashMapYear = new LinkedHashMap<>(); int totalYearAttendance = 0; // 涓�骞�12涓湀 @@ -234,17 +234,33 @@ 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); - }); + public List<List<Object>> dataRequiredForProcessingIntoExcel(List<Map<String, Object>> list, List<Enums> enums) 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")); + enums.forEach(j -> { + excelRowList.add(year.get(j.getLabel())); + }); + 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 (Enums anEnum : enums) { + excelRowList.add(month.get(j + "").get(anEnum.getLabel())); + } + } + data.add(excelRowList); + } + return data; } @Override - public Map<Object, Object> exportToExcel(String time, String userName, String laboratory) { + public Map<Object, Object> exportToExcel(String time, String userName, String laboratory) throws Exception { Map<Object, Object> map = new HashMap<>(); List<Enums> shiftType = enumService.selectEnumByCategory("鐝绫诲瀷"); DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -253,8 +269,8 @@ 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); + List<List<Object>> lists = dataRequiredForProcessingIntoExcel(mapYearList, shiftType); + map.put("data", lists); return map; } @@ -319,12 +335,14 @@ line.add(Arrays.asList("鑰冨嫟姹囨��", "搴忓彿", "搴忓彿")); line.add(Arrays.asList("鑰冨嫟姹囨��", "宸ュ彿", "宸ュ彿")); line.add(Arrays.asList("鑰冨嫟姹囨��", "濮撳悕", "濮撳悕")); + line.add(Arrays.asList("鍑哄嫟璇︽儏", month, "鍑哄嫟")); // 骞� header for (Enums anEnum : enums) { line.add(Arrays.asList("鑰冨嫟姹囨��", month, anEnum.getLabel())); } // 鏈坔eader for (int i = 1; i < 13; i++) { + line.add(Arrays.asList("鍑哄嫟璇︽儏", i + " 鏈�", "鍑哄嫟")); for (Enums anEnum : enums) { line.add(Arrays.asList("鍑哄嫟璇︽儏", i + " 鏈�", anEnum.getLabel())); } -- Gitblit v1.9.3