From 0100359605ba05638c1f683d68a2948cc273b0d2 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期一, 08 十二月 2025 11:21:29 +0800
Subject: [PATCH] yys 修改设备模块
---
src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java | 136 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 131 insertions(+), 5 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 707063b..c771b47 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
@@ -5,31 +5,44 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
import com.ruoyi.device.pojo.DeviceRepair;
+import com.ruoyi.device.service.DeviceDefectRecordService;
+import com.ruoyi.device.service.IDeviceLedgerService;
import com.ruoyi.device.service.IDeviceRepairService;
import com.ruoyi.framework.web.domain.AjaxResult;
import lombok.AllArgsConstructor;
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
@Slf4j
public class DeviceRepairServiceImpl extends ServiceImpl<DeviceRepairMapper, DeviceRepair> implements IDeviceRepairService {
-
+ @Autowired
+ private DeviceDefectRecordService deviceDefectRecordService;
@Autowired
private DeviceRepairMapper deviceRepairMapper;
-
+ @Autowired
+ private IDeviceLedgerService deviceLedgerService;
@Override
public IPage<DeviceRepairDto> queryPage(Page page, DeviceRepairDto deviceRepairDto) {
@@ -38,6 +51,9 @@
@Override
public AjaxResult saveDeviceRepair(DeviceRepair deviceRepair) {
+ DeviceLedger byId = deviceLedgerService.getById(deviceRepair.getDeviceLedgerId());
+ deviceRepair.setDeviceName(byId.getDeviceName());
+ deviceRepair.setDeviceModel(byId.getDeviceModel());
boolean save = this.save(deviceRepair);
if (save){
return AjaxResult.success();
@@ -48,6 +64,18 @@
@Override
public AjaxResult updateDeviceRepair(DeviceRepair deviceRepair) {
if (this.updateById(deviceRepair)) {
+ Long id = deviceRepair.getId();
+ //
+ DeviceDefectRecordDto deviceDefectRecordDto = new DeviceDefectRecordDto();
+ deviceDefectRecordDto.setDeviceLedgerId(id);
+ deviceDefectRecordDto.setStatus("涓ラ噸缂洪櫡");
+ List<DeviceDefectRecordDto> records = deviceDefectRecordService.listPage(new Page<>(1, -1), deviceDefectRecordDto).getRecords();
+ if (!records.isEmpty()){
+ records.forEach(deviceDefectRecord -> {
+ deviceDefectRecord.setStatus("姝e父");
+ deviceDefectRecordService.updateByDDR(deviceDefectRecord);
+ });
+ }
return AjaxResult.success();
}
return AjaxResult.error();
@@ -87,4 +115,102 @@
}
+ @Override
+ public DeviceRepairDto detailById(Long id) {
+
+ 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