From 765fe6f253d1dd6ce26e492b989136fe68e6dd72 Mon Sep 17 00:00:00 2001 From: wangxy <1481820854@qq.com> Date: Thu, 14 Nov 2024 19:34:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=94=A8=E6=88=B7=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/system/SysUserController.java | 27 ++++++++++++++++--- .../ruoyi/system/mapper/SysUserMapper.java | 4 +++ .../ruoyi/system/service/ISysUserService.java | 8 ++++++ .../service/impl/SysUserServiceImpl.java | 6 +++++ .../resources/mapper/system/SysUserMapper.xml | 20 +++++++++++--- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java index b3313bf..65b262e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java @@ -5,7 +5,11 @@ import java.util.stream.Collectors; import cn.hutool.core.util.RandomUtil; import cn.hutool.extra.pinyin.PinyinUtil; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.system.domain.UserCheckDTO; +import com.ruoyi.system.service.*; import com.ruoyi.web.controller.manager.UserRecordManager; +import lombok.val; import org.apache.commons.lang3.ArrayUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.slf4j.Logger; @@ -31,10 +35,6 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.shiro.service.SysPasswordService; import com.ruoyi.framework.shiro.util.AuthorizationUtils; -import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysPostService; -import com.ruoyi.system.service.ISysRoleService; -import com.ruoyi.system.service.ISysUserService; /** * 用户信息 @@ -65,6 +65,9 @@ public class SysUserController extends BaseController { @Autowired private UserRecordManager userRecordManager; + @Autowired + private ISysDictDataService dictDataService; + @RequiresPermissions("system:user:view") @GetMapping() public String user() { @@ -134,6 +137,15 @@ public class SysUserController extends BaseController { } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在"); } + List smType = dictDataService.selectDictDataByType("sys_role_key"); + UserCheckDTO userCheckDTO = new UserCheckDTO(); + userCheckDTO.setDeptId(user.getDeptId()); + userCheckDTO.setRoleId(user.getRoleIds()[0]); + userCheckDTO.setRoleKey(smType.get(0).getDictValue()); + int total = userService.checkUser(userCheckDTO); + if(total>=1){ + return error("新增用户'" + user.getLoginName() + "'在当前部门该角色下账号已存在,不能重复新增"); + } user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(getLoginName()); @@ -357,4 +369,11 @@ public class SysUserController extends BaseController { } + @PostMapping("/checkUser") + @ResponseBody + public AjaxResult checkUser(UserCheckDTO userCheckDTO) { + return success(userService.checkUser(userCheckDTO)); + } + + } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index c077739..a3221d5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -5,6 +5,7 @@ import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.system.domain.UserCheckDTO; import com.ruoyi.system.domain.count.UserCountDTO; import com.ruoyi.system.domain.count.UserSmCountDTO; @@ -133,4 +134,7 @@ public interface SysUserMapper extends BaseMapper public UserCountDTO selectCountUser(); public UserSmCountDTO selectCountSmUser(); + + + public int checkUser(UserCheckDTO userCheckDTO); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java index e41560b..a344941 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.domain.UserCheckDTO; import com.ruoyi.system.domain.count.UserCountDTO; import com.ruoyi.system.domain.count.UserSmCountDTO; @@ -234,4 +235,11 @@ public interface ISysUserService extends IService public UserSmCountDTO selectCountSmUser(); + + + /** + * 校验用户一个部门下一个角色 + * @return + */ + public int checkUser(UserCheckDTO userCheckDTO); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index f5d484a..dc4c73f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -7,6 +7,7 @@ import javax.validation.Validator; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.system.domain.UserCheckDTO; import com.ruoyi.system.domain.count.UserCountDTO; import com.ruoyi.system.domain.count.UserSmCountDTO; import org.slf4j.Logger; @@ -594,4 +595,9 @@ public class SysUserServiceImpl extends ServiceImpl imple public UserSmCountDTO selectCountSmUser() { return userMapper.selectCountSmUser(); } + + @Override + public int checkUser(UserCheckDTO userCheckDTO) { + return userMapper.checkUser(userCheckDTO); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 440c2c1..998b209 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -335,8 +335,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SUM (CASE WHEN shemichengdu = 2 THEN 1 ELSE 0 END) AS hx from ${prefix}sys_user where status='0' and del_flag='0' + - - - \ No newline at end of file + \ No newline at end of file