| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?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="cn.sciento.farm.automationv2.infra.mapper.AlarmRecordMapper">
- <resultMap id="BaseResultMap" type="cn.sciento.farm.automationv2.domain.entity.AlarmRecord">
- <id column="id" property="id"/>
- <result column="execution_id" property="executionId"/>
- <result column="task_id" property="taskId"/>
- <result column="task_name" property="taskName"/>
- <result column="alarm_type" property="alarmType" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
- <result column="alarm_level" property="alarmLevel"/>
- <result column="failed_node" property="failedNode"/>
- <result column="failed_node_index" property="failedNodeIndex"/>
- <result column="fail_reason" property="failReason"/>
- <result column="failed_devices" property="failedDevices"/>
- <result column="success_devices" property="successDevices"/>
- <result column="safe_close_status" property="safeCloseStatus"/>
- <result column="safe_close_details" property="safeCloseDetails"/>
- <result column="notified_channels" property="notifiedChannels"/>
- <result column="notify_status" property="notifyStatus"/>
- <result column="notify_error" property="notifyError"/>
- <result column="handled" property="handled"/>
- <result column="handled_by" property="handledBy"/>
- <result column="handled_at" property="handledAt"/>
- <result column="handle_remark" property="handleRemark"/>
- <result column="tenant_id" property="tenantId"/>
- <result column="created_at" property="createdAt"/>
- </resultMap>
- <insert id="insert" parameterType="cn.sciento.farm.automationv2.domain.entity.AlarmRecord" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO alarm_record (
- execution_id, task_id, task_name, alarm_type, alarm_level,
- failed_node, failed_node_index, fail_reason, failed_devices, success_devices,
- safe_close_status, safe_close_details, notified_channels, notify_status,
- tenant_id, created_at
- ) VALUES (
- #{executionId}, #{taskId}, #{taskName}, #{alarmType}, #{alarmLevel},
- #{failedNode}, #{failedNodeIndex}, #{failReason}, #{failedDevices}, #{successDevices},
- #{safeCloseStatus}, #{safeCloseDetails}, #{notifiedChannels}, #{notifyStatus},
- #{tenantId}, NOW()
- )
- </insert>
- <select id="selectById" resultMap="BaseResultMap">
- SELECT * FROM alarm_record WHERE id = #{id}
- </select>
- <select id="selectByExecutionId" resultMap="BaseResultMap">
- SELECT * FROM alarm_record WHERE execution_id = #{executionId} LIMIT 1
- </select>
- <select id="selectByTaskId" resultMap="BaseResultMap">
- SELECT * FROM alarm_record
- WHERE task_id = #{taskId}
- ORDER BY created_at DESC
- LIMIT #{offset}, #{limit}
- </select>
- <select id="selectUnhandledAlarms" resultMap="BaseResultMap">
- SELECT * FROM alarm_record
- WHERE tenant_id = #{tenantId} AND handled = 0
- ORDER BY created_at DESC
- <if test="limit != null">
- LIMIT #{limit}
- </if>
- </select>
- <update id="updateById">
- UPDATE alarm_record
- <set>
- <if test="notifiedChannels != null">notified_channels = #{notifiedChannels},</if>
- <if test="notifyStatus != null">notify_status = #{notifyStatus},</if>
- <if test="notifyError != null">notify_error = #{notifyError},</if>
- <if test="handled != null">handled = #{handled},</if>
- <if test="handledBy != null">handled_by = #{handledBy},</if>
- <if test="handledAt != null">handled_at = #{handledAt},</if>
- <if test="handleRemark != null">handle_remark = #{handleRemark},</if>
- </set>
- WHERE id = #{id}
- </update>
- <update id="markAsHandled">
- UPDATE alarm_record
- SET handled = 1,
- handled_by = #{handledBy},
- handled_at = NOW(),
- handle_remark = #{handleRemark}
- WHERE id = #{id}
- </update>
- <update id="updateNotifyStatus">
- UPDATE alarm_record
- SET notify_status = #{notifyStatus},
- notified_channels = #{notifiedChannels}
- WHERE id = #{id}
- </update>
- <select id="selectByTenant" resultMap="BaseResultMap">
- SELECT
- *
- FROM
- wfauto_v2_alarm_record
- WHERE
- tenant_id = #{alarm.tenantId}
- <if test="alarm.executionId != null and alarm.executionId != ''">
- AND execution_id = #{alarm.executionId}
- </if>
- <if test="alarm.taskId != null and alarm.taskId != ''">
- AND task_id = #{alarm.taskId}
- </if>
- <if test="alarm.handled != null and alarm.handled != ''">
- AND handled = #{alarm.handled}
- </if>
- </select>
- <select id="countUnhandled" resultType="int">
- SELECT COUNT(*) FROM alarm_record
- WHERE tenant_id = #{tenantId} AND handled = 0
- </select>
- <delete id="deleteById">
- DELETE FROM alarm_record WHERE id = #{id}
- </delete>
- </mapper>
|