From 704265308b1227dbada5a36b2027b588c062ded2 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 12 十月 2026 09:14:37 +0800
Subject: [PATCH] feat(mes): 新增业务码支持并优化追溯查询功能
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java | 70 +++++++++++++++++++++++++++++++---
1 files changed, 63 insertions(+), 7 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
index effcd75..6830e19 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
@@ -5,6 +5,7 @@
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.pro.bagcode.vo.MesProBagCodePageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.bagcode.MesProBagCodeDO;
+import cn.iocoder.yudao.module.mes.enums.pro.MesProBagCodeStatusEnum;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -27,6 +28,18 @@
return selectOne(MesProBagCodeDO::getCode, code);
}
+ /** 鍐呴儴鎵爜鍏煎涓氬姟鐮佷笌鍘嗗彶杩芥函鐮侊紱鍏紬杩芥函缁х画鍙寜 code 鏌ヨ銆� */
+ default MesProBagCodeDO selectByScanCode(String code) {
+ return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
+ .and(q -> q.eq(MesProBagCodeDO::getBusinessCode, code).or().eq(MesProBagCodeDO::getCode, code)));
+ }
+
+ default MesProBagCodeDO selectByScanCodeForUpdate(String code) {
+ return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
+ .and(q -> q.eq(MesProBagCodeDO::getBusinessCode, code).or().eq(MesProBagCodeDO::getCode, code))
+ .last("FOR UPDATE"));
+ }
+
default MesProBagCodeDO selectByCodeForUpdate(String code) {
return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
.eq(MesProBagCodeDO::getCode, code).last("FOR UPDATE"));
@@ -38,13 +51,13 @@
/** 鎵规鏁存壒鍏ュ簱鏃舵壒閲忔爣璁板叾涓嬫湭鍏ュ簱琚嬬爜锛堝箓绛夛級锛屼繚鎸佽鐮佷笌搴撳瓨鐘舵�佷竴鑷� */
@Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, update_time = NOW() "
- + "WHERE deleted = 0 AND inbound_event_id IS NULL AND batch_id = #{batchId}")
+ + "WHERE deleted = 0 AND status <> 30 AND inbound_event_id IS NULL AND batch_id = #{batchId}")
int markInboundByBatchId(@Param("batchId") Long batchId, @Param("eventId") Long eventId,
@Param("lineCode") String lineCode);
/** 鏁存墭鍏ュ簱鏃舵壒閲忔爣璁版墭鐩樹笅鏈叆搴撹鐮侊紙骞傜瓑锛� */
@Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, update_time = NOW() "
- + "WHERE deleted = 0 AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
+ + "WHERE deleted = 0 AND status <> 30 AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
int markInboundByPalletId(@Param("palletId") Long palletId, @Param("eventId") Long eventId,
@Param("lineCode") String lineCode);
@@ -72,6 +85,29 @@
return selectList(MesProBagCodeDO::getBatchId, batchId);
}
+ /**
+ * 鏌ヨ鐢熸垚缁勪笅鍙嵃鍒风殑琚嬬爜锛堟帓闄ゅ凡浣滃簾锛夛紝鐢ㄤ簬浜岀淮鐮佹爣绛惧鍑�
+ * <p>
+ * 宸蹭綔搴熻鐮佺殑鏍囩涓嶅緱鍐嶅嵃鍒凤細鍏舵爣绛捐嫢璐村埌浜у搧涓婏紝娑堣垂鑰呮壂鐮佷細琚彁绀恒�岃杩芥函鐮佸凡浣滃簾銆嶏紝
+ * 瀵艰嚧鐪熷搧琚鍒や负鍋囪揣銆�
+ */
+ default List<MesProBagCodeDO> selectPrintableListByUuid(String uuid) {
+ return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
+ .eq(MesProBagCodeDO::getUuid, uuid)
+ .ne(MesProBagCodeDO::getStatus, MesProBagCodeStatusEnum.CANCELED.getStatus())
+ .orderByAsc(MesProBagCodeDO::getBagNo));
+ }
+
+ /**
+ * 鏌ヨ鎵规涓嬪彲鍗板埛鐨勮鐮侊紙鎺掗櫎宸蹭綔搴燂級锛岀敤浜庝簩缁寸爜鏍囩瀵煎嚭
+ */
+ default List<MesProBagCodeDO> selectPrintableListByBatchId(Long batchId) {
+ return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
+ .eq(MesProBagCodeDO::getBatchId, batchId)
+ .ne(MesProBagCodeDO::getStatus, MesProBagCodeStatusEnum.CANCELED.getStatus())
+ .orderByAsc(MesProBagCodeDO::getBagNo));
+ }
+
default Long selectCountByBatchId(Long batchId) {
return selectCount(MesProBagCodeDO::getBatchId, batchId);
}
@@ -83,10 +119,16 @@
default List<MesProBagCodeDO> selectListByPalletId(Long palletId) {
return selectList(MesProBagCodeDO::getPalletId, palletId);
}
+ default List<MesProBagCodeDO> selectListByPalletIdForUpdate(Long palletId) {
+ return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>().eq(MesProBagCodeDO::getPalletId, palletId).orderByAsc(MesProBagCodeDO::getId).last("FOR UPDATE"));
+ }
+ default List<MesProBagCodeDO> selectListByBatchIdForUpdate(Long batchId) {
+ return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>().eq(MesProBagCodeDO::getBatchId, batchId).orderByAsc(MesProBagCodeDO::getId).last("FOR UPDATE"));
+ }
default PageResult<MesProBagCodeDO> selectPage(MesProBagCodePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MesProBagCodeDO>()
- .likeIfPresent(MesProBagCodeDO::getCode, reqVO.getCode())
+ .likeIfPresent(MesProBagCodeDO::getBusinessCode, reqVO.getBusinessCode())
.eqIfPresent(MesProBagCodeDO::getBatchId, reqVO.getBatchId())
.likeIfPresent(MesProBagCodeDO::getBatchCode, reqVO.getBatchCode())
.eqIfPresent(MesProBagCodeDO::getUuid, reqVO.getUuid())
@@ -95,7 +137,10 @@
.eqIfPresent(MesProBagCodeDO::getStatus, reqVO.getStatus())
.betweenIfPresent(MesProBagCodeDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MesProBagCodeDO::getCreateTime)
- .orderByDesc(MesProBagCodeDO::getId));
+ .orderByDesc(MesProBagCodeDO::getId)
+ .and(cn.hutool.core.util.StrUtil.isNotBlank(reqVO.getCode()), q ->
+ q.like(MesProBagCodeDO::getCode, reqVO.getCode()).or()
+ .like(MesProBagCodeDO::getBusinessCode, reqVO.getCode())));
}
/**
@@ -137,10 +182,13 @@
}
/**
- * 鏌ヨ鎵规鍐呰鐮佹渶澶у簭鍙凤紙鍖呭惈宸查�昏緫鍒犻櫎璁板綍锛屼繚璇佸簭鍙蜂笉鍥為��銆佺爜鍊煎敮涓�锛�
+ * 鏌ヨ鍏ㄥ眬鏈�澶ц搴忓彿锛堣搴忓彿涓哄叏灞�搴忓彿锛屼笉鍖哄垎鎵规锛涘寘鍚凡閫昏緫鍒犻櫎璁板綍锛屼繚璇佸簭鍙蜂笉鍥為��锛�
+ * <p>
+ * 浠呯敤浜庝负 Redis 搴忓彿鍒嗛厤鎻愪緵鍩哄噯鍊硷紝涓嶈鍦ㄤ笟鍔′腑鐩存帴鐢ㄣ�岃繑鍥炲�� + 1銆嶄綔涓鸿捣濮嬪簭鍙封�斺��
+ * 閭f槸鍏堣鍚庡啓锛屽苟鍙戠敓鎴愪細浜х敓閲嶅搴忓彿銆傝浣跨敤
+ * {@code MesCodeRedisDAO#allocateBagNoStart(int, Integer)} 鍘熷瓙鍒嗛厤銆�
*
- * @param batchId 鎵规缂栧彿
- * @return 鏈�澶ц搴忓彿锛屾棤璁板綍杩斿洖 0
+ * @return 鍏ㄥ眬鏈�澶ц搴忓彿锛屾棤璁板綍杩斿洖 0
*/
@Select("SELECT IFNULL(MAX(bag_no), 0) FROM mes_pro_bag_code")
Integer selectMaxBagNo();
@@ -192,6 +240,14 @@
"AND deleted = 0 AND status <> 30")
int selectEffectiveCountByBatchId(@Param("batchId") Long batchId);
+ @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE deleted = 0 AND status <> 30 "
+ + "AND inbound_event_id IS NULL AND batch_id = #{batchId}")
+ int selectPendingInboundCountByBatchId(@Param("batchId") Long batchId);
+
+ @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE deleted = 0 AND status <> 30 "
+ + "AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
+ int selectPendingInboundCountByPalletId(@Param("palletId") Long palletId);
+
/**
* 鎵归噺鏍囪涓哄凡瀵煎嚭鍗板埛锛堜粎鏇存柊澶勪簬鐩爣鍘熺姸鎬佺殑璁板綍锛�
*
--
Gitblit v1.9.3