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/DeviceMaintenanceServiceImpl.java | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 101 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java b/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
index 011d32b..8cfe235 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
@@ -7,18 +7,24 @@
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
+import com.ruoyi.device.dto.DeviceMonthlyRepairTableDTO;
+import com.ruoyi.device.dto.RepairAmountGroupDTO;
import com.ruoyi.device.execl.DeviceMaintenanceExeclDto;
+import com.ruoyi.device.mapper.DeviceLedgerMapper;
import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
+import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.device.pojo.DeviceMaintenance;
import com.ruoyi.device.service.IDeviceMaintenanceService;
import com.ruoyi.framework.web.domain.AjaxResult;
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
@@ -73,4 +79,96 @@
return deviceMaintenanceMapper.detailById(id);
}
+
+ @Autowired
+ private DeviceLedgerMapper deviceLedgerMapper;
+
+ @Override
+ public List<DeviceMonthlyRepairTableDTO> getMonthlyRepairAmountByYear(String year) {
+ List<RepairAmountGroupDTO> repairAmountGroupDTOS = deviceMaintenanceMapper.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 = deviceMaintenanceMapper.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