From a7cf1913c376b53f487f0ef8dfff084c5bc010a7 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期六, 17 十月 2026 11:19:12 +0800
Subject: [PATCH] feat(mes): 支持二维码导出任务的分段下载功能
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/bagcode/MesProBagCodeServiceImpl.java | 72 ++++++++++++++++++++++++++++--------
1 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/bagcode/MesProBagCodeServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/bagcode/MesProBagCodeServiceImpl.java
index ddd169b..b60d9f8 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/bagcode/MesProBagCodeServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/bagcode/MesProBagCodeServiceImpl.java
@@ -83,9 +83,9 @@
*/
private static final String UNIT_TYPE_TON = "鍚�";
/**
- * 璁¢噺鍗曚綅绫诲瀷銆孨鍗冨厠銆嶏細姣忔墭鐩樿 N 涓鐮�
+ * 璁¢噺鍗曚綅绫诲瀷銆孨琚嬨�嶏細姣忔墭鐩樿 N 涓鐮�
*/
- private static final Pattern KG_TYPE_PATTERN = Pattern.compile("^(\\d{1,5})鍗冨厠$");
+ private static final Pattern BAG_TYPE_PATTERN = Pattern.compile("^(\\d{1,5})琚�$");
@Resource
private MesCodeRedisDAO codeRedisDao;
@@ -99,9 +99,9 @@
MesMdmItemDO item = mdmItemService.validateItemExists(generateReqVO.getItemId());
String type = getUnitType(item);
- // 2. 鎸夌被鍨嬫崲绠楄鐮佹暟閲忥細N鍗冨厠 = 姣忔墭 N 琚� 脳 鎵樼洏鏁帮紱鍚� = 鐩存帴杈撳叆琚嬬爜鏁帮紙鏃犳墭鐩橈級
+ // 2. 鎸夌被鍨嬫崲绠楄鐮佹暟閲忥細N琚� = 姣忔墭 N 琚� 脳 鎵樼洏鏁帮紱鍚� = 鐩存帴杈撳叆琚嬬爜鏁帮紙鏃犳墭鐩橈級
boolean ton = UNIT_TYPE_TON.equals(type);
- int perPallet = ton ? 0 : parseKgPerPallet(type);
+ int perPallet = ton ? 0 : parseBagsPerPallet(type);
int totalCount;
int palletCount = 0;
if (ton) {
@@ -190,7 +190,7 @@
}
/**
- * 璇诲彇鍝佺涓昏閲忓崟浣嶇殑绫诲瀷锛�48鍗冨厠/100鍗冨厠/鍚級锛屾湭閰嶇疆鎴栨棤娉曡瘑鍒椂鎶ラ敊
+ * 璇诲彇鍝佺涓昏閲忓崟浣嶇殑绫诲瀷锛�48琚�/100琚�/鍚級锛屾湭閰嶇疆鎴栨棤娉曡瘑鍒椂鎶ラ敊
*/
private String getUnitType(MesMdmItemDO item) {
String type = null;
@@ -203,17 +203,17 @@
if (type == null) {
throw exception(PRO_BAG_CODE_ITEM_TYPE_NOT_CONFIGURED);
}
- if (!UNIT_TYPE_TON.equals(type) && !KG_TYPE_PATTERN.matcher(type).matches()) {
+ if (!UNIT_TYPE_TON.equals(type) && !BAG_TYPE_PATTERN.matcher(type).matches()) {
throw exception(PRO_BAG_CODE_ITEM_TYPE_NOT_CONFIGURED);
}
return type;
}
/**
- * 瑙f瀽銆孨鍗冨厠銆嶇被鍨嬪緱鍑烘瘡鎵樼洏琚嬫暟
+ * 瑙f瀽銆孨琚嬨�嶇被鍨嬪緱鍑烘瘡鎵樼洏琚嬫暟
*/
- private int parseKgPerPallet(String type) {
- Matcher matcher = KG_TYPE_PATTERN.matcher(type);
+ private int parseBagsPerPallet(String type) {
+ Matcher matcher = BAG_TYPE_PATTERN.matcher(type);
if (!matcher.matches()) {
throw exception(PRO_BAG_CODE_ITEM_TYPE_NOT_CONFIGURED);
}
@@ -223,7 +223,20 @@
@Override
@Transactional(rollbackFor = Exception.class)
public void bindBatch(MesProBagCodeBindBatchReqVO bindReqVO) {
- MesProBatchDO batch = batchMapper.selectByIdForUpdate(bindReqVO.getBatchId());
+ doBindBatch(bindReqVO.getBatchId(), bindReqVO.getIds());
+ }
+
+ /**
+ * 灏嗚鐮佸綍鍏ユ寚瀹氭壒娆★紝鍔犻攣椤哄簭涓恒�屾壒娆� 鈫� 琚嬬爜 鈫� 鎵樼洏銆嶃��
+ * <p>
+ * 銆屽綍鍏ユ壒娆°�嶄笌銆岀粦瀹氭墭鐩樸�嶅叡鐢ㄦ瀹炵幇锛氱粦瀹氭墭鐩樻椂鑻ユ墭鐩樺凡灞炴煇鎵规銆佽�屾墍閫夎鐮佸皻鏈綍鍏ユ壒娆★紝
+ * 鍏堟寜鏈柟娉曞畬鎴愬綍鍏ワ紝浠庤�屼繚璇佹壒娆″噯鍏ユ牎楠屻�佸搧绉嶄竴鑷存�ф牎楠屻�佹壒娆℃眹鎬诲洖鍐欎笌瀹屾暣鎬ц褰曞彧鏈変竴浠姐��
+ *
+ * @param batchId 鐢熶骇鎵规缂栧彿
+ * @param rawIds 寰呭綍鍏ョ殑琚嬬爜缂栧彿锛堟湭鍘婚噸锛�
+ */
+ private void doBindBatch(Long batchId, List<Long> rawIds) {
+ MesProBatchDO batch = batchMapper.selectByIdForUpdate(batchId);
if (batch == null) {
throw exception(PRO_BATCH_NOT_EXISTS);
}
@@ -234,7 +247,7 @@
if (StrUtil.isEmpty(batch.getCode())) {
throw exception(PRO_BATCH_NOT_FILLED);
}
- List<Long> ids = bindReqVO.getIds().stream().distinct().toList();
+ List<Long> ids = rawIds.stream().distinct().toList();
List<MesProBagCodeDO> bagCodes = bagCodeMapper.selectListByIdsForUpdate(ids);
if (bagCodes.size() != ids.size() || bagCodes.stream().anyMatch(code ->
code.getBatchId() != null
@@ -459,13 +472,40 @@
@Override
@Transactional(rollbackFor = Exception.class)
public void bindPallet(MesProBagCodeBindReqVO bindReqVO) {
- // 1. 閿佸畾鎵樼洏锛岄伩鍏嶄笌鑷姩褰掗泦骞跺彂淇敼琚嬫暟
+ // 1. 鏃犻攣棰勮鎵樼洏涓庢墍閫夎鐮侊紝鍒ゆ柇鏄惁闇�瑕佸厛涓烘湭褰曞叆鎵规鐨勮鐮佽ˉ褰曟壒娆°��
+ // 鍔犻攣椤哄簭蹇呴』涓庛�屽綍鍏ユ壒娆°�嶄竴鑷达紙鎵规 鈫� 琚嬬爜 鈫� 鎵樼洏锛夛紝鍚﹀垯涓や釜鍏ュ彛骞跺彂鏃朵氦鍙夌瓑寰呬細姝婚攣銆�
+ List<Long> ids = bindReqVO.getIds().stream().distinct().toList();
+ MesProPalletDO palletSnapshot = palletMapper.selectById(bindReqVO.getPalletId());
+ if (palletSnapshot == null) {
+ throw exception(PRO_PALLET_NOT_EXISTS);
+ }
+ List<MesProBagCodeDO> snapshots = bagCodeMapper.selectListByIds(ids);
+ if (snapshots.size() != ids.size()) {
+ throw exception(PRO_BAG_CODE_NOT_EXISTS);
+ }
+ // 2. 鎵樼洏鏈粦瀹氭壒娆℃椂锛岃鐮佷篃蹇呴』鏈綍鍏ユ壒娆★紙鍙嶅悜涓嶆垚绔嬶細鏈綍鍏ユ壒娆$殑琚嬬爜鍙粦鍒颁换鎰忔墭鐩橈級
+ if (palletSnapshot.getBatchId() == null
+ && snapshots.stream().anyMatch(code -> code.getBatchId() != null)) {
+ throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400,
+ "鎵�閫夎鐮佸凡褰曞叆鐢熶骇鎵规锛岃鏀归�夎鎵规涓嬬殑鎵樼洏");
+ }
+ // 3. 鎵樼洏宸茬粦瀹氭壒娆°�佷笖瀛樺湪鏈綍鍏ユ壒娆$殑琚嬬爜鏃讹紝澶嶇敤銆屽綍鍏ユ壒娆°�嶉�昏緫琛ュ綍
+ if (palletSnapshot.getBatchId() != null) {
+ List<Long> unboundIds = snapshots.stream()
+ .filter(code -> code.getBatchId() == null && code.getPalletId() == null
+ && !MesProBagCodeStatusEnum.CANCELED.getStatus().equals(code.getStatus()))
+ .map(MesProBagCodeDO::getId).toList();
+ if (!unboundIds.isEmpty()) {
+ doBindBatch(palletSnapshot.getBatchId(), unboundIds);
+ }
+ }
+ // 4. 閿佸畾鎵樼洏锛岄伩鍏嶄笌鑷姩褰掗泦骞跺彂淇敼琚嬫暟
MesProPalletDO pallet = palletMapper.selectByIdForUpdate(bindReqVO.getPalletId());
if (pallet == null) {
throw exception(PRO_PALLET_NOT_EXISTS);
}
- // 2. 閿佸畾骞舵牎楠岃鐮�
- List<MesProBagCodeDO> bagCodes = validateBagCodesForBind(bindReqVO.getIds(), pallet, true);
+ // 5. 閿佸畾骞舵牎楠岃鐮侊紙褰曞叆鎵规鍚庯紝琚嬬爜涓庢墭鐩樺繀鐒跺悓鎵规锛�
+ List<MesProBagCodeDO> bagCodes = validateBagCodesForBind(ids, pallet, true);
Long itemId = cn.iocoder.yudao.module.mes.service.pro.pallet.MesProPalletItemResolver.resolve(pallet,
bagCodeMapper.selectListByPalletId(pallet.getId()));
for (MesProBagCodeDO bag : bagCodes) {
@@ -473,9 +513,9 @@
itemId = cn.iocoder.yudao.module.mes.service.pro.pallet.MesProPalletItemResolver.merge(itemId, bag.getItemId());
}
palletMapper.updateById(new MesProPalletDO().setId(pallet.getId()).setItemId(itemId));
- // 3. 缁戝畾琚嬬爜骞剁疮鍔犳墭鐩樺凡瑁呰鏁帮紙鎵樼洏鏃犲閲忎笂闄愶級
+ // 6. 缁戝畾琚嬬爜骞剁疮鍔犳墭鐩樺凡瑁呰鏁帮紙鎵樼洏鏃犲閲忎笂闄愶級
int currentCount = pallet.getBagCount() == null ? 0 : pallet.getBagCount();
- bagCodeMapper.bindPalletByIds(bindReqVO.getIds(), pallet.getId(), StrUtil.isNotBlank(pallet.getCode()) ? pallet.getCode() : pallet.getTempCode());
+ bagCodeMapper.bindPalletByIds(ids, pallet.getId(), StrUtil.isNotBlank(pallet.getCode()) ? pallet.getCode() : pallet.getTempCode());
palletService.updatePalletBagCount(pallet.getId(), currentCount + bagCodes.size());
}
--
Gitblit v1.9.3