JensionDzero 1 жил өмнө
parent
commit
980ca13529

+ 12 - 9
ruoyi-admin/src/main/java/com/ruoyi/web/controller/benyun/IUserinfoController.java

@@ -7,6 +7,7 @@ import com.ruoyi.system.service.AccountService;
 import com.ruoyi.system.service.IUserinfoService;
 import com.ruoyi.system.service.IUserinfoService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
@@ -29,12 +30,12 @@ public class IUserinfoController {
      * @return
      * @return
      */
      */
     @PostMapping("/createAdmin")
     @PostMapping("/createAdmin")
-    public R createAdmin(@RequestBody OpenAccountVO openAccountVO) {
+    public R createAdmin(@Validated @RequestBody OpenAccountVO openAccountVO) {
         ArrayList<Integer> integers = new ArrayList<>();
         ArrayList<Integer> integers = new ArrayList<>();
-        integers.add(1);
+        integers.add(3); //管理员
         openAccountVO.setRoles(integers);
         openAccountVO.setRoles(integers);
-        iUserinfoService.createAdmin(openAccountVO);
-        return R.ok();
+        R admin = iUserinfoService.createAdmin(openAccountVO);
+        return admin;
     }
     }
 
 
     /**
     /**
@@ -43,15 +44,17 @@ public class IUserinfoController {
      * @return
      * @return
      */
      */
     @PostMapping("/createUser")
     @PostMapping("/createUser")
-    public R createUser(@RequestBody OpenAccountVO openAccountVO) {
-        openAccountVO.setRoles(null);
-        iUserinfoService.createUser(openAccountVO);
-        return R.ok();
+    public R createUser(@Validated @RequestBody OpenAccountVO openAccountVO) {
+        ArrayList<Integer> integers = new ArrayList<>();
+        integers.add(2); //管理员
+        openAccountVO.setRoles(integers);
+        R user = iUserinfoService.createUser(openAccountVO);
+        return user;
     }
     }
 
 
 
 
     @PostMapping("/disableUser")
     @PostMapping("/disableUser")
-    public R disableUser(@RequestBody OpenAccountVO openAccountVO) {
+    public R disableUser(@Validated @RequestBody OpenAccountVO openAccountVO) {
         iUserinfoService.disableUser(openAccountVO);
         iUserinfoService.disableUser(openAccountVO);
         return R.ok();
         return R.ok();
     }
     }

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -164,7 +164,7 @@ mybatis-plus:
     # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
     # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
     # 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
     # 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
     # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
     # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
-    logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+    logImpl: org.apache.ibatis.logging.stdout.StdOutImpl #org.apache.ibatis.logging.nologging.NoLoggingImpl
 #  global-config:
 #  global-config:
 #    # 是否打印 Logo banner
 #    # 是否打印 Logo banner
 #    banner: true
 #    banner: true

+ 1 - 7
ruoyi-system/src/main/java/com/ruoyi/system/domain/OpenAccount.java

@@ -80,11 +80,6 @@ public class OpenAccount {
     @TableField("password")
     @TableField("password")
     private String password;
     private String password;
 
 
-    /**
-     * 角色列表
-     */
-    //private List<Integer> roles;
-
 
 
     /**
     /**
      * 部门ID
      * 部门ID
@@ -93,7 +88,6 @@ public class OpenAccount {
 
 
 
 
 
 
-
     /**
     /**
      * 用户类型(sys_user系统用户)
      * 用户类型(sys_user系统用户)
      */
      */
@@ -182,7 +176,7 @@ public class OpenAccount {
     }
     }
 
 
     public OpenAccount(OpenAccountVO openAccountVO) {
     public OpenAccount(OpenAccountVO openAccountVO) {
-        this.uId = openAccountVO.getUId();
+        this.uId = openAccountVO.getU_id();
         this.userName = openAccountVO.getUserName();
         this.userName = openAccountVO.getUserName();
         this.nickName = openAccountVO.getNickName();
         this.nickName = openAccountVO.getNickName();
         this.phonenumber = openAccountVO.getPhonenumber();
         this.phonenumber = openAccountVO.getPhonenumber();

+ 6 - 2
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/OpenAccountVO.java

@@ -15,9 +15,13 @@ public class OpenAccountVO implements Serializable {
     private static final long serialVersionUID = 1L;
     private static final long serialVersionUID = 1L;
 
 
     /**
     /**
-     * 统一用户id
+     * 统一用户id(uId不懂为什么用不了)
      */
      */
-    private Long uId;
+//    @NotBlank(message = "uId不能为空")
+//    private Long uId;
+
+    @NotNull(message = "u_id不能为空")
+    private Long u_id;
 
 
     /**
     /**
      * 用户账号
      * 用户账号

+ 3 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/IUserinfoService.java

@@ -1,9 +1,10 @@
 package com.ruoyi.system.service;
 package com.ruoyi.system.service;
 
 
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.system.domain.vo.OpenAccountVO;
 import com.ruoyi.system.domain.vo.OpenAccountVO;
 
 
 public interface IUserinfoService {
 public interface IUserinfoService {
-    void createAdmin(OpenAccountVO openAccountVO);
-    void createUser(OpenAccountVO openAccountVO);
+    R createAdmin(OpenAccountVO openAccountVO);
+    R createUser(OpenAccountVO openAccountVO);
     void disableUser(OpenAccountVO openAccountVO);
     void disableUser(OpenAccountVO openAccountVO);
 }
 }

+ 62 - 17
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IUserinfoServiceImpl.java

@@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.system.domain.OpenAccount;
 import com.ruoyi.system.domain.OpenAccount;
 import com.ruoyi.system.domain.SysUserRole;
 import com.ruoyi.system.domain.SysUserRole;
 import com.ruoyi.system.domain.vo.OpenAccountVO;
 import com.ruoyi.system.domain.vo.OpenAccountVO;
@@ -9,44 +10,88 @@ import com.ruoyi.system.mapper.IUserinfoMapper;
 import com.ruoyi.system.mapper.SysUserRoleMapper;
 import com.ruoyi.system.mapper.SysUserRoleMapper;
 import com.ruoyi.system.service.IUserinfoService;
 import com.ruoyi.system.service.IUserinfoService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
+import java.util.List;
+
 @Service
 @Service
 @RequiredArgsConstructor
 @RequiredArgsConstructor
 @Transactional
 @Transactional
 public class IUserinfoServiceImpl implements IUserinfoService {
 public class IUserinfoServiceImpl implements IUserinfoService {
-
-    private final IUserinfoMapper iUserinfoMapper;
+    @Autowired
+    IUserinfoMapper iUserinfoMapper;
     private final SysUserRoleMapper userRoleMapper;
     private final SysUserRoleMapper userRoleMapper;
 
 
 
 
     @Override
     @Override
-    public void createAdmin(OpenAccountVO openAccountVO) {
-        //注册用户
-        OpenAccount openAccount = new OpenAccount(openAccountVO);
-        iUserinfoMapper.insert(openAccount);
-        //设置权限
-        for (Integer role : openAccountVO.getRoles()) {
-            SysUserRole sysUserRole = new SysUserRole();
-            sysUserRole.setUserId(openAccount.getUserId());
-            sysUserRole.setRoleId(Long.valueOf(role));
-            userRoleMapper.insert(sysUserRole);
+    public R createAdmin(OpenAccountVO openAccountVO) {
+        //检查用户名称、Uid是否重复
+        String s = checkUIdAndUserName(openAccountVO);
+        if (s == null){
+            //注册用户
+            OpenAccount openAccount = new OpenAccount(openAccountVO);
+            iUserinfoMapper.insert(openAccount);
+            //设置角色
+            for (Integer role : openAccountVO.getRoles()) {
+                SysUserRole sysUserRole = new SysUserRole();
+                sysUserRole.setUserId(openAccount.getUserId());
+                sysUserRole.setRoleId(Long.valueOf(role));
+                userRoleMapper.insert(sysUserRole);
+            }
+            return R.ok();
         }
         }
-
+        return R.fail(s);
     }
     }
 
 
     @Override
     @Override
-    public void createUser(OpenAccountVO openAccountVO) {
-        OpenAccount openAccount = new OpenAccount(openAccountVO);
-        iUserinfoMapper.insert(openAccount);
+    public R createUser(OpenAccountVO openAccountVO) {
+        //检查用户名称、Uid是否重复
+        String s = checkUIdAndUserName(openAccountVO);
+        if (s == null){
+            //注册用户
+            OpenAccount openAccount = new OpenAccount(openAccountVO);
+            iUserinfoMapper.insert(openAccount);
+            //设置角色
+            for (Integer role : openAccountVO.getRoles()) {
+                SysUserRole sysUserRole = new SysUserRole();
+                sysUserRole.setUserId(openAccount.getUserId());
+                sysUserRole.setRoleId(Long.valueOf(role));
+                userRoleMapper.insert(sysUserRole);
+            }
+            return R.ok();
+        }
+        return R.fail(s);
     }
     }
 
 
     @Override
     @Override
     public void disableUser(OpenAccountVO openAccountVO) {
     public void disableUser(OpenAccountVO openAccountVO) {
         UpdateWrapper<OpenAccount> updateWrapper = new UpdateWrapper<>();
         UpdateWrapper<OpenAccount> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("u_id",openAccountVO.getUId());
+        updateWrapper.eq("u_id",openAccountVO.getU_id());
         updateWrapper.set("delFlag",2);
         updateWrapper.set("delFlag",2);
         iUserinfoMapper.update(null,updateWrapper);
         iUserinfoMapper.update(null,updateWrapper);
     }
     }
+
+    /**
+     * 判断用户是否存在
+     * */
+    public String checkUIdAndUserName(OpenAccountVO openAccountVO){
+        //判断u_id 和 用户名称是否存在
+        QueryWrapper<OpenAccount> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("u_id","user_name");
+        queryWrapper.eq("u_id",openAccountVO.getU_id());
+        queryWrapper.or();
+        queryWrapper.eq("user_name",openAccountVO.getUserName());
+        List<OpenAccount> openAccounts = iUserinfoMapper.selectList(queryWrapper);
+        if (!openAccounts.isEmpty()){
+            if (openAccounts.size() == 2)
+                return "u_id、userName已存在";
+            else if (openAccounts.get(0).getUId() == openAccountVO.getU_id())
+                return "u_id已存在";
+            else
+                return "userName已存在";
+        }
+        return null;
+    }
 }
 }