feat: plan shadow decisions from leased generation
This commit is contained in:
@@ -6,77 +6,98 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectInboundInput" resultType="com.ruoyi.algorithm.shadow.ShadowInboundReference">
|
||||
select top (1)
|
||||
job.job_id as requestId,
|
||||
job.warehouse_id as warehouseId,
|
||||
job.tray_code as trayNo,
|
||||
coalesce(nullif(ltrim(rtrim(detail.spare4)), ''),
|
||||
nullif(ltrim(rtrim(stock.spare4)), '')) as projectNo,
|
||||
jobDetail.product_id as productId,
|
||||
jobDetail.lot_no as lotNo
|
||||
from mydo_job job
|
||||
left join mydo_job_detail jobDetail on jobDetail.job_id = job.job_id
|
||||
left join in_stockin_detail detail on detail.stockin_detail_id = jobDetail.stockin_detail_id
|
||||
left join bas_stock stock on stock.stock_id = jobDetail.stock_id
|
||||
where job.task_no = #{taskNo}
|
||||
and job.tray_code = #{trayNo}
|
||||
order by jobDetail.job_detail_id
|
||||
input.request_id as requestId,
|
||||
input.raw_warehouse_id as warehouseId,
|
||||
input.tray_no as trayNo,
|
||||
input.project_no as projectNo,
|
||||
input.product_id as productId,
|
||||
input.lot_no as lotNo,
|
||||
convert(int, coalesce((
|
||||
select sum(convert(bigint, lane.available_count))
|
||||
from alg.lane_state lane
|
||||
where lane.warehouse_id = #{warehouseId}
|
||||
and lane.snapshot_generation = #{generation}
|
||||
), 0)) as shadowCandidateCount
|
||||
from alg.shadow_inbound_request_snapshot input
|
||||
where input.warehouse_id = #{warehouseId}
|
||||
and input.snapshot_generation = #{generation}
|
||||
and input.task_no = #{taskNo}
|
||||
and input.tray_no = #{trayNo}
|
||||
</select>
|
||||
|
||||
<select id="selectProjectOutboundReference" resultType="com.ruoyi.algorithm.shadow.ShadowStockReference">
|
||||
select detail.stockout_detail_id as requestId,
|
||||
detail.warehouse_id as warehouseId,
|
||||
nullif(ltrim(rtrim(detail.spare4)), '') as projectNo,
|
||||
detail.product_id as productId,
|
||||
convert(varchar(40), (select max(snapshot.synchronized_at)
|
||||
from alg.inventory_item_snapshot snapshot
|
||||
where snapshot.warehouse_id = detail.warehouse_id), 126)
|
||||
as snapshotSynchronizedAt,
|
||||
<select id="selectProjectOutboundReference"
|
||||
resultType="com.ruoyi.algorithm.shadow.ShadowStockReference">
|
||||
select top (1)
|
||||
input.stockout_detail_id as requestId,
|
||||
input.raw_warehouse_id as warehouseId,
|
||||
input.project_no as projectNo,
|
||||
input.product_id as productId,
|
||||
input.requested_quantity as requestedQuantity,
|
||||
convert(varchar(40), input.synchronized_at, 126) as snapshotSynchronizedAt,
|
||||
(select count(*)
|
||||
from bas_stock live
|
||||
where live.warehouse_id = detail.warehouse_id
|
||||
and live.stock_status = '1'
|
||||
and live.product_status = '1'
|
||||
and live.quantity > live.out_quantity
|
||||
and (NULLIF(LTRIM(RTRIM(detail.product_id)), '') IS NULL
|
||||
OR live.product_id = NULLIF(LTRIM(RTRIM(detail.product_id)), ''))) as liveMatchCount,
|
||||
(select count(*)
|
||||
from alg.inventory_item_snapshot snapshot
|
||||
where snapshot.warehouse_id = detail.warehouse_id
|
||||
and snapshot.project_no = nullif(ltrim(rtrim(detail.spare4)), '')
|
||||
and (NULLIF(LTRIM(RTRIM(detail.product_id)), '') IS NULL
|
||||
OR snapshot.product_no = NULLIF(LTRIM(RTRIM(detail.product_id)), '')))
|
||||
from alg.inventory_item_snapshot item
|
||||
where item.warehouse_id = #{warehouseId}
|
||||
and item.snapshot_generation = #{generation}
|
||||
and item.project_no = nullif(ltrim(rtrim(input.project_no)), '')
|
||||
and (nullif(ltrim(rtrim(input.product_id)), '') is null
|
||||
or item.product_no = nullif(ltrim(rtrim(input.product_id)), ''))
|
||||
and isnull(item.quantity, 0) > isnull(item.out_quantity, 0))
|
||||
as shadowMatchCount
|
||||
from out_stockout_detail detail
|
||||
where detail.stockout_detail_id = #{stockoutDetailId}
|
||||
from alg.shadow_outbound_request_snapshot input
|
||||
where input.warehouse_id = #{warehouseId}
|
||||
and input.snapshot_generation = #{generation}
|
||||
and input.stockout_detail_id = #{stockoutDetailId}
|
||||
</select>
|
||||
|
||||
<select id="selectStockReference" resultType="com.ruoyi.algorithm.shadow.ShadowStockReference">
|
||||
select top (1)
|
||||
stock.stock_id as stockId,
|
||||
stock.tray_code as trayNo,
|
||||
stock.cargo_space_id as spaceId,
|
||||
stock.warehouse_id as warehouseId,
|
||||
nullif(ltrim(rtrim(stock.spare4)), '') as projectNo,
|
||||
stock.product_id as productId,
|
||||
convert(varchar(40), (select max(snapshot.synchronized_at)
|
||||
from alg.inventory_item_snapshot snapshot
|
||||
where snapshot.warehouse_id = stock.warehouse_id), 126)
|
||||
as snapshotSynchronizedAt,
|
||||
item.stock_id as stockId,
|
||||
item.tray_code as trayNo,
|
||||
item.space_id as spaceId,
|
||||
item.warehouse_id as warehouseId,
|
||||
nullif(ltrim(rtrim(item.project_no)), '') as projectNo,
|
||||
item.product_no as productId,
|
||||
convert(varchar(40), item.synchronized_at, 126) as snapshotSynchronizedAt,
|
||||
(select count(*)
|
||||
from bas_stock live
|
||||
where live.stock_id = stock.stock_id
|
||||
and live.stock_status = '1'
|
||||
and live.product_status = '1'
|
||||
and live.quantity > live.out_quantity) as liveMatchCount,
|
||||
(select count(*)
|
||||
from alg.inventory_item_snapshot snapshot
|
||||
where snapshot.stock_id = stock.stock_id
|
||||
and snapshot.warehouse_id = stock.warehouse_id) as shadowMatchCount
|
||||
from bas_stock stock
|
||||
where stock.stock_id = #{stockId}
|
||||
and stock.stock_status = '1'
|
||||
and stock.product_status = '1'
|
||||
and stock.quantity > stock.out_quantity
|
||||
from alg.inventory_item_snapshot candidate
|
||||
where candidate.warehouse_id = #{warehouseId}
|
||||
and candidate.snapshot_generation = #{generation}
|
||||
and candidate.stock_id = #{stockId}
|
||||
and isnull(candidate.quantity, 0) > isnull(candidate.out_quantity, 0))
|
||||
as shadowMatchCount
|
||||
from alg.inventory_item_snapshot item
|
||||
where item.warehouse_id = #{warehouseId}
|
||||
and item.snapshot_generation = #{generation}
|
||||
and item.stock_id = #{stockId}
|
||||
and isnull(item.quantity, 0) > isnull(item.out_quantity, 0)
|
||||
</select>
|
||||
|
||||
<select id="claimInstance" resultType="boolean">
|
||||
if convert(int, #{staleSeconds}) <> 120
|
||||
throw 51026, 'shadow instance stale threshold must be 120 seconds', 1;
|
||||
declare @claimed bit;
|
||||
exec alg.usp_claim_shadow_instance
|
||||
@warehouse_id = #{warehouseId},
|
||||
@instance_id = #{instanceId},
|
||||
@claimed = @claimed output;
|
||||
</select>
|
||||
|
||||
<update id="refreshSnapshot">
|
||||
exec alg.usp_refresh_shadow_snapshot
|
||||
@warehouse_id = #{warehouseId},
|
||||
@snapshot_generation = #{generation},
|
||||
@instance_id = #{instanceId};
|
||||
</update>
|
||||
|
||||
<select id="selectPublishedSnapshot"
|
||||
resultType="com.ruoyi.algorithm.shadow.ShadowSnapshotDescriptor">
|
||||
select state.snapshot_generation as snapshotGeneration,
|
||||
state.warehouse_id as warehouseId,
|
||||
state.snapshot_status as snapshotStatus,
|
||||
state.synchronized_at as synchronizedAt,
|
||||
convert(varchar(64), state.source_signature, 2) as sourceSignature
|
||||
from alg.shadow_snapshot_state state
|
||||
where state.warehouse_id = #{warehouseId}
|
||||
</select>
|
||||
|
||||
<insert id="insertComparison">
|
||||
@@ -84,6 +105,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
decision_id, warehouse_id, decision_type, input_version, result_code, reason)
|
||||
values (
|
||||
try_convert(uniqueidentifier, #{decisionId}), #{warehouseId}, #{decisionType},
|
||||
null, #{resultCode}, #{reason})
|
||||
convert(binary(8), #{inputVersion}), #{resultCode}, #{reason})
|
||||
</insert>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user