From c21cb3d8cebd9cdef4df2efa372c5b9257c713e4 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期三, 28 十月 2026 17:57:40 +0800
Subject: [PATCH] feat(device,supply,satisfaction): 设备计划后端改造、耗材存放位置与满意度照片支持
---
cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceImpl.java | 301 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 195 insertions(+), 106 deletions(-)
diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceImpl.java
index 22b2895..bf261f6 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceImpl.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceImpl.java
@@ -1,42 +1,38 @@
package com.ruoyi.device.service.impl;
-import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
-import com.deepoove.poi.data.Pictures;
-import com.ruoyi.common.core.domain.entity.SysDictData;
+import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.utils.QueryWrappers;
-import com.ruoyi.device.dto.DeviceImpowerDetailsDto;
-import com.ruoyi.device.dto.DeviceImpowerDto;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
-import com.ruoyi.device.mapper.DeviceMapper;
import com.ruoyi.device.pojo.Device;
-import com.ruoyi.device.pojo.DeviceImpower;
import com.ruoyi.device.pojo.DeviceMaintenance;
+import com.ruoyi.device.pojo.DeviceMaintenancePlanDetails;
+import com.ruoyi.device.service.DeviceMaintenancePlanService;
import com.ruoyi.device.service.DeviceMaintenanceService;
import com.ruoyi.device.service.DeviceService;
+import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
import com.ruoyi.inspect.util.UserUtils;
-import com.ruoyi.system.service.ISysDictDataService;
-import com.ruoyi.system.service.ISysDictTypeService;
-import lombok.AllArgsConstructor;
+import com.ruoyi.system.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
-import java.time.format.DateTimeFormatter;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -45,14 +41,14 @@
* 璁惧缁存姢淇濆吇
*/
@Service
+@Transactional(rollbackFor = Exception.class)
public class DeviceMaintenanceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements DeviceMaintenanceService {
@Resource
private DeviceService deviceService;
@Resource
- private ISysDictTypeService iSysDictTypeService;
-
- @Value("${file.path}")
- private String imgUrl;
+ private DeviceMaintenancePlanService deviceMaintenancePlanService;
+ @Resource
+ private UserMapper userMapper;
/**
* 璁惧缁存姢鍒嗛〉鏌ヨ
@@ -67,52 +63,160 @@
}
/**
- * 瀵煎嚭璁惧缁存姢淇濆吇
+ * 淇濆瓨淇濆吇璁板綍锛堝叧鑱斾繚鍏昏鍒掓槑缁嗭紝淇濆瓨鍚庤繘鍏ュ緟瀹℃牳锛屼笉婊氬姩璁惧妗f鏃ユ湡锛�
+ */
+ @Override
+ public boolean saveDeviceMaintenance(DeviceMaintenance deviceMaintenance) {
+ if (deviceMaintenance == null) {
+ throw new ErrorException("缂哄皯淇濆吇璁板綍");
+ }
+ if (deviceMaintenance.getDeviceId() == null) {
+ throw new ErrorException("缂哄皯璁惧id");
+ }
+ if (deviceMaintenance.getMaintenanceDate() == null) {
+ throw new ErrorException("璇烽�夋嫨淇濆吇鏃ユ湡");
+ }
+ if (deviceMaintenance.getMaintenanceUserId() == null) {
+ throw new ErrorException("璇烽�夋嫨缁存姢浜�");
+ }
+ DeviceMaintenance exist = deviceMaintenance.getId() == null ? null : baseMapper.selectById(deviceMaintenance.getId());
+ if (exist != null) {
+ if (exist.getMaintenancePlanDetailId() == null) {
+ throw new ErrorException("鍘嗗彶淇濆吇璁板綍涓嶅厑璁镐慨鏀�");
+ }
+ if (exist.getReviewStatus() != null) {
+ throw new ErrorException("宸插鏍哥殑淇濆吇璁板綍涓嶅厑璁镐慨鏀�");
+ }
+ // 璁板綍褰掑睘鐢卞簱閲岀殑鍏宠仈鍐冲畾锛岄伩鍏嶆敼鍒板埆鐨勮澶囨垨璁″垝
+ deviceMaintenance.setDeviceId(exist.getDeviceId());
+ deviceMaintenance.setMaintenancePlanDetailId(exist.getMaintenancePlanDetailId());
+ deviceMaintenance.setReviewStatus(null);
+ } else {
+ DeviceMaintenancePlanDetails detail = deviceMaintenancePlanService.resolveMaintenancePlanDetail(
+ deviceMaintenance.getDeviceId(), deviceMaintenance.getMaintenancePlanDetailId(), deviceMaintenance.getMaintenanceDate());
+ if (!deviceMaintenance.getDeviceId().equals(detail.getDeviceId())) {
+ throw new ErrorException("淇濆吇璁″垝鏄庣粏涓庤澶囦笉鍖归厤");
+ }
+ DeviceMaintenance other = baseMapper.selectOne(Wrappers.<DeviceMaintenance>lambdaQuery()
+ .eq(DeviceMaintenance::getMaintenancePlanDetailId, detail.getMaintenancePlanDetailId())
+ .last("limit 1"));
+ if (other != null) {
+ throw new ErrorException("璇ヨ鍒掑凡瀛樺湪淇濆吇璁板綍");
+ }
+ deviceMaintenance.setMaintenancePlanDetailId(detail.getMaintenancePlanDetailId());
+ deviceMaintenance.setReviewStatus(null);
+ deviceMaintenance.setReviewUserId(null);
+ deviceMaintenance.setReviewUserName(null);
+ deviceMaintenance.setReviewRemark(null);
+ deviceMaintenance.setReviewTime(null);
+ }
+ User user = userMapper.selectById(deviceMaintenance.getMaintenanceUserId());
+ deviceMaintenance.setMaintenanceUserName(user == null ? null : user.getName());
+ return saveOrUpdate(deviceMaintenance);
+ }
+
+ /**
+ * 瀹℃牳淇濆吇璁板綍锛涘鏍搁�氳繃鍚庢寜瀹℃牳閫氳繃褰撳ぉ婊氬姩璁惧妗f鐨勬渶杩�/涓嬫淇濆吇鏃ユ湡锛堜笌鏍告煡璁″垝涓�鑷达級
+ */
+ @Override
+ public boolean reviewDeviceMaintenance(DeviceMaintenanceDto deviceMaintenanceDto) {
+ DeviceMaintenance record = findMaintenanceRecord(deviceMaintenanceDto);
+ if (record == null) {
+ throw new ErrorException("璇ヨ鍒掓殏鏃犱繚鍏昏褰曪紝璇峰厛濉啓淇濆吇璁板綍");
+ }
+ if (record.getMaintenancePlanDetailId() == null) {
+ throw new ErrorException("鍘嗗彶淇濆吇璁板綍鏃犻渶瀹℃牳");
+ }
+ if (deviceMaintenanceDto.getReviewStatus() == null) {
+ throw new ErrorException("璇烽�夋嫨瀹℃牳缁撴灉");
+ }
+ if (record.getReviewStatus() != null && record.getReviewStatus() == 1) {
+ throw new ErrorException("璇ヤ繚鍏昏褰曞凡瀹℃牳閫氳繃");
+ }
+ if (record.getMaintenanceUserId() == null && StringUtils.isBlank(record.getMaintenanceUserName())) {
+ throw new ErrorException("璇峰厛鍦ㄧ紪杈戜腑濉啓缁存姢浜�");
+ }
+ Integer reviewerId = SecurityUtils.getUserId().intValue();
+ User reviewer = userMapper.selectById(reviewerId);
+ boolean updated = this.update(Wrappers.<DeviceMaintenance>lambdaUpdate()
+ .eq(DeviceMaintenance::getId, record.getId())
+ .set(DeviceMaintenance::getReviewStatus, deviceMaintenanceDto.getReviewStatus())
+ .set(DeviceMaintenance::getReviewUserId, reviewerId)
+ .set(DeviceMaintenance::getReviewUserName, reviewer == null ? null : reviewer.getName())
+ .set(DeviceMaintenance::getReviewRemark, deviceMaintenanceDto.getReviewRemark())
+ .set(DeviceMaintenance::getReviewTime, LocalDateTime.now()));
+ // 瀹℃牳閫氳繃鍚庯紝鎸夊鏍搁�氳繃褰撳ぉ鍥炲啓妗f鐨勬渶杩戜繚鍏绘棩鏈熷苟鎺ㄧ畻涓嬩竴杞紙涓庢牳鏌ヨ鍒掍竴鑷达級
+ if (updated && deviceMaintenanceDto.getReviewStatus() == 1) {
+ LocalDate reviewDate = LocalDate.now();
+ // 瀹℃牳瀹屾垚骞翠唤鍗冲綊绫诲勾浠斤細鎻愬墠瀹屾垚鐨勬槑缁嗕粠鍘熻鍒掑勾浠芥尓鍒板鏍稿勾浠�
+ deviceMaintenancePlanService.reclassifyMaintenanceDetailByReviewDate(record.getMaintenancePlanDetailId(), reviewDate);
+ deviceMaintenancePlanService.updateDeviceMaintenanceDate(record.getDeviceId(), reviewDate);
+ }
+ return updated;
+ }
+
+ /**
+ * 鍒犻櫎淇濆吇璁板綍锛涘鏍搁�氳繃鍜屽巻鍙茶褰曚笉鍏佽鍒犻櫎
+ */
+ @Override
+ public boolean deleteDeviceMaintenance(Integer id) {
+ DeviceMaintenance record = id == null ? null : baseMapper.selectById(id);
+ if (record == null) {
+ return false;
+ }
+ if (record.getMaintenancePlanDetailId() == null) {
+ throw new ErrorException("鍘嗗彶淇濆吇璁板綍涓虹暀妗e唴瀹癸紝涓嶅厑璁稿垹闄�");
+ }
+ if (record.getReviewStatus() != null && record.getReviewStatus() == 1) {
+ throw new ErrorException("瀹℃牳閫氳繃鐨勪繚鍏昏褰曚负鍘嗗彶璁板綍锛屼笉鍏佽鍒犻櫎");
+ }
+ return removeById(id);
+ }
+
+ /**
+ * 鎸夎褰昳d鎴栬鍒掓槑缁唅d瀹氫綅淇濆吇璁板綍
+ */
+ private DeviceMaintenance findMaintenanceRecord(DeviceMaintenanceDto dto) {
+ if (dto == null) {
+ return null;
+ }
+ if (dto.getId() != null) {
+ return baseMapper.selectById(dto.getId());
+ }
+ if (dto.getMaintenancePlanDetailId() != null) {
+ return baseMapper.selectOne(Wrappers.<DeviceMaintenance>lambdaQuery()
+ .eq(DeviceMaintenance::getMaintenancePlanDetailId, dto.getMaintenancePlanDetailId())
+ .last("limit 1"));
+ }
+ return null;
+ }
+
+ /**
+ * 瀵煎嚭浠櫒璁惧缁存姢淇濆吇璁板綍锛堝彧璇诲彴璐︼紝鏁版嵁鏉ヨ嚜淇濆吇璁″垝鐢熸垚鐨勪繚鍏昏褰曪級
* @param deviceId
* @param response
*/
@Override
public void exportDeviceMaintenance(Integer deviceId, HttpServletResponse response) {
- // 鏌ヨ璁惧缁存姢淇濆吇
- List<DeviceMaintenance> deviceMaintenanceList = baseMapper.selectList(Wrappers.<DeviceMaintenance>lambdaQuery()
- .eq(DeviceMaintenance::getDeviceId, deviceId));
-
- // 鑾峰彇鍒扮涓�涓澶囦娇鐢ㄦ巿鏉�
- DeviceMaintenanceDto deviceMaintenanceDto = new DeviceMaintenanceDto();
-
- List<SysDictData> sysDictDataList = null;
- if (CollectionUtils.isNotEmpty(deviceMaintenanceList)) {
- BeanUtils.copyProperties(deviceMaintenanceList.get(0), deviceMaintenanceDto);
- // 鏌ヨ璁惧淇℃伅
- Device device = deviceService.getById(deviceId);
- deviceMaintenanceDto.setDeviceName(device.getDeviceName());
- deviceMaintenanceDto.setManagementNumber(device.getManagementNumber());
-
- //鏌ヨ缁存姢淇濆吇瀵煎嚭瀛楀吀鍊�
- sysDictDataList = getDeviceMaintenanceDict(device);
+ Device device = deviceId == null ? null : deviceService.getById(deviceId);
+ if (device == null) {
+ throw new ErrorException("璁惧涓嶅瓨鍦�");
}
-
- // 娣诲姞瀛楀吀鏋氫妇鍊�
- for (DeviceMaintenance deviceMaintenance : deviceMaintenanceList) {
- StringBuilder maintenanceContent = new StringBuilder(deviceMaintenance.getMaintenanceContent());
- if (CollectionUtils.isNotEmpty(sysDictDataList) && StringUtils.isNotBlank(deviceMaintenance.getMaintenanceContent())) {
- maintenanceContent = new StringBuilder();
- List<String> splitList = StrUtil.split(deviceMaintenance.getMaintenanceContent(), ',');
- // 寰幆鍒ゆ柇鏄惁鏈変竴鏍穔ey
- for (SysDictData sysDictData : sysDictDataList) {
- if (splitList.contains(sysDictData.getDictLabel())) {
- maintenanceContent.append("鈽�").append(sysDictData.getDictLabel()).append(" ");
- } else {
- maintenanceContent.append("鈻�").append(sysDictData.getDictLabel()).append(" ");
- }
- }
- }
- deviceMaintenance.setMaintenanceContent(maintenanceContent.toString());
- // 娣诲姞缁存姢浜哄浘鐗�
- deviceMaintenance.setMaintenanceUserUrlRender(UserUtils.getFinalUserSignatureOrTransparent(deviceMaintenance.getMaintenanceUserId()));
-
+ // 鍙拌处鎸夌淮鎶ゆ棩鏈熸搴忔帓鍒�
+ List<DeviceMaintenance> records = baseMapper.selectList(Wrappers.<DeviceMaintenance>lambdaQuery()
+ .eq(DeviceMaintenance::getDeviceId, deviceId)
+ .orderByAsc(DeviceMaintenance::getMaintenanceDate)
+ .orderByAsc(DeviceMaintenance::getId));
+ List<DeviceMaintenanceDto> deviceMaintenances = new ArrayList<>();
+ int index = 1;
+ for (DeviceMaintenance record : records) {
+ DeviceMaintenanceDto dto = new DeviceMaintenanceDto();
+ BeanUtils.copyProperties(record, dto);
+ dto.setIndex(index++);
+ // 缁存姢浜哄垪灞曠ず绛惧悕鍥剧墖锛屾湭閰嶇疆绛惧悕鏃剁敤閫忔槑鍥剧墖鍏滃簳
+ dto.setMaintenanceUserUrlRender(UserUtils.getFinalUserSignatureOrTransparent(record.getMaintenanceUserId()));
+ deviceMaintenances.add(dto);
}
-
// 鑾峰彇璺緞
InputStream inputStream = this.getClass().getResourceAsStream("/static/word/device-maintenance.docx");
@@ -121,14 +225,17 @@
.build();
XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
new HashMap<String, Object>() {{
- put("device", deviceMaintenanceDto);
- put("deviceMaintenances", deviceMaintenanceList);
+ put("deviceName", device.getDeviceName());
+ put("specificationModel", device.getSpecificationModel());
+ put("managementNumber", device.getManagementNumber());
+ put("cycleNote", buildCycleNote(device.getMaintenanceCycle()));
+ put("deviceMaintenances", deviceMaintenances);
}});
try {
response.setContentType("application/msword");
String fileName = URLEncoder.encode(
- "璁惧淇濆吇缁存姢", "UTF-8");
+ "浠櫒璁惧缁存姢淇濆吇璁板綍", "UTF-8");
response.setHeader("Content-disposition",
"attachment;filename=" + fileName + ".docx");
OutputStream os = response.getOutputStream();
@@ -144,54 +251,36 @@
}
/**
- * ****鏌ヨ缁存姢淇濆吇瀵煎嚭瀛楀吀鍊�***
- * @param device
+ * 琛ㄦ牸搴曢儴鐨勭淮鎶や繚鍏婚鐜囪鏄庯紝鎸夋。妗堥噷鐨勪繚鍏诲懆鏈燂紙鏈堬級鐢熸垚
*/
- private List<SysDictData> getDeviceMaintenanceDict(Device device) {
- List<SysDictData> sysDictDataList = new ArrayList<>();
- // 鏌ヨ缁存姢淇濆吇瀵煎嚭瀛楀吀鍊�
- if (StringUtils.isNotBlank(device.getStoragePoint())) {
- String dictType = null;
- switch (device.getStoragePoint()) {
- case "鑰佸寲瀹�":
- dictType = "aging_maintenance_content";
- break;
- case "鑰佸寲瀹為獙瀹�":
- dictType = "aging_maintenance_content";
- break;
- case "鐢垫�ц兘瀹為獙瀹�":
- dictType = "electrical_maintenance_content";
- break;
- case "鐜瀹為獙瀹�":
- dictType = "environmental_maintenance_content";
- break;
- case "鐕冪儳瀹為獙瀹�":
- dictType = "burn_maintenance_content";
- break;
- case "娣风偧瀹為獙瀹�":
- dictType = "mixing_maintenance_content";
- break;
- case "妫�娴嬩腑蹇冪數鎬ц兘瀹為獙瀹�":
- dictType = "center_electrical_maintenance_content";
- break;
- case "鎭掓俯浜�":
- dictType = "temperature2_maintenance_content";
- break;
- case "鎭掓俯涓�":
- dictType = "temperature1_maintenance_content";
- break;
- case "鍖栧瀹為獙瀹�":
- dictType = "chemistry_maintenance_content";
- break;
- case "鍒舵牱瀹�":
- dictType = "sample_maintenance_content";
- break;
- case "浣庢俯瀹為獙瀹�":
- dictType = "hypothermia_maintenance_content";
- break;
- }
- sysDictDataList = iSysDictTypeService.selectDictDataByType(dictType);
+ private String buildCycleNote(String maintenanceCycle) {
+ if (StringUtils.isBlank(maintenanceCycle)) {
+ return "";
}
- return sysDictDataList;
+ int months;
+ try {
+ months = Integer.parseInt(maintenanceCycle.trim());
+ } catch (NumberFormatException e) {
+ return "";
+ }
+ if (months <= 0) {
+ return "";
+ }
+ if (months == 1) {
+ return "缁存姢淇濆吇姣忔湀 1 娆�";
+ }
+ if (months == 3) {
+ return "缁存姢淇濆吇姣忓搴� 1 娆�";
+ }
+ if (months == 6) {
+ return "缁存姢淇濆吇姣忓崐骞� 1 娆�";
+ }
+ if (months == 12) {
+ return "缁存姢淇濆吇姣忓勾 1 娆�";
+ }
+ if (months % 12 == 0) {
+ return "缁存姢淇濆吇姣� " + months / 12 + " 骞� 1 娆�";
+ }
+ return "缁存姢淇濆吇姣� " + months + " 涓湀 1 娆�";
}
}
--
Gitblit v1.9.3