<?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.meta.MdPractitionerHiringApproveStepsMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.meta.MdPractitionerHiringApproveSteps">
    <!--@mbg.generated-->
    <!--@Table ag_md_practitioner_hiring_approve_steps-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="step_name" jdbcType="VARCHAR" property="stepName" />
    <result column="approve_role" jdbcType="VARCHAR" property="approveRole" />
    <result column="appointed_approve_practitioners" jdbcType="VARCHAR" property="appointedApprovePractitioners" />
    <result column="step_seq" jdbcType="INTEGER" property="stepSeq" />
    <result column="can_aprrove_grade" jdbcType="VARCHAR" property="canAprroveGrade" />
    <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, step_name, approve_role, appointed_approve_practitioners, step_seq, can_aprrove_grade, 
    is_active, created_at, created_by, updated_at, updated_by
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from ag_md_practitioner_hiring_approve_steps
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from ag_md_practitioner_hiring_approve_steps
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.meta.MdPractitionerHiringApproveSteps" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_md_practitioner_hiring_approve_steps (step_name, approve_role, appointed_approve_practitioners, 
      step_seq, can_aprrove_grade, is_active, 
      created_at, created_by, updated_at, 
      updated_by)
    values (#{stepName,jdbcType=VARCHAR}, #{approveRole,jdbcType=VARCHAR}, #{appointedApprovePractitioners,jdbcType=VARCHAR}, 
      #{stepSeq,jdbcType=INTEGER}, #{canAprroveGrade,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.meta.MdPractitionerHiringApproveSteps" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_md_practitioner_hiring_approve_steps
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="stepName != null">
        step_name,
      </if>
      <if test="approveRole != null">
        approve_role,
      </if>
      <if test="appointedApprovePractitioners != null">
        appointed_approve_practitioners,
      </if>
      <if test="stepSeq != null">
        step_seq,
      </if>
      <if test="canAprroveGrade != null">
        can_aprrove_grade,
      </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="stepName != null">
        #{stepName,jdbcType=VARCHAR},
      </if>
      <if test="approveRole != null">
        #{approveRole,jdbcType=VARCHAR},
      </if>
      <if test="appointedApprovePractitioners != null">
        #{appointedApprovePractitioners,jdbcType=VARCHAR},
      </if>
      <if test="stepSeq != null">
        #{stepSeq,jdbcType=INTEGER},
      </if>
      <if test="canAprroveGrade != null">
        #{canAprroveGrade,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.meta.MdPractitionerHiringApproveSteps">
    <!--@mbg.generated-->
    update ag_md_practitioner_hiring_approve_steps
    <set>
      <if test="stepName != null">
        step_name = #{stepName,jdbcType=VARCHAR},
      </if>
      <if test="approveRole != null">
        approve_role = #{approveRole,jdbcType=VARCHAR},
      </if>
      <if test="appointedApprovePractitioners != null">
        appointed_approve_practitioners = #{appointedApprovePractitioners,jdbcType=VARCHAR},
      </if>
      <if test="stepSeq != null">
        step_seq = #{stepSeq,jdbcType=INTEGER},
      </if>
      <if test="canAprroveGrade != null">
        can_aprrove_grade = #{canAprroveGrade,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.meta.MdPractitionerHiringApproveSteps">
    <!--@mbg.generated-->
    update ag_md_practitioner_hiring_approve_steps
    set step_name = #{stepName,jdbcType=VARCHAR},
      approve_role = #{approveRole,jdbcType=VARCHAR},
      appointed_approve_practitioners = #{appointedApprovePractitioners,jdbcType=VARCHAR},
      step_seq = #{stepSeq,jdbcType=INTEGER},
      can_aprrove_grade = #{canAprroveGrade,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_md_practitioner_hiring_approve_steps
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="step_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.stepName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="approve_role = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.approveRole,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="appointed_approve_practitioners = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.appointedApprovePractitioners,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="step_seq = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.stepSeq,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="can_aprrove_grade = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.canAprroveGrade,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_md_practitioner_hiring_approve_steps
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="step_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.stepName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.stepName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="approve_role = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.approveRole != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.approveRole,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="appointed_approve_practitioners = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.appointedApprovePractitioners != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.appointedApprovePractitioners,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="step_seq = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.stepSeq != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.stepSeq,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="can_aprrove_grade = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.canAprroveGrade != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.canAprroveGrade,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_md_practitioner_hiring_approve_steps
    (step_name, approve_role, appointed_approve_practitioners, step_seq, can_aprrove_grade, 
      is_active, created_at, created_by, updated_at, updated_by)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.stepName,jdbcType=VARCHAR}, #{item.approveRole,jdbcType=VARCHAR}, #{item.appointedApprovePractitioners,jdbcType=VARCHAR}, 
        #{item.stepSeq,jdbcType=INTEGER}, #{item.canAprroveGrade,jdbcType=VARCHAR}, #{item.isActive,jdbcType=INTEGER}, 
        #{item.createdAt,jdbcType=TIMESTAMP}, #{item.createdBy,jdbcType=BIGINT}, #{item.updatedAt,jdbcType=TIMESTAMP}, 
        #{item.updatedBy,jdbcType=BIGINT})
    </foreach>
  </insert>

    <select id="findAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ag_md_practitioner_hiring_approve_steps
        where is_active = 1
        order by step_seq
    </select>

    <select id="findByPractitionerLevel" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ag_md_practitioner_hiring_approve_steps
        where is_active = 1
          and (can_aprrove_grade is null or find_in_set(#{practitionerLevelId,jdbcType=VARCHAR}, can_aprrove_grade))
        order by step_seq
    </select>

    <select id="findByAppointedApprovePractitioners" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ag_md_practitioner_hiring_approve_steps
        where is_active = 1
        and find_in_set(#{appointedApprovePractitioners,jdbcType=VARCHAR},appointed_approve_practitioners)
        order by step_seq
    </select>
</mapper>