<?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.fs.store.mapper.FsUserBillMapper">
    
    <resultMap type="FsUserBill" id="FsUserBillResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="businessId"    column="business_id"    />
        <result property="category"    column="category"    />
        <result property="billType"    column="bill_type"    />
        <result property="type"    column="type"    />
        <result property="title"    column="title"    />
        <result property="number"    column="number"    />
        <result property="balance"    column="balance"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
        <result property="tuiUserId"    column="tui_user_id"    />
    </resultMap>

    <sql id="selectFsUserBillVo">
        select id, user_id, business_id, category, bill_type, type, title, number, balance, remark, create_time, update_time, status,tui_user_id from fs_user_bill
    </sql>

    <select id="selectFsUserBillList" parameterType="FsUserBill" resultMap="FsUserBillResult">
        <include refid="selectFsUserBillVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="businessId != null  and businessId != ''"> and business_id = #{businessId}</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="billType != null "> and bill_type = #{billType}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="number != null "> and number = #{number}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="tuiUserId != null "> and tui_user_id = #{tuiUserId}</if>
        </where>
    </select>
    
    <select id="selectFsUserBillById" parameterType="Long" resultMap="FsUserBillResult">
        <include refid="selectFsUserBillVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsUserBill" parameterType="FsUserBill" useGeneratedKeys="true" keyProperty="id">
        insert into fs_user_bill
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="businessId != null and businessId != ''">business_id,</if>
            <if test="category != null">category,</if>
            <if test="billType != null">bill_type,</if>
            <if test="type != null">type,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="number != null">number,</if>
            <if test="balance != null">balance,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="tuiUserId != null">tui_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="businessId != null and businessId != ''">#{businessId},</if>
            <if test="category != null">#{category},</if>
            <if test="billType != null">#{billType},</if>
            <if test="type != null">#{type},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="number != null">#{number},</if>
            <if test="balance != null">#{balance},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="tuiUserId != null">#{tuiUserId},</if>
         </trim>
    </insert>

    <update id="updateFsUserBill" parameterType="FsUserBill">
        update fs_user_bill
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="businessId != null and businessId != ''">business_id = #{businessId},</if>
            <if test="category != null">category = #{category},</if>
            <if test="billType != null">bill_type = #{billType},</if>
            <if test="type != null">type = #{type},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="number != null">number = #{number},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsUserBillById" parameterType="Long">
        delete from fs_user_bill where id = #{id}
    </delete>

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