<?xml version="1.0" encoding="UTF-8"?>
|
<!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
|
</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
|
</sql>
|
|
<update id="updateSubtractStockUnInventory">
|
update stock_uninventory
|
<set>
|
<if test="ew.qualitity != null">
|
qualitity = qualitity - #{ew.qualitity},
|
</if>
|
<if test="ew.version != null">
|
version = version + 1,
|
</if>
|
<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}
|
<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 != ''">
|
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,
|
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.update_time,
|
(su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity,
|
pm.model,
|
pm.unit,
|
p.product_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="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
|
<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,
|
(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="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>
|