feat: 完善盘点出入库流程

This commit is contained in:
zgw
2026-06-25 18:31:17 +08:00
parent 4b8bc03343
commit c7c07c01cf
21 changed files with 1974 additions and 111 deletions

View File

@@ -112,6 +112,88 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<update id="applyApprovedDifference" parameterType="PdDifferenceRecord">
update bsd
set bsd.quantity = #{pdQuantity},
bsd.out_quantity = case
when isnull(bsd.out_quantity, 0) &gt; #{pdQuantity} then #{pdQuantity}
else isnull(bsd.out_quantity, 0)
end,
bsd.update_time = sysdatetime()
from bas_stock_detail bsd
inner join bas_stock bs on bsd.stock_id = bs.stock_id
left join pd_stockpd_detail pdd on pdd.stockpd_detail_id = #{stockpdDetailId}
left join pd_stockpd_detail_finish pddf on pddf.stockpd_detail_id = #{stockpdDetailId}
outer apply (
select coalesce(nullif(pdd.stock_detail_id, ''), nullif(pddf.stock_detail_id, '')) as stock_detail_id
) src
where (
src.stock_detail_id is not null
and (bsd.stockin_detail_id = src.stock_detail_id or bsd.detail_id = src.stock_detail_id)
)
or (
src.stock_detail_id is null
and bs.tray_code = #{trayCode}
and bsd.product_id = #{productId}
<if test="warehouseId != null and warehouseId != ''">
and bs.warehouse_id = #{warehouseId}
</if>
)
</update>
<update id="refreshApprovedDifferenceStockSummary" parameterType="PdDifferenceRecord">
update bs
set bs.quantity = isnull(bsa.quantity, 0),
bs.out_quantity = isnull(bsa.out_quantity, 0)
from bas_stock bs
left join (
select stock_id,
sum(isnull(quantity, 0)) as quantity,
sum(isnull(out_quantity, 0)) as out_quantity
from bas_stock_detail
group by stock_id
) bsa on bsa.stock_id = bs.stock_id
where bs.stock_id in (
select distinct bsd.stock_id
from bas_stock_detail bsd
inner join bas_stock xbs on bsd.stock_id = xbs.stock_id
left join pd_stockpd_detail pdd on pdd.stockpd_detail_id = #{stockpdDetailId}
left join pd_stockpd_detail_finish pddf on pddf.stockpd_detail_id = #{stockpdDetailId}
outer apply (
select coalesce(nullif(pdd.stock_detail_id, ''), nullif(pddf.stock_detail_id, '')) as stock_detail_id
) src
where (
src.stock_detail_id is not null
and (bsd.stockin_detail_id = src.stock_detail_id or bsd.detail_id = src.stock_detail_id)
)
or (
src.stock_detail_id is null
and xbs.tray_code = #{trayCode}
and bsd.product_id = #{productId}
<if test="warehouseId != null and warehouseId != ''">
and xbs.warehouse_id = #{warehouseId}
</if>
)
)
</update>
<update id="markInboundDifferencesPendingReviewByJobId" parameterType="String">
update pd_difference_record
set status = '1'
where status = '0'
and stockpd_detail_id in (
select in_or_out_d_id
from mydo_job_detail
where job_id = #{jobId}
and in_or_out_d_id is not null
union
select in_or_out_d_id
from mydo_job_detail_finish
where job_id = #{jobId}
and in_or_out_d_id is not null
)
</update>
<delete id="deletePdDifferenceRecordById" parameterType="Long">
delete from pd_difference_record where id = #{id}
</delete>
@@ -122,4 +204,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
</mapper>
</mapper>

View File

