From 2f07589b54d56085af77b50d580890cd4130b444 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期一, 19 十月 2026 15:19:53 +0800
Subject: [PATCH] 设备模块后端业务规则、计划接口与日期联动

---
 cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java |  177 ++++++----------------------------------------------------
 1 files changed, 20 insertions(+), 157 deletions(-)

diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java
index e006b84..a0cc9d1 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java
@@ -25,15 +25,14 @@
 import com.ruoyi.device.mapper.CollectBridgeMapper;
 import com.ruoyi.device.mapper.DeviceCalibrationPlanDetailMapper;
 import com.ruoyi.device.mapper.DeviceCalibrationPlanMapper;
-import com.ruoyi.device.mapper.DeviceExaminePlanDetailsMapper;
-import com.ruoyi.device.mapper.DeviceExaminePlanMapper;
 import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
-import com.ruoyi.device.mapper.DeviceMaintenancePlanDetailsMapper;
-import com.ruoyi.device.mapper.DeviceMaintenancePlanMapper;
 import com.ruoyi.device.mapper.DeviceMapper;
 import com.ruoyi.device.mapper.DeviceMetricRecordMapper;
 import com.ruoyi.device.pojo.*;
 import com.ruoyi.device.service.DataConfigService;
+import com.ruoyi.device.service.DeviceCalibrationPlanService;
+import com.ruoyi.device.service.DeviceExaminePlanService;
+import com.ruoyi.device.service.DeviceMaintenancePlanService;
 import com.ruoyi.device.service.DeviceService;
 import com.ruoyi.device.service.DeviceDocumentsService;
 import com.ruoyi.device.utils.DataAcquisition;
@@ -89,17 +88,11 @@
 
     private CollectBridgeMapper collectBridgeMapper;
 
-    private DeviceCalibrationPlanMapper deviceCalibrationPlanMapper;
+    private DeviceCalibrationPlanService deviceCalibrationPlanService;
 
-    private DeviceCalibrationPlanDetailMapper deviceCalibrationPlanDetailMapper;
+    private DeviceExaminePlanService deviceExaminePlanService;
 
-    private DeviceExaminePlanMapper deviceExaminePlanMapper;
-
-    private DeviceExaminePlanDetailsMapper deviceExaminePlanDetailsMapper;
-
-    private DeviceMaintenancePlanMapper deviceMaintenancePlanMapper;
-
-    private DeviceMaintenancePlanDetailsMapper deviceMaintenancePlanDetailsMapper;
+    private DeviceMaintenancePlanService deviceMaintenancePlanService;
 
     @Override
     public IPage<DeviceDto> selectDeviceParameter(Page page, DeviceDto itemParameter, Boolean laboratoryNameIsNull) {
@@ -121,153 +114,22 @@
     @Override
     public int upDeviceParameter(Device itemParameter) {
         int rows = deviceMapper.updateById(itemParameter);
-        // 妗f淇濉啓浜嗘牎鍑嗘湁鏁堟湡鍜屾牎鍑嗗懆鏈熷悗锛岃嚜鍔ㄥ悓姝ュ埌璁惧鏍″噯璁″垝
+        // 妗f淇濉啓浜嗘牎鍑嗕俊鎭悗锛屽埌鐐圭殑鑷姩鍚屾鍒拌澶囨牎鍑嗚鍒�
         Device device = deviceMapper.selectById(itemParameter.getId());
-        if (device != null && device.getActivationDate() != null && StringUtils.isNotBlank(device.getCalibrationDate())) {
-            syncCalibrationPlanDetail(device);
+        if (device != null && (device.getNextCalibrationDate() != null || device.getActivationDate() != null)) {
+            deviceCalibrationPlanService.syncDeviceCalibrationDetail(device);
         }
-        // 妗f淇濉啓浜嗘牳鏌ヤ俊鎭悗锛岃嚜鍔ㄥ悓姝ュ埌璁惧鏍告煡璁″垝
-        if (device != null && device.getNextExamineDate() != null && StringUtils.isNotBlank(device.getExamineCycle())) {
-            syncExaminePlanDetail(device);
+        // 妗f淇濉啓浜嗘牳鏌ヤ俊鎭悗锛屽埌鐐圭殑鑷姩鍚屾鍒拌澶囨牳鏌ヨ鍒�
+        if (device != null && (device.getNextExamineDate() != null
+                || (device.getLastExamineDate() != null && StringUtils.isNotBlank(device.getExamineCycle())))) {
+            deviceExaminePlanService.syncDeviceExamineDetail(device);
         }
-        // 妗f淇濉啓浜嗕繚鍏讳俊鎭悗锛岃嚜鍔ㄥ悓姝ュ埌璁惧淇濆吇璁″垝
-        if (device != null && device.getNextMaintenanceDate() != null && StringUtils.isNotBlank(device.getMaintenanceCycle())) {
-            syncMaintenancePlanDetail(device);
+        // 妗f淇濉啓浜嗕繚鍏讳俊鎭悗锛屽埌鐐圭殑鑷姩鍚屾鍒拌澶囦繚鍏昏鍒�
+        if (device != null && (device.getNextMaintenanceDate() != null
+                || (device.getLastMaintenanceDate() != null && StringUtils.isNotBlank(device.getMaintenanceCycle())))) {
+            deviceMaintenancePlanService.syncDeviceMaintenanceDetail(device);
         }
         return rows;
-    }
-
-    /**
-     * 鎶婅澶囧悓姝ュ埌浠婂勾鐨勮澶囨牎鍑嗚鍒掓槑缁嗭細鏈勾璁″垝鏍″噯鏃堕棿 = 鏍″噯鏈夋晥鏈熷墠涓�涓湀
-     */
-    private void syncCalibrationPlanDetail(Device device) {
-        String planYear = String.valueOf(LocalDate.now().getYear());
-        DeviceCalibrationPlan plan = deviceCalibrationPlanMapper.selectOne(Wrappers.<DeviceCalibrationPlan>lambdaQuery()
-                .eq(DeviceCalibrationPlan::getPlanYear, planYear)
-                .and(w -> w.isNull(DeviceCalibrationPlan::getRatifyStatus).or().ne(DeviceCalibrationPlan::getRatifyStatus, 1))
-                .orderByDesc(DeviceCalibrationPlan::getPlanId)
-                .last("limit 1"));
-        if (plan == null) {
-            plan = new DeviceCalibrationPlan();
-            plan.setPlanName(planYear + "骞村害璁惧鏍″噯璁″垝");
-            plan.setPlanYear(planYear);
-            plan.setWriteUserId(SecurityUtils.getUserId().intValue());
-            plan.setWriteTime(LocalDateTime.now());
-            deviceCalibrationPlanMapper.insert(plan);
-        }
-
-        DeviceCalibrationPlanDetail detail = deviceCalibrationPlanDetailMapper.selectOne(Wrappers.<DeviceCalibrationPlanDetail>lambdaQuery()
-                .eq(DeviceCalibrationPlanDetail::getPlanId, plan.getPlanId())
-                .eq(DeviceCalibrationPlanDetail::getDeviceId, device.getId())
-                .last("limit 1"));
-        boolean isInsert = detail == null;
-        if (isInsert) {
-            detail = new DeviceCalibrationPlanDetail();
-            detail.setPlanId(plan.getPlanId());
-            detail.setDeviceId(device.getId());
-        }
-        String deviceName = device.getDeviceName() == null ? "" : device.getDeviceName();
-        if (StringUtils.isNotBlank(device.getSpecificationModel())) {
-            deviceName = deviceName + " " + device.getSpecificationModel();
-        }
-        detail.setDeviceName(deviceName);
-        detail.setDeviceAmount("1");
-        detail.setDeviceNumber(device.getManagementNumber());
-        detail.setVerificationUnit(device.getCalibrationServices());
-        detail.setVerificationCycles(device.getCalibrationDate());
-        detail.setLastDate(device.getLastCalibrationDate() == null ? null : device.getLastCalibrationDate().toLocalDate());
-        detail.setPlanDate(device.getActivationDate().toLocalDate().minusMonths(1));
-        if (isInsert) {
-            deviceCalibrationPlanDetailMapper.insert(detail);
-        } else {
-            deviceCalibrationPlanDetailMapper.updateById(detail);
-        }
-    }
-
-    /**
-     * 鎶婅澶囧悓姝ュ埌浠婂勾鐨勮澶囨牳鏌ヨ鍒掓槑缁嗭細鏍告煡鏃堕棿 = 涓嬫鏍告煡鏃ユ湡鍓嶄竴涓湀
-     */
-    private void syncExaminePlanDetail(Device device) {
-        String planYear = String.valueOf(LocalDate.now().getYear());
-        DeviceExaminePlan plan = deviceExaminePlanMapper.selectOne(Wrappers.<DeviceExaminePlan>lambdaQuery()
-                .eq(DeviceExaminePlan::getPlanYear, planYear)
-                .and(w -> w.isNull(DeviceExaminePlan::getRatifyStatus).or().ne(DeviceExaminePlan::getRatifyStatus, 1))
-                .orderByDesc(DeviceExaminePlan::getPlanId)
-                .last("limit 1"));
-        if (plan == null) {
-            plan = new DeviceExaminePlan();
-            plan.setPlanName(planYear + "骞村害璁惧鏍告煡璁″垝");
-            plan.setPlanYear(planYear);
-            plan.setWriteUserId(SecurityUtils.getUserId().intValue());
-            plan.setWriteTime(LocalDateTime.now());
-            deviceExaminePlanMapper.insert(plan);
-        }
-
-        DeviceExaminePlanDetails detail = deviceExaminePlanDetailsMapper.selectOne(Wrappers.<DeviceExaminePlanDetails>lambdaQuery()
-                .eq(DeviceExaminePlanDetails::getPlanId, plan.getPlanId())
-                .eq(DeviceExaminePlanDetails::getDeviceId, device.getId())
-                .last("limit 1"));
-        boolean isInsert = detail == null;
-        if (isInsert) {
-            detail = new DeviceExaminePlanDetails();
-            detail.setPlanId(plan.getPlanId());
-            detail.setDeviceId(device.getId());
-        }
-        String deviceName = device.getDeviceName() == null ? "" : device.getDeviceName();
-        if (StringUtils.isNotBlank(device.getSpecificationModel())) {
-            deviceName = deviceName + " " + device.getSpecificationModel();
-        }
-        detail.setDeviceName(deviceName);
-        detail.setDeviceNumber(device.getManagementNumber());
-        detail.setCheckTime(device.getNextExamineDate().toLocalDate().minusMonths(1).toString());
-        if (isInsert) {
-            deviceExaminePlanDetailsMapper.insert(detail);
-        } else {
-            deviceExaminePlanDetailsMapper.updateById(detail);
-        }
-    }
-
-    /**
-     * 鎶婅澶囧悓姝ュ埌浠婂勾鐨勮澶囦繚鍏昏鍒掓槑缁嗭細璁″垝淇濆吇鏃堕棿 = 涓嬫淇濆吇鏃ユ湡鍓嶄竴涓湀
-     */
-    private void syncMaintenancePlanDetail(Device device) {
-        String planYear = String.valueOf(LocalDate.now().getYear());
-        DeviceMaintenancePlan plan = deviceMaintenancePlanMapper.selectOne(Wrappers.<DeviceMaintenancePlan>lambdaQuery()
-                .eq(DeviceMaintenancePlan::getPlanYear, planYear)
-                .and(w -> w.isNull(DeviceMaintenancePlan::getStatus).or().ne(DeviceMaintenancePlan::getStatus, 1))
-                .orderByDesc(DeviceMaintenancePlan::getMaintenancePlanId)
-                .last("limit 1"));
-        if (plan == null) {
-            plan = new DeviceMaintenancePlan();
-            plan.setPlanName(planYear + "骞村害璁惧淇濆吇璁″垝");
-            plan.setPlanYear(planYear);
-            Integer userId = SecurityUtils.getUserId().intValue();
-            User user = userMapper.selectById(userId);
-            plan.setCompilerId(userId);
-            if (user != null) {
-                plan.setCompiler(user.getName());
-            }
-            plan.setDatePreparation(LocalDateTime.now());
-            deviceMaintenancePlanMapper.insert(plan);
-        }
-
-        DeviceMaintenancePlanDetails detail = deviceMaintenancePlanDetailsMapper.selectOne(Wrappers.<DeviceMaintenancePlanDetails>lambdaQuery()
-                .eq(DeviceMaintenancePlanDetails::getMaintenancePlanId, plan.getMaintenancePlanId())
-                .eq(DeviceMaintenancePlanDetails::getDeviceId, device.getId())
-                .last("limit 1"));
-        boolean isInsert = detail == null;
-        if (isInsert) {
-            detail = new DeviceMaintenancePlanDetails();
-            detail.setMaintenancePlanId(plan.getMaintenancePlanId());
-            detail.setDeviceId(device.getId());
-        }
-        detail.setMaintenanceIntervals(device.getMaintenanceCycle());
-        detail.setMaintenanceDate(device.getNextMaintenanceDate().toLocalDate().minusMonths(1));
-        if (isInsert) {
-            deviceMaintenancePlanDetailsMapper.insert(detail);
-        } else {
-            deviceMaintenancePlanDetailsMapper.updateById(detail);
-        }
     }
 
     @Override
@@ -619,8 +481,9 @@
     }
 
     @Override
-    public void exportEquipmentDetails(HttpServletResponse response) {
-        List<Device> deviceList = baseMapper.selectList(null);
+    public void exportEquipmentDetails(DeviceDto itemParameter, HttpServletResponse response) {
+        // 鎸夊綋鍓嶇瓫閫夋潯浠跺鍑�(鏉′欢涓虹┖鏃跺鍑哄叏閮�)
+        List<Device> deviceList = baseMapper.selectList(QueryWrappers.<Device>queryWrappers(itemParameter));
         List<DeviceExport> deviceExportList = new ArrayList<>();
 
         int index = 1;

--
Gitblit v1.9.3