<?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.mp.qrcode.dao.QrCodeMapper">

    <resultMap id="resultMap" type="com.cftech.mp.qrcode.model.QrCode">
        <id column="id" property="id"/>
        <result column="ticket" property="ticket"/>
        <result column="reply_type" property="reply_type"/>
        <result column="content_source" property="content_source"/>
        <result column="action_name" property="action_name"/>
        <result column="expire_seconds" property="expire_seconds"/>
        <result column="shortUrl" property="shortUrl"/>
        <result column="accountsid" property="accountsId"/>
        <result column="es_endtime" property="esEndtime"/>
        <result column="sence" property="sence"/>
        <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="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,
                ticket,
                reply_type,
                content_source,
                action_name,
                expire_seconds,
                shortUrl,
                accountsid,
                es_endtime,
                sence,
                del_flag,
                status,
                create_time,
                update_time,
                create_by,
                update_by
    </sql>


    <insert id="save" parameterType="com.cftech.mp.qrcode.model.QrCode" useGeneratedKeys="true"
            keyProperty="id">
        insert into wx_mp_wechat_qrcode
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{ticket, jdbcType=VARCHAR},
        #{reply_type, jdbcType=VARCHAR},
        #{content_source, jdbcType=VARCHAR},
        #{action_name, jdbcType=VARCHAR},
        #{expire_seconds, jdbcType=BIGINT},
        #{shortUrl, jdbcType=VARCHAR},
        #{accountsId, jdbcType=BIGINT},
        #{esEndtime, jdbcType=DATE},
        #{sence, jdbcType=VARCHAR},
        #{delFlag, jdbcType=TINYINT},
        #{status, jdbcType=VARCHAR},
        now(),
        now(),
        #{createBy, jdbcType=BIGINT},
        #{updateBy, jdbcType=BIGINT}
        )
    </insert>

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

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

    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_mp_wechat_qrcode
        <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.mp.qrcode.model.QrCode">
        update wx_mp_wechat_qrcode
        <set>
            <if test="id != null">
                id = #{id, jdbcType=BIGINT},
            </if>
            <if test="ticket != null">
                ticket = #{ticket, jdbcType=VARCHAR},
            </if>
            <if test="reply_type != null">
                reply_type = #{reply_type, jdbcType=VARCHAR},
            </if>
            <if test="content_source != null">
                content_source = #{content_source, jdbcType=VARCHAR},
            </if>
            <if test="action_name != null">
                action_name = #{action_name, jdbcType=VARCHAR},
            </if>
            <if test="expire_seconds != null">
                expire_seconds = #{expire_seconds, jdbcType=BIGINT},
            </if>
            <if test="shortUrl != null">
                shortUrl = #{shortUrl, jdbcType=VARCHAR},
            </if>
            <if test="accountsId != null">
                accountsid = #{accountsId, jdbcType=BIGINT},
            </if>
            <if test="esEndtime != null">
                es_endtime = #{esEndtime, jdbcType=TIMESTAMP},
            </if>
            <if test="sence != null">
                sence = #{sence, jdbcType=VARCHAR},
            </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, jdbcType=TIMESTAMP},
            </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_mp_wechat_qrcode set del_flag=1 where id=#{id,jdbcType=BIGINT}
    </update>

    <select id="bySceneFindQrcode" parameterType="java.lang.String" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_mp_wechat_qrcode t
        WHERE t.sence=#{scene,jdbcType=VARCHAR}
    </select>
</mapper>