<?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.marketing.MktLeadsGoalsActionsMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.marketing.MktLeadsGoalsActions">
    <!--@mbg.generated-->
    <!--@Table ag_mkt_leads_goals_actions-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="goals_type" jdbcType="INTEGER" property="goalsType" />
    <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="leads_action_id" jdbcType="BIGINT" property="leadsActionId" />
    <result column="leads_action_name" jdbcType="VARCHAR" property="leadsActionName" />
    <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">
    <!--@mbg.generated-->
    id, goals_type, practitioner_id, current_year, statistic_time_unit, leads_action_id, 
    leads_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">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from ag_mkt_leads_goals_actions
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from ag_mkt_leads_goals_actions
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.marketing.MktLeadsGoalsActions" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_mkt_leads_goals_actions (goals_type, practitioner_id, current_year, 
      statistic_time_unit, leads_action_id, leads_action_name, 
      action_standards, current_version, is_active, 
      created_at, created_by, updated_at, 
      updated_by)
    values (#{goalsType,jdbcType=INTEGER}, #{practitionerId,jdbcType=BIGINT}, #{currentYear,jdbcType=INTEGER}, 
      #{statisticTimeUnit,jdbcType=INTEGER}, #{leadsActionId,jdbcType=BIGINT}, #{leadsActionName,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.marketing.MktLeadsGoalsActions" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_mkt_leads_goals_actions
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="goalsType != null">
        goals_type,
      </if>
      <if test="practitionerId != null">
        practitioner_id,
      </if>
      <if test="currentYear != null">
        current_year,
      </if>
      <if test="statisticTimeUnit != null">
        statistic_time_unit,
      </if>
      <if test="leadsActionId != null">
        leads_action_id,
      </if>
      <if test="leadsActionName != null">
        leads_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="goalsType != null">
        #{goalsType,jdbcType=INTEGER},
      </if>
      <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="leadsActionId != null">
        #{leadsActionId,jdbcType=BIGINT},
      </if>
      <if test="leadsActionName != null">
        #{leadsActionName,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.marketing.MktLeadsGoalsActions">
    <!--@mbg.generated-->
    update ag_mkt_leads_goals_actions
    <set>
      <if test="goalsType != null">
        goals_type = #{goalsType,jdbcType=INTEGER},
      </if>
      <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="leadsActionId != null">
        leads_action_id = #{leadsActionId,jdbcType=BIGINT},
      </if>
      <if test="leadsActionName != null">
        leads_action_name = #{leadsActionName,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.marketing.MktLeadsGoalsActions">
    <!--@mbg.generated-->
    update ag_mkt_leads_goals_actions
    set goals_type = #{goalsType,jdbcType=INTEGER},
      practitioner_id = #{practitionerId,jdbcType=BIGINT},
      current_year = #{currentYear,jdbcType=INTEGER},
      statistic_time_unit = #{statisticTimeUnit,jdbcType=INTEGER},
      leads_action_id = #{leadsActionId,jdbcType=BIGINT},
      leads_action_name = #{leadsActionName,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>
    <update id="updateIsActiveIsNull">
        UPDATE ag_mkt_leads_goals_actions
        set
            is_active = 0
        where
            practitioner_id = #{practitionerId,jdbcType=BIGINT}
            and current_year = #{year,jdbcType=INTEGER}
            and goals_type = #{goalsType,jdbcType=INTEGER}
            and is_active =1;
    </update>
    <select id="findByMktLeadsGoalsActions" resultMap="BaseResultMap">
      select
      <include refid="Base_Column_List" />
      from ag_mkt_leads_goals_actions
      <where>
        <if test="id != null">
          id = #{id,jdbcType=BIGINT}
        </if>
        <if test="practitionerId != null">
          and practitioner_id = #{practitionerId,jdbcType=BIGINT}
        </if>
        <if test="currentYear != null">
          and current_year = #{currentYear,jdbcType=INTEGER}
        </if>
        <if test="statisticTimeUnit != null">
          and statistic_time_unit = #{statisticTimeUnit,jdbcType=INTEGER}
        </if>
        <if test="leadsActionId != null">
          and leads_action_id = #{leadsActionId,jdbcType=BIGINT}
        </if>
        <if test="leadsActionName != null">
          and leads_action_name = #{leadsActionName,jdbcType=VARCHAR}
        </if>
        <if test="actionStandards != null">
          and action_standards = #{actionStandards,jdbcType=INTEGER}
        </if>
        <if test="currentVersion != null">
          and current_version = #{currentVersion,jdbcType=TIMESTAMP}
        </if>
        <if test="isActive != null">
          and is_active = #{isActive,jdbcType=INTEGER}
        </if>
        <if test="createdAt != null">
          and created_at = #{createdAt,jdbcType=TIMESTAMP}
        </if>
        <if test="createdBy != null">
          and created_by = #{createdBy,jdbcType=BIGINT}
        </if>
        <if test="updatedAt != null">
          and updated_at = #{updatedAt,jdbcType=TIMESTAMP}
        </if>
        <if test="updatedBy != null">
          and updated_by = #{updatedBy,jdbcType=BIGINT}
        </if>
        <if test="goalsType != null">
          and goals_type = #{goalsType,jdbcType=INTEGER}
        </if>
      </where>
    </select>
    <select id="findTeamGoalsMonth" resultMap="BaseResultMap">
      select a.*
      from ag_mkt_leads_goals_actions a
        left join ag_acl_practitioner p left join  ag_acl_practitioner_subordinate_system s on p.subordinate_system_id = s.id on a.practitioner_id = p.id
      where owner_practitioner_id = #{practitionerId,jdbcType=BIGINT}
        and a.current_year= #{year,jdbcType=INTEGER}
        and a.is_active = 1
        and a.goals_type = 1
        and a.statistic_time_unit = 3
    </select>
</mapper>