From 46944d762174e5b7e7a627c59928e2a3c9e03dd4 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期六, 30 五月 2026 15:23:11 +0800
Subject: [PATCH] feat(quality): 增加检验管理功能并完善库存预警

---
 src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java |  113 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 98 insertions(+), 15 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..803450a 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
@@ -4,30 +4,46 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.enums.RecordTypeEnum;
+import com.ruoyi.basic.utils.FileUtil;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.device.dto.DeviceMaintenanceDto;
 import com.ruoyi.device.execl.DeviceMaintenanceExeclDto;
 import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
+import com.ruoyi.device.pojo.DeviceLedger;
 import com.ruoyi.device.pojo.DeviceMaintenance;
+import com.ruoyi.device.service.IDeviceLedgerService;
 import com.ruoyi.device.service.IDeviceMaintenanceService;
+import com.ruoyi.device.vo.DeviceMaintenanceVo;
+import com.ruoyi.device.vo.DeviceRepairVo;
 import com.ruoyi.framework.web.domain.AjaxResult;
-import org.springframework.beans.factory.annotation.Autowired;
+import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper;
+import com.ruoyi.project.system.service.ISysNoticeService;
+import com.ruoyi.measuringinstrumentledger.pojo.SpareParts;
+import com.ruoyi.measuringinstrumentledger.pojo.SparePartsRequisitionRecord;
+import com.ruoyi.measuringinstrumentledger.service.SparePartsRequisitionRecordService;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 
 @Service
+@RequiredArgsConstructor
 public class DeviceMaintenanceServiceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements IDeviceMaintenanceService {
 
-
-
-    @Autowired
-    private DeviceMaintenanceMapper deviceMaintenanceMapper;
+    private final DeviceMaintenanceMapper deviceMaintenanceMapper;
+    private final IDeviceLedgerService deviceLedgerService;
+    private final SparePartsMapper sparePartsMapper;
+    private final SparePartsRequisitionRecordService sparePartsRequisitionRecordService;
+    private final FileUtil fileUtil;
+    private final ISysNoticeService sysNoticeService;
 
     @Override
     public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) {
@@ -36,17 +52,84 @@
     }
 
     @Override
-    public AjaxResult saveDeviceRepair(DeviceMaintenance deviceMaintenance) {
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult saveDeviceRepair(DeviceMaintenanceDto deviceMaintenance) {
+        DeviceLedger byId = deviceLedgerService.getById(deviceMaintenance.getDeviceLedgerId());
+        if (byId != null) {
+            deviceMaintenance.setDeviceName(byId.getDeviceName());
+            deviceMaintenance.setDeviceModel(byId.getDeviceModel());
+            deviceMaintenance.setAreaId(byId.getAreaId());
+        }
         boolean save = this.save(deviceMaintenance);
         if (save){
+            // 澶勭悊鍥剧墖涓婁紶
+            fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs());
             return AjaxResult.success();
         }
         return AjaxResult.error();
     }
 
     @Override
