Compare commits

..

2 Commits

Author SHA1 Message Date
21a1d339d5 Merge remote-tracking branch 'origin/master' 2026-06-09 17:28:39 +08:00
c47da2f443 fix(mill): 优化换辊记录查询逻辑
- 修改selectCurrentStateByStand方法实现各辊位独立获取最新非空记录
- 更新selectLatestByStandAndPosition方法支持按辊位类型条件查询
- 添加删除标记过滤确保只查询有效数据
- 优化SQL查询结构提升部分换辊场景的数据准确性
- 调整查询条件顺序增强查询性能
- 修正注释描述以准确反映新的查询逻辑
2026-06-09 17:28:29 +08:00

View File

@@ -148,33 +148,34 @@
</foreach>
</delete>
<!-- 查询指定机架当前各辊位状态(最近一次换辊记录) -->
<!-- 组合查询各辊位当前实际在机状态(每个位置独立取最新非空记录) -->
<select id="selectCurrentStateByStand" resultType="map">
SELECT change_time AS changeTime,
upper_wr_no AS upperWrNo,
upper_wr_dia AS upperWrDia,
lower_wr_no AS lowerWrNo,
lower_wr_dia AS lowerWrDia,
upper_br_no AS upperBrNo,
upper_br_dia AS upperBrDia,
lower_br_no AS lowerBrNo,
lower_br_dia AS lowerBrDia
FROM mes_roll_change
WHERE line_id = #{lineId} AND stand_no = #{standNo}
ORDER BY change_id DESC
LIMIT 1
SELECT
(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,
(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,
(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,
(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,
(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,
(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,
(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,
(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,
(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
</select>
<!-- 查询指定机架+辊位最新换辊记录 -->
<!-- 辊位最新非空换辊记录(支持部分换辊) -->
<select id="selectLatestByStandAndPosition" resultMap="MesRollChangeResult">
<include refid="selectMesRollChangeVo"/>
WHERE line_id = #{lineId} AND stand_no = #{standNo} AND del_flag = 0
AND (
(#{posType} = 'upperWr' AND upper_wr_no IS NOT NULL)
OR (#{posType} = 'lowerWr' AND lower_wr_no IS NOT NULL)
OR (#{posType} = 'upperBr' AND upper_br_no IS NOT NULL)
OR (#{posType} = 'lowerBr' AND lower_br_no IS NOT NULL)
)
SELECT change_id, line_id, change_no, change_time, stand_no, operator,
upper_wr_no, upper_wr_dia, lower_wr_no, lower_wr_dia,
upper_br_no, upper_br_dia, lower_br_no, lower_br_dia
FROM mes_roll_change
WHERE del_flag = 0 AND stand_no = #{standNo}
<if test="lineId != null">AND line_id = #{lineId}</if>
<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
LIMIT 1
</select>