<?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.product.ProductPlanMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.product.ProductPlan">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="insurer_id" jdbcType="BIGINT" property="insurerId" />
    <result column="product_id" jdbcType="BIGINT" property="productId" />
    <result column="plan_code" jdbcType="VARCHAR" property="planCode" />
    <result column="contract_id" jdbcType="VARCHAR" property="contractId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="name_sub" jdbcType="VARCHAR" property="nameSub" />
    <result column="name_en" jdbcType="VARCHAR" property="nameEn" />
    <result column="level" jdbcType="INTEGER" property="level" />
    <result column="commision_rate" jdbcType="DECIMAL" property="commisionRate" />
    <result column="referral_rate" jdbcType="DECIMAL" property="referralRate" />
    <result column="sale_price" jdbcType="DECIMAL" property="salePrice" />
    <result column="effective_start_date" jdbcType="DATE" property="effectiveStartDate" />
    <result column="effective_end_date" jdbcType="DATE" property="effectiveEndDate" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="is_global" jdbcType="INTEGER" property="isGlobal" />
    <result column="continent_id" jdbcType="BIGINT" property="continentId" />
    <result column="country_id" jdbcType="BIGINT" property="countryId" />
    <result column="region_id" jdbcType="BIGINT" property="regionId" />
    <result column="is_popular" jdbcType="INTEGER" property="isPopular" />
    <result column="sales_count" jdbcType="INTEGER" property="salesCount" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="is_social_insured" jdbcType="INTEGER" property="isSocialInsured" />
    <result column="app_gender" jdbcType="INTEGER" property="appGender" />
    <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, insurer_id, product_id, plan_code, contract_id, `name`, name_sub, name_en, `level`, 
    commision_rate, referral_rate, sale_price, effective_start_date, effective_end_date, 
    is_active, is_global, continent_id, country_id, region_id, is_popular, sales_count, 
    version, is_social_insured, app_gender, 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_product_plan
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_product_plan
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.product.ProductPlan" useGeneratedKeys="true">
    insert into ag_product_plan (insurer_id, product_id, plan_code, 
      contract_id, `name`, name_sub, 
      name_en, `level`, commision_rate, 
      referral_rate, sale_price, effective_start_date, 
      effective_end_date, is_active, is_global, 
      continent_id, country_id, region_id, 
      is_popular, sales_count, version, 
      is_social_insured, app_gender, created_at, 
      created_by, updated_at, updated_by
      )
    values (#{insurerId,jdbcType=BIGINT}, #{productId,jdbcType=BIGINT}, #{planCode,jdbcType=VARCHAR}, 
      #{contractId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{nameSub,jdbcType=VARCHAR}, 
      #{nameEn,jdbcType=VARCHAR}, #{level,jdbcType=INTEGER}, #{commisionRate,jdbcType=DECIMAL}, 
      #{referralRate,jdbcType=DECIMAL}, #{salePrice,jdbcType=DECIMAL}, #{effectiveStartDate,jdbcType=DATE}, 
      #{effectiveEndDate,jdbcType=DATE}, #{isActive,jdbcType=INTEGER}, #{isGlobal,jdbcType=INTEGER}, 
      #{continentId,jdbcType=BIGINT}, #{countryId,jdbcType=BIGINT}, #{regionId,jdbcType=BIGINT}, 
      #{isPopular,jdbcType=INTEGER}, #{salesCount,jdbcType=INTEGER}, #{version,jdbcType=INTEGER}, 
      #{isSocialInsured,jdbcType=INTEGER}, #{appGender,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.product.ProductPlan" useGeneratedKeys="true">
    insert into ag_product_plan
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="insurerId != null">
        insurer_id,
      </if>
      <if test="productId != null">
        product_id,
      </if>
      <if test="planCode != null">
        plan_code,
      </if>
      <if test="contractId != null">
        contract_id,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="nameSub != null">
        name_sub,
      </if>
      <if test="nameEn != null">
        name_en,
      </if>
      <if test="level != null">
        `level`,
      </if>
      <if test="commisionRate != null">
        commision_rate,
      </if>
      <if test="referralRate != null">
        referral_rate,
      </if>
      <if test="salePrice != null">
        sale_price,
      </if>
      <if test="effectiveStartDate != null">
        effective_start_date,
      </if>
      <if test="effectiveEndDate != null">
        effective_end_date,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="isGlobal != null">
        is_global,
      </if>
      <if test="continentId != null">
        continent_id,
      </if>
      <if test="countryId != null">
        country_id,
      </if>
      <if test="regionId != null">
        region_id,
      </if>
      <if test="isPopular != null">
        is_popular,
      </if>
      <if test="salesCount != null">
        sales_count,
      </if>
      <if test="version != null">
        version,
      </if>
      <if test="isSocialInsured != null">
        is_social_insured,
      </if>
      <if test="appGender != null">
        app_gender,
      </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="insurerId != null">
        #{insurerId,jdbcType=BIGINT},
      </if>
      <if test="productId != null">
        #{productId,jdbcType=BIGINT},
      </if>
      <if test="planCode != null">
        #{planCode,jdbcType=VARCHAR},
      </if>
      <if test="contractId != null">
        #{contractId,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="nameSub != null">
        #{nameSub,jdbcType=VARCHAR},
      </if>
      <if test="nameEn != null">
        #{nameEn,jdbcType=VARCHAR},
      </if>
      <if test="level != null">
        #{level,jdbcType=INTEGER},
      </if>
      <if test="commisionRate != null">
        #{commisionRate,jdbcType=DECIMAL},
      </if>
      <if test="referralRate != null">
        #{referralRate,jdbcType=DECIMAL},
      </if>
      <if test="salePrice != null">
        #{salePrice,jdbcType=DECIMAL},
      </if>
      <if test="effectiveStartDate != null">
        #{effectiveStartDate,jdbcType=DATE},
      </if>
      <if test="effectiveEndDate != null">
        #{effectiveEndDate,jdbcType=DATE},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="isGlobal != null">
        #{isGlobal,jdbcType=INTEGER},
      </if>
      <if test="continentId != null">
        #{continentId,jdbcType=BIGINT},
      </if>
      <if test="countryId != null">
        #{countryId,jdbcType=BIGINT},
      </if>
      <if test="regionId != null">
        #{regionId,jdbcType=BIGINT},
      </if>
      <if test="isPopular != null">
        #{isPopular,jdbcType=INTEGER},
      </if>
      <if test="salesCount != null">
        #{salesCount,jdbcType=INTEGER},
      </if>
      <if test="version != null">
        #{version,jdbcType=INTEGER},
      </if>
      <if test="isSocialInsured != null">
        #{isSocialInsured,jdbcType=INTEGER},
      </if>
      <if test="appGender != null">
        #{appGender,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.product.ProductPlan">
    update ag_product_plan
    <set>
      <if test="insurerId != null">
        insurer_id = #{insurerId,jdbcType=BIGINT},
      </if>
      <if test="productId != null">
        product_id = #{productId,jdbcType=BIGINT},
      </if>
      <if test="planCode != null">
        plan_code = #{planCode,jdbcType=VARCHAR},
      </if>
      <if test="contractId != null">
        contract_id = #{contractId,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="nameSub != null">
        name_sub = #{nameSub,jdbcType=VARCHAR},
      </if>
      <if test="nameEn != null">
        name_en = #{nameEn,jdbcType=VARCHAR},
      </if>
      <if test="level != null">
        `level` = #{level,jdbcType=INTEGER},
      </if>
      <if test="commisionRate != null">
        commision_rate = #{commisionRate,jdbcType=DECIMAL},
      </if>
      <if test="referralRate != null">
        referral_rate = #{referralRate,jdbcType=DECIMAL},
      </if>
      <if test="salePrice != null">
        sale_price = #{salePrice,jdbcType=DECIMAL},
      </if>
      <if test="effectiveStartDate != null">
        effective_start_date = #{effectiveStartDate,jdbcType=DATE},
      </if>
      <if test="effectiveEndDate != null">
        effective_end_date = #{effectiveEndDate,jdbcType=DATE},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="isGlobal != null">
        is_global = #{isGlobal,jdbcType=INTEGER},
      </if>
      <if test="continentId != null">
        continent_id = #{continentId,jdbcType=BIGINT},
      </if>
      <if test="countryId != null">
        country_id = #{countryId,jdbcType=BIGINT},
      </if>
      <if test="regionId != null">
        region_id = #{regionId,jdbcType=BIGINT},
      </if>
      <if test="isPopular != null">
        is_popular = #{isPopular,jdbcType=INTEGER},
      </if>
      <if test="salesCount != null">
        sales_count = #{salesCount,jdbcType=INTEGER},
      </if>
      <if test="version != null">
        version = #{version,jdbcType=INTEGER},
      </if>
      <if test="isSocialInsured != null">
        is_social_insured = #{isSocialInsured,jdbcType=INTEGER},
      </if>
      <if test="appGender != null">
        app_gender = #{appGender,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.product.ProductPlan">
    update ag_product_plan
    set insurer_id = #{insurerId,jdbcType=BIGINT},
      product_id = #{productId,jdbcType=BIGINT},
      plan_code = #{planCode,jdbcType=VARCHAR},
      contract_id = #{contractId,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      name_sub = #{nameSub,jdbcType=VARCHAR},
      name_en = #{nameEn,jdbcType=VARCHAR},
      `level` = #{level,jdbcType=INTEGER},
      commision_rate = #{commisionRate,jdbcType=DECIMAL},
      referral_rate = #{referralRate,jdbcType=DECIMAL},
      sale_price = #{salePrice,jdbcType=DECIMAL},
      effective_start_date = #{effectiveStartDate,jdbcType=DATE},
      effective_end_date = #{effectiveEndDate,jdbcType=DATE},
      is_active = #{isActive,jdbcType=INTEGER},
      is_global = #{isGlobal,jdbcType=INTEGER},
      continent_id = #{continentId,jdbcType=BIGINT},
      country_id = #{countryId,jdbcType=BIGINT},
      region_id = #{regionId,jdbcType=BIGINT},
      is_popular = #{isPopular,jdbcType=INTEGER},
      sales_count = #{salesCount,jdbcType=INTEGER},
      version = #{version,jdbcType=INTEGER},
      is_social_insured = #{isSocialInsured,jdbcType=INTEGER},
      app_gender = #{appGender,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="findAll" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_product_plan
    where is_active is not null
  </select>
</mapper>