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/DeviceRepairServiceImpl.java |   70 +++++++++++++++++++++++-----------
 1 files changed, 47 insertions(+), 23 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 98f0d27..997b4a8 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceRepairServiceImpl.java
@@ -18,14 +18,16 @@
 import com.ruoyi.device.service.IDeviceLedgerService;
 import com.ruoyi.device.service.IDeviceRepairService;
 import com.ruoyi.device.vo.DeviceRepairVo;
-import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.framework.web.domain.AjaxResult;
 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 lombok.extern.slf4j.Slf4j;
+import org.apache.commons.compress.utils.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -46,6 +48,7 @@
     private final SparePartsMapper sparePartsMapper;
     private final SparePartsRequisitionRecordService sparePartsRequisitionRecordService;
     private final FileUtil fileUtil;
+    private final ISysNoticeService sysNoticeService;
 
     private static final int STATUS_PENDING_REPAIR = 0;
     private static final int STATUS_COMPLETED = 1;
@@ -63,10 +66,11 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R<?> saveDeviceRepair(DeviceRepairDto deviceRepairDto) {
+    public AjaxResult saveDeviceRepair(DeviceRepairDto deviceRepairDto) {
         DeviceLedger byId = deviceLedgerService.getById(deviceRepairDto.getDeviceLedgerId());
         deviceRepairDto.setDeviceName(byId.getDeviceName());
         deviceRepairDto.setDeviceModel(byId.getDeviceModel());
+        deviceRepairDto.setAreaId(byId.getAreaId());
         if (deviceRepairDto.getStatus() == null) {
             deviceRepairDto.setStatus(STATUS_PENDING_REPAIR);
         }
@@ -74,23 +78,32 @@
         if (save) {
             // 澶勭悊鍥剧墖涓婁紶
             fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_REPAIR, deviceRepairDto.getId(), deviceRepairDto.getStorageBlobDTOs());
-            return R.ok();
+            return AjaxResult.success();
         }
-        return R.fail("淇濆瓨澶辫触");
+        return AjaxResult.error("淇濆瓨澶辫触");
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R<?> updateDeviceRepair(DeviceRepairDto deviceRepairDto) {
+    public AjaxResult updateDeviceRepair(DeviceRepairDto deviceRepairDto) {
         DeviceRepair oldDeviceRepair = this.getById(deviceRepairDto.getId());
         if (oldDeviceRepair == null) {
-            return R.fail("鎶ヤ慨璁板綍涓嶅瓨鍦�");
+            return AjaxResult.error("鎶ヤ慨璁板綍涓嶅瓨鍦�");
+        }
+        Long effectiveDeviceLedgerId = deviceRepairDto.getDeviceLedgerId() != null
+                ? deviceRepairDto.getDeviceLedgerId()
+                : oldDeviceRepair.getDeviceLedgerId();
+        DeviceLedger byId = deviceLedgerService.getById(effectiveDeviceLedgerId);
+        if (byId != null) {
+            deviceRepairDto.setDeviceName(byId.getDeviceName());
+            deviceRepairDto.setDeviceModel(byId.getDeviceModel());
+            deviceRepairDto.setAreaId(byId.getAreaId());
         }
         if (deviceRepairDto.getStatus() != null
                 && deviceRepairDto.getStatus() == STATUS_COMPLETED
                 && (oldDeviceRepair.getStatus() == null
                 || oldDeviceRepair.getStatus() != STATUS_COMPLETED)) {
-            return R.fail("璇峰厛鎻愪氦楠屾敹瀹℃壒锛岄獙鏀堕�氳繃鍚庢墠鍙畬缁�");
+            return AjaxResult.error("璇峰厛鎻愪氦楠屾敹瀹℃壒锛岄獙鏀堕�氳繃鍚庢墠鍙畬缁�");
         }
         // 澶勭悊澶囦欢浣跨敤鎯呭喌
         if (CollectionUtils.isNotEmpty(deviceRepairDto.getSparePartsUseList())) {
@@ -106,6 +119,17 @@
                         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(0); // 0 缁翠慨
@@ -115,7 +139,7 @@
                         record.setQuantity(sparePartUse.getQuantity());
                         sparePartsRequisitionRecordService.save(record);
                     } else {
-                        return R.fail("澶囦欢 " + spareParts.getName() + " 鏁伴噺涓嶈冻");
+                        return AjaxResult.error("澶囦欢 " + spareParts.getName() + " 鏁伴噺涓嶈冻");
                     }
                 }
             }
@@ -142,23 +166,23 @@
             if (deviceRepairDto.getStorageBlobDTOs() != null) {
                 fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_REPAIR, id, deviceRepairDto.getStorageBlobDTOs());
             }
