feat: enforce dense lane outermost order

This commit is contained in:
zgw
2026-07-16 10:14:19 +08:00
parent 9158a5fa54
commit 66830dc649
9 changed files with 612 additions and 2 deletions

View File

@@ -4,6 +4,221 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.out.dense.mapper.DenseLaneMapper">
<resultMap id="DenseLanePositionResult" type="com.ruoyi.out.dense.domain.DenseLanePosition">
<id property="cargoSpaceId" column="cargo_space_id" />
<result property="cargoSpaceName" column="cargo_space_name" />
<result property="warehouseId" column="warehouse_id" />
<result property="groupCoding" column="group_coding" />
<result property="cargoArea" column="this_cargo_area" />
<result property="thePlatoon" column="the_platoon" />
<result property="theColumn" column="the_column" />
<result property="theFloor" column="the_floor" />
<result property="status" column="status" />
<result property="locked" column="locked" />
<result property="trayCode" column="tray_code" />
<result property="directionType" column="direction_type" />
<result property="minColumn" column="min_column" />
<result property="maxColumn" column="max_column" />
</resultMap>
<select id="selectPosition" resultMap="DenseLanePositionResult">
select source_space.cargo_space_id,
source_space.cargo_space_name,
source_space.warehouse_id,
source_space.group_coding,
source_space.this_cargo_area,
source_space.the_platoon,
source_space.the_column,
source_space.the_floor,
source_space.status,
source_space.locked,
source_space.tray_code,
isnull(area_config.direction_type, '1') as direction_type,
boundary.min_column,
boundary.max_column
from bas_cargo_space source_space
left join bas_cargo_area_config area_config
on area_config.warehouse_id = source_space.warehouse_id
and area_config.cargo_area_code = source_space.this_cargo_area
and area_config.is_active = '1'
outer apply
(
select min(the_column) as min_column,
max(the_column) as max_column
from bas_cargo_space lane_space
where lane_space.warehouse_id = source_space.warehouse_id
and lane_space.group_coding = source_space.group_coding
and lane_space.the_floor = source_space.the_floor
) boundary
where source_space.cargo_space_id = #{cargoSpaceId}
</select>
<select id="selectOccupiedLanePositions" resultMap="DenseLanePositionResult">
select occupied.cargo_space_id,
occupied.cargo_space_name,
occupied.warehouse_id,
occupied.group_coding,
occupied.this_cargo_area,
occupied.the_platoon,
occupied.the_column,
occupied.the_floor,
occupied.status,
occupied.locked,
occupied.tray_code,
isnull(area_config.direction_type, '1') as direction_type,
boundary.min_column,
boundary.max_column
from bas_cargo_space occupied
left join bas_cargo_area_config area_config
on area_config.warehouse_id = occupied.warehouse_id
and area_config.cargo_area_code = occupied.this_cargo_area
and area_config.is_active = '1'
cross apply
(
select min(lane_space.the_column) as min_column,
max(lane_space.the_column) as max_column
from bas_cargo_space lane_space
where lane_space.warehouse_id = occupied.warehouse_id
and lane_space.group_coding = occupied.group_coding
and lane_space.the_floor = occupied.the_floor
) boundary
where occupied.warehouse_id = #{warehouseId}
and occupied.group_coding = #{groupCoding}
and occupied.the_floor = #{theFloor}
and occupied.status in ('2', '3', '4')
and occupied.tray_code is not null
and ltrim(rtrim(occupied.tray_code)) != ''
</select>
<select id="selectBlockersForUpdate" resultMap="DenseLanePositionResult">
;with source_position as
(
select source_space.warehouse_id,
source_space.group_coding,
source_space.the_floor,
source_space.the_column,
isnull(area_config.direction_type, '1') as direction_type,
boundary.min_column,
boundary.max_column,
case when source_space.the_column - boundary.min_column
&lt;= boundary.max_column - source_space.the_column
then source_space.the_column - boundary.min_column
else boundary.max_column - source_space.the_column end as distance_to_edge
from bas_cargo_space source_space with (UPDLOCK,HOLDLOCK)
left join bas_cargo_area_config area_config
on area_config.warehouse_id = source_space.warehouse_id
and area_config.cargo_area_code = source_space.this_cargo_area
and area_config.is_active = '1'
cross apply
(
select min(lane_space.the_column) as min_column,
max(lane_space.the_column) as max_column
from bas_cargo_space lane_space with (UPDLOCK,HOLDLOCK)
where lane_space.warehouse_id = source_space.warehouse_id
and lane_space.group_coding = source_space.group_coding
and lane_space.the_floor = source_space.the_floor
) boundary
where source_space.cargo_space_id = #{cargoSpaceId}
and source_space.warehouse_id = '03'
and source_space.group_coding is not null
), lane_positions as
(
select occupied.cargo_space_id,
occupied.cargo_space_name,
occupied.warehouse_id,
occupied.group_coding,
occupied.this_cargo_area,
occupied.the_platoon,
occupied.the_column,
occupied.the_floor,
occupied.status,
occupied.locked,
occupied.tray_code,
source.direction_type,
source.min_column,
source.max_column,
case when occupied.the_column - source.min_column
&lt;= source.max_column - occupied.the_column
then occupied.the_column - source.min_column
else source.max_column - occupied.the_column end as distance_to_edge,
source.the_column as source_column,
source.distance_to_edge as source_distance
from bas_cargo_space occupied with (UPDLOCK,HOLDLOCK)
inner join source_position source
on source.warehouse_id = occupied.warehouse_id
and source.group_coding = occupied.group_coding
and source.the_floor = occupied.the_floor
where occupied.status in ('2', '3', '4')
and occupied.tray_code is not null
and ltrim(rtrim(occupied.tray_code)) != ''
and not exists
(
select 1
from mydo_job active_job with (UPDLOCK,HOLDLOCK)
where active_job.in_or_out &gt;= 20
and active_job.status in ('1', '2', '3')
and (active_job.cargo_space_id = occupied.cargo_space_id
or active_job.tray_code = occupied.tray_code)
)
)
select cargo_space_id, cargo_space_name, warehouse_id, group_coding,
this_cargo_area, the_platoon, the_column, the_floor, status,
locked, tray_code, direction_type, min_column, max_column
from lane_positions
where (direction_type = '1' and the_column &gt; source_column)
or (direction_type = '2' and the_column &lt; source_column)
or (direction_type = '3' and
(distance_to_edge &lt; source_distance
or (distance_to_edge = source_distance and the_column &lt; source_column)))
order by case when direction_type = '1' then the_column end desc,
case when direction_type = '2' then the_column end asc,
case when direction_type = '3' then distance_to_edge end asc,
the_column asc
</select>
<select id="selectRelocationTargetForUpdate"
parameterType="com.ruoyi.out.dense.domain.RelocationTargetQuery"
resultType="com.ruoyi.bas.cargospace.domain.BasCargoSpace">
select top 1 target_space.*
from bas_cargo_space target_space with (UPDLOCK,HOLDLOCK,ROWLOCK)
left join bas_cargo_area_config area_config
on area_config.warehouse_id = target_space.warehouse_id
and area_config.cargo_area_code = target_space.this_cargo_area
and area_config.is_active = '1'
where target_space.warehouse_id = #{warehouseId}
and target_space.the_floor = #{theFloor}
and target_space.group_coding != #{sourceGroupCoding}
and target_space.group_coding is not null
and target_space.status = '1'
and isnull(target_space.locked, 'N') = 'N'
and target_space.tray_code is null
<if test="targetGroupCoding != null and targetGroupCoding != ''">
and target_space.group_coding = #{targetGroupCoding}
</if>
<if test="cargoSpaceType != null and cargoSpaceType != ''">
and target_space.the_type = #{cargoSpaceType}
</if>
<if test="height != null">
and target_space.the_height &gt;= #{height}
</if>
and not exists
(
select 1
from mydo_job active_job with (UPDLOCK,HOLDLOCK)
where active_job.status in ('1', '2', '3')
and (active_job.cargo_space_id = target_space.cargo_space_id
or active_job.target_cargo_space_id = target_space.cargo_space_id)
)
order by case when isnull(area_config.direction_type, '1') = '1'
then target_space.the_column end asc,
case when area_config.direction_type = '2'
then target_space.the_column end desc,
case when area_config.direction_type = '3'
then abs(target_space.the_column - 1) end asc,
target_space.group_coding asc,
target_space.cargo_space_id asc
</select>
<select id="isCurrentOutermost" resultType="java.lang.Integer">
select case
when source_space.warehouse_id != '03'