From fbd4ecb70baf2e671876ca809a81f6e6fe7342ee Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期日, 20 九月 2026 19:52:50 +0800
Subject: [PATCH] feat(inspect): 新增检测标准方法报告文本功能并优化报告生成 - 委托编号生成逻辑调整为下单时生成并校验唯一性,避免审核时重复 - 新增标准模板价格字段及对应的数据模型和数据库映射 - 订单费用详情查询逻辑重构为基于模板价格计算方式 - 新增标准模板与设备绑定关系的数据结构和管理功能 - 委托编号唯一性校验逻辑增强
---
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java | 432 +++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 335 insertions(+), 97 deletions(-)
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
index c9d4bb2..dff3ad5 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -46,6 +46,7 @@
import com.ruoyi.inspect.service.*;
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
import com.ruoyi.inspect.util.PreserveReportPicturePlaceholderHandler;
+import com.ruoyi.inspect.util.ReportSignaturePictureUtils;
import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo;
import com.ruoyi.inspect.vo.InsOrderPlanVO;
import com.ruoyi.inspect.vo.InsSampleUserVO;
@@ -178,8 +179,12 @@
String userName = null;
Integer userId = null;
if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) {
- userId = SecurityUtils.getUserId().intValue();
- userName = userMapper.selectById(userId).getName();
+ Integer currentUserId = SecurityUtils.getUserId().intValue();
+ // 绠$悊鍛樺彲浠ユ煡鐪嬪苟澶嶆牳鍏ㄩ儴寰呭鏍镐换鍔★紝鏅�氱敤鎴蜂粛鍙煡鐪嬪垎閰嶇粰鑷繁鐨勪换鍔°��
+ if (!SecurityUtils.isAdmin(currentUserId.longValue())) {
+ userId = currentUserId;
+ userName = userMapper.selectById(userId).getName();
+ }
insOrderPlanDTO.setUserId(null);
}
Integer isCheck = insOrderPlanDTO.getIsCheck();
@@ -745,18 +750,9 @@
} catch (Exception ignored) {
thing = compressedThing;
}
- JSONArray cellData = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0).getJSONArray("celldata");
+ JSONObject sheet = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0);
+ JSONArray cellData = sheet.getJSONArray("celldata");
NavigableMap<Integer, List<String>> result = new TreeMap<>();
- Integer inspectionResultColumn = null;
- for (Object item : cellData) {
- JSONObject cell = JSON.parseObject(JSON.toJSONString(item));
- Integer column = cell.getInteger("c");
- JSONObject value = cell.getJSONObject("v");
- String displayValue = value == null ? null : value.getString("v");
- if (inspectionResultColumn == null && "妫�楠岀粨鏋�".equals(StringUtils.trim(displayValue))) {
- inspectionResultColumn = column;
- }
- }
for (Object item : cellData) {
JSONObject cell = JSON.parseObject(JSON.toJSONString(item));
JSONObject value = cell.getJSONObject("v");
@@ -767,16 +763,119 @@
Integer row = cell.getInteger("r");
Integer column = cell.getInteger("c");
if (row != null && column != null) {
- // 鈥滃鍑哄�尖�濇爣鍦ㄦ娴嬮」鐩爣棰樺崟鍏冩牸鏃讹紝鐪熸瀵煎嚭鐨勫�兼槸鍚屼竴琛屸�滄楠岀粨鏋溾�濆垪鐨勫崟鍏冩牸銆�
- String coordinate = row + "-" + column;
- String resultCoordinate = row + "-" + inspectionResultColumn;
- if (inspectionResultColumn != null && !Objects.equals(column, inspectionResultColumn)) {
- coordinate = resultCoordinate;
- }
+ // 鎵规敞鍗曞厓鏍煎彲鑳芥í鍚戝悎骞讹紝鍙充晶缁撴灉鍗曞厓鏍间篃鍙兘绾靛悜鍚堝苟锛涙渶缁堣鍙栫粨鏋滃尯鍩熺殑宸︿笂瑙掑瓨鍌ㄥ潗鏍囥��
+ String coordinate = getRightAdjacentCoordinate(sheet, row, column);
result.computeIfAbsent(row, ignored -> new ArrayList<>()).add(coordinate);
}
}
return result;
+ }
+
+ /**
+ * 杩斿洖鎸囧畾鍗曞厓鏍硷紙鎴栧叾鎵�鍦ㄥ悎骞跺尯鍩燂級鍙充晶绱ч偦鍒楃殑涓嬫爣銆�
+ * Luckysheet 鐨勫悎骞朵俊鎭�氬父淇濆瓨鍦� config.merge锛涢儴鍒嗗巻鍙叉ā鏉垮彧鍦ㄥ崟鍏冩牸 v.mc 涓繚鐣欙紝
+ * 鍥犳涓ょ缁撴瀯閮借鍏煎銆�
+ */
+ private int getRightAdjacentColumn(JSONObject sheet, int row, int column) {
+ int rightEdge = column;
+ JSONObject config = sheet == null ? null : sheet.getJSONObject("config");
+ JSONObject merges = config == null ? null : config.getJSONObject("merge");
+ if (merges != null) {
+ for (Object rawMerge : merges.values()) {
+ rightEdge = extendMergedRightEdge(rightEdge, row, column, rawMerge);
+ }
+ }
+
+ JSONArray cellData = sheet == null ? null : sheet.getJSONArray("celldata");
+ if (cellData != null) {
+ for (Object rawCell : cellData) {
+ JSONObject cell = JSON.parseObject(JSON.toJSONString(rawCell));
+ JSONObject value = cell == null ? null : cell.getJSONObject("v");
+ JSONObject merge = value == null ? null : value.getJSONObject("mc");
+ rightEdge = extendMergedRightEdge(rightEdge, row, column, merge);
+ }
+ }
+ return rightEdge + 1;
+ }
+
+ private String getRightAdjacentCoordinate(JSONObject sheet, int row, int column) {
+ int adjacentColumn = getRightAdjacentColumn(sheet, row, column);
+ int[] anchor = findMergedAnchor(sheet, row, adjacentColumn);
+ return anchor[0] + "-" + anchor[1];
+ }
+
+ /**
+ * Luckysheet 鍙湪鍚堝苟鍖哄煙宸︿笂瑙掍繚瀛樺疄闄呭�笺�傝嫢鐩爣鍗曞厓鏍间綅浜庡悎骞跺尯鍩熷唴閮紝
+ * 灏嗗叾杞崲涓鸿鍖哄煙鐨勫乏涓婅鍧愭爣锛涙湭鍚堝苟鍒欒繑鍥炲師鍧愭爣銆�
+ */
+ private int[] findMergedAnchor(JSONObject sheet, int row, int column) {
+ JSONObject config = sheet == null ? null : sheet.getJSONObject("config");
+ JSONObject merges = config == null ? null : config.getJSONObject("merge");
+ if (merges != null) {
+ for (Object rawMerge : merges.values()) {
+ int[] anchor = findMergedAnchor(row, column, rawMerge);
+ if (anchor != null) {
+ return anchor;
+ }
+ }
+ }
+
+ JSONArray cellData = sheet == null ? null : sheet.getJSONArray("celldata");
+ if (cellData != null) {
+ for (Object rawCell : cellData) {
+ JSONObject cell = JSON.parseObject(JSON.toJSONString(rawCell));
+ JSONObject value = cell == null ? null : cell.getJSONObject("v");
+ int[] anchor = findMergedAnchor(row, column,
+ value == null ? null : value.getJSONObject("mc"));
+ if (anchor != null) {
+ return anchor;
+ }
+ }
+ }
+ return new int[]{row, column};
+ }
+
+ private int[] findMergedAnchor(int row, int column, Object rawMerge) {
+ if (rawMerge == null) {
+ return null;
+ }
+ JSONObject merge = rawMerge instanceof JSONObject
+ ? (JSONObject) rawMerge : JSON.parseObject(JSON.toJSONString(rawMerge));
+ Integer startRow = merge.getInteger("r");
+ Integer startColumn = merge.getInteger("c");
+ Integer rowSpan = merge.getInteger("rs");
+ Integer columnSpan = merge.getInteger("cs");
+ if (startRow == null || startColumn == null || rowSpan == null || columnSpan == null
+ || rowSpan < 1 || columnSpan < 1) {
+ return null;
+ }
+ if (row >= startRow && row < startRow + rowSpan
+ && column >= startColumn && column < startColumn + columnSpan) {
+ return new int[]{startRow, startColumn};
+ }
+ return null;
+ }
+
+ private int extendMergedRightEdge(int currentRightEdge, int row, int column, Object rawMerge) {
+ if (rawMerge == null) {
+ return currentRightEdge;
+ }
+ JSONObject merge = rawMerge instanceof JSONObject
+ ? (JSONObject) rawMerge : JSON.parseObject(JSON.toJSONString(rawMerge));
+ Integer startRow = merge.getInteger("r");
+ Integer startColumn = merge.getInteger("c");
+ Integer rowSpan = merge.getInteger("rs");
+ Integer columnSpan = merge.getInteger("cs");
+ if (startRow == null || startColumn == null || rowSpan == null || columnSpan == null
+ || rowSpan < 1 || columnSpan < 1) {
+ return currentRightEdge;
+ }
+ int endRow = startRow + rowSpan - 1;
+ int endColumn = startColumn + columnSpan - 1;
+ if (row >= startRow && row <= endRow && column >= startColumn && column <= endColumn) {
+ return Math.max(currentRightEdge, endColumn);
+ }
+ return currentRightEdge;
}
/**
@@ -794,7 +893,7 @@
}
/**
- * 鐩寸粦妯℃澘璁㈠崟鍙牎楠屾ā鏉夸腑鏍囪涓衡�滃鍑哄�尖�濈殑鍗曞厓鏍硷紝涓嶄娇鐢ㄦ楠岄」鐘舵�佹垨 last_value 鍒ゅ畾銆�
+ * 鐩寸粦妯℃澘璁㈠崟鍙牎楠屾瘡涓�滃鍑哄�尖�濇壒娉ㄦ墍鍦ㄥ尯鍩熷彸渚х揣閭诲崟鍏冩牸锛屼笉浣跨敤妫�楠岄」鐘舵�佹垨 last_value 鍒ゅ畾銆�
*/
private List<String> getMissingTemplateExportValues(Integer orderId) {
List<InsOrderStandardTemplate> snapshots = insOrderStandardTemplateService.list(
@@ -820,12 +919,12 @@
JSONObject recordValues = StrUtil.isBlank(snapshot.getRecordValues())
? new JSONObject() : JSON.parseObject(snapshot.getRecordValues());
- // 淇濆瓨鏃跺悓鏍峰彧鍙栨ā鏉夸腑鐨勭涓�涓鍑哄�硷紝鎻愪氦鏍¢獙涓庝繚瀛樺彛寰勪繚鎸佷竴鑷淬��
- String coordinate = coordinates.get(0);
- JSONObject cell = recordValues.getJSONObject(coordinate);
- Object value = cell == null ? null : cell.get("v");
- if (value == null || StringUtils.isBlank(String.valueOf(value))) {
- missing.add(templateName + "锛�" + coordinate + "锛�");
+ for (String coordinate : coordinates) {
+ JSONObject cell = recordValues.getJSONObject(coordinate);
+ Object value = cell == null ? null : cell.get("v");
+ if (value == null || StringUtils.isBlank(String.valueOf(value))) {
+ missing.add(templateName + "锛�" + coordinate + "锛�");
+ }
}
}
return missing;
@@ -1119,13 +1218,12 @@
.last("FOR UPDATE"));
boolean isInspectionReport = Objects.equals(INSPECTION_REPORT, reportType);
registerInsResults = isInspectionReport && Boolean.TRUE.equals(registerInsResults);
- // 1. 鍒ゆ柇鏄惁鏈夐噸澶嶇紪鍙�, 鏈夐噸澶嶇紪鍙峰仛鎻愰啋
+ // 1. 濮旀墭缂栧彿鍏ㄥ眬鍞竴锛屾彁浜ゅ鏍告椂鍐嶆鏍¢獙锛岄槻姝㈠苟鍙戞垨鍘嗗彶鏁版嵁缁曡繃鐢熸垚鏍¢獙銆�
Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
- .ne(InsOrder::getState, -1)
- .ne(InsOrder::getIfsInventoryId, order.getIfsInventoryId())
+ .ne(InsOrder::getId, orderId)
.eq(InsOrder::getEntrustCode, order.getEntrustCode()));
if (codeCount > 0) {
- throw new ErrorException("褰撳墠缂栧彿鏈夐噸澶�, 璇峰厛鍘讳慨鏀归噸澶嶇紪鍙�");
+ throw new ErrorException("鏍峰搧/濮旀墭鍗曞凡瀛樺湪锛岃纭鏍峰搧缂栧彿");
}
// 2. 鍒ゆ柇璇ヨ鍗曟槸鍚︽槸绗竴娆$敓浜�(鍚庣画鎶ュ憡鐢熸垚鍙彇绗竴娆℃彁浜ゆ椂闂�)
@@ -1532,6 +1630,10 @@
refreshed.setRecordValues(templateRecordValuesMap.get(templateId));
refreshed.setTemperature(templateTemperatureMap.get(templateId));
refreshed.setHumidity(templateHumidityMap.get(templateId));
+ // 鍒锋柊妯℃澘缁撴瀯鏃跺繀椤讳繚鐣欐楠岄樁娈靛~鍐欑殑涓氬姟鏁版嵁锛岄伩鍏嶈繘鍏ュ鏍稿悗鍥炴樉涓虹┖銆�
+ refreshed.setDetectionTime(oldSnapshot == null ? null : oldSnapshot.getDetectionTime());
+ refreshed.setDetectionPlace(oldSnapshot == null ? null : oldSnapshot.getDetectionPlace());
+ refreshed.setInsResult(oldSnapshot == null ? null : oldSnapshot.getInsResult());
Integer templateSort = templateSortMap.get(templateId);
refreshed.setSort(templateSort == null ? nextTemplateSort++ : templateSort);
refreshedSnapshots.add(refreshed);
@@ -1586,12 +1688,13 @@
InsReport existingReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
.eq(InsReport::getInsOrderId, orderId)
.last("limit 1"));
+ boolean directTemplateOrder = isDirectTemplateOrder(orderId);
if (currentState != null && Objects.equals(currentState.getInsState(), 5)
- && existingReport != null && StringUtils.isNotBlank(existingReport.getUrl())) {
+ && existingReport != null && StringUtils.isNotBlank(existingReport.getUrl())
+ && (!directTemplateOrder || StringUtils.isNotBlank(existingReport.getInspectionUrl()))) {
// 闃叉澶嶆牳椤甸潰閲嶅鐐瑰嚮鎴栫綉缁滈噸璇曢噸澶嶇敓鎴愭姤鍛娿�侀噸澶嶅彂璧锋姤鍛婂鎵广��
return 1;
}
- boolean directTemplateOrder = isDirectTemplateOrder(orderId);
if (directTemplateOrder && Objects.equals(type, 1)
&& !Objects.equals(dto.getInsResult(), 0) && !Objects.equals(dto.getInsResult(), 1)) {
throw new ErrorException("璇烽�夋嫨妫�楠屽崟缁撹");
@@ -1640,15 +1743,22 @@
.eq(InsOrder::getId, orderId)
.set(InsOrder::getInsState, 5));
- // 妫�楠屼汉鍛樻彁浜ゅ鏍告椂涓嶅啀鐢熸垚鎶ュ憡锛涗粎鍦ㄥ叏閮ㄨ瘯楠屽澶嶆牳閫氳繃鍚庣敓鎴愭娴嬫姤鍛娿��
+ // 妫�楠屼汉鍛樻彁浜ゅ鏍告椂涓嶇敓鎴愭姤鍛婏紱鍏ㄩ儴璇曢獙瀹ゅ鏍搁�氳繃鍚庣敓鎴愭姤鍛娿��
if (report == null || StringUtils.isBlank(report.getUrl())) {
this.generateReport(orderId, DETECTION_REPORT, writeUserId);
- report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
- .eq(InsReport::getInsOrderId, orderId)
- .last("limit 1"));
}
+ // 鐩寸粦妯℃澘璁㈠崟鍚屾椂鐢熸垚妫�楠屾姤鍛婏紝涓や唤鏂囦欢鍏辩敤鍚屼竴鏉″鎵硅褰曘��
+ if (directTemplateOrder && (report == null || StringUtils.isBlank(report.getInspectionUrl()))) {
+ this.generateReport(orderId, INSPECTION_REPORT, writeUserId);
+ }
+ report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
+ .eq(InsReport::getInsOrderId, orderId)
+ .last("limit 1"));
if (report == null || StringUtils.isBlank(report.getUrl())) {
throw new ErrorException("妫�娴嬫姤鍛婄敓鎴愬け璐�");
+ }
+ if (directTemplateOrder && StringUtils.isBlank(report.getInspectionUrl())) {
+ throw new ErrorException("妫�楠屾姤鍛婄敓鎴愬け璐�");
}
if (report.getTempUrlPdf() == null) {
String tempUrlPdf = this.wordToPdfTemp(report.getUrl().replace("/word", wordUrl));
@@ -1798,6 +1908,101 @@
throw new ErrorException("鎵句笉鍒板綋鍓嶆楠屼换鍔$殑妫�楠屼汉锛屾棤娉曠敓鎴愭娴嬫姤鍛�");
}
return inspector.getUserId();
+ }
+
+ /**
+ * 閲嶆柊鐢熸垚灏氭湭鎵瑰噯鐨勭郴缁熸姤鍛婏紝骞舵仮澶嶅凡瀛樺湪鐨勭紪鍒躲�佸鏍哥鍚嶃��
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void regenerateReport(Integer reportId, Integer createOrderUser) {
+ if (reportId == null) {
+ throw new ErrorException("鎶ュ憡涓嶈兘涓虹┖");
+ }
+ InsReport accessibleReport = insReportMapper.selectDownloadableReport(reportId, createOrderUser);
+ if (accessibleReport == null) {
+ throw new ErrorException("鎶ュ憡涓嶅瓨鍦ㄣ�佸皻鏈敓鎴愭垨鏃犳潈鎿嶄綔");
+ }
+ // 鏁版嵁搴撹閿侀伩鍏嶅悓涓�鎶ュ憡琚浜哄悓鏃堕噸鏂扮敓鎴愬苟瑕嗙洊銆�
+ InsReport report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
+ .eq(InsReport::getId, reportId)
+ .last("FOR UPDATE"));
+ if (report == null) {
+ throw new ErrorException("鎶ュ憡涓嶅瓨鍦�");
+ }
+ if (Objects.equals(report.getIsRatify(), 1)) {
+ throw new ErrorException("宸叉壒鍑嗘姤鍛婁笉鑳介噸鏂扮敓鎴�");
+ }
+ if (StringUtils.isNotBlank(report.getUrlS())) {
+ throw new ErrorException("褰撳墠鎶ュ憡宸叉墜鍔ㄤ笂浼狅紝璇峰厛杩樺師涓虹郴缁熸姤鍛婂悗鍐嶉噸鏂扮敓鎴�");
+ }
+ if (report.getInsOrderId() == null) {
+ throw new ErrorException("鎶ュ憡鏈叧鑱旀楠屽崟锛屾棤娉曢噸鏂扮敓鎴�");
+ }
+
+ Integer reportType = report.getReportType() == null ? DETECTION_REPORT : report.getReportType();
+ Integer writeUserId = report.getWriteUserId() == null
+ ? SecurityUtils.getUserId().intValue() : report.getWriteUserId();
+ boolean directTemplateOrder = isDirectTemplateOrder(report.getInsOrderId());
+ if (directTemplateOrder) {
+ generateReport(report.getInsOrderId(), DETECTION_REPORT, writeUserId);
+ generateReport(report.getInsOrderId(), INSPECTION_REPORT, writeUserId);
+ } else {
+ generateReport(report.getInsOrderId(), reportType, writeUserId);
+ }
+
+ InsReport regenerated = insReportMapper.selectById(reportId);
+ if (regenerated == null || StringUtils.isBlank(regenerated.getUrl())) {
+ throw new ErrorException("鎶ュ憡閲嶆柊鐢熸垚澶辫触");
+ }
+ if (directTemplateOrder && StringUtils.isBlank(regenerated.getInspectionUrl())) {
+ throw new ErrorException("妫�楠屾姤鍛婇噸鏂扮敓鎴愬け璐�");
+ }
+ String reportPath = regenerated.getUrl().replace("/word", wordUrl);
+ Map<String, Object> marks = buildExistingReportMarks(report);
+ if (!marks.isEmpty()) {
+ insReportService.wordInsertUrl(marks, reportPath);
+ if (StringUtils.isNotBlank(regenerated.getInspectionUrl())) {
+ insReportService.wordInsertUrl(marks,
+ regenerated.getInspectionUrl().replace("/word", wordUrl));
+ }
+ }
+ String tempPdfName = wordToPdfTemp(reportPath);
+ if (StringUtils.isBlank(tempPdfName)) {
+ throw new ErrorException("鎶ュ憡棰勮鏂囦欢鐢熸垚澶辫触");
+ }
+ // generateReport 浼氬啓鍏ュ綋鍓嶆椂闂达紱閲嶆柊鐢熸垚涓嶅簲鏀瑰彉鍘熷鎵硅褰曟椂闂淬��
+ insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate()
+ .eq(InsReport::getId, reportId)
+ .set(InsReport::getWriteTime, report.getWriteTime())
+ .set(InsReport::getTempUrlPdf, "/word/" + tempPdfName));
+ }
+
+ private Map<String, Object> buildExistingReportMarks(InsReport report) {
+ Map<String, Object> marks = new HashMap<>();
+ boolean submitted = Objects.equals(report.getState(), 1)
+ || report.getIsExamine() != null
+ || report.getExamineTime() != null;
+ if (submitted) {
+ User writer = getReportSigner(report.getWriteUserId(), "缂栧埗浜�");
+ marks.put("writeUrl", ReportSignaturePictureUtils.create(imgUrl, writer.getSignatureUrl()));
+ marks.put("writeDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(report.getWriteTime())).create());
+ marks.put("insUrl", ReportSignaturePictureUtils.create(imgUrl, writer.getSignatureUrl()));
+ }
+ if (Objects.equals(report.getIsExamine(), 1)) {
+ User examiner = getReportSigner(report.getExamineUserId(), "瀹℃牳浜�");
+ marks.put("examineUrl", ReportSignaturePictureUtils.create(imgUrl, examiner.getSignatureUrl()));
+ marks.put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(report.getExamineTime())).create());
+ }
+ return marks;
+ }
+
+ private User getReportSigner(Integer userId, String roleName) {
+ User user = userId == null ? null : userMapper.selectById(userId);
+ if (user == null || StringUtils.isBlank(user.getSignatureUrl())) {
+ throw new ErrorException("鎵句笉鍒�" + roleName + "鐨勭鍚�");
+ }
+ return user;
}
/**
@@ -2331,13 +2536,18 @@
enterFactoryReport.setLotBatchNo(ifsInventoryQuantity.getUpdateBatchNo());
// 妫�娴嬩緷鎹�
- Set<String> standardMethod = new HashSet<>();
+ Set<String> standardMethod = new LinkedHashSet<>();
StringBuilder standardMethod2 = new StringBuilder();
- standardMethod.add(baseMapper.getStandardMethodCode(insSample.getStandardMethodListId()));
+ String reportStandardMethod = baseMapper.getStandardMethodReportText(insSample.getStandardMethodListId());
+ if (StringUtils.isNotBlank(reportStandardMethod)) {
+ standardMethod.add(reportStandardMethod);
+ }
for (String s : standardMethod) {
standardMethod2.append("銆�").append(s);
}
- standardMethod2.replace(0, 1, "");
+ if (standardMethod2.length() > 0) {
+ standardMethod2.deleteCharAt(0);
+ }
// 鏍峰搧绫诲瀷
String orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE, insOrder.getOrderType());
@@ -3009,7 +3219,7 @@
insReport.setReportType(reportType);
boolean showResult = Objects.equals(reportType, INSPECTION_REPORT);
List<Map<String, Object>> tables = new ArrayList<>();
- Set<String> standardMethod = new HashSet<>();
+ Set<String> standardMethod = new LinkedHashSet<>();
Set<String> deviceSet = new HashSet<>();
Set<String> models = new HashSet<>();
// 鏌ヨ妫�楠岄」鏁伴噺
@@ -3022,11 +3232,13 @@
/*鍩虹鎶ュ憡(鏍规嵁缁樺埗鐨勫師濮嬭褰曟ā鐗堝舰鎴�)*/
samples.forEach(a -> {
models.add(a.getModel());
- String standardMethodCode = baseMapper.getStandardMethodCode(a.getStandardMethodListId());
- if (StrUtil.isNotBlank(a.getSpecialStandardMethod())) {
- standardMethodCode = standardMethodCode + "+" + a.getSpecialStandardMethod();
+ String standardMethodCode = baseMapper.getStandardMethodReportText(a.getStandardMethodListId());
+ if (StrUtil.isNotBlank(standardMethodCode)) {
+ if (StrUtil.isNotBlank(a.getSpecialStandardMethod())) {
+ standardMethodCode = standardMethodCode + "+" + a.getSpecialStandardMethod();
+ }
+ standardMethod.add(standardMethodCode);
}
- standardMethod.add(standardMethodCode);
for (InsProduct b : a.getInsProduct()) {
if (b.getInsProductResult() != null) {
List<JSONObject> jsonObjects = JSON.parseArray(b.getInsProductResult().getEquipValue(), JSONObject.class);
@@ -3038,9 +3250,9 @@
}
}
}
- // 鏂扮増妫�娴嬫姤鍛婄洿鎺ヤ娇鐢ㄥ浐瀹氬洓鍒楃粨鏋滆锛屼笉鍐嶆瀯閫犳棫鐗堝彲鍙樺垪 TableRenderData銆�
- // 妫�楠屾姤鍛婁粛娌跨敤涓嬫柟鍘熸湁鐨勫ぇ琛ㄦ牸閫昏緫銆�
- if (!showResult) {
+ // 鐩寸粦妯℃澘鐨勬娴嬫姤鍛娿�佹楠屾姤鍛婇兘浣跨敤鏂扮増鍥哄畾缁撴灉琛岋紝涓嶅啀杩涘叆鏃х増妫�楠岄」琛ㄦ牸閫昏緫銆�
+ // 鐩寸粦妯℃澘涓殑鎵胯浇璁板綍娌℃湁鏃ф楠岄」瀛楁锛岃繘鍏ユ棫閫昏緫浼氬湪鏍煎紡鍖栨椂浜х敓绌烘寚閽堛��
+ if (!showResult || directTemplateOrder) {
return;
}
// 鏀舵牱鏃ユ湡
@@ -3372,9 +3584,14 @@
if (firstInspectDate == null) {
firstInspectDate = insOrder.getSendTime();
}
+ if (firstInspectDate == null) {
+ firstInspectDate = submitTime;
+ }
String insTime = firstInspectDate.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�")) + "-"
+ submitTime.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"));
+ String testStartDate = firstInspectDate.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"));
+ String testEndDate = submitTime.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"));
String insTimeEn = monthNames[firstInspectDate.getMonthValue() - 1] + " " + firstInspectDate.format(DateTimeFormatter.ofPattern("dd, yyyy")) + "-"
+ monthNames[submitTime.getMonthValue() - 1] + " " + submitTime.format(DateTimeFormatter.ofPattern("dd, yyyy"));
@@ -3431,11 +3648,8 @@
productionDate = insOrder.getProductionDate().format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"));
}
batchNo = defaultReportText(insOrder.getProductionBatch(), "/");
- standardMethodText = templateSnapshots.stream()
- .map(InsOrderStandardTemplate::getRemark)
- .filter(StringUtils::isNotBlank)
- .distinct()
- .collect(Collectors.joining("锛�"));
+ standardMethodText = defaultReportText(
+ baseMapper.getStandardMethodReportTextByCode(insOrder.getSample()), insOrder.getSample());
}
boolean containsOrganicChlorine = detectionResultRows.stream()
.map(row -> row.get("itemName"))
@@ -3445,8 +3659,9 @@
? "寰簱浠戞硶锛屾湁鏈烘隘鍚噺灏忎簬0.005%鏃讹紝浠ユ湭妫�鍑烘姤鍑恒��"
: defaultReportText(insOrder.getRemark(), "/");
- // 妫�娴嬫姤鍛婂拰妫�楠屾姤鍛婄粺涓�浣跨敤鏂扮増鎶ュ憡妯℃澘
- String templateName = "/static/detection-report-template-v2.docx";
+ String templateName = showResult
+ ? "/static/inspection-report-template-v2.docx"
+ : "/static/detection-report-template-v2.docx";
InputStream inputStream = this.getClass().getResourceAsStream(templateName);
if (inputStream == null) {
throw new RuntimeException("鎵句笉鍒版姤鍛婃ā鏉�: " + templateName);
@@ -3523,6 +3738,8 @@
put("batch", finalBatchNo);
put("phone", defaultReportText(insOrder.getPhone(), "/"));
put("testDate", insTime);
+ put("testStartDate", testStartDate);
+ put("testEndDate", testEndDate);
put("entrustNo", defaultReportText(insOrder.getEntrustCode(), "/"));
put("sampling", "/");
put("standard", finalStandardMethodText);
@@ -3533,7 +3750,7 @@
put("resultNote", finalResultRemark);
}});
try {
- String name = insReport.getCode().replace("/", "") + (showResult ? ".docx" : "-C.docx");
+ String name = insReport.getCode().replace("/", "") + (showResult ? "-J.docx" : "-C.docx");
Files.createDirectories(Paths.get(wordUrl));
template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl, name)));
insReport.setUrl("/word/" + name);
@@ -3550,6 +3767,22 @@
InsReport existing = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
.eq(InsReport::getInsOrderId, report.getInsOrderId())
.last("limit 1"));
+ if (Objects.equals(report.getReportType(), INSPECTION_REPORT)) {
+ String inspectionUrl = report.getUrl();
+ if (existing == null) {
+ report.setReportType(DETECTION_REPORT);
+ report.setUrl(null);
+ report.setInspectionUrl(inspectionUrl);
+ insReportMapper.insert(report);
+ } else {
+ insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate()
+ .eq(InsReport::getId, existing.getId())
+ .set(InsReport::getInspectionUrl, inspectionUrl)
+ .set(InsReport::getWriteUserId, report.getWriteUserId())
+ .set(InsReport::getWriteTime, report.getWriteTime()));
+ }
+ return;
+ }
if (existing == null) {
insReportMapper.insert(report);
return;
@@ -3591,6 +3824,7 @@
row.put("itemName", itemName);
row.put("unit", defaultReportText(product.getUnit(), "/"));
row.put("result", defaultReportText(product.getLastValue(), "/"));
+ row.put("inspectionConclusion", formatInspectionConclusion(product.getInsResult()));
rows.add(row);
}
}
@@ -3598,7 +3832,7 @@
}
/**
- * 鏂拌仛鐩寸粦妯℃澘璁㈠崟锛氫竴涓ā鏉块〉绛惧湪鎶ュ憡涓彧瀵瑰簲涓�鏉℃娴嬮」鐩��
+ * 鏂拌仛鐩寸粦妯℃澘璁㈠崟锛氭ā鏉夸腑姣忎竴涓�滃鍑哄�尖�濇壒娉ㄩ兘瀵瑰簲鎶ュ憡涓殑涓�鏉℃娴嬮」鐩��
*/
private List<Map<String, String>> buildTemplateDetectionResultRows(Integer orderId) {
List<InsOrderStandardTemplate> snapshots = insOrderStandardTemplateService.list(
@@ -3608,27 +3842,30 @@
List<Map<String, String>> rows = new ArrayList<>();
int sequence = 1;
for (InsOrderStandardTemplate snapshot : snapshots) {
- TemplateExportCell exportCell = getFirstTemplateExportCell(snapshot.getThing());
+ List<TemplateExportCell> exportCells = getTemplateExportCells(snapshot.getThing());
JSONObject recordValues = StrUtil.isBlank(snapshot.getRecordValues())
? new JSONObject() : JSON.parseObject(snapshot.getRecordValues());
- String result = readTemplateCellText(recordValues, exportCell.resultCoordinate, exportCell.templateValues);
- if (StringUtils.isBlank(result)) {
- throw new ErrorException("妯℃澘鈥�" + defaultReportText(snapshot.getName(), "妯℃澘ID " + snapshot.getTemplateId())
- + "鈥濈殑瀵煎嚭鍊间笉鑳戒负绌�");
- }
- String unit = exportCell.unitCoordinate == null ? null
- : readTemplateCellText(recordValues, exportCell.unitCoordinate, exportCell.templateValues);
- String itemName = exportCell.itemCoordinate == null ? null
- : readTemplateCellText(recordValues, exportCell.itemCoordinate, exportCell.templateValues);
+ for (TemplateExportCell exportCell : exportCells) {
+ String result = readTemplateCellText(recordValues, exportCell.resultCoordinate, exportCell.templateValues);
+ if (StringUtils.isBlank(result)) {
+ throw new ErrorException("妯℃澘鈥�" + defaultReportText(snapshot.getName(), "妯℃澘ID " + snapshot.getTemplateId())
+ + "鈥濈殑瀵煎嚭鍊间笉鑳戒负绌猴紙" + exportCell.resultCoordinate + "锛�");
+ }
+ String unit = exportCell.unitCoordinate == null ? null
+ : readTemplateCellText(recordValues, exportCell.unitCoordinate, exportCell.templateValues);
+ String itemName = exportCell.itemCoordinate == null ? null
+ : readTemplateCellText(recordValues, exportCell.itemCoordinate, exportCell.templateValues);
- Map<String, String> row = new LinkedHashMap<>();
- row.put("seq", String.valueOf(sequence++));
- String reportItemName = defaultReportText(itemName,
- defaultReportText(snapshot.getName(), "妯℃澘ID " + snapshot.getTemplateId()));
- row.put("itemName", formatExportItemName(reportItemName));
- row.put("unit", defaultReportText(unit, "/"));
- row.put("result", result);
- rows.add(row);
+ Map<String, String> row = new LinkedHashMap<>();
+ row.put("seq", String.valueOf(sequence++));
+ String reportItemName = defaultReportText(itemName,
+ defaultReportText(snapshot.getName(), "妯℃澘ID " + snapshot.getTemplateId()));
+ row.put("itemName", formatExportItemName(reportItemName));
+ row.put("unit", defaultReportText(unit, "/"));
+ row.put("result", result);
+ row.put("inspectionConclusion", formatInspectionConclusion(snapshot.getInsResult()));
+ rows.add(row);
+ }
}
if (rows.isEmpty()) {
throw new ErrorException("褰撳墠璁㈠崟鏈壘鍒板彲鐢熸垚鎶ュ憡鐨勫師濮嬭褰曟ā鏉�");
@@ -3636,7 +3873,17 @@
return rows;
}
- private TemplateExportCell getFirstTemplateExportCell(String compressedThing) {
+ private static String formatInspectionConclusion(Integer insResult) {
+ if (Objects.equals(insResult, 1)) {
+ return "鍚堟牸";
+ }
+ if (Objects.equals(insResult, 0)) {
+ return "涓嶅悎鏍�";
+ }
+ return "/";
+ }
+
+ private List<TemplateExportCell> getTemplateExportCells(String compressedThing) {
if (StrUtil.isBlank(compressedThing)) {
throw new ErrorException("鍘熷璁板綍妯℃澘涓虹┖");
}
@@ -3646,9 +3893,8 @@
} catch (Exception ignored) {
thing = compressedThing;
}
- JSONArray cellData = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0).getJSONArray("celldata");
- Integer resultColumn = null;
- Integer itemColumn = null;
+ JSONObject sheet = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0);
+ JSONArray cellData = sheet.getJSONArray("celldata");
Integer unitColumn = null;
List<int[]> exportCells = new ArrayList<>();
Map<String, String> templateValues = new HashMap<>();
@@ -3662,13 +3908,6 @@
}
String displayValue = value.get("v") == null ? null : String.valueOf(value.get("v"));
templateValues.put(row + "-" + column, displayValue);
- if (resultColumn == null && "妫�楠岀粨鏋�".equals(StringUtils.trim(displayValue))) {
- resultColumn = column;
- }
- if (itemColumn == null && ("妫�娴嬮」鐩�".equals(StringUtils.trim(displayValue))
- || "妫�楠岄」鐩�".equals(StringUtils.trim(displayValue)))) {
- itemColumn = column;
- }
if (unitColumn == null && "鍗曚綅".equals(StringUtils.trim(displayValue))) {
unitColumn = column;
}
@@ -3681,17 +3920,16 @@
throw new ErrorException("妯℃澘蹇呴』鑷冲皯閰嶇疆涓�涓鍑哄�兼壒娉�");
}
exportCells.sort(Comparator.comparingInt((int[] cell) -> cell[0]).thenComparingInt(cell -> cell[1]));
- int[] firstExport = exportCells.get(0);
- int resultColumnForRow = resultColumn == null ? firstExport[1] : resultColumn;
- // 閫氬父鈥滃鍑哄�尖�濇壒娉ㄩ厤缃湪椤圭洰鍚嶇О鍗曞厓鏍硷紱鑻ラ厤缃湪缁撴灉鍗曞厓鏍硷紝鍒欏洖鍒扳�滄娴嬮」鐩�濆垪鍙栧悕绉般��
- Integer itemColumnForRow = !Objects.equals(firstExport[1], resultColumnForRow)
- ? firstExport[1] : itemColumn;
- TemplateExportCell result = new TemplateExportCell();
- result.resultCoordinate = firstExport[0] + "-" + resultColumnForRow;
- result.itemCoordinate = itemColumnForRow == null ? null : firstExport[0] + "-" + itemColumnForRow;
- result.unitCoordinate = unitColumn == null ? null : firstExport[0] + "-" + unitColumn;
- result.templateValues = templateValues;
- return result;
+ List<TemplateExportCell> results = new ArrayList<>();
+ for (int[] exportCell : exportCells) {
+ TemplateExportCell result = new TemplateExportCell();
+ result.resultCoordinate = getRightAdjacentCoordinate(sheet, exportCell[0], exportCell[1]);
+ result.itemCoordinate = exportCell[0] + "-" + exportCell[1];
+ result.unitCoordinate = unitColumn == null ? null : exportCell[0] + "-" + unitColumn;
+ result.templateValues = templateValues;
+ results.add(result);
+ }
+ return results;
}
private String readTemplateCellText(JSONObject recordValues, String coordinate, Map<String, String> templateValues) {
@@ -5134,7 +5372,7 @@
}
}
// 鍒ゆ柇鏄惁鏄暟瀛楃被鍨�
- if (sampleProductDto2.getInspectionValueType().equals("1")) {
+ if ("1".equals(sampleProductDto2.getInspectionValueType())) {
// 鎶婃楠屽唴瀹瑰鏋滄纭寲鐐瑰拰鐒︾儳鏃堕棿鎶� . 鍒囧壊鎴� :
String lastValue = sampleProductDto2.getLastValue();
if (sampleProductDto2.getInspectionItem().contains("姝g~鍖栫偣") || sampleProductDto2.getInspectionItem().contains("鐒︾儳鏃堕棿")) {
--
Gitblit v1.9.3