<?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.AclPractitionerPotentialGoalsMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclPractitionerPotentialGoals">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="practitioner_id" jdbcType="BIGINT" property="practitionerId" />
    <result column="current_year" jdbcType="INTEGER" property="currentYear" />
    <result column="statistic_time_unit" jdbcType="INTEGER" property="statisticTimeUnit" />
    <result column="seq_time" jdbcType="INTEGER" property="seqTime" />
    <result column="number_recruits" jdbcType="INTEGER" property="numberRecruits" />
    <result column="number_mdrt" jdbcType="INTEGER" property="numberMdrt" />
    <result column="current_version" jdbcType="TIMESTAMP" property="currentVersion" />
    <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">
    id, practitioner_id, current_year, statistic_time_unit, seq_time, number_recruits, 
    number_mdrt, current_version, is_active, created_at, created_by, updated_at, updated_by
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ag_acl_practitioner_potential_goals
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_acl_practitioner_potential_goals
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclPractitionerPotentialGoals" useGeneratedKeys="true">
    insert into ag_acl_practitioner_potential_goals (practitioner_id, current_year, statistic_time_unit, 
      seq_time, number_recruits, number_mdrt, 
      current_version, is_active, created_at, 
      created_by, updated_at, updated_by
      )
    values (#{practitionerId,jdbcType=BIGINT}, #{currentYear,jdbcType=INTEGER}, #{statisticTimeUnit,jdbcType=INTEGER}, 
      #{seqTime,jdbcType=INTEGER}, #{numberRecruits,jdbcType=INTEGER}, #{numberMdrt,jdbcType=INTEGER}, 
      #{currentVersion,jdbcType=TIMESTAMP}, #{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.AclPractitionerPotentialGoals" useGeneratedKeys="true">
    insert into ag_acl_practitioner_potential_goals
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="practitionerId != null">
        practitioner_id,
      </if>
      <if test="currentYear != null">
        current_year,
      </if>
      <if test="statisticTimeUnit != null">
        statistic_time_unit,
      </if>
      <if test="seqTime != null">
        seq_time,
      </if>
      <if test="numberRecruits != null">
        number_recruits,
      </if>
      <if test="numberMdrt != null">
        number_mdrt,
      </if>
      <if test="currentVersion != null">
        current_version,
      </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="practitionerId != null">
        #{practitionerId,jdbcType=BIGINT},
      </if>
      <if test="currentYear != null">
        #{currentYear,jdbcType=INTEGER},
      </if>
      <if test="statisticTimeUnit != null">
        #{statisticTimeUnit,jdbcType=INTEGER},
      </if>
      <if test="seqTime != null">
        #{seqTime,jdbcType=INTEGER},
      </if>
      <if test="numberRecruits != null">
        #{numberRecruits,jdbcType=INTEGER},
      </if>
      <if test="numberMdrt != null">
        #{numberMdrt,jdbcType=INTEGER},
      </if>
      <if test="currentVersion != null">
        #{currentVersion,jdbcType=TIMESTAMP},
      </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.AclPractitionerPotentialGoals">
    update ag_acl_practitioner_potential_goals
    <set>
      <if test="practitionerId != null">
        practitioner_id = #{practitionerId,jdbcType=BIGINT},
      </if>
      <if test="currentYear != null">
        current_year = #{currentYear,jdbcType=INTEGER},
      </if>
      <if test="statisticTimeUnit != null">
        statistic_time_unit = #{statisticTimeUnit,jdbcType=INTEGER},
      </if>
      <if test="seqTime != null">
        seq_time = #{seqTime,jdbcType=INTEGER},
      </if>
      <if test="numberRecruits != null">
        number_recruits = #{numberRecruits,jdbcType=INTEGER},
      </if>
      <if test="numberMdrt != null">
        number_mdrt = #{numberMdrt,jdbcType=INTEGER},
      </if>
      <if test="currentVersion != null">
        current_version = #{currentVersion,jdbcType=TIMESTAMP},
      </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.AclPractitionerPotentialGoals">
    update ag_acl_practitioner_potential_goals
    set practitioner_id = #{practitionerId,jdbcType=BIGINT},
      current_year = #{currentYear,jdbcType=INTEGER},
      statistic_time_unit = #{statisticTimeUnit,jdbcType=INTEGER},
      seq_time = #{seqTime,jdbcType=INTEGER},
      number_recruits = #{numberRecruits,jdbcType=INTEGER},
      number_mdrt = #{numberMdrt,jdbcType=INTEGER},
      current_version = #{currentVersion,jdbcType=TIMESTAMP},
      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>
  <select id="findByPractitionerAndCurrentYear" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_practitioner_potential_goals
    where practitioner_id = #{practitionerId,jdbcType=BIGINT} and current_year = #{currentYear,jdbcType=INTEGER} and is_active = 1
  </select>

  <insert id="saveAll"  parameterType="java.util.List" useGeneratedKeys="true">
    insert into ag_acl_practitioner_potential_goals (practitioner_id, current_year, statistic_time_unit,
    seq_time, number_recruits, number_mdrt,
    current_version, is_active, created_at,
    created_by, updated_at, updated_by
    )
    values
    <foreach collection="potentialGoalsList" item="item" index="index" separator=",">
      (
      #{item.practitionerId},
      #{item.currentYear},
      #{item.statisticTimeUnit},
      #{item.seqTime},
      #{item.numberRecruits},
      #{item.numberMdrt},
      #{item.currentVersion},
      #{item.isActive},
      #{item.createdAt},
      #{item.createdBy},
      #{item.updatedAt},
      #{item.updatedBy}
      )
    </foreach>
  </insert>

  <select id="findByPractitionerAndCurrentYearAndTimeUnit" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_practitioner_potential_goals
    where practitioner_id = #{practitionerId,jdbcType=BIGINT} and current_year = #{currentYear,jdbcType=INTEGER} and is_active = 1 and statistic_time_unit in
    <foreach collection="timeTypeList" item="timeType" open="(" separator="," close=")">
      #{timeType}
    </foreach>
  </select>
</mapper>