<?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.cyl.manager.marketing.mapper.WechatStockMapper">
    
    <resultMap type="WechatStock" id="WechatStockResult">
        <result property="id" column="id"/>
        <result property="stockName" column="stock_name"/>
        <result property="comment" column="comment"/>
        <result property="goodsName" column="goods_name"/>
        <result property="stockType" column="stock_type"/>
        <result property="availableBeginTime" column="available_begin_time"/>
        <result property="availableEndTime" column="available_end_time"/>
        <result property="availableDayAfterReceive" column="available_day_after_receive"/>
        <result property="discountAmount" column="discount_amount"/>
        <result property="transactionMinimum" column="transaction_minimum"/>
        <result property="discountPercent" column="discount_percent"/>
        <result property="useMethod" column="use_method"/>
        <result property="outRequestNo" column="out_request_no"/>
        <result property="maxCoupons" column="max_coupons"/>
        <result property="maxCouponsPerUser" column="max_coupons_per_user"/>
        <result property="couponCodeMode" column="coupon_code_mode"/>
        <result property="stockState" column="stock_state"/>
        <result property="stockId" column="stock_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>

        <result property="sendType" column="send_type"/>
        <result property="discountType" column="discount_type"/>
        <result property="eventType" column="event_type"/>
    </resultMap>

    <sql id="selectWechatStockVo">
        select id, stock_name, comment, goods_name, stock_type, available_begin_time, available_end_time, available_day_after_receive, discount_amount, transaction_minimum, discount_percent, use_method, out_request_no, max_coupons, max_coupons_per_user, coupon_code_mode, stock_state, stock_id, create_by, create_time, update_by, update_time, send_type, discount_type, event_type from wechat_stock
    </sql>

    <select id="selectList2" parameterType="WechatStock" resultMap="WechatStockResult">
        <include refid="selectWechatStockVo"/>
        <where>  
            <if test="stockName != null  and stockName != ''"> and stock_name like concat('%', #{stockName}, '%')</if>
            <if test="comment != null  and comment != ''"> and comment = #{comment}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="stockType != null  and stockType != ''"> and stock_type = #{stockType}</if>
            <if test="availableBeginTime != null "> and available_begin_time = #{availableBeginTime}</if>
            <if test="availableEndTime != null "> and available_end_time = #{availableEndTime}</if>
            <if test="availableDayAfterReceive != null "> and available_day_after_receive = #{availableDayAfterReceive}</if>
            <if test="discountAmount != null "> and discount_amount = #{discountAmount}</if>
            <if test="transactionMinimum != null "> and transaction_minimum = #{transactionMinimum}</if>
            <if test="discountPercent != null "> and discount_percent = #{discountPercent}</if>
            <if test="useMethod != null  and useMethod != ''"> and use_method = #{useMethod}</if>
            <if test="outRequestNo != null  and outRequestNo != ''"> and out_request_no = #{outRequestNo}</if>
            <if test="maxCoupons != null "> and max_coupons = #{maxCoupons}</if>
            <if test="maxCouponsPerUser != null "> and max_coupons_per_user = #{maxCouponsPerUser}</if>
            <if test="couponCodeMode != null  and couponCodeMode != ''"> and coupon_code_mode = #{couponCodeMode}</if>
            <if test="stockState != null  and stockState != ''"> and stock_state = #{stockState}</if>
            <if test="stockId != null  and stockId != ''"> and stock_id = #{stockId}</if>

            <if test="sendType != null  and sendType != ''"> and send_type = #{sendType}</if>
            <if test="discountType != null  and discountType != ''"> and discount_type = #{discountType}</if>
            <if test="eventType != null  and eventType != ''"> and event_type = #{eventType}</if>
        </where>
    </select>
    
    <select id="selectById" parameterType="Long" resultMap="WechatStockResult">
        <include refid="selectWechatStockVo"/>
        where id = #{id}
    </select>
        
    <insert id="insert" parameterType="WechatStock" useGeneratedKeys="true" keyProperty="id">
        insert into wechat_stock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="stockName != null and stockName != ''">stock_name,</if>
            <if test="comment != null">comment,</if>
            <if test="goodsName != null and goodsName != ''">goods_name,</if>
            <if test="stockType != null and stockType != ''">stock_type,</if>
            <if test="availableBeginTime != null">available_begin_time,</if>
            <if test="availableEndTime != null">available_end_time,</if>
            <if test="availableDayAfterReceive != null">available_day_after_receive,</if>
            <if test="discountAmount != null">discount_amount,</if>
            <if test="transactionMinimum != null">transaction_minimum,</if>
            <if test="discountPercent != null">discount_percent,</if>
            <if test="useMethod != null and useMethod != ''">use_method,</if>
            <if test="outRequestNo != null and outRequestNo != ''">out_request_no,</if>
            <if test="maxCoupons != null">max_coupons,</if>
            <if test="maxCouponsPerUser != null">max_coupons_per_user,</if>
            <if test="couponCodeMode != null and couponCodeMode != ''">coupon_code_mode,</if>
            <if test="stockState != null">stock_state,</if>
            <if test="stockId != null and stockId != ''">stock_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>

            <if test="sendType != null and sendType != ''">send_type,</if>
            <if test="discountType != null and discountType != ''">discount_type,</if>
            <if test="eventType != null and eventType != ''">event_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="stockName != null and stockName != ''">#{stockName},</if>
            <if test="comment != null">#{comment},</if>
            <if test="goodsName != null and goodsName != ''">#{goodsName},</if>
            <if test="stockType != null and stockType != ''">#{stockType},</if>
            <if test="availableBeginTime != null">#{availableBeginTime},</if>
            <if test="availableEndTime != null">#{availableEndTime},</if>
            <if test="availableDayAfterReceive != null">#{availableDayAfterReceive},</if>
            <if test="discountAmount != null">#{discountAmount},</if>
            <if test="transactionMinimum != null">#{transactionMinimum},</if>
            <if test="discountPercent != null">#{discountPercent},</if>
            <if test="useMethod != null and useMethod != ''">#{useMethod},</if>
            <if test="outRequestNo != null and outRequestNo != ''">#{outRequestNo},</if>
            <if test="maxCoupons != null">#{maxCoupons},</if>
            <if test="maxCouponsPerUser != null">#{maxCouponsPerUser},</if>
            <if test="couponCodeMode != null and couponCodeMode != ''">#{couponCodeMode},</if>
            <if test="stockState != null">#{stockState},</if>
            <if test="stockId != null and stockId != ''">#{stockId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>

            <if test="sendType != null and sendType != ''">#{sendType},</if>
            <if test="discountType != null and discountType != ''">#{discountType},</if>
            <if test="eventType != null and eventType != ''">#{eventType},</if>
         </trim>
    </insert>

    <update id="update" parameterType="WechatStock">
        update wechat_stock
        <trim prefix="SET" suffixOverrides=",">
            <if test="stockName != null and stockName != ''">stock_name = #{stockName},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
            <if test="stockType != null and stockType != ''">stock_type = #{stockType},</if>
            <if test="availableBeginTime != null">available_begin_time = #{availableBeginTime},</if>
            <if test="availableEndTime != null">available_end_time = #{availableEndTime},</if>
            <if test="availableDayAfterReceive != null">available_day_after_receive = #{availableDayAfterReceive},</if>
            <if test="discountAmount != null">discount_amount = #{discountAmount},</if>
            <if test="transactionMinimum != null">transaction_minimum = #{transactionMinimum},</if>
            <if test="discountPercent != null">discount_percent = #{discountPercent},</if>
            <if test="useMethod != null and useMethod != ''">use_method = #{useMethod},</if>
            <if test="outRequestNo != null and outRequestNo != ''">out_request_no = #{outRequestNo},</if>
            <if test="maxCoupons != null">max_coupons = #{maxCoupons},</if>
            <if test="maxCouponsPerUser != null">max_coupons_per_user = #{maxCouponsPerUser},</if>
            <if test="couponCodeMode != null and couponCodeMode != ''">coupon_code_mode = #{couponCodeMode},</if>
            <if test="stockState != null">stock_state = #{stockState},</if>
            <if test="stockId != null and stockId != ''">stock_id = #{stockId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>

            <if test="sendType != null and sendType != ''">send_type = #{sendType},</if>
            <if test="discountType != null and discountType != ''">discount_type = #{discountType},</if>
            <if test="eventType != null and eventType != ''">event_type = #{eventType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteById" parameterType="Long">
        delete from wechat_stock where id = #{id}
    </delete>

    <delete id="deleteByIds" parameterType="String">
        delete from wechat_stock where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertOrUpdate" parameterType="WechatStock" useGeneratedKeys="true" keyProperty="id">
        insert into wechat_stock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
             stock_name, comment, goods_name, stock_type, available_begin_time, available_end_time, available_day_after_receive, discount_amount, transaction_minimum, discount_percent, use_method, out_request_no, max_coupons, max_coupons_per_user, coupon_code_mode, stock_state, stock_id, create_by, create_time, update_by, update_time, send_type, discount_type, event_type
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id, jdbcType=BIGINT},
        </if>
        #{stockName, jdbcType=VARCHAR},
            #{comment, jdbcType=VARCHAR},
            #{goodsName, jdbcType=VARCHAR},
            #{stockType, jdbcType=VARCHAR},
            #{availableBeginTime, jdbcType=DATE},
            #{availableEndTime, jdbcType=DATE},
            #{availableDayAfterReceive, jdbcType=INTEGER},
            #{discountAmount, jdbcType=INTEGER},
            #{transactionMinimum, jdbcType=INTEGER},
            #{discountPercent, jdbcType=INTEGER},
            #{useMethod, jdbcType=VARCHAR},
            #{outRequestNo, jdbcType=VARCHAR},
            #{maxCoupons, jdbcType=INTEGER},
            #{maxCouponsPerUser, jdbcType=INTEGER},
            #{couponCodeMode, jdbcType=VARCHAR},
            #{stockState, jdbcType=VARCHAR},
            #{stockId, jdbcType=VARCHAR},
            #{createBy, jdbcType=BIGINT},
            #{createTime, jdbcType=DATE},
            #{updateBy, jdbcType=BIGINT},
            #{updateTime, jdbcType=DATE},
            #{sendType, jdbcType=VARCHAR},
            #{discountType, jdbcType=VARCHAR},
            #{eventType, jdbcType=VARCHAR}
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=BIGINT},
            </if>
            stock_name = #{stockName, jdbcType=VARCHAR},
            comment = #{comment, jdbcType=VARCHAR},
            goods_name = #{goodsName, jdbcType=VARCHAR},
            stock_type = #{stockType, jdbcType=VARCHAR},
            available_begin_time = #{availableBeginTime, jdbcType=DATE},
            available_end_time = #{availableEndTime, jdbcType=DATE},
            available_day_after_receive = #{availableDayAfterReceive, jdbcType=INTEGER},
            discount_amount = #{discountAmount, jdbcType=INTEGER},
            transaction_minimum = #{transactionMinimum, jdbcType=INTEGER},
            discount_percent = #{discountPercent, jdbcType=INTEGER},
            use_method = #{useMethod, jdbcType=VARCHAR},
            out_request_no = #{outRequestNo, jdbcType=VARCHAR},
            max_coupons = #{maxCoupons, jdbcType=INTEGER},
            max_coupons_per_user = #{maxCouponsPerUser, jdbcType=INTEGER},
            coupon_code_mode = #{couponCodeMode, jdbcType=VARCHAR},
            stock_state = #{stockState, jdbcType=VARCHAR},
            stock_id = #{stockId, jdbcType=VARCHAR},
            create_by = #{createBy, jdbcType=BIGINT},
            create_time = #{createTime, jdbcType=DATE},
            update_by = #{updateBy, jdbcType=BIGINT},
            update_time = #{updateTime, jdbcType=DATE},
            discount_type = #{discountType, jdbcType=VARCHAR},
            send_type = #{sendType, jdbcType=VARCHAR},
            event_type = #{eventType, jdbcType=VARCHAR}
        </trim>
    </insert>
</mapper>