@@ -8,6 +8,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="stockpdDetailId" column="stockpd_detail_id" />
<result property="stockpdId" column="stockpd_id" />
<result property="trayCode" column="tray_code" />
<result property="stockId" column="stock_id" />
<result property="stockDetailId" column="stock_detail_id" />
<result property="cargoSpaceId" column="cargo_space_id" />
<result property="cargoSpaceName" column="cargo_space_name" />
<result property="warehouseId" column="warehouse_id" />
<result property="warehouseName" column="warehouse_name" />
<result property="productId" column="product_id" />
<result property="productName" column="product_name" />
<result property="quantity" column="quantity" />
@@ -17,12 +23,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectPdStockpdDetailVo">
select stockpd_detail_id, stockpd_id, tray_code, product_id, product_name, quantity, allot_num, assign_num, remark from pd_stockpd_detail
select stockpd_detail_id, stockpd_id, tray_code, stock_id, stock_detail_id, cargo_space_id, cargo_space_name,
warehouse_id, warehouse_name, product_id, product_name, quantity, allot_num, assign_num, remark
from pd_stockpd_detail
</sql>
<sql id="selectPdStockpdDetailFinishVo">
select stockpd_detail_id,
stockpd_id,
tray_code,
stock_id,
stock_detail_id,
cargo_space_id,
cargo_space_name,
warehouse_id,
warehouse_name,
product_id,
product_name,
quantity,
@@ -37,6 +51,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="stockpdId != null and stockpdId != ''"> and stockpd_id = #{stockpdId}</if>
<if test="trayCode != null and trayCode != ''"> and tray_code = #{trayCode}</if>
<if test="stockId != null and stockId != ''"> and stock_id = #{stockId}</if>
<if test="stockDetailId != null and stockDetailId != ''"> and stock_detail_id = #{stockDetailId}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id = #{cargoSpaceId}</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="productId != null and productId != ''"> and product_id = #{productId}</if>
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
<if test="quantity != null "> and quantity = #{quantity}</if>
@@ -54,6 +72,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="stockpdId != null and stockpdId != ''"> and stockpd_id = #{stockpdId}</if>
<if test="trayCode != null and trayCode != ''"> and tray_code = #{trayCode}</if>
<if test="stockId != null and stockId != ''"> and stock_id = #{stockId}</if>
<if test="stockDetailId != null and stockDetailId != ''"> and stock_detail_id = #{stockDetailId}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id = #{cargoSpaceId}</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="productId != null and productId != ''"> and product_id = #{productId}</if>
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
<if test="quantity != null "> and quantity = #{quantity}</if>
@@ -68,6 +90,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="stockpdDetailId != null">stockpd_detail_id,</if>
<if test="stockpdId != null and stockpdId != ''">stockpd_id,</if>
<if test="trayCode != null">tray_code,</if>
<if test="stockId != null">stock_id,</if>
<if test="stockDetailId != null">stock_detail_id,</if>
<if test="cargoSpaceId != null">cargo_space_id,</if>
<if test="cargoSpaceName != null">cargo_space_name,</if>
<if test="warehouseId != null">warehouse_id,</if>
<if test="warehouseName != null">warehouse_name,</if>
<if test="productId != null and productId != ''">product_id,</if>
<if test="productName != null">product_name,</if>
<if test="quantity != null">quantity,</if>
@@ -79,6 +107,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="stockpdDetailId != null">#{stockpdDetailId},</if>
<if test="stockpdId != null and stockpdId != ''">#{stockpdId},</if>
<if test="trayCode != null">#{trayCode},</if>
<if test="stockId != null">#{stockId},</if>
<if test="stockDetailId != null">#{stockDetailId},</if>
<if test="cargoSpaceId != null">#{cargoSpaceId},</if>
<if test="cargoSpaceName != null">#{cargoSpaceName},</if>
<if test="warehouseId != null">#{warehouseId},</if>
<if test="warehouseName != null">#{warehouseName},</if>
<if test="productId != null and productId != ''">#{productId},</if>
<if test="productName != null">#{productName},</if>
<if test="quantity != null">#{quantity},</if>
@@ -93,6 +127,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="stockpdId != null and stockpdId != ''">stockpd_id = #{stockpdId},</if>
<if test="trayCode != null">tray_code = #{trayCode},</if>
<if test="stockId != null">stock_id = #{stockId},</if>
<if test="stockDetailId != null">stock_detail_id = #{stockDetailId},</if>
<if test="cargoSpaceId != null">cargo_space_id = #{cargoSpaceId},</if>
<if test="cargoSpaceName != null">cargo_space_name = #{cargoSpaceName},</if>
<if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
<if test="warehouseName != null">warehouse_name = #{warehouseName},</if>
<if test="productId != null and productId != ''">product_id = #{productId},</if>
<if test="productName != null">product_name = #{productName},</if>
<if test="quantity != null">quantity = #{quantity},</if>
@@ -113,4 +153,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{stockpdDetailId}
</foreach>
</delete>
</mapper>
</mapper>

View File

