提交 27fe4a6b authored 作者: gongwenjie's avatar gongwenjie

接口注释,人员代码(剩下几个接口,需要任务模块提供接口才能写)

上级 176caa66
......@@ -88,4 +88,6 @@ public interface PasUserDao extends MongoRepository<User, String> {
* @return
*/
List<User> findAllByDepartmentIdIn(List<String> departmentIds);
}
......@@ -12,4 +12,6 @@ import java.util.List;
*/
public interface RoleDao extends MongoRepository<Role, String> {
List<Role> findAllByIdIn(List<String> ids);
List<Role> findAllByDepartmentIdAndIsLeader(String departmentIds,String isLeader);
}
......@@ -15,4 +15,6 @@ public interface UserRoleDao extends MongoRepository<UserRole,String> {
List<UserRole> findAllByUserId(String userId);
void deleteAllByUserId(String userId);
List<UserRole> findAllByRoleIdIn(List<String> roleIds);
}
......@@ -82,4 +82,19 @@ public interface IUserService {
*/
User addUser(User user);
/**
* 根据用户id判断是否有某个权限
* @param userId
* @param authorityName
* @return
*/
boolean isHaveAuthority(String userId,String authorityName);
/**
* 查询上级管理人员集合
* @param userId
* @return
*/
List<User> findParentManager(String userId);
}
......@@ -176,6 +176,12 @@ public class UserServiceImpl implements IUserService {
public User addUser(User user) {
List<Role> roles = user.getRoles();
List<UserRole> userRoles = new ArrayList<>();
List<User> users = pasUserDao.findAll();
for (User user1 : users) {
if(user1.getUsername().equals(user.getUsername())){
return null;
}
}
User save = pasUserDao.save(user);
List<String> ids = new ArrayList<>();
if(roles!=null){
......@@ -194,5 +200,74 @@ public class UserServiceImpl implements IUserService {
return save;
}
@Override
public boolean isHaveAuthority(String userId, String authorityName) {
List<UserRole> userRoles = userRoleDao.findAllByUserId(userId);
List<String> roleIds = new ArrayList<>();
for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId());
}
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleIdIn(roleIds);
List<String> authorityIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) {
authorityIds.add(roleAuthority.getAuthorityId());
}
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
for (Authority authority : authorities) {
if(authorityName.equals(authority.getName())){
return true;
}
}
return false;
}
@Override
public List<User> findParentManager(String userId) {
List<User> users = new ArrayList<>();
List<UserRole> userRoles = userRoleDao.findAllByUserId(userId);
List<String> roleIds = new ArrayList<>();
for (UserRole userRole : userRoles) {
String roleId = userRole.getRoleId();
roleIds.add(roleId);
}
List<Role> roles = roleDao.findAllByIdIn(roleIds);
for (Role role : roles) {
List<String> roleIds2 = new ArrayList<>();
List<String> userIds = new ArrayList<>();
if(("1").equals(role.getIsLeader())){
List<Role> roles1 = roleDao.findAllByDepartmentIdAndIsLeader(
role.getDepartmentId(), "0");
for (Role role1 : roles1) {
roleIds2.add(role1.getId());
}
List<UserRole> userRoleList = userRoleDao.findAllByRoleIdIn(roleIds2);
for (UserRole userRole : userRoleList) {
userIds.add(userRole.getUserId());
}
List<User> userList = pasUserDao.findAllByIdIn(userIds);
users.addAll(userList);
}else{
Optional<Department> op = departmentDao.findById(role.getDepartmentId());
if(op.isPresent()){
Department department = op.get();
String parentId = department.getParentId();
List<Role> roles1 = roleDao.findAllByDepartmentIdAndIsLeader(
role.getDepartmentId(), "0");
for (Role role1 : roles1) {
roleIds2.add(role1.getId());
}
List<UserRole> userRoleList = userRoleDao.findAllByRoleIdIn(roleIds2);
for (UserRole userRole : userRoleList) {
userIds.add(userRole.getUserId());
}
List<User> userList = pasUserDao.findAllByIdIn(userIds);
users.addAll(userList);
}
}
}
return null;
}
}
......@@ -163,4 +163,7 @@ public class UserManageServiceImpl implements UserManageService {
return des;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论