<?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.ProductMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.product.Product">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="insurer_id" jdbcType="BIGINT" property="insurerId" />
    <result column="insurer_name" jdbcType="VARCHAR" property="insurerName" />
    <result column="insurer_branch_id" jdbcType="BIGINT" property="insurerBranchId" />
    <result column="product_category_id" jdbcType="BIGINT" property="productCategoryId" />
    <result column="no" jdbcType="VARCHAR" property="no" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="name_en" jdbcType="VARCHAR" property="nameEn" />
    <result column="description" jdbcType="VARCHAR" property="description" />
    <result column="effective_start_date" jdbcType="DATE" property="effectiveStartDate" />
    <result column="effective_end_date" jdbcType="DATE" property="effectiveEndDate" />
    <result column="sale_price" jdbcType="DECIMAL" property="salePrice" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="policy_eff_count" jdbcType="INTEGER" property="policyEffCount" />
    <result column="policy_eff_count_unit" jdbcType="VARCHAR" property="policyEffCountUnit" />
    <result column="min_cover_term" jdbcType="INTEGER" property="minCoverTerm" />
    <result column="min_cover_term_unit" jdbcType="VARCHAR" property="minCoverTermUnit" />
    <result column="hesitate_peroid" jdbcType="INTEGER" property="hesitatePeroid" />
    <result column="ui_display_unit" jdbcType="VARCHAR" property="uiDisplayUnit" />
    <result column="article_url" jdbcType="VARCHAR" property="articleUrl" />
    <result column="is_pay_to_yd" jdbcType="INTEGER" property="isPayToYd" />
    <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, insurer_name, insurer_branch_id, product_category_id, `no`, `name`, 
    name_en, description, effective_start_date, effective_end_date, sale_price, is_active, 
    policy_eff_count, policy_eff_count_unit, min_cover_term, min_cover_term_unit, hesitate_peroid, 
    ui_display_unit, article_url, is_pay_to_yd, 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
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_product
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.product.Product" useGeneratedKeys="true">
    insert into ag_product (insurer_id, insurer_name, insurer_branch_id, 
      product_category_id, `no`, `name`, 
      name_en, description, effective_start_date, 
      effective_end_date, sale_price, is_active, 
      policy_eff_count, policy_eff_count_unit, min_cover_term, 
      min_cover_term_unit, hesitate_peroid, ui_display_unit, 
      article_url, is_pay_to_yd, created_at, 
      created_by, updated_at, updated_by
      )
    values (#{insurerId,jdbcType=BIGINT}, #{insurerName,jdbcType=VARCHAR}, #{insurerBranchId,jdbcType=BIGINT}, 
      #{productCategoryId,jdbcType=BIGINT}, #{no,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{nameEn,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{effectiveStartDate,jdbcType=DATE}, 
      #{effectiveEndDate,jdbcType=DATE}, #{salePrice,jdbcType=DECIMAL}, #{isActive,jdbcType=INTEGER}, 
      #{policyEffCount,jdbcType=INTEGER}, #{policyEffCountUnit,jdbcType=VARCHAR}, #{minCoverTerm,jdbcType=INTEGER}, 
      #{minCoverTermUnit,jdbcType=VARCHAR}, #{hesitatePeroid,jdbcType=INTEGER}, #{uiDisplayUnit,jdbcType=VARCHAR}, 
      #{articleUrl,jdbcType=VARCHAR}, #{isPayToYd,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.Product" useGeneratedKeys="true">
    insert into ag_product
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="insurerId != null">
        insurer_id,
      </if>
      <if test="insurerName != null">
        insurer_name,
      </if>
      <if test="insurerBranchId != null">
        insurer_branch_id,
      </if>
      <if test="productCategoryId != null">
        product_category_id,
      </if>
      <if test="no != null">
        `no`,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="nameEn != null">
        name_en,
      </if>
      <if test="description != null">
        description,
      </if>
      <if test="effectiveStartDate != null">
        effective_start_date,
      </if>
      <if test="effectiveEndDate != null">
        effective_end_date,
      </if>
      <if test="salePrice != null">
        sale_price,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="policyEffCount != null">
        policy_eff_count,
      </if>
      <if test="policyEffCountUnit != null">
        policy_eff_count_unit,
      </if>
      <if test="minCoverTerm != null">
        min_cover_term,
      </if>
      <if test="minCoverTermUnit != null">
        min_cover_term_unit,
      </if>
      <if test="hesitatePeroid != null">
        hesitate_peroid,
      </if>
      <if test="uiDisplayUnit != null">
        ui_display_unit,
      </if>
      <if test="articleUrl != null">
        article_url,
      </if>
      <if test="isPayToYd != null">
        is_pay_to_yd,
      </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="insurerName != null">
        #{insurerName,jdbcType=VARCHAR},
      </if>
      <if test="insurerBranchId != null">
        #{insurerBranchId,jdbcType=BIGINT},
      </if>
      <if test="productCategoryId != null">
        #{productCategoryId,jdbcType=BIGINT},
      </if>
      <if test="no != null">
        #{no,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="nameEn != null">
        #{nameEn,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="effectiveStartDate != null">
        #{effectiveStartDate,jdbcType=DATE},
      </if>
      <if test="effectiveEndDate != null">
        #{effectiveEndDate,jdbcType=DATE},
      </if>
      <if test="salePrice != null">
        #{salePrice,jdbcType=DECIMAL},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="policyEffCount != null">
        #{policyEffCount,jdbcType=INTEGER},
      </if>
      <if test="policyEffCountUnit != null">
        #{policyEffCountUnit,jdbcType=VARCHAR},
      </if>
      <if test="minCoverTerm != null">
        #{minCoverTerm,jdbcType=INTEGER},
      </if>
      <if test="minCoverTermUnit != null">
        #{minCoverTermUnit,jdbcType=VARCHAR},
      </if>
      <if test="hesitatePeroid != null">
        #{hesitatePeroid,jdbcType=INTEGER},
      </if>
      <if test="uiDisplayUnit != null">
        #{uiDisplayUnit,jdbcType=VARCHAR},
      </if>
      <if test="articleUrl != null">
        #{articleUrl,jdbcType=VARCHAR},
      </if>
      <if test="isPayToYd != null">
        #{isPayToYd,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.Product">
    update ag_product
    <set>
      <if test="insurerId != null">
        insurer_id = #{insurerId,jdbcType=BIGINT},
      </if>
      <if test="insurerName != null">
        insurer_name = #{insurerName,jdbcType=VARCHAR},
      </if>
      <if test="insurerBranchId != null">
        insurer_branch_id = #{insurerBranchId,jdbcType=BIGINT},
      </if>
      <if test="productCategoryId != null">
        product_category_id = #{productCategoryId,jdbcType=BIGINT},
      </if>
      <if test="no != null">
        `no` = #{no,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="nameEn != null">
        name_en = #{nameEn,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        description = #{description,jdbcType=VARCHAR},
      </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="salePrice != null">
        sale_price = #{salePrice,jdbcType=DECIMAL},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="policyEffCount != null">
        policy_eff_count = #{policyEffCount,jdbcType=INTEGER},
      </if>
      <if test="policyEffCountUnit != null">
        policy_eff_count_unit = #{policyEffCountUnit,jdbcType=VARCHAR},
      </if>
      <if test="minCoverTerm != null">
        min_cover_term = #{minCoverTerm,jdbcType=INTEGER},
      </if>
      <if test="minCoverTermUnit != null">
        min_cover_term_unit = #{minCoverTermUnit,jdbcType=VARCHAR},
      </if>
      <if test="hesitatePeroid != null">
        hesitate_peroid = #{hesitatePeroid,jdbcType=INTEGER},
      </if>
      <if test="uiDisplayUnit != null">
        ui_display_unit = #{uiDisplayUnit,jdbcType=VARCHAR},
      </if>
      <if test="articleUrl != null">
        article_url = #{articleUrl,jdbcType=VARCHAR},
      </if>
      <if test="isPayToYd != null">
        is_pay_to_yd = #{isPayToYd,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.Product">
    update ag_product
    set insurer_id = #{insurerId,jdbcType=BIGINT},
      insurer_name = #{insurerName,jdbcType=VARCHAR},
      insurer_branch_id = #{insurerBranchId,jdbcType=BIGINT},
      product_category_id = #{productCategoryId,jdbcType=BIGINT},
      `no` = #{no,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      name_en = #{nameEn,jdbcType=VARCHAR},
      description = #{description,jdbcType=VARCHAR},
      effective_start_date = #{effectiveStartDate,jdbcType=DATE},
      effective_end_date = #{effectiveEndDate,jdbcType=DATE},
      sale_price = #{salePrice,jdbcType=DECIMAL},
      is_active = #{isActive,jdbcType=INTEGER},
      policy_eff_count = #{policyEffCount,jdbcType=INTEGER},
      policy_eff_count_unit = #{policyEffCountUnit,jdbcType=VARCHAR},
      min_cover_term = #{minCoverTerm,jdbcType=INTEGER},
      min_cover_term_unit = #{minCoverTermUnit,jdbcType=VARCHAR},
      hesitate_peroid = #{hesitatePeroid,jdbcType=INTEGER},
      ui_display_unit = #{uiDisplayUnit,jdbcType=VARCHAR},
      article_url = #{articleUrl,jdbcType=VARCHAR},
      is_pay_to_yd = #{isPayToYd,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
      where is_active is not null
    </select>
    <select id="findAllE" resultType="com.yd.dal.entity.product.ProductE">
      select
        t.prd_mst_id as productId,
        t.PRD_MST_PRO_NAME as productName
      from prd001 t
    </select>
</mapper>