From a829dd34332bbc10c6b42ef86635ed48e34c6207 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 03 十一月 2026 10:21:50 +0800
Subject: [PATCH] fix: 原料领料批号按可用库存过滤并实现先进先出
---
src/main/resources/mapper/basic/ProductModelMapper.xml | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/main/resources/mapper/basic/ProductModelMapper.xml b/src/main/resources/mapper/basic/ProductModelMapper.xml
index 6270b1d..a78f521 100644
--- a/src/main/resources/mapper/basic/ProductModelMapper.xml
+++ b/src/main/resources/mapper/basic/ProductModelMapper.xml
@@ -54,12 +54,25 @@
</select>
<select id="selectBatchNoListByProductModelId" resultType="java.lang.String">
- select distinct si.batch_no
+ select si.batch_no
from stock_inventory si
+ left join (
+ select sir.batch_no, min(sir.create_time) as first_in_time
+ from stock_in_record sir
+ where sir.product_model_id = #{productModelId}
+ and sir.batch_no is not null
+ and sir.batch_no != ''
+ group by sir.batch_no
+ ) first_in on first_in.batch_no = si.batch_no
where si.product_model_id = #{productModelId}
and si.batch_no is not null
and si.batch_no != ''
- order by si.batch_no
+ and si.qualitity - IFNULL(si.locked_quantity, 0) > 0
+ group by si.batch_no
+ order by MIN(first_in.first_in_time) is null,
+ MIN(first_in.first_in_time),
+ MIN(si.create_time),
+ MIN(si.batch_no)
</select>
<select id="selectLatestRecord" resultType="com.ruoyi.basic.pojo.ProductModel">
SELECT * FROM product_model
--
Gitblit v1.9.3