From 5a90ac8955f198f21954a3dca0443d1c5892bf0b Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期二, 03 十一月 2026 18:08:29 +0800
Subject: [PATCH] 成品下单批量下单接口与检验委托单批次合并(batch_no),含数据库加列脚本
---
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java | 89 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 1 deletions(-)
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
index 2820bd8..891bdac 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -302,6 +302,9 @@
@Override
@Transactional(rollbackFor = Exception.class)
public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder) {
+ if (insOrder == null || insOrder.getSampleDate() == null) {
+ throw new ErrorException("閫佹牱鏃ユ湡涓嶈兘涓虹┖");
+ }
// todo: 涓嬪崟鍒ゆ柇鎶芥牱璁″垝鐨勫敮涓�鎬�
if (insOrder.getQuarterItemId() != null) {
Long quarterItemCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
@@ -504,6 +507,64 @@
@Override
@Transactional(rollbackFor = Exception.class)
public int addNewJuInsOrder(InsPlaceOrderDto dto) {
+ return createNewJuOrder(dto, null, false);
+ }
+
+ /**
+ * 鎵归噺涓嬪崟锛氬叕鍏卞鎵樹俊鎭彧濉竴娆★紝鍚庡彴鎸夋牱鍝侀�愭潯鎷嗘垚鐙珛濮旀墭鍗曞苟鍏变韩鎵规鍙枫��
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int addBatchNewJuInsOrder(InsBatchPlaceOrderDto dto) {
+ if (dto == null || dto.getInsOrder() == null) {
+ throw new ErrorException("涓嬪崟淇℃伅涓嶈兘涓虹┖");
+ }
+ List<InsBatchSampleDto> rows = dto.getSampleList();
+ if (CollectionUtils.isEmpty(rows)) {
+ throw new ErrorException("璇疯嚦灏戞坊鍔犱竴涓牱鍝�");
+ }
+ // 鍙湁涓�涓牱鍝佹椂鎸夋櫘閫氬崟鏍峰搧涓嬪崟澶勭悊锛屼笉浜х敓鎵规
+ if (rows.size() == 1) {
+ return createNewJuOrder(buildBatchRowOrder(dto.getInsOrder(), rows.get(0)), null, false);
+ }
+ String batchNo = "PC" + DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
+ int firstOrderId = 0;
+ for (InsBatchSampleDto row : rows) {
+ int orderId = createNewJuOrder(buildBatchRowOrder(dto.getInsOrder(), row), batchNo, true);
+ if (firstOrderId == 0) {
+ firstOrderId = orderId;
+ }
+ }
+ return firstOrderId;
+ }
+
+ private InsPlaceOrderDto buildBatchRowOrder(InsOrder common, InsBatchSampleDto row) {
+ if (common == null || row == null) {
+ throw new ErrorException("涓嬪崟淇℃伅涓嶈兘涓虹┖");
+ }
+ if (row.getStandardTreeId() == null) {
+ throw new ErrorException("璇蜂负姣忎釜鏍峰搧閫夋嫨妫�娴嬩緷鎹�");
+ }
+ if (StringUtils.isBlank(row.getSampleCode()) || row.getSampleCode().trim().length() < 2) {
+ throw new ErrorException("鏍峰搧缂栧彿涓嶈兘涓虹┖涓斾笉鑳藉皯浜�2浣�");
+ }
+ InsOrder order = new InsOrder();
+ BeanUtils.copyProperties(common, order);
+ order.setId(null);
+ order.setEntrustCode(null);
+ order.setBatchNo(null);
+ order.setSampleView(row.getSampleView());
+ order.setTestQuantity(row.getTestQuantity());
+ order.setSampleStatus(row.getSampleStatus());
+ InsPlaceOrderDto single = new InsPlaceOrderDto();
+ single.setInsOrder(order);
+ single.setStandardTreeId(row.getStandardTreeId());
+ single.setSampleCode(row.getSampleCode());
+ single.setTemplateList(row.getTemplateList());
+ return single;
+ }
+
+ private int createNewJuOrder(InsPlaceOrderDto dto, String batchNo, boolean batchEntrustFallback) {
if (dto == null || dto.getInsOrder() == null || dto.getStandardTreeId() == null) {
throw new ErrorException("涓嬪崟淇℃伅鎴栨爣鍑嗕笉鑳戒负绌�");
}
@@ -595,6 +656,7 @@
InsOrder order = dto.getInsOrder();
order.setId(null);
+ order.setBatchNo(StringUtils.isBlank(batchNo) ? null : batchNo);
// 鏂拌仛涓嬪崟鍏嶅鏍革細鐩存帴鍙楃悊锛屼笅鍗曞嵆娴佽浆鍒版牱鍝佹帴鏀�
order.setState(1);
order.setExamineTime(LocalDateTime.now());
@@ -655,6 +717,10 @@
// 涓嬪崟鏃剁敓鎴愬鎵樼紪鍙峰苟鏍¢獙鍞竴鎬э紝閲嶅鍒欐彁绀猴紝閬垮厤鐣欏埌瀹℃牳鎵嶆姤閿欍��
String entrustCode = buildEntrustCode(order, Collections.singletonList(sample));
+ if (batchEntrustFallback && isEntrustCodeUsed(entrustCode)) {
+ // 鎵归噺涓嬪崟鏃朵笉鍚屾牱鍝佺紪鍙锋湯涓や綅鍙兘鐩稿悓锛屾敼鐢ㄥ綋澶╅『寤剁紪鍙峰厹搴�
+ entrustCode = buildNextAvailableEntrustCode(order);
+ }
assertEntrustCodeUnique(entrustCode, order.getId());
insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
.eq(InsOrder::getId, order.getId())
@@ -846,6 +912,7 @@
snapshot.setTemplateId(template.getId());
snapshot.setName(template.getName());
snapshot.setNumber(template.getNumber());
+ snapshot.setStandardRequirement(template.getStandardRequirement());
snapshot.setRemark(template.getRemark());
snapshot.setThing(template.getThing());
snapshot.setSort(selection.getSort());
@@ -1046,6 +1113,23 @@
}
}
+ private boolean isEntrustCodeUsed(String entrustCode) {
+ return StringUtils.isNotBlank(entrustCode) && insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
+ .eq(InsOrder::getEntrustCode, entrustCode)) > 0;
+ }
+
+ private String buildNextAvailableEntrustCode(InsOrder order) {
+ LocalDate entrustDate = order.getSampleDate() == null ? LocalDate.now() : order.getSampleDate();
+ String prefix = "LMSY-" + entrustDate.format(DateTimeFormatter.BASIC_ISO_DATE) + "-";
+ for (int seq = 1; seq <= 99; seq++) {
+ String candidate = prefix + String.format("%02d", seq);
+ if (!isEntrustCodeUsed(candidate)) {
+ return candidate;
+ }
+ }
+ throw new ErrorException("褰撳ぉ濮旀墭缂栧彿宸茬敤灏斤紝璇疯皟鏁存牱鍝佺紪鍙�");
+ }
+
/**
* 鐢熸垚濮旀墭缂栧彿锛氭柊鑱氱洿缁戞ā鏉胯鍗曟湯涓や綅鍙栨牱鍝佺紪鍙锋湯涓や綅锛屽叾浣欐寜閫佹牱鏃ユ湡鐢熸垚搴忓彿銆�
*/
@@ -1091,6 +1175,7 @@
.select(InsOrderStandardTemplate::getTemplateId,
InsOrderStandardTemplate::getTemperature,
InsOrderStandardTemplate::getDetectionTime,
+ InsOrderStandardTemplate::getDetectionEndTime,
InsOrderStandardTemplate::getDetectionPlace,
InsOrderStandardTemplate::getInsResult)
.orderByAsc(InsOrderStandardTemplate::getSort,
@@ -1100,6 +1185,8 @@
condition.setTemplateId(snapshot.getTemplateId());
condition.setTemperature(snapshot.getTemperature());
condition.setDetectionTime(snapshot.getDetectionTime());
+ condition.setDetectionEndTime(snapshot.getDetectionEndTime() == null
+ ? snapshot.getDetectionTime() : snapshot.getDetectionEndTime());
condition.setDetectionPlace(snapshot.getDetectionPlace());
condition.setInsResult(snapshot.getInsResult());
condition.setDeviceIds(templateDeviceIds.getOrDefault(
@@ -1799,7 +1886,7 @@
List<String> unqualifiedList = insProductMapper.selectUnqualifiedList(orderDto.getId());
orderDto.setUnqualifiedItem(CollUtil.join(unqualifiedList, ","));
}
- orderDto.setCreateTimeString(orderDto.getCreateTime() == null ? "" : orderDto.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+ orderDto.setSampleDateString(orderDto.getSampleDate() == null ? "" : orderDto.getSampleDate().toString());
}
--
Gitblit v1.9.3