Browse Source

feat: 登录认证

WangJiaHui 1 month ago
parent
commit
6c515c482b

+ 2 - 2
pom.xml

@@ -18,10 +18,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
         </dependency>
-        <!--<dependency>
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
-        </dependency>-->
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>

+ 4 - 0
src/main/java/com/joa/backend/constant/Constants.java

@@ -18,4 +18,8 @@ public class Constants {
      */
     public static final String HTTPS = "https://";
 
+    /**
+     * 所有权限标识
+     */
+    public static final String ALL_PERMISSION = "*:*:*";
 }

+ 18 - 0
src/main/java/com/joa/backend/controller/BaseController.java

@@ -0,0 +1,18 @@
+package com.joa.backend.controller;
+
+
+import com.joa.backend.utils.ResponseResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BaseController {
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    public ResponseResult error(String msg){
+        return ResponseResult.error(msg);
+    }
+
+    public ResponseResult toResult(int rows){
+        return rows > 0 ? ResponseResult.success() : ResponseResult.error();
+    }
+}

+ 11 - 10
src/main/java/com/joa/backend/controller/SysUserController.java

@@ -3,38 +3,39 @@ package com.joa.backend.controller;
 import com.joa.backend.constant.HttpStatus;
 import com.joa.backend.entity.SysUser;
 import com.joa.backend.service.ISysUserService;
-import com.joa.backend.utils.ResultUtils;
+import com.joa.backend.utils.ResponseResult;
 import com.joa.backend.utils.SecurityUtils;
 import com.joa.backend.utils.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 @RestController
 @RequestMapping("/sys/user")
-public class SysUserController {
+public class SysUserController extends BaseController{
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     @Autowired
     private ISysUserService userService;
 
     @GetMapping("/list")
-    public ResultUtils list(SysUser sysUser){
-        return new ResultUtils(HttpStatus.SUCCESS,"请求成功",userService.selectSysUserAll(sysUser));
+    public ResponseResult list(SysUser sysUser){
+        return new ResponseResult(HttpStatus.SUCCESS,"请求成功",userService.selectSysUserAll(sysUser));
     }
 
     @PostMapping
-    public ResultUtils add(@RequestBody SysUser sysUser){
+    public ResponseResult add(@RequestBody SysUser sysUser){
         if (!userService.checkUserNameUnique(sysUser)){
-            return ResultUtils.error("新增用户:"+sysUser.getUserName()+"失败,登陆账号已存在");
+            return error("新增用户:"+sysUser.getUserName()+"失败,登陆账号已存在");
         }
         else if (StringUtils.isNotEmpty(sysUser.getPhone()) && !userService.checkPhoneUnique(sysUser)) {
-            return ResultUtils.error("新增用户:"+sysUser.getUserName()+"失败,手机号码已存在");
+            return error("新增用户:"+sysUser.getUserName()+"失败,手机号码已存在");
         }else if (StringUtils.isNotEmpty(sysUser.getEmail()) && !userService.checkEmailUnique(sysUser)){
-            return ResultUtils.error("新增用户:"+sysUser.getUserName()+"失败,邮箱账号已存在");
+            return error("新增用户:"+sysUser.getUserName()+"失败,邮箱账号已存在");
         }
-//        sysUser.setCreateBy(SecurityUtils);
+        sysUser.setCreateBy(SecurityUtils.getLoginUser().getUsername());
+        sysUser.setPassword(SecurityUtils.encryptPassword(sysUser.getPassword()));
+        return toResult(userService.insertSysUser(sysUser));
     }
 }

+ 59 - 0
src/main/java/com/joa/backend/exception/ServiceException.java

@@ -0,0 +1,59 @@
+package com.joa.backend.exception;
+
+public class ServiceException extends RuntimeException{
+    private static final long serialVersionUID = 1L;
+
+    /** 错误码 **/
+    private Integer code;
+
+    /** 错误提示 **/
+    private String message;
+
+    /** 错误明细 **/
+    private String detailMessage;
+
+    public ServiceException()
+    {
+    }
+
+    public ServiceException(String message)
+    {
+        this.message = message;
+    }
+
+    public ServiceException(String message, Integer code)
+    {
+        this.message = message;
+        this.code = code;
+    }
+
+    public String getDetailMessage()
+    {
+        return detailMessage;
+    }
+
+    @Override
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public Integer getCode()
+    {
+        return code;
+    }
+
+    public ServiceException setMessage(String message)
+    {
+        this.message = message;
+        return this;
+    }
+
+    public ServiceException setDetailMessage(String detailMessage)
+    {
+        this.detailMessage = detailMessage;
+        return this;
+    }
+
+
+}

+ 5 - 0
src/main/java/com/joa/backend/mapper/SysUserMapper.java

@@ -11,6 +11,11 @@ public interface SysUserMapper {
 
     List<SysUser> selectSysUserAll(SysUser sysUser);
 
+    /**
+     * 新增用户信息
+     */
+    int insertUser(SysUser sysUser);
+
     /**
      * 校验用户名是否唯一
      */

+ 94 - 0
src/main/java/com/joa/backend/model/LoginUser.java

@@ -0,0 +1,94 @@
+package com.joa.backend.model;
+
+import com.joa.backend.entity.SysUser;
+import lombok.Data;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.util.Collection;
+import java.util.Set;
+
+
+@Data
+public class LoginUser implements UserDetails {
+
+    private static final long serialVersionUID = 1L;
+    /* 用户ID */
+    private Long userId;
+    /* 部门ID */
+    private Long deptId;
+    /* 用户唯一标识 */
+    private String token;
+    /* 登陆时间 */
+    private Long loginTime;
+    /* 过期时间 */
+    private Long expireTime;
+    /* 登录IP地址 */
+    private String ipaddr;
+    /* 登陆地点 */
+    private String loginLocation;
+    /* 浏览器类型 */
+    private String browser;
+    /* 操作系统 */
+    private String os;
+    /* 权限列表 */
+    private Set<String> permissions;
+    /* 用户信息 */
+    private SysUser sysUser;
+
+    public LoginUser() {
+    }
+
+    public LoginUser(SysUser sysUser,Set<String> permissions) {
+        this.sysUser = sysUser;
+        this.permissions = permissions;
+    }
+
+    public LoginUser(Long userId,Long deptId,SysUser sysUser,Set<String> permissions) {
+        this.userId = userId;
+        this.deptId = deptId;
+        this.sysUser = sysUser;
+        this.permissions = permissions;
+    }
+
+    @Override
+    public Collection<? extends GrantedAuthority> getAuthorities() {
+        return null;
+    }
+
+    @Override
+    public String getPassword() {
+        return sysUser.getPassword();
+    }
+
+    @Override
+    public String getUsername() {
+        return sysUser.getUserName();
+    }
+
+    @Override
+    public boolean isAccountNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isAccountNonLocked() {
+        return true;
+    }
+
+    @Override
+    public boolean isCredentialsNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+    public SysUser getUser()
+    {
+        return sysUser;
+    }
+
+
+}

+ 8 - 0
src/main/java/com/joa/backend/service/IDeptService.java

@@ -0,0 +1,8 @@
+package com.joa.backend.service;
+
+public interface IDeptService {
+    /**
+     * 校验部门是否有数据权限
+     * */
+    void checkDeptDataScope(Long deptId);
+}

+ 4 - 0
src/main/java/com/joa/backend/service/ISysLoginService.java

@@ -0,0 +1,4 @@
+package com.joa.backend.service;
+
+public interface ISysLoginService {
+}

+ 2 - 0
src/main/java/com/joa/backend/service/ISysUserService.java

@@ -7,6 +7,8 @@ import java.util.List;
 public interface ISysUserService {
     List<SysUser> selectSysUserAll(SysUser sysUser);
 
+    int insertSysUser(SysUser sysUser);
+
     boolean checkUserNameUnique(SysUser sysUser);
 
     boolean checkPhoneUnique(SysUser sysUser);

+ 6 - 0
src/main/java/com/joa/backend/service/impl/SysUserServiceImpl.java

@@ -20,6 +20,12 @@ public class SysUserServiceImpl implements ISysUserService {
         return sysUserMapper.selectSysUserAll(sysUser);
     }
 
+    @Override
+    public int insertSysUser(SysUser sysUser) {
+        int rows = sysUserMapper.insertUser(sysUser);
+        return rows;
+    }
+
     @Override
     public boolean checkUserNameUnique(SysUser sysUser) {
         Long userId = StringUtils.isNull(sysUser.getUserId()) ? -1L : sysUser.getUserId();

+ 25 - 25
src/main/java/com/joa/backend/utils/ResultUtils.java → src/main/java/com/joa/backend/utils/ResponseResult.java

@@ -8,7 +8,7 @@ import java.util.Objects;
 /**
  * 操作消息提醒
  * */
-public class ResultUtils extends HashMap<String,Object> {
+public class ResponseResult extends HashMap<String,Object> {
     private static final long serialVersionUID = 1L;
 
     /** 状态码 */
@@ -23,7 +23,7 @@ public class ResultUtils extends HashMap<String,Object> {
     /**
      * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
      */
-    public ResultUtils()
+    public ResponseResult()
     {
     }
 
@@ -33,7 +33,7 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param code 状态码
      * @param msg 返回内容
      */
-    public ResultUtils(int code, String msg)
+    public ResponseResult(int code, String msg)
     {
         super.put(CODE_TAG, code);
         super.put(MSG_TAG, msg);
@@ -46,7 +46,7 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param msg 返回内容
      * @param data 数据对象
      */
-    public ResultUtils(int code, String msg, Object data)
+    public ResponseResult(int code, String msg, Object data)
     {
         super.put(CODE_TAG, code);
         super.put(MSG_TAG, msg);
@@ -61,9 +61,9 @@ public class ResultUtils extends HashMap<String,Object> {
      *
      * @return 成功消息
      */
-    public static ResultUtils success()
+    public static ResponseResult success()
     {
-        return ResultUtils.success("操作成功");
+        return ResponseResult.success("操作成功");
     }
 
     /**
@@ -71,9 +71,9 @@ public class ResultUtils extends HashMap<String,Object> {
      *
      * @return 成功消息
      */
-    public static ResultUtils success(Object data)
+    public static ResponseResult success(Object data)
     {
-        return ResultUtils.success("操作成功", data);
+        return ResponseResult.success("操作成功", data);
     }
 
     /**
@@ -82,9 +82,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param msg 返回内容
      * @return 成功消息
      */
-    public static ResultUtils success(String msg)
+    public static ResponseResult success(String msg)
     {
-        return ResultUtils.success(msg, null);
+        return ResponseResult.success(msg, null);
     }
 
     /**
@@ -94,9 +94,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param data 数据对象
      * @return 成功消息
      */
-    public static ResultUtils success(String msg, Object data)
+    public static ResponseResult success(String msg, Object data)
     {
-        return new ResultUtils(HttpStatus.SUCCESS, msg, data);
+        return new ResponseResult(HttpStatus.SUCCESS, msg, data);
     }
 
     /**
@@ -105,9 +105,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param msg 返回内容
      * @return 警告消息
      */
-    public static ResultUtils warn(String msg)
+    public static ResponseResult warn(String msg)
     {
-        return ResultUtils.warn(msg, null);
+        return ResponseResult.warn(msg, null);
     }
 
     /**
@@ -117,9 +117,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param data 数据对象
      * @return 警告消息
      */
-    public static ResultUtils warn(String msg, Object data)
+    public static ResponseResult warn(String msg, Object data)
     {
-        return new ResultUtils(HttpStatus.WARN, msg, data);
+        return new ResponseResult(HttpStatus.WARN, msg, data);
     }
 
     /**
@@ -127,9 +127,9 @@ public class ResultUtils extends HashMap<String,Object> {
      *
      * @return 错误消息
      */
-    public static ResultUtils error()
+    public static ResponseResult error()
     {
-        return ResultUtils.error("操作失败");
+        return ResponseResult.error("操作失败");
     }
 
     /**
@@ -138,9 +138,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param msg 返回内容
      * @return 错误消息
      */
-    public static ResultUtils error(String msg)
+    public static ResponseResult error(String msg)
     {
-        return ResultUtils.error(msg, null);
+        return ResponseResult.error(msg, null);
     }
 
     /**
@@ -150,9 +150,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param data 数据对象
      * @return 错误消息
      */
-    public static ResultUtils error(String msg, Object data)
+    public static ResponseResult error(String msg, Object data)
     {
-        return new ResultUtils(HttpStatus.ERROR, msg, data);
+        return new ResponseResult(HttpStatus.ERROR, msg, data);
     }
 
     /**
@@ -162,9 +162,9 @@ public class ResultUtils extends HashMap<String,Object> {
      * @param msg 返回内容
      * @return 错误消息
      */
-    public static ResultUtils error(int code, String msg)
+    public static ResponseResult error(int code, String msg)
     {
-        return new ResultUtils(code, msg, null);
+        return new ResponseResult(code, msg, null);
     }
 
     /**
@@ -205,7 +205,7 @@ public class ResultUtils extends HashMap<String,Object> {
      * @return 数据对象
      */
     @Override
-    public ResultUtils put(String key, Object value)
+    public ResponseResult put(String key, Object value)
     {
         super.put(key, value);
         return this;

+ 159 - 140
src/main/java/com/joa/backend/utils/SecurityUtils.java

@@ -1,7 +1,14 @@
 package com.joa.backend.utils;
 
+
+import com.joa.backend.exception.ServiceException;
 import com.joa.backend.constant.Constants;
 import com.joa.backend.constant.HttpStatus;
+import com.joa.backend.entity.SysRole;
+import com.joa.backend.model.LoginUser;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.util.PatternMatchUtils;
 
 import java.util.Collection;
@@ -13,144 +20,156 @@ import java.util.stream.Collectors;
  */
 
 public class SecurityUtils {
-//    /**
-//     * 用户ID
-//     **/
-//    public static Long getUserId()
-//    {
-//        try
-//        {
-//            return getLoginUser().getUserId();
-//        }
-//        catch (Exception e)
-//        {
-//            throw new ServiceException("获取用户ID异常", HttpStatus.UNAUTHORIZED);
-//        }
-//    }
-//
-//    /**
-//     * 获取部门ID
-//     **/
-//    public static Long getDeptId()
-//    {
-//        try
-//        {
-//            return getLoginUser().getDeptId();
-//        }
-//        catch (Exception e)
-//        {
-//            throw new ServiceException("获取部门ID异常", HttpStatus.UNAUTHORIZED);
-//        }
-//    }
-//
-//    /**
-//     * 获取用户账户
-//     **/
-//    public static String getUsername()
-//    {
-//        try
-//        {
-//            return getLoginUser().getUsername();
-//        }
-//        catch (Exception e)
-//        {
-//            throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
-//        }
-//    }
-//
-//    /**
-//     * 获取用户
-//     **/
-//    public static LoginUser getLoginUser()
-//    {
-//        try
-//        {
-//            return (LoginUser) getAuthentication().getPrincipal();
-//        }
-//        catch (Exception e)
-//        {
-//            throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
-//        }
-//    }
-//
-//    /**
-//     * 获取Authentication
-//     */
-//    public static Authentication getAuthentication()
-//    {
-//        return SecurityContextHolder.getContext().getAuthentication();
-//    }
-//
-//    /**
-//     * 生成BCryptPasswordEncoder密码
-//     *
-//     * @param password 密码
-//     * @return 加密字符串
-//     */
-//    public static String encryptPassword(String password)
-//    {
-//        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
-//        return passwordEncoder.encode(password);
-//    }
-//
-//    /**
-//     * 判断密码是否相同
-//     *
-//     * @param rawPassword 真实密码
-//     * @param encodedPassword 加密后字符
-//     * @return 结果
-//     */
-//    public static boolean matchesPassword(String rawPassword, String encodedPassword)
-//    {
-//        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
-//        return passwordEncoder.matches(rawPassword, encodedPassword);
-//    }
-//
-//    /**
-//     * 是否为管理员
-//     *
-//     * @param userId 用户ID
-//     * @return 结果
-//     */
-//    public static boolean isAdmin(Long userId)
-//    {
-//        return userId != null && 1L == userId;
-//    }
-//
-//    /**
-//     * 验证用户是否具备某权限
-//     *
-//     * @param permission 权限字符串
-//     * @return 用户是否具备某权限
-//     */
-//    public static boolean hasPermi(String permission)
-//    {
-//        return hasPermi(getLoginUser().getPermissions(), permission);
-//    }
-//
-//    /**
-//     * 判断是否包含权限
-//     *
-//     * @param authorities 权限列表
-//     * @param permission 权限字符串
-//     * @return 用户是否具备某权限
-//     */
-//    public static boolean hasPermi(Collection<String> authorities, String permission)
-//    {
-//        return authorities.stream().filter(StringUtils::hasText)
-//                .anyMatch(x -> Constants.ALL_PERMISSION.equals(x) || PatternMatchUtils.simpleMatch(x, permission));
-//    }
-//
-//    /**
-//     * 验证用户是否拥有某个角色
-//     *
-//     * @param role 角色标识
-//     * @return 用户是否具备某角色
-//     */
-//    public static boolean hasRole(String role)
-//    {
-//        List<SysRole> roleList = getLoginUser().getUser().getRoles();
-//        Collection<String> roles = roleList.stream().map(SysRole::getRoleKey).collect(Collectors.toSet());
-//        return hasRole(roles, role);
-//    }
+    /**
+     * 用户ID
+     **/
+    public static Long getUserId()
+    {
+        try
+        {
+            return getLoginUser().getUserId();
+        }
+        catch (Exception e)
+        {
+            throw new ServiceException("获取用户ID异常", HttpStatus.UNAUTHORIZED);
+        }
+    }
+
+    /**
+     * 获取部门ID
+     **/
+    public static Long getDeptId()
+    {
+        try
+        {
+            return getLoginUser().getDeptId();
+        }
+        catch (Exception e)
+        {
+            throw new ServiceException("获取部门ID异常", HttpStatus.UNAUTHORIZED);
+        }
+    }
+
+    /**
+     * 获取用户账户
+     **/
+    public static String getUsername()
+    {
+        try
+        {
+            return getLoginUser().getUsername();
+        }
+        catch (Exception e)
+        {
+            throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
+        }
+    }
+
+    /**
+     * 获取用户
+     **/
+    public static LoginUser getLoginUser()
+    {
+        try
+        {
+            return (LoginUser) getAuthentication().getPrincipal();
+        }
+        catch (Exception e)
+        {
+            throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
+        }
+    }
+
+    /**
+     * 获取Authentication
+     */
+    public static Authentication getAuthentication()
+    {
+        return SecurityContextHolder.getContext().getAuthentication();
+    }
+
+    /**
+     * 生成BCryptPasswordEncoder密码
+     *
+     * @param password 密码
+     * @return 加密字符串
+     */
+    public static String encryptPassword(String password)
+    {
+        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
+        return passwordEncoder.encode(password);
+    }
+
+    /**
+     * 判断密码是否相同
+     *
+     * @param rawPassword 真实密码
+     * @param encodedPassword 加密后字符
+     * @return 结果
+     */
+    public static boolean matchesPassword(String rawPassword, String encodedPassword)
+    {
+        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
+        return passwordEncoder.matches(rawPassword, encodedPassword);
+    }
+
+    /**
+     * 是否为管理员
+     *
+     * @param userId 用户ID
+     * @return 结果
+     */
+    public static boolean isAdmin(Long userId)
+    {
+        return userId != null && 1L == userId;
+    }
+
+    /**
+     * 验证用户是否具备某权限
+     *
+     * @param permission 权限字符串
+     * @return 用户是否具备某权限
+     */
+    public static boolean hasPermi(String permission)
+    {
+        return hasPermi(getLoginUser().getPermissions(), permission);
+    }
+
+    /**
+     * 判断是否包含权限
+     *
+     * @param authorities 权限列表
+     * @param permission 权限字符串
+     * @return 用户是否具备某权限
+     */
+    public static boolean hasPermi(Collection<String> authorities, String permission)
+    {
+        return authorities.stream().filter(StringUtils::hasText)
+                .anyMatch(x -> Constants.ALL_PERMISSION.equals(x) || PatternMatchUtils.simpleMatch(x, permission));
+    }
+
+    /**
+     * 验证用户是否拥有某个角色
+     *
+     * @param role 角色标识
+     * @return 用户是否具备某角色
+     */
+    public static boolean hasRole(String role)
+    {
+        List<SysRole> roleList = getLoginUser().getUser().getRoles();
+        Collection<String> roles = roleList.stream().map(SysRole::getRoleKey).collect(Collectors.toSet());
+        return hasRole(roles, role);
+    }
+    /**
+     * 判断是否包含角色
+     *
+     * @param roles 角色列表
+     * @param role 角色
+     * @return 用户是否具备某角色权限
+     */
+    public static boolean hasRole(Collection<String> roles, String role)
+    {
+        return roles.stream().filter(StringUtils::hasText)
+                .anyMatch(x -> Constants.SUPER_ADMIN.equals(x) || PatternMatchUtils.simpleMatch(x, role));
+    }
 }

+ 34 - 2
src/main/resources/mappers/SysUserMapper.xml

@@ -9,7 +9,7 @@
         <result property="userName" column="user_name"/>
         <result property="nickName" column="nick_name"/>
         <result property="email" column="email"/>
-            <result property="phone" column="phone"/>
+        <result property="phone" column="phone"/>
         <result property="sex" column="sex"/>
         <result property="avatar" column="avatar"/>
         <result property="password" column="password"/>
@@ -64,13 +64,45 @@
 
     </select>
 
+    <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
+        insert into sys_user(
+        <if test="userId != null and userId != 0">user_id,</if>
+        <if test="deptId != null and deptId != 0">dept_id,</if>
+        <if test="userName != null and userName != ''">user_name,</if>
+        <if test="nickName != null and nickName != ''">nick_name,</if>
+        <if test="email != null and email != ''">email,</if>
+        <if test="avatar != null and avatar != ''">avatar,</if>
+        <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
+        <if test="sex != null and sex != ''">sex,</if>
+        <if test="password != null and password != ''">password,</if>
+        <if test="status != null and status != ''">status,</if>
+        <if test="createBy != null and createBy != ''">create_by,</if>
+        <if test="remark != null and remark != ''">remark,</if>
+        create_time
+        )values(
+        <if test="userId != null and userId != ''">#{userId},</if>
+        <if test="deptId != null and deptId != ''">#{deptId},</if>
+        <if test="userName != null and userName != ''">#{userName},</if>
+        <if test="nickName != null and nickName != ''">#{nickName},</if>
+        <if test="email != null and email != ''">#{email},</if>
+        <if test="avatar != null and avatar != ''">#{avatar},</if>
+        <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
+        <if test="sex != null and sex != ''">#{sex},</if>
+        <if test="password != null and password != ''">#{password},</if>
+        <if test="status != null and status != ''">#{status},</if>
+        <if test="createBy != null and createBy != ''">#{createBy},</if>
+        <if test="remark != null and remark != ''">#{remark},</if>
+        sysdate()
+        )
+    </insert>
+
     <select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
         select user_id,user_name from sys_user where user_name = #{userName} and del_flag = '0' limit 1
     </select>
 
     <select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
         select user_id,phone from sys_user where phone = #{phone} and del_flag = '0' limit 1
-    </select>+
+    </select>
 
     <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
         select user_id,email from sys_user where email = #{email} and del_flag = '0' limit 1