AlarmRecordMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.sciento.farm.automationv2.infra.mapper.AlarmRecordMapper">
  4. <resultMap id="BaseResultMap" type="cn.sciento.farm.automationv2.domain.entity.AlarmRecord">
  5. <id column="id" property="id"/>
  6. <result column="execution_id" property="executionId"/>
  7. <result column="task_id" property="taskId"/>
  8. <result column="task_name" property="taskName"/>
  9. <result column="alarm_type" property="alarmType" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
  10. <result column="alarm_level" property="alarmLevel"/>
  11. <result column="failed_node" property="failedNode"/>
  12. <result column="failed_node_index" property="failedNodeIndex"/>
  13. <result column="fail_reason" property="failReason"/>
  14. <result column="failed_devices" property="failedDevices"/>
  15. <result column="success_devices" property="successDevices"/>
  16. <result column="safe_close_status" property="safeCloseStatus"/>
  17. <result column="safe_close_details" property="safeCloseDetails"/>
  18. <result column="notified_channels" property="notifiedChannels"/>
  19. <result column="notify_status" property="notifyStatus"/>
  20. <result column="notify_error" property="notifyError"/>
  21. <result column="handled" property="handled"/>
  22. <result column="handled_by" property="handledBy"/>
  23. <result column="handled_at" property="handledAt"/>
  24. <result column="handle_remark" property="handleRemark"/>
  25. <result column="tenant_id" property="tenantId"/>
  26. <result column="created_at" property="createdAt"/>
  27. </resultMap>
  28. <insert id="insert" parameterType="cn.sciento.farm.automationv2.domain.entity.AlarmRecord" useGeneratedKeys="true" keyProperty="id">
  29. INSERT INTO alarm_record (
  30. execution_id, task_id, task_name, alarm_type, alarm_level,
  31. failed_node, failed_node_index, fail_reason, failed_devices, success_devices,
  32. safe_close_status, safe_close_details, notified_channels, notify_status,
  33. tenant_id, created_at
  34. ) VALUES (
  35. #{executionId}, #{taskId}, #{taskName}, #{alarmType}, #{alarmLevel},
  36. #{failedNode}, #{failedNodeIndex}, #{failReason}, #{failedDevices}, #{successDevices},
  37. #{safeCloseStatus}, #{safeCloseDetails}, #{notifiedChannels}, #{notifyStatus},
  38. #{tenantId}, NOW()
  39. )
  40. </insert>
  41. <select id="selectById" resultMap="BaseResultMap">
  42. SELECT * FROM alarm_record WHERE id = #{id}
  43. </select>
  44. <select id="selectByExecutionId" resultMap="BaseResultMap">
  45. SELECT * FROM alarm_record WHERE execution_id = #{executionId} LIMIT 1
  46. </select>
  47. <select id="selectByTaskId" resultMap="BaseResultMap">
  48. SELECT * FROM alarm_record
  49. WHERE task_id = #{taskId}
  50. ORDER BY created_at DESC
  51. LIMIT #{offset}, #{limit}
  52. </select>
  53. <select id="selectUnhandledAlarms" resultMap="BaseResultMap">
  54. SELECT * FROM alarm_record
  55. WHERE tenant_id = #{tenantId} AND handled = 0
  56. ORDER BY created_at DESC
  57. <if test="limit != null">
  58. LIMIT #{limit}
  59. </if>
  60. </select>
  61. <update id="updateById">
  62. UPDATE alarm_record
  63. <set>
  64. <if test="notifiedChannels != null">notified_channels = #{notifiedChannels},</if>
  65. <if test="notifyStatus != null">notify_status = #{notifyStatus},</if>
  66. <if test="notifyError != null">notify_error = #{notifyError},</if>
  67. <if test="handled != null">handled = #{handled},</if>
  68. <if test="handledBy != null">handled_by = #{handledBy},</if>
  69. <if test="handledAt != null">handled_at = #{handledAt},</if>
  70. <if test="handleRemark != null">handle_remark = #{handleRemark},</if>
  71. </set>
  72. WHERE id = #{id}
  73. </update>
  74. <update id="markAsHandled">
  75. UPDATE alarm_record
  76. SET handled = 1,
  77. handled_by = #{handledBy},
  78. handled_at = NOW(),
  79. handle_remark = #{handleRemark}
  80. WHERE id = #{id}
  81. </update>
  82. <update id="updateNotifyStatus">
  83. UPDATE alarm_record
  84. SET notify_status = #{notifyStatus},
  85. notified_channels = #{notifiedChannels}
  86. WHERE id = #{id}
  87. </update>
  88. <select id="selectByTenant" resultMap="BaseResultMap">
  89. SELECT
  90. *
  91. FROM
  92. wfauto_v2_alarm_record
  93. WHERE
  94. tenant_id = #{alarm.tenantId}
  95. <if test="alarm.executionId != null and alarm.executionId != ''">
  96. AND execution_id = #{alarm.executionId}
  97. </if>
  98. <if test="alarm.taskId != null and alarm.taskId != ''">
  99. AND task_id = #{alarm.taskId}
  100. </if>
  101. <if test="alarm.handled != null and alarm.handled != ''">
  102. AND handled = #{alarm.handled}
  103. </if>
  104. </select>
  105. <select id="countUnhandled" resultType="int">
  106. SELECT COUNT(*) FROM alarm_record
  107. WHERE tenant_id = #{tenantId} AND handled = 0
  108. </select>
  109. <delete id="deleteById">
  110. DELETE FROM alarm_record WHERE id = #{id}
  111. </delete>
  112. </mapper>