From 72a372cb26c4ba489efae6b65dbf9fdfea1b5815 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期三, 19 十一月 2025 16:53:11 +0800
Subject: [PATCH] yys 1.劳保台账修改

---
 src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java b/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
index 1f09d07..c771b47 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
@@ -6,9 +6,12 @@
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.device.dto.DeviceDefectRecordDto;
+import com.ruoyi.device.dto.DeviceMonthlyRepairTableDTO;
 import com.ruoyi.device.dto.DeviceRepairDto;
+import com.ruoyi.device.dto.RepairAmountGroupDTO;
 import com.ruoyi.device.execl.DeviceRepairExeclDto;
 import com.ruoyi.device.mapper.DeviceDefectRecordMapper;
+import com.ruoyi.device.mapper.DeviceLedgerMapper;
 import com.ruoyi.device.mapper.DeviceRepairMapper;
 import com.ruoyi.device.pojo.DeviceDefectRecord;
 import com.ruoyi.device.pojo.DeviceLedger;
@@ -21,11 +24,13 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 @Service
 @AllArgsConstructor
@@ -116,4 +121,96 @@
         return deviceRepairMapper.detailById(id);
     }
 
+    @Autowired
+    private DeviceLedgerMapper deviceLedgerMapper;
+
+    @Override
+    public List<DeviceMonthlyRepairTableDTO> getMonthlyRepairAmountByYear(String year) {
+        List<RepairAmountGroupDTO> repairAmountGroupDTOS = deviceRepairMapper.groupByMonthAndDeviceLedger(year);
+        // 1. 鍏堥�氳繃璁惧鍙拌处id鍏宠仈璁惧鍚嶇О锛堝鏋淩epairAmountGroupDTO娌℃湁deviceName锛岄渶鍏堟煡璁惧鍙拌处琛級
+        // 杩欓噷鍋囪浣犺兘閫氳繃deviceLedgerId鑾峰彇鍒癲eviceName锛屾瘮濡傦細
+        Map<Long, String> deviceNameMap = new HashMap<>(); // key:deviceLedgerId, value:deviceName
+        // 锛堝疄闄呴渶璋冪敤璁惧鍙拌处鐨凪apper鏌ヨ锛歞eviceNameMap = deviceLedgerMapper.listAll().stream().collect(Collectors.toMap(DeviceLedger::getId, DeviceLedger::getDeviceName))锛�
+        deviceNameMap = deviceLedgerMapper.selectList(null)
+                .stream()
+                .collect(Collectors.toMap(DeviceLedger::getId, DeviceLedger::getDeviceName));
+        if(CollectionUtils.isEmpty(deviceNameMap)){
+            return Collections.emptyList();
+        }
+        // 2. 鎸夎澶囧悕绉板垎缁勶紝瀛樺偍姣忎釜璁惧鐨勫悇鏈堥噾棰�
+        Map<String, DeviceMonthlyRepairTableDTO> deviceTableMap = new HashMap<>();
+
+        for (RepairAmountGroupDTO dto : repairAmountGroupDTOS) {
+            // 鎷嗗垎repairYearMonth涓烘湀浠斤紙濡�"2025-01" 鈫� "01" 鈫� 1锛�
+            String yearMonth = dto.getRepairYearMonth(); // 鏍煎紡锛歽yyy-MM
+            int month = Integer.parseInt(yearMonth); // 鎻愬彇MM骞惰浆鎴愭暟瀛楋紙1-12锛�
+
+            // 鑾峰彇璁惧鍚嶇О
+            String deviceName = deviceNameMap.get(dto.getDeviceLedgerId());
+            if (deviceName == null) {
+                deviceName = "鏈煡璁惧"; // 鍏滃簳
+            }
+
+            // 浠嶮ap涓幏鍙栬璁惧鐨勮〃鏍糄TO锛屼笉瀛樺湪鍒欏垵濮嬪寲
+            DeviceMonthlyRepairTableDTO tableDTO = deviceTableMap.getOrDefault(deviceName, new DeviceMonthlyRepairTableDTO());
+            tableDTO.setDeviceName(deviceName);
+
+            // 鏍规嵁鏈堜唤濉厖閲戦锛圔igDecimal榛樿0锛岄伩鍏峮ull锛�
+            BigDecimal amount = dto.getTotalRepairPrice() == null ? BigDecimal.ZERO : dto.getTotalRepairPrice();
+            switch (month) {
+                case 1: tableDTO.setMonth1(amount); break;
+                case 2: tableDTO.setMonth2(amount); break;
+                case 3: tableDTO.setMonth3(amount); break;
+                case 4: tableDTO.setMonth4(amount); break;
+                case 5: tableDTO.setMonth5(amount); break;
+                case 6: tableDTO.setMonth6(amount); break;
+                case 7: tableDTO.setMonth7(amount); break;
+                case 8: tableDTO.setMonth8(amount); break;
+                case 9: tableDTO.setMonth9(amount); break;
+                case 10: tableDTO.setMonth10(amount); break;
+                case 11: tableDTO.setMonth11(amount); break;
+                case 12: tableDTO.setMonth12(amount); break;
+            }
+
+            // 閲嶆柊鏀惧叆Map
+            deviceTableMap.put(deviceName, tableDTO);
+        }
+
+
+        // 3. 璁$畻姣忎釜璁惧鐨勬�昏锛屽苟琛ュ厖搴忓彿
+        List<DeviceMonthlyRepairTableDTO> resultList = new ArrayList<>();
+        for (DeviceMonthlyRepairTableDTO tableDTO : deviceTableMap.values()) {
+            // 璁$畻鎬昏锛�1-12鏈堥噾棰濈浉鍔�
+            BigDecimal total = Stream.of(
+                            tableDTO.getMonth1(), tableDTO.getMonth2(), tableDTO.getMonth3(),
+                            tableDTO.getMonth4(), tableDTO.getMonth5(), tableDTO.getMonth6(),
+                            tableDTO.getMonth7(), tableDTO.getMonth8(), tableDTO.getMonth9(),
+                            tableDTO.getMonth10(), tableDTO.getMonth11(), tableDTO.getMonth12()
+                    )
+                    .map(amt -> amt == null ? BigDecimal.ZERO : amt)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            tableDTO.setTotal(total);
+            resultList.add(tableDTO);
+        }
+        return resultList;
+    }
+
+    @Override
+    public List<RepairAmountGroupDTO> getRepairAmountByYear(String year) {
+        List<RepairAmountGroupDTO> repairAmountGroupDTOS = deviceRepairMapper.groupByDeviceLedger(year);
+        Map<Long, String> deviceNameMap = new HashMap<>(); // key:deviceLedgerId, value:deviceName
+        // 锛堝疄闄呴渶璋冪敤璁惧鍙拌处鐨凪apper鏌ヨ锛歞eviceNameMap = deviceLedgerMapper.listAll().stream().collect(Collectors.toMap(DeviceLedger::getId, DeviceLedger::getDeviceName))锛�
+        deviceNameMap = deviceLedgerMapper.selectList(null)
+                .stream()
+                .collect(Collectors.toMap(DeviceLedger::getId, DeviceLedger::getDeviceName));
+        if(CollectionUtils.isEmpty(deviceNameMap)){
+            return Collections.emptyList();
+        }
+        Map<Long, String> finalDeviceNameMap = deviceNameMap;
+        repairAmountGroupDTOS.forEach(dto -> {
+            dto.setDeviceName(finalDeviceNameMap.get(dto.getDeviceLedgerId()));
+        });
+        return repairAmountGroupDTOS;
+    }
+
 }

--
Gitblit v1.9.3