From bcbdb084c3a3a0a4de8fca1aa16caf0bc4681ddf Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期二, 27 十月 2026 09:41:51 +0800
Subject: [PATCH] feat(device): 删除核查计划明细时连带清理未审核记录和附件,已审核记录仍禁止删除
---
cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java | 193 +++++++----------------------------------------
1 files changed, 31 insertions(+), 162 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..810d54e 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) {
@@ -109,7 +102,13 @@
@Override
public int addDeviceParameter(Device itemParameter) {
- return deviceMapper.insert(itemParameter);
+ int rows = deviceMapper.insert(itemParameter);
+ Device device = deviceMapper.selectById(itemParameter.getId());
+ if (device != null && (device.getNextExamineDate() != null
+ || (device.getLastExamineDate() != null && StringUtils.isNotBlank(device.getExamineCycle())))) {
+ deviceExaminePlanService.syncDeviceExamineDetail(device);
+ }
+ return rows;
}
@Override
@@ -121,153 +120,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 +487,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;
@@ -711,10 +580,10 @@
Set<String> fileKeys = new HashSet<>();
for (int i = 0; i < rows.size(); i++) {
String managementNumber = required(rows.get(i).getManagementNumber(), i + 2, "绠$悊缂栧彿");
- String deviceName = required(rows.get(i).getDeviceName(), i + 2, "浠櫒鍚嶇О");
+ String deviceName = required(rows.get(i).getDeviceName(), i + 2, "璁惧鍚嶇О");
String specificationModel = required(rows.get(i).getSpecificationModel(), i + 2, "瑙勬牸鍨嬪彿");
if (!fileKeys.add(deviceKey(deviceName, specificationModel, managementNumber))) {
- throw new RuntimeException("绗�" + (i + 2) + "琛岋細浠櫒鍚嶇О+瑙勬牸鍨嬪彿+绠$悊缂栧彿鍦ㄦ枃浠朵腑閲嶅");
+ throw new RuntimeException("绗�" + (i + 2) + "琛岋細璁惧鍚嶇О+瑙勬牸鍨嬪彿+绠$悊缂栧彿鍦ㄦ枃浠朵腑閲嶅");
}
}
Set<String> existingKeys = baseMapper.selectList(Wrappers.<Device>lambdaQuery()
@@ -732,10 +601,10 @@
int rowNumber = i + 2;
DeviceImport row = rows.get(i);
String managementNumber = required(row.getManagementNumber(), rowNumber, "绠$悊缂栧彿");
- String deviceName = required(row.getDeviceName(), rowNumber, "浠櫒鍚嶇О");
+ String deviceName = required(row.getDeviceName(), rowNumber, "璁惧鍚嶇О");
String specificationModel = required(row.getSpecificationModel(), rowNumber, "瑙勬牸鍨嬪彿");
if (existingKeys.contains(deviceKey(deviceName, specificationModel, managementNumber))) {
- throw new RuntimeException("绗�" + rowNumber + "琛岋細浠櫒鍚嶇О鈥�" + deviceName + "鈥�+瑙勬牸鍨嬪彿鈥�" + specificationModel + "鈥�+绠$悊缂栧彿鈥�" + managementNumber + "鈥濆凡瀛樺湪");
+ throw new RuntimeException("绗�" + rowNumber + "琛岋細璁惧鍚嶇О鈥�" + deviceName + "鈥�+瑙勬牸鍨嬪彿鈥�" + specificationModel + "鈥�+绠$悊缂栧彿鈥�" + managementNumber + "鈥濆凡瀛樺湪");
}
Device device = new Device();
--
Gitblit v1.9.3