From 7486f6d6a93d98f96f45f0cc4846be9c8a2345df Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 09 六月 2026 15:39:20 +0800
Subject: [PATCH] 增加废品库详情接口
---
src/main/resources/mapper/stock/StockUninventoryMapper.xml | 208 +++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 189 insertions(+), 19 deletions(-)
diff --git a/src/main/resources/mapper/stock/StockUninventoryMapper.xml b/src/main/resources/mapper/stock/StockUninventoryMapper.xml
index 6c5d3be..fbdb322 100644
--- a/src/main/resources/mapper/stock/StockUninventoryMapper.xml
+++ b/src/main/resources/mapper/stock/StockUninventoryMapper.xml
@@ -2,15 +2,54 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.stock.mapper.StockUninventoryMapper">
- <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
<resultMap id="BaseResultMap" type="com.ruoyi.stock.pojo.StockUninventory">
<result column="id" property="id" />
<result column="product_model_id" property="productModelId" />
<result column="qualitity" property="qualitity" />
+ <result column="type" property="type" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="version" property="version" />
</resultMap>
+
+ <sql id="WasteQueryRecursiveTree">
+ WITH RECURSIVE product_tree AS (
+ SELECT id
+ FROM product
+ WHERE id = #{ew.topParentProductId}
+
+ UNION ALL
+
+ SELECT p.id
+ FROM product p
+ INNER JOIN product_tree pt ON p.parent_id = pt.id
+ )
+ </sql>
+
+ <sql id="BaseWasteFromClause">
+ from stock_uninventory su
+ left join product_model pm on su.product_model_id = pm.id
+ left join product p on pm.product_id = p.id
+ left join manufacturer m on su.manufacturer_id = m.id
+ </sql>
+
+ <sql id="WastePageColumns">
+ su.id,
+ su.qualitity,
+ su.type,
+ COALESCE(su.locked_quantity, 0) as locked_quantity,
+ su.product_model_id,
+ su.create_time,
+ su.update_time,
+ su.version,
+ (su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity,
+ pm.model,
+ pm.unit,
+ p.product_name,
+ m.name as manufacturer_name,
+ su.source
+ </sql>
+
<update id="updateSubtractStockUnInventory">
update stock_uninventory
<set>
@@ -20,32 +59,64 @@
<if test="ew.version != null">
version = version + 1,
</if>
- <if test="ew.remark != null and ew.remark !=''">
+ <if test="ew.remark != null and ew.remark != ''">
remark = #{ew.remark},
+ </if>
+ <if test="ew.type != null and ew.type != ''">
+ type = #{ew.type},
</if>
update_time = now()
</set>
- where product_model_id = #{ew.productModelId} and qualitity >= #{ew.qualitity}
+ where product_model_id = #{ew.productModelId}
+ and qualitity >= #{ew.qualitity}
+ <if test="ew.type != null and ew.type != ''">
+ and type = #{ew.type}
+ </if>
+ <if test="ew.batchNo == null">
+ and batch_no is null
+ </if>
+ <if test="ew.batchNo != null">
+ and batch_no = #{ew.batchNo}
+ </if>
</update>
+
<update id="updateAddStockUnInventory">
update stock_uninventory
<set>
<if test="ew.qualitity != null">
qualitity = qualitity + #{ew.qualitity},
</if>
+ <if test="ew.lockedQuantity != null">
+ locked_quantity = locked_quantity + #{ew.lockedQuantity},
+ </if>
<if test="ew.version != null">
version = version + 1,
</if>
- <if test="ew.remark != null and ew.remark !=''">
+ <if test="ew.remark != null and ew.remark != ''">
remark = #{ew.remark},
+ </if>
+ <if test="ew.type != null and ew.type != ''">
+ type = #{ew.type},
</if>
update_time = now()
</set>
where product_model_id = #{ew.productModelId}
+ <if test="ew.type != null and ew.type != ''">
+ and type = #{ew.type}
+ </if>
+ <if test="ew.batchNo == null">
+ and batch_no is null
+ </if>
+ <if test="ew.batchNo != null">
+ and batch_no = #{ew.batchNo}
+ </if>
</update>
+
<select id="pageStockUninventory" resultType="com.ruoyi.stock.dto.StockUninventoryDto">
- select su.id,
+ select
+ su.id,
su.qualitity,
+ su.type,
COALESCE(su.locked_quantity, 0) as locked_quantity,
su.product_model_id,
su.create_time,
@@ -56,26 +127,125 @@
pm.model,
pm.unit,
p.product_name
- from stock_uninventory su
- left join product_model pm on su.product_model_id = pm.id
- left join product p on pm.product_id = p.id
- where 1 = 1
- <if test="ew.productName != null and ew.productName !=''">
- and p.product_name like concat('%',#{ew.productName},'%')
- </if>
+ <include refid="BaseWasteFromClause" />
+ <where>
+ <if test="ew.type != null and ew.type != ''">
+ and su.type = #{ew.type}
+ </if>
+ <if test="ew.productName != null and ew.productName != ''">
+ and p.product_name like concat('%', #{ew.productName}, '%')
+ </if>
+ </where>
</select>
- <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockInventoryExportData">
- select su.*,
+
+ <select id="pageWasteQuery" resultType="com.ruoyi.stock.dto.StockUninventoryDto">
+ <include refid="WasteQueryRecursiveTree" />
+ select
+ <include refid="WastePageColumns" />
+ <include refid="BaseWasteFromClause" />
+ <where>
+ and su.type = 'waste'
+ <if test="ew.productName != null and ew.productName != ''">
+ and p.product_name like concat('%', #{ew.productName}, '%')
+ </if>
+ <if test="ew.model != null and ew.model != ''">
+ and pm.model like concat('%', #{ew.model}, '%')
+ </if>
+ <if test="ew.batchNo != null and ew.batchNo != ''">
+ and su.batch_no like concat('%', #{ew.batchNo}, '%')
+ </if>
+ <if test="ew.topParentProductId != null and ew.topParentProductId > 0">
+ and p.id in (select id from product_tree)
+ </if>
+ </where>
+
+ order by su.update_time desc, su.id desc
+ </select>
+
+ <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockUnInventoryExportData">
+ select
+ su.*,
pm.model,
pm.unit,
- p.product_name
+ p.product_name,
+ m.name as manufacturer_name
+ <include refid="BaseWasteFromClause" />
+ <where>
+ <if test="ew.type != null and ew.type != ''">
+ and su.type = #{ew.type}
+ </if>
+ <if test="ew.productName != null and ew.productName != ''">
+ and p.product_name like concat('%', #{ew.productName}, '%')
+ </if>
+ </where>
+ </select>
+
+ <select id="listWasteQueryExportData" resultType="com.ruoyi.stock.execl.StockUnInventoryExportData">
+ <include refid="WasteQueryRecursiveTree" />
+ select
+ su.*,
+ pm.model,
+ pm.unit,
+ p.product_name,
+ m.name as manufacturer_name,
+ (su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity
+ <include refid="BaseWasteFromClause" />
+ <where>
+ and su.type = 'waste'
+ <if test="ew.productName != null and ew.productName != ''">
+ and p.product_name like concat('%', #{ew.productName}, '%')
+ </if>
+ <if test="ew.model != null and ew.model != ''">
+ and pm.model like concat('%', #{ew.model}, '%')
+ </if>
+ <if test="ew.batchNo != null and ew.batchNo != ''">
+ and su.batch_no like concat('%', #{ew.batchNo}, '%')
+ </if>
+ <if test="ew.topParentProductId != null and ew.topParentProductId > 0">
+ and p.id in (select id from product_tree)
+ </if>
+ </where>
+ order by su.update_time desc, su.id desc
+ </select>
+
+ <select id="getWasteBatchNoQty" resultType="com.ruoyi.stock.dto.StockUninventoryDto">
+ select
+ su.id,
+ p.product_name,
+ pm.model,
+ m.name as manufacturer_name,
+ su.source,
+ pm.unit,
+ su.batch_no,
+ su.qualitity,
+ COALESCE(su.locked_quantity, 0) as locked_quantity,
+ (su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity,
+ su.remark,
+ su.update_time,
+ su.product_model_id
from stock_uninventory su
left join product_model pm on su.product_model_id = pm.id
left join product p on pm.product_id = p.id
- where 1 = 1
- <if test="ew.productName != null and ew.productName !=''">
- and p.product_name like concat('%',#{ew.productName},'%')
- </if>
+ left join manufacturer m on su.manufacturer_id = m.id
+ <where>
+ and su.type = 'waste'
+ <if test="ew.productModelId != null and ew.productModelId > 0">
+ and su.product_model_id = #{ew.productModelId}
+ </if>
+ <if test="ew.productId != null and ew.productId > 0">
+ and p.id = #{ew.productId}
+ </if>
+ </where>
+ order by su.batch_no
+ </select>
+
+ <select id="selectPendingOutQuantity" resultType="java.math.BigDecimal">
+ SELECT IFNULL(SUM(sor.stock_out_num), 0)
+ FROM stock_out_record sor
+ WHERE sor.product_model_id = #{productModelId}
+ AND (sor.batch_no = #{batchNo} OR (#{batchNo} IS NULL AND sor.batch_no IS NULL))
+ AND sor.type = #{type}
+ AND sor.approval_status = 0
</select>
</mapper>
--
Gitblit v1.9.3