feat: 完善WCS调度、库存追溯和出库分配

This commit is contained in:
zgw
2026-07-15 16:24:07 +08:00
parent 9d3aa7a3bd
commit 66ac268524
101 changed files with 12596 additions and 669 deletions

View File

@@ -166,10 +166,15 @@ external:
reportMaterialConsume: /material/consume
reportQualityCheck: /quality/check
WCS:
base-url: http://172.16.4.63:8084
base-url: ${WCS_DEFAULT_BASE_URL:http://172.16.4.63:8084}
token: wcs-token
# 本地测试默认启用模拟返回;联调或生产设为 false 即可恢复真实 WCS 调用
mock-enabled: false
mock-enabled: true
# 各仓库WCS地址独立配置;未列出的仓库兼容使用上面的默认地址。
warehouse-base-urls:
'01': ${WCS_01_BASE_URL:${WCS_DEFAULT_BASE_URL:http://172.16.4.63:8084}}
'02': ${WCS_02_BASE_URL:${WCS_DEFAULT_BASE_URL:http://172.16.4.63:8084}}
'03': ${WCS_03_BASE_URL:${WCS_DEFAULT_BASE_URL:http://172.16.4.63:8084}}
apis:
sendPutawayTask: /wcs/api/receiveWmsJob
sendRetrieveTask: /wcs/api/receiveWmsJob

View File

@@ -35,7 +35,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasCargoSpaceList" parameterType="BasCargoSpace" resultMap="BasCargoSpaceResult">
<include refid="selectBasCargoSpaceVo"/>
<where>
<where>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id like concat('%', #{cargoSpaceId}, '%')</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="roadwayId != null and roadwayId != ''"> and roadway_id = #{roadwayId}</if>
<if test="cargoAreaId != null and cargoAreaId != ''"> and cargo_area_id = #{cargoAreaId}</if>
@@ -245,32 +246,287 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<select id="selectAvailableInboundCargoSpaceInRoadway" parameterType="com.ruoyi.in.job.domain.MydoJob" resultMap="BasCargoSpaceResult">
select top 1 cargo_space_id, warehouse_id, roadway_id, cargo_area_id, the_type, the_type_name, cargo_space_name, the_platoon, the_column, the_floor, status, locked, tray_code, iss_double, group_coding_no, group_coding, cargo_space_logo, this_cargo_area, dept_id, dept_name, the_weight, the_height
from (
select bcs.cargo_space_id, bcs.warehouse_id, bcs.roadway_id, bcs.cargo_area_id, bcs.the_type, bcs.the_type_name,
bcs.cargo_space_name, bcs.the_platoon, bcs.the_column, bcs.the_floor, bcs.status, bcs.locked,
bcs.tray_code, bcs.iss_double, bcs.group_coding_no, bcs.group_coding, bcs.cargo_space_logo,
bcs.this_cargo_area, bcs.dept_id, bcs.dept_name, bcs.the_weight, bcs.the_height,
count(1) over (partition by bcs.the_platoon) as platoon_empty_count
from bas_cargo_space bcs
where bcs.warehouse_id = #{warehouseId}
and bcs.roadway_id = #{roadwayId}
and bcs.status = '1'
and ISNULL(bcs.locked, 'N') = 'N'
and (#{cargoSpaceId} is null or bcs.cargo_space_id != #{cargoSpaceId})
and bcs.the_type = (select top 1 btr.allowed_cargo_type
from bas_tray_rule btr
where btr.tray_type is not null
and btr.tray_type != ''
and #{trayCode} is not null
and #{trayCode} != ''
and left(#{trayCode}, len(btr.tray_type)) = btr.tray_type
and charindex(',' + #{warehouseId} + ',', ',' + btr.allowed_warehouses + ',') &gt; 0
order by len(btr.tray_type) desc, btr.id)
) candidate
order by platoon_empty_count desc, the_platoon asc, the_floor asc, the_column asc, cargo_space_id asc
<choose>
<when test="warehouseId == '03'">
;with lift_conflict_floors as (
select distinct outbound_space.the_floor as conflict_floor
from mydo_job inbound_job
inner join mydo_job outbound_job
on outbound_job.warehouse_id = inbound_job.warehouse_id
and outbound_job.exit_id = inbound_job.entrance_id
inner join bas_cargo_space outbound_space
on outbound_space.cargo_space_id = outbound_job.cargo_space_id
where inbound_job.job_id = #{jobId}
and outbound_job.in_or_out &gt;= 20
and outbound_job.status = '3'
and outbound_space.the_floor is not null
),
available_slots as (
select bcs.cargo_space_id, bcs.warehouse_id, bcs.roadway_id, bcs.cargo_area_id,
bcs.the_type, bcs.the_type_name, bcs.cargo_space_name, bcs.the_platoon,
bcs.the_column, bcs.the_floor, bcs.status, bcs.locked, bcs.tray_code,
bcs.iss_double, bcs.group_coding_no, bcs.group_coding, bcs.cargo_space_logo,
bcs.this_cargo_area, bcs.dept_id, bcs.dept_name, bcs.the_weight, bcs.the_height,
coalesce(cac.direction_type, '1') as direction_type,
case when bcs.the_height = #{height} then 0 else 1 end as height_priority,
case
when upper(ltrim(rtrim(isnull(#{entranceId}, '')))) in ('03-AU-01', '03-AU-03')
then case when bcs.this_cargo_area in ('G', 'H') then 0 else 1 end
when upper(ltrim(rtrim(isnull(#{entranceId}, '')))) in ('03-AU-02', '03-AU-04')
then case when bcs.this_cargo_area in ('A', 'B') then 0 else 1 end
else 0
end as entrance_area_priority
from bas_cargo_space bcs
left join bas_cargo_area_config cac
on cac.warehouse_id = bcs.warehouse_id
and cac.cargo_area_code = bcs.this_cargo_area
and cac.is_active = '1'
where bcs.warehouse_id = #{warehouseId}
and bcs.the_floor = try_convert(bigint, #{roadwayId})
and bcs.the_height &gt;= #{height}
and bcs.status = '1'
and isnull(bcs.locked, 'N') = 'N'
and (bcs.tray_code is null or ltrim(rtrim(bcs.tray_code)) = '')
and (#{cargoSpaceId} is null or bcs.cargo_space_id != #{cargoSpaceId})
and bcs.group_coding is not null
and ltrim(rtrim(bcs.group_coding)) != ''
and ((bcs.this_cargo_area in ('A', 'B') and bcs.the_column between 1 and 6)
or (bcs.this_cargo_area in ('C', 'D') and bcs.the_column between 8 and 12)
or (bcs.this_cargo_area in ('E', 'F') and bcs.the_column between 14 and 18)
or (bcs.this_cargo_area in ('G', 'H') and bcs.the_column between 20 and 22))
and not exists (
select 1
from lift_conflict_floors
where lift_conflict_floors.conflict_floor = bcs.the_floor
)
and bcs.the_type = (select top 1 btr.allowed_cargo_type
from bas_tray_rule btr
where btr.tray_type is not null
and btr.tray_type != ''
and #{trayCode} is not null
and #{trayCode} != ''
and left(#{trayCode}, len(btr.tray_type)) = btr.tray_type
and charindex(',' + #{warehouseId} + ',', ',' + btr.allowed_warehouses + ',') &gt; 0
order by len(btr.tray_type) desc, btr.id)
),
stock_profiles as (
select occupied.cargo_space_id, occupied.group_coding,
case
when ltrim(rtrim(isnull(bsd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) != '' and bs.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) != '' and bs.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) = '' and bs.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(coalesce(bsd.project_no, bs.project_no))), '') as project_no,
nullif(ltrim(rtrim(bsd.product_id)), '') as product_id,
nullif(ltrim(rtrim(bsd.product_name)), '') as product_name
from bas_stock bs
inner join bas_stock_detail bsd on bsd.stock_id = bs.stock_id
inner join bas_cargo_space occupied on occupied.cargo_space_id = bs.cargo_space_id
where bs.warehouse_id = #{warehouseId}
and occupied.the_floor = try_convert(bigint, #{roadwayId})
and occupied.group_coding is not null
and isnull(bsd.quantity, 0) - isnull(bsd.out_quantity, 0) &gt; 0
),
assigned_job_profiles as (
select assigned.cargo_space_id, assigned.group_coding,
case
when ltrim(rtrim(isnull(jd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) = '' and ins.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(jd.project_no)), '') as project_no,
nullif(ltrim(rtrim(jd.product_id)), '') as product_id,
nullif(ltrim(rtrim(jd.product_name)), '') as product_name
from mydo_job j
inner join mydo_job_detail jd on jd.job_id = j.job_id
left join in_stockin ins on ins.stockin_id = jd.stockin_id
inner join bas_cargo_space assigned on assigned.cargo_space_id = j.cargo_space_id
where j.warehouse_id = #{warehouseId}
and assigned.the_floor = try_convert(bigint, #{roadwayId})
and j.in_or_out &lt; 20
and j.status in ('1', '2', '3')
and j.job_id != #{jobId}
and assigned.group_coding is not null
),
reserved_job_profiles as (
select reserved.cargo_space_id, reserved.group_coding,
case
when ltrim(rtrim(isnull(jd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) = '' and ins.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(jd.project_no)), '') as project_no,
nullif(ltrim(rtrim(jd.product_id)), '') as product_id,
nullif(ltrim(rtrim(jd.product_name)), '') as product_name
from bas_cargo_space reserved
inner join mydo_job j
on j.warehouse_id = reserved.warehouse_id
and j.tray_code = reserved.tray_code
inner join mydo_job_detail jd on jd.job_id = j.job_id
left join in_stockin ins on ins.stockin_id = jd.stockin_id
where reserved.warehouse_id = #{warehouseId}
and reserved.the_floor = try_convert(bigint, #{roadwayId})
and reserved.status = '3'
and reserved.tray_code is not null
and ltrim(rtrim(reserved.tray_code)) != ''
and reserved.group_coding is not null
and j.in_or_out &lt; 20
and j.status in ('1', '2', '3')
and j.job_id != #{jobId}
),
profiled_occupancy as (
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from stock_profiles
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from assigned_job_profiles
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from reserved_job_profiles
),
occupied_spaces as (
select bcs.cargo_space_id, bcs.group_coding
from bas_cargo_space bcs
where bcs.warehouse_id = #{warehouseId}
and bcs.the_floor = try_convert(bigint, #{roadwayId})
and bcs.group_coding is not null
and bcs.status not in ('1', '7', '8', '9', '10')
),
unknown_occupancy as (
select occupied.cargo_space_id, occupied.group_coding, 'UNKNOWN' as storage_mode,
cast(null as nvarchar(80)) as project_no,
cast(null as nvarchar(80)) as product_id,
cast(null as nvarchar(200)) as product_name
from occupied_spaces occupied
where not exists (
select 1 from profiled_occupancy profiled
where profiled.cargo_space_id = occupied.cargo_space_id
)
),
all_occupancy as (
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from profiled_occupancy
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from unknown_occupancy
),
eligible_lanes as (
select lane.group_coding,
case when count(distinct occupancy.cargo_space_id) &gt; 0 then 1 else 0 end as has_occupancy,
count(distinct occupancy.cargo_space_id) as occupied_space_count
from (select distinct group_coding from available_slots) lane
left join all_occupancy occupancy on occupancy.group_coding = lane.group_coding
group by lane.group_coding
having sum(case
when occupancy.cargo_space_id is null then 0
when #{storageMode} = 'EMPTY_TRAY' and occupancy.storage_mode = 'EMPTY_TRAY'
and occupancy.product_id = 'KTP0001' then 0
when #{storageMode} = 'RAW_PRODUCT' and occupancy.storage_mode = 'RAW_PRODUCT'
and occupancy.project_no is null
and occupancy.product_id = #{productId}
and occupancy.product_name = #{productName} then 0
when #{storageMode} in ('RAW_PROJECT', 'SEMI_PROJECT')
and occupancy.storage_mode in ('RAW_PROJECT', 'SEMI_PROJECT')
and occupancy.project_no = #{projectNo} then 0
else 1
end) = 0
),
lane_candidates as (
select slots.*, lanes.has_occupancy, lanes.occupied_space_count,
abs(convert(bigint, checksum(slots.group_coding, #{trayCode}))) as lane_random_key
from available_slots slots
inner join eligible_lanes lanes on lanes.group_coding = slots.group_coding
)
select top 1 cargo_space_id, warehouse_id, roadway_id, cargo_area_id, the_type,
the_type_name, cargo_space_name, the_platoon, the_column, the_floor, status,
locked, tray_code, iss_double, group_coding_no, group_coding, cargo_space_logo,
this_cargo_area, dept_id, dept_name, the_weight, the_height
from lane_candidates
order by height_priority asc,
entrance_area_priority asc,
case when #{storageMode} = 'EMPTY_TRAY' then lane_random_key end asc,
case when #{storageMode} != 'EMPTY_TRAY' then has_occupancy end desc,
case when #{storageMode} != 'EMPTY_TRAY' then occupied_space_count end desc,
group_coding asc,
the_platoon asc,
the_floor asc,
case when direction_type = '1' then the_column end asc,
case when direction_type = '2' then the_column end desc,
the_column asc,
cargo_space_id asc
</when>
<otherwise>
select top 1 cargo_space_id, warehouse_id, roadway_id, cargo_area_id, the_type, the_type_name, cargo_space_name, the_platoon, the_column, the_floor, status, locked, tray_code, iss_double, group_coding_no, group_coding, cargo_space_logo, this_cargo_area, dept_id, dept_name, the_weight, the_height
from (
select bcs.cargo_space_id, bcs.warehouse_id, bcs.roadway_id, bcs.cargo_area_id, bcs.the_type, bcs.the_type_name,
bcs.cargo_space_name, bcs.the_platoon, bcs.the_column, bcs.the_floor, bcs.status, bcs.locked,
bcs.tray_code, bcs.iss_double, bcs.group_coding_no, bcs.group_coding, bcs.cargo_space_logo,
bcs.this_cargo_area, bcs.dept_id, bcs.dept_name, bcs.the_weight, bcs.the_height,
coalesce(cac.direction_type, '1') as direction_type,
min(bcs.the_column) over (partition by bcs.warehouse_id, bcs.this_cargo_area) as area_min_column,
max(bcs.the_column) over (partition by bcs.warehouse_id, bcs.this_cargo_area) as area_max_column,
case when bcs.the_height = #{height} then 0 else 1 end as height_priority,
count(1) over (partition by bcs.the_platoon) as platoon_empty_count
from bas_cargo_space bcs
left join bas_cargo_area_config cac
on cac.warehouse_id = bcs.warehouse_id
and cac.cargo_area_code = bcs.this_cargo_area
and cac.is_active = '1'
where bcs.warehouse_id = #{warehouseId}
and bcs.roadway_id = #{roadwayId}
and bcs.the_height &gt;= #{height}
and bcs.status = '1'
and ISNULL(bcs.locked, 'N') = 'N'
and (bcs.tray_code is null or ltrim(rtrim(bcs.tray_code)) = '')
and (#{cargoSpaceId} is null or bcs.cargo_space_id != #{cargoSpaceId})
and bcs.the_type = (select top 1 btr.allowed_cargo_type
from bas_tray_rule btr
where btr.tray_type is not null
and btr.tray_type != ''
and #{trayCode} is not null
and #{trayCode} != ''
and left(#{trayCode}, len(btr.tray_type)) = btr.tray_type
and charindex(',' + #{warehouseId} + ',', ',' + btr.allowed_warehouses + ',') &gt; 0
order by len(btr.tray_type) desc, btr.id)
) candidate
order by height_priority asc, platoon_empty_count desc,
the_platoon asc, the_floor asc,
case when direction_type = '1' then the_column end asc,
case when direction_type = '2' then the_column end desc,
case when direction_type = '3' then
case
when the_column - area_min_column &lt;= area_max_column - the_column
then the_column - area_min_column
else area_max_column - the_column
end
end asc,
case when direction_type = '3' then the_column end asc,
cargo_space_id asc
</otherwise>
</choose>
</select>
<update id="lockAvailableInboundCargoSpace" parameterType="com.ruoyi.bas.cargospace.domain.BasCargoSpace">
update bas_cargo_space
set status = '3',
tray_code = #{trayCode}
where cargo_space_id = #{cargoSpaceId}
and warehouse_id = #{warehouseId}
<choose>
<when test="warehouseId == '03'">
and the_floor = #{theFloor}
</when>
<otherwise>
and roadway_id = #{roadwayId}
</otherwise>
</choose>
and the_height &gt;= #{theHeight}
and status = '1'
and ISNULL(locked, 'N') = 'N'
and (tray_code is null or ltrim(rtrim(tray_code)) = '')
</update>
<delete id="deleteBasCargoSpaceByCargoSpaceId" parameterType="String">
delete from bas_cargo_space where cargo_space_id = #{cargoSpaceId}
</delete>

View File

@@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="outQuantity" column="out_quantity" />
<result property="jobDetailId" column="job_detail_id" />
<result property="stockinDetailId" column="stockin_detail_id" />
<result property="projectNo" column="project_no" />
<result property="cargoSpaceId" column="cargo_space_id" />
<result property="cargoSpaceName" column="cargo_space_name" />
<result property="stockStatus" column="stock_status" />
@@ -32,7 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectBasStockDetailVo">
select bsd.detail_id, bsd.stock_id, bsd.product_status, bsd.lot_no, bsd.product_id, bsd.product_name,
bsd.quantity, bsd.out_quantity, bsd.job_detail_id, bsd.stockin_detail_id,
bsd.quantity, bsd.out_quantity, bsd.job_detail_id, bsd.stockin_detail_id, bsd.project_no,
bs.cargo_space_id, bcs.cargo_space_name, bs.stock_status, bs.in_date, bs.back_date,
bs.tray_code, bs.warehouse_id, ISNULL(NULLIF(bs.warehouse_name, ''), bw.warehouse_name) as warehouse_name,
bbf.tray_type,
@@ -65,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="productName != null and productName != ''"> and bsd.product_name like concat('%', #{productName}, '%')</if>
<if test="jobDetailId != null and jobDetailId != ''"> and bsd.job_detail_id = #{jobDetailId}</if>
<if test="stockinDetailId != null and stockinDetailId != ''"> and bsd.stockin_detail_id = #{stockinDetailId}</if>
<if test="projectNo != null and projectNo != ''"> and bsd.project_no = #{projectNo}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and bs.cargo_space_id = #{cargoSpaceId}</if>
<if test="stockStatus != null and stockStatus != ''"> and bs.stock_status = #{stockStatus}</if>
<if test="trayCode != null and trayCode != ''"> and bs.tray_code = #{trayCode}</if>
@@ -108,6 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outQuantity != null">out_quantity,</if>
<if test="jobDetailId != null">job_detail_id,</if>
<if test="stockinDetailId != null">stockin_detail_id,</if>
<if test="projectNo != null">project_no,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
@@ -123,6 +126,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outQuantity != null">#{outQuantity},</if>
<if test="jobDetailId != null">#{jobDetailId},</if>
<if test="stockinDetailId != null">#{stockinDetailId},</if>
<if test="projectNo != null">#{projectNo},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
@@ -139,8 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="productName != null">product_name = #{productName},</if>
<if test="quantity != null">quantity = #{quantity},</if>
<if test="outQuantity != null">out_quantity = #{outQuantity},</if>
<if test="jobDetailId != null">job_detail_id = #{jobDetailId},</if>
<if test="stockinDetailId != null">stockin_detail_id = #{stockinDetailId},</if>
<if test="projectNo != null">project_no = #{projectNo},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>

View File

@@ -21,6 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="outQuantity" column="out_quantity" />
<result property="stockinDetailId" column="stockin_detail_id" />
<result property="stockinId" column="stockin_id" />
<result property="projectNo" column="project_no" />
<result property="inType" column="in_type" />
<result property="warehouseId" column="warehouse_id" />
<result property="warehouseName" column="warehouse_name" />
@@ -35,7 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectBasStockVo">
select stock_id, cargo_space_id, stock_status, product_status, lot_no, in_date, back_date, product_id, product_name, quantity, job_id, job_detail_id, tray_code, out_quantity, stockin_detail_id, stockin_id, in_type, warehouse_id,
select stock_id, cargo_space_id, stock_status, product_status, lot_no, in_date, back_date, product_id, product_name, quantity, job_id, job_detail_id, tray_code, out_quantity, stockin_detail_id, stockin_id, project_no, in_type, warehouse_id,
ISNULL(NULLIF(warehouse_name, ''), (select top 1 bw.warehouse_name from bas_warehouse bw where bw.warehouse_id = bas_stock.warehouse_id)) as warehouse_name,
user_id, user_name, dept_id, dept_name, supplier_id as suplier_id, supplier_name as suplier_name from bas_stock
</sql>
@@ -48,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bs.job_id, null as job_detail_id,
bs.tray_code, ISNULL(bsa.out_quantity, 0) as out_quantity,
null as stockin_detail_id,
bs.stockin_id, bs.in_type, bs.warehouse_id, ISNULL(NULLIF(bs.warehouse_name, ''), bw.warehouse_name) as warehouse_name,
bs.stockin_id, bs.project_no, bs.in_type, bs.warehouse_id, ISNULL(NULLIF(bs.warehouse_name, ''), bw.warehouse_name) as warehouse_name,
bs.user_id, bs.user_name, bs.dept_id, bs.dept_name, bs.supplier_id as suplier_id, bs.supplier_name as suplier_name,
ISNULL(bsa.detail_count, 0) as detail_count,
ISNULL(bsa.quantity, 0) - ISNULL(bsa.out_quantity, 0) as available_quantity
@@ -81,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outQuantity != null "> and (ISNULL(bsa.out_quantity, 0) = #{outQuantity} or exists (select 1 from bas_stock_detail x where x.stock_id = bs.stock_id and x.out_quantity = #{outQuantity}))</if>
<if test="stockinDetailId != null and stockinDetailId != ''"> and exists (select 1 from bas_stock_detail x where x.stock_id = bs.stock_id and x.stockin_detail_id = #{stockinDetailId})</if>
<if test="stockinId != null and stockinId != ''"> and bs.stockin_id = #{stockinId}</if>
<if test="projectNo != null and projectNo != ''"> and (bs.project_no = #{projectNo} or exists (select 1 from bas_stock_detail x where x.stock_id = bs.stock_id and x.project_no = #{projectNo}))</if>
<if test="inType != null and inType != ''"> and bs.in_type = #{inType}</if>
<if test="warehouseId != null and warehouseId != ''"> and bs.warehouse_id = #{warehouseId}</if>
<if test="warehouseName != null and warehouseName != ''"> and ISNULL(NULLIF(bs.warehouse_name, ''), bw.warehouse_name) like concat('%', #{warehouseName}, '%')</if>
@@ -115,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outQuantity != null">out_quantity,</if>
<if test="stockinDetailId != null">stockin_detail_id,</if>
<if test="stockinId != null">stockin_id,</if>
<if test="projectNo != null">project_no,</if>
<if test="inType != null">in_type,</if>
<if test="warehouseId != null">warehouse_id,</if>
<if test="warehouseName != null">warehouse_name,</if>
@@ -142,6 +145,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outQuantity != null">#{outQuantity},</if>
<if test="stockinDetailId != null">#{stockinDetailId},</if>
<if test="stockinId != null">#{stockinId},</if>
<if test="projectNo != null">#{projectNo},</if>
<if test="inType != null">#{inType},</if>
<if test="warehouseId != null">#{warehouseId},</if>
<if test="warehouseName != null">#{warehouseName},</if>
@@ -172,6 +176,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outQuantity != null">out_quantity = #{outQuantity},</if>
<if test="stockinDetailId != null">stockin_detail_id = #{stockinDetailId},</if>
<if test="stockinId != null">stockin_id = #{stockinId},</if>
<if test="projectNo != null">project_no = #{projectNo},</if>
<if test="inType != null">in_type = #{inType},</if>
<if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
<if test="warehouseName != null">warehouse_name = #{warehouseName},</if>

View File

@@ -25,16 +25,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="inventoryStatus" column="inventory_" />
<result property="sourceDocN" column="source_doc_n" />
<result property="remar" column="remar" />
<result property="projectNo" column="project_no" />
</resultMap>
<sql id="selectInStockinDetailVo">
select stockin_detail_id, stockin_id, lot_no, product_id, product_name, quantity, scan_num, assign_num, remark,
line_n, item_cod, item_nam, spec_mode, uni, actual_qt, warehous, locatio, inventory_, source_doc_n, remar
line_n, item_cod, item_nam, spec_mode, uni, actual_qt, warehous, locatio, inventory_, source_doc_n, remar, project_no
from in_stockin_detail
</sql>
<sql id="selectInStockinDetailFinishVo">
select stockin_detail_id, stockin_id, lot_no, product_id, product_name, quantity, scan_num, assign_num, remark,
line_n, item_cod, item_nam, spec_mode, uni, actual_qt, warehous, locatio, inventory_, source_doc_n, remar
line_n, item_cod, item_nam, spec_mode, uni, actual_qt, warehous, locatio, inventory_, source_doc_n, remar, project_no
from in_stockin_detail_finish
</sql>
@@ -50,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="assignNum != null">and assign_num = #{assignNum}</if>
<if test="itemCod != null and itemCod != ''">and item_cod like concat('%', #{itemCod}, '%')</if>
<if test="itemNam != null and itemNam != ''">and item_nam like concat('%', #{itemNam}, '%')</if>
<if test="projectNo != null and projectNo != ''">and project_no = #{projectNo}</if>
</where>
</select>
@@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="stockinDetailId != null and stockinDetailId != ''">and stockin_detail_id = #{stockinDetailId}</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="projectNo != null and projectNo != ''">and project_no = #{projectNo}</if>
</where>
order by line_n asc, stockin_detail_id asc
</select>
@@ -83,6 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="assignNum != null">and assign_num = #{assignNum}</if>
<if test="itemCod != null and itemCod != ''">and item_cod like concat('%', #{itemCod}, '%')</if>
<if test="itemNam != null and itemNam != ''">and item_nam like concat('%', #{itemNam}, '%')</if>
<if test="projectNo != null and projectNo != ''">and project_no = #{projectNo}</if>
</where>
</select>
@@ -109,6 +113,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="inventoryStatus != null and inventoryStatus != ''">inventory_,</if>
<if test="sourceDocN != null and sourceDocN != ''">source_doc_n,</if>
<if test="remar != null and remar != ''">remar,</if>
<if test="projectNo != null and projectNo != ''">project_no,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="stockinDetailId != null">#{stockinDetailId},</if>
@@ -131,6 +136,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="inventoryStatus != null and inventoryStatus != ''">#{inventoryStatus},</if>
<if test="sourceDocN != null and sourceDocN != ''">#{sourceDocN},</if>
<if test="remar != null and remar != ''">#{remar},</if>
<if test="projectNo != null and projectNo != ''">#{projectNo},</if>
</trim>
</insert>
@@ -156,6 +162,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="inventoryStatus != null and inventoryStatus != ''">inventory_ = #{inventoryStatus},</if>
<if test="sourceDocN != null and sourceDocN != ''">source_doc_n = #{sourceDocN},</if>
<if test="remar != null and remar != ''">remar = #{remar},</if>
<if test="projectNo != null and projectNo != ''">project_no = #{projectNo},</if>
</trim>
where stockin_detail_id = #{stockinDetailId}
</update>

View File

@@ -24,6 +24,7 @@
<result property="documentN" column="document_n" />
<result property="documentDat" column="document_dat" />
<result property="projectNam" column="project_nam" />
<result property="projectNo" column="project_no" />
<result property="counterpart" column="counterpart" />
<result property="receivingOr" column="receiving_or" />
<result property="purchasingOr" column="purchasing_or" />
@@ -47,14 +48,14 @@
<sql id="selectInStockinVo">
select stockin_id, in_type, stock_source, status, create_date, start_date, finish_date, erp_bill, warehouse_id, warehouse_name, user_id, user_name, dept_id, dept_name, supplier_id, supplier_name,
document_n, document_dat, project_nam, counterpart, receiving_or, purchasing_or, receiving_dep, purchasing_dep,
document_n, document_dat, project_nam, project_no, counterpart, receiving_or, purchasing_or, receiving_dep, purchasing_dep,
handle, creato, logistics_, logistics_n, warehous, print_coun, tota, reviewe, create_dat, review_dat,
receive, receiver_a, receiver_phon, material_re
from in_stockin
</sql>
<sql id="selectInStockinFinishVo">
select stockin_id, in_type, stock_source, status, create_date, start_date, finish_date, erp_bill, warehouse_id, warehouse_name, user_id, user_name, dept_id, dept_name, supplier_id, supplier_name,
document_n, document_dat, project_nam, counterpart, receiving_or, purchasing_or, receiving_dep, purchasing_dep,
document_n, document_dat, project_nam, project_no, counterpart, receiving_or, purchasing_or, receiving_dep, purchasing_dep,
handle, creato, logistics_, logistics_n, warehous, print_coun, tota, reviewe, create_dat, review_dat,
receive, receiver_a, receiver_phon, material_re
from in_stockin_finish
@@ -75,6 +76,7 @@
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="documentN != null and documentN != ''"> and document_n like concat('%', #{documentN}, '%')</if>
<if test="projectNam != null and projectNam != ''"> and project_nam like concat('%', #{projectNam}, '%')</if>
<if test="projectNo != null and projectNo != ''"> and project_no like concat('%', #{projectNo}, '%')</if>
<if test="counterpart != null and counterpart != ''"> and counterpart like concat('%', #{counterpart}, '%')</if>
${params.warehouseScope}
</where>
@@ -96,6 +98,7 @@
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
<if test="documentN != null and documentN != ''"> and document_n like concat('%', #{documentN}, '%')</if>
<if test="projectNo != null and projectNo != ''"> and project_no like concat('%', #{projectNo}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
${params.warehouseScope}
</where>
@@ -131,13 +134,14 @@
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="documentN != null and documentN != ''"> and document_n like concat('%', #{documentN}, '%')</if>
<if test="projectNam != null and projectNam != ''"> and project_nam like concat('%', #{projectNam}, '%')</if>
<if test="projectNo != null and projectNo != ''"> and project_no like concat('%', #{projectNo}, '%')</if>
<if test="counterpart != null and counterpart != ''"> and counterpart like concat('%', #{counterpart}, '%')</if>
${params.warehouseScope}
</where>
</select>
<select id="selectTop5InStockinList" resultMap="InStockinResult">
select TOP 5 stockin_id, in_type, stock_source, status, create_date, start_date, finish_date, erp_bill, warehouse_id, warehouse_name, user_id, user_name, dept_id, dept_name, supplier_id, supplier_name,
document_n, document_dat, project_nam, counterpart, receiving_or, purchasing_or, receiving_dep, purchasing_dep,
document_n, document_dat, project_nam, project_no, counterpart, receiving_or, purchasing_or, receiving_dep, purchasing_dep,
handle, creato, logistics_, logistics_n, warehous, print_coun, tota, reviewe, create_dat, review_dat,
receive, receiver_a, receiver_phon, material_re
from in_stockin
@@ -166,6 +170,7 @@
<if test="documentN != null and documentN != ''">document_n,</if>
<if test="documentDat != null">document_dat,</if>
<if test="projectNam != null and projectNam != ''">project_nam,</if>
<if test="projectNo != null and projectNo != ''">project_no,</if>
<if test="counterpart != null and counterpart != ''">counterpart,</if>
<if test="receivingOr != null and receivingOr != ''">receiving_or,</if>
<if test="purchasingOr != null and purchasingOr != ''">purchasing_or,</if>
@@ -206,6 +211,7 @@
<if test="documentN != null and documentN != ''">#{documentN},</if>
<if test="documentDat != null">#{documentDat},</if>
<if test="projectNam != null and projectNam != ''">#{projectNam},</if>
<if test="projectNo != null and projectNo != ''">#{projectNo},</if>
<if test="counterpart != null and counterpart != ''">#{counterpart},</if>
<if test="receivingOr != null and receivingOr != ''">#{receivingOr},</if>
<if test="purchasingOr != null and purchasingOr != ''">#{purchasingOr},</if>
@@ -249,6 +255,7 @@
<if test="documentN != null and documentN != ''">document_n = #{documentN},</if>
<if test="documentDat != null">document_dat = #{documentDat},</if>
<if test="projectNam != null and projectNam != ''">project_nam = #{projectNam},</if>
<if test="projectNo != null and projectNo != ''">project_no = #{projectNo},</if>
<if test="counterpart != null and counterpart != ''">counterpart = #{counterpart},</if>
<if test="receivingOr != null and receivingOr != ''">receiving_or = #{receivingOr},</if>
<if test="purchasingOr != null and purchasingOr != ''">purchasing_or = #{purchasingOr},</if>

View File

@@ -23,13 +23,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="customerName" column="customer_name" />
<result property="supplierId" column="supplier_id" />
<result property="supplierName" column="supplier_name" />
<result property="projectNo" column="project_no" />
</resultMap>
<sql id="selectMydoJobDetailVo">
select job_detail_id, job_id, stock_id, lot_no, in_date, in_or_out_id, in_or_out_d_id, product_id, product_name, in_quantity, stock_quantity, out_quantity, stockin_id, stockin_detail_id, customer_id, customer_name, supplier_id, supplier_name from mydo_job_detail
select job_detail_id, job_id, stock_id, lot_no, in_date, in_or_out_id, in_or_out_d_id, product_id, product_name, in_quantity, stock_quantity, out_quantity, stockin_id, stockin_detail_id, customer_id, customer_name, supplier_id, supplier_name, project_no from mydo_job_detail
</sql>
<sql id="selectMydoJobDetailFinishVo">
select job_detail_id, job_id, stock_id, lot_no, in_date, in_or_out_id, in_or_out_d_id, product_id, product_name, in_quantity, stock_quantity, out_quantity, stockin_id, stockin_detail_id, customer_id, customer_name, supplier_id, supplier_name from mydo_job_detail_finish
select job_detail_id, job_id, stock_id, lot_no, in_date, in_or_out_id, in_or_out_d_id, product_id, product_name, in_quantity, stock_quantity, out_quantity, stockin_id, stockin_detail_id, customer_id, customer_name, supplier_id, supplier_name, project_no from mydo_job_detail_finish
</sql>
<select id="selectMydoJobDetailList" parameterType="MydoJobDetail" resultMap="MydoJobDetailResult">
@@ -49,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="supplierId != null and supplierId != ''"> and supplier_id = #{supplierId}</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="projectNo != null and projectNo != ''"> and project_no = #{projectNo}</if>
</where>
</select>
@@ -73,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="supplierId != null and supplierId != ''"> and supplier_id = #{supplierId}</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="projectNo != null and projectNo != ''"> and project_no = #{projectNo}</if>
</where>
</select>
<insert id="insertMydoJobDetail" parameterType="MydoJobDetail">
@@ -96,6 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null">customer_name,</if>
<if test="supplierId != null">supplier_id,</if>
<if test="supplierName != null">supplier_name,</if>
<if test="projectNo != null">project_no,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="jobDetailId != null">#{jobDetailId},</if>
@@ -116,6 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null">#{customerName},</if>
<if test="supplierId != null">#{supplierId},</if>
<if test="supplierName != null">#{supplierName},</if>
<if test="projectNo != null">#{projectNo},</if>
</trim>
</insert>
@@ -139,6 +144,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null">customer_name = #{customerName},</if>
<if test="supplierId != null">supplier_id = #{supplierId},</if>
<if test="supplierName != null">supplier_name = #{supplierName},</if>
<if test="projectNo != null">project_no = #{projectNo},</if>
</trim>
where job_detail_id = #{jobDetailId}
</update>

View File

@@ -82,6 +82,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where job_id = #{jobId}
</select>
<select id="acquirePutOccupiedJobLock" parameterType="java.util.Map" resultType="java.lang.Integer">
declare @lock_result int;
declare @lock_resource nvarchar(255);
declare @job_id nvarchar(4000) = upper(rtrim(convert(nvarchar(4000), #{jobId})));
set @lock_resource = N'wms:put-occupied:'
+ convert(varchar(64), hashbytes('SHA2_256', concat(
N'j=', convert(nvarchar(20), datalength(@job_id)), N':', @job_id
)), 2);
exec @lock_result = sys.sp_getapplock
@Resource = @lock_resource,
@LockMode = 'Exclusive',
@LockOwner = 'Transaction',
@LockTimeout = 10000,
@DbPrincipal = N'public';
select @lock_result;
</select>
<select id="acquirePutOccupiedRoadwayLock" parameterType="java.util.Map" resultType="java.lang.Integer">
declare @lock_result int;
declare @lock_resource nvarchar(255);
declare @warehouse_id nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{warehouseId})));
declare @roadway_id nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{roadwayId})));
set @lock_resource = N'wms:inbound-roadway:'
+ convert(varchar(64), hashbytes('SHA2_256', concat(
N'w=', convert(nvarchar(20), datalength(@warehouse_id)), N':', @warehouse_id,
N'|r=', convert(nvarchar(20), datalength(@roadway_id)), N':', @roadway_id
)), 2);
exec @lock_result = sys.sp_getapplock
@Resource = @lock_resource,
@LockMode = 'Exclusive',
@LockOwner = 'Transaction',
@LockTimeout = 10000,
@DbPrincipal = N'public';
select @lock_result;
</select>
<select id="selectLatestInMydoJobByTrayCode" parameterType="String" resultMap="MydoJobResult">
select top 1 job_id, status, task_no, in_or_out, execution_phase, tray_code, warehouse_id, warehouse_name,
roadway_id, cargo_space_id, cargo_space_name, target_roadway_id, target_cargo_space_id,
@@ -93,6 +131,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_time desc
</select>
<select id="countMydoJobByTrayCode" parameterType="String" resultType="int">
select count(1) from mydo_job where tray_code = #{trayCode}
</select>
<update id="claimDenseInboundJob" parameterType="map">
update mydo_job
set entrance_id = #{entranceId}, height = #{height}, status = '3', execution_phase = '1',
start_time = coalesce(start_time, #{startTime})
where job_id = #{jobId}
and warehouse_id = '03'
and in_or_out &lt; 20
and status in ('1', '2')
and execution_phase = '0'
</update>
<select id="selectInMydoJobByTaskNo" parameterType="String" resultMap="MydoJobResult">
select top 1 job_id, status, task_no, in_or_out, execution_phase, tray_code, warehouse_id, warehouse_name,
roadway_id, cargo_space_id, cargo_space_name, target_roadway_id, target_cargo_space_id,
@@ -301,6 +354,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where job_id = #{jobId}
</update>
<update id="assignInboundCargoSpaceIfUnassigned" parameterType="MydoJob">
update mydo_job
set roadway_id = #{roadwayId},
cargo_space_id = #{cargoSpaceId},
cargo_space_name = #{cargoSpaceName},
height = #{height}
where job_id = #{jobId}
and tray_code = #{trayCode}
and warehouse_id = #{warehouseId}
and roadway_id = #{roadwayId}
and in_or_out &lt; 20
and status in ('1', '2', '3')
and (cargo_space_id is null or ltrim(rtrim(cargo_space_id)) = '')
</update>
<update id="reassignInboundCargoSpaceIfCurrent" parameterType="java.util.Map">
update mydo_job
set roadway_id = #{roadwayId},
cargo_space_id = #{cargoSpaceId},
cargo_space_name = #{cargoSpaceName}
where job_id = #{jobId}
and cargo_space_id = #{expectedCargoSpaceId}
and in_or_out &lt; 20
and status in ('1', '2', '3')
</update>
<delete id="deleteMydoJobByJobId" parameterType="String">
delete from mydo_job where job_id = #{jobId}
</delete>
@@ -379,6 +458,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectInventoryInMydoJobList" resultType="com.ruoyi.in.job.domain.MydoJob" resultMap="MydoJobResult">
<include refid="selectMydoJobVo"/>
where
in_or_out in (10, 11)
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="taskNo != null and taskNo != ''"> and task_no = #{taskNo}</if>
<if test="inOrOut != null "> and in_or_out = #{inOrOut}</if>
<if test="executionPhase != null and executionPhase != ''"> and execution_phase = #{executionPhase}</if>
<if test="trayCode != null and trayCode != ''"> and tray_code = #{trayCode}</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
<if test="roadwayId != null and roadwayId != ''"> and roadway_id = #{roadwayId}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id = #{cargoSpaceId}</if>
<if test="cargoSpaceName != null and cargoSpaceName != ''"> and cargo_space_name like concat('%', #{cargoSpaceName}, '%')</if>
<if test="lineType != null and lineType != ''"> and line_type = #{lineType}</if>
<if test="priority != null "> and priority = #{priority}</if>
<if test="height != null "> and height = #{height}</if>
<if test="weight != null "> and weight = #{weight}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="entranceId != null and entranceId != ''"> and entrance_id = #{entranceId}</if>
<if test="exitId != null and exitId != ''"> and exit_id = #{exitId}</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectInventoryInMydoJobFinishList" resultType="com.ruoyi.in.job.domain.MydoJob" resultMap="MydoJobResult">
<include refid="selectMydoJobFinishVo"/>
where
in_or_out in (10, 11)
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="taskNo != null and taskNo != ''"> and task_no = #{taskNo}</if>
<if test="inOrOut != null "> and in_or_out = #{inOrOut}</if>
<if test="executionPhase != null and executionPhase != ''"> and execution_phase = #{executionPhase}</if>
<if test="trayCode != null and trayCode != ''"> and tray_code = #{trayCode}</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
<if test="roadwayId != null and roadwayId != ''"> and roadway_id = #{roadwayId}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id = #{cargoSpaceId}</if>
<if test="cargoSpaceName != null and cargoSpaceName != ''"> and cargo_space_name like concat('%', #{cargoSpaceName}, '%')</if>
<if test="lineType != null and lineType != ''"> and line_type = #{lineType}</if>
<if test="priority != null "> and priority = #{priority}</if>
<if test="height != null "> and height = #{height}</if>
<if test="weight != null "> and weight = #{weight}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="entranceId != null and entranceId != ''"> and entrance_id = #{entranceId}</if>
<if test="exitId != null and exitId != ''"> and exit_id = #{exitId}</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectOutMydoJobFinishList" resultType="com.ruoyi.in.job.domain.MydoJob" resultMap="MydoJobResult">
<include refid="selectMydoJobFinishVo"/>
where
@@ -406,6 +539,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectInventoryOutMydoJobFinishList" resultType="com.ruoyi.in.job.domain.MydoJob" resultMap="MydoJobResult">
<include refid="selectMydoJobFinishVo"/>
where
in_or_out in (30, 31)
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="taskNo != null and taskNo != ''"> and task_no = #{taskNo}</if>
<if test="inOrOut != null "> and in_or_out = #{inOrOut}</if>
<if test="executionPhase != null and executionPhase != ''"> and execution_phase = #{executionPhase}</if>
<if test="trayCode != null and trayCode != ''"> and tray_code = #{trayCode}</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
<if test="roadwayId != null and roadwayId != ''"> and roadway_id = #{roadwayId}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id = #{cargoSpaceId}</if>
<if test="cargoSpaceName != null and cargoSpaceName != ''"> and cargo_space_name like concat('%', #{cargoSpaceName}, '%')</if>
<if test="lineType != null and lineType != ''"> and line_type = #{lineType}</if>
<if test="priority != null "> and priority = #{priority}</if>
<if test="height != null "> and height = #{height}</if>
<if test="weight != null "> and weight = #{weight}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="entranceId != null and entranceId != ''"> and entrance_id = #{entranceId}</if>
<if test="exitId != null and exitId != ''"> and exit_id = #{exitId}</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectOutMydoJobList" resultType="com.ruoyi.in.job.domain.MydoJob" resultMap="MydoJobResult">
<include refid="selectMydoJobVo"/>
@@ -434,6 +595,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectInventoryOutMydoJobList" resultType="com.ruoyi.in.job.domain.MydoJob" resultMap="MydoJobResult">
<include refid="selectMydoJobVo"/>
where
in_or_out in (30, 31)
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="taskNo != null and taskNo != ''"> and task_no = #{taskNo}</if>
<if test="inOrOut != null "> and in_or_out = #{inOrOut}</if>
<if test="executionPhase != null and executionPhase != ''"> and execution_phase = #{executionPhase}</if>
<if test="trayCode != null and trayCode != ''"> and tray_code = #{trayCode}</if>
<if test="warehouseId != null and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
<if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
<if test="roadwayId != null and roadwayId != ''"> and roadway_id = #{roadwayId}</if>
<if test="cargoSpaceId != null and cargoSpaceId != ''"> and cargo_space_id = #{cargoSpaceId}</if>
<if test="cargoSpaceName != null and cargoSpaceName != ''"> and cargo_space_name like concat('%', #{cargoSpaceName}, '%')</if>
<if test="lineType != null and lineType != ''"> and line_type = #{lineType}</if>
<if test="priority != null "> and priority = #{priority}</if>
<if test="height != null "> and height = #{height}</if>
<if test="weight != null "> and weight = #{weight}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="entranceId != null and entranceId != ''"> and entrance_id = #{entranceId}</if>
<if test="exitId != null and exitId != ''"> and exit_id = #{exitId}</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
${params.warehouseScope}
</select>
<select id="selectInMydoJobFinishListGroupByWarehouseId" resultType="com.ruoyi.kpi.domain.InAnalysisData">
SELECT

View File

@@ -14,6 +14,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)}
</insert>
<update id="rollbackPendingTrayBindings" parameterType="java.util.Map">
update d
set scan_num = case
when isnull(d.scan_num, 0) - pending.quantity &lt; 0 then 0
else isnull(d.scan_num, 0) - pending.quantity
end
from in_stockin_detail d
inner join (
select stockin_detail_id, sum(isnull(quantity, 0)) as quantity
from in_tray_msg
where tray_code = #{v_tray_code}
and warehouse_id = #{v_warehouse_id}
and stockin_detail_id is not null
and stockin_detail_id != ''
group by stockin_detail_id
) pending on pending.stockin_detail_id = d.stockin_detail_id
</update>
<delete id="deletePendingTrayBindings" parameterType="java.util.Map">
delete from in_tray_msg
where tray_code = #{v_tray_code}
and warehouse_id = #{v_warehouse_id}
</delete>
<select id="bindTray" parameterType="java.util.Map" statementType="CALLABLE">
{call proc_bind_tray_msg(
#{v_stockin_detail_id,mode=IN,jdbcType=VARCHAR},
@@ -47,36 +71,592 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by roadway_id asc, the_floor asc, the_platoon asc, the_column asc
</select>
<update id="lockInboundCargoSpace" parameterType="java.util.Map">
update bas_cargo_space
set status = '3',
tray_code = #{v_tray_code}
where cargo_space_id = (
select top 1 cargo_space_id
from (
select bcs.cargo_space_id,
bcs.the_platoon,
bcs.the_column,
bcs.the_floor,
count(1) over (partition by bcs.the_platoon) as platoon_empty_count
from bas_cargo_space bcs with (UPDLOCK, READPAST, ROWLOCK)
where bcs.warehouse_id = #{v_warehouse_id}
and bcs.the_type = #{v_cargo_type}
and (#{v_roadway_id} is null or #{v_roadway_id} = '' or bcs.roadway_id = #{v_roadway_id})
and bcs.status = '1'
and bcs.locked = 'N'
and (bcs.tray_code is null or bcs.tray_code = '')
) candidate
order by platoon_empty_count desc, the_platoon asc, the_floor asc, the_column asc, cargo_space_id asc
<select id="acquireInboundCargoSpaceAllocationLock" parameterType="java.util.Map" resultType="java.lang.Integer">
declare @lock_result int;
declare @lock_resource nvarchar(255);
declare @warehouse_id nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{v_warehouse_id})));
declare @tray_code nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{v_tray_code})));
set @lock_resource = N'wms:inbound-cargo-space:'
+ convert(varchar(64), hashbytes('SHA2_256', concat(
N'w=', convert(nvarchar(20), datalength(@warehouse_id)), N':', @warehouse_id,
N'|t=', convert(nvarchar(20), datalength(@tray_code)), N':', @tray_code
)), 2);
exec @lock_result = sys.sp_getapplock
@Resource = @lock_resource,
@LockMode = 'Exclusive',
@LockOwner = 'Transaction',
@LockTimeout = 10000,
@DbPrincipal = N'public';
select @lock_result;
</select>
<select id="acquireInboundRoadwayAllocationLock" parameterType="java.util.Map" resultType="java.lang.Integer">
declare @lock_result int;
declare @lock_resource nvarchar(255);
declare @warehouse_id nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{v_warehouse_id})));
declare @roadway_id nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{v_roadway_id})));
set @lock_resource = N'wms:inbound-roadway:'
+ convert(varchar(64), hashbytes('SHA2_256', concat(
N'w=', convert(nvarchar(20), datalength(@warehouse_id)), N':', @warehouse_id,
N'|r=', convert(nvarchar(20), datalength(@roadway_id)), N':', @roadway_id
)), 2);
exec @lock_result = sys.sp_getapplock
@Resource = @lock_resource,
@LockMode = 'Exclusive',
@LockOwner = 'Transaction',
@LockTimeout = 10000,
@DbPrincipal = N'public';
select @lock_result;
</select>
<select id="acquireInboundLayerPlanningLock" parameterType="java.util.Map" resultType="java.lang.Integer">
declare @lock_result int;
declare @lock_resource nvarchar(255);
declare @warehouse_id nvarchar(4000) =
upper(rtrim(convert(nvarchar(4000), #{v_warehouse_id})));
set @lock_resource = N'wms:inbound-layer-planning:'
+ convert(varchar(64), hashbytes('SHA2_256', concat(
N'w=', convert(nvarchar(20), datalength(@warehouse_id)), N':', @warehouse_id
)), 2);
exec @lock_result = sys.sp_getapplock
@Resource = @lock_resource,
@LockMode = 'Exclusive',
@LockOwner = 'Transaction',
@LockTimeout = 10000,
@DbPrincipal = N'public';
select @lock_result;
</select>
<select id="selectAvailableInboundLayerCandidate" parameterType="java.util.Map" resultType="java.util.HashMap">
;with lift_conflict_floors as (
select distinct outbound_space.the_floor as conflict_floor
from mydo_job inbound_job
inner join mydo_job outbound_job
on outbound_job.warehouse_id = inbound_job.warehouse_id
and outbound_job.exit_id = inbound_job.entrance_id
inner join bas_cargo_space outbound_space
on outbound_space.cargo_space_id = outbound_job.cargo_space_id
where inbound_job.job_id = #{v_job_id}
and outbound_job.in_or_out &gt;= 20
and outbound_job.status = '3'
and outbound_space.the_floor is not null
),
available_slots as (
select bcs.cargo_space_id,
bcs.group_coding,
bcs.the_platoon,
bcs.the_column,
bcs.the_floor,
coalesce(cac.direction_type, '1') as direction_type,
case when bcs.the_height = #{v_height} then 0 else 1 end as height_priority,
case
when upper(ltrim(rtrim(isnull(#{v_entrance_id}, '')))) in ('03-AU-01', '03-AU-03')
then case when bcs.this_cargo_area in ('G', 'H') then 0 else 1 end
when upper(ltrim(rtrim(isnull(#{v_entrance_id}, '')))) in ('03-AU-02', '03-AU-04')
then case when bcs.this_cargo_area in ('A', 'B') then 0 else 1 end
else 0
end as entrance_area_priority
from bas_cargo_space bcs
left join bas_cargo_area_config cac
on cac.warehouse_id = bcs.warehouse_id
and cac.cargo_area_code = bcs.this_cargo_area
and cac.is_active = '1'
where bcs.warehouse_id = #{v_warehouse_id}
and bcs.the_floor = try_convert(bigint, #{v_roadway_id})
and bcs.the_type = #{v_cargo_type}
and bcs.the_height &gt;= #{v_height}
and bcs.status = '1'
and isnull(bcs.locked, 'N') = 'N'
and (bcs.tray_code is null or ltrim(rtrim(bcs.tray_code)) = '')
and bcs.group_coding is not null
and ltrim(rtrim(bcs.group_coding)) != ''
and ((bcs.this_cargo_area in ('A', 'B') and bcs.the_column between 1 and 6)
or (bcs.this_cargo_area in ('C', 'D') and bcs.the_column between 8 and 12)
or (bcs.this_cargo_area in ('E', 'F') and bcs.the_column between 14 and 18)
or (bcs.this_cargo_area in ('G', 'H') and bcs.the_column between 20 and 22))
and not exists (
select 1
from lift_conflict_floors
where lift_conflict_floors.conflict_floor = bcs.the_floor
)
),
stock_profiles as (
select occupied.cargo_space_id,
occupied.group_coding,
case
when ltrim(rtrim(isnull(bsd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) != ''
and bs.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) != ''
and bs.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) = ''
and bs.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(coalesce(bsd.project_no, bs.project_no))), '') as project_no,
nullif(ltrim(rtrim(bsd.product_id)), '') as product_id,
nullif(ltrim(rtrim(bsd.product_name)), '') as product_name
from bas_stock bs
inner join bas_stock_detail bsd on bsd.stock_id = bs.stock_id
inner join bas_cargo_space occupied on occupied.cargo_space_id = bs.cargo_space_id
where bs.warehouse_id = #{v_warehouse_id}
and occupied.the_floor = try_convert(bigint, #{v_roadway_id})
and occupied.group_coding is not null
and isnull(bsd.quantity, 0) - isnull(bsd.out_quantity, 0) &gt; 0
),
assigned_job_profiles as (
select assigned.cargo_space_id,
assigned.group_coding,
case
when ltrim(rtrim(isnull(jd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) = '' and ins.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(jd.project_no)), '') as project_no,
nullif(ltrim(rtrim(jd.product_id)), '') as product_id,
nullif(ltrim(rtrim(jd.product_name)), '') as product_name
from mydo_job j
inner join mydo_job_detail jd on jd.job_id = j.job_id
left join in_stockin ins on ins.stockin_id = jd.stockin_id
inner join bas_cargo_space assigned on assigned.cargo_space_id = j.cargo_space_id
where j.warehouse_id = #{v_warehouse_id}
and assigned.the_floor = try_convert(bigint, #{v_roadway_id})
and j.in_or_out &lt; 20
and j.status in ('1', '2', '3')
and j.job_id != #{v_job_id}
and assigned.group_coding is not null
),
reserved_job_profiles as (
select reserved.cargo_space_id,
reserved.group_coding,
case
when ltrim(rtrim(isnull(jd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) = '' and ins.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(jd.project_no)), '') as project_no,
nullif(ltrim(rtrim(jd.product_id)), '') as product_id,
nullif(ltrim(rtrim(jd.product_name)), '') as product_name
from bas_cargo_space reserved
inner join mydo_job j
on j.warehouse_id = reserved.warehouse_id
and j.tray_code = reserved.tray_code
inner join mydo_job_detail jd on jd.job_id = j.job_id
left join in_stockin ins on ins.stockin_id = jd.stockin_id
where reserved.warehouse_id = #{v_warehouse_id}
and reserved.the_floor = try_convert(bigint, #{v_roadway_id})
and reserved.status = '3'
and reserved.tray_code is not null
and ltrim(rtrim(reserved.tray_code)) != ''
and reserved.group_coding is not null
and j.in_or_out &lt; 20
and j.status in ('1', '2', '3')
and j.job_id != #{v_job_id}
),
profiled_occupancy as (
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from stock_profiles
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from assigned_job_profiles
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from reserved_job_profiles
),
occupied_spaces as (
select bcs.cargo_space_id, bcs.group_coding
from bas_cargo_space bcs
where bcs.warehouse_id = #{v_warehouse_id}
and bcs.the_floor = try_convert(bigint, #{v_roadway_id})
and bcs.group_coding is not null
and bcs.status not in ('1', '7', '8', '9', '10')
),
unknown_occupancy as (
select occupied.cargo_space_id,
occupied.group_coding,
'UNKNOWN' as storage_mode,
cast(null as nvarchar(80)) as project_no,
cast(null as nvarchar(80)) as product_id,
cast(null as nvarchar(200)) as product_name
from occupied_spaces occupied
where not exists (
select 1 from profiled_occupancy profiled
where profiled.cargo_space_id = occupied.cargo_space_id
)
),
all_occupancy as (
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from profiled_occupancy
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name from unknown_occupancy
),
eligible_lanes as (
select lane.group_coding,
case when count(distinct occupancy.cargo_space_id) &gt; 0 then 1 else 0 end as has_occupancy,
count(distinct occupancy.cargo_space_id) as occupied_space_count
from (select distinct group_coding from available_slots) lane
left join all_occupancy occupancy on occupancy.group_coding = lane.group_coding
group by lane.group_coding
having sum(case
when occupancy.cargo_space_id is null then 0
when #{v_storage_mode} = 'EMPTY_TRAY' and occupancy.storage_mode = 'EMPTY_TRAY'
and occupancy.product_id = 'KTP0001' then 0
when #{v_storage_mode} = 'RAW_PRODUCT' and occupancy.storage_mode = 'RAW_PRODUCT'
and occupancy.project_no is null
and occupancy.product_id = #{v_product_id}
and occupancy.product_name = #{v_product_name} then 0
when #{v_storage_mode} in ('RAW_PROJECT', 'SEMI_PROJECT')
and occupancy.storage_mode in ('RAW_PROJECT', 'SEMI_PROJECT')
and occupancy.project_no = #{v_project_no} then 0
else 1
end) = 0
),
lane_candidates as (
select slots.*, lanes.has_occupancy, lanes.occupied_space_count,
abs(convert(bigint, checksum(slots.group_coding, #{v_tray_code}))) as lane_random_key
from available_slots slots
inner join eligible_lanes lanes on lanes.group_coding = slots.group_coding
),
pending_layer_reservations as (
select count(*) as pending_count
from mydo_job pending
where pending.warehouse_id = #{v_warehouse_id}
and pending.in_or_out &lt; 20
and pending.status in ('1', '2', '3')
and pending.job_id != #{v_job_id}
and pending.roadway_id = convert(nvarchar(80), #{v_roadway_id})
and (pending.cargo_space_id is null or ltrim(rtrim(pending.cargo_space_id)) = '')
),
candidate_capacity as (
select count(*) as candidate_count from lane_candidates
)
select top 1 the_floor as selected_layer, cargo_space_id,
candidate_count, pending_count
from lane_candidates
cross join pending_layer_reservations
cross join candidate_capacity
where candidate_count &gt; pending_count
order by height_priority asc,
entrance_area_priority asc,
case when #{v_storage_mode} = 'EMPTY_TRAY' then lane_random_key end asc,
case when #{v_storage_mode} != 'EMPTY_TRAY' then has_occupancy end desc,
case when #{v_storage_mode} != 'EMPTY_TRAY' then occupied_space_count end desc,
group_coding asc, the_platoon asc, the_floor asc,
case when direction_type = '1' then the_column end asc,
case when direction_type = '2' then the_column end desc,
the_column asc, cargo_space_id asc
</select>
<update id="assignInboundLayerIfUnassigned" parameterType="java.util.Map">
update mydo_job
set roadway_id = #{v_roadway_id}
where job_id = #{v_job_id}
and tray_code = #{v_tray_code}
and warehouse_id = #{v_warehouse_id}
and in_or_out &lt; 20
and status in ('1', '2', '3')
and (roadway_id is null or ltrim(rtrim(roadway_id)) = '')
and (cargo_space_id is null or ltrim(rtrim(cargo_space_id)) = '')
</update>
<update id="lockInboundCargoSpace" parameterType="java.util.Map">
<choose>
<when test="v_warehouse_id == '03'">
;with lift_conflict_floors as (
select distinct outbound_space.the_floor as conflict_floor
from mydo_job inbound_job
inner join mydo_job outbound_job
on outbound_job.warehouse_id = inbound_job.warehouse_id
and outbound_job.exit_id = inbound_job.entrance_id
inner join bas_cargo_space outbound_space
on outbound_space.cargo_space_id = outbound_job.cargo_space_id
where inbound_job.job_id = #{v_job_id}
and outbound_job.in_or_out &gt;= 20
and outbound_job.status = '3'
and outbound_space.the_floor is not null
),
available_slots as (
select bcs.cargo_space_id,
bcs.group_coding,
bcs.the_platoon,
bcs.the_column,
bcs.the_floor,
coalesce(cac.direction_type, '1') as direction_type,
case when bcs.the_height = #{v_height} then 0 else 1 end as height_priority,
case
when upper(ltrim(rtrim(isnull(#{v_entrance_id}, '')))) in ('03-AU-01', '03-AU-03')
then case when bcs.this_cargo_area in ('G', 'H') then 0 else 1 end
when upper(ltrim(rtrim(isnull(#{v_entrance_id}, '')))) in ('03-AU-02', '03-AU-04')
then case when bcs.this_cargo_area in ('A', 'B') then 0 else 1 end
else 0
end as entrance_area_priority
from bas_cargo_space bcs with (UPDLOCK, READPAST, ROWLOCK)
left join bas_cargo_area_config cac
on cac.warehouse_id = bcs.warehouse_id
and cac.cargo_area_code = bcs.this_cargo_area
and cac.is_active = '1'
where bcs.warehouse_id = #{v_warehouse_id}
and bcs.the_floor = try_convert(bigint, #{v_roadway_id})
and bcs.the_type = #{v_cargo_type}
and bcs.the_height &gt;= #{v_height}
and bcs.status = '1'
and isnull(bcs.locked, 'N') = 'N'
and (bcs.tray_code is null or ltrim(rtrim(bcs.tray_code)) = '')
and bcs.group_coding is not null
and ltrim(rtrim(bcs.group_coding)) != ''
and ((bcs.this_cargo_area in ('A', 'B') and bcs.the_column between 1 and 6)
or (bcs.this_cargo_area in ('C', 'D') and bcs.the_column between 8 and 12)
or (bcs.this_cargo_area in ('E', 'F') and bcs.the_column between 14 and 18)
or (bcs.this_cargo_area in ('G', 'H') and bcs.the_column between 20 and 22))
and not exists (
select 1
from lift_conflict_floors
where lift_conflict_floors.conflict_floor = bcs.the_floor
)
),
stock_profiles as (
select occupied.cargo_space_id,
occupied.group_coding,
case
when ltrim(rtrim(isnull(bsd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) != ''
and bs.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) != ''
and bs.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(coalesce(bsd.project_no, bs.project_no), ''))) = ''
and bs.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(coalesce(bsd.project_no, bs.project_no))), '') as project_no,
nullif(ltrim(rtrim(bsd.product_id)), '') as product_id,
nullif(ltrim(rtrim(bsd.product_name)), '') as product_name
from bas_stock bs
inner join bas_stock_detail bsd on bsd.stock_id = bs.stock_id
inner join bas_cargo_space occupied on occupied.cargo_space_id = bs.cargo_space_id
where bs.warehouse_id = #{v_warehouse_id}
and occupied.the_floor = try_convert(bigint, #{v_roadway_id})
and occupied.group_coding is not null
and isnull(bsd.quantity, 0) - isnull(bsd.out_quantity, 0) &gt; 0
),
assigned_job_profiles as (
select assigned.cargo_space_id,
assigned.group_coding,
case
when ltrim(rtrim(isnull(jd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) = '' and ins.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(jd.project_no)), '') as project_no,
nullif(ltrim(rtrim(jd.product_id)), '') as product_id,
nullif(ltrim(rtrim(jd.product_name)), '') as product_name
from mydo_job j
inner join mydo_job_detail jd on jd.job_id = j.job_id
left join in_stockin ins on ins.stockin_id = jd.stockin_id
inner join bas_cargo_space assigned on assigned.cargo_space_id = j.cargo_space_id
where j.warehouse_id = #{v_warehouse_id}
and assigned.the_floor = try_convert(bigint, #{v_roadway_id})
and j.in_or_out &lt; 20
and j.status in ('1', '2', '3')
and j.job_id != #{v_job_id}
and assigned.group_coding is not null
),
reserved_job_profiles as (
select reserved.cargo_space_id,
reserved.group_coding,
case
when ltrim(rtrim(isnull(jd.product_id, ''))) = 'KTP0001' then 'EMPTY_TRAY'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '1' then 'RAW_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) != '' and ins.in_type = '2' then 'SEMI_PROJECT'
when ltrim(rtrim(isnull(jd.project_no, ''))) = '' and ins.in_type = '1' then 'RAW_PRODUCT'
else 'UNKNOWN'
end as storage_mode,
nullif(ltrim(rtrim(jd.project_no)), '') as project_no,
nullif(ltrim(rtrim(jd.product_id)), '') as product_id,
nullif(ltrim(rtrim(jd.product_name)), '') as product_name
from bas_cargo_space reserved
inner join mydo_job j
on j.warehouse_id = reserved.warehouse_id
and j.tray_code = reserved.tray_code
inner join mydo_job_detail jd on jd.job_id = j.job_id
left join in_stockin ins on ins.stockin_id = jd.stockin_id
where reserved.warehouse_id = #{v_warehouse_id}
and reserved.the_floor = try_convert(bigint, #{v_roadway_id})
and reserved.status = '3'
and reserved.tray_code is not null
and ltrim(rtrim(reserved.tray_code)) != ''
and reserved.group_coding is not null
and j.in_or_out &lt; 20
and j.status in ('1', '2', '3')
and j.job_id != #{v_job_id}
),
profiled_occupancy as (
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name
from stock_profiles
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name
from assigned_job_profiles
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name
from reserved_job_profiles
),
occupied_spaces as (
select bcs.cargo_space_id, bcs.group_coding
from bas_cargo_space bcs
where bcs.warehouse_id = #{v_warehouse_id}
and bcs.the_floor = try_convert(bigint, #{v_roadway_id})
and bcs.group_coding is not null
and bcs.status not in ('1', '7', '8', '9', '10')
),
unknown_occupancy as (
select occupied.cargo_space_id,
occupied.group_coding,
'UNKNOWN' as storage_mode,
cast(null as nvarchar(80)) as project_no,
cast(null as nvarchar(80)) as product_id,
cast(null as nvarchar(200)) as product_name
from occupied_spaces occupied
where not exists (
select 1
from profiled_occupancy profiled
where profiled.cargo_space_id = occupied.cargo_space_id
)
),
all_occupancy as (
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name
from profiled_occupancy
union all
select cargo_space_id, group_coding, storage_mode, project_no, product_id, product_name
from unknown_occupancy
),
eligible_lanes as (
select lane.group_coding,
case when count(distinct occupancy.cargo_space_id) &gt; 0 then 1 else 0 end as has_occupancy,
count(distinct occupancy.cargo_space_id) as occupied_space_count
from (select distinct group_coding from available_slots) lane
left join all_occupancy occupancy on occupancy.group_coding = lane.group_coding
group by lane.group_coding
having sum(case
when occupancy.cargo_space_id is null then 0
when #{v_storage_mode} = 'EMPTY_TRAY'
and occupancy.storage_mode = 'EMPTY_TRAY'
and occupancy.product_id = 'KTP0001' then 0
when #{v_storage_mode} = 'RAW_PRODUCT'
and occupancy.storage_mode = 'RAW_PRODUCT'
and occupancy.project_no is null
and occupancy.product_id = #{v_product_id}
and occupancy.product_name = #{v_product_name} then 0
when #{v_storage_mode} in ('RAW_PROJECT', 'SEMI_PROJECT')
and occupancy.storage_mode in ('RAW_PROJECT', 'SEMI_PROJECT')
and occupancy.project_no = #{v_project_no} then 0
else 1
end) = 0
),
lane_candidates as (
select slots.*,
lanes.has_occupancy,
lanes.occupied_space_count,
abs(convert(bigint, checksum(slots.group_coding, #{v_tray_code}))) as lane_random_key
from available_slots slots
inner join eligible_lanes lanes on lanes.group_coding = slots.group_coding
),
pending_layer_reservations as (
select count(*) as pending_count
from mydo_job pending
where pending.warehouse_id = #{v_warehouse_id}
and pending.in_or_out &lt; 20
and pending.status in ('1', '2', '3')
and pending.job_id != #{v_job_id}
and pending.roadway_id = convert(nvarchar(80), #{v_roadway_id})
and (pending.cargo_space_id is null or ltrim(rtrim(pending.cargo_space_id)) = '')
),
candidate_capacity as (
select count(*) as candidate_count from lane_candidates
)
update target with (ROWLOCK)
set target.status = '3',
target.tray_code = #{v_tray_code}
from bas_cargo_space target
inner join (
select top 1 cargo_space_id
from lane_candidates
cross join pending_layer_reservations
cross join candidate_capacity
where candidate_count &gt; pending_count
order by height_priority asc,
entrance_area_priority asc,
case when #{v_storage_mode} = 'EMPTY_TRAY' then lane_random_key end asc,
case when #{v_storage_mode} != 'EMPTY_TRAY' then has_occupancy end desc,
case when #{v_storage_mode} != 'EMPTY_TRAY' then occupied_space_count end desc,
group_coding asc,
the_platoon asc,
the_floor asc,
case when direction_type = '1' then the_column end asc,
case when direction_type = '2' then the_column end desc,
the_column asc,
cargo_space_id asc
) selected on selected.cargo_space_id = target.cargo_space_id
where target.status = '1'
and isnull(target.locked, 'N') = 'N'
and (target.tray_code is null or ltrim(rtrim(target.tray_code)) = '')
</when>
<otherwise>
update bas_cargo_space
set status = '3',
tray_code = #{v_tray_code}
where cargo_space_id = (
select top 1 cargo_space_id
from (
select bcs.cargo_space_id,
bcs.the_platoon,
bcs.the_column,
bcs.the_floor,
coalesce(cac.direction_type, '1') as direction_type,
min(bcs.the_column) over (partition by bcs.warehouse_id, bcs.this_cargo_area) as area_min_column,
max(bcs.the_column) over (partition by bcs.warehouse_id, bcs.this_cargo_area) as area_max_column,
case when bcs.the_height = #{v_height} then 0 else 1 end as height_priority,
count(1) over (partition by bcs.the_platoon) as platoon_empty_count
from bas_cargo_space bcs with (UPDLOCK, READPAST, ROWLOCK)
left join bas_cargo_area_config cac
on cac.warehouse_id = bcs.warehouse_id
and cac.cargo_area_code = bcs.this_cargo_area
and cac.is_active = '1'
where bcs.warehouse_id = #{v_warehouse_id}
and bcs.the_type = #{v_cargo_type}
and (#{v_roadway_id} is null or #{v_roadway_id} = '' or bcs.roadway_id = #{v_roadway_id})
and bcs.the_height &gt;= #{v_height}
and bcs.status = '1'
and bcs.locked = 'N'
and (bcs.tray_code is null or bcs.tray_code = '')
) candidate
order by height_priority asc, platoon_empty_count desc,
the_platoon asc, the_floor asc,
case when direction_type = '1' then the_column end asc,
case when direction_type = '2' then the_column end desc,
case when direction_type = '3' then
case
when the_column - area_min_column &lt;= area_max_column - the_column
then the_column - area_min_column
else area_max_column - the_column
end
end asc,
case when direction_type = '3' then the_column end asc,
cargo_space_id asc
)
</otherwise>
</choose>
</update>
<select id="selectLockedCargoSpaceByTrayCode" parameterType="java.util.Map" resultType="java.util.HashMap">
select top 1 cargo_space_id, cargo_space_name, roadway_id
select top 1 cargo_space_id, cargo_space_name, roadway_id, the_floor, the_height
from bas_cargo_space
where warehouse_id = #{v_warehouse_id}
and tray_code = #{v_tray_code}
and (#{v_roadway_id} is null or #{v_roadway_id} = '' or roadway_id = #{v_roadway_id})
and status = '3'
order by the_floor asc, the_platoon asc, the_column asc
</select>
@@ -87,6 +667,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
tray_code = null
where warehouse_id = #{v_warehouse_id}
and tray_code = #{v_tray_code}
and cargo_space_id = #{v_cargo_space_id}
and status = '3'
</update>
@@ -219,6 +800,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
jd.product_id as materialCode,
jd.product_name as materialName,
jd.lot_no as lotNo,
jd.project_no as projectNo,
jd.stock_quantity as stockQuantity,
jd.out_quantity as quantity,
isnull(jd.stock_quantity, 0) - isnull(jd.out_quantity, 0) as residualQuantity
@@ -235,9 +817,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
jd.product_id as materialCode,
jd.product_name as materialName,
jd.lot_no as lotNo,
jd.project_no as projectNo,
bs.stockin_id as stockinId,
bs.in_type as inType,
jd.stock_quantity as stockQuantity,
jd.out_quantity as quantity
from mydo_job_detail jd
left join bas_stock bs on bs.stock_id = jd.stock_id
where jd.job_id = #{jobId}
order by jd.job_detail_id
</select>
@@ -274,6 +860,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bsd.product_name as productName,
bsd.product_name as materialName,
bsd.lot_no as lotNo,
bsd.project_no as projectNo,
isnull(bsd.quantity, 0) as quantity,
bs.tray_code as trayCode,
bs.warehouse_id as warehouseId,
@@ -300,6 +887,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bsd.product_name as productName,
bsd.product_name as materialName,
bsd.lot_no as lotNo,
bsd.project_no as projectNo,
isnull(bsd.quantity, 0) as quantity,
isnull(bsd.out_quantity, 0) as outQuantity,
isnull(bsd.quantity, 0) - isnull(bsd.out_quantity, 0) as availableQuantity,
@@ -370,6 +958,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bsd.lot_no as lotNo,
bsd.product_id as productId,
bsd.product_name as productName,
bsd.project_no as projectNo,
isnull(bsd.quantity, 0) - isnull(bsd.out_quantity, 0) as availableQuantity,
bs.tray_code as trayCode,
bs.warehouse_id as warehouseId,