@@ -120,12 +120,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from mydo_job j
inner join mydo_job_detail jd on j.job_id = jd.job_id
where j.in_or_out &gt;= 20
and j.in_or_out not in (30, 31)
and j.status in ('1', '2', '3')
and (#{taskNo} is null or #{taskNo} = '' or j.task_no = #{taskNo})
group by j.job_id, j.task_no, j.exit_id, j.create_time, j.status, j.execution_phase
order by j.create_time desc
</select>
<select id="inventoryTaskList" parameterType="java.util.Map" resultType="java.util.HashMap">
select j.job_id as jobId,
j.task_no as taskNo,
'inventory' as type,
case when j.in_or_out = 31 then '货位盘点' else '物料盘点' end as typeName,
'inventory' as typeClass,
max(jd.product_id) as materialCode,
max(jd.product_name) as materialName,
sum(isnull(jd.out_quantity, 0)) as quantity,
isnull(j.exit_id, '') as portName,
j.tray_code as trayCode,
convert(varchar(19), j.create_time, 120) as createTime,
j.status as status,
j.execution_phase as executionPhase,
case
when j.execution_phase = '5' then '待扫码盘点'
when j.status = '1' then '未下发'
when j.status = '2' then '待执行'
when j.status = '3' then 'WCS执行中'
else '待盘点'
end as statusName,
case
when j.execution_phase = '5' then 'pending'
when j.status = '3' then 'processing'
else 'pending'
end as statusClass
from mydo_job j
inner join mydo_job_detail jd on j.job_id = jd.job_id
where j.in_or_out in (30, 31)
and j.status in ('1', '2', '3')
and (#{taskNo} is null or #{taskNo} = '' or j.task_no = #{taskNo})
group by j.job_id, j.task_no, j.in_or_out, j.exit_id, j.tray_code, j.create_time, j.status, j.execution_phase
order by j.create_time desc
</select>
<select id="selectOutboundDetail" parameterType="java.util.Map" resultType="java.util.HashMap">
select top 1 j.job_id as jobId,
j.task_no as taskNo,
@@ -142,6 +178,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from mydo_job j
inner join mydo_job_detail jd on j.job_id = jd.job_id
where j.in_or_out &gt;= 20
and j.in_or_out not in (30, 31)
and j.status in ('1', '2', '3')
and (#{taskNo} is null or #{taskNo} = '' or j.task_no = #{taskNo})
and (#{barcode} is null or #{barcode} = '' or j.tray_code = #{barcode})
@@ -150,6 +187,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by j.create_time desc
</select>
<select id="selectInventoryDetail" parameterType="java.util.Map" resultType="java.util.HashMap">
select top 1 j.job_id as jobId,
j.task_no as taskNo,
j.tray_code as trayCode,
j.cargo_space_id as locationCode,
j.cargo_space_name as locationName,
j.warehouse_id as warehouseId,
j.warehouse_name as warehouseName,
j.execution_phase as executionPhase,
j.in_or_out as inventoryType,
isnull(j.exit_id, '') as portName,
sum(isnull(jd.out_quantity, 0)) as quantity,
count(1) as materialCount,
'' as spec
from mydo_job j
inner join mydo_job_detail jd on j.job_id = jd.job_id
where j.in_or_out in (30, 31)
and j.status in ('1', '2', '3')
and (#{taskNo} is null or #{taskNo} = '' or j.task_no = #{taskNo})
and (#{barcode} is null or #{barcode} = '' or j.tray_code = #{barcode})
group by j.job_id, j.task_no, j.tray_code, j.cargo_space_id, j.cargo_space_name,
j.warehouse_id, j.warehouse_name, j.execution_phase, j.in_or_out, j.exit_id, j.create_time
order by j.create_time desc
</select>
<select id="selectOutboundTrayMaterials" parameterType="java.util.Map" resultType="java.util.HashMap">
select jd.job_detail_id as jobDetailId,
jd.stock_id as stockId,
@@ -165,6 +227,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by jd.job_detail_id
</select>
<select id="selectInventoryTrayMaterials" parameterType="java.util.Map" resultType="java.util.HashMap">
select jd.job_detail_id as jobDetailId,
jd.stock_id as stockId,
jd.stockin_detail_id as stockDetailId,
jd.in_or_out_d_id as stockpdDetailId,
jd.product_id as materialCode,
jd.product_name as materialName,
jd.lot_no as lotNo,
jd.stock_quantity as stockQuantity,
jd.out_quantity as quantity
from mydo_job_detail jd
where jd.job_id = #{jobId}
order by jd.job_detail_id
</select>
<select id="selectInventoryInboundJobByOutboundJobId" parameterType="String" resultType="java.util.HashMap">
select top 1 jobId, taskNo, status
from (
select j.job_id as jobId,
j.task_no as taskNo,
j.status as status,
j.create_time as createTime
from mydo_job j
inner join mydo_job_detail jd on j.job_id = jd.job_id
where j.in_or_out in (10, 11)
and jd.in_or_out_id = #{outboundJobId}
union all
select jf.job_id as jobId,
jf.task_no as taskNo,
jf.status as status,
jf.create_time as createTime
from mydo_job_finish jf
inner join mydo_job_detail_finish jdf on jf.job_id = jdf.job_id
where jf.in_or_out in (10, 11)
and jdf.in_or_out_id = #{outboundJobId}
) x
order by createTime desc
</select>
<select id="selectResidualTrayMaterials" parameterType="java.util.Map" resultType="java.util.HashMap">
select bsd.detail_id as stockDetailId,
bsd.stock_id as stockId,
@@ -301,6 +402,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and isnull(quantity, 0) - isnull(out_quantity, 0) &gt;= #{quantity}
</update>
<update id="reserveInventoryStockDetail" parameterType="java.util.Map">
update bas_stock_detail
set out_quantity = isnull(out_quantity, 0) + #{quantity},
job_detail_id = #{jobDetailId},
update_time = sysdatetime()
where detail_id = #{stockDetailId}
and stock_id = #{stockId}
and isnull(quantity, 0) - isnull(out_quantity, 0) &gt;= #{quantity}
</update>
<update id="lockEmptyTrayCargoSpace" parameterType="java.util.Map">
update bcs
set status = '4',
@@ -310,4 +421,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where bs.stock_id = #{stockId}
and bs.cargo_space_id = #{cargoSpaceId}
</update>
<update id="lockInventoryOutboundCargoSpace" parameterType="java.util.Map">
update bcs
set status = '4',
tray_code = bs.tray_code
from bas_cargo_space bcs
inner join bas_stock bs on bcs.cargo_space_id = bs.cargo_space_id
where bs.stock_id = #{stockId}
and bs.cargo_space_id = #{cargoSpaceId}
</update>
</mapper>