116 lines
5.5 KiB
XML
116 lines
5.5 KiB
XML
<?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.algorithm.shadow.mapper.ShadowInputMapper">
|
|
|
|
<select id="selectInboundInput" resultType="com.ruoyi.algorithm.shadow.ShadowInboundReference">
|
|
select top (1)
|
|
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 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 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 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)
|
|
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 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 with (readcommittedlock)
|
|
where state.warehouse_id = #{warehouseId}
|
|
</select>
|
|
|
|
<insert id="insertComparison">
|
|
insert into alg.decision_log (
|
|
decision_id, warehouse_id, decision_type, input_version, result_code, reason)
|
|
select try_convert(uniqueidentifier, #{decisionId}), state.warehouse_id, #{decisionType},
|
|
convert(binary(8), #{inputVersion}), #{resultCode}, #{reason}
|
|
from alg.shadow_snapshot_state state with (updlock, holdlock)
|
|
where state.warehouse_id = #{warehouseId}
|
|
and state.snapshot_status = 'PUBLISHED'
|
|
and state.snapshot_generation = #{inputVersion}
|
|
and state.synchronized_at = #{snapshotSynchronizedAt}
|
|
and convert(varchar(64), state.source_signature, 2) = #{sourceSignature}
|
|
</insert>
|
|
</mapper>
|