<?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.securitycontrol.system.base.mapper.IUserMapper">
    <!--新增/修改用户-->
    <insert id="addOrUpdateUser">
        <if test="type == 1">
            INSERT INTO sys_user
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="userName != null and userName != ''">user_name,</if>
                <if test="loginName != null and loginName!=''">login_name,</if>
                <if test="password != null and password !=''">password,</if>
                <if test="orgId != null and orgId!=''">org_id,</if>
                <if test="deptName != null and deptName != ''">dept_name,</if>
                <if test="orgName != null and orgName != ''">org_name,</if>
                <if test="createTime != null and createTime != ''">create_time,</if>
                <if test="phone != null and phone != ''">phone,</if>
                <if test="loginType != null and loginType != ''">login_type,</if>
                <if test="userType != null">user_type,</if>
                <if test="isAdmin != null">is_admin,</if>
                <if test="roleId != null and roleId != ''">role_id,</if>
                <if test="roleName != null and roleName != ''">role_name,</if>
                <if test="accountStatus != null">status,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="userName != null and userName != ''">#{userName},</if>
                <if test="loginName != null and loginName!=''">#{loginName},</if>
                <if test="password != null and password !=''">#{password},</if>
                <if test="orgId != null and orgId!=''">#{orgId},</if>
                <if test="deptName != null and deptName != ''">#{deptName},</if>
                <if test="orgName != null and orgName != ''">#{orgName},</if>
                <if test="createTime != null and createTime != ''">#{createTime},</if>
                <if test="phone != null and phone != ''">#{phone},</if>
                <if test="loginType != null and loginType != ''">#{loginType},</if>
                <if test="userType != null">#{userType},</if>
                <if test="isAdmin != null">#{isAdmin},</if>
                <if test="roleId != null and roleId != ''">#{roleId},</if>
                <if test="roleName != null and roleName != ''">#{roleName},</if>
                <if test="accountStatus != null">#{accountStatus},</if>
            </trim>
        </if>
        <if test="type == 2">
            UPDATE sys_user
            <set>
                <if test="userName != null and userName != ''">user_name = #{userName},</if>
                <if test="orgId != null and orgId != ''">org_id = #{orgId},</if>
                <if test="orgName != null and orgName != ''">org_name = #{orgName},</if>
                <if test="phone != null and phone != ''">phone = #{phone},</if>
                <if test="loginType != null and loginType != ''">login_type = #{loginType},</if>
                <if test="userType != null and userType != ''">user_type = #{userType},</if>
                <if test="isAdmin != null">is_admin = #{isAdmin},</if>
                <if test="roleId != null and roleId != ''">role_id = #{roleId},</if>
                <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
                <if test="accountStatus != null">status = #{accountStatus},</if>
            </set>
            WHERE user_id = #{userId}
        </if>
    </insert>
    <!--删除用户-->
    <update id="delUser">
        UPDATE sys_user SET del_flag = '1' WHERE user_id = #{userId}
    </update>
    <!--重置密码-->
    <update id="editPwd">
        UPDATE sys_user SET password = #{password} WHERE user_id = #{userId}
    </update>

    <!--获取用户列表-->
    <select id="getUserLists" resultType="com.securitycontrol.entity.system.vo.UserVo">
        SELECT su.user_id AS userId,
        su.user_name AS userName,
        su.login_name AS loginName,
        su.del_flag AS delFlag,
        su.phone,
        su.del_flag AS delFlag
        FROM sys_user su
        <where>
            <if test="userName!=null and userName!=''">
                INSTR(su.user_name,#{userName}) > 0
            </if>
            <if test="loginName!=null and loginName!=''">
                AND INSTR(su.login_name,#{loginName}) > 0
            </if>
            <if test="phone!=null and phone!=''">
                AND INSTR(su.phone,#{phone}) > 0
            </if>
        </where>
        ORDER BY su.update_time ASC,su.del_flag ASC
    </select>
    <!--用户详情-->
    <select id="getUserById" resultType="com.securitycontrol.entity.system.vo.UserVo">
        SELECT su.user_id AS userId,
        su.user_name AS userName,
        su.login_name AS loginName,
        su.del_flag AS delFlag,
        su.phone,
        su.org_id AS orgId,
        su.login_type AS loginType,
        su.user_type AS userType,
        su.role_id AS roleId,
        su.role_name AS roleName,
        su.status AS accountStatus
        FROM sys_user su
        WHERE user_id = #{userId}
    </select>
</mapper>