<?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.AclCustomerShareMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclCustomerShare">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="config_level" jdbcType="INTEGER" property="configLevel" />
    <result column="product_id" jdbcType="BIGINT" property="productId" />
    <result column="plan_id" jdbcType="BIGINT" property="planId" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="share_code" jdbcType="VARCHAR" property="shareCode" />
    <result column="customer_id" jdbcType="BIGINT" property="customerId" />
    <result column="account_id" jdbcType="VARCHAR" property="accountId" />
    <result column="destination_type" jdbcType="INTEGER" property="destinationType" />
    <result column="destination_id" jdbcType="BIGINT" property="destinationId" />
    <result column="share_type" jdbcType="INTEGER" property="shareType" />
    <result column="os" jdbcType="INTEGER" property="os" />
    <result column="channel" jdbcType="INTEGER" property="channel" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="json_params" jdbcType="VARCHAR" property="jsonParams" />
    <result column="json_params_coverage_info" jdbcType="VARCHAR" property="jsonParamsCoverageInfo" />
    <result column="is_order" jdbcType="BIGINT" property="isOrder" />
    <result column="effective_start_date" jdbcType="TIMESTAMP" property="effectiveStartDate" />
    <result column="effective_end_date" jdbcType="TIMESTAMP" property="effectiveEndDate" />
    <result column="adult_count" jdbcType="INTEGER" property="adultCount" />
    <result column="child_count" jdbcType="INTEGER" property="childCount" />
    <result column="eld_count" jdbcType="INTEGER" property="eldCount" />
    <result column="day_count" jdbcType="INTEGER" property="dayCount" />
    <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" />
    <result column="level_code_for_building" jdbcType="VARCHAR" property="levelCodeForBuilding" />
  </resultMap>
  <sql id="Base_Column_List">
    id, config_level, product_id, plan_id, order_id, share_code, customer_id, account_id, 
    destination_type, destination_id, share_type, os, channel, url, json_params, json_params_coverage_info, 
    is_order, effective_start_date, effective_end_date, adult_count, child_count, eld_count, 
    day_count, created_at, created_by, updated_at, updated_by, level_code_for_building
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ag_acl_customer_share
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_acl_customer_share
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerShare" useGeneratedKeys="true">
    insert into ag_acl_customer_share (config_level, product_id, plan_id, 
      order_id, share_code, customer_id, 
      account_id, destination_type, destination_id, 
      share_type, os, channel, 
      url, json_params, json_params_coverage_info, 
      is_order, effective_start_date, effective_end_date, 
      adult_count, child_count, eld_count, 
      day_count, created_at, created_by, 
      updated_at, updated_by, level_code_for_building
      )
    values (#{configLevel,jdbcType=INTEGER}, #{productId,jdbcType=BIGINT}, #{planId,jdbcType=BIGINT}, 
      #{orderId,jdbcType=BIGINT}, #{shareCode,jdbcType=VARCHAR}, #{customerId,jdbcType=BIGINT}, 
      #{accountId,jdbcType=VARCHAR}, #{destinationType,jdbcType=INTEGER}, #{destinationId,jdbcType=BIGINT}, 
      #{shareType,jdbcType=INTEGER}, #{os,jdbcType=INTEGER}, #{channel,jdbcType=INTEGER}, 
      #{url,jdbcType=VARCHAR}, #{jsonParams,jdbcType=VARCHAR}, #{jsonParamsCoverageInfo,jdbcType=VARCHAR}, 
      #{isOrder,jdbcType=BIGINT}, #{effectiveStartDate,jdbcType=TIMESTAMP}, #{effectiveEndDate,jdbcType=TIMESTAMP}, 
      #{adultCount,jdbcType=INTEGER}, #{childCount,jdbcType=INTEGER}, #{eldCount,jdbcType=INTEGER}, 
      #{dayCount,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{updatedAt,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=BIGINT}, #{levelCodeForBuilding,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerShare" useGeneratedKeys="true">
    insert into ag_acl_customer_share
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="configLevel != null">
        config_level,
      </if>
      <if test="productId != null">
        product_id,
      </if>
      <if test="planId != null">
        plan_id,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="shareCode != null">
        share_code,
      </if>
      <if test="customerId != null">
        customer_id,
      </if>
      <if test="accountId != null">
        account_id,
      </if>
      <if test="destinationType != null">
        destination_type,
      </if>
      <if test="destinationId != null">
        destination_id,
      </if>
      <if test="shareType != null">
        share_type,
      </if>
      <if test="os != null">
        os,
      </if>
      <if test="channel != null">
        channel,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="jsonParams != null">
        json_params,
      </if>
      <if test="jsonParamsCoverageInfo != null">
        json_params_coverage_info,
      </if>
      <if test="isOrder != null">
        is_order,
      </if>
      <if test="effectiveStartDate != null">
        effective_start_date,
      </if>
      <if test="effectiveEndDate != null">
        effective_end_date,
      </if>
      <if test="adultCount != null">
        adult_count,
      </if>
      <if test="childCount != null">
        child_count,
      </if>
      <if test="eldCount != null">
        eld_count,
      </if>
      <if test="dayCount != null">
        day_count,
      </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>
      <if test="levelCodeForBuilding != null">
        level_code_for_building,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="configLevel != null">
        #{configLevel,jdbcType=INTEGER},
      </if>
      <if test="productId != null">
        #{productId,jdbcType=BIGINT},
      </if>
      <if test="planId != null">
        #{planId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="shareCode != null">
        #{shareCode,jdbcType=VARCHAR},
      </if>
      <if test="customerId != null">
        #{customerId,jdbcType=BIGINT},
      </if>
      <if test="accountId != null">
        #{accountId,jdbcType=VARCHAR},
      </if>
      <if test="destinationType != null">
        #{destinationType,jdbcType=INTEGER},
      </if>
      <if test="destinationId != null">
        #{destinationId,jdbcType=BIGINT},
      </if>
      <if test="shareType != null">
        #{shareType,jdbcType=INTEGER},
      </if>
      <if test="os != null">
        #{os,jdbcType=INTEGER},
      </if>
      <if test="channel != null">
        #{channel,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="jsonParams != null">
        #{jsonParams,jdbcType=VARCHAR},
      </if>
      <if test="jsonParamsCoverageInfo != null">
        #{jsonParamsCoverageInfo,jdbcType=VARCHAR},
      </if>
      <if test="isOrder != null">
        #{isOrder,jdbcType=BIGINT},
      </if>
      <if test="effectiveStartDate != null">
        #{effectiveStartDate,jdbcType=TIMESTAMP},
      </if>
      <if test="effectiveEndDate != null">
        #{effectiveEndDate,jdbcType=TIMESTAMP},
      </if>
      <if test="adultCount != null">
        #{adultCount,jdbcType=INTEGER},
      </if>
      <if test="childCount != null">
        #{childCount,jdbcType=INTEGER},
      </if>
      <if test="eldCount != null">
        #{eldCount,jdbcType=INTEGER},
      </if>
      <if test="dayCount != null">
        #{dayCount,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>
      <if test="levelCodeForBuilding != null">
        #{levelCodeForBuilding,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.customer.AclCustomerShare">
    update ag_acl_customer_share
    <set>
      <if test="configLevel != null">
        config_level = #{configLevel,jdbcType=INTEGER},
      </if>
      <if test="productId != null">
        product_id = #{productId,jdbcType=BIGINT},
      </if>
      <if test="planId != null">
        plan_id = #{planId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="shareCode != null">
        share_code = #{shareCode,jdbcType=VARCHAR},
      </if>
      <if test="customerId != null">
        customer_id = #{customerId,jdbcType=BIGINT},
      </if>
      <if test="accountId != null">
        account_id = #{accountId,jdbcType=VARCHAR},
      </if>
      <if test="destinationType != null">
        destination_type = #{destinationType,jdbcType=INTEGER},
      </if>
      <if test="destinationId != null">
        destination_id = #{destinationId,jdbcType=BIGINT},
      </if>
      <if test="shareType != null">
        share_type = #{shareType,jdbcType=INTEGER},
      </if>
      <if test="os != null">
        os = #{os,jdbcType=INTEGER},
      </if>
      <if test="channel != null">
        channel = #{channel,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="jsonParams != null">
        json_params = #{jsonParams,jdbcType=VARCHAR},
      </if>
      <if test="jsonParamsCoverageInfo != null">
        json_params_coverage_info = #{jsonParamsCoverageInfo,jdbcType=VARCHAR},
      </if>
      <if test="isOrder != null">
        is_order = #{isOrder,jdbcType=BIGINT},
      </if>
      <if test="effectiveStartDate != null">
        effective_start_date = #{effectiveStartDate,jdbcType=TIMESTAMP},
      </if>
      <if test="effectiveEndDate != null">
        effective_end_date = #{effectiveEndDate,jdbcType=TIMESTAMP},
      </if>
      <if test="adultCount != null">
        adult_count = #{adultCount,jdbcType=INTEGER},
      </if>
      <if test="childCount != null">
        child_count = #{childCount,jdbcType=INTEGER},
      </if>
      <if test="eldCount != null">
        eld_count = #{eldCount,jdbcType=INTEGER},
      </if>
      <if test="dayCount != null">
        day_count = #{dayCount,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>
      <if test="levelCodeForBuilding != null">
        level_code_for_building = #{levelCodeForBuilding,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.customer.AclCustomerShare">
    update ag_acl_customer_share
    set config_level = #{configLevel,jdbcType=INTEGER},
      product_id = #{productId,jdbcType=BIGINT},
      plan_id = #{planId,jdbcType=BIGINT},
      order_id = #{orderId,jdbcType=BIGINT},
      share_code = #{shareCode,jdbcType=VARCHAR},
      customer_id = #{customerId,jdbcType=BIGINT},
      account_id = #{accountId,jdbcType=VARCHAR},
      destination_type = #{destinationType,jdbcType=INTEGER},
      destination_id = #{destinationId,jdbcType=BIGINT},
      share_type = #{shareType,jdbcType=INTEGER},
      os = #{os,jdbcType=INTEGER},
      channel = #{channel,jdbcType=INTEGER},
      url = #{url,jdbcType=VARCHAR},
      json_params = #{jsonParams,jdbcType=VARCHAR},
      json_params_coverage_info = #{jsonParamsCoverageInfo,jdbcType=VARCHAR},
      is_order = #{isOrder,jdbcType=BIGINT},
      effective_start_date = #{effectiveStartDate,jdbcType=TIMESTAMP},
      effective_end_date = #{effectiveEndDate,jdbcType=TIMESTAMP},
      adult_count = #{adultCount,jdbcType=INTEGER},
      child_count = #{childCount,jdbcType=INTEGER},
      eld_count = #{eldCount,jdbcType=INTEGER},
      day_count = #{dayCount,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=BIGINT},
      level_code_for_building = #{levelCodeForBuilding,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
    <select id="findByCustomerIdAndInsurerId" resultMap="BaseResultMap">
      select
        <include refid="Base_Column_List" />
      from ag_acl_customer_share
      where
        customer_id = #{customerId}
      and
        plan_id in (SELECT id FROM ag_product_plan WHERE insurer_id = #{insurerId} )
    </select>
</mapper>