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/DeviceStateServiceImpl.java | 122 ++++++++++++++++++++--------------------
1 files changed, 62 insertions(+), 60 deletions(-)
diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceStateServiceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceStateServiceImpl.java
index e45aaed..06ce59a 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceStateServiceImpl.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceStateServiceImpl.java
@@ -7,18 +7,21 @@
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.basic.mapper.LaboratoryMapper;
import com.ruoyi.basic.pojo.Laboratory;
import com.ruoyi.common.core.domain.entity.User;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.device.dto.DeviceStateDto;
+import com.ruoyi.device.mapper.DeviceMapper;
import com.ruoyi.device.mapper.DeviceStateMapper;
+import com.ruoyi.device.pojo.Device;
import com.ruoyi.device.pojo.DeviceState;
import com.ruoyi.device.service.DeviceStateService;
-import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.util.UserUtils;
import com.ruoyi.system.mapper.UserMapper;
-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;
@@ -41,12 +44,59 @@
@Resource
private LaboratoryMapper laboratoryMapper;
-
@Resource
private UserMapper userMapper;
+ @Resource
+ private DeviceMapper deviceMapper;
- @Value("${file.path}")
- private String imgUrl;
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean saveDeviceState(DeviceState deviceState) {
+ User user = userMapper.selectById(SecurityUtils.getUserId().intValue());
+ if (deviceState.getStateId() != null) {
+ DeviceState existing = baseMapper.selectById(deviceState.getStateId());
+ if (existing == null) {
+ throw new ServiceException("鍗曟嵁涓嶅瓨鍦�");
+ }
+ if ("鍏抽棴".equals(existing.getCurrentState())) {
+ throw new ServiceException("璇ユ祦绋嬪凡缁撴潫锛屼笉鑳藉啀鎿嶄綔");
+ }
+ if (StringUtils.isNotBlank(existing.getCurrentResponsible())
+ && !existing.getCurrentResponsible().equals(user.getName())) {
+ throw new ServiceException("鎮ㄤ笉鏄綋鍓嶇幆鑺傝矗浠讳汉锛屾棤鏉冩搷浣�");
+ }
+ }
+ boolean saved = saveOrUpdate(deviceState);
+ if (saved && "鍏抽棴".equals(deviceState.getCurrentState())) {
+ updateDeviceStatus(deviceState);
+ }
+ return saved;
+ }
+
+ /**
+ * 娴佺▼鏈�缁堟壒鍑嗗悗锛屾妸鍋滅敤/鍚敤缁撴灉鍚屾鍒拌澶囨。妗堢姸鎬�
+ */
+ private void updateDeviceStatus(DeviceState deviceState) {
+ if (deviceState.getDeviceId() == null) {
+ return;
+ }
+ Device device = deviceMapper.selectById(deviceState.getDeviceId());
+ if (device == null) {
+ return;
+ }
+ Integer status = null;
+ if ("0scrap".equals(deviceState.getDeviceStatus())) {
+ status = 3;
+ } else if ("1startUsing".equals(deviceState.getDeviceStatus())) {
+ status = 0;
+ } else if ("2stopUsing".equals(deviceState.getDeviceStatus())) {
+ status = 2;
+ }
+ if (status != null) {
+ device.setDeviceStatus(status);
+ deviceMapper.updateById(device);
+ }
+ }
@Override
public IPage<DeviceStateDto> getDeviceStatePage(Integer deviceId, Page page, String processNumber) {
@@ -78,73 +128,25 @@
laboratoryName = "";
}
- //todo: 璁惧鐘舵�佹煡璇㈢鍚嶅湴鍧� 鏆傛椂浜哄悕鏌ヨ
- //鑾峰彇鐢宠浜虹殑绛惧悕鍦板潃
- String applicantUrl = null;
- if (deviceStateDto.getSubmitOperatingPersonnel() != null) {
- applicantUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery()
- .eq(User::getName, deviceStateDto.getSubmitOperatingPersonnel()))
- .getSignatureUrl();
- if (StringUtils.isBlank(applicantUrl)) {
- throw new ErrorException("鎵句笉鍒扮敵璇蜂汉鐨勭鍚�");
- }
- }
-
- //鑾峰彇閮ㄩ棬璐熻矗浜虹殑绛惧悕鍦板潃
- String headOfDepartmentUrl = null;
- if (deviceStateDto.getDepartmentNextPesponsible() != null) {
- headOfDepartmentUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery()
- .eq(User::getName, deviceStateDto.getDepartmentNextPesponsible()))
- .getSignatureUrl();
- if (StringUtils.isBlank(headOfDepartmentUrl)) {
- throw new ErrorException("鎵句笉鍒伴儴闂ㄨ礋璐d汉鐨勭鍚�");
- }
- }
-
- //鑾峰彇璁¢噺瀹ゅ娴嬩汉鐨勭鍚嶅湴鍧�
- String measurementRoomUrl = null;
- if (deviceStateDto.getMeasuringRoomNextPesponsible() != null) {
- measurementRoomUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery()
- .eq(User::getName, deviceStateDto.getMeasuringRoomNextPesponsible()))
- .getSignatureUrl();
- if (StringUtils.isBlank(measurementRoomUrl)) {
- throw new ErrorException("鎵句笉鍒拌閲忓澶嶆祴浜虹殑绛惧悕");
- }
- }
-
- //鑾峰彇鎵瑰噯浜虹殑绛惧悕鍦板潃
- String approvedUrl = null;
- if (deviceStateDto.getApprovalNextPesponsible() != null) {
- approvedUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery()
- .eq(User::getName, deviceStateDto.getApprovalNextPesponsible()))
- .getSignatureUrl();
- if (StringUtils.isBlank(approvedUrl)) {
- throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�");
- }
- }
-
// 鑾峰彇璺緞
InputStream inputStream = this.getClass().getResourceAsStream("/static/word/device-status.docx");
Configure configure = Configure.builder()
.build();
- String finalApplicantUrl = applicantUrl; // 鐢宠浜虹殑绛惧悕鍦板潃
- String finalHeadOfDepartmentUrl = headOfDepartmentUrl; // 閮ㄩ棬璐熻矗浜虹殑绛惧悕鍦板潃
- String finalMeasurementRoomUrl = measurementRoomUrl; // 璁¢噺瀹ゅ娴嬩汉鐨勭鍚嶅湴鍧�
- String finalApprovedUrl = approvedUrl; // 鎵瑰噯浜虹殑绛惧悕鍦板潃
XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
new HashMap<String, Object>() {{
put("deviceStateDto", deviceStateDto);
- put("submitOperatingPersonnelUrl", StringUtils.isNotBlank(finalApplicantUrl) ? Pictures.ofLocal(imgUrl + "/" + finalApplicantUrl).create() : null);
- put("departmentNextPesponsibleUrl", StringUtils.isNotBlank(finalHeadOfDepartmentUrl) ? Pictures.ofLocal(imgUrl + "/" + finalHeadOfDepartmentUrl).create() : null);
- put("measuringRoomNextPesponsibleUrl", StringUtils.isNotBlank(finalMeasurementRoomUrl) ? Pictures.ofLocal(imgUrl + "/" + finalMeasurementRoomUrl).create() : null);
- put("approvalNextPesponsibleUrl", StringUtils.isNotBlank(finalApprovedUrl) ? Pictures.ofLocal(imgUrl + "/" + finalApprovedUrl).create() : null);
+ // 绛惧悕鍏滃簳: 浜哄憳鏈厤缃鍚嶆垨绛惧悕鏂囦欢缂哄け鏃惰繑鍥為�忔槑鍥剧墖, 淇濊瘉瀵煎嚭涓嶅洜绌哄浘鐗囨姤閿�
+ put("submitOperatingPersonnelUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getSubmitOperatingPersonnel()));
+ put("departmentNextPesponsibleUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getDepartmentNextPesponsible()));
+ put("measuringRoomNextPesponsibleUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getMeasuringRoomNextPesponsible()));
+ put("approvalNextPesponsibleUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getApprovalNextPesponsible()));
put("laboratory", laboratoryName);
}});
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();
--
Gitblit v1.9.3