From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001 From: maven <2163098428@qq.com> Date: 星期五, 01 八月 2025 13:27:59 +0800 Subject: [PATCH] yys 密码已重置 --- cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceStateServiceImpl.java | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 160 insertions(+), 0 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 new file mode 100644 index 0000000..412e97d --- /dev/null +++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceStateServiceImpl.java @@ -0,0 +1,160 @@ +package com.ruoyi.device.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +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.basic.mapper.LaboratoryMapper; +import com.ruoyi.basic.pojo.Laboratory; +import com.ruoyi.common.core.domain.entity.User; +import com.ruoyi.device.dto.DeviceStateDto; +import com.ruoyi.device.mapper.DeviceStateMapper; +import com.ruoyi.device.pojo.DeviceState; +import com.ruoyi.device.service.DeviceStateService; +import com.ruoyi.framework.exception.ErrorException; +import com.ruoyi.system.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; + +/** + * <p> + * 璁惧鍋滅敤/鍚敤 鏈嶅姟瀹炵幇绫� + * </p> + * + * @author + * @since 2024-09-26 09:51:40 + */ +@Service +public class DeviceStateServiceImpl extends ServiceImpl<DeviceStateMapper, DeviceState> implements DeviceStateService { + + @Resource + private LaboratoryMapper laboratoryMapper; + + @Resource + private UserMapper userMapper; + + @Value("${file.path}") + private String imgUrl; + + @Override + public IPage<DeviceStateDto> getDeviceStatePage(Integer deviceId, Page page, String processNumber) { + return baseMapper.getDeviceStatePage(deviceId, page, processNumber); + } + + @Override + public void exportDeviceStatus(Integer deviceId, String processNumber, HttpServletResponse response) { + // 鏍规嵁娴佺▼缂栧彿 鏌ヨcnas璁惧鐘舵�� + DeviceStateDto deviceStateDto = baseMapper.getDeviceStatePage(deviceId,new Page<DeviceStateDto>(1,1), processNumber).getRecords().get(0); + + // 瀵规椂闂磋繘琛屼慨鏀� + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"); + deviceStateDto.setSubmitDateString(deviceStateDto.getSubmitDate() != null ? deviceStateDto.getSubmitDate().format(format) : " 骞� 鏈� 鏃�"); + deviceStateDto.setDepartmentDateString(deviceStateDto.getDepartmentDate() != null? deviceStateDto.getDepartmentDate().format(format) : " 骞� 鏈� 鏃�"); + deviceStateDto.setMeasuringRoomDateString(deviceStateDto.getMeasuringRoomDate() != null? deviceStateDto.getMeasuringRoomDate().format(format) : " 骞� 鏈� 鏃�"); + deviceStateDto.setApprovalDateString(deviceStateDto.getApprovalDate() != null? deviceStateDto.getApprovalDate().format(format) : " 骞� 鏈� 鏃�"); + + // 鏌ヨ璁惧灞炰簬鍝釜瀹為獙瀹� + String laboratoryName; + String largeCategory = deviceStateDto.getLargeCategory(); + if (StringUtils.isNotBlank(largeCategory)) { + largeCategory = largeCategory.substring(0, 1); + Laboratory laboratory = laboratoryMapper.selectOne(Wrappers.<Laboratory>lambdaQuery() + .eq(Laboratory::getLaboratoryNumber, largeCategory) + .select(Laboratory::getLaboratoryName)); + laboratoryName = laboratory.getLaboratoryName(); + } else { + 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("laboratory", laboratoryName); + }}); + + try { + response.setContentType("application/msword"); + String fileName = URLEncoder.encode( + "璁惧缁存姢淇濆吇璁板綍", "UTF-8"); + response.setHeader("Content-disposition", + "attachment;filename=" + fileName + ".docx"); + OutputStream os = response.getOutputStream(); + template.write(os); + os.flush(); + os.close(); + inputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("瀵煎嚭澶辫触"); + } + } +} -- Gitblit v1.9.3