<?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="com.energy.manage.service.mappers.analysispriorityrecords.AnalysisPriorityRecordsMapper">
  <resultMap id="BaseResultMap" type="com.energy.manage.common.po.analysispriorityrecords.AnalysisPriorityRecordsPo">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="batch_code" jdbcType="VARCHAR" property="batchCode" />
    <result column="priority" jdbcType="TINYINT" property="priority" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="execute_status" jdbcType="TINYINT" property="executeStatus" />
    <result column="task_id" jdbcType="VARCHAR" property="taskId" />
  </resultMap>
  <sql id="Base_Column_List">
    id, batch_code, priority, create_time, update_time, execute_status, task_id
  </sql>

  <select id="queryFirstPriority" resultMap="BaseResultMap">
    select * from analysis_priority_records where execute_status = 0 order by priority desc , update_time asc limit 1
  </select>

  <select id="queryAllPriority" resultMap="BaseResultMap">
    select * from analysis_priority_records where execute_status = 0 order by priority desc , update_time asc
  </select>
  <update id="updateExecuteStatus">
    update analysis_priority_records
    set execute_status = #{executeStatus,jdbcType=TINYINT}
    where task_id = #{taskId,jdbcType=VARCHAR}
  </update>

  <update id="updatePriotityByBatchCode">
    update analysis_priority_records
    set priority = #{priority,jdbcType=TINYINT}
    where batch_code = #{batchCode,jdbcType=VARCHAR}
    and execute_status = 0
  </update>
</mapper>
