<?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.yd.dal.mapper.customer.AclPractitionerHiringApproveRecordsMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclPractitionerHiringApproveRecords">
    <!--@mbg.generated-->
    <!--@Table ag_acl_practitioner_hiring_approve_records-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="hiring_basic_info_id" jdbcType="BIGINT" property="hiringBasicInfoId" />
    <result column="approve_step_id" jdbcType="VARCHAR" property="approveStepId" />
    <result column="approve_step_name" jdbcType="VARCHAR" property="approveStepName" />
    <result column="approving_practitioner_id" jdbcType="BIGINT" property="approvingPractitionerId" />
    <result column="approving_status" jdbcType="BIGINT" property="approvingStatus" />
    <result column="reject_note" jdbcType="VARCHAR" property="rejectNote" />
    <result column="interview_assessment" jdbcType="VARCHAR" property="interviewAssessment" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
    <result column="updated_by" jdbcType="BIGINT" property="updatedBy" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, hiring_basic_info_id, approve_step_id, approve_step_name, approving_practitioner_id, 
    approving_status, reject_note, is_active, created_at, created_by, updated_at, updated_by,
    interview_assessment
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from ag_acl_practitioner_hiring_approve_records
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from ag_acl_practitioner_hiring_approve_records
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclPractitionerHiringApproveRecords" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_acl_practitioner_hiring_approve_records (hiring_basic_info_id, approve_step_id, 
      approve_step_name, approving_practitioner_id, 
      approving_status, reject_note, interview_assessment, is_active,
      created_at, created_by, updated_at, 
      updated_by)
    values (#{hiringBasicInfoId,jdbcType=BIGINT}, #{approveStepId,jdbcType=VARCHAR}, 
      #{approveStepName,jdbcType=VARCHAR}, #{approvingPractitionerId,jdbcType=BIGINT}, 
      #{approvingStatus,jdbcType=BIGINT}, #{rejectNote,jdbcType=VARCHAR}, #{interviewAssessment,jdbcType=VARCHAR}, #{isActive,jdbcType=INTEGER},
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{updatedAt,jdbcType=TIMESTAMP}, 
      #{updatedBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclPractitionerHiringApproveRecords" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_acl_practitioner_hiring_approve_records
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="hiringBasicInfoId != null">
        hiring_basic_info_id,
      </if>
      <if test="approveStepId != null">
        approve_step_id,
      </if>
      <if test="approveStepName != null">
        approve_step_name,
      </if>
      <if test="approvingPractitionerId != null">
        approving_practitioner_id,
      </if>
      <if test="approvingStatus != null">
        approving_status,
      </if>
      <if test="rejectNote != null">
        reject_note,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="hiringBasicInfoId != null">
        #{hiringBasicInfoId,jdbcType=BIGINT},
      </if>
      <if test="approveStepId != null">
        #{approveStepId,jdbcType=VARCHAR},
      </if>
      <if test="approveStepName != null">
        #{approveStepName,jdbcType=VARCHAR},
      </if>
      <if test="approvingPractitionerId != null">
        #{approvingPractitionerId,jdbcType=BIGINT},
      </if>
      <if test="approvingStatus != null">
        #{approvingStatus,jdbcType=BIGINT},
      </if>
      <if test="rejectNote != null">
        #{rejectNote,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.customer.AclPractitionerHiringApproveRecords">
    <!--@mbg.generated-->
    update ag_acl_practitioner_hiring_approve_records
    <set>
      <if test="hiringBasicInfoId != null">
        hiring_basic_info_id = #{hiringBasicInfoId,jdbcType=BIGINT},
      </if>
      <if test="approveStepId != null">
        approve_step_id = #{approveStepId,jdbcType=VARCHAR},
      </if>
      <if test="approveStepName != null">
        approve_step_name = #{approveStepName,jdbcType=VARCHAR},
      </if>
      <if test="approvingPractitionerId != null">
        approving_practitioner_id = #{approvingPractitionerId,jdbcType=BIGINT},
      </if>
      <if test="approvingStatus != null">
        approving_status = #{approvingStatus,jdbcType=BIGINT},
      </if>
      <if test="rejectNote != null">
        reject_note = #{rejectNote,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.customer.AclPractitionerHiringApproveRecords">
    <!--@mbg.generated-->
    update ag_acl_practitioner_hiring_approve_records
    set hiring_basic_info_id = #{hiringBasicInfoId,jdbcType=BIGINT},
      approve_step_id = #{approveStepId,jdbcType=VARCHAR},
      approve_step_name = #{approveStepName,jdbcType=VARCHAR},
      approving_practitioner_id = #{approvingPractitionerId,jdbcType=BIGINT},
      approving_status = #{approvingStatus,jdbcType=BIGINT},
      reject_note = #{rejectNote,jdbcType=VARCHAR},
      is_active = #{isActive,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update ag_acl_practitioner_hiring_approve_records
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="hiring_basic_info_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.hiringBasicInfoId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="approve_step_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.approveStepId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="approve_step_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.approveStepName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="approving_practitioner_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.approvingPractitionerId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="approving_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.approvingStatus,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="reject_note = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.rejectNote,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="is_active = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.isActive,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="created_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.createdAt,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="created_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.createdBy,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="updated_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.updatedAt,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="updated_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.updatedBy,jdbcType=BIGINT}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update ag_acl_practitioner_hiring_approve_records
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="hiring_basic_info_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.hiringBasicInfoId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.hiringBasicInfoId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="approve_step_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.approveStepId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.approveStepId,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="approve_step_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.approveStepName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.approveStepName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="approving_practitioner_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.approvingPractitionerId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.approvingPractitionerId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="approving_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.approvingStatus != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.approvingStatus,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="reject_note = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.rejectNote != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.rejectNote,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="is_active = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.isActive != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.isActive,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="created_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createdAt != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.createdAt,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="created_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createdBy != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.createdBy,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="updated_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updatedAt != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.updatedAt,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="updated_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updatedBy != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.updatedBy,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_acl_practitioner_hiring_approve_records
    (hiring_basic_info_id, approve_step_id, approve_step_name, approving_practitioner_id, 
      approving_status, interview_assessment, reject_note, is_active, created_at, created_by, updated_at, updated_by
      )
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.hiringBasicInfoId,jdbcType=BIGINT}, #{item.approveStepId,jdbcType=VARCHAR}, 
        #{item.approveStepName,jdbcType=VARCHAR}, #{item.approvingPractitionerId,jdbcType=BIGINT}, 
        #{item.approvingStatus,jdbcType=BIGINT}, #{item.interviewAssessment,jdbcType=VARCHAR}, #{item.rejectNote,jdbcType=VARCHAR}, #{item.isActive,jdbcType=INTEGER},
        #{item.createdAt,jdbcType=TIMESTAMP}, #{item.createdBy,jdbcType=BIGINT}, #{item.updatedAt,jdbcType=TIMESTAMP}, 
        #{item.updatedBy,jdbcType=BIGINT})
    </foreach>
  </insert>

  <resultMap id="LastOneRecord" type="com.yd.dal.entity.customer.AclPractitionerHiringApproveRecords">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="hiring_basic_info_id" jdbcType="BIGINT" property="hiringBasicInfoId" />
    <result column="approve_step_id" jdbcType="VARCHAR" property="approveStepId" />
    <result column="approve_step_name" jdbcType="VARCHAR" property="approveStepName" />
    <result column="step_seq" jdbcType="VARCHAR" property="stepSeq" />
    <result column="approving_practitioner_id" jdbcType="BIGINT" property="approvingPractitionerId" />
    <result column="approving_status" jdbcType="BIGINT" property="approvingStatus" />
    <result column="reject_note" jdbcType="VARCHAR" property="rejectNote" />
    <result column="interview_assessment" jdbcType="VARCHAR" property="interviewAssessment" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
    <result column="updated_by" jdbcType="BIGINT" property="updatedBy" />
  </resultMap>
    <select id="queryLastOneByBasicInfoId" resultMap="LastOneRecord">
        select r.*, s.step_seq
        from  ag_acl_practitioner_hiring_approve_records r
        left join ag_md_practitioner_hiring_approve_steps s on r.approve_step_id = s.id
        where r.hiring_basic_info_id = #{hiringBasicInfoId,jdbcType=BIGINT}
        order by s.step_seq desc
        limit 1
    </select>

    <select id="queryListByBasicInfoId" resultMap="LastOneRecord">
        select r.*, s.step_seq
        from  ag_acl_practitioner_hiring_approve_records r
        left join ag_md_practitioner_hiring_approve_steps s on r.approve_step_id = s.id
        where r.hiring_basic_info_id = #{hiringBasicInfoId,jdbcType=BIGINT}
        order by s.step_seq desc
    </select>

    <delete id="deleteByHiringBasicInfoId">
        delete from ag_acl_practitioner_hiring_approve_records where hiring_basic_info_id = #{hiringBasicInfoId,jdbcType=BIGINT}
    </delete>
</mapper>