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/DeviceExaminePlanServiceImpl.java | 284 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 231 insertions(+), 53 deletions(-)
diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExaminePlanServiceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExaminePlanServiceImpl.java
index 1381d0e..5e8fd20 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExaminePlanServiceImpl.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExaminePlanServiceImpl.java
@@ -9,8 +9,6 @@
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.ruoyi.common.constant.MenuJumpPathConstants;
import com.ruoyi.common.core.domain.entity.InformationNotification;
import com.ruoyi.common.core.domain.entity.User;
@@ -39,10 +37,19 @@
import com.ruoyi.device.service.DeviceExaminePlanDetailsService;
import com.ruoyi.device.service.DeviceExaminePlanService;
import com.ruoyi.framework.exception.ErrorException;
-import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
-import com.ruoyi.inspect.util.UserUtils;
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.InformationNotificationService;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -54,7 +61,6 @@
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.time.LocalDate;
@@ -65,6 +71,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -292,57 +299,196 @@
}
/**
- * 瀵煎嚭璁惧鏍告煡璁″垝
+ * 瀵煎嚭璁惧鏍告煡璁″垝锛圗xcel锛夛細鏈夌瓫閫夋潯浠舵椂瀵煎嚭绛涢�夌粨鏋滐紝娌℃湁绛涢�夋椂瀵煎嚭璇ュ勾浠藉叏閮�
* @param deviceExaminePlanId 璁惧鏍告煡璁″垝id
+ * @param deviceName 璁惧鍚嶇О绛涢��
+ * @param deviceNumber 璁惧缂栧彿绛涢��
* @param response 鍝嶅簲浣�
*/
@Override
- public void exportDeviceExaminePlanDetail(Integer deviceExaminePlanId, HttpServletResponse response) {
- // 鏌ヨ璁惧鏍告煡璁″垝
- DeviceExaminePlanDto deviceExaminePlanDto = baseMapper.selectExamineExaminePlanDto(deviceExaminePlanId);
+ public void exportDeviceExaminePlanDetail(Integer deviceExaminePlanId, String deviceName, String deviceNumber, HttpServletResponse response) {
+ DeviceExaminePlan deviceExaminePlan = baseMapper.selectById(deviceExaminePlanId);
+ if (deviceExaminePlan == null) {
+ throw new ErrorException("璁惧鏍告煡璁″垝涓嶅瓨鍦�");
+ }
+ DeviceExaminePlanDetails query = new DeviceExaminePlanDetails();
+ query.setPlanId(deviceExaminePlanId);
+ query.setDeviceName(deviceName);
+ query.setDeviceNumber(deviceNumber);
+ List<DeviceExaminePlanDetailsDto> deviceExaminePlanDetailsDtoList =
+ deviceExaminePlanDetailsMapper.listDeviceExaminePlanDetail(QueryWrappers.queryWrappers(query));
- // 鏌ヨ璁惧鏍告煡璁″垝璇︽儏
- List<DeviceExaminePlanDetails> deviceExaminePlanDetailsList = deviceExaminePlanDetailsMapper.selectList(Wrappers.<DeviceExaminePlanDetails>lambdaQuery().eq(DeviceExaminePlanDetails::getPlanId, deviceExaminePlanId)
- .orderByAsc(DeviceExaminePlanDetails::getCheckTime));
- // 璁剧疆搴忓彿
- ArrayList<DeviceExaminePlanDetailsDto> deviceExaminePlanDetailsDtoList = new ArrayList<>();
- deviceExaminePlanDetailsList.forEach(deviceExamineRecordContrastDetail -> {
- DeviceExaminePlanDetailsDto deviceExaminePlanDetailsDto = new DeviceExaminePlanDetailsDto();
- BeanUtils.copyProperties(deviceExamineRecordContrastDetail, deviceExaminePlanDetailsDto);
- deviceExaminePlanDetailsDto.setIndex(deviceExaminePlanDetailsList.indexOf(deviceExamineRecordContrastDetail) + 1);
- deviceExaminePlanDetailsDtoList.add(deviceExaminePlanDetailsDto);
- });
+ String planName = StringUtils.isNotBlank(deviceExaminePlan.getPlanName()) ? deviceExaminePlan.getPlanName() : "璁惧鏍告煡璁″垝";
+ String[] columns = {"搴忓彿", "璁惧缂栧彿", "璁惧鍚嶇О", "璁惧鍨嬪彿", "鏍告煡鏃堕棿", "鏍告煡鎸囨爣",
+ "鏍告煡鏂规硶", "缁撴灉濡備綍鍒ゅ畾", "鏍告煡璐熻矗浜�", "瀹℃牳鐘舵��", "澶囨敞"};
+ List<String[]> dataRows = new ArrayList<>();
+ int index = 1;
+ for (DeviceExaminePlanDetailsDto detail : deviceExaminePlanDetailsDtoList) {
+ String checkTime = StringUtils.isNotBlank(detail.getCompleteDate()) ? detail.getCompleteDate() : detail.getCheckTime();
+ dataRows.add(new String[]{
+ String.valueOf(index++),
+ blankToEmpty(detail.getDeviceNumber()),
+ blankToEmpty(detail.getDeviceName()),
+ blankToEmpty(detail.getDeviceModel()),
+ blankToEmpty(checkTime),
+ blankToEmpty(detail.getCheckIndex()),
+ blankToEmpty(detail.getCheckMethod()),
+ blankToEmpty(detail.getHowResults()),
+ blankToEmpty(detail.getCheckChargerUser()),
+ recordStatusText(detail.getRecordStatus()),
+ blankToEmpty(detail.getRemark())
+ });
+ }
- // 鑾峰彇璺緞
- InputStream inputStream = this.getClass().getResourceAsStream("/static/word/examine-plan-detail.docx");
- Configure configure = Configure.builder()
- .bind("deviceExaminePlanDetailsDtoList", new HackLoopTableRenderPolicy())
- .build();
- XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
- new HashMap<String, Object>() {{
- put("deviceExaminePlan", deviceExaminePlanDto);
- put("deviceExaminePlanDetailsDtoList", deviceExaminePlanDetailsDtoList);
- //鑾峰彇鏍告煡浜虹殑绛惧悕鍦板潃
- put("writeUserUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceExaminePlanDto.getWriteUserId()));
- //鑾峰彇瀹℃煡浜虹殑绛惧悕鍦板潃
- put("reviewUserUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceExaminePlanDto.getRatifyUserId()));
- }});
-
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setCharacterEncoding("UTF-8");
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();
+ "attachment;filename=" + URLEncoder.encode(planName, "UTF-8") + ".xlsx");
+ writePlanExcel(response, planName, columns, dataRows);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("瀵煎嚭澶辫触");
}
+ }
+
+ /**
+ * 鍐欒鍒掕〃锛氭爣棰樿 + 鍒楀悕 + 鏁版嵁锛屾暣浣撳彧鍔犳渶澶栬竟妗嗭紝鍏ㄩ儴灞呬腑锛屾棤鑳屾櫙鑹�
+ */
+ private void writePlanExcel(HttpServletResponse response, String planName, String[] columns,
+ List<String[]> dataRows) throws IOException {
+ Workbook workbook = new XSSFWorkbook();
+ Map<String, CellStyle> styleCache = new HashMap<>();
+ Font titleFont = buildExcelFont(workbook, true, 16);
+ Font headerFont = buildExcelFont(workbook, true, 12);
+ Font contentFont = buildExcelFont(workbook, false, 12);
+
+ Sheet sheet = workbook.createSheet("璁惧鏍告煡璁″垝");
+ int lastColumn = columns.length - 1;
+
+ Row titleRow = sheet.createRow(0);
+ titleRow.setHeightInPoints(30);
+ for (int c = 0; c <= lastColumn; c++) {
+ Cell cell = titleRow.createCell(c);
+ if (c == 0) {
+ cell.setCellValue(planName);
+ }
+ cell.setCellStyle(exportStyle(workbook, styleCache, titleFont, c == 0, c == lastColumn, true, false));
+ }
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, lastColumn));
+
+ Row headerRow = sheet.createRow(1);
+ headerRow.setHeightInPoints(22);
+ for (int c = 0; c <= lastColumn; c++) {
+ Cell cell = headerRow.createCell(c);
+ cell.setCellValue(columns[c]);
+ cell.setCellStyle(exportStyle(workbook, styleCache, headerFont,
+ c == 0, c == lastColumn, false, dataRows.isEmpty()));
+ }
+
+ for (int r = 0; r < dataRows.size(); r++) {
+ Row row = sheet.createRow(r + 2);
+ boolean lastDataRow = r == dataRows.size() - 1;
+ for (int c = 0; c <= lastColumn; c++) {
+ Cell cell = row.createCell(c);
+ cell.setCellValue(dataRows.get(r)[c]);
+ cell.setCellStyle(exportStyle(workbook, styleCache, contentFont,
+ c == 0, c == lastColumn, false, lastDataRow));
+ }
+ }
+
+ for (int c = 0; c <= lastColumn; c++) {
+ int width = textWidth(columns[c]);
+ for (String[] row : dataRows) {
+ width = Math.max(width, textWidth(row[c]));
+ }
+ sheet.setColumnWidth(c, Math.min(255, width + 4) * 256);
+ }
+
+ OutputStream os = response.getOutputStream();
+ workbook.write(os);
+ os.flush();
+ workbook.close();
+ }
+
+ private Font buildExcelFont(Workbook workbook, boolean bold, int size) {
+ Font font = workbook.createFont();
+ font.setFontName("瀹嬩綋");
+ font.setBold(bold);
+ font.setFontHeightInPoints((short) size);
+ return font;
+ }
+
+ /**
+ * 鍗曞厓鏍兼牱寮忥細灞呬腑銆佹棤鑳屾櫙鑹诧紱鍐呴儴缁嗙綉鏍肩嚎锛屾暣浣撴渶澶栧湀绮楄竟妗�
+ */
+ private CellStyle exportStyle(Workbook workbook, Map<String, CellStyle> styleCache, Font font,
+ boolean outerLeft, boolean outerRight, boolean outerTop, boolean outerBottom) {
+ String key = font.getBold() + "-" + font.getFontHeightInPoints() + "-" + (outerLeft ? 1 : 0)
+ + (outerRight ? 1 : 0) + (outerTop ? 1 : 0) + (outerBottom ? 1 : 0);
+ CellStyle cached = styleCache.get(key);
+ if (cached != null) {
+ return cached;
+ }
+ CellStyle style = workbook.createCellStyle();
+ style.setFont(font);
+ style.setAlignment(HorizontalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ style.setBorderLeft(BorderStyle.THIN);
+ style.setBorderRight(BorderStyle.THIN);
+ style.setBorderTop(BorderStyle.THIN);
+ style.setBorderBottom(BorderStyle.THIN);
+ if (outerLeft) {
+ style.setBorderLeft(BorderStyle.MEDIUM);
+ }
+ if (outerRight) {
+ style.setBorderRight(BorderStyle.MEDIUM);
+ }
+ if (outerTop) {
+ style.setBorderTop(BorderStyle.MEDIUM);
+ }
+ if (outerBottom) {
+ style.setBorderBottom(BorderStyle.MEDIUM);
+ }
+ styleCache.put(key, style);
+ return style;
+ }
+
+ /**
+ * 浼扮畻鏄剧ず瀹藉害锛堜腑鏂囨寜涓や釜瀛楃瀹斤級
+ */
+ private int textWidth(String text) {
+ if (text == null) {
+ return 0;
+ }
+ int width = 0;
+ for (int i = 0; i < text.length(); i++) {
+ width += text.charAt(i) > 0xFF ? 2 : 1;
+ }
+ return width;
+ }
+
+ /**
+ * 璁板綍鐘舵�佹枃妗堬細0鏈紑濮嬨��1寰呮壒鍑嗐��2閫氳繃銆�3涓嶉�氳繃
+ */
+ private String recordStatusText(Integer recordStatus) {
+ if (recordStatus == null) {
+ return "鏈紑濮�";
+ }
+ switch (recordStatus) {
+ case 1:
+ return "寰呮壒鍑�";
+ case 2:
+ return "閫氳繃";
+ case 3:
+ return "涓嶉�氳繃";
+ default:
+ return "鏈紑濮�";
+ }
+ }
+
+ private String blankToEmpty(String value) {
+ return value == null ? "" : value;
}
@Override
@@ -409,6 +555,22 @@
}
}
return planDto;
+ }
+
+ /**
+ * 鏍告煡璁″垝骞翠唤鍒楄〃锛氬垹闄ゆ病鏈変换浣曟槑缁嗙殑绌哄勾浠借鍒掑悗锛岃繑鍥炴湁鏄庣粏鐨勫勾浠斤紙鍊掑簭锛�
+ */
+ @Override
+ public List<String> getExaminePlanYears() {
+ List<DeviceExaminePlan> plans = baseMapper.selectList(null);
+ for (DeviceExaminePlan plan : plans) {
+ Long detailCount = deviceExaminePlanDetailsMapper.selectCount(Wrappers.<DeviceExaminePlanDetails>lambdaQuery()
+ .eq(DeviceExaminePlanDetails::getPlanId, plan.getPlanId()));
+ if (detailCount == null || detailCount == 0) {
+ removeById(plan.getPlanId());
+ }
+ }
+ return baseMapper.selectPlanYears();
}
/**
@@ -499,17 +661,32 @@
}
/**
- * 璁″垝涓皻鏃犺璁惧鏈疆鏄庣粏鏃惰嚜鍔ㄨˉ涓�鏉★紱鏍告煡鏃堕棿鍙栧簲鏍告煡鏈堜唤
+ * 璁″垝涓皻鏃犺璁惧鏈疆鏄庣粏鏃惰嚜鍔ㄨˉ涓�鏉★紱鏍告煡鏃堕棿鍙栨。妗堜笅娆℃牳鏌ユ棩鏈燂紙绮剧‘鍒版棩锛�
*/
private void fillExamineDetailIfAbsent(DeviceExaminePlan plan, Device device) {
LocalDate due = calcExamineDueDate(device);
if (due == null) {
return;
}
- if (plan.getPlanYear() != null && String.valueOf(due.getYear()).compareTo(plan.getPlanYear()) > 0) {
+ if (StringUtils.isBlank(plan.getPlanYear())) {
return;
}
- String checkTime = due.format(DateTimeFormatter.ofPattern("yyyy-MM"));
+ int planYearValue;
+ try {
+ planYearValue = Integer.parseInt(plan.getPlanYear().trim());
+ } catch (NumberFormatException e) {
+ return;
+ }
+ int dueYear = due.getYear();
+ // 鏈潵骞翠唤鐨勮鍒掑彧鐧昏搴旀牳鏌ユ棩鏈熷氨鍦ㄨ骞翠唤鐨勮澶囷紝閬垮厤鎶婂線骞寸殑鏃ф棩鏈熻ˉ杩涙湭鏉ョ殑璁″垝
+ if (planYearValue > LocalDate.now().getYear()) {
+ if (dueYear != planYearValue) {
+ return;
+ }
+ } else if (dueYear > planYearValue) {
+ return;
+ }
+ String checkTime = due.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
Long exist = deviceExaminePlanDetailsMapper.selectCount(Wrappers.<DeviceExaminePlanDetails>lambdaQuery()
.eq(DeviceExaminePlanDetails::getPlanId, plan.getPlanId())
.eq(DeviceExaminePlanDetails::getDeviceId, device.getId())
@@ -682,12 +859,13 @@
.eq(DeviceExamineRecord::getPlanDetailsId, planDetailsId));
List<DeviceExamineRecordContrast> contrasts = deviceExamineRecordContrastMapper.selectList(Wrappers.<DeviceExamineRecordContrast>lambdaQuery()
.eq(DeviceExamineRecordContrast::getPlanDetailsId, planDetailsId));
- boolean hasReviewedRecord = records.stream().anyMatch(item -> item.getReviewStatus() != null
- && (item.getReviewStatus() == 0 || item.getReviewStatus() == 1));
- boolean hasReviewedContrast = contrasts.stream().anyMatch(item -> item.getReviewStatus() != null
- && (item.getReviewStatus() == 0 || item.getReviewStatus() == 1));
- if (hasReviewedRecord || hasReviewedContrast) {
- throw new ErrorException("璇ヨ鍒掑凡瀛樺湪瀹℃牳瀹屾垚鐨勬牳鏌ヨ褰曪紝涓轰繚鐣欏巻鍙茶褰曚笉鍏佽鍒犻櫎");
+ // 瀹℃牳涓嶉�氳繃鐨勮褰曞厑璁歌繛鍚屾槑缁嗕竴璧峰垹闄わ紱瀹℃牳閫氳繃鐨勮褰曚负鍘嗗彶鐣欐。锛屼笉鍏佽鍒犻櫎
+ boolean hasPassedRecord = records.stream().anyMatch(item -> item.getReviewStatus() != null
+ && item.getReviewStatus() == 1);
+ boolean hasPassedContrast = contrasts.stream().anyMatch(item -> item.getReviewStatus() != null
+ && item.getReviewStatus() == 1);
+ if (hasPassedRecord || hasPassedContrast) {
+ throw new ErrorException("璇ヨ鍒掑凡瀛樺湪瀹℃牳閫氳繃鐨勬牳鏌ヨ褰曪紝涓轰繚鐣欏巻鍙茶褰曚笉鍏佽鍒犻櫎");
}
if (!records.isEmpty()) {
List<Integer> recordIds = records.stream().map(DeviceExamineRecord::getRecordId).collect(Collectors.toList());
--
Gitblit v1.9.3