<?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.CustomRightsSettingItemMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomRightsSettingItem" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="custom_rights_setting_id" property="customRightsSettingId" jdbcType="BIGINT" />
    <result column="rights_setting_classify_id" property="rightsSettingClassifyId" jdbcType="BIGINT" />
    <result column="item_title" property="itemTitle" jdbcType="VARCHAR" />
    <result column="description" property="description" 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_id, rights_setting_classify_id, item_title, description, 
    create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from custom_rights_setting_item
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from custom_rights_setting_item
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByPlanId" parameterType="integer">
    DELETE cs
    FROM
    custom_rights_setting_item cs
    RIGHT JOIN (
    SELECT
    cr.id
    FROM
    custom_rights_setting_item cr
    LEFT JOIN custom_plan_rights_setting cp ON cr.custom_rights_setting_id = cp.id
    WHERE
    cp.custom_plan_id = #{planId}
    ) m ON cs.id = m.id
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.custom.entity.CustomRightsSettingItem" useGeneratedKeys="true" keyProperty="id" >
    insert into custom_rights_setting_item (custom_rights_setting_id, rights_setting_classify_id,
      item_title, create_time,
      update_time)
    values (#{customRightsSettingId,jdbcType=BIGINT}, #{rightsSettingClassifyId,jdbcType=BIGINT},
      #{itemTitle,jdbcType=VARCHAR}, now(), now())
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.custom.entity.CustomRightsSettingItem" >
    insert into custom_rights_setting_item
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="customRightsSettingId != null" >
        custom_rights_setting_id,
      </if>
      <if test="rightsSettingClassifyId != null" >
        rights_setting_classify_id,
      </if>
      <if test="itemTitle != null" >
        item_title,
      </if>
      <if test="description != null" >
        description,
      </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="customRightsSettingId != null" >
        #{customRightsSettingId,jdbcType=BIGINT},
      </if>
      <if test="rightsSettingClassifyId != null" >
        #{rightsSettingClassifyId,jdbcType=BIGINT},
      </if>
      <if test="itemTitle != null" >
        #{itemTitle,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.custom.entity.CustomRightsSettingItem" >
    update custom_rights_setting_item
    <set >
      <if test="customRightsSettingId != null" >
        custom_rights_setting_id = #{customRightsSettingId,jdbcType=BIGINT},
      </if>
      <if test="rightsSettingClassifyId != null" >
        rights_setting_classify_id = #{rightsSettingClassifyId,jdbcType=BIGINT},
      </if>
      <if test="itemTitle != null" >
        item_title = #{itemTitle,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        description = #{description,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.CustomRightsSettingItem" >
    update custom_rights_setting_item
    set custom_rights_setting_id = #{customRightsSettingId,jdbcType=BIGINT},
      rights_setting_classify_id = #{rightsSettingClassifyId,jdbcType=BIGINT},
      item_title = #{itemTitle,jdbcType=VARCHAR},
      description = #{description,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>