<?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.FsUserMapper">
    <resultMap type="FsUser" id="FsUserResult">
        <result property="userId"    column="user_id"    />
        <result property="username"    column="username"    />
        <result property="password"    column="password"    />
        <result property="realName"    column="real_name"    />
        <result property="birthday"    column="birthday"    />
        <result property="idCard"    column="id_card"    />
        <result property="remark"    column="remark"    />
        <result property="nickname"    column="nickname"    />
        <result property="avatar"    column="avatar"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="lastIp"    column="last_ip"    />
        <result property="nowMoney"    column="now_money"    />
        <result property="brokeragePrice"    column="brokerage_price"    />
        <result property="integral"    column="integral"    />
        <result property="signNum"    column="sign_num"    />
        <result property="status"    column="status"    />
        <result property="level"    column="level"    />
        <result property="spreadUserId"    column="spread_user_id"    />
        <result property="spreadTime"    column="spread_time"    />
        <result property="userType"    column="user_type"    />
        <result property="isPromoter"    column="is_promoter"    />
        <result property="payCount"    column="pay_count"    />
        <result property="spreadCount"    column="spread_count"    />
        <result property="addres"    column="addres"    />
        <result property="maOpenId"    column="ma_open_id"    />
        <result property="mpOpenId"    column="mp_open_id"    />
        <result property="unionId"    column="union_id"    />
        <result property="isDel"    column="is_del"    />
        <result property="isWeixinAuth"    column="is_weixin_auth"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="registerDate"    column="register_date"    />
        <result property="registerCode"    column="register_code"    />
        <result property="source"    column="source"    />
        <result property="userCode"    column="user_code"    />
    </resultMap>

    <sql id="selectFsUserVo">
        select user_id, username, password, real_name, birthday, id_card, remark, nickname, avatar, phone, create_time, update_time, last_ip, now_money, brokerage_price, integral, sign_num, status, level, spread_user_id, spread_time, user_type, is_promoter, pay_count, spread_count, addres,ma_open_id,mp_open_id,union_id, is_del,is_weixin_auth,company_id,company_user_id,register_date,register_code,source,user_code from fs_user
    </sql>

    <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
        <include refid="selectFsUserVo"/>
        <where>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="remark != null  and remark != ''"> and remark = #{remark}</if>
            <if test="nickname != null  and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="lastIp != null  and lastIp != ''"> and last_ip = #{lastIp}</if>
            <if test="nowMoney != null "> and now_money = #{nowMoney}</if>
            <if test="brokeragePrice != null "> and brokerage_price = #{brokeragePrice}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="signNum != null "> and sign_num = #{signNum}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="spreadUserId != null "> and spread_user_id = #{spreadUserId}</if>
            <if test="spreadTime != null "> and spread_time = #{spreadTime}</if>
            <if test="userType != null  and userType != ''"> and user_type = #{userType}</if>
            <if test="isPromoter != null "> and is_promoter = #{isPromoter}</if>
            <if test="payCount != null "> and pay_count = #{payCount}</if>
            <if test="spreadCount != null "> and spread_count = #{spreadCount}</if>
            <if test="addres != null  and addres != ''"> and addres = #{addres}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="registerDate != null "> and DATE_FORMAT(register_date,'%Y-%m-%d') = DATE_FORMAT(#{registerDate},'%Y-%m-%d')</if>
            <if test="registerCode != null   and registerCode != '' "> and register_code = #{registerCode}</if>
            <if test="source != null  and source != '' "> and source = #{source}</if>
        </where>
        order by user_id desc
    </select>

    <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
        <include refid="selectFsUserVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
        insert into fs_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="realName != null">real_name,</if>
            <if test="birthday != null">birthday,</if>
            <if test="idCard != null">id_card,</if>
            <if test="remark != null">remark,</if>
            <if test="nickname != null">nickname,</if>
            <if test="avatar != null">avatar,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="lastIp != null">last_ip,</if>
            <if test="nowMoney != null">now_money,</if>
            <if test="brokeragePrice != null">brokerage_price,</if>
            <if test="integral != null">integral,</if>
            <if test="signNum != null">sign_num,</if>
            <if test="status != null">status,</if>
            <if test="level != null">level,</if>
            <if test="spreadUserId != null">spread_user_id,</if>
            <if test="spreadTime != null">spread_time,</if>
            <if test="userType != null and userType != ''">user_type,</if>
            <if test="isPromoter != null">is_promoter,</if>
            <if test="payCount != null">pay_count,</if>
            <if test="spreadCount != null">spread_count,</if>
            <if test="addres != null and addres != ''">addres,</if>
            <if test="maOpenId != null">ma_open_id,</if>
            <if test="mpOpenId != null">mp_open_id,</if>
            <if test="unionId != null">union_id,</if>
            <if test="isDel != null">is_del,</if>
            <if test="isWeixinAuth != null">is_weixin_auth,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="registerDate != null">register_date,</if>
            <if test="registerCode != null">register_code,</if>
            <if test="source != null">source,</if>
            <if test="userCode != null">user_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="realName != null">#{realName},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="remark != null">#{remark},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="lastIp != null">#{lastIp},</if>
            <if test="nowMoney != null">#{nowMoney},</if>
            <if test="brokeragePrice != null">#{brokeragePrice},</if>
            <if test="integral != null">#{integral},</if>
            <if test="signNum != null">#{signNum},</if>
            <if test="status != null">#{status},</if>
            <if test="level != null">#{level},</if>
            <if test="spreadUserId != null">#{spreadUserId},</if>
            <if test="spreadTime != null">#{spreadTime},</if>
            <if test="userType != null and userType != ''">#{userType},</if>
            <if test="isPromoter != null">#{isPromoter},</if>
            <if test="payCount != null">#{payCount},</if>
            <if test="spreadCount != null">#{spreadCount},</if>
            <if test="addres != null and addres != ''">#{addres},</if>
            <if test="maOpenId != null">#{maOpenId},</if>
            <if test="mpOpenId != null">#{mpOpenId},</if>
            <if test="unionId != null">#{unionId},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="registerDate != null">#{registerDate},</if>
            <if test="registerCode != null">#{registerCode},</if>
            <if test="source != null">#{source},</if>
            <if test="userCode != null">#{userCode},</if>
         </trim>
    </insert>

    <update id="updateFsUser" parameterType="FsUser">
        update fs_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="nickname != null">nickname = #{nickname},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="lastIp != null">last_ip = #{lastIp},</if>
            <if test="nowMoney != null">now_money = #{nowMoney},</if>
            <if test="brokeragePrice != null">brokerage_price = #{brokeragePrice},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="signNum != null">sign_num = #{signNum},</if>
            <if test="status != null">status = #{status},</if>
            <if test="level != null">level = #{level},</if>
            <if test="spreadUserId != null">spread_user_id = #{spreadUserId},</if>
            <if test="spreadTime != null">spread_time = #{spreadTime},</if>
            <if test="userType != null and userType != ''">user_type = #{userType},</if>
            <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
            <if test="payCount != null">pay_count = #{payCount},</if>
            <if test="spreadCount != null">spread_count = #{spreadCount},</if>
            <if test="addres != null and addres != ''">addres = #{addres},</if>
            <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
            <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
            <if test="unionId != null">union_id = #{unionId},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="registerDate != null">register_date = #{registerDate},</if>
            <if test="registerCode != null">register_code = #{registerCode},</if>
            <if test="source != null">source = #{source},</if>
            <if test="userCode != null">user_code = #{userCode},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteFsUserById" parameterType="Long">
        delete from fs_user where user_id = #{userId}
    </delete>

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

</mapper>
