feat: add WCS dispatch outbox
This commit is contained in:
@@ -36,12 +36,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="supplierName" column="supplier_name" />
|
||||
<result property="customerId" column="customer_id" />
|
||||
<result property="customerName" column="customer_name" />
|
||||
<result property="dispatchStatus" column="dispatch_status" />
|
||||
<result property="autoRetryCount" column="auto_retry_count" />
|
||||
<result property="manualRetryCount" column="manual_retry_count" />
|
||||
<result property="lastDispatchError" column="last_dispatch_error" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectMydoJobVo">
|
||||
select job_id, status, task_no, in_or_out, execution_phase, tray_code, warehouse_id,
|
||||
select mydo_job.job_id, status, task_no, in_or_out, execution_phase, tray_code, warehouse_id,
|
||||
isnull(nullif(warehouse_name, ''), (select top 1 bw.warehouse_name from bas_warehouse bw where bw.warehouse_id = mydo_job.warehouse_id)) as warehouse_name,
|
||||
roadway_id, cargo_space_id, cargo_space_name, target_roadway_id, target_cargo_space_id, target_cargo_space_name, line_type, priority, height, weight, create_time, start_time, finish_time, entrance_id, exit_id, dept_id, dept_name, user_id, user_name, supplier_id, supplier_name, customer_id, customer_name from mydo_job
|
||||
roadway_id, cargo_space_id, cargo_space_name, target_roadway_id, target_cargo_space_id, target_cargo_space_name, line_type, priority, height, weight, mydo_job.create_time, start_time, finish_time, entrance_id, exit_id, dept_id, dept_name, user_id, user_name, supplier_id, supplier_name, customer_id, customer_name,
|
||||
wjd.dispatch_status as dispatch_status, wjd.auto_retry_count as auto_retry_count,
|
||||
wjd.manual_retry_count as manual_retry_count, wjd.last_error as last_dispatch_error
|
||||
from mydo_job
|
||||
left join wcs_job_dispatch wjd on wjd.job_id = mydo_job.job_id
|
||||
</sql>
|
||||
<sql id="selectMydoJobFinishVo">
|
||||
select job_id, status, task_no, in_or_out, execution_phase, tray_code, warehouse_id,
|
||||
@@ -79,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectMydoJobByJobId" parameterType="String" resultMap="MydoJobResult">
|
||||
<include refid="selectMydoJobVo"/>
|
||||
where job_id = #{jobId}
|
||||
where mydo_job.job_id = #{jobId}
|
||||
</select>
|
||||
|
||||
<select id="acquirePutOccupiedJobLock" parameterType="java.util.Map" resultType="java.lang.Integer">
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
<?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.out.dispatch.mapper.WcsJobDispatchMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.out.dispatch.domain.WcsJobDispatch" id="WcsJobDispatchResult">
|
||||
<id property="jobId" column="job_id" />
|
||||
<result property="dispatchStatus" column="dispatch_status" />
|
||||
<result property="autoRetryCount" column="auto_retry_count" />
|
||||
<result property="manualRetryCount" column="manual_retry_count" />
|
||||
<result property="lastError" column="last_error" />
|
||||
<result property="lastAttemptTime" column="last_attempt_time" />
|
||||
<result property="nextRetryTime" column="next_retry_time" />
|
||||
<result property="successTime" column="success_time" />
|
||||
<result property="versionNo" column="version_no" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<insert id="insertIfAbsent" parameterType="String">
|
||||
if not exists (select 1 from wcs_job_dispatch with (updlock, holdlock) where job_id = #{jobId})
|
||||
begin
|
||||
insert into wcs_job_dispatch
|
||||
(job_id, dispatch_status, auto_retry_count, manual_retry_count, version_no, create_time, update_time)
|
||||
values
|
||||
(#{jobId}, 'PENDING', 0, 0, 0, getdate(), getdate())
|
||||
end
|
||||
</insert>
|
||||
|
||||
<select id="selectByJobId" parameterType="String" resultMap="WcsJobDispatchResult">
|
||||
select job_id, dispatch_status, auto_retry_count, manual_retry_count, last_error,
|
||||
last_attempt_time, next_retry_time, success_time, version_no, create_time, update_time
|
||||
from wcs_job_dispatch
|
||||
where job_id = #{jobId}
|
||||
</select>
|
||||
|
||||
<select id="selectRetryCandidates" resultMap="WcsJobDispatchResult">
|
||||
select top (#{limit}) job_id, dispatch_status, auto_retry_count, manual_retry_count, last_error,
|
||||
last_attempt_time, next_retry_time, success_time, version_no, create_time, update_time
|
||||
from wcs_job_dispatch with (readpast)
|
||||
where (dispatch_status = 'RETRY_WAIT'
|
||||
and auto_retry_count < 5
|
||||
and (next_retry_time is null or next_retry_time <= #{now}))
|
||||
or dispatch_status = 'BLOCKED'
|
||||
or (dispatch_status = 'SENDING'
|
||||
and last_attempt_time <= dateadd(minute, -5, #{now}))
|
||||
order by create_time, job_id
|
||||
</select>
|
||||
|
||||
<update id="claimForSend" parameterType="map">
|
||||
update wcs_job_dispatch
|
||||
set dispatch_status = 'SENDING',
|
||||
auto_retry_count = auto_retry_count + case when #{trigger} = 'AUTO_RETRY' then 1 else 0 end,
|
||||
manual_retry_count = manual_retry_count + case when #{trigger} = 'MANUAL' then 1 else 0 end,
|
||||
last_attempt_time = #{attemptTime},
|
||||
next_retry_time = null,
|
||||
update_time = #{attemptTime},
|
||||
version_no = version_no + 1
|
||||
where job_id = #{jobId}
|
||||
and version_no = #{versionNo}
|
||||
and dispatch_status in ('PENDING', 'BLOCKED', 'RETRY_WAIT', 'EXHAUSTED', 'SENDING')
|
||||
and (#{trigger} != 'AUTO_RETRY' or auto_retry_count < 5)
|
||||
</update>
|
||||
|
||||
<update id="markBlocked" parameterType="map">
|
||||
update wcs_job_dispatch
|
||||
set dispatch_status = 'BLOCKED', last_error = #{lastError}, next_retry_time = #{nextRetryTime},
|
||||
update_time = #{updateTime}, version_no = version_no + 1
|
||||
where job_id = #{jobId} and dispatch_status != 'SUCCESS'
|
||||
</update>
|
||||
|
||||
<update id="markRetryWait" parameterType="map">
|
||||
update wcs_job_dispatch
|
||||
set dispatch_status = 'RETRY_WAIT', last_error = #{lastError}, next_retry_time = #{nextRetryTime},
|
||||
update_time = #{updateTime}, version_no = version_no + 1
|
||||
where job_id = #{jobId} and dispatch_status = 'SENDING'
|
||||
</update>
|
||||
|
||||
<update id="markSuccess" parameterType="map">
|
||||
update wcs_job_dispatch
|
||||
set dispatch_status = 'SUCCESS', last_error = null, next_retry_time = null,
|
||||
success_time = #{successTime}, update_time = #{successTime}, version_no = version_no + 1
|
||||
where job_id = #{jobId} and dispatch_status = 'SENDING'
|
||||
</update>
|
||||
|
||||
<update id="markExhausted" parameterType="map">
|
||||
update wcs_job_dispatch
|
||||
set dispatch_status = 'EXHAUSTED', last_error = #{lastError}, next_retry_time = null,
|
||||
update_time = #{updateTime}, version_no = version_no + 1
|
||||
where job_id = #{jobId} and dispatch_status = 'SENDING'
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user