<?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.pcloud.book.custom.mapper.CustomRightsItemDescriptionMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomRightsItemDescription" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="custom_rights_setting_item_id" property="customRightsSettingItemId" jdbcType="BIGINT" />
    <result column="descripiton" property="descripiton" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, custom_rights_setting_item_id, descripiton, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from custom_rights_item_description
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from custom_rights_item_description
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByPlanId">
    DELETE cd
    FROM
    custom_rights_item_description  cd
    RIGHT JOIN (
    SELECT
    crid.id
    FROM
    custom_rights_item_description crid
    left join
    custom_rights_setting_item cr on crid.custom_rights_setting_item_id = cr.id
    LEFT JOIN custom_plan_rights_setting cp ON cr.custom_rights_setting_id = cp.id
    WHERE
    cp.custom_plan_id = #{planId}
    ) m ON cd.id = m.id
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.custom.entity.CustomRightsItemDescription" >
    insert into custom_rights_item_description (id, custom_rights_setting_item_id, descripiton, 
      create_time, update_time)
    values (#{id,jdbcType=BIGINT}, #{customRightsSettingItemId,jdbcType=BIGINT}, #{descripiton,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.custom.entity.CustomRightsItemDescription" >
    insert into custom_rights_item_description
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="customRightsSettingItemId != null" >
        custom_rights_setting_item_id,
      </if>
      <if test="descripiton != null" >
        descripiton,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="customRightsSettingItemId != null" >
        #{customRightsSettingItemId,jdbcType=BIGINT},
      </if>
      <if test="descripiton != null" >
        #{descripiton,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <insert id="batchInsert" parameterType="com.pcloud.book.custom.entity.CustomRightsItemDescription">
    insert into custom_rights_item_description (custom_rights_setting_item_id, descripiton,
    create_time, update_time)
    values
    <foreach collection="list" index="index" item="item"  separator=",">
    (#{item.customRightsSettingItemId,jdbcType=BIGINT}, #{item.descripiton,jdbcType=VARCHAR},
    now(), now())
    </foreach>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.custom.entity.CustomRightsItemDescription" >
    update custom_rights_item_description
    <set >
      <if test="customRightsSettingItemId != null" >
        custom_rights_setting_item_id = #{customRightsSettingItemId,jdbcType=BIGINT},
      </if>
      <if test="descripiton != null" >
        descripiton = #{descripiton,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.custom.entity.CustomRightsItemDescription" >
    update custom_rights_item_description
    set custom_rights_setting_item_id = #{customRightsSettingItemId,jdbcType=BIGINT},
      descripiton = #{descripiton,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>