feat: 机构关联关联角色
This commit is contained in:
@@ -6,14 +6,21 @@ import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.slrs.sarMenu.entity.SarMenu;
|
||||
import com.adc.da.slrs.sarPosition.entity.TsPosition;
|
||||
import com.adc.da.slrs.sarResource.entity.TsResource;
|
||||
import com.adc.da.slrs.sarResource.service.ITsResourceService;
|
||||
import com.adc.da.slrs.sarRole.dao.TsRoleDao;
|
||||
import com.adc.da.slrs.sarRole.entity.TsRoleMenuVO;
|
||||
import com.adc.da.slrs.sarRole.entity.TsRoleResourceVO;
|
||||
import com.adc.da.slrs.sarRole.service.ITsRoleService;
|
||||
import com.adc.da.slrs.sarUser.entity.UserPositionBatchVO;
|
||||
import com.adc.da.slrs.sarUser.entity.UserPositionVO;
|
||||
import com.adc.da.slrs.sarUser.entity.UserRoleBatchVO;
|
||||
import com.adc.da.slrs.sarUser.entity.UserRoleVO;
|
||||
import com.adc.da.slrs.sarUser.service.ITsUserService;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
@@ -24,6 +31,7 @@ import com.adc.da.slrs.sarRole.entity.TsRole;
|
||||
import io.swagger.annotations.Api;
|
||||
import com.adc.da.base.web.BaseController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,6 +51,8 @@ public class TsRoleController extends BaseController<TsRole> {
|
||||
private ITsRoleService tsRoleService;
|
||||
@Autowired
|
||||
private TsRoleDao tsRoleDao;
|
||||
@Resource
|
||||
private ITsUserService tsUserService;
|
||||
|
||||
@ApiOperation("查询所有角色")
|
||||
@GetMapping
|
||||
@@ -51,6 +61,17 @@ public class TsRoleController extends BaseController<TsRole> {
|
||||
return Result.success(tsRoles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色(可通过name筛选)
|
||||
* @param tsRole:筛选信息
|
||||
*/
|
||||
@ApiOperation("查询角色")
|
||||
@GetMapping("/allPage")
|
||||
public ResponseMessage<IPage<TsRole>> getPosition(TsRole tsRole){
|
||||
IPage<TsRole> roles = tsRoleService.getRole(tsRole);
|
||||
return Result.success(roles);
|
||||
}
|
||||
|
||||
@ApiOperation("根据角色名筛选角色")
|
||||
@GetMapping("/name")
|
||||
public ResponseMessage<List<TsRole>> getByName(String name){
|
||||
|
||||
@@ -123,5 +123,14 @@ public class TsRole extends BaseEntity {
|
||||
@TableField(exist = false)
|
||||
private String parent;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer current;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer pageSize;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer total;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.slrs.sarRole.entity.TsRole;
|
||||
import com.adc.da.slrs.sarRole.entity.TsRoleMenuVO;
|
||||
import com.adc.da.slrs.sarRole.entity.TsRoleResourceVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -86,4 +87,11 @@ public interface ITsRoleService extends IService<TsRole> {
|
||||
* @return List<String>
|
||||
*/
|
||||
List<String> getRootMenuIdsByRoleIds(List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 分页获取所有角色
|
||||
* @param tsRole
|
||||
* @return
|
||||
*/
|
||||
IPage<TsRole> getRole(TsRole tsRole);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.adc.da.slrs.sarRole.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import com.adc.da.slrs.sarMenu.dao.SarMenuDao;
|
||||
import com.adc.da.slrs.sarMenu.entity.SarMenu;
|
||||
import com.adc.da.slrs.sarMenu.service.ISarMenuService;
|
||||
import com.adc.da.slrs.sarPersonalCenter.service.ISarUserPersonalMenuService;
|
||||
import com.adc.da.slrs.sarPosition.entity.TsPosition;
|
||||
import com.adc.da.slrs.sarResource.service.ITsResourceService;
|
||||
import com.adc.da.slrs.sarRole.entity.TsRole;
|
||||
import com.adc.da.slrs.sarRole.dao.TsRoleDao;
|
||||
@@ -17,7 +19,10 @@ import com.adc.da.slrs.sarUser.service.ITsUserService;
|
||||
import com.adc.da.slrs.zlTree.dao.ZlTreeDao;
|
||||
import com.adc.da.slrs.zlTree.entity.ZlTree;
|
||||
import com.adc.da.utils.util.ListUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -289,5 +294,20 @@ public class TsRoleServiceImpl extends ServiceImpl<TsRoleDao, TsRole> implements
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<TsRole> getRole(TsRole tsRole) {
|
||||
IPage<TsRole> page = new Page<>(tsRole.getCurrent(), tsRole.getPageSize());
|
||||
LambdaQueryWrapper<TsRole> roleWrapper = new LambdaQueryWrapper<>();
|
||||
roleWrapper.like(StrUtil.isNotBlank(tsRole.getName()), TsRole::getName, tsRole.getName());
|
||||
IPage<TsRole> tsRoleIPage = baseMapper.selectPage(page, roleWrapper);
|
||||
List<TsRole> records = tsRoleIPage.getRecords();
|
||||
page.setRecords(records);
|
||||
page.setTotal(page.getTotal());
|
||||
page.setCurrent(tsRole.getCurrent());
|
||||
page.setSize(tsRole.getPageSize());
|
||||
System.out.println(page.getTotal());
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +71,25 @@ public class TsUserController extends BaseController<TsUser> {
|
||||
return tsUserService.setPositionBatchByOrgId(userPositionVO);
|
||||
}
|
||||
|
||||
@ApiOperation("配置角色")
|
||||
@PostMapping("/role")
|
||||
public ResponseMessage<Object> setPosition(@Valid @RequestBody UserRoleVO userRoleVO){
|
||||
return tsUserService.setRole(userRoleVO);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("配置角色")
|
||||
@PostMapping("/roleBatch")
|
||||
public ResponseMessage<Object> setPositionBatch(@Valid @RequestBody UserRoleBatchVO userRoleVO){
|
||||
return tsUserService.setRoleBatch(userRoleVO);
|
||||
}
|
||||
|
||||
@ApiOperation("配置角色")
|
||||
@PostMapping("/roleBatchByOrgId")
|
||||
public ResponseMessage<Object> setPositionBatchByOrgId(@Valid @RequestBody UserRoleBatchVO userRoleVO){
|
||||
return tsUserService.setRoleBatchByOrgId(userRoleVO);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("查询当前登录用户权限")
|
||||
@GetMapping("/menu")
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.adc.da.slrs.sarUser.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/11/22 22:50
|
||||
*/
|
||||
@Data
|
||||
public class UserRoleBatchVO {
|
||||
@NotNull(message = "userId不能为空")
|
||||
private List<String> userId;
|
||||
@NotNull(message = "roleIds不能为空")
|
||||
private List<String> roleIds;
|
||||
@NotNull(message = "orgId不能为空")
|
||||
private String orgId;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.adc.da.slrs.sarUser.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/11/22 22:50
|
||||
*/
|
||||
@Data
|
||||
public class UserRoleVO {
|
||||
@NotNull(message = "userId不能为空")
|
||||
private String userId;
|
||||
@NotNull(message = "roleIds不能为空")
|
||||
private List<String> roleIds;
|
||||
}
|
||||
@@ -3,10 +3,7 @@ package com.adc.da.slrs.sarUser.service;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.slrs.sarMenu.entity.SarMenu;
|
||||
import com.adc.da.slrs.sarResource.entity.TsResource;
|
||||
import com.adc.da.slrs.sarUser.entity.TsUser;
|
||||
import com.adc.da.slrs.sarUser.entity.UpDTO;
|
||||
import com.adc.da.slrs.sarUser.entity.UserPositionBatchVO;
|
||||
import com.adc.da.slrs.sarUser.entity.UserPositionVO;
|
||||
import com.adc.da.slrs.sarUser.entity.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
@@ -92,4 +89,10 @@ public interface ITsUserService extends IService<TsUser> {
|
||||
IPage<TsUser> getAllUsers(TsUser tsUser);
|
||||
|
||||
String userIdByName(String userId);
|
||||
|
||||
ResponseMessage<Object> setRole(UserRoleVO userRoleVO);
|
||||
|
||||
ResponseMessage<Object> setRoleBatch(UserRoleBatchVO userRoleVO);
|
||||
|
||||
ResponseMessage<Object> setRoleBatchByOrgId(UserRoleBatchVO userRoleVO);
|
||||
}
|
||||
|
||||
+85
-1
@@ -79,7 +79,6 @@ public class TsUserServiceImpl extends ServiceImpl<TsUserDao, TsUser> implements
|
||||
private IUserRoleEOService userRoleEOService;
|
||||
|
||||
|
||||
|
||||
public void deleteUser(){
|
||||
tsUserDao.deleteUser();
|
||||
};
|
||||
@@ -550,5 +549,90 @@ public class TsUserServiceImpl extends ServiceImpl<TsUserDao, TsUser> implements
|
||||
return userName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseMessage<Object> setRole(UserRoleVO userRoleVO) {
|
||||
TsUser tsUser=tsUserDao.selectById(userRoleVO.getUserId());
|
||||
if(tsUser==null){
|
||||
return Result.error("该用户不存在");
|
||||
}
|
||||
// 删除原来的角色关联
|
||||
QueryWrapper<UserRoleEO> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.eq("USER_ID",userRoleVO.getUserId());
|
||||
userRoleEOService.remove(queryWrapper);
|
||||
// 设置新的角色关联
|
||||
List<UserRoleEO> userRoleEOList=new ArrayList<>();
|
||||
userRoleVO.getRoleIds().forEach(roleId -> {
|
||||
UserRoleEO userRoleEO=new UserRoleEO();
|
||||
userRoleEO.setUserId(userRoleVO.getUserId());
|
||||
userRoleEO.setRoleId(roleId);
|
||||
userRoleEOList.add(userRoleEO);
|
||||
});
|
||||
userRoleEOService.saveBatch(userRoleEOList);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseMessage<Object> setRoleBatch(UserRoleBatchVO userRoleVO) {
|
||||
// 删除原来的角色关联
|
||||
QueryWrapper<UserRoleEO> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.in("USER_ID",userRoleVO.getUserId());
|
||||
userRoleEOService.remove(queryWrapper);
|
||||
// 设置新的角色关联
|
||||
List<UserRoleEO> userRoleEOList=new ArrayList<>();
|
||||
userRoleVO.getUserId().forEach(userId -> {
|
||||
userRoleVO.getRoleIds().forEach(roleId -> {
|
||||
UserRoleEO userRoleEO=new UserRoleEO();
|
||||
userRoleEO.setUserId(userId);
|
||||
userRoleEO.setRoleId(roleId);
|
||||
userRoleEOList.add(userRoleEO);
|
||||
});
|
||||
});
|
||||
userRoleEOService.saveBatch(userRoleEOList);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseMessage<Object> setRoleBatchByOrgId(UserRoleBatchVO userRoleVO) {
|
||||
//首先将所有用户查出来
|
||||
List<String> orgIds=new ArrayList<>();
|
||||
orgIds.add(userRoleVO.getOrgId());
|
||||
List<String> middle=new ArrayList<>();
|
||||
middle.addAll(orgIds);
|
||||
boolean Orgflag=true;
|
||||
while (Orgflag){
|
||||
QueryWrapper<TsInstitution> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.in("parent_id",middle);
|
||||
List<TsInstitution> tsmiddle=tsInstitutionService.list(queryWrapper);
|
||||
if (tsmiddle.size()>0){
|
||||
tsmiddle.forEach(tsInstitution -> {
|
||||
middle.add(tsInstitution.getId());
|
||||
});
|
||||
middle.removeAll(orgIds);
|
||||
orgIds.addAll(middle);
|
||||
}else {
|
||||
tsmiddle.forEach(tsInstitution -> {
|
||||
middle.add(tsInstitution.getId());
|
||||
});
|
||||
middle.removeAll(orgIds);
|
||||
orgIds.addAll(middle);
|
||||
Orgflag=false;
|
||||
}
|
||||
}
|
||||
orgIds.removeIf(s -> null==s);
|
||||
List<UserRoleEO> userRoleEOList=new ArrayList<>();
|
||||
List<TsUser> allUsers = tsUserDao.getUserUnderInstitutionAll(orgIds);
|
||||
for (TsUser tsUser : allUsers){
|
||||
String userId = tsUser.getUserId();
|
||||
// 设置新的角色关联
|
||||
userRoleVO.getRoleIds().forEach(roleId -> {
|
||||
UserRoleEO userRoleEO=new UserRoleEO();
|
||||
userRoleEO.setUserId(userId);
|
||||
userRoleEO.setRoleId(roleId);
|
||||
userRoleEOList.add(userRoleEO);
|
||||
});
|
||||
}
|
||||
userRoleEOService.saveBatch(userRoleEOList);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user