<?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.weixinclock.dao.impl.WeixinClockCouponDaoImpl" >
    <resultMap id="BaseResultMap" type="com.pcloud.book.weixinclock.entity.WeixinClockCoupon" >
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="weixin_clock_id" property="weixinClockId" jdbcType="BIGINT"/>
        <result column="coupon_platform" property="couponPlatform" jdbcType="INTEGER" />
        <result column="title" property="title" jdbcType="VARCHAR" />
        <result column="pict_url" property="pictUrl" jdbcType="VARCHAR" />
        <result column="pro_origin_price" property="proOriginPrice" 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="day_num" property="dayNum" jdbcType="INTEGER"/>
        <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" />
    </resultMap>
    
    <sql id="Base_Column_List">
        id, weixin_clock_id, coupon_platform, title, pict_url, pro_origin_price, coupon_price, after_coupon_price, coupon_click_url, day_num,
        create_user, create_time, update_user, update_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.weixinclock.entity.WeixinClockCoupon" keyProperty="id" useGeneratedKeys="true">
        insert into weixin_clock_coupon(weixin_clock_id, coupon_platform, title, pict_url,
                                        pro_origin_price, coupon_price,
                                        after_coupon_price, coupon_click_url, day_num,
                                        create_user, create_time, update_user, update_time)
        values (#{weixinClockId}, #{couponPlatform}, #{title}, #{pictUrl},
                #{proOriginPrice}, #{couponPrice},
                #{afterCouponPrice}, #{couponClickUrl}, #{dayNum},
                #{createUser}, now(), #{updateUser}, now())
    </insert>

    <update id="update" parameterType="com.pcloud.book.weixinclock.entity.WeixinClockCoupon">
        update weixin_clock_coupon
        <set >
            <if test="couponPlatform != null">
                coupon_platform = #{couponPlatform},
            </if>
            <if test="title != null" >
                title = #{title,jdbcType=VARCHAR},
            </if>
            <if test="pictUrl != null" >
                pict_url = #{pictUrl,jdbcType=VARCHAR},
            </if>
            <if test="proOriginPrice != null" >
                pro_origin_price = #{proOriginPrice,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="dayNum != null">
                day_num = #{dayNum},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser},
            </if>
            update_time = NOW()
        </set>
        where id = #{id}
    </update>

    <select id="getBaseById" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from weixin_clock_coupon where id = #{id}
    </select>

    <select id="getBaseByClockId" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from weixin_clock_coupon where weixin_clock_id = #{weixinClockId}
    </select>

    <select id="getByClockIds" parameterType="list" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from weixin_clock_coupon where weixin_clock_id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>
</mapper>