<?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.wheel.dao.WheelMapper">

    <resultMap id="resultMap" type="com.cftech.activity.wheel.model.Wheel">
        <id column="id" property="id"/>
        <result column="title" property="title"/>
        <result column="keywords" property="keywords"/>
        <result column="explain" property="explain"/>
        <result column="explain_en" property="explainEn"/>
        <result column="wintips" property="wintips"/>
        <result column="wintips_en" property="wintipsEn"/>
        <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"/>
        <result column="explain_en" property="explainEn"/>
        <result column="wintips_en" property="wintipsEn"/>
        <result column="draw_again_reply_en" property="drawAgainReplyEn"/>
        <result column="end_title_en" property="endTitleEn"/>
        <result column="end_explain_en" property="endExplainEn"/>
        <result column="draw_again_day_reply_en" property="drawAgainDayReplyEn"/>
        <result column="title_en" property="titleEn"/>
    </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,
                                                explain_en,
                                                wintips_en,
                                                draw_again_reply_en,
                                                end_title_en,
                                                end_explain_en,
                                                draw_again_day_reply,
                                                draw_again_day_reply_en,
                                                title_en
                        </sql>
    <insert id="save" parameterType="com.cftech.activity.wheel.model.Wheel" useGeneratedKeys="true"
            keyProperty="id">
        insert into wx_mp_activity_wheel
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{title, jdbcType=VARCHAR},
        #{keywords, jdbcType=VARCHAR},
        #{explain, jdbcType=VARCHAR},
        #{wintips, jdbcType=VARCHAR},
        #{startTime},
        #{endTime},
        #{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},
        #{explainEn, jdbcType=VARCHAR},
        #{wintipsEn, jdbcType=VARCHAR},
        #{drawAgainReplyEn, jdbcType=VARCHAR},
        #{endTitleEn, jdbcType=VARCHAR},
        #{endExplainEn, jdbcType=VARCHAR},
        #{drawAgainDayReply, jdbcType=VARCHAR},
        #{drawAgainDayReplyEn, jdbcType=VARCHAR},
        #{titleEn, jdbcType=VARCHAR}
        )
    </insert>

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

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

    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_mp_activity_wheel
        <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.wheel.model.Wheel">
        update wx_mp_activity_wheel
        <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>
            <if test="explainEn != null">
                explain_en = #{explainEn, jdbcType=VARCHAR},
            </if>
            <if test="wintipsEn != null">
                wintips_en = #{wintipsEn, jdbcType=VARCHAR},
            </if>
            <if test="drawAgainReplyEn != null">
                draw_again_reply_en = #{drawAgainReplyEn, jdbcType=VARCHAR},
            </if>
            <if test="endTitleEn != null">
                end_title_en = #{endTitleEn, jdbcType=VARCHAR},
            </if>
            <if test="endExplainEn != null">
                end_explain_en = #{endExplainEn, jdbcType=VARCHAR},
            </if>
            <if test="drawAgainDayReply != null">
                draw_again_day_reply = #{drawAgainDayReply, jdbcType=VARCHAR},
            </if>
            <if test="drawAgainDayReplyEn != null">
                draw_again_day_reply_en = #{drawAgainDayReplyEn, jdbcType=VARCHAR},
            </if>
            <if test="titleEn != null">
                title_en = #{titleEn, jdbcType=VARCHAR},
            </if>
        </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

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