<?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.ruoyi.framework.recovery.mapper.WxCreditMapper">

    <resultMap type="WxCredit" id="WxCreditResult">
        <result property="id"    column="id"    />
        <result property="creditType"    column="credit_type"    />
        <result property="creditNum"    column="credit_num"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
    </resultMap>

    <sql id="selectWxCreditVo">
        select id, credit_type, credit_num, create_by, create_date, update_by, update_date from wx_credit
    </sql>

    <select id="selectWxCreditList" parameterType="WxCredit" resultMap="WxCreditResult">
        <include refid="selectWxCreditVo"/>
        <where>
            <if test="creditType != null  and creditType != ''"> and credit_type = #{creditType}</if>
            <if test="creditNum != null "> and credit_num = #{creditNum}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
        </where>
    </select>

    <select id="selectWxCreditById" parameterType="Long" resultMap="WxCreditResult">
        <include refid="selectWxCreditVo"/>
        where id = #{id}
    </select>
    <select id="selectWxCreditUser" resultType="java.lang.Long">
        select credit_id from wx_credit_user where open_id = #{openId} and create_date between #{start} and #{end}
    </select>

    <insert id="insertWxCredit" parameterType="WxCredit">
        insert into wx_credit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="creditType != null">credit_type,</if>
            <if test="creditNum != null">credit_num,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="creditType != null">#{creditType},</if>
            <if test="creditNum != null">#{creditNum},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
         </trim>
    </insert>
    <insert id="insertWxCreditUser">
        insert into wx_credit_user (open_id, credit_id, create_date) values (#{openId}, #{id}, #{date})
    </insert>

    <update id="updateWxCredit" parameterType="WxCredit">
        update wx_credit
        <trim prefix="SET" suffixOverrides=",">
            <if test="creditType != null">credit_type = #{creditType},</if>
            <if test="creditNum != null">credit_num = #{creditNum},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxCreditById" parameterType="Long">
        delete from wx_credit where id = #{id}
    </delete>

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