fix(ems): 修复 dailyfaultrecord 插入和更新时的处理时长计算问题

- 移除了插入语句中的 handling_duration 字段的空值判断
- 在插入和更新语句中增加了对故障发生时间和处理完成时间的判断
- 使用 CASE 语句计算处理时长,考虑了跨天的情况
- 保留了原有的 handlingDuration 字段值作为备用
boardTest
zch 3 weeks ago
parent 034b5cc981
commit 1424a07027

@ -55,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="faultType != null">fault_type,</if>
<if test="faultOccurrenceTime != null">fault_occurrence_time,</if>
<if test="handlingCompletionTime != null">handling_completion_time,</if>
<if test="handlingDuration != null">handling_duration,</if>
handling_duration,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="date != null">#{date},</if>
@ -67,7 +67,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="faultType != null">#{faultType},</if>
<if test="faultOccurrenceTime != null">#{faultOccurrenceTime},</if>
<if test="handlingCompletionTime != null">#{handlingCompletionTime},</if>
<if test="handlingDuration != null">#{handlingDuration},</if>
<choose>
<when test="faultOccurrenceTime != null and handlingCompletionTime != null and faultOccurrenceTime != '' and handlingCompletionTime != ''">
CASE
WHEN TIME_TO_SEC(#{handlingCompletionTime}) >= TIME_TO_SEC(#{faultOccurrenceTime}) THEN
TIME_TO_SEC(#{handlingCompletionTime}) - TIME_TO_SEC(#{faultOccurrenceTime})
ELSE
TIME_TO_SEC(#{handlingCompletionTime}) + 86400 - TIME_TO_SEC(#{faultOccurrenceTime})
END,
</when>
<otherwise>
#{handlingDuration},
</otherwise>
</choose>
</trim>
</insert>
@ -83,7 +95,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="faultType != null">fault_type = #{faultType},</if>
<if test="faultOccurrenceTime != null">fault_occurrence_time = #{faultOccurrenceTime},</if>
<if test="handlingCompletionTime != null">handling_completion_time = #{handlingCompletionTime},</if>
<if test="handlingDuration != null">handling_duration = #{handlingDuration},</if>
handling_duration =
<choose>
<when test="faultOccurrenceTime != null and handlingCompletionTime != null and faultOccurrenceTime != '' and handlingCompletionTime != ''">
CASE
WHEN TIME_TO_SEC(#{handlingCompletionTime}) >= TIME_TO_SEC(#{faultOccurrenceTime}) THEN
TIME_TO_SEC(#{handlingCompletionTime}) - TIME_TO_SEC(#{faultOccurrenceTime})
ELSE
TIME_TO_SEC(#{handlingCompletionTime}) + 86400 - TIME_TO_SEC(#{faultOccurrenceTime})
END
</when>
<otherwise>
#{handlingDuration}
</otherwise>
</choose>,
</trim>
where id = #{id}
</update>

Loading…
Cancel
Save