<?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.riddle.dao.impl.RiddleCouponDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.riddle.entity.RiddleCoupon" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="pict_url" property="pictUrl" jdbcType="VARCHAR" />
    <result column="zk_final_price" property="zkFinalPrice" jdbcType="DECIMAL" />
    <result column="coupon_price" property="couponPrice" jdbcType="DECIMAL" />
    <result column="after_coupon_price" property="afterCouponPrice" jdbcType="DECIMAL" />
    <result column="coupon_click_url" property="couponClickUrl" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="TINYINT" />
    <result column="create_user" property="createUser" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="status" property="status" jdbcType="BIT" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, title, pict_url, zk_final_price, coupon_price, after_coupon_price, coupon_click_url,
    type, create_user, create_time, update_time, status
  </sql>

  <select id="getByAdviser" resultType="com.pcloud.book.riddle.dto.RiddleCouponDTO" parameterType="java.lang.Long" >
    select 
    id id,
    title title,
    pict_url  pictUrl,
    zk_final_price  zkFinalPrice,
    coupon_price  couponPrice,
    after_coupon_price  afterCouponPrice,
    coupon_click_url  couponClickUrl,
    type  type,
    status  status
    from riddle_coupon
    where create_user = #{createUser,jdbcType=BIGINT}
  </select>

  <insert id="insert" parameterType="com.pcloud.book.riddle.entity.RiddleCoupon" useGeneratedKeys="true" keyProperty="id">
    insert into riddle_coupon ( title, pict_url,
      zk_final_price, coupon_price, after_coupon_price,
      coupon_click_url, type, create_user,
      create_time, update_time, status
      )
    values ( #{title,jdbcType=VARCHAR}, #{pictUrl,jdbcType=VARCHAR},
      #{zkFinalPrice,jdbcType=DECIMAL}, #{couponPrice,jdbcType=DECIMAL}, #{afterCouponPrice,jdbcType=DECIMAL},
      #{couponClickUrl,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{createUser,jdbcType=BIGINT},
      NOW(), NOW(), #{status}
      )
  </insert>

  <update id="update" parameterType="com.pcloud.book.riddle.entity.RiddleCoupon" >
    update riddle_coupon
    <set >
      <if test="title != null" >
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="pictUrl != null" >
        pict_url = #{pictUrl,jdbcType=VARCHAR},
      </if>
      <if test="zkFinalPrice != null" >
        zk_final_price = #{zkFinalPrice,jdbcType=DECIMAL},
      </if>
      <if test="couponPrice != null" >
        coupon_price = #{couponPrice,jdbcType=DECIMAL},
      </if>
      <if test="afterCouponPrice != null" >
        after_coupon_price = #{afterCouponPrice,jdbcType=DECIMAL},
      </if>
      <if test="couponClickUrl != null" >
        coupon_click_url = #{couponClickUrl,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        type = #{type,jdbcType=TINYINT},
      </if>
        update_time = NOW(),
      <if test="status != null" >
        status = #{status,jdbcType=BIT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

  <delete id="deleteByAdviser" parameterType="long">
    DELETE  FROM riddle_coupon
    WHERE create_user = #{createUser,jdbcType=BIGINT}
  </delete>

</mapper>