feat:用户添加校验

new-exam
wangxy 5 months ago
parent 9089e411c7
commit 765fe6f253

@ -5,7 +5,11 @@ import java.util.stream.Collectors;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.pinyin.PinyinUtil; 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 com.ruoyi.web.controller.manager.UserRecordManager;
import lombok.val;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -31,10 +35,6 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.shiro.service.SysPasswordService; import com.ruoyi.framework.shiro.service.SysPasswordService;
import com.ruoyi.framework.shiro.util.AuthorizationUtils; 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 @Autowired
private UserRecordManager userRecordManager; private UserRecordManager userRecordManager;
@Autowired
private ISysDictDataService dictDataService;
@RequiresPermissions("system:user:view") @RequiresPermissions("system:user:view")
@GetMapping() @GetMapping()
public String user() { public String user() {
@ -134,6 +137,15 @@ public class SysUserController extends BaseController {
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在"); return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
} }
List<SysDictData> 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.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
user.setCreateBy(getLoginName()); 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));
}
} }

@ -5,6 +5,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser; 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.UserCountDTO;
import com.ruoyi.system.domain.count.UserSmCountDTO; import com.ruoyi.system.domain.count.UserSmCountDTO;
@ -133,4 +134,7 @@ public interface SysUserMapper extends BaseMapper<SysUser>
public UserCountDTO selectCountUser(); public UserCountDTO selectCountUser();
public UserSmCountDTO selectCountSmUser(); public UserSmCountDTO selectCountSmUser();
public int checkUser(UserCheckDTO userCheckDTO);
} }

@ -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.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SysUserRole; 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.UserCountDTO;
import com.ruoyi.system.domain.count.UserSmCountDTO; import com.ruoyi.system.domain.count.UserSmCountDTO;
@ -234,4 +235,11 @@ public interface ISysUserService extends IService<SysUser>
public UserSmCountDTO selectCountSmUser(); public UserSmCountDTO selectCountSmUser();
/**
*
* @return
*/
public int checkUser(UserCheckDTO userCheckDTO);
} }

@ -7,6 +7,7 @@ import javax.validation.Validator;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysDept; 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.UserCountDTO;
import com.ruoyi.system.domain.count.UserSmCountDTO; import com.ruoyi.system.domain.count.UserSmCountDTO;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -594,4 +595,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper,SysUser> imple
public UserSmCountDTO selectCountSmUser() { public UserSmCountDTO selectCountSmUser() {
return userMapper.selectCountSmUser(); return userMapper.selectCountSmUser();
} }
@Override
public int checkUser(UserCheckDTO userCheckDTO) {
return userMapper.checkUser(userCheckDTO);
}
} }

@ -335,8 +335,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SUM (CASE WHEN shemichengdu = 2 THEN 1 ELSE 0 END) AS hx SUM (CASE WHEN shemichengdu = 2 THEN 1 ELSE 0 END) AS hx
from ${prefix}sys_user where status='0' and del_flag='0' from ${prefix}sys_user where status='0' and del_flag='0'
</select> </select>
<select id="checkUser" parameterType="UserCheckDTO" resultType="java.lang.Integer">
SELECT COUNT(*) as total
FROM
${prefix}sys_user e
WHERE
e.dept_id = #{deptId} and e.del_flag !='2'
AND EXISTS (
SELECT
1
FROM
${prefix}sys_role
A LEFT JOIN ${prefix}sys_user_role r ON A.role_id = r.role_id
WHERE
r.user_id = e.user_id
AND A.role_id = #{roleId} AND role_key != #{roleKey} );
</select>
</mapper>
</mapper>
Loading…
Cancel
Save