<?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.advertising.dao.impl.BmOptionItemDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingBmOptionItem" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="option_id" property="optionId" jdbcType="BIGINT" />
    <result column="parent_id" property="parentId" jdbcType="BIGINT" />
    <result column="text" property="text" jdbcType="VARCHAR" />
    <result column="img_url" property="imgUrl" jdbcType="VARCHAR" />
    <result column="create_user" property="createUser" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="BIGINT" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="jump_url" property="jumpUrl" jdbcType="VARCHAR" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, option_id, parent_id, text, img_url, create_user, create_time, update_user, update_time,jump_url
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingBmOptionItem" useGeneratedKeys="true" keyProperty="id">
    insert into advertising_bm_option_item (option_id, parent_id,
      text, img_url, create_user, create_time,jump_url
      )
    values (#{optionId,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT},
      #{text,jdbcType=VARCHAR}, #{imgUrl,jdbcType=VARCHAR}, #{createUser,jdbcType=BIGINT}, NOW(),#{jumpUrl}
      )
  </insert>

  <!-- 根据选项ID删除选项清单信息 -->
  <delete id="deleteByOptionId" parameterType="java.lang.Long" >
    delete from advertising_bm_option_item
    where option_id = #{id,jdbcType=BIGINT}
  </delete>

  <select id="getByOptionId" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from advertising_bm_option_item
    where option_id = #{optionId,jdbcType=BIGINT} and PARENT_ID=0
  </select>

  <select id="getValueById" resultType="String" parameterType="Long">
    select text
    from advertising_bm_option_item
    where id = #{id,jdbcType=BIGINT}
  </select>

</mapper>