From 0fd551911bb5b0b2ed16db87fecc085c98e9a68d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 16 十月 2026 17:15:44 +0800
Subject: [PATCH] fix:1. 过程要求 - 样品接收:列表样式优化。 2. 过程要求 - 方法验证:点击详情还能修改,导出格式优化,按客户给的文档来。 3. 业务管理 - 检验任务:删除不合格相关的检测。 4. 业务管理 - 报告结果:按照发送日期倒序排列。 5. 基础配置 - 行业管理:删除印章管理。 6. 体系管理要求 - 客户满意度:附件上传报错,精简上传逻辑。
---
cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodVerifyServiceImpl.java | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 165 insertions(+), 1 deletions(-)
diff --git a/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodVerifyServiceImpl.java b/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodVerifyServiceImpl.java
index ca298cb..af266b6 100644
--- a/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodVerifyServiceImpl.java
+++ b/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodVerifyServiceImpl.java
@@ -2,6 +2,9 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -29,6 +32,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.apache.poi.xwpf.usermodel.XWPFTable;
+import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
@@ -41,6 +49,9 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Set;
/**
* 鏍囧噯鏂规硶楠岃瘉
@@ -103,6 +114,7 @@
if (methodVerifyDto.getOperationType() == null) {
throw new ErrorException("璇烽�夋嫨鏄彉鏇磋繕鏄獙璇�");
}
+ validateWordVerification(methodVerifyDto);
// 鏂板
baseMapper.insert(methodVerifyDto);
@@ -148,6 +160,37 @@
return processMethodVerifyDto;
}
+ @Override
+ public List<ProcessMethodVerifyWorkFile> getCurrentWorkFiles(String userIds) {
+ List<ProcessMethodVerifyWorkFile> files = new ArrayList<>();
+ if (StringUtils.isBlank(userIds)) return files;
+
+ Set<Integer> ids = new LinkedHashSet<>();
+ for (String value : StrUtil.split(userIds, ",")) {
+ try {
+ ids.add(Integer.valueOf(value.trim()));
+ } catch (NumberFormatException e) {
+ throw new ErrorException("妫�娴嬩汉鍛業D鏃犳晥");
+ }
+ }
+ if (ids.size() > 5) throw new ErrorException("鏈�澶氶�夋嫨5鍚嶆娴嬩汉鍛�");
+
+ for (Integer userId : ids) {
+ ProcessMethodVerifyWorkFile file = processMethodVerifyWorkFileMapper.selectLatestAuthorization(userId);
+ if (file == null) continue;
+ file.setUserId(userId);
+ if (StringUtils.isBlank(file.getFileUrl())) {
+ file.setFileName("鏈笂浼犱笂宀楄瘉涔�");
+ file.setType(0);
+ } else {
+ file.setFileName(file.getFileUrl());
+ file.setType(file.getFileUrl().matches("(?i).*\\.(png|jpe?g|gif|bmp|webp)$") ? 1 : 2);
+ }
+ files.add(file);
+ }
+ return files;
+ }
+
/**
* 淇敼鏍囧噯鏂规硶楠岃瘉
*
@@ -156,6 +199,7 @@
*/
@Override
public boolean updateMethodVerify(ProcessMethodVerifyDto methodVerifyDto) {
+ validateWordVerification(methodVerifyDto);
baseMapper.updateById(methodVerifyDto);
// 鍒犻櫎涓婂矖璇�
@@ -288,6 +332,14 @@
public void exportMethodVerify(Integer methodVerifyId, HttpServletResponse response) {
// 鑾峰彇鏍囧噯鏂规硶鏇存柊楠岃瘉鏁版嵁
ProcessMethodVerify processMethodVerify = baseMapper.selectById(methodVerifyId);
+ if (processMethodVerify == null) {
+ throw new ErrorException("鏂规硶楠岃瘉璁板綍涓嶅瓨鍦�");
+ }
+ if (Objects.equals(processMethodVerify.getOperationType(), 1)
+ && StringUtils.isNotBlank(processMethodVerify.getVerificationContent())) {
+ exportWordVerification(processMethodVerify, response);
+ return;
+ }
// 灏嗗唴閮ㄥ瓧娈佃浆鎹㈡垚灞曠ず鍒皐ord涓殑瀵硅薄
ProcessMethodVerifyExportWordDto exportWordTemplate = getExportWordTemplate(processMethodVerify);
@@ -350,6 +402,118 @@
e.printStackTrace();
throw new RuntimeException("瀵煎嚭澶辫触");
}
+ }
+
+ /** 鎸夊鎴锋彁渚涚殑妯悜鏂规硶楠岃瘉琛ㄥ鍑猴紱鍘熷璁板綍鍜岄獙璇佺粨鏋滀粛浣滀负闄勪欢淇濆瓨銆� */
+ private void exportWordVerification(ProcessMethodVerify verify, HttpServletResponse response) {
+ JSONObject content = JSONUtil.parseObj(verify.getVerificationContent());
+ String[] checkKeys = {"personnel", "equipment", "reagents", "conditions", "sample", "steps",
+ "processing", "qualityControl", "result"};
+ InputStream templateStream = getClass().getResourceAsStream("/static/method-verification-customer.docx");
+ if (templateStream == null) throw new IllegalStateException("鏂规硶楠岃瘉瀵煎嚭妯℃澘涓嶅瓨鍦�");
+ try (InputStream inputStream = templateStream; XWPFDocument document = new XWPFDocument(inputStream)) {
+ XWPFTable table = document.getTables().get(0);
+ setTemplateCell(table, 0, 1, verify.getStandardName());
+ setTemplateCell(table, 0, 3, verify.getStandardCode());
+ setTemplateCell(table, 1, 1, verify.getVerifyItem());
+
+ JSONArray entries = content.getJSONArray("checks");
+ for (int i = 0; i < checkKeys.length; i++) {
+ JSONObject entry = findCheck(entries, checkKeys[i]);
+ Integer satisfied = entry == null ? null : entry.getInt("satisfied");
+ int row = i + 3;
+ if (row <= 8) {
+ setTemplateCell(table, row, 1, field(entry, "requirement"));
+ setTemplateCell(table, row, 2, field(entry, "capability"));
+ setTemplateCell(table, row, 3, satisfiedText(satisfied));
+ } else {
+ setTemplateCell(table, row, 1, mergedCheckText(entry));
+ setTemplateCell(table, row, 2, satisfiedText(satisfied));
+ }
+ }
+ setTemplateCell(table, 12, 1, field(content, "conclusion"));
+ setTemplateCell(table, 13, 1, decisionText(field(content, "reviewDecision"),
+ "璇勫浜哄憳", field(content, "reviewer"), field(content, "reviewDate")));
+ setTemplateCell(table, 14, 1, decisionText(field(content, "approvalDecision"),
+ "鎶�鏈礋璐d汉", field(content, "approver"), field(content, "approvalDate")));
+
+ response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+ String fileName = URLEncoder.encode("鏂规硶楠岃瘉璁板綍", "UTF-8");
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx");
+ document.write(response.getOutputStream());
+ } catch (Exception e) {
+ throw new RuntimeException("瀵煎嚭鏂规硶楠岃瘉璁板綍澶辫触", e);
+ }
+ }
+
+ private JSONObject findCheck(JSONArray entries, String key) {
+ if (entries == null) return null;
+ for (Object value : entries) {
+ JSONObject check = JSONUtil.parseObj(value);
+ if (key.equals(check.getStr("key"))) return check;
+ }
+ return null;
+ }
+
+ private String field(JSONObject object, String key) {
+ return object == null ? "" : StrUtil.nullToEmpty(object.getStr(key));
+ }
+
+ private String satisfiedText(Integer satisfied) {
+ return satisfied == null ? "" : satisfied == 1 ? "鏄�" : "鍚�";
+ }
+
+ private String mergedCheckText(JSONObject entry) {
+ String requirement = field(entry, "requirement").trim();
+ String capability = field(entry, "capability").trim();
+ if (requirement.isEmpty()) return capability;
+ if (capability.isEmpty() || requirement.equals(capability)) return requirement;
+ return "鏂规硶瑕佹眰锛�" + requirement + "\n瀹為獙瀹よ兘鍔涳細" + capability;
+ }
+
+ private String decisionText(String decision, String personLabel, String person, String date) {
+ StringBuilder value = new StringBuilder();
+ for (String choice : new String[]{"鍚屾剰浣跨敤", "涓嶈兘浣跨敤", "闄愬埗浣跨敤"}) {
+ if (value.length() > 0) value.append(" ");
+ value.append(choice.equals(decision) ? "鈽�" : "鈻�").append(choice);
+ }
+ value.append("\n").append(personLabel).append("锛�").append(person);
+ if (StringUtils.isNotBlank(date)) {
+ String[] parts = date.split("-");
+ value.append(" 鏃ユ湡锛�");
+ value.append(parts.length == 3 ? parts[0] + "骞�" + parts[1] + "鏈�" + parts[2] + "鏃�" : date);
+ }
+ return value.toString();
+ }
+
+ private void setTemplateCell(XWPFTable table, int row, int cellIndex, String value) {
+ XWPFTableCell cell = table.getRow(row).getCell(cellIndex);
+ XWPFParagraph paragraph = cell.getParagraphs().get(0);
+ XWPFRun run = paragraph.getRuns().get(0);
+ String[] lines = StrUtil.nullToEmpty(value).replace("\r\n", "\n").split("\n", -1);
+ run.setText(lines[0], 0);
+ for (int i = 1; i < lines.length; i++) {
+ run.addBreak();
+ run.setText(lines[i]);
+ }
+ }
+
+ private void validateWordVerification(ProcessMethodVerifyDto verify) {
+ // 娌℃湁 verificationContent 鐨勬棫璁板綍缁х画鐢辨棫琛ㄥ崟缁存姢銆�
+ if (!Objects.equals(verify.getOperationType(), 1)
+ || StringUtils.isBlank(verify.getVerificationContent())) return;
+ if (StringUtils.isBlank(verify.getStandardName())
+ || StringUtils.isBlank(verify.getStandardCode())
+ || StringUtils.isBlank(verify.getVerifyItem())) {
+ throw new ErrorException("璇峰~鍐欐爣鍑嗗悕绉般�佹爣鍑嗙紪鍙峰拰楠岃瘉椤圭洰");
+ }
+ try {
+ JSONUtil.parseObj(verify.getVerificationContent());
+ } catch (Exception e) {
+ throw new ErrorException("鏂规硶楠岃瘉鍐呭鏍煎紡閿欒");
+ }
+ // 淇濈暀鏃у垪渚涚幇鏈変緷璧� method_name 鐨勬煡璇娇鐢ㄣ��
+ verify.setMethodName(verify.getStandardName());
}
private ProcessMethodVerifyExportWordDto getExportWordTemplate(ProcessMethodVerify processMethodVerify) {
@@ -424,7 +588,7 @@
User user = userMapper.selectById(userId);
ProcessMethodVerifyWorkFile workFile = new ProcessMethodVerifyWorkFile();
workFile.setMethodVerifyId(methodVerifyDto.getMethodVerifyId());
- workFile.setType(1);
+ workFile.setType(workName.matches("(?i).*\\.(png|jpe?g|gif|bmp|webp)$") ? 1 : 2);
workFile.setFileUrl(workName);
workFile.setFileName(workName);
workFile.setUserId(user.getId());
--
Gitblit v1.9.3