fix(mill): 优化换辊记录查询逻辑
- 修改selectCurrentStateByStand方法实现各辊位独立获取最新非空记录 - 更新selectLatestByStandAndPosition方法支持按辊位类型条件查询 - 添加删除标记过滤确保只查询有效数据 - 优化SQL查询结构提升部分换辊场景的数据准确性 - 调整查询条件顺序增强查询性能 - 修正注释描述以准确反映新的查询逻辑
This commit is contained in:
@@ -148,33 +148,34 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 查询指定机架当前各辊位状态(最近一次换辊记录) -->
|
<!-- 组合查询各辊位当前实际在机状态(每个位置独立取最新非空记录) -->
|
||||||
<select id="selectCurrentStateByStand" resultType="map">
|
<select id="selectCurrentStateByStand" resultType="map">
|
||||||
SELECT change_time AS changeTime,
|
SELECT
|
||||||
upper_wr_no AS upperWrNo,
|
(SELECT upper_wr_no FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND upper_wr_no IS NOT NULL AND upper_wr_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS upperWrNo,
|
||||||
upper_wr_dia AS upperWrDia,
|
(SELECT upper_wr_dia FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND upper_wr_no IS NOT NULL AND upper_wr_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS upperWrDia,
|
||||||
lower_wr_no AS lowerWrNo,
|
(SELECT lower_wr_no FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND lower_wr_no IS NOT NULL AND lower_wr_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS lowerWrNo,
|
||||||
lower_wr_dia AS lowerWrDia,
|
(SELECT lower_wr_dia FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND lower_wr_no IS NOT NULL AND lower_wr_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS lowerWrDia,
|
||||||
upper_br_no AS upperBrNo,
|
(SELECT upper_br_no FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND upper_br_no IS NOT NULL AND upper_br_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS upperBrNo,
|
||||||
upper_br_dia AS upperBrDia,
|
(SELECT upper_br_dia FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND upper_br_no IS NOT NULL AND upper_br_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS upperBrDia,
|
||||||
lower_br_no AS lowerBrNo,
|
(SELECT lower_br_no FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND lower_br_no IS NOT NULL AND lower_br_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS lowerBrNo,
|
||||||
lower_br_dia AS lowerBrDia
|
(SELECT lower_br_dia FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if> AND lower_br_no IS NOT NULL AND lower_br_no != '' ORDER BY change_time DESC, change_id DESC LIMIT 1) AS lowerBrDia,
|
||||||
FROM mes_roll_change
|
(SELECT MAX(change_time) FROM mes_roll_change WHERE stand_no = #{standNo} AND del_flag = 0 <if test="lineId != null">AND line_id = #{lineId}</if>) AS changeTime
|
||||||
WHERE line_id = #{lineId} AND stand_no = #{standNo}
|
|
||||||
ORDER BY change_id DESC
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 查询指定机架+辊位的最新换辊记录 -->
|
<!-- 按辊位查最新非空换辊记录(支持部分换辊) -->
|
||||||
<select id="selectLatestByStandAndPosition" resultMap="MesRollChangeResult">
|
<select id="selectLatestByStandAndPosition" resultMap="MesRollChangeResult">
|
||||||
<include refid="selectMesRollChangeVo"/>
|
SELECT change_id, line_id, change_no, change_time, stand_no, operator,
|
||||||
WHERE line_id = #{lineId} AND stand_no = #{standNo} AND del_flag = 0
|
upper_wr_no, upper_wr_dia, lower_wr_no, lower_wr_dia,
|
||||||
AND (
|
upper_br_no, upper_br_dia, lower_br_no, lower_br_dia
|
||||||
(#{posType} = 'upperWr' AND upper_wr_no IS NOT NULL)
|
FROM mes_roll_change
|
||||||
OR (#{posType} = 'lowerWr' AND lower_wr_no IS NOT NULL)
|
WHERE del_flag = 0 AND stand_no = #{standNo}
|
||||||
OR (#{posType} = 'upperBr' AND upper_br_no IS NOT NULL)
|
<if test="lineId != null">AND line_id = #{lineId}</if>
|
||||||
OR (#{posType} = 'lowerBr' AND lower_br_no IS NOT NULL)
|
<choose>
|
||||||
)
|
<when test="posType == 'upperWr'">AND upper_wr_no IS NOT NULL AND upper_wr_no != ''</when>
|
||||||
|
<when test="posType == 'lowerWr'">AND lower_wr_no IS NOT NULL AND lower_wr_no != ''</when>
|
||||||
|
<when test="posType == 'upperBr'">AND upper_br_no IS NOT NULL AND upper_br_no != ''</when>
|
||||||
|
<when test="posType == 'lowerBr'">AND lower_br_no IS NOT NULL AND lower_br_no != ''</when>
|
||||||
|
</choose>
|
||||||
ORDER BY change_time DESC, change_id DESC
|
ORDER BY change_time DESC, change_id DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user