<?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">
<!--  Copyright (c) 京北方信息技术股份有限公司 Corporation 2023 . All rights reserved. -->
<!--  Mybatis数据库持久层（底层映射文件）：计划执行批次表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2023-10-11 20:31:24  -->
<mapper namespace="net.northking.cctp.executePlan.db.dao.AtuPlanBatchDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.executePlan.db.entity.AtuPlanBatch">
      <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                                              <!-- 计划主键 -->
    <result column="plan_id" jdbcType="VARCHAR" property="planId"/>
        <!-- 任务批次 -->
    <result column="batch" jdbcType="INTEGER" property="batch"/>
        <!-- 状态;0-等待中，1-执行中，2-已完成，3-已取消 -->
    <result column="status" jdbcType="CHAR" property="status"/>
        <!-- 调度开始时间 -->
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
        <!-- 调度结束时间 -->
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
        <!-- 任务总数 -->
    <result column="task_total" jdbcType="INTEGER" property="taskTotal"/>
        <!-- 执行成功脚本数 -->
    <result column="success_num" jdbcType="INTEGER" property="successNum"/>
        <!-- 执行失败脚本数 -->
    <result column="exec_fail_num" jdbcType="INTEGER" property="execFailNum"/>
        <!-- 断言失败脚本数 -->
    <result column="assert_fail_num" jdbcType="INTEGER" property="assertFailNum"/>
        <!-- 超时脚本数 -->
    <result column="timeout_num" jdbcType="INTEGER" property="timeoutNum"/>
        <!-- 取消脚本数 -->
    <result column="cancel_num" jdbcType="INTEGER" property="cancelNum"/>
        <!-- 成功率 -->
    <result column="success_rate" jdbcType="VARCHAR" property="successRate"/>
        <!-- 创建时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <!-- 执行人 -->
    <result column="executed_by" jdbcType="VARCHAR" property="executedBy"/>
        <!-- 触发类型；1-自动，2-手动，3-devops -->
    <result column="trigger_type" jdbcType="CHAR" property="triggerType"/>
        <!-- 脚本总数 -->
    <result column="script_num" jdbcType="INTEGER" property="scriptNum"/>
        <!-- 批次性能数据文件存放地址 -->
    <result column="per_data_path" jdbcType="VARCHAR" property="perDataPath"/>
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,plan_id
    ,batch
    ,status
    ,start_time
    ,end_time
    ,task_total
    ,success_num
    ,exec_fail_num
    ,assert_fail_num
    ,timeout_num
    ,cancel_num
    ,success_rate
    ,created_time
    ,executed_by
    ,trigger_type
    ,script_num
    ,per_data_path
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.atu_plan_batch
  </sql>

  <select id="findByPrimaryKey" parameterType="String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </select>

  <select id="findByPrimaryKeys" parameterType="java.util.List">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </select>

  <delete id="deleteByPrimaryKey" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <delete id="deleteByPrimaryKeys" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </delete>

  <delete id="deleteByExample" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatch">
    delete from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <choose>
        <when test="id != null">
          id = #{id,jdbcType=VARCHAR}
        </when>
      </choose>
              <if test="id != null">
          AND id=#{id,jdbcType=VARCHAR}
        </if>
              <if test="planId != null">
          AND plan_id=#{planId,jdbcType=VARCHAR}
        </if>
              <if test="batch != null">
          AND batch=#{batch,jdbcType=INTEGER}
        </if>
              <if test="status != null">
          AND status=#{status,jdbcType=CHAR}
        </if>
              <if test="startTime != null">
          AND start_time=#{startTime,jdbcType=TIMESTAMP}
        </if>
              <if test="endTime != null">
          AND end_time=#{endTime,jdbcType=TIMESTAMP}
        </if>
              <if test="taskTotal != null">
          AND task_total=#{taskTotal,jdbcType=INTEGER}
        </if>
              <if test="successNum != null">
          AND success_num=#{successNum,jdbcType=INTEGER}
        </if>
              <if test="execFailNum != null">
          AND exec_fail_num=#{execFailNum,jdbcType=INTEGER}
        </if>
              <if test="assertFailNum != null">
          AND assert_fail_num=#{assertFailNum,jdbcType=INTEGER}
        </if>
              <if test="timeoutNum != null">
          AND timeout_num=#{timeoutNum,jdbcType=INTEGER}
        </if>
              <if test="cancelNum != null">
          AND cancel_num=#{cancelNum,jdbcType=INTEGER}
        </if>
              <if test="successRate != null">
          AND success_rate=#{successRate,jdbcType=VARCHAR}
        </if>
              <if test="createdTime != null">
          AND created_time=#{createdTime,jdbcType=TIMESTAMP}
        </if>
              <if test="executedBy != null">
          AND executed_by=#{executedBy,jdbcType=VARCHAR}
        </if>
              <if test="triggerType != null">
          AND trigger_type=#{triggerType,jdbcType=CHAR}
        </if>
              <if test="scriptNum != null">
          AND script_num=#{scriptNum,jdbcType=INTEGER}
        </if>
              <if test="perDataPath != null">
          AND per_data_path=#{perDataPath,jdbcType=VARCHAR}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatch">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="planId != null">
        plan_id,
      </if>
      <if test="batch != null">
        batch,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="endTime != null">
        end_time,
      </if>
      <if test="taskTotal != null">
        task_total,
      </if>
      <if test="successNum != null">
        success_num,
      </if>
      <if test="execFailNum != null">
        exec_fail_num,
      </if>
      <if test="assertFailNum != null">
        assert_fail_num,
      </if>
      <if test="timeoutNum != null">
        timeout_num,
      </if>
      <if test="cancelNum != null">
        cancel_num,
      </if>
      <if test="successRate != null">
        success_rate,
      </if>
      <if test="createdTime != null">
        created_time,
      </if>
      <if test="executedBy != null">
        executed_by,
      </if>
      <if test="triggerType != null">
        trigger_type,
      </if>
      <if test="scriptNum != null">
        script_num,
      </if>
      <if test="perDataPath != null">
        per_data_path,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=VARCHAR},
      </if>
      <if test="planId != null">
          #{planId, jdbcType=VARCHAR},
      </if>
      <if test="batch != null">
          #{batch, jdbcType=INTEGER},
      </if>
      <if test="status != null">
          #{status, jdbcType=CHAR},
      </if>
      <if test="startTime != null">
          #{startTime, jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null">
          #{endTime, jdbcType=TIMESTAMP},
      </if>
      <if test="taskTotal != null">
          #{taskTotal, jdbcType=INTEGER},
      </if>
      <if test="successNum != null">
          #{successNum, jdbcType=INTEGER},
      </if>
      <if test="execFailNum != null">
          #{execFailNum, jdbcType=INTEGER},
      </if>
      <if test="assertFailNum != null">
          #{assertFailNum, jdbcType=INTEGER},
      </if>
      <if test="timeoutNum != null">
          #{timeoutNum, jdbcType=INTEGER},
      </if>
      <if test="cancelNum != null">
          #{cancelNum, jdbcType=INTEGER},
      </if>
      <if test="successRate != null">
          #{successRate, jdbcType=VARCHAR},
      </if>
      <if test="createdTime != null">
          #{createdTime, jdbcType=TIMESTAMP},
      </if>
      <if test="executedBy != null">
          #{executedBy, jdbcType=VARCHAR},
      </if>
      <if test="triggerType != null">
          #{triggerType, jdbcType=CHAR},
      </if>
      <if test="scriptNum != null">
          #{scriptNum, jdbcType=INTEGER},
      </if>
      <if test="perDataPath != null">
          #{perDataPath, jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    plan_id,
    batch,
    status,
    start_time,
    end_time,
    task_total,
    success_num,
    exec_fail_num,
    assert_fail_num,
    timeout_num,
    cancel_num,
    success_rate,
    created_time,
    executed_by,
    trigger_type,
    script_num,
    per_data_path,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.planId, jdbcType=VARCHAR},
    #{item.batch, jdbcType=INTEGER},
    #{item.status, jdbcType=CHAR},
    #{item.startTime, jdbcType=TIMESTAMP},
    #{item.endTime, jdbcType=TIMESTAMP},
    #{item.taskTotal, jdbcType=INTEGER},
    #{item.successNum, jdbcType=INTEGER},
    #{item.execFailNum, jdbcType=INTEGER},
    #{item.assertFailNum, jdbcType=INTEGER},
    #{item.timeoutNum, jdbcType=INTEGER},
    #{item.cancelNum, jdbcType=INTEGER},
    #{item.successRate, jdbcType=VARCHAR},
    #{item.createdTime, jdbcType=TIMESTAMP},
    #{item.executedBy, jdbcType=VARCHAR},
    #{item.triggerType, jdbcType=CHAR},
    #{item.scriptNum, jdbcType=INTEGER},
    #{item.perDataPath, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatch">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="planId != null">
        plan_id = #{planId, jdbcType=VARCHAR},
      </if>
      <if test="batch != null">
        batch = #{batch, jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status, jdbcType=CHAR},
      </if>
      <if test="startTime != null">
        start_time = #{startTime, jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null">
        end_time = #{endTime, jdbcType=TIMESTAMP},
      </if>
      <if test="taskTotal != null">
        task_total = #{taskTotal, jdbcType=INTEGER},
      </if>
      <if test="successNum != null">
        success_num = #{successNum, jdbcType=INTEGER},
      </if>
      <if test="execFailNum != null">
        exec_fail_num = #{execFailNum, jdbcType=INTEGER},
      </if>
      <if test="assertFailNum != null">
        assert_fail_num = #{assertFailNum, jdbcType=INTEGER},
      </if>
      <if test="timeoutNum != null">
        timeout_num = #{timeoutNum, jdbcType=INTEGER},
      </if>
      <if test="cancelNum != null">
        cancel_num = #{cancelNum, jdbcType=INTEGER},
      </if>
      <if test="successRate != null">
        success_rate = #{successRate, jdbcType=VARCHAR},
      </if>
      <if test="createdTime != null">
        created_time = #{createdTime, jdbcType=TIMESTAMP},
      </if>
      <if test="executedBy != null">
        executed_by = #{executedBy, jdbcType=VARCHAR},
      </if>
      <if test="triggerType != null">
        trigger_type = #{triggerType, jdbcType=CHAR},
      </if>
      <if test="scriptNum != null">
        script_num = #{scriptNum, jdbcType=INTEGER},
      </if>
      <if test="perDataPath != null">
        per_data_path = #{perDataPath, jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatch">
    select
    <include refid="Base_Column_List" />
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="planId != null">
        AND plan_id = #{planId,jdbcType=VARCHAR}
      </if>
      <if test="batch != null">
        AND batch = #{batch,jdbcType=INTEGER}
      </if>
      <if test="status != null">
        AND status = #{status,jdbcType=CHAR}
      </if>
      <if test="startTime != null">
        AND start_time = #{startTime,jdbcType=TIMESTAMP}
      </if>
      <if test="endTime != null">
        AND end_time = #{endTime,jdbcType=TIMESTAMP}
      </if>
      <if test="taskTotal != null">
        AND task_total = #{taskTotal,jdbcType=INTEGER}
      </if>
      <if test="successNum != null">
        AND success_num = #{successNum,jdbcType=INTEGER}
      </if>
      <if test="execFailNum != null">
        AND exec_fail_num = #{execFailNum,jdbcType=INTEGER}
      </if>
      <if test="assertFailNum != null">
        AND assert_fail_num = #{assertFailNum,jdbcType=INTEGER}
      </if>
      <if test="timeoutNum != null">
        AND timeout_num = #{timeoutNum,jdbcType=INTEGER}
      </if>
      <if test="cancelNum != null">
        AND cancel_num = #{cancelNum,jdbcType=INTEGER}
      </if>
      <if test="successRate != null">
        AND success_rate = #{successRate,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="executedBy != null">
        AND executed_by = #{executedBy,jdbcType=VARCHAR}
      </if>
      <if test="triggerType != null">
        AND trigger_type = #{triggerType,jdbcType=CHAR}
      </if>
      <if test="scriptNum != null">
        AND script_num = #{scriptNum,jdbcType=INTEGER}
      </if>
      <if test="perDataPath != null">
        AND per_data_path = #{perDataPath,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatch">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id=#{id,jdbcType=VARCHAR}
      </if>
      <if test="planId != null">
        AND plan_id=#{planId,jdbcType=VARCHAR}
      </if>
      <if test="batch != null">
        AND batch=#{batch,jdbcType=INTEGER}
      </if>
      <if test="status != null">
        AND status=#{status,jdbcType=CHAR}
      </if>
      <if test="startTime != null">
        AND start_time=#{startTime,jdbcType=TIMESTAMP}
      </if>
      <if test="endTime != null">
        AND end_time=#{endTime,jdbcType=TIMESTAMP}
      </if>
      <if test="taskTotal != null">
        AND task_total=#{taskTotal,jdbcType=INTEGER}
      </if>
      <if test="successNum != null">
        AND success_num=#{successNum,jdbcType=INTEGER}
      </if>
      <if test="execFailNum != null">
        AND exec_fail_num=#{execFailNum,jdbcType=INTEGER}
      </if>
      <if test="assertFailNum != null">
        AND assert_fail_num=#{assertFailNum,jdbcType=INTEGER}
      </if>
      <if test="timeoutNum != null">
        AND timeout_num=#{timeoutNum,jdbcType=INTEGER}
      </if>
      <if test="cancelNum != null">
        AND cancel_num=#{cancelNum,jdbcType=INTEGER}
      </if>
      <if test="successRate != null">
        AND success_rate=#{successRate,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time=#{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="executedBy != null">
        AND executed_by=#{executedBy,jdbcType=VARCHAR}
      </if>
      <if test="triggerType != null">
        AND trigger_type=#{triggerType,jdbcType=CHAR}
      </if>
      <if test="scriptNum != null">
        AND script_num=#{scriptNum,jdbcType=INTEGER}
      </if>
      <if test="perDataPath != null">
        AND per_data_path=#{perDataPath,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

</mapper>