<?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.AclPractitionerPotentialGoalsActionsMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclPractitionerPotentialGoalsActions">
    <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="potential_action_id" jdbcType="BIGINT" property="potentialActionId" />
    <result column="potential_action_name" jdbcType="VARCHAR" property="potentialActionName" />
    <result column="action_standards" jdbcType="INTEGER" property="actionStandards" />
    <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, potential_action_id, potential_action_name, 
    action_standards, 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_actions
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_acl_practitioner_potential_goals_actions
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclPractitionerPotentialGoalsActions" useGeneratedKeys="true">
    insert into ag_acl_practitioner_potential_goals_actions (practitioner_id, current_year, statistic_time_unit, 
      potential_action_id, potential_action_name, 
      action_standards, current_version, is_active, 
      created_at, created_by, updated_at, 
      updated_by)
    values (#{practitionerId,jdbcType=BIGINT}, #{currentYear,jdbcType=INTEGER}, #{statisticTimeUnit,jdbcType=INTEGER}, 
      #{potentialActionId,jdbcType=BIGINT}, #{potentialActionName,jdbcType=VARCHAR},
      #{actionStandards,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.AclPractitionerPotentialGoalsActions" useGeneratedKeys="true">
    insert into ag_acl_practitioner_potential_goals_actions
    <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="potentialActionId != null">
        potential_action_id,
      </if>
      <if test="potentialActionName != null">
        potential_action_name,
      </if>
      <if test="actionStandards != null">
        action_standards,
      </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="potentialActionId != null">
        #{potentialActionId,jdbcType=BIGINT},
      </if>
      <if test="potentialActionName != null">
        #{potentialActionName,jdbcType=VARCHAR},
      </if>
      <if test="actionStandards != null">
        #{actionStandards,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.AclPractitionerPotentialGoalsActions">
    update ag_acl_practitioner_potential_goals_actions
    <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="potentialActionId != null">
        potential_action_id = #{potentialActionId,jdbcType=BIGINT},
      </if>
      <if test="potentialActionName != null">
        potential_action_name = #{potentialActionName,jdbcType=VARCHAR},
      </if>
      <if test="actionStandards != null">
        action_standards = #{actionStandards,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.AclPractitionerPotentialGoalsActions">
    update ag_acl_practitioner_potential_goals_actions
    set practitioner_id = #{practitionerId,jdbcType=BIGINT},
      current_year = #{currentYear,jdbcType=INTEGER},
      statistic_time_unit = #{statisticTimeUnit,jdbcType=INTEGER},
      potential_action_id = #{potentialActionId,jdbcType=BIGINT},
      potential_action_name = #{potentialActionName,jdbcType=VARCHAR},
      action_standards = #{actionStandards,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="findByPractitionerIdAndCurrentYearAndIsActive" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_practitioner_potential_goals_actions
    where practitioner_id = #{practitionerId,jdbcType=BIGINT} and is_active = #{isActive,jdbcType=INTEGER} and current_year = #{currentYear,jdbcType=INTEGER}
  </select>

  <insert id="saveAll" parameterType="java.util.List" useGeneratedKeys="true" >
    insert into ag_acl_practitioner_potential_goals_actions (practitioner_id, current_year, statistic_time_unit,
    potential_action_id, potential_action_name,
    action_standards, current_version, is_active,
    created_at, created_by, updated_at,
    updated_by)
    values
    <foreach collection="potentialGoalsActionsList" item="item" index="index" separator=",">
      (
      #{item.practitionerId},
      #{item.currentYear},
      #{item.statisticTimeUnit},
      #{item.potentialActionId},
      #{item.potentialActionName},
      #{item.actionStandards},
      #{item.currentVersion},
      #{item.isActive},
      #{item.createdAt},
      #{item.createdBy},
      #{item.updatedAt},
      #{item.updatedBy}
      )
    </foreach>
  </insert>
    <select id="findByPractitionerIdAndCurrentYearAndIsActiveAndTimeUnit" resultMap="BaseResultMap">
      select
      <include refid="Base_Column_List" />
      from ag_acl_practitioner_potential_goals_actions
      where practitioner_id = #{practitionerId,jdbcType=BIGINT} and is_active = #{isActive,jdbcType=INTEGER} and current_year = #{currentYear,jdbcType=INTEGER} and statistic_time_unit = #{timeType,jdbcType=INTEGER}
    </select>
</mapper>