<?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.flossom.common.core.mapper.WxNoRemindRecordMapper">
    
    <resultMap type="WxNoRemindRecord" id="WxNoRemindRecordResult">
        <result property="id"    column="id"    />
        <result property="openid"    column="openid"    />
        <result property="type"    column="type"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectWxNoRemindRecordVo">
        select id, openid, type, create_time from wx_no_remind_record
    </sql>

    <select id="selectWxNoRemindRecordList" parameterType="WxNoRemindRecord" resultMap="WxNoRemindRecordResult">
        <include refid="selectWxNoRemindRecordVo"/>
        <where>  
            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
            <if test="type != null "> and type = #{type}</if>
        </where>
    </select>
    
    <select id="selectWxNoRemindRecordById" parameterType="Long" resultMap="WxNoRemindRecordResult">
        <include refid="selectWxNoRemindRecordVo"/>
        where id = #{id}
    </select>

    <select id="selectWxNoRemindRecordByOpenid" resultType="java.lang.Integer">
        SELECT
            count(1)
        FROM
            `wx_no_remind_record`
        WHERE
            openid = #{openid}
            AND YEAR (create_time) = YEAR (sysdate())
    </select>

    <insert id="insertWxNoRemindRecord" parameterType="WxNoRemindRecord" useGeneratedKeys="true" keyProperty="id">
        insert into wx_no_remind_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="openid != null">openid,</if>
            <if test="type != null">type,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="openid != null">#{openid},</if>
            <if test="type != null">#{type},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWxNoRemindRecord" parameterType="WxNoRemindRecord">
        update wx_no_remind_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="openid != null">openid = #{openid},</if>
            <if test="type != null">type = #{type},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxNoRemindRecordById" parameterType="Long">
        delete from wx_no_remind_record where id = #{id}
    </delete>

    <delete id="deleteWxNoRemindRecordByIds" parameterType="String">
        delete from wx_no_remind_record where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteWxNoRemindRecordByOpenid" parameterType="String">
        delete from wx_no_remind_record where openid = #{openid}
    </delete>
</mapper>