<?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.system.mapper.UsersMapper">
    
    <resultMap type="Users" id="UsersResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="nickname"    column="nickname"    />
        <result property="phone"    column="phone"    />
        <result property="password"    column="password"    />
        <result property="rememberToken"    column="remember_token"    />
        <result property="openid"    column="openid"    />
        <result property="avatar"    column="avatar"    />
        <result property="type"    column="type"    />
        <result property="workerTime"    column="worker_time"    />
        <result property="integral"    column="integral"    />
        <result property="totalIntegral"    column="total_integral"    />
        <result property="status"    column="status"    />
        <result property="level"    column="level"    />
        <result property="commission"    column="commission"    />
        <result property="totalComm"    column="total_comm"    />
        <result property="margin"    column="margin"    />
        <result property="jobNumber"    column="job_number"    />
        <result property="prohibitTime"    column="prohibit_time"    />
        <result property="prohibitTimeNum"    column="prohibit_time_num"    />
        <result property="toa"    column="toa"    />
        <result property="serviceCityPid"    column="service_city_pid"    />
        <result property="serviceCityIds"    column="service_city_ids"    />
        <result property="skillIds"    column="skill_ids"    />
        <result property="propose"    column="propose"    />
        <result property="loginStatus"    column="login_status"    />
        <result property="isStop"    column="is_stop"    />
        <result property="middleAuth"    column="middle_auth"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectUsersVo">
        select id, name, nickname, phone, password, remember_token, openid, avatar, type, worker_time, integral, total_integral, status, level, commission, total_comm, margin, job_number, prohibit_time, prohibit_time_num, toa, service_city_pid, service_city_ids, skill_ids, propose, login_status, is_stop, middle_auth, created_at, updated_at from users
    </sql>

    <select id="selectUsersList" parameterType="Users" resultMap="UsersResult">
        <include refid="selectUsersVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="nickname != null  and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="rememberToken != null  and rememberToken != ''"> and remember_token = #{rememberToken}</if>
            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="workerTime != null "> and worker_time = #{workerTime}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="totalIntegral != null "> and total_integral = #{totalIntegral}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="commission != null "> and commission = #{commission}</if>
            <if test="totalComm != null "> and total_comm = #{totalComm}</if>
            <if test="margin != null "> and margin = #{margin}</if>
            <if test="jobNumber != null "> and job_number = #{jobNumber}</if>
            <if test="prohibitTime != null "> and prohibit_time = #{prohibitTime}</if>
            <if test="prohibitTimeNum != null "> and prohibit_time_num = #{prohibitTimeNum}</if>
            <if test="toa != null "> and toa = #{toa}</if>
            <if test="serviceCityPid != null "> and service_city_pid = #{serviceCityPid}</if>
            <if test="serviceCityIds != null  and serviceCityIds != ''"> and service_city_ids = #{serviceCityIds}</if>
            <if test="skillIds != null  and skillIds != ''"> and skill_ids = #{skillIds}</if>
            <if test="propose != null "> and propose = #{propose}</if>
            <if test="loginStatus != null "> and login_status = #{loginStatus}</if>
            <if test="isStop != null "> and is_stop = #{isStop}</if>
            <if test="middleAuth != null "> and middle_auth = #{middleAuth}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectUsersById" parameterType="Long" resultMap="UsersResult">
        <include refid="selectUsersVo"/>
        where id = #{id}
    </select>

    <insert id="insertUsers" parameterType="Users" useGeneratedKeys="true" keyProperty="id">
        insert into users
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="nickname != null">nickname,</if>
            <if test="phone != null">phone,</if>
            <if test="password != null">password,</if>
            <if test="rememberToken != null">remember_token,</if>
            <if test="openid != null">openid,</if>
            <if test="avatar != null">avatar,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="workerTime != null">worker_time,</if>
            <if test="integral != null">integral,</if>
            <if test="totalIntegral != null">total_integral,</if>
            <if test="status != null">status,</if>
            <if test="level != null">level,</if>
            <if test="commission != null">commission,</if>
            <if test="totalComm != null">total_comm,</if>
            <if test="margin != null">margin,</if>
            <if test="jobNumber != null">job_number,</if>
            <if test="prohibitTime != null">prohibit_time,</if>
            <if test="prohibitTimeNum != null">prohibit_time_num,</if>
            <if test="toa != null">toa,</if>
            <if test="serviceCityPid != null">service_city_pid,</if>
            <if test="serviceCityIds != null">service_city_ids,</if>
            <if test="skillIds != null">skill_ids,</if>
            <if test="propose != null">propose,</if>
            <if test="loginStatus != null">login_status,</if>
            <if test="isStop != null">is_stop,</if>
            <if test="middleAuth != null">middle_auth,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="phone != null">#{phone},</if>
            <if test="password != null">#{password},</if>
            <if test="rememberToken != null">#{rememberToken},</if>
            <if test="openid != null">#{openid},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="workerTime != null">#{workerTime},</if>
            <if test="integral != null">#{integral},</if>
            <if test="totalIntegral != null">#{totalIntegral},</if>
            <if test="status != null">#{status},</if>
            <if test="level != null">#{level},</if>
            <if test="commission != null">#{commission},</if>
            <if test="totalComm != null">#{totalComm},</if>
            <if test="margin != null">#{margin},</if>
            <if test="jobNumber != null">#{jobNumber},</if>
            <if test="prohibitTime != null">#{prohibitTime},</if>
            <if test="prohibitTimeNum != null">#{prohibitTimeNum},</if>
            <if test="toa != null">#{toa},</if>
            <if test="serviceCityPid != null">#{serviceCityPid},</if>
            <if test="serviceCityIds != null">#{serviceCityIds},</if>
            <if test="skillIds != null">#{skillIds},</if>
            <if test="propose != null">#{propose},</if>
            <if test="loginStatus != null">#{loginStatus},</if>
            <if test="isStop != null">#{isStop},</if>
            <if test="middleAuth != null">#{middleAuth},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateUsers" parameterType="Users">
        update users
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="nickname != null">nickname = #{nickname},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="password != null">password = #{password},</if>
            <if test="rememberToken != null">remember_token = #{rememberToken},</if>
            <if test="openid != null">openid = #{openid},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="workerTime != null">worker_time = #{workerTime},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="totalIntegral != null">total_integral = #{totalIntegral},</if>
            <if test="status != null">status = #{status},</if>
            <if test="level != null">level = #{level},</if>
            <if test="commission != null">commission = #{commission},</if>
            <if test="totalComm != null">total_comm = #{totalComm},</if>
            <if test="margin != null">margin = #{margin},</if>
            <if test="jobNumber != null">job_number = #{jobNumber},</if>
            <if test="prohibitTime != null">prohibit_time = #{prohibitTime},</if>
            <if test="prohibitTimeNum != null">prohibit_time_num = #{prohibitTimeNum},</if>
            <if test="toa != null">toa = #{toa},</if>
            <if test="serviceCityPid != null">service_city_pid = #{serviceCityPid},</if>
            <if test="serviceCityIds != null">service_city_ids = #{serviceCityIds},</if>
            <if test="skillIds != null">skill_ids = #{skillIds},</if>
            <if test="propose != null">propose = #{propose},</if>
            <if test="loginStatus != null">login_status = #{loginStatus},</if>
            <if test="isStop != null">is_stop = #{isStop},</if>
            <if test="middleAuth != null">middle_auth = #{middleAuth},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUsersById" parameterType="Long">
        delete from users where id = #{id}
    </delete>

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