-            return R.ok();
+            return AjaxResult.success();
         }
-        return R.fail();
+        return AjaxResult.error();
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R<?> confirmRepair(DeviceRepairDto deviceRepairDto) {
+    public AjaxResult confirmRepair(DeviceRepairDto deviceRepairDto) {
         DeviceRepair oldDeviceRepair = this.getById(deviceRepairDto.getId());
         if (oldDeviceRepair == null) {
-            return R.fail("鎶ヤ慨璁板綍涓嶅瓨鍦�");
+            return AjaxResult.error("鎶ヤ慨璁板綍涓嶅瓨鍦�");
         }
         if (oldDeviceRepair.getStatus() != null && oldDeviceRepair.getStatus() == STATUS_COMPLETED) {
-            return R.fail("璇ユ姤淇凡瀹岀粨锛屼笉鑳介噸澶嶇‘璁ょ淮淇�");
+            return AjaxResult.error("璇ユ姤淇凡瀹岀粨锛屼笉鑳介噸澶嶇‘璁ょ淮淇�");
         }
         if (oldDeviceRepair.getStatus() != null && oldDeviceRepair.getStatus() == STATUS_PENDING_ACCEPTANCE) {
-            return R.fail("璇ユ姤淇凡鎻愪氦楠屾敹瀹℃壒");
+            return AjaxResult.error("璇ユ姤淇凡鎻愪氦楠屾敹瀹℃壒");
         }
         deviceRepairDto.setStatus(STATUS_PENDING_ACCEPTANCE);
         return updateDeviceRepair(deviceRepairDto);
@@ -166,25 +190,25 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R<?> approveRepairAcceptance(DeviceRepairDto deviceRepairDto) {
+    public AjaxResult approveRepairAcceptance(DeviceRepairDto deviceRepairDto) {
         if (deviceRepairDto.getId() == null) {
-            return R.fail("鎶ヤ慨璁板綍id涓嶈兘涓虹┖");
+            return AjaxResult.error("鎶ヤ慨璁板綍id涓嶈兘涓虹┖");
         }
         DeviceRepair oldDeviceRepair = this.getById(deviceRepairDto.getId());
         if (oldDeviceRepair == null) {
-            return R.fail("鎶ヤ慨璁板綍涓嶅瓨鍦�");
+            return AjaxResult.error("鎶ヤ慨璁板綍涓嶅瓨鍦�");
         }
         if (oldDeviceRepair.getStatus() == null || oldDeviceRepair.getStatus() != STATUS_PENDING_ACCEPTANCE) {
-            return R.fail("璇ユ姤淇湭杩涘叆寰呴獙鏀剁姸鎬侊紝涓嶈兘瀹℃壒");
+            return AjaxResult.error("璇ユ姤淇湭杩涘叆寰呴獙鏀剁姸鎬侊紝涓嶈兘瀹℃壒");
         }
         if (StringUtils.isBlank(deviceRepairDto.getAcceptanceName())) {
-            return R.fail("楠屾敹浜轰笉鑳戒负绌�");
+            return AjaxResult.error("楠屾敹浜轰笉鑳戒负绌�");
         }
         if (deviceRepairDto.getAcceptanceTime() == null) {
-            return R.fail("楠屾敹鏃堕棿涓嶈兘涓虹┖");
+            return AjaxResult.error("楠屾敹鏃堕棿涓嶈兘涓虹┖");
         }
         if (StringUtils.isBlank(deviceRepairDto.getAcceptanceRemark())) {
-            return R.fail("楠屾敹澶囨敞涓嶈兘涓虹┖");
+            return AjaxResult.error("楠屾敹澶囨敞涓嶈兘涓虹┖");
         }
 
         DeviceRepair update = new DeviceRepair();
@@ -194,9 +218,9 @@
         update.setAcceptanceRemark(deviceRepairDto.getAcceptanceRemark());
         update.setStatus(STATUS_COMPLETED);
         if (this.updateById(update)) {
-            return R.ok();
+            return AjaxResult.success();
         }
-        return R.fail("楠屾敹瀹℃壒澶辫触");
+        return AjaxResult.error("楠屾敹瀹℃壒澶辫触");
     }
 
     @Override

--
Gitblit v1.9.3