使用mybatis-flex重构“用户管理”模块代码
This commit is contained in:
parent
5e147e2f88
commit
1fe08a0945
2
pom.xml
2
pom.xml
@ -18,7 +18,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>17</java.version>
|
||||
<spring-boot.version>3.1.4</spring-boot.version>
|
||||
<mybatis-flex.version>1.6.8</mybatis-flex.version>
|
||||
<mybatis-flex.version>1.7.1</mybatis-flex.version>
|
||||
<satoken.version>1.36.0</satoken.version>
|
||||
<mysql.version>8.0.33</mysql.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysMenu;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.*;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -94,7 +95,7 @@ public class AuthController {
|
||||
|
||||
//TODO:多租户 超级管理员 如果重新加载用户信息需清除动态租户
|
||||
|
||||
SysUser user = sysUserService.selectUserById(loginUser.getUserId());
|
||||
SysUserVo user = sysUserService.selectUserById(loginUser.getUserId());
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(user.getUserId());
|
||||
// 权限集合
|
||||
@ -117,7 +118,7 @@ public class AuthController {
|
||||
{
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
// 用户信息
|
||||
SysUser user = sysUserService.selectUserById(loginUser.getUserId());
|
||||
SysUserVo user = sysUserService.selectUserById(loginUser.getUserId());
|
||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getUserId());
|
||||
return AjaxResult.success(menuService.buildMenus(menus));
|
||||
}
|
||||
@ -126,9 +127,9 @@ public class AuthController {
|
||||
* 退出登录
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public AjaxResult logout() {
|
||||
public R<Void> logout() {
|
||||
loginService.logout();
|
||||
return AjaxResult.success("退出成功!");
|
||||
return R.ok("退出成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,8 +15,10 @@ import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.tenant.helper.TenantHelper;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysPermissionService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -49,7 +51,7 @@ public class SysLoginService {
|
||||
|
||||
private final ISysPermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
/**
|
||||
@ -105,7 +107,7 @@ public class SysLoginService {
|
||||
/**
|
||||
* 构建登录用户
|
||||
*/
|
||||
public LoginUser buildLoginUser(SysUser user) {
|
||||
public LoginUser buildLoginUser(SysUserVo user) {
|
||||
LoginUser loginUser = new LoginUser();
|
||||
loginUser.setTenantId(user.getTenantId());
|
||||
loginUser.setUserId(user.getUserId());
|
||||
@ -127,7 +129,7 @@ public class SysLoginService {
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
public void recordLoginInfo(Long userId) {
|
||||
SysUser sysUser = new SysUser();
|
||||
SysUserBo sysUser = new SysUserBo();
|
||||
sysUser.setUserId(userId);
|
||||
sysUser.setLoginIp(ServletUtils.getClientIP());
|
||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
|
@ -56,7 +56,7 @@ public class SysRegisterService
|
||||
if (captchaEnabled) {
|
||||
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid());
|
||||
}
|
||||
SysUser sysUser = new SysUser();
|
||||
SysUserBo sysUser = new SysUserBo();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPassword(BCrypt.hashpw(password));
|
||||
|
@ -4,7 +4,10 @@ import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
@ -38,8 +41,12 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class EmailAuthStrategy implements IAuthStrategy {
|
||||
|
||||
@Resource
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
// private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public void validate(LoginBody loginBody) {
|
||||
@ -53,7 +60,7 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
String emailCode = loginBody.getEmailCode();
|
||||
|
||||
// 通过邮箱查找用户
|
||||
SysUser user = loadUserByEmail(tenantId, email);
|
||||
SysUserVo user = loadUserByEmail(tenantId, email);
|
||||
|
||||
loginService.checkLogin(LoginType.EMAIL, tenantId, user.getUserName(), () -> !validateEmailCode(tenantId, email, emailCode));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
@ -91,12 +98,12 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
return code.equals(emailCode);
|
||||
}
|
||||
|
||||
private SysUser loadUserByEmail(Long tenantId, String email) {
|
||||
private SysUserVo loadUserByEmail(Long tenantId, String email) {
|
||||
// SysUser user = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||
// .select(SysUser::getEmail, SysUser::getStatus)
|
||||
// .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId)
|
||||
// .eq(SysUser::getEmail, email));
|
||||
SysUser user =userMapper.selectUserByEmail(email);
|
||||
SysUserVo user =userService.selectUserByEmail(email);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", email);
|
||||
throw new UserException("user.not.exists", email);
|
||||
|
@ -49,7 +49,6 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
//private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public void validate(LoginBody loginBody) {
|
||||
@ -70,7 +69,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
validateCaptcha(tenantId, username, code, uuid);
|
||||
}
|
||||
|
||||
SysUser user = loadUserByUsername(tenantId, username);
|
||||
SysUserVo user = loadUserByUsername(tenantId, username);
|
||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
||||
LoginUser loginUser = loginService.buildLoginUser(user);
|
||||
@ -118,9 +117,9 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
private SysUser loadUserByUsername(Long tenantId, String username) {
|
||||
private SysUserVo loadUserByUsername(Long tenantId, String username) {
|
||||
//TODO:以后根据tenantId条件过滤查询:
|
||||
SysUser user = userService.selectUserByUserName(username);
|
||||
SysUserVo user = userService.selectUserByUserName(username);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
throw new UserException("user.not.exists", username);
|
||||
|
@ -117,7 +117,7 @@ management:
|
||||
--- # 监控中心客户端配置
|
||||
spring.boot.admin.client:
|
||||
# 增加客户端开关
|
||||
enabled: true
|
||||
enabled: false
|
||||
url: http://localhost:9090/admin
|
||||
instance:
|
||||
service-host-type: IP
|
||||
@ -128,7 +128,7 @@ spring.boot.admin.client:
|
||||
powerjob:
|
||||
worker:
|
||||
# 如何开启调度中心请查看文档教程
|
||||
enabled: true
|
||||
enabled: false
|
||||
# 需要先在 powerjob 登录页执行应用注册后才能使用
|
||||
app-name: ruoyi-worker
|
||||
# 28080 端口 随着主应用端口飘逸 避免集群冲突
|
||||
|
@ -24,11 +24,11 @@ public class BaseEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private Long tenantId;
|
||||
// /**
|
||||
// * 租户编号
|
||||
// */
|
||||
// @Column(ignore = true)
|
||||
// private Long tenantId;
|
||||
|
||||
/**
|
||||
* 搜索值
|
||||
|
@ -18,7 +18,6 @@ public class TenantEntity extends BaseEntity {
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
//@NotNull(message = "id不能为空", groups = { EditGroup.class })
|
||||
private Long tenantId;
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import java.lang.reflect.Method;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysRole;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
@ -61,7 +64,7 @@ public class DataScopeAspect
|
||||
public static final String DATA_SCOPE = "dataScope";
|
||||
|
||||
@Resource
|
||||
private SysUserMapper userMapper;
|
||||
private ISysUserService userService;
|
||||
|
||||
// 配置织入点
|
||||
@Pointcut("@annotation(com.ruoyi.common.core.annotation.DataScope)")
|
||||
@ -89,11 +92,11 @@ public class DataScopeAspect
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (StringUtils.isNotNull(loginUser))
|
||||
{
|
||||
Long usetId=loginUser.getUserId();
|
||||
if (usetId>0){
|
||||
SysUser currentUser = userMapper.selectUserById(usetId);
|
||||
Long userId=loginUser.getUserId();
|
||||
if (userId>0){
|
||||
SysUserVo currentUser = userService.selectUserById(userId);
|
||||
// 如果是超级管理员,则不过滤数据
|
||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||
if (StringUtils.isNotNull(currentUser) && !LoginHelper.isSuperAdmin(userId))
|
||||
{
|
||||
// String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
|
||||
// dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
||||
@ -130,12 +133,12 @@ public class DataScopeAspect
|
||||
* @param deptAlias 部门别名
|
||||
* @param userAlias 用户别名
|
||||
*/
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUserVo user, String deptAlias, String userAlias)
|
||||
{
|
||||
StringBuilder sqlString = new StringBuilder();
|
||||
List<String> conditions = new ArrayList<>();
|
||||
|
||||
for (SysRole role : user.getRoles())
|
||||
for (SysRoleVo role : user.getRoles())
|
||||
{
|
||||
String dataScope = role.getDataScope();
|
||||
if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope))
|
||||
|
@ -11,6 +11,7 @@ import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.system.domain.bo.SysPostBo;
|
||||
import com.ruoyi.system.domain.vo.SysPostVo;
|
||||
import com.ruoyi.system.service.ISysUserPostService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -39,6 +40,8 @@ public class SysPostController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ISysPostService postService;
|
||||
@Resource
|
||||
private ISysUserPostService userPostService;
|
||||
|
||||
/**
|
||||
* 获取岗位列表
|
||||
@ -109,7 +112,7 @@ public class SysPostController extends BaseController
|
||||
return R.fail("修改岗位'" + postBo.getPostName() + "'失败,岗位编码已存在");
|
||||
}
|
||||
else if (UserConstants.POST_DISABLE.equals(postBo.getStatus())
|
||||
&& postService.countUserPostById(postBo.getPostId()) > 0) {
|
||||
&& userPostService.countUserPostById(postBo.getPostId()) > 0) {
|
||||
return R.fail("该岗位下存在已分配用户,不能禁用!");
|
||||
}
|
||||
Boolean updated = postService.updatePost(postBo);
|
||||
|
@ -1,20 +1,23 @@
|
||||
package com.ruoyi.system.controller.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.ruoyi.common.core.core.domain.R;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.bo.SysUserProfileBo;
|
||||
import com.ruoyi.system.domain.vo.AvatarVo;
|
||||
import com.ruoyi.system.domain.vo.ProfileVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.core.config.RuoYiConfig;
|
||||
import com.ruoyi.common.web.core.BaseController;
|
||||
@ -26,6 +29,8 @@ import com.ruoyi.common.core.utils.file.MimeTypeUtils;
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 个人信息 业务处理
|
||||
*
|
||||
@ -44,14 +49,15 @@ public class SysProfileController extends BaseController
|
||||
* 个人信息
|
||||
*/
|
||||
@GetMapping
|
||||
public AjaxResult profile()
|
||||
public R<ProfileVo> profile()
|
||||
{
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
SysUser user = userService.selectUserById(loginUser.getUserId());
|
||||
AjaxResult ajax = AjaxResult.success(user);
|
||||
ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
|
||||
ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
|
||||
return ajax;
|
||||
SysUserVo user = userService.selectUserById(loginUser.getUserId());
|
||||
ProfileVo profileVo = new ProfileVo();
|
||||
profileVo.setUser(user);
|
||||
profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserName()));
|
||||
profileVo.setPostGroup(userService.selectUserPostGroup(user.getUserName()));
|
||||
return R.ok(profileVo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,34 +65,29 @@ public class SysProfileController extends BaseController
|
||||
*/
|
||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult updateProfile(@RequestBody SysUser user)
|
||||
public R<Void> updateProfile(@RequestBody SysUserProfileBo profile)
|
||||
{
|
||||
SysUserBo user = BeanUtil.toBean(profile, SysUserBo.class);
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
SysUser sysUser = userService.selectUserById(loginUser.getUserId());
|
||||
SysUserVo sysUser = userService.selectUserById(loginUser.getUserId());
|
||||
user.setUserName(sysUser.getUserName());
|
||||
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
||||
{
|
||||
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
||||
{
|
||||
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
user.setUserId(sysUser.getUserId());
|
||||
user.setPassword(null);
|
||||
user.setAvatar(null);
|
||||
user.setDeptId(null);
|
||||
if (userService.updateUserProfile(user) > 0)
|
||||
// user.setPassword(null);
|
||||
// user.setAvatar(null);
|
||||
// user.setDeptId(null);
|
||||
if (userService.updateUserProfile(user))
|
||||
{
|
||||
// // 更新缓存用户信息
|
||||
// sysUser.setNickName(user.getNickName());
|
||||
// sysUser.setPhonenumber(user.getPhonenumber());
|
||||
// sysUser.setEmail(user.getEmail());
|
||||
// sysUser.setSex(user.getSex());
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
return success();
|
||||
return R.ok();
|
||||
}
|
||||
return error("修改个人信息异常,请联系管理员");
|
||||
return R.fail("修改个人信息异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,43 +95,49 @@ public class SysProfileController extends BaseController
|
||||
*/
|
||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/updatePwd")
|
||||
public AjaxResult updatePwd(String oldPassword, String newPassword)
|
||||
public R<Void> updatePwd(String oldPassword, String newPassword)
|
||||
{
|
||||
SysUser sysUser = userService.selectUserById(LoginHelper.getUserId());
|
||||
SysUserVo sysUser = userService.selectUserById(LoginHelper.getUserId());
|
||||
String userName = sysUser.getUserName();
|
||||
String password = sysUser.getPassword();
|
||||
if (!BCrypt.checkpw(oldPassword, password)) {
|
||||
return error("修改密码失败,旧密码错误");
|
||||
return R.fail("修改密码失败,旧密码错误");
|
||||
}
|
||||
if (BCrypt.checkpw(newPassword, password)) {
|
||||
return error("新密码不能与旧密码相同");
|
||||
return R.fail("新密码不能与旧密码相同");
|
||||
}
|
||||
if (userService.resetUserPwd(userName, BCrypt.hashpw(newPassword)) > 0)
|
||||
if (userService.resetUserPwd(userName, BCrypt.hashpw(newPassword)))
|
||||
{
|
||||
return success();
|
||||
return R.ok();
|
||||
}
|
||||
return error("修改密码异常,请联系管理员");
|
||||
return R.fail("修改密码异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像上传
|
||||
*/
|
||||
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/avatar")
|
||||
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception
|
||||
@PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<AvatarVo> avatar(@RequestPart("avatarfile") MultipartFile file) throws Exception
|
||||
{
|
||||
if (!file.isEmpty())
|
||||
{
|
||||
String extension = FileUtil.extName(file.getOriginalFilename());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) {
|
||||
return R.fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式");
|
||||
}
|
||||
|
||||
//TODO:需要使用OSS来存储操作用户上传的头像
|
||||
SysUser sysUser = userService.selectUserById(LoginHelper.getUserId());
|
||||
|
||||
SysUserVo sysUser = userService.selectUserById(LoginHelper.getUserId());
|
||||
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
|
||||
if (userService.updateUserAvatar(sysUser.getUserName(), avatar))
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("imgUrl", avatar);
|
||||
return ajax;
|
||||
AvatarVo avatarVo = new AvatarVo();
|
||||
avatarVo.setImgUrl(avatar);
|
||||
return R.ok(avatarVo);
|
||||
}
|
||||
}
|
||||
return error("上传图片异常,请联系管理员");
|
||||
return R.fail("上传图片异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,10 @@ import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysDeptBo;
|
||||
import com.ruoyi.system.domain.bo.SysRoleBo;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.DeptTreeSelectVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysUserRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@ -27,7 +29,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.web.core.BaseController;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
@ -178,25 +179,21 @@ public class SysRoleController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询已分配用户角色列表
|
||||
* 查询已分配用户角色分页列表
|
||||
*/
|
||||
@SaCheckPermission("system:role:list")
|
||||
@GetMapping("/authUser/allocatedList")
|
||||
public TableDataInfo allocatedList(SysUser user) {
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectAllocatedList(user);
|
||||
return getDataTable(list);
|
||||
public TableDataInfo<SysUserVo> allocatedList(SysUserBo userBo) {
|
||||
return userService.selectAllocatedPage(userBo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未分配用户角色列表
|
||||
* 查询未分配用户角色分页列表
|
||||
*/
|
||||
@SaCheckPermission("system:role:list")
|
||||
@GetMapping("/authUser/unallocatedList")
|
||||
public TableDataInfo unallocatedList(SysUser user) {
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectUnallocatedList(user);
|
||||
return getDataTable(list);
|
||||
public TableDataInfo<SysUserVo> unallocatedList(SysUserBo userBo) {
|
||||
return userService.selectUnallocatedPage(userBo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,26 +1,34 @@
|
||||
package com.ruoyi.system.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.mask.MaskManager;
|
||||
import com.ruoyi.common.core.core.domain.R;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||
import com.ruoyi.common.core.utils.StreamUtils;
|
||||
import com.ruoyi.common.excel.core.ExcelResult;
|
||||
import com.ruoyi.common.excel.utils.ExcelUtil;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.system.domain.SysDept;
|
||||
import com.ruoyi.system.domain.SysPost;
|
||||
import com.ruoyi.system.domain.SysRole;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.common.tenant.helper.TenantHelper;
|
||||
import com.ruoyi.system.domain.bo.SysDeptBo;
|
||||
import com.ruoyi.system.domain.bo.SysPostBo;
|
||||
import com.ruoyi.system.domain.bo.SysRoleBo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.*;
|
||||
import com.ruoyi.system.listener.SysUserImportListener;
|
||||
import com.ruoyi.system.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -36,7 +44,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.web.core.BaseController;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
@ -65,10 +73,8 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("system:user:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysUser user) {
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectUserList(user);
|
||||
return getDataTable(list);
|
||||
public TableDataInfo<SysUserVo> list(SysUserBo userBo) {
|
||||
return userService.selectPage(userBo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,10 +83,10 @@ public class SysUserController extends BaseController {
|
||||
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||
@SaCheckPermission("system:user:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysUser user) {
|
||||
List<SysUser> list = userService.selectUserList(user);
|
||||
ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class);
|
||||
util.exportExcel(response, list, "用户数据");
|
||||
public void export(HttpServletResponse response, SysUserBo userBo) {
|
||||
List<SysUserVo> list = userService.selectUserList(userBo);
|
||||
List<SysUserExportVo> listVo = MapstructUtils.convert(list, SysUserExportVo.class);
|
||||
ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,19 +98,37 @@ public class SysUserController extends BaseController {
|
||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
@SaCheckPermission("system:user:import")
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
||||
ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class);
|
||||
List<SysUser> userList = util.importExcel(file.getInputStream());
|
||||
Long operId = LoginHelper.getUserId();
|
||||
//TODO 以后需要改造,使用common-excel工具ExcelUtil.importExcel导出
|
||||
String message = userService.importUser(userList, updateSupport, operId);
|
||||
return success(message);
|
||||
public R<Void> importData(MultipartFile file, boolean updateSupport) throws Exception {
|
||||
ExcelResult<SysUserImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class, new SysUserImportListener(updateSupport));
|
||||
return R.ok(result.getAnalysis());
|
||||
}
|
||||
|
||||
@PostMapping("/importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class);
|
||||
util.importTemplateExcel(response, "用户数据");
|
||||
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
@GetMapping("/getInfo")
|
||||
public R<UserInfoVo> getInfo() {
|
||||
UserInfoVo userInfoVo = new UserInfoVo();
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
|
||||
// 超级管理员 如果重新加载用户信息需清除动态租户
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
SysUserVo user = userService.selectUserById(loginUser.getUserId());
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
return R.fail("没有权限访问用户数据!");
|
||||
}
|
||||
userInfoVo.setUser(user);
|
||||
userInfoVo.setPermissions(loginUser.getMenuPermission());
|
||||
userInfoVo.setRoles(loginUser.getRolePermission());
|
||||
return R.ok(userInfoVo);
|
||||
}
|
||||
|
||||
|
||||
@ -113,21 +137,34 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("system:user:query")
|
||||
@GetMapping(value = {"/", "/{userId}"})
|
||||
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
public R<SysUserInfoVo> getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||
userService.checkUserDataScope(userId);
|
||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||
|
||||
SysRoleBo sysRole = new SysRoleBo();
|
||||
sysRole.setStatus(UserConstants.ROLE_NORMAL);
|
||||
List<SysRoleVo> roles = roleService.selectRoleList(sysRole);
|
||||
SysPostBo sysPost = new SysPostBo();
|
||||
sysPost.setStatus(UserConstants.POST_NORMAL);
|
||||
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
||||
ajax.put("posts", postService.selectPostList(sysPost));
|
||||
if (StringUtils.isNotNull(userId)) {
|
||||
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
|
||||
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
||||
ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
|
||||
userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin()));
|
||||
userInfoVo.setPosts(postService.selectPostList(sysPost));
|
||||
if (ObjectUtil.isNotNull(userId)) {
|
||||
//暂时取消脱敏处理
|
||||
SysUserVo sysUser;
|
||||
try{
|
||||
MaskManager.skipMask();
|
||||
sysUser = userService.selectUserById(userId);
|
||||
} finally {
|
||||
MaskManager.restoreMask();
|
||||
}
|
||||
return ajax;
|
||||
userInfoVo.setUser(sysUser);
|
||||
|
||||
List<SysRoleVo> userRoles = roleService.selectUserRolesByUserId(userId);
|
||||
userInfoVo.setRoleIds(StreamUtils.toList(userRoles, SysRoleVo::getRoleId));
|
||||
//userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getRoleId));
|
||||
userInfoVo.setPostIds(postService.selectPostListByUserId(userId));
|
||||
}
|
||||
return R.ok(userInfoVo);
|
||||
}
|
||||
|
||||
|
||||
@ -137,18 +174,20 @@ public class SysUserController extends BaseController {
|
||||
@SaCheckPermission("system:user:add")
|
||||
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody SysUser user) {
|
||||
if (!userService.checkUserNameUnique(user)) {
|
||||
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||
return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
public R<Void> add(@Validated @RequestBody SysUserBo userBo) {
|
||||
if (!userService.checkUserNameUnique(userBo)) {
|
||||
return R.fail("新增用户'" + userBo.getUserName() + "'失败,登录账号已存在");
|
||||
} else if (StringUtils.isNotEmpty(userBo.getPhonenumber()) && !userService.checkPhoneUnique(userBo)) {
|
||||
return R.fail("新增用户'" + userBo.getUserName() + "'失败,手机号码已存在");
|
||||
} else if (StringUtils.isNotEmpty(userBo.getEmail()) && !userService.checkEmailUnique(userBo)) {
|
||||
return R.fail("新增用户'" + userBo.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
user.setCreateBy(LoginHelper.getUserId());
|
||||
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||
//SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
|
||||
return toAjax(userService.insertUser(user));
|
||||
userBo.setPassword(BCrypt.hashpw(userBo.getPassword()));
|
||||
boolean inserted = userService.insertUser(userBo);
|
||||
if (!inserted) {
|
||||
return R.fail("新增用户记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,18 +196,21 @@ public class SysUserController extends BaseController {
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody SysUser user) {
|
||||
userService.checkUserAllowed(user);
|
||||
userService.checkUserDataScope(user.getUserId());
|
||||
if (!userService.checkUserNameUnique(user)) {
|
||||
return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
public R<Void> edit(@Validated @RequestBody SysUserBo userBo) {
|
||||
userService.checkUserAllowed(userBo.getUserId());
|
||||
userService.checkUserDataScope(userBo.getUserId());
|
||||
if (!userService.checkUserNameUnique(userBo)) {
|
||||
return R.fail("修改用户'" + userBo.getUserName() + "'失败,登录账号已存在");
|
||||
} else if (StringUtils.isNotEmpty(userBo.getPhonenumber()) && !userService.checkPhoneUnique(userBo)) {
|
||||
return R.fail("修改用户'" + userBo.getUserName() + "'失败,手机号码已存在");
|
||||
} else if (StringUtils.isNotEmpty(userBo.getEmail()) && !userService.checkEmailUnique(userBo)) {
|
||||
return R.fail("修改用户'" + userBo.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
user.setUpdateBy(LoginHelper.getUserId());
|
||||
return toAjax(userService.updateUser(user));
|
||||
boolean updated = userService.updateUser(userBo);
|
||||
if (!updated) {
|
||||
return R.fail("修改用户记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,11 +219,15 @@ public class SysUserController extends BaseController {
|
||||
@SaCheckPermission("system:user:remove")
|
||||
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{userIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] userIds) {
|
||||
public R<Void> remove(@PathVariable Long[] userIds) {
|
||||
if (ArrayUtils.contains(userIds, LoginHelper.getUserId())) {
|
||||
return error("当前用户不能删除");
|
||||
return R.fail("当前用户不能删除");
|
||||
}
|
||||
return toAjax(userService.deleteUserByIds(userIds));
|
||||
boolean deleted = userService.deleteUserByIds(userIds);
|
||||
if (!deleted) {
|
||||
return R.fail("删除用户记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,12 +235,15 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("system:user:resetPwd")
|
||||
@PutMapping("/resetPwd")
|
||||
public AjaxResult resetPwd(@RequestBody SysUser user) {
|
||||
userService.checkUserAllowed(user);
|
||||
public R<Void> resetPwd(@RequestBody SysUserBo user) {
|
||||
userService.checkUserAllowed(user.getUserId());
|
||||
userService.checkUserDataScope(user.getUserId());
|
||||
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||
user.setUpdateBy(LoginHelper.getUserId());
|
||||
return toAjax(userService.resetPwd(user));
|
||||
boolean reseted = userService.resetPwd(user);
|
||||
if (!reseted) {
|
||||
return R.fail("重置密码失败!");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,11 +252,14 @@ public class SysUserController extends BaseController {
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody SysUser user) {
|
||||
userService.checkUserAllowed(user);
|
||||
public R<Void> changeStatus(@RequestBody SysUserBo user) {
|
||||
userService.checkUserAllowed(user.getUserId());
|
||||
userService.checkUserDataScope(user.getUserId());
|
||||
user.setUpdateBy(LoginHelper.getUserId());
|
||||
return toAjax(userService.updateUserStatus(user));
|
||||
boolean updated = userService.updateUserStatus(user);
|
||||
if (!updated) {
|
||||
return R.fail("状态修改失败!");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,13 +267,14 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("system:user:query")
|
||||
@GetMapping("/authRole/{userId}")
|
||||
public AjaxResult authRole(@PathVariable("userId") Long userId) {
|
||||
public R<SysUserInfoVo> authRole(@PathVariable("userId") Long userId) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
SysUser user = userService.selectUserById(userId);
|
||||
SysUserVo user = userService.selectUserById(userId);
|
||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||
ajax.put("user", user);
|
||||
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
||||
return ajax;
|
||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||
userInfoVo.setUser(user);
|
||||
userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin()));
|
||||
return R.ok(userInfoVo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,10 +283,10 @@ public class SysUserController extends BaseController {
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
||||
@PutMapping("/authRole")
|
||||
public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
|
||||
public R<Void> insertAuthRole(Long userId, Long[] roleIds) {
|
||||
userService.checkUserDataScope(userId);
|
||||
userService.insertUserAuth(userId, roleIds);
|
||||
return success();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,8 +294,17 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("system:user:list")
|
||||
@GetMapping("/deptTree")
|
||||
public AjaxResult deptTree(SysDeptBo dept) {
|
||||
return success(deptService.selectDeptTreeList(dept));
|
||||
public R<List<Tree<Long>>> deptTree(SysDeptBo dept) {
|
||||
return R.ok(deptService.selectDeptTreeList(dept));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门下的所有用户信息
|
||||
*/
|
||||
@SaCheckPermission("system:user:list")
|
||||
@GetMapping("/list/dept/{deptId}")
|
||||
public R<List<SysUserVo>> listByDept(@PathVariable @NotNull Long deptId) {
|
||||
return R.ok(userService.selectUserListByDept(deptId));
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,28 +31,25 @@ import com.ruoyi.common.core.xss.Xss;
|
||||
public class SysUser extends BaseEntity
|
||||
{
|
||||
/** 用户ID */
|
||||
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/** 部门ID */
|
||||
@Excel(name = "部门编号", type = Type.IMPORT)
|
||||
private Long deptId;
|
||||
|
||||
/** 部门对象 */
|
||||
@Excels({
|
||||
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
|
||||
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
|
||||
})
|
||||
@RelationManyToOne(selfField = "deptId", targetField = "deptId")
|
||||
//@RelationManyToOne(selfField = "deptId", targetField = "deptId")
|
||||
private SysDept dept;
|
||||
|
||||
/** 用户账号 */
|
||||
@Excel(name = "登录名称")
|
||||
private String userName;
|
||||
|
||||
/** 用户昵称 */
|
||||
@Excel(name = "用户名称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
@ -61,15 +58,12 @@ public class SysUser extends BaseEntity
|
||||
private String userType;
|
||||
|
||||
/** 用户邮箱 */
|
||||
@Excel(name = "用户邮箱")
|
||||
private String email;
|
||||
|
||||
/** 手机号码 */
|
||||
@Excel(name = "手机号码")
|
||||
private String phonenumber;
|
||||
|
||||
/** 用户性别 */
|
||||
@Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
|
||||
private String gender;
|
||||
|
||||
/** 用户头像 */
|
||||
@ -78,50 +72,41 @@ public class SysUser extends BaseEntity
|
||||
/** 密码 */
|
||||
private String password;
|
||||
|
||||
/** 盐加密 */
|
||||
private String salt;
|
||||
|
||||
/** 帐号状态(0正常 1停用) */
|
||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
/** 最后登录IP */
|
||||
@Excel(name = "最后登录IP", type = Type.EXPORT)
|
||||
private String loginIp;
|
||||
|
||||
/** 最后登录时间 */
|
||||
@Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
|
||||
private Date loginDate;
|
||||
|
||||
|
||||
|
||||
/** 角色对象 */
|
||||
@RelationManyToMany(
|
||||
selfField = "userId", targetField = "roleId",
|
||||
joinTable = "sys_user_role",
|
||||
joinSelfColumn = "user_id", joinTargetColumn = "role_id"
|
||||
)
|
||||
// @RelationManyToMany(
|
||||
// selfField = "userId", targetField = "roleId",
|
||||
// joinTable = "sys_user_role",
|
||||
// joinSelfColumn = "user_id", joinTargetColumn = "role_id"
|
||||
// )
|
||||
private List<SysRole> roles;
|
||||
|
||||
/** 角色组 */
|
||||
private Long[] roleIds;
|
||||
|
||||
@RelationManyToMany(
|
||||
selfField = "userId", targetField = "postId",
|
||||
joinTable = "sys_user_post",
|
||||
joinSelfColumn = "user_id", joinTargetColumn = "post_id"
|
||||
)
|
||||
// @RelationManyToMany(
|
||||
// selfField = "userId", targetField = "postId",
|
||||
// joinTable = "sys_user_post",
|
||||
// joinSelfColumn = "user_id", joinTargetColumn = "post_id"
|
||||
// )
|
||||
private List<SysPost> postList;
|
||||
|
||||
/** 岗位组 */
|
||||
private Long[] postIds;
|
||||
|
||||
/** 角色ID */
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ -255,16 +240,6 @@ public class SysUser extends BaseEntity
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSalt()
|
||||
{
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt)
|
||||
{
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
return status;
|
||||
@ -345,16 +320,6 @@ public class SysUser extends BaseEntity
|
||||
this.postIds = postIds;
|
||||
}
|
||||
|
||||
public Long getRoleId()
|
||||
{
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Long roleId)
|
||||
{
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
@ -363,6 +328,14 @@ public class SysUser extends BaseEntity
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Long getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(Long tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
@ -376,7 +349,6 @@ public class SysUser extends BaseEntity
|
||||
.append("sex", getGender())
|
||||
.append("avatar", getAvatar())
|
||||
.append("password", getPassword())
|
||||
.append("salt", getSalt())
|
||||
.append("status", getStatus())
|
||||
.append("delFlag", getDelFlag())
|
||||
.append("loginIp", getLoginIp())
|
||||
|
@ -15,11 +15,11 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
public class SysUserPost
|
||||
{
|
||||
/** 用户ID */
|
||||
@Id(keyType = KeyType.None)
|
||||
@Id
|
||||
private Long userId;
|
||||
|
||||
/** 岗位ID */
|
||||
@Id(keyType = KeyType.None)
|
||||
@Id
|
||||
private Long postId;
|
||||
|
||||
public Long getUserId()
|
||||
|
@ -12,6 +12,8 @@ import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.xss.Xss;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户信息业务对象 sys_user
|
||||
*
|
||||
@ -87,6 +89,12 @@ public class SysUserBo extends BaseEntity {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/** 最后登录IP */
|
||||
private String loginIp;
|
||||
|
||||
/** 最后登录时间 */
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 角色组
|
||||
*/
|
||||
|
@ -60,8 +60,8 @@ public class SysUserExportVo implements Serializable {
|
||||
* 用户性别
|
||||
*/
|
||||
@ExcelProperty(value = "用户性别", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_user_sex")
|
||||
private String sex;
|
||||
@ExcelDictFormat(dictType = "sys_user_gender")
|
||||
private String gender;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
@ -92,7 +92,7 @@ public class SysUserExportVo implements Serializable {
|
||||
/**
|
||||
* 负责人
|
||||
*/
|
||||
@ReverseAutoMapping(target = "leader", source = "dept.leader")
|
||||
//@ReverseAutoMapping(target = "leader", source = "dept.leader")
|
||||
@ExcelProperty(value = "部门负责人")
|
||||
private String leader;
|
||||
|
||||
|
@ -0,0 +1,119 @@
|
||||
package com.ruoyi.system.listener;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.ValidatorUtils;
|
||||
import com.ruoyi.common.excel.core.ExcelListener;
|
||||
import com.ruoyi.common.excel.core.ExcelResult;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.SysUserImportVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户自定义导入
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo> implements ExcelListener<SysUserImportVo> {
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final String password;
|
||||
|
||||
private final Boolean isUpdateSupport;
|
||||
|
||||
private final Long operUserId;
|
||||
|
||||
private int successNum = 0;
|
||||
private int failureNum = 0;
|
||||
private final StringBuilder successMsg = new StringBuilder();
|
||||
private final StringBuilder failureMsg = new StringBuilder();
|
||||
|
||||
public SysUserImportListener(Boolean isUpdateSupport) {
|
||||
String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword");
|
||||
this.userService = SpringUtils.getBean(ISysUserService.class);
|
||||
this.password = BCrypt.hashpw(initPassword);
|
||||
this.isUpdateSupport = isUpdateSupport;
|
||||
this.operUserId = LoginHelper.getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(SysUserImportVo userVo, AnalysisContext context) {
|
||||
SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName());
|
||||
try {
|
||||
// 验证是否存在这个用户
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
ValidatorUtils.validate(user);
|
||||
user.setPassword(password);
|
||||
user.setCreateBy(operUserId);
|
||||
userService.insertUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
|
||||
} else if (isUpdateSupport) {
|
||||
Long userId = sysUser.getUserId();
|
||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
user.setUserId(userId);
|
||||
ValidatorUtils.validate(user);
|
||||
userService.checkUserAllowed(user.getUserId());
|
||||
userService.checkUserDataScope(user.getUserId());
|
||||
user.setUpdateBy(operUserId);
|
||||
userService.updateUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功");
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(sysUser.getUserName()).append(" 已存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、账号 " + userVo.getUserName() + " 导入失败:";
|
||||
failureMsg.append(msg).append(e.getMessage());
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExcelResult<SysUserImportVo> getExcelResult() {
|
||||
return new ExcelResult<>() {
|
||||
|
||||
@Override
|
||||
public String getAnalysis() {
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
} else {
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserImportVo> getList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getErrorList() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -14,20 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface SysPostMapper extends BaseMapper<SysPost>
|
||||
{
|
||||
/**
|
||||
* 根据用户ID获取岗位选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中岗位ID列表
|
||||
*/
|
||||
List<Long> selectPostListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户所属岗位组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
List<SysPost> selectPostsByUserName(String userName);
|
||||
|
||||
}
|
||||
|
@ -14,35 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface SysRoleDeptMapper extends BaseMapper<SysRoleDept>
|
||||
{
|
||||
// /**
|
||||
// * 通过角色ID删除角色和部门关联
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleDeptByRoleId(Long roleId);
|
||||
|
||||
// /**
|
||||
// * 批量删除角色部门关联信息
|
||||
// *
|
||||
// * @param ids 需要删除的数据ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleDept(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询部门使用数量
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int selectCountRoleDeptByDeptId(Long deptId);
|
||||
|
||||
// /**
|
||||
// * 批量新增角色部门信息
|
||||
// *
|
||||
// * @param roleDeptList 角色部门列表
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int batchRoleDept(List<SysRoleDept> roleDeptList);
|
||||
}
|
||||
|
@ -14,35 +14,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu>
|
||||
{
|
||||
/**
|
||||
* 查询菜单使用数量
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int checkMenuExistRole(Long menuId);
|
||||
|
||||
// /**
|
||||
// * 通过角色ID删除角色和菜单关联
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleMenuByRoleId(Long roleId);
|
||||
//
|
||||
// /**
|
||||
// * 批量删除角色菜单关联信息
|
||||
// *
|
||||
// * @param ids 需要删除的数据ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleMenu(Long[] ids);
|
||||
|
||||
// /**
|
||||
// * 批量新增角色菜单信息
|
||||
// *
|
||||
// * @param roleMenuList 角色菜单列表
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int batchRoleMenu(List<SysRoleMenu> roleMenuList);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@ -15,125 +16,27 @@ import org.apache.ibatis.annotations.Param;
|
||||
@Mapper
|
||||
public interface SysUserMapper extends BaseMapper<SysUser>
|
||||
{
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
* @param sysUser 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
List<SysUser> selectUserList(SysUser sysUser);
|
||||
// /**
|
||||
// * 根据条件分页查询用户列表
|
||||
// *
|
||||
// * @param sysUser 用户信息
|
||||
// * @return 用户信息集合信息
|
||||
// */
|
||||
// List<SysUser> selectUserList(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询已配用户角色列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
List<SysUser> selectAllocatedList(SysUser user);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
List<SysUser> selectUnallocatedList(SysUser user);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUser selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 通过邮箱查询用户
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUser selectUserByEmail(String email);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUser selectUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 新增用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertUser(SysUser user);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateUser(SysUser user);
|
||||
|
||||
/**
|
||||
* 修改用户头像
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param avatar 头像地址
|
||||
* @return 结果
|
||||
*/
|
||||
int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar);
|
||||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
*/
|
||||
int resetUserPwd(@Param("userName") String userName, @Param("password") String password);
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户信息
|
||||
*
|
||||
* @param userIds 需要删除的用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteUserByIds(Long[] userIds);
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param userName 用户名称
|
||||
* @return 结果
|
||||
*/
|
||||
SysUser checkUserNameUnique(String userName);
|
||||
|
||||
/**
|
||||
* 校验手机号码是否唯一
|
||||
*
|
||||
* @param phonenumber 手机号码
|
||||
* @return 结果
|
||||
*/
|
||||
SysUser checkPhoneUnique(String phonenumber);
|
||||
|
||||
/**
|
||||
* 校验email是否唯一
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 结果
|
||||
*/
|
||||
SysUser checkEmailUnique(String email);
|
||||
// /**
|
||||
// * 根据条件分页查询已配用户角色列表
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 用户信息集合信息
|
||||
// */
|
||||
// List<SysUser> selectAllocatedList(SysUser user);
|
||||
//
|
||||
// /**
|
||||
// * 根据条件分页查询未分配用户角色列表
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 用户信息集合信息
|
||||
// */
|
||||
// List<SysUser> selectUnallocatedList(SysUser user);
|
||||
}
|
||||
|
@ -14,35 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface SysUserPostMapper extends BaseMapper<SysUserPost>
|
||||
{
|
||||
/**
|
||||
* 通过用户ID删除用户和岗位关联
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserPostByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 通过岗位ID查询岗位使用数量
|
||||
*
|
||||
* @param postId 岗位ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int countUserPostById(Long postId);
|
||||
|
||||
/**
|
||||
* 批量删除用户和岗位关联
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserPost(Long[] ids);
|
||||
|
||||
/**
|
||||
* 批量新增用户岗位信息
|
||||
*
|
||||
* @param userPostList 用户角色列表
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchUserPost(List<SysUserPost> userPostList);
|
||||
}
|
||||
|
@ -15,52 +15,6 @@ import com.ruoyi.system.domain.SysUserRole;
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole>
|
||||
{
|
||||
/**
|
||||
* 通过用户ID删除用户和角色关联
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserRoleByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户和角色关联
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserRole(Long[] ids);
|
||||
|
||||
// /**
|
||||
// * 通过角色ID查询角色使用数量
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int countUserRoleByRoleId(Long roleId);
|
||||
|
||||
// /**
|
||||
// * 批量新增用户角色信息
|
||||
// *
|
||||
// * @param userRoleList 用户角色列表
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int batchUserRole(List<SysUserRole> userRoleList);
|
||||
|
||||
// /**
|
||||
// * 删除用户和角色关联信息
|
||||
// *
|
||||
// * @param userRole 用户和角色关联信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteUserRoleInfo(SysUserRole userRole);
|
||||
|
||||
// /**
|
||||
// * 批量取消授权用户角色
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @param userIds 需要删除的用户数据ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
||||
}
|
||||
|
@ -70,13 +70,13 @@ public interface ISysPostService extends IBaseService<SysPost>
|
||||
*/
|
||||
boolean checkPostCodeUnique(SysPostBo post);
|
||||
|
||||
/**
|
||||
* 通过岗位ID查询岗位使用数量
|
||||
*
|
||||
* @param postId 岗位ID
|
||||
* @return 结果
|
||||
*/
|
||||
int countUserPostById(Long postId);
|
||||
// /**
|
||||
// * 通过岗位ID查询岗位使用数量
|
||||
// *
|
||||
// * @param postId 岗位ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// int countUserPostById(Long postId);
|
||||
|
||||
/**
|
||||
* 删除岗位信息
|
||||
@ -109,4 +109,13 @@ public interface ISysPostService extends IBaseService<SysPost>
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
boolean updatePost(SysPostBo post);
|
||||
|
||||
|
||||
/**
|
||||
* 查询用户所属岗位组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果:SysPostVo集合
|
||||
*/
|
||||
List<SysPostVo> selectPostsByUserName(String userName);
|
||||
}
|
||||
|
@ -26,4 +26,12 @@ public interface ISysRoleDeptService extends IBaseService<SysRoleDept> {
|
||||
*/
|
||||
boolean deleteRoleDept(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询部门使用数量
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
int selectCountRoleDeptByDeptId(Long deptId);
|
||||
|
||||
}
|
||||
|
@ -18,4 +18,20 @@ public interface ISysRoleMenuService extends IBaseService<SysRoleMenu> {
|
||||
*/
|
||||
boolean deleteRoleMenu(Long[] ids);
|
||||
|
||||
/**
|
||||
* 通过角色ID删除用户和菜单关联
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteRoleMenuByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 查询菜单使用数量
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
int checkMenuExistRole(Long menuId);
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,14 @@ public interface ISysRoleService extends IBaseService<SysRole>
|
||||
*/
|
||||
List<SysRoleVo> selectRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询其拥有的角色列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 拥有的角色列表
|
||||
*/
|
||||
List<SysRoleVo> selectUserRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色权限
|
||||
*
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.orm.core.service.IBaseService;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
|
||||
/**
|
||||
* ruoyi-flex
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
public interface ISysUserPostService extends IBaseService<SysUserPost> {
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户和岗位关联
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteUserPostByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户和岗位关联
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteUserPost(Long[] ids);
|
||||
|
||||
/**
|
||||
* 通过岗位ID查询岗位使用数量
|
||||
*
|
||||
* @param postId 岗位ID
|
||||
* @return 结果:数量
|
||||
*/
|
||||
int countUserPostById(Long postId);
|
||||
|
||||
}
|
@ -36,11 +36,36 @@ public interface ISysUserRoleService extends IBaseService<SysUserRole> {
|
||||
boolean deleteUserRoleInfos(Long roleId, Long[] userIds);
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
* 批量选择授权角色用户
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要新增的用户数据ID
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
boolean insertAuthUsers(Long roleId, Long[] userIds);
|
||||
|
||||
/**
|
||||
* 新增用户角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param roleIds 需要新增的角色数据ID
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
boolean insertUserRoles(Long userId, Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户和角色关联
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteUserRoleByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户和角色关联
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteUserRole(Long[] ids);
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.orm.core.service.IBaseService;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysPostBo;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.SysPostVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,26 +20,34 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
List<SysUser> selectUserList(SysUser user);
|
||||
List<SysUserVo> selectUserList(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询已分配用户角色列表
|
||||
* 分页查询用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
List<SysUser> selectAllocatedList(SysUser user);
|
||||
TableDataInfo<SysUserVo> selectPage(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色列表
|
||||
* 根据条件分页查询已分配用户角色分页列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
List<SysUser> selectUnallocatedList(SysUser user);
|
||||
TableDataInfo<SysUserVo> selectAllocatedPage(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色分页列表
|
||||
*
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
TableDataInfo<SysUserVo> selectUnallocatedPage(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
@ -44,7 +55,15 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* @param userName 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUser selectUserByUserName(String userName);
|
||||
SysUserVo selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 通过邮箱查询用户
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserVo selectUserByEmail(String email);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
@ -52,7 +71,7 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* @param userId 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUser selectUserById(Long userId);
|
||||
SysUserVo selectUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询用户所属角色组
|
||||
@ -73,18 +92,18 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkUserNameUnique(SysUser user);
|
||||
boolean checkUserNameUnique(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 校验手机号码是否唯一
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkPhoneUnique(SysUser user);
|
||||
boolean checkPhoneUnique(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 校验email是否唯一
|
||||
@ -92,14 +111,14 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkEmailUnique(SysUser user);
|
||||
boolean checkEmailUnique(SysUserBo user);
|
||||
|
||||
/**
|
||||
* 校验用户是否允许操作
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userId 用户Id
|
||||
*/
|
||||
void checkUserAllowed(SysUser user);
|
||||
void checkUserAllowed(Long userId);
|
||||
|
||||
/**
|
||||
* 校验用户是否有数据权限
|
||||
@ -119,10 +138,10 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
/**
|
||||
* 新增用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @param userBo 用户信息
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
int insertUser(SysUser user);
|
||||
boolean insertUser(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
@ -130,15 +149,15 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean registerUser(SysUser user, Long tenantId);
|
||||
boolean registerUser(SysUserBo user, Long tenantId);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @param userBo 用户信息
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
int updateUser(SysUser user);
|
||||
boolean updateUser(SysUserBo userBo);
|
||||
|
||||
/**
|
||||
* 用户授权角色
|
||||
@ -152,9 +171,9 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* 修改用户状态
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @return 结果:true 操作成功,false 操作失败。
|
||||
*/
|
||||
int updateUserStatus(SysUser user);
|
||||
boolean updateUserStatus(SysUserBo user);
|
||||
|
||||
/**
|
||||
* 修改用户基本信息
|
||||
@ -162,14 +181,14 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateUserProfile(SysUser user);
|
||||
boolean updateUserProfile(SysUserBo user);
|
||||
|
||||
/**
|
||||
* 修改用户头像
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param avatar 头像地址
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
boolean updateUserAvatar(String userName, String avatar);
|
||||
|
||||
@ -177,34 +196,34 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* 重置用户密码
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @return 结果:true 操作成功,false 操作失败。
|
||||
*/
|
||||
int resetPwd(SysUser user);
|
||||
boolean resetPwd(SysUserBo user);
|
||||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
int resetUserPwd(String userName, String password);
|
||||
boolean resetUserPwd(String userName, String password);
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
int deleteUserById(Long userId);
|
||||
boolean deleteUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户信息
|
||||
*
|
||||
* @param userIds 需要删除的用户ID
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败。
|
||||
*/
|
||||
int deleteUserByIds(Long[] userIds);
|
||||
boolean deleteUserByIds(Long[] userIds);
|
||||
|
||||
/**
|
||||
* 导入用户数据
|
||||
@ -215,4 +234,12 @@ public interface ISysUserService extends IBaseService<SysUser>
|
||||
* @return 结果
|
||||
*/
|
||||
String importUser(List<SysUser> userList, Boolean isUpdateSupport, Long operID);
|
||||
|
||||
/**
|
||||
* 通过部门id查询当前部门所有用户
|
||||
*
|
||||
* @param deptId
|
||||
* @return 用户vo列表
|
||||
*/
|
||||
List<SysUserVo> selectUserListByDept(Long deptId);
|
||||
}
|
||||
|
@ -309,6 +309,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept>
|
||||
* @param newAncestors 新的父ID集合
|
||||
* @param oldAncestors 旧的父ID集合
|
||||
*/
|
||||
@Transactional
|
||||
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
|
||||
//select * from sys_dept where find_in_set(#{deptId}, ancestors)
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
|
@ -26,6 +26,7 @@ import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.SysDictDataMapper;
|
||||
import com.ruoyi.system.service.ISysDictDataService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysDictDataTableDef.SYS_DICT_DATA;
|
||||
|
||||
@ -158,6 +159,7 @@ public class SysDictDataServiceImpl extends BaseServiceImpl<SysDictDataMapper, S
|
||||
* @return 结果:true 删除成功,false 删除失败。
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteDictDataByIds(Long[] dictCodes)
|
||||
{
|
||||
for (Long dictCode : dictCodes)
|
||||
|
@ -167,6 +167,7 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeMapper, S
|
||||
* @return true 删除成功,false 删除失败。
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteDictTypeByIds(Long[] dictIds)
|
||||
{
|
||||
for (Long dictId : dictIds)
|
||||
|
@ -19,6 +19,7 @@ import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysMenuBo;
|
||||
import com.ruoyi.system.domain.vo.SysMenuVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.service.ISysRoleMenuService;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -48,7 +49,8 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuMapper,SysMenu> i
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
private ISysRoleMenuService roleMenuService;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_MENU);
|
||||
@ -275,7 +277,7 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuMapper,SysMenu> i
|
||||
*/
|
||||
@Override
|
||||
public boolean checkMenuExistRole(Long menuId) {
|
||||
int result = roleMenuMapper.checkMenuExistRole(menuId);//TODO:转化为mybatis-flex
|
||||
int result = roleMenuService.checkMenuExistRole(menuId);
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.bo.SysPostBo;
|
||||
import com.ruoyi.system.domain.vo.SysPostVo;
|
||||
import com.ruoyi.system.service.ISysUserPostService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
@ -23,8 +24,11 @@ import com.ruoyi.system.domain.SysPost;
|
||||
import com.ruoyi.system.mapper.SysPostMapper;
|
||||
import com.ruoyi.system.mapper.SysUserPostMapper;
|
||||
import com.ruoyi.system.service.ISysPostService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysPostTableDef.SYS_POST;
|
||||
import static com.ruoyi.system.domain.table.SysUserPostTableDef.SYS_USER_POST;
|
||||
import static com.ruoyi.system.domain.table.SysUserTableDef.SYS_USER;
|
||||
|
||||
/**
|
||||
* 岗位信息 服务层处理
|
||||
@ -35,10 +39,7 @@ import static com.ruoyi.system.domain.table.SysPostTableDef.SYS_POST;
|
||||
public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost> implements ISysPostService
|
||||
{
|
||||
@Resource
|
||||
private SysPostMapper postMapper;
|
||||
|
||||
@Resource
|
||||
private SysUserPostMapper userPostMapper;
|
||||
private ISysUserPostService userPostService;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
@ -129,7 +130,39 @@ public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost>
|
||||
@Override
|
||||
public List<Long> selectPostListByUserId(Long userId)
|
||||
{
|
||||
return postMapper.selectPostListByUserId(userId);
|
||||
/*select p.post_id
|
||||
from sys_post p
|
||||
left join sys_user_post up on up.post_id = p.post_id
|
||||
left join sys_user u on u.user_id = up.user_id
|
||||
where u.user_id = #{userId}*/
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().select(SYS_POST.POST_ID)
|
||||
.from(SYS_POST).as("p")
|
||||
.leftJoin(SYS_USER_POST).as("up").on(SYS_USER_POST.POST_ID.eq(SYS_POST.POST_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_POST.USER_ID))
|
||||
.where(SYS_USER.USER_ID.eq(userId));
|
||||
return this.listAs(queryWrapper,Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户所属岗位组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果:SysPostVo集合
|
||||
*/
|
||||
@Override
|
||||
public List<SysPostVo> selectPostsByUserName(String userName) {
|
||||
/* select p.post_id, p.post_name, p.post_code
|
||||
from sys_post p
|
||||
left join sys_user_post up on up.post_id = p.post_id
|
||||
left join sys_user u on u.user_id = up.user_id
|
||||
where u.user_name = #{userName}*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().select(SYS_POST.POST_ID,SYS_POST.POST_NAME,SYS_POST.POST_CODE)
|
||||
.from(SYS_POST).as("p")
|
||||
.leftJoin(SYS_USER_POST).as("up").on(SYS_USER_POST.POST_ID.eq(SYS_POST.POST_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_POST.USER_ID))
|
||||
.where(SYS_USER.USER_NAME.eq(userName));
|
||||
return this.listAs(queryWrapper,SysPostVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,17 +201,17 @@ public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost>
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过岗位ID查询岗位使用数量
|
||||
*
|
||||
* @param postId 岗位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int countUserPostById(Long postId)
|
||||
{
|
||||
return userPostMapper.countUserPostById(postId);
|
||||
}
|
||||
// /**
|
||||
// * 通过岗位ID查询岗位使用数量
|
||||
// *
|
||||
// * @param postId 岗位ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int countUserPostById(Long postId)
|
||||
// {
|
||||
// return userPostMapper.countUserPostById(postId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除岗位信息
|
||||
@ -199,12 +232,13 @@ public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost>
|
||||
* @return 结果:true 删除成功,false 删除失败。
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deletePostByIds(Long[] postIds)
|
||||
{
|
||||
for (Long postId : postIds)
|
||||
{
|
||||
SysPostVo post = selectPostById(postId);
|
||||
if (countUserPostById(postId) > 0)
|
||||
if (userPostService.countUserPostById(postId) > 0)
|
||||
{
|
||||
throw new ServiceException(String.format("%1$s已分配,不能删除!", post.getPostName()));
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
||||
import com.ruoyi.system.service.ISysRoleDeptService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -19,6 +21,9 @@ import static com.ruoyi.system.domain.table.SysRoleDeptTableDef.SYS_ROLE_DEPT;
|
||||
@Service
|
||||
public class SysRoleDeptServiceImpl extends BaseServiceImpl<SysRoleDeptMapper, SysRoleDept> implements ISysRoleDeptService {
|
||||
|
||||
@Resource
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_ROLE_DEPT);
|
||||
@ -47,4 +52,19 @@ public class SysRoleDeptServiceImpl extends BaseServiceImpl<SysRoleDeptMapper, S
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_DEPT).where(SYS_ROLE_DEPT.ROLE_ID.in(Arrays.asList(ids)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
/**
|
||||
* 查询部门使用数量
|
||||
* select count(1) from sys_role_dept where dept_id=#{deptId}
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int selectCountRoleDeptByDeptId(Long deptId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.count(SYS_ROLE_DEPT.ROLE_ID))
|
||||
.from(SYS_ROLE_DEPT)
|
||||
.where(SYS_ROLE_DEPT.DEPT_ID.eq(deptId));
|
||||
|
||||
return roleDeptMapper.selectObjectByQueryAs(queryWrapper,Integer.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
||||
import com.ruoyi.system.service.ISysRoleMenuService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -18,6 +20,8 @@ import static com.ruoyi.system.domain.table.SysRoleMenuTableDef.SYS_ROLE_MENU;
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements ISysRoleMenuService {
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
/**
|
||||
* 批量删除角色菜单关联信息
|
||||
@ -30,4 +34,32 @@ public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenuMapper, S
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_MENU).where(SYS_ROLE_MENU.ROLE_ID.in(Arrays.asList(ids)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID删除用户和菜单关联
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteRoleMenuByRoleId(Long roleId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_MENU).where(SYS_ROLE_MENU.ROLE_ID.eq(roleId));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜单使用数量
|
||||
* select count(1) from sys_role_menu where menu_id = #{menuId}
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int checkMenuExistRole(Long menuId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.count(SYS_ROLE_MENU.ROLE_ID))
|
||||
.from(SYS_ROLE_MENU)
|
||||
.where(SYS_ROLE_MENU.MENU_ID.eq(menuId));
|
||||
|
||||
return roleMenuMapper.selectObjectByQueryAs(queryWrapper,Integer.class);
|
||||
}
|
||||
}
|
||||
|
@ -112,10 +112,7 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
|
||||
@Override
|
||||
//@DataScope(deptAlias = "d")
|
||||
public List<SysRoleVo> selectRoleList(SysRoleBo roleBo) {
|
||||
//return roleMapper.selectRoleList(roleBo);
|
||||
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(roleBo);
|
||||
//List<SysRoleVo> list = roleMapper.selectListByQueryAs(queryWrapper, SysRoleVo.class);
|
||||
return this.listAs(queryWrapper, SysRoleVo.class);
|
||||
}
|
||||
|
||||
@ -155,7 +152,6 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
|
||||
queryWrapper.where(SYS_ROLE.DEL_FLAG.eq("0"))
|
||||
.and(SYS_USER_ROLE.USER_ID.eq(userId));
|
||||
|
||||
//List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
|
||||
List<SysRoleVo> userRoles = this.listAs(queryWrapper, SysRoleVo.class);
|
||||
List<SysRoleVo> roles = selectRoleAll();
|
||||
for (SysRoleVo role : roles) {
|
||||
@ -169,6 +165,34 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
|
||||
return roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询其拥有的角色列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 拥有的角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRoleVo> selectUserRolesByUserId(Long userId) {
|
||||
/*select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
|
||||
r.status, r.del_flag, r.create_time, r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
where r.del_flag = '0' and ur.user_id = #{userId}*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_ROLE.ALL_COLUMNS))
|
||||
.from(SYS_ROLE.as("r"))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.ROLE_ID.eq(SYS_ROLE.ROLE_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_ROLE.USER_ID))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID));
|
||||
queryWrapper.where(SYS_ROLE.DEL_FLAG.eq("0"))
|
||||
.and(SYS_USER_ROLE.USER_ID.eq(userId));
|
||||
|
||||
List<SysRoleVo> userRoles = this.listAs(queryWrapper, SysRoleVo.class);
|
||||
|
||||
return userRoles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
@ -359,8 +383,7 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
|
||||
boolean updated = this.updateById(role);
|
||||
// 删除角色与菜单关联
|
||||
if (updated) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_MENU).where(SYS_ROLE_MENU.ROLE_ID.eq(role.getRoleId()));
|
||||
roleMenuService.remove(queryWrapper);//TODO:这两行封装到 roleMenuService一个方法中
|
||||
roleMenuService.deleteRoleMenuByRoleId(role.getRoleId());
|
||||
|
||||
return insertRoleMenu(role);
|
||||
}
|
||||
@ -414,9 +437,9 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
|
||||
* @param role 角色对象
|
||||
* @return true 保存成功,false 保存失败
|
||||
*/
|
||||
@Transactional
|
||||
public boolean insertRoleMenu(SysRole role) {
|
||||
boolean inserted = true;
|
||||
int insertedRows = 0;
|
||||
// 新增用户与角色管理
|
||||
List<SysRoleMenu> list = new ArrayList<>();
|
||||
for (Long menuId : role.getMenuIds()) {
|
||||
@ -436,6 +459,7 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
@Transactional
|
||||
public boolean insertRoleDept(SysRole role) {
|
||||
boolean inserted = true;
|
||||
// 新增角色与部门(数据权限)管理
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
import com.ruoyi.system.mapper.SysUserPostMapper;
|
||||
import com.ruoyi.system.service.ISysUserPostService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysUserPostTableDef.SYS_USER_POST;
|
||||
|
||||
/**
|
||||
* ruoyi-flex
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
@Service
|
||||
public class SysUserPostServiceImpl extends BaseServiceImpl<SysUserPostMapper, SysUserPost> implements ISysUserPostService {
|
||||
@Resource
|
||||
private SysUserPostMapper userPostMapper;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_USER_POST);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户和岗位关联
|
||||
* delete from sys_user_post where user_id=#{userId}
|
||||
* @param userId 用户ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserPostByUserId(Long userId) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER_POST.USER_ID.eq(userId));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户和岗位关联
|
||||
* delete from sys_user_post where user_id in
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserPost(Long[] ids) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER_POST.USER_ID.in(Arrays.asList(ids)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过岗位ID查询岗位使用数量
|
||||
* select count(1) from sys_user_post where post_id=#{postId}
|
||||
* @param postId 岗位ID
|
||||
* @return 结果:数量
|
||||
*/
|
||||
@Override
|
||||
public int countUserPostById(Long postId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.count(SYS_USER_POST.USER_ID))
|
||||
.from(SYS_USER_POST)
|
||||
.where(SYS_USER_POST.POST_ID.eq(postId));
|
||||
|
||||
return userPostMapper.selectObjectByQueryAs(queryWrapper,Integer.class);
|
||||
}
|
||||
}
|
@ -26,6 +26,11 @@ public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRoleMapper, S
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_USER_ROLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
@ -88,4 +93,48 @@ public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRoleMapper, S
|
||||
}
|
||||
return this.saveBatchWithPk(list,100);//批量插入
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param roleIds 需要新增的角色数据ID
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
@Override
|
||||
public boolean insertUserRoles(Long userId, Long[] roleIds) {
|
||||
// 新增用户与角色管理
|
||||
List<SysUserRole> list = new ArrayList<>();
|
||||
for (Long roleId : roleIds) {
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
return this.saveBatchWithPk(list,100);//批量插入
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户和角色关联
|
||||
* delete from sys_user_role where user_id=#{userId}
|
||||
* @param userId 用户ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserRoleByUserId(Long userId) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER_ROLE.USER_ID.eq(userId));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户和角色关联
|
||||
* delete from sys_user_role where user_id in
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserRole(Long[] ids) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER_ROLE.USER_ID.in(Arrays.asList(ids)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,31 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.ruoyi.common.core.constant.CacheNames;
|
||||
import com.ruoyi.common.core.service.UserService;
|
||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.SysPostVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import com.ruoyi.system.service.ISysUserRoleService;
|
||||
import com.ruoyi.system.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import org.slf4j.Logger;
|
||||
@ -27,16 +34,16 @@ import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import com.ruoyi.common.core.annotation.DataScope;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.bean.BeanValidators;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.*;
|
||||
import static com.ruoyi.system.domain.table.SysDeptTableDef.SYS_DEPT;
|
||||
import static com.ruoyi.system.domain.table.SysRoleTableDef.SYS_ROLE;
|
||||
import static com.ruoyi.system.domain.table.SysUserRoleTableDef.SYS_USER_ROLE;
|
||||
import static com.ruoyi.system.domain.table.SysUserTableDef.SYS_USER;
|
||||
|
||||
/**
|
||||
@ -55,15 +62,13 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Resource
|
||||
private SysPostMapper postMapper;
|
||||
private ISysPostService postService;
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
@Resource
|
||||
private ISysUserRoleService userRoleService;
|
||||
|
||||
@Resource
|
||||
private SysUserPostMapper userPostMapper;
|
||||
private ISysUserPostService userPostService;
|
||||
|
||||
@Resource
|
||||
private ISysConfigService configService;
|
||||
@ -71,40 +76,187 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
@Resource
|
||||
protected Validator validator;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_USER);
|
||||
}
|
||||
|
||||
private QueryWrapper buildListQueryWrapper(SysUserBo userBo){
|
||||
/*select u.user_id, u.tenant_id, u.dept_id, u.nick_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.gender, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
where u.del_flag = '0'*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(SYS_USER.USER_ID,SYS_USER.TENANT_ID,SYS_USER.DEPT_ID,SYS_USER.NICK_NAME,SYS_USER.USER_NAME,SYS_USER.USER_TYPE,SYS_USER.EMAIL,SYS_USER.AVATAR,SYS_USER.PHONENUMBER,SYS_USER.GENDER,SYS_USER.STATUS,SYS_USER.DEL_FLAG,SYS_USER.LOGIN_IP,SYS_USER.LOGIN_DATE,SYS_USER.CREATE_BY,SYS_USER.CREATE_TIME,SYS_USER.REMARK,SYS_DEPT.DEPT_NAME,SYS_DEPT.LEADER)
|
||||
.from(SYS_USER.as("u"))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID))
|
||||
.where(SYS_USER.DEL_FLAG.eq("0"));
|
||||
if (ObjectUtil.isNotNull(userBo.getUserId())) {
|
||||
queryWrapper.and(SYS_USER.USER_ID.eq(userBo.getUserId()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userBo.getUserName())) {
|
||||
queryWrapper.and(SYS_USER.USER_NAME.like(userBo.getUserName()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userBo.getStatus())) {
|
||||
queryWrapper.and(SYS_USER.STATUS.eq(userBo.getStatus()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userBo.getPhonenumber())) {
|
||||
queryWrapper.and(SYS_USER.PHONENUMBER.like(userBo.getPhonenumber()));
|
||||
}
|
||||
Map<String, Object> params = userBo.getParams();
|
||||
if (params.get("beginTime") != null && params.get("endTime") != null) {
|
||||
queryWrapper.and(SYS_USER.CREATE_TIME.between(params.get("beginTime"), params.get("endTime")));
|
||||
}
|
||||
if (ObjectUtil.isNotNull(userBo.getDeptId())) {
|
||||
queryWrapper.and(SYS_USER.DEPT_ID.eq(userBo.getDeptId()).or(SYS_USER.DEPT_ID.in(select(SYS_DEPT.DEPT_ID).from(SYS_DEPT.as("t")).where(findInSet(number(userBo.getDeptId()),SYS_DEPT.ANCESTORS).gt(0)))));
|
||||
}
|
||||
// addDataScope()
|
||||
//TODO:数据范围过滤
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
private QueryWrapper buildOneQueryWrapper(){
|
||||
/* select u.user_id, u.tenant_id,u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.avatar, u.phonenumber, u.password, u.gender, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
|
||||
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
|
||||
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id */
|
||||
/*return QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_USER.USER_ID,SYS_USER.TENANT_ID,SYS_USER.DEPT_ID,SYS_USER.NICK_NAME,SYS_USER.USER_NAME,SYS_USER.USER_TYPE,SYS_USER.EMAIL,SYS_USER.AVATAR,SYS_USER.PHONENUMBER,SYS_USER.PASSWORD,SYS_USER.GENDER,SYS_USER.STATUS,SYS_USER.DEL_FLAG,SYS_USER.LOGIN_IP,SYS_USER.LOGIN_DATE,SYS_USER.CREATE_BY,SYS_USER.CREATE_TIME,SYS_USER.REMARK,
|
||||
SYS_DEPT.DEPT_ID,SYS_DEPT.PARENT_ID,SYS_DEPT.ANCESTORS,SYS_DEPT.DEPT_NAME,SYS_DEPT.ORDER_NUM,SYS_DEPT.LEADER,SYS_DEPT.STATUS.as("dept_status"),
|
||||
SYS_ROLE.ROLE_ID,SYS_ROLE.ROLE_NAME,SYS_ROLE.ROLE_KEY,SYS_ROLE.ROLE_SORT,SYS_ROLE.DATA_SCOPE,SYS_ROLE.STATUS.as("role_status")))
|
||||
.from(SYS_USER.as("u"))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.USER_ID.eq(SYS_USER.USER_ID))
|
||||
.leftJoin(SYS_ROLE).as("r").on(SYS_ROLE.ROLE_ID.eq(SYS_USER_ROLE.ROLE_ID));*/
|
||||
return QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_USER.USER_ID,SYS_USER.TENANT_ID,SYS_USER.DEPT_ID,SYS_USER.NICK_NAME,SYS_USER.USER_NAME,SYS_USER.USER_TYPE,SYS_USER.EMAIL,SYS_USER.AVATAR,SYS_USER.PHONENUMBER,SYS_USER.PASSWORD,SYS_USER.GENDER,SYS_USER.STATUS,SYS_USER.DEL_FLAG,SYS_USER.LOGIN_IP,SYS_USER.LOGIN_DATE,SYS_USER.CREATE_BY,SYS_USER.CREATE_TIME,SYS_USER.REMARK,
|
||||
SYS_DEPT.DEPT_ID,SYS_DEPT.PARENT_ID,SYS_DEPT.ANCESTORS,SYS_DEPT.DEPT_NAME,SYS_DEPT.ORDER_NUM,SYS_DEPT.LEADER,SYS_DEPT.STATUS.as("dept_status")
|
||||
))
|
||||
.from(SYS_USER.as("u"))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID));
|
||||
//.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.USER_ID.eq(SYS_USER.USER_ID))
|
||||
//.leftJoin(SYS_ROLE).as("r").on(SYS_ROLE.ROLE_ID.eq(SYS_USER_ROLE.ROLE_ID));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUser> selectUserList(SysUser user) {
|
||||
return userMapper.selectUserList(user);
|
||||
//@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUserVo> selectUserList(SysUserBo userBo) {
|
||||
QueryWrapper queryWrapper = buildListQueryWrapper(userBo);
|
||||
//TODO:数据范围过滤
|
||||
return this.listAs(queryWrapper, SysUserVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页查询已分配用户角色列表
|
||||
* 分页查询用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUser> selectAllocatedList(SysUser user) {
|
||||
return userMapper.selectAllocatedList(user);
|
||||
public TableDataInfo<SysUserVo> selectPage(SysUserBo userBo) {
|
||||
QueryWrapper queryWrapper = buildListQueryWrapper(userBo);
|
||||
//TODO:数据范围过滤
|
||||
Page<SysUserVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysUserVo.class);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色列表
|
||||
* 根据条件分页查询已分配用户角色分页列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUser> selectUnallocatedList(SysUser user) {
|
||||
return userMapper.selectUnallocatedList(user);
|
||||
//@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public TableDataInfo<SysUserVo> selectAllocatedPage(SysUserBo userBo) {
|
||||
/* select distinct u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
where u.del_flag = '0' and r.role_id = #{roleId}
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_USER.USER_ID,SYS_USER.TENANT_ID,SYS_USER.DEPT_ID,SYS_USER.USER_NAME,SYS_USER.NICK_NAME,SYS_USER.USER_TYPE,SYS_USER.EMAIL,SYS_USER.PHONENUMBER,SYS_USER.STATUS,SYS_USER.CREATE_TIME))
|
||||
.from(SYS_USER.as("u"))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.USER_ID.eq(SYS_USER.USER_ID))
|
||||
.leftJoin(SYS_ROLE).as("r").on(SYS_ROLE.ROLE_ID.eq(SYS_USER_ROLE.ROLE_ID))
|
||||
.where(SYS_USER.DEL_FLAG.eq("0"))
|
||||
.and(SYS_ROLE.ROLE_ID.eq(userBo.getRoleId()));
|
||||
if (StringUtils.isNotEmpty(userBo.getUserName())) {
|
||||
queryWrapper.and(SYS_USER.USER_NAME.like(userBo.getUserName()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userBo.getPhonenumber())) {
|
||||
queryWrapper.and(SYS_USER.PHONENUMBER.like(userBo.getPhonenumber()));
|
||||
}
|
||||
//TODO:数据范围过滤
|
||||
|
||||
Page<SysUserVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysUserVo.class);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色分页列表
|
||||
*
|
||||
* @param userBo 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
//@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public TableDataInfo<SysUserVo> selectUnallocatedPage(SysUserBo userBo) {
|
||||
/*select distinct u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
|
||||
and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_USER.USER_ID,SYS_USER.TENANT_ID,SYS_USER.DEPT_ID,SYS_USER.USER_NAME,SYS_USER.NICK_NAME,SYS_USER.USER_TYPE,SYS_USER.EMAIL,SYS_USER.PHONENUMBER,SYS_USER.STATUS,SYS_USER.CREATE_TIME))
|
||||
.from(SYS_USER.as("u"))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.USER_ID.eq(SYS_USER.USER_ID))
|
||||
.leftJoin(SYS_ROLE).as("r").on(SYS_ROLE.ROLE_ID.eq(SYS_USER_ROLE.ROLE_ID))
|
||||
.where(SYS_USER.DEL_FLAG.eq("0"))
|
||||
.and(SYS_ROLE.ROLE_ID.ne(userBo.getRoleId()).or(SYS_ROLE.ROLE_ID.isNull()))
|
||||
.and(SYS_USER.USER_ID.notIn(select(SYS_USER.USER_ID).from(SYS_USER.as("u")).innerJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.USER_ID.eq(SYS_USER.USER_ID).and(SYS_USER_ROLE.ROLE_ID.eq(userBo.getRoleId())))));
|
||||
if (StringUtils.isNotEmpty(userBo.getUserName())) {
|
||||
queryWrapper.and(SYS_USER.USER_NAME.like(userBo.getUserName()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userBo.getPhonenumber())) {
|
||||
queryWrapper.and(SYS_USER.PHONENUMBER.like(userBo.getPhonenumber()));
|
||||
}
|
||||
//TODO:数据范围过滤
|
||||
|
||||
Page<SysUserVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysUserVo.class);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,8 +266,29 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectUserByUserName(String userName) {
|
||||
return userMapper.selectUserByUserName(userName);
|
||||
public SysUserVo selectUserByUserName(String userName) {
|
||||
QueryWrapper queryWrapper = buildOneQueryWrapper();
|
||||
queryWrapper.where(SYS_USER.DEL_FLAG.eq("0"));
|
||||
if (StringUtils.isNotEmpty(userName)) {
|
||||
queryWrapper.and(SYS_USER.USER_NAME.eq(userName));
|
||||
}
|
||||
return this.getOneAs(queryWrapper,SysUserVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过邮箱查询用户
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserVo selectUserByEmail(String email) {
|
||||
QueryWrapper queryWrapper = buildOneQueryWrapper();
|
||||
queryWrapper.where(SYS_USER.DEL_FLAG.eq("0"));
|
||||
if (StringUtils.isNotEmpty(email)) {
|
||||
queryWrapper.and(SYS_USER.EMAIL.eq(email));
|
||||
}
|
||||
return this.getOneAs(queryWrapper,SysUserVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,8 +298,13 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectUserById(Long userId) {
|
||||
return userMapper.selectUserById(userId);
|
||||
public SysUserVo selectUserById(Long userId) {
|
||||
//QueryWrapper queryWrapper = buildOneQueryWrapper();//当角色有多个时,如果使用leftjoin角色表,后面在提取角色时会出错,所以弃用!
|
||||
QueryWrapper queryWrapper = query();
|
||||
if (ObjectUtil.isNotNull(userId)) {
|
||||
queryWrapper.where(SYS_USER.USER_ID.eq(userId));
|
||||
}
|
||||
return this.getOneAs(queryWrapper,SysUserVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +315,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
*/
|
||||
@Override
|
||||
public String selectUserRoleGroup(String userName) {
|
||||
//List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
||||
List<SysRoleVo> list = roleService.selectRolesByUserName(userName);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return StringUtils.EMPTY;
|
||||
@ -153,23 +330,25 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
*/
|
||||
@Override
|
||||
public String selectUserPostGroup(String userName) {
|
||||
List<SysPost> list = postMapper.selectPostsByUserName(userName);
|
||||
List<SysPostVo> list = postService.selectPostsByUserName(userName);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return list.stream().map(SysPost::getPostName).collect(Collectors.joining(","));
|
||||
return list.stream().map(SysPostVo::getPostName).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUserNameUnique(SysUser user) {
|
||||
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
||||
SysUser info = userMapper.checkUserNameUnique(user.getUserName());
|
||||
public boolean checkUserNameUnique(SysUserBo userBo) {
|
||||
Long userId = ObjectUtil.isNull(userBo.getUserId()) ? -1L : userBo.getUserId();
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.USER_NAME.eq(userBo.getUserName()))
|
||||
.and(SYS_USER.DEL_FLAG.eq("0"));
|
||||
SysUser info = this.getOne(queryWrapper);
|
||||
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
@ -180,12 +359,14 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* 校验手机号码是否唯一
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return
|
||||
* @return UNIQUE或者NOT_UNIQUE
|
||||
*/
|
||||
@Override
|
||||
public boolean checkPhoneUnique(SysUser user) {
|
||||
public boolean checkPhoneUnique(SysUserBo user) {
|
||||
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
||||
SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.PHONENUMBER.eq(user.getPhonenumber()))
|
||||
.and(SYS_USER.DEL_FLAG.eq("0"));
|
||||
SysUser info = this.getOne(queryWrapper);
|
||||
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
@ -199,9 +380,11 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean checkEmailUnique(SysUser user) {
|
||||
public boolean checkEmailUnique(SysUserBo user) {
|
||||
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
||||
SysUser info = userMapper.checkEmailUnique(user.getEmail());
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.EMAIL.eq(user.getEmail()))
|
||||
.and(SYS_USER.DEL_FLAG.eq("0"));
|
||||
SysUser info = this.getOne(queryWrapper);
|
||||
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
@ -211,11 +394,11 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
/**
|
||||
* 校验用户是否允许操作
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userId 用户Id
|
||||
*/
|
||||
@Override
|
||||
public void checkUserAllowed(SysUser user) {
|
||||
if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) {
|
||||
public void checkUserAllowed(Long userId) {
|
||||
if (ObjectUtil.isNotNull(userId) && LoginHelper.isSuperAdmin(userId)) {
|
||||
throw new ServiceException("不允许操作超级管理员用户");
|
||||
}
|
||||
}
|
||||
@ -234,9 +417,9 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
return;
|
||||
}
|
||||
|
||||
SysUser user = new SysUser();
|
||||
SysUserBo user = new SysUserBo();
|
||||
user.setUserId(userId);
|
||||
List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
|
||||
List<SysUserVo> users = SpringUtils.getAopProxy(this).selectUserList(user);
|
||||
if (StringUtils.isEmpty(users)) {
|
||||
throw new ServiceException("没有权限访问用户数据!");
|
||||
}
|
||||
@ -263,19 +446,23 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
/**
|
||||
* 新增保存用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @param userBo 用户信息
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertUser(SysUser user) {
|
||||
public boolean insertUser(SysUserBo userBo) {
|
||||
SysUser user = MapstructUtils.convert(userBo, SysUser.class);
|
||||
// 新增用户信息
|
||||
int rows = userMapper.insertUser(user);
|
||||
boolean saved = this.save(user);
|
||||
if(saved){
|
||||
// 新增用户岗位关联
|
||||
insertUserPost(user);
|
||||
// 新增用户与角色管理
|
||||
insertUserRole(user);
|
||||
return rows;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,33 +472,37 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean registerUser(SysUser user, Long tenantId) {
|
||||
user.setCreateBy(user.getUserId());
|
||||
user.setUpdateBy(user.getUserId());
|
||||
public boolean registerUser(SysUserBo user, Long tenantId) {
|
||||
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
|
||||
sysUser.setTenantId(Long.valueOf(tenantId));
|
||||
return userMapper.insertUser(sysUser) > 0;
|
||||
return this.save(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @param userBo 用户信息
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateUser(SysUser user) {
|
||||
public boolean updateUser(SysUserBo userBo) {
|
||||
SysUser user = MapstructUtils.convert(userBo, SysUser.class);
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
Long userId = user.getUserId();
|
||||
// 删除用户与角色关联
|
||||
userRoleMapper.deleteUserRoleByUserId(userId);
|
||||
userRoleService.deleteUserRoleByUserId(userId);
|
||||
// 新增用户与角色管理
|
||||
insertUserRole(user);
|
||||
|
||||
// 删除用户与岗位关联
|
||||
userPostMapper.deleteUserPostByUserId(userId);
|
||||
userPostService.deleteUserPostByUserId(userId);
|
||||
// 新增用户与岗位管理
|
||||
insertUserPost(user);
|
||||
return userMapper.updateUser(user);
|
||||
|
||||
return this.updateById(user);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,65 +514,78 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
@Override
|
||||
@Transactional
|
||||
public void insertUserAuth(Long userId, Long[] roleIds) {
|
||||
userRoleMapper.deleteUserRoleByUserId(userId);
|
||||
insertUserRole(userId, roleIds);
|
||||
userRoleService.deleteUserRoleByUserId(userId);
|
||||
userRoleService.insertUserRoles(userId,roleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*
|
||||
* update sys_user set status = #{status} where user_id = #{userId}
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @return 结果:true 操作成功,false 操作失败。
|
||||
*/
|
||||
@Override
|
||||
public int updateUserStatus(SysUser user) {
|
||||
return userMapper.updateUser(user);
|
||||
public boolean updateUserStatus(SysUserBo user) {
|
||||
return UpdateChain.of(SysUser.class)
|
||||
.set(SysUser::getStatus, user.getStatus())
|
||||
.where(SysUser::getUserId).eq(user.getUserId())
|
||||
.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户基本信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @param userBo 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateUserProfile(SysUser user) {
|
||||
return userMapper.updateUser(user);
|
||||
public boolean updateUserProfile(SysUserBo userBo) {
|
||||
SysUser user = MapstructUtils.convert(userBo, SysUser.class);
|
||||
return this.updateById(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户头像
|
||||
*
|
||||
* update sys_user set avatar = #{avatar} where user_name = #{userName}
|
||||
* @param userName 用户名
|
||||
* @param avatar 头像地址
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
@Override
|
||||
public boolean updateUserAvatar(String userName, String avatar) {
|
||||
return userMapper.updateUserAvatar(userName, avatar) > 0;
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.USER_NAME.eq(userName));
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setAvatar(avatar);
|
||||
return this.update(sysUser,queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
* @return 结果:true 操作成功,false 操作失败。
|
||||
*/
|
||||
@Override
|
||||
public int resetPwd(SysUser user) {
|
||||
return userMapper.updateUser(user);
|
||||
public boolean resetPwd(SysUserBo user) {
|
||||
return UpdateChain.of(SysUser.class)
|
||||
.set(SysUser::getPassword, user.getPassword())
|
||||
.where(SysUser::getUserId).eq(user.getUserId())
|
||||
.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
* update sys_user set password = #{password} where user_name = #{userName}
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
@Override
|
||||
public int resetUserPwd(String userName, String password) {
|
||||
return userMapper.resetUserPwd(userName, password);
|
||||
public boolean resetUserPwd(String userName, String password) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.USER_NAME.eq(userName));
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setPassword(password);
|
||||
return this.update(sysUser,queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,7 +594,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* @param user 用户对象
|
||||
*/
|
||||
public void insertUserRole(SysUser user) {
|
||||
this.insertUserRole(user.getUserId(), user.getRoleIds());
|
||||
userRoleService.insertUserRoles(user.getUserId(),user.getRoleIds());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,7 +602,8 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
public void insertUserPost(SysUser user) {
|
||||
public boolean insertUserPost(SysUser user) {
|
||||
boolean inserted = true;
|
||||
Long[] posts = user.getPostIds();
|
||||
if (StringUtils.isNotEmpty(posts)) {
|
||||
// 新增用户与岗位管理
|
||||
@ -409,65 +614,61 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
up.setPostId(postId);
|
||||
list.add(up);
|
||||
}
|
||||
userPostMapper.batchUserPost(list);
|
||||
if (list.size() > 0) {
|
||||
return userPostService.saveBatchWithPk(list,100);//批量保存
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户角色信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param roleIds 角色组
|
||||
*/
|
||||
public void insertUserRole(Long userId, Long[] roleIds) {
|
||||
userRoleService.insertAuthUsers(userId,roleIds);
|
||||
// if (StringUtils.isNotEmpty(roleIds)) {
|
||||
// // 新增用户与角色管理
|
||||
// List<SysUserRole> list = new ArrayList<>(roleIds.length);
|
||||
// for (Long roleId : roleIds) {
|
||||
// SysUserRole ur = new SysUserRole();
|
||||
// ur.setUserId(userId);
|
||||
// ur.setRoleId(roleId);
|
||||
// list.add(ur);
|
||||
// }
|
||||
// userRoleMapper.batchUserRole(list);
|
||||
// }
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteUserById(Long userId) {
|
||||
public boolean deleteUserById(Long userId) {
|
||||
// 删除用户与角色关联
|
||||
userRoleMapper.deleteUserRoleByUserId(userId);
|
||||
userRoleService.deleteUserRoleByUserId(userId);
|
||||
// 删除用户与岗位表
|
||||
userPostMapper.deleteUserPostByUserId(userId);
|
||||
return userMapper.deleteUserById(userId);
|
||||
userPostService.deleteUserPostByUserId(userId);
|
||||
|
||||
//逻辑删除用户:update sys_user set del_flag = '1' where user_id = #{userId}
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(userId);
|
||||
sysUser.setDelFlag("1");
|
||||
return this.updateById(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户信息
|
||||
*
|
||||
* @param userIds 需要删除的用户ID
|
||||
* @return 结果
|
||||
* @return 结果:true 更新成功,false 更新失败。
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteUserByIds(Long[] userIds) {
|
||||
public boolean deleteUserByIds(Long[] userIds) {
|
||||
for (Long userId : userIds) {
|
||||
checkUserAllowed(new SysUser(userId));
|
||||
checkUserAllowed(userId);
|
||||
checkUserDataScope(userId);
|
||||
}
|
||||
// 删除用户与角色关联
|
||||
userRoleMapper.deleteUserRole(userIds);
|
||||
userRoleService.deleteUserRole(userIds);
|
||||
// 删除用户与岗位关联
|
||||
userPostMapper.deleteUserPost(userIds);
|
||||
return userMapper.deleteUserByIds(userIds);
|
||||
userPostService.deleteUserPost(userIds);
|
||||
|
||||
//逻辑删除:update sys_user set del_flag = '1' where user_id in
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.USER_ID.in(Arrays.asList(userIds)));
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setDelFlag("1");
|
||||
return this.update(sysUser,queryWrapper);
|
||||
//return UpdateChain.of(SysUser.class)
|
||||
// .set(SysUser::getDelFlag, "1")
|
||||
// .where(SysUser::getUserId).in(Arrays.asList(userIds))
|
||||
// .update();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,11 +676,11 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
*
|
||||
* @param userList 用户数据列表
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
* @param operID 操作用户ID
|
||||
* @param operId 操作用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, Long operID) {
|
||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, Long operId) {
|
||||
if (StringUtils.isNull(userList) || userList.size() == 0) {
|
||||
throw new ServiceException("导入用户数据不能为空!");
|
||||
}
|
||||
@ -491,21 +692,21 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
for (SysUser user : userList) {
|
||||
try {
|
||||
// 验证是否存在这个用户
|
||||
SysUser u = userMapper.selectUserByUserName(user.getUserName());
|
||||
SysUserVo u = selectUserByUserName(user.getUserName());
|
||||
if (StringUtils.isNull(u)) {
|
||||
BeanValidators.validateWithException(validator, user);
|
||||
user.setPassword(BCrypt.hashpw(initPassword));
|
||||
user.setCreateBy(operID);
|
||||
userMapper.insertUser(user);
|
||||
user.setCreateBy(operId);
|
||||
this.save(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
|
||||
} else if (isUpdateSupport) {
|
||||
BeanValidators.validateWithException(validator, user);
|
||||
checkUserAllowed(u);
|
||||
checkUserAllowed(u.getUserId());
|
||||
checkUserDataScope(u.getUserId());
|
||||
user.setUserId(u.getUserId());
|
||||
user.setUpdateBy(operID);
|
||||
userMapper.updateUser(user);
|
||||
user.setUpdateBy(operId);
|
||||
this.updateById(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
|
||||
} else {
|
||||
@ -531,7 +732,19 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
@Cacheable(cacheNames = CacheNames.SYS_USER_NAME, key = "#userId")
|
||||
@Override
|
||||
public String selectUserNameById(Long userId) {
|
||||
SysUser sysUser=userMapper.selectUserById(userId);
|
||||
SysUserVo sysUser=selectUserById(userId);
|
||||
return ObjectUtil.isNull(sysUser) ? null : sysUser.getUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门id查询当前部门所有用户
|
||||
*
|
||||
* @param deptId
|
||||
* @return 用户vo列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysUserVo> selectUserListByDept(Long deptId) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_USER.DEPT_ID.eq(deptId)).and(SYS_USER.DEL_FLAG.eq("0"));
|
||||
return this.listAs(queryWrapper,SysUserVo.class);
|
||||
}
|
||||
}
|
||||
|
@ -21,25 +21,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select post_id, post_code, post_name, post_sort, status, create_by, create_time, remark
|
||||
from sys_post
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
<select id="selectPostListByUserId" parameterType="Long" resultType="Long">
|
||||
select p.post_id
|
||||
from sys_post p
|
||||
left join sys_user_post up on up.post_id = p.post_id
|
||||
left join sys_user u on u.user_id = up.user_id
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectPostsByUserName" parameterType="String" resultMap="SysPostResult">
|
||||
select p.post_id, p.post_name, p.post_code
|
||||
from sys_post p
|
||||
left join sys_user_post up on up.post_id = p.post_id
|
||||
left join sys_user u on u.user_id = up.user_id
|
||||
where u.user_name = #{userName}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -9,26 +9,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="deptId" column="dept_id" />
|
||||
</resultMap>
|
||||
|
||||
<!-- <delete id="deleteRoleDeptByRoleId" parameterType="Long">-->
|
||||
<!-- delete from sys_role_dept where role_id=#{roleId}-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<select id="selectCountRoleDeptByDeptId" resultType="Integer">
|
||||
select count(1) from sys_role_dept where dept_id=#{deptId}
|
||||
</select>
|
||||
|
||||
<!-- <delete id="deleteRoleDept" parameterType="Long">-->
|
||||
<!-- delete from sys_role_dept where role_id in-->
|
||||
<!-- <foreach collection="array" item="roleId" open="(" separator="," close=")">-->
|
||||
<!-- #{roleId}-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<!-- <insert id="batchRoleDept">-->
|
||||
<!-- insert into sys_role_dept(role_id, dept_id) values-->
|
||||
<!-- <foreach item="item" index="index" collection="list" separator=",">-->
|
||||
<!-- (#{item.roleId},#{item.deptId})-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </insert>-->
|
||||
|
||||
</mapper>
|
||||
|
@ -30,30 +30,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
</sql>
|
||||
|
||||
<!-- <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">-->
|
||||
<!-- <include refid="selectRoleVo"/>-->
|
||||
<!-- where r.del_flag = '0'-->
|
||||
<!-- <if test="roleId != null and roleId != 0">-->
|
||||
<!-- AND r.role_id = #{roleId}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="roleName != null and roleName != ''">-->
|
||||
<!-- AND r.role_name like concat('%', #{roleName}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="status != null and status != ''">-->
|
||||
<!-- AND r.status = #{status}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="roleKey != null and roleKey != ''">-->
|
||||
<!-- AND r.role_key like concat('%', #{roleKey}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.beginTime != null and params.beginTime != ''"><!– 开始时间检索 –>-->
|
||||
<!-- and date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.endTime != null and params.endTime != ''"><!– 结束时间检索 –>-->
|
||||
<!-- and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')-->
|
||||
<!-- </if>-->
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- ${params.dataScope}-->
|
||||
<!-- order by r.role_sort-->
|
||||
<!-- </select>-->
|
||||
|
||||
</mapper>
|
||||
|
@ -9,26 +9,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="menuId" column="menu_id" />
|
||||
</resultMap>
|
||||
|
||||
<select id="checkMenuExistRole" resultType="Integer">
|
||||
select count(1) from sys_role_menu where menu_id = #{menuId}
|
||||
</select>
|
||||
|
||||
<!-- <delete id="deleteRoleMenuByRoleId" parameterType="Long">-->
|
||||
<!-- delete from sys_role_menu where role_id=#{roleId}-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<!-- <delete id="deleteRoleMenu" parameterType="Long">-->
|
||||
<!-- delete from sys_role_menu where role_id in-->
|
||||
<!-- <foreach collection="array" item="roleId" open="(" separator="," close=")">-->
|
||||
<!-- #{roleId}-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<!-- <insert id="batchRoleMenu">-->
|
||||
<!-- insert into sys_role_menu(role_id, menu_id) values-->
|
||||
<!-- <foreach item="item" index="index" collection="list" separator=",">-->
|
||||
<!-- (#{item.roleId},#{item.menuId})-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </insert>-->
|
||||
|
||||
</mapper>
|
||||
|
@ -58,170 +58,70 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
</sql>
|
||||
|
||||
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select u.user_id, u.tenant_id, u.dept_id, u.nick_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.gender, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
where u.del_flag = '0'
|
||||
<if test="userId != null and userId != 0">
|
||||
AND u.user_id = #{userId}
|
||||
</if>
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND u.status = #{status}
|
||||
</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
||||
AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="deptId != null and deptId != 0">
|
||||
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
<!-- <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">-->
|
||||
<!-- select u.user_id, u.tenant_id, u.dept_id, u.nick_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.gender, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u-->
|
||||
<!-- left join sys_dept d on u.dept_id = d.dept_id-->
|
||||
<!-- where u.del_flag = '0'-->
|
||||
<!-- <if test="userId != null and userId != 0">-->
|
||||
<!-- AND u.user_id = #{userId}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="userName != null and userName != ''">-->
|
||||
<!-- AND u.user_name like concat('%', #{userName}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="status != null and status != ''">-->
|
||||
<!-- AND u.status = #{status}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="phonenumber != null and phonenumber != ''">-->
|
||||
<!-- AND u.phonenumber like concat('%', #{phonenumber}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.beginTime != null and params.beginTime != ''"><!– 开始时间检索 –>-->
|
||||
<!-- AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.endTime != null and params.endTime != ''"><!– 结束时间检索 –>-->
|
||||
<!-- AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="deptId != null and deptId != 0">-->
|
||||
<!-- AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))-->
|
||||
<!-- </if>-->
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- ${params.dataScope}-->
|
||||
<!-- </select>-->
|
||||
|
||||
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select distinct u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
where u.del_flag = '0' and r.role_id = #{roleId}
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
<!-- <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">-->
|
||||
<!-- select distinct u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time-->
|
||||
<!-- from sys_user u-->
|
||||
<!-- left join sys_dept d on u.dept_id = d.dept_id-->
|
||||
<!-- left join sys_user_role ur on u.user_id = ur.user_id-->
|
||||
<!-- left join sys_role r on r.role_id = ur.role_id-->
|
||||
<!-- where u.del_flag = '0' and r.role_id = #{roleId}-->
|
||||
<!-- <if test="userName != null and userName != ''">-->
|
||||
<!-- AND u.user_name like concat('%', #{userName}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="phonenumber != null and phonenumber != ''">-->
|
||||
<!-- AND u.phonenumber like concat('%', #{phonenumber}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- ${params.dataScope}-->
|
||||
<!-- </select>-->
|
||||
|
||||
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select distinct u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
|
||||
and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
<!-- <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">-->
|
||||
<!-- select distinct u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time-->
|
||||
<!-- from sys_user u-->
|
||||
<!-- left join sys_dept d on u.dept_id = d.dept_id-->
|
||||
<!-- left join sys_user_role ur on u.user_id = ur.user_id-->
|
||||
<!-- left join sys_role r on r.role_id = ur.role_id-->
|
||||
<!-- where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)-->
|
||||
<!-- and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})-->
|
||||
<!-- <if test="userName != null and userName != ''">-->
|
||||
<!-- AND u.user_name like concat('%', #{userName}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="phonenumber != null and phonenumber != ''">-->
|
||||
<!-- AND u.phonenumber like concat('%', #{phonenumber}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- ${params.dataScope}-->
|
||||
<!-- </select>-->
|
||||
|
||||
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_name = #{userName} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<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, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
|
||||
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
||||
</select>
|
||||
<select id="selectUserByEmail" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.email = #{email} and u.del_flag = '0'
|
||||
</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="gender != null and gender != ''">gender,</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="gender != null and gender != ''">#{gender},</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>
|
||||
|
||||
<update id="updateUser" parameterType="SysUser">
|
||||
update sys_user
|
||||
<set>
|
||||
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
|
||||
<if test="userName != null and userName != ''">user_name = #{userName},</if>
|
||||
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
|
||||
<if test="email != null ">email = #{email},</if>
|
||||
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
|
||||
<if test="gender != null and gender != ''">gender = #{gender},</if>
|
||||
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
|
||||
<if test="password != null and password != ''">password = #{password},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
|
||||
<if test="loginDate != null">login_date = #{loginDate},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<update id="updateUserStatus" parameterType="SysUser">
|
||||
update sys_user set status = #{status} where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<update id="updateUserAvatar" parameterType="SysUser">
|
||||
update sys_user set avatar = #{avatar} where user_name = #{userName}
|
||||
</update>
|
||||
|
||||
<update id="resetUserPwd" parameterType="SysUser">
|
||||
update sys_user set password = #{password} where user_name = #{userName}
|
||||
</update>
|
||||
|
||||
<delete id="deleteUserById" parameterType="Long">
|
||||
update sys_user set del_flag = '1' where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteUserByIds" parameterType="Long">
|
||||
update sys_user set del_flag = '1' where user_id in
|
||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
@ -9,26 +9,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="postId" column="post_id" />
|
||||
</resultMap>
|
||||
|
||||
<delete id="deleteUserPostByUserId" parameterType="Long">
|
||||
delete from sys_user_post where user_id=#{userId}
|
||||
</delete>
|
||||
|
||||
<select id="countUserPostById" resultType="Integer">
|
||||
select count(1) from sys_user_post where post_id=#{postId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteUserPost" parameterType="Long">
|
||||
delete from sys_user_post where user_id in
|
||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchUserPost">
|
||||
insert into sys_user_post(user_id, post_id) values
|
||||
<foreach item="item" index="index" collection="list" separator=",">
|
||||
(#{item.userId},#{item.postId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
@ -9,18 +9,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="roleId" column="role_id" />
|
||||
</resultMap>
|
||||
|
||||
<delete id="deleteUserRoleByUserId" parameterType="Long">
|
||||
delete from sys_user_role where user_id=#{userId}
|
||||
</delete>
|
||||
|
||||
|
||||
|
||||
<delete id="deleteUserRole" parameterType="Long">
|
||||
delete from sys_user_role where user_id in
|
||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -35,11 +35,11 @@
|
||||
"url": "https://gitee.com/dataprince/ruoyi-flex.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "2.0.10",
|
||||
"@element-plus/icons-vue": "2.1.0",
|
||||
"@vueup/vue-quill": "1.1.0",
|
||||
"@vueuse/core": "9.5.0",
|
||||
"@zeronejs/utils": "^1.4.0",
|
||||
"axios": "0.27.2",
|
||||
"axios": "^1.3.4",
|
||||
"echarts": "5.4.0",
|
||||
"element-plus": "2.2.27",
|
||||
"file-saver": "2.0.5",
|
||||
@ -54,27 +54,27 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/file-saver": "^2.0.5",
|
||||
"@types/js-cookie": "^3.0.2",
|
||||
"@types/node": "^18.7.15",
|
||||
"@types/js-cookie": "^3.0.3",
|
||||
"@types/node": "^18.14.6",
|
||||
"@types/nprogress": "^0.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||
"@typescript-eslint/parser": "^5.33.1",
|
||||
"@vitejs/plugin-vue": "3.1.0",
|
||||
"@vue/compiler-sfc": "3.2.22",
|
||||
"autoprefixer": "^10.4.8",
|
||||
"eslint": "^8.22.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-vue": "^9.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
||||
"@typescript-eslint/parser": "^5.56.0",
|
||||
"@vitejs/plugin-vue": "4.0.0",
|
||||
"@vue/compiler-sfc": "3.2.47",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"eslint": "^8.51.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-vue": "^9.9.0",
|
||||
"fast-glob": "^3.3.1",
|
||||
"postcss": "^8.4.16",
|
||||
"postcss": "^8.4.31",
|
||||
"sass": "1.56.1",
|
||||
"tailwindcss": "^3.1.8",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.1.0",
|
||||
"typescript": "^4.8.2",
|
||||
"unplugin-auto-import": "0.11.4",
|
||||
"unplugin-vue-components": "^0.22.4",
|
||||
"vite": "3.2.7",
|
||||
"typescript": "^4.9.5",
|
||||
"unplugin-auto-import": "0.16.6",
|
||||
"unplugin-vue-components": "^0.23.0",
|
||||
"vite": "4.4.11",
|
||||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-svg-icons": "^2.0.1",
|
||||
"vite-plugin-vue-setup-extend": "^0.4.0"
|
||||
|
@ -136,12 +136,7 @@
|
||||
<el-table-column label="手机号码" align="center" key="phonenumber" prop="phonenumber" v-if="columns[4].visible" width="120" />
|
||||
<el-table-column label="状态" align="center" key="status" v-if="columns[5].visible">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.status"
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
@change="handleStatusChange(scope.row)"
|
||||
></el-switch>
|
||||
<el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
|
||||
@ -247,7 +242,7 @@
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="用户性别">
|
||||
<el-select v-model="form.sex" placeholder="请选择">
|
||||
<el-select v-model="form.gender" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="dict in sys_user_gender"
|
||||
:key="dict.value"
|
||||
@ -351,6 +346,7 @@
|
||||
|
||||
<script setup>
|
||||
import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from "@/api/system/user";
|
||||
import { getConfigKey } from "@/api/system/config";
|
||||
import { getToken } from "@/utils/auth";
|
||||
|
||||
const router = useRouter();
|
||||
@ -369,7 +365,7 @@ const title = ref("");
|
||||
const dateRange = ref([]);
|
||||
const deptName = ref("");
|
||||
const deptOptions = ref(undefined);
|
||||
const initPassword = ref('123456');//TODO:修改默认密码的加载方式,允许终端用户自定义
|
||||
const initPassword = ref('123456');//允许终端用户可以通过“参数设置”模块自定义默认密码
|
||||
const postOptions = ref([]);
|
||||
const roleOptions = ref([]);
|
||||
/*** 用户导入参数 */
|
||||
@ -428,6 +424,12 @@ const filterNode = (value, data) => {
|
||||
watch(deptName, val => {
|
||||
proxy.$refs["deptTreeRef"].filter(val);
|
||||
});
|
||||
/** 从参数设置模块获取账号初始密码 */
|
||||
function getInitPassword() {
|
||||
getConfigKey("sys.user.initPassword").then(response => {
|
||||
initPassword.value = response.msg;
|
||||
});
|
||||
}
|
||||
/** 查询部门下拉树结构 */
|
||||
function getTreeselect() {
|
||||
deptTreeSelect().then(response => {
|
||||
@ -570,7 +572,7 @@ function reset() {
|
||||
password: undefined,
|
||||
phonenumber: undefined,
|
||||
email: undefined,
|
||||
sex: undefined,
|
||||
gender: undefined,
|
||||
status: "0",
|
||||
remark: undefined,
|
||||
postIds: [],
|
||||
@ -588,11 +590,11 @@ function handleAdd() {
|
||||
reset();
|
||||
initTreeData();
|
||||
getUser().then(response => {
|
||||
postOptions.value = response.posts;
|
||||
roleOptions.value = response.roles;
|
||||
postOptions.value = response.data.posts;
|
||||
roleOptions.value = response.data.roles;
|
||||
open.value = true;
|
||||
title.value = "添加用户";
|
||||
form.password.value = initPassword.value;
|
||||
form.value.password = initPassword.value;
|
||||
});
|
||||
};
|
||||
/** 修改按钮操作 */
|
||||
@ -601,14 +603,14 @@ function handleUpdate(row) {
|
||||
initTreeData();
|
||||
const userId = row.userId || ids.value;
|
||||
getUser(userId).then(response => {
|
||||
form.value = response.data;
|
||||
postOptions.value = response.posts;
|
||||
roleOptions.value = response.roles;
|
||||
form.value.postIds = response.postIds;
|
||||
form.value.roleIds = response.roleIds;
|
||||
form.value = response.data.user;
|
||||
postOptions.value = response.data.posts;
|
||||
roleOptions.value = response.data.roles;
|
||||
form.value.postIds = response.data.postIds;
|
||||
form.value.roleIds = response.data.roleIds;
|
||||
open.value = true;
|
||||
title.value = "修改用户";
|
||||
form.password = "";
|
||||
form.value.password = "";
|
||||
});
|
||||
};
|
||||
/** 提交按钮 */
|
||||
@ -634,9 +636,6 @@ function submitForm() {
|
||||
|
||||
getTreeselect();
|
||||
getList();
|
||||
//TODO:加载终端用户自定义的默认密码
|
||||
// proxy.getConfigKey("sys.user.initPassword").then(response => {
|
||||
// this.initPassword = response.msg;
|
||||
// });
|
||||
getInitPassword();
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user