| | |
| | | <!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.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.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> |
| | |
| | | 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, |
| | |
| | | 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="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.*, |
| | | select |
| | | su.*, |
| | | 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="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"> |