<?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.cftech.activity.oil.dao.OilMapper">

    <resultMap id="resultMap" type="com.cftech.activity.oil.model.Oil">
        <id column="id" property="id"/>
        <result column="title" property="title"/>
        <result column="keywords" property="keywords"/>
        <result column="explain" property="explain"/>
        <result column="wintips" property="wintips"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="draw_again_reply" property="drawAgainReply"/>
        <result column="act_start_pic" property="actStartPic"/>
        <result column="end_title" property="endTitle"/>
        <result column="end_explain" property="endExplain"/>
        <result column="act_end_pic" property="actEndPic"/>
        <result column="prizes" property="prizes"/>
        <result column="probability" property="probabilityMethod"/>
        <result column="attend_person_num" property="attendPersonNum"/>
        <result column="per_person_draw_num" property="perPersonDrawNum"/>
        <result column="per_person_can_prize" property="perPersonCanPrize"/>
        <result column="per_day_draw_num" property="perDayDrawNum"/>
        <result column="show_prizes_num" property="showPrizesNum"/>
        <result column="need_register" property="needRegister"/>
        <result column="accounts_id" property="accountsId"/>
        <result column="del_flag" property="delFlag"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
    </resultMap>

    <sql id="sqlWhere">
        <if test="conds!=null">
            <trim prefix="WHERE" prefixOverrides="AND|OR">
                <foreach collection="conds.conds" index="index" item="cond">
                    ${cond.linkType}
                    <if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
                    <if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
                    <if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
                    <if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
                    <if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
                    <if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
                    <if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND
                        #{cond.endValue}
                    </if>
                    <if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
                    <if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
                    <if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
                    <if test="cond.condType == 'IN'">${cond.param} IN
                        <foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                </foreach>
            </trim>
        </if>
    </sql>

    <sql id="sqlColumns">
                                    id,
                                                title,
                                                keywords,
                                                `explain`,
                                                wintips,
                                                start_time,
                                                end_time,
                                                draw_again_reply,
                                                act_start_pic,
                                                end_title,
                                                end_explain,
                                                act_end_pic,
                                                prizes,
                                                probability,
                                                attend_person_num,
                                                per_person_draw_num,
                                                per_person_can_prize,
                                                per_day_draw_num,
                                                show_prizes_num,
                                                need_register,
                                                accounts_id,
                                                del_flag,
                                                status,
                                                create_time,
                                                update_time,
                                                description,
                                                create_by,
                                                update_by
                        </sql>


    <insert id="save" parameterType="com.cftech.activity.oil.model.Oil" useGeneratedKeys="true"
            keyProperty="id">
        insert into wx_activity_oil
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{title, jdbcType=VARCHAR},
        #{keywords, jdbcType=VARCHAR},
        #{explain, jdbcType=VARCHAR},
        #{wintips, jdbcType=VARCHAR},
        now(),
        now(),
        #{drawAgainReply, jdbcType=VARCHAR},
        #{actStartPic, jdbcType=VARCHAR},
        #{endTitle, jdbcType=VARCHAR},
        #{endExplain, jdbcType=VARCHAR},
        #{actEndPic, jdbcType=VARCHAR},
        #{prizes,jdbcType=CLOB},
        #{probabilityMethod,jdbcType=VARCHAR},
        #{attendPersonNum,jdbcType=INTEGER},
        #{perPersonDrawNum,jdbcType=INTEGER},
        #{perPersonCanPrize,jdbcType=INTEGER},
        #{perDayDrawNum,jdbcType=INTEGER},
        #{showPrizesNum, jdbcType=TINYINT},
        #{needRegister, jdbcType=TINYINT},
        #{accountsId, jdbcType=BIGINT},
        #{delFlag, jdbcType=TINYINT},
        #{status, jdbcType=VARCHAR},
        now(),
        now(),
        #{description, jdbcType=VARCHAR},
        #{createBy, jdbcType=BIGINT},
        #{updateBy, jdbcType=BIGINT}
        )
    </insert>

    <select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_activity_oil t
        WHERE t.id=#{id}
    </select>

    <select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM wx_activity_oil
        <include refid="sqlWhere"/>

    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_activity_oil
        <include refid="sqlWhere"/>
        <if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
        <if test="limit>0">limit #{offset},#{limit}</if>
    </select>

    <update id="update" parameterType="com.cftech.activity.oil.model.Oil">
        update wx_activity_oil
        <set>
            <if test="id != null">
                id = #{id, jdbcType=BIGINT},
            </if>
            <if test="title != null">
                title = #{title, jdbcType=VARCHAR},
            </if>
            <if test="keywords != null">
                keywords = #{keywords, jdbcType=VARCHAR},
            </if>
            <if test="explain != null">
                `explain` = #{explain, jdbcType=VARCHAR},
            </if>
            <if test="wintips != null">
                wintips = #{wintips, jdbcType=VARCHAR},
            </if>
            <if test="startTime != null">
                start_time = #{startTime},
            </if>
            <if test="endTime != null">
                end_time = #{endTime},
            </if>
            <if test="drawAgainReply != null">
                draw_again_reply = #{drawAgainReply, jdbcType=VARCHAR},
            </if>
            <if test="actStartPic != null">
                act_start_pic = #{actStartPic, jdbcType=VARCHAR},
            </if>
            <if test="endTitle != null">
                end_title = #{endTitle, jdbcType=VARCHAR},
            </if>
            <if test="endExplain != null">
                end_explain = #{endExplain, jdbcType=VARCHAR},
            </if>
            <if test="actEndPic != null">
                act_end_pic = #{actEndPic, jdbcType=VARCHAR},
            </if>
            <if test="prizes != null">
                prizes = #{prizes},
            </if>
            <if test="probabilityMethod != null">
                probability = #{probabilityMethod},
            </if>
            <if test="attendPersonNum != null">
                attend_person_num = #{attendPersonNum},
            </if>
            <if test="perPersonDrawNum != null">
                per_person_draw_num = #{perPersonDrawNum},
            </if>
            <if test="perPersonCanPrize != null">
                per_person_can_prize = #{perPersonCanPrize},
            </if>
            <if test="perDayDrawNum != null">
                per_day_draw_num = #{perDayDrawNum},
            </if>
            <if test="showPrizesNum != null">
                show_prizes_num = #{showPrizesNum},
            </if>
            <if test="needRegister != null">
                need_register = #{needRegister, jdbcType=TINYINT},
            </if>
            <if test="accountsId != null">
                accounts_id = #{accountsId, jdbcType=BIGINT},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag, jdbcType=TINYINT},
            </if>
            <if test="status != null">
                status = #{status, jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="description != null">
                description = #{description, jdbcType=VARCHAR},
            </if>
            <if test="createBy != null">
                create_by = #{createBy, jdbcType=BIGINT},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy, jdbcType=BIGINT},
            </if>
        </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

    <update id="delete" parameterType="java.lang.Long">
        update wx_activity_oil set del_flag=1 where id=#{id,jdbcType=BIGINT}
    </update>
</mapper>