-    public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenance deviceMaintenance) {
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenanceDto deviceMaintenance) {
+        DeviceMaintenance oldDeviceMaintenance = this.getById(deviceMaintenance.getId());
+        Long effectiveDeviceLedgerId = deviceMaintenance.getDeviceLedgerId() != null
+                ? deviceMaintenance.getDeviceLedgerId()
+                : oldDeviceMaintenance.getDeviceLedgerId();
+        DeviceLedger byId = deviceLedgerService.getById(effectiveDeviceLedgerId);
+        if (byId != null) {
+            deviceMaintenance.setDeviceName(byId.getDeviceName());
+            deviceMaintenance.setDeviceModel(byId.getDeviceModel());
+            deviceMaintenance.setAreaId(byId.getAreaId());
+        }
+        // 澶勭悊澶囦欢浣跨敤鎯呭喌
+        if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(deviceMaintenance.getSparePartsUseList())) {
+            List<Long> sparePartIds = new ArrayList<>();
+            for (DeviceMaintenance.SparePartUse sparePartUse : deviceMaintenance.getSparePartsUseList()) {
+                // 鑾峰彇澶囦欢淇℃伅
+                SpareParts spareParts = sparePartsMapper.selectById(sparePartUse.getId());
+                if (spareParts != null) {
+                    // 妫�鏌ユ暟閲忔槸鍚﹁冻澶�
+                    if (spareParts.getQuantity().compareTo(new BigDecimal(sparePartUse.getQuantity())) >= 0) {
+                        // 鏇存柊鏁伴噺
+                        spareParts.setQuantity(spareParts.getQuantity().subtract(new BigDecimal(sparePartUse.getQuantity())));
+                        sparePartsMapper.updateById(spareParts);
+                        sparePartIds.add(sparePartUse.getId());
+
+                        // 搴撳瓨棰勮閫氱煡
+                        if (spareParts.getWarnNum() != null && spareParts.getNotifyPersonId() != null
+                                && spareParts.getQuantity().compareTo(spareParts.getWarnNum()) < 0) {
+                            sysNoticeService.simpleNoticeByUser(
+                                    "澶囦欢搴撳瓨棰勮",
+                                    "澶囦欢銆�" + spareParts.getName() + "銆戝綋鍓嶅簱瀛�(" + spareParts.getQuantity()
+                                            + ")宸蹭綆浜庨璀︽暟閲�(" + spareParts.getWarnNum() + ")锛岃鍙婃椂閲囪喘琛ュ厖銆�",
+                                    List.of(spareParts.getNotifyPersonId()),
+                                    "/equipmentManagement/spareParts"
+                                    );
+                        }
+
+                        // 鍒涘缓澶囦欢棰嗙敤璁板綍
+                        SparePartsRequisitionRecord record = new SparePartsRequisitionRecord();
+                        record.setSourceType(1); // 1 淇濆吇
+                        record.setSourceId(deviceMaintenance.getId());
+                        record.setDeviceLedgerId(oldDeviceMaintenance.getDeviceLedgerId());
+                        record.setSparePartsId(sparePartUse.getId());
+                        record.setQuantity(sparePartUse.getQuantity());
+                        sparePartsRequisitionRecordService.save(record);
+                    } else {
+                        return AjaxResult.error("澶囦欢 " + spareParts.getName() + " 鏁伴噺涓嶈冻");
+                    }
+                }
+            }
+            // 鏇存柊澶囦欢IDs瀛楁
+            if (!sparePartIds.isEmpty()) {
+                deviceMaintenance.setSparePartsIds(StringUtils.join(sparePartIds, ","));
+            }
+        }
+
         if (this.updateById(deviceMaintenance)) {
+            // 澶勭悊鍥剧墖涓婁紶
+            fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs());
             return AjaxResult.success();
         }
         return AjaxResult.error();
@@ -59,9 +142,8 @@
         supplierManageList.forEach(deviceMaintenance -> {
             DeviceMaintenanceExeclDto deviceRepairExeclDto = new DeviceMaintenanceExeclDto();
             BeanUtils.copyProperties(deviceMaintenance,deviceRepairExeclDto);
-            deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "寰呯淮淇�" : "瀹岀粨");
-            deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() != null && deviceMaintenance.getMaintenanceResult() == 0 ? "缁翠慨" : "瀹屽ソ");
-
+            deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "寰呯淮淇�" : deviceMaintenance.getStatus() == 1 ? "瀹岀粨" : "澶辫触");
+//            deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() != null && deviceMaintenance.getMaintenanceResult() == 0 ? "缁翠慨" : "瀹屽ソ");
             deviceLedgerExeclDtos.add(deviceRepairExeclDto);
         });
         ExcelUtil<DeviceMaintenanceExeclDto> util = new ExcelUtil<DeviceMaintenanceExeclDto>(DeviceMaintenanceExeclDto.class);
@@ -69,8 +151,9 @@
     }
 
     @Override
-    public DeviceMaintenanceDto detailById(Long id) {
-
-        return deviceMaintenanceMapper.detailById(id);
+    public DeviceMaintenanceVo detailById(Long id) {
+        DeviceMaintenanceVo vo = deviceMaintenanceMapper.detailById(id);
+        vo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum.DEVICE_MAINTENANCE, id));
+        return vo;
     }
 }

--
Gitblit v1.9.3