提交 5dc66fb8 authored 作者: gongwenjie's avatar gongwenjie

合并分支 'gwj' 到 'master'

Gwj 查看合并请求 !22
流水线 #29 已取消 于阶段
...@@ -51,8 +51,6 @@ ...@@ -51,8 +51,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -13,4 +13,6 @@ public interface DepartmentDao extends MongoRepository<Department,String> { ...@@ -13,4 +13,6 @@ public interface DepartmentDao extends MongoRepository<Department,String> {
Department findByLevel(String level); Department findByLevel(String level);
List<Department> findAllByParentId(String parentId); List<Department> findAllByParentId(String parentId);
List<Department> findAllByIdIn(List<String> departmentIds);
} }
...@@ -68,25 +68,12 @@ public interface PasUserDao extends MongoRepository<User, String> { ...@@ -68,25 +68,12 @@ public interface PasUserDao extends MongoRepository<User, String> {
List<User> findAllByIdIn(List<String> ids); List<User> findAllByIdIn(List<String> ids);
/** /**
* 根用户名查询用户 * 根用户名查询用户
* @param name * @param name
* @return * @return
*/ */
List<User> findAllByUsername(String name); List<User> findAllByUsername(String name);
/**
* 根据部门id查询用户
* @param id
* @return
*/
List<User> findAllByDepartmentId(String id);
/**
* 根据部门列表查询用户
* @param departmentIds
* @return
*/
List<User> findAllByDepartmentIdIn(List<String> departmentIds);
......
package com.zjty.tynotes.pas.entity; package com.zjty.tynotes.pas.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -81,9 +82,9 @@ public class User implements UserDetails, Serializable { ...@@ -81,9 +82,9 @@ public class User implements UserDetails, Serializable {
@ApiModelProperty(value = "密码",example = "password") @ApiModelProperty(value = "密码",example = "password")
private String password; private String password;
@NotEmpty(message = "部门id") // @NotEmpty(message = "部门id集合")
@ApiModelProperty(value = "部门id",example = "1") @ApiModelProperty(value = "部门id集合",example = "1")
private String departmentId; private List<String> departmentIds;
@Transient @Transient
private List<Role> roles; private List<Role> roles;
...@@ -150,7 +151,7 @@ public class User implements UserDetails, Serializable { ...@@ -150,7 +151,7 @@ public class User implements UserDetails, Serializable {
this.setIdCard("1231245325325"); this.setIdCard("1231245325325");
ArrayList<String> list = new ArrayList<>(); ArrayList<String> list = new ArrayList<>();
list.add("1"); list.add("1");
this.setDepartmentId("1"); this.setDepartmentIds(new ArrayList<>());
this.setUsername("zhangsan"); this.setUsername("zhangsan");
this.setPassword("123456"); this.setPassword("123456");
return this; return this;
......
package com.zjty.tynotes.pas.service.impl; package com.zjty.tynotes.pas.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zjty.tynotes.pas.dao.DepartmentDao; import com.zjty.tynotes.pas.dao.DepartmentDao;
import com.zjty.tynotes.pas.dao.PasUserDao; import com.zjty.tynotes.pas.dao.PasUserDao;
import com.zjty.tynotes.pas.dao.RoleDao; import com.zjty.tynotes.pas.dao.RoleDao;
...@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.*; import java.util.*;
...@@ -68,10 +71,19 @@ public class DepartmentServiceImpl implements IDepartmentService { ...@@ -68,10 +71,19 @@ public class DepartmentServiceImpl implements IDepartmentService {
@Override @Override
public boolean deleteDepartment(String id) { public boolean deleteDepartment(String id) {
List<Role> roles = roleDao.findAllByDepartmentId(id); List<Role> roles = roleDao.findAllByDepartmentId(id);
List<User> users = pasUserDao.findAllByDepartmentId(id); List<User> userList = pasUserDao.findAll();
for (User user : userList) {
List<String> departmentIds = user.getDepartmentIds();
if(departmentIds!=null){
for (String string : departmentIds) {
if(id.equals(string)){
return false;
}
}
}
}
List<Department> departments = departmentDao.findAllByParentId(id); List<Department> departments = departmentDao.findAllByParentId(id);
if((roles==null || roles.size()==0) if((roles==null || roles.size()==0)
&& (users==null || users.size()!=0)
&& (departments!=null || departments.size()!=0)){ && (departments!=null || departments.size()!=0)){
departmentDao.deleteById(id); departmentDao.deleteById(id);
return true; return true;
......
...@@ -98,7 +98,6 @@ public class RoleServiceImpl implements IRoleService { ...@@ -98,7 +98,6 @@ public class RoleServiceImpl implements IRoleService {
try { try {
userRoleDao.deleteAllByRoleId(id); userRoleDao.deleteAllByRoleId(id);
roleAuthorityDao.deleteAllByRoleId(id); roleAuthorityDao.deleteAllByRoleId(id);
roleDao.deleteById(id);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
logger.error("mongodb删除角色时出错"); logger.error("mongodb删除角色时出错");
......
package com.zjty.tynotes.pas.service.impl; package com.zjty.tynotes.pas.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zjty.tynotes.pas.dao.*; import com.zjty.tynotes.pas.dao.*;
import com.zjty.tynotes.pas.entity.*; import com.zjty.tynotes.pas.entity.*;
import com.zjty.tynotes.pas.entity.vo.PageRequest; import com.zjty.tynotes.pas.entity.vo.PageRequest;
...@@ -148,7 +150,6 @@ public class UserServiceImpl implements IUserService { ...@@ -148,7 +150,6 @@ public class UserServiceImpl implements IUserService {
List<Role> roles = roleDao.findAllByIdIn(roleIds); List<Role> roles = roleDao.findAllByIdIn(roleIds);
user.setRoles(roles); user.setRoles(roles);
} }
return user; return user;
} }
...@@ -213,6 +214,7 @@ public class UserServiceImpl implements IUserService { ...@@ -213,6 +214,7 @@ public class UserServiceImpl implements IUserService {
return null; return null;
} }
} }
String departmentIdList = JSON.toJSONString(user.getDepartmentIds());
User save = pasUserDao.save(user); User save = pasUserDao.save(user);
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
if(roles!=null){ if(roles!=null){
...@@ -228,6 +230,7 @@ public class UserServiceImpl implements IUserService { ...@@ -228,6 +230,7 @@ public class UserServiceImpl implements IUserService {
} }
List<Role> roleList = roleDao.findAllByIdIn(ids); List<Role> roleList = roleDao.findAllByIdIn(ids);
save.setRoles(roleList); save.setRoles(roleList);
save.setDepartmentIds(user.getDepartmentIds());
return save; return save;
} }
......
...@@ -76,9 +76,9 @@ public class UserVo { ...@@ -76,9 +76,9 @@ public class UserVo {
@ApiModelProperty(value = "密码",example = "password") @ApiModelProperty(value = "密码",example = "password")
private String password; private String password;
@NotEmpty(message = "部门id") @NotEmpty(message = "部门id集合")
@ApiModelProperty(value = "部门id",example = "1") @ApiModelProperty(value = "部门id集合",example = "1")
private String departmentId; private List<String> departmentIds;
private List<Role> roles; private List<Role> roles;
...@@ -105,7 +105,7 @@ public class UserVo { ...@@ -105,7 +105,7 @@ public class UserVo {
this.email = user.getEmail(); this.email = user.getEmail();
this.username = user.getUsername(); this.username = user.getUsername();
this.password = user.getPassword(); this.password = user.getPassword();
this.departmentId = user.getDepartmentId(); this.departmentIds = user.getDepartmentIds();
this.roles = new ArrayList<>(); this.roles = new ArrayList<>();
this.status = null; this.status = null;
this.workCount = null; this.workCount = null;
......
...@@ -63,58 +63,61 @@ public class UserManageServiceImpl implements UserManageService { ...@@ -63,58 +63,61 @@ public class UserManageServiceImpl implements UserManageService {
*/ */
@Override @Override
public PageResponse<UserVo> findUserList(PageRequest pageRequest) { public PageResponse<UserVo> findUserList(PageRequest pageRequest) {
List<User> users = new ArrayList<>(); String deId = pageRequest.getDeId();
PageResponse<UserVo> pageResponse = new PageResponse<>(); Integer sort = pageRequest.getSort();
pageResponse.setCurrentPage(pageRequest.getCurrentPage()); return null;
pageResponse.setPageSize(pageRequest.getPageSize()); // List<User> users = new ArrayList<>();
if(pageRequest.getDeId()!=null){ // PageResponse<UserVo> pageResponse = new PageResponse<>();
users = pasUserDao.findAllByDepartmentId(pageRequest.getId()); // pageResponse.setCurrentPage(pageRequest.getCurrentPage());
}else{ // pageResponse.setPageSize(pageRequest.getPageSize());
List<Department> departmentList = findDepartmentList(pageRequest.getId()); // if(pageRequest.getDeId()!=null){
List<String> departmentIds = new ArrayList<>(); // users = pasUserDao.findAllByDepartmentId(pageRequest.getId());
for (Department department : departmentList) { // }else{
departmentIds.add(department.getId()); // List<Department> departmentList = findDepartmentList(pageRequest.getId());
} // List<String> departmentIds = new ArrayList<>();
users = pasUserDao.findAllByDepartmentIdIn(departmentIds); // for (Department department : departmentList) {
} // departmentIds.add(department.getId());
List<String> userIds = new ArrayList<>(); // }
for (User user : users) { // users = pasUserDao.findAllByDepartmentIdIn(departmentIds);
userIds.add(user.getId()); // }
} // List<String> userIds = new ArrayList<>();
List<Personnel> personnels = internalService.personnels(userIds); // for (User user : users) {
List<UserVo> userVos = new ArrayList<>(); // userIds.add(user.getId());
for (User user : users) { // }
for (Personnel personnel : personnels) { // List<Personnel> personnels = internalService.personnels(userIds);
if(user.getId().equals(personnel.getId())){ // List<UserVo> userVos = new ArrayList<>();
UserVo userVo = new UserVo(user); // for (User user : users) {
userVo.setWorkCount(personnel.getCount()); // for (Personnel personnel : personnels) {
userVos.add(userVo); // if(user.getId().equals(personnel.getId())){
} // UserVo userVo = new UserVo(user);
} // userVo.setWorkCount(personnel.getCount());
} // userVos.add(userVo);
// }
if(pageRequest.getSort()!=null && pageRequest.getSort()==1) { // }
Collections.sort(userVos, new Comparator<UserVo>() { // }
@Override //
public int compare(UserVo o1, UserVo o2) { // if(pageRequest.getSort()!=null && pageRequest.getSort()==1) {
return o1.getWorkCount()-o2.getWorkCount(); // Collections.sort(userVos, new Comparator<UserVo>() {
} // @Override
}); // public int compare(UserVo o1, UserVo o2) {
}else{ // return o1.getWorkCount()-o2.getWorkCount();
Collections.sort(userVos, new Comparator<UserVo>() { // }
@Override // });
public int compare(UserVo o1, UserVo o2) { // }else{
return o2.getWorkCount()-o1.getWorkCount(); // Collections.sort(userVos, new Comparator<UserVo>() {
} // @Override
}); // public int compare(UserVo o1, UserVo o2) {
} // return o2.getWorkCount()-o1.getWorkCount();
int startNum=(pageResponse.getCurrentPage()-1)*10+1; // }
int endNum = startNum+pageResponse.getPageSize(); // });
List<UserVo> userVos1 = userVos.subList(startNum - 1, endNum - 1); // }
pageResponse.setRows(userVos1); // int startNum=(pageResponse.getCurrentPage()-1)*10+1;
pageResponse.setTotalPage((userVos.size()/pageResponse.getPageSize())+1); // int endNum = startNum+pageResponse.getPageSize();
pageResponse.setTotalCount(userVos.size()); // List<UserVo> userVos1 = userVos.subList(startNum - 1, endNum - 1);
return pageResponse; // pageResponse.setRows(userVos1);
// pageResponse.setTotalPage((userVos.size()/pageResponse.getPageSize())+1);
// pageResponse.setTotalCount(userVos.size());
// return null;
} }
...@@ -127,6 +130,7 @@ public class UserManageServiceImpl implements UserManageService { ...@@ -127,6 +130,7 @@ public class UserManageServiceImpl implements UserManageService {
public List<Department> findDepartmentList(String id) { public List<Department> findDepartmentList(String id) {
List<UserRole> userRoles = userRoleDao.findAllByUserId(id); List<UserRole> userRoles = userRoleDao.findAllByUserId(id);
List<String> roleIds = new ArrayList<>(); List<String> roleIds = new ArrayList<>();
List<String> departmentIds = new ArrayList<>();
for (UserRole userRole : userRoles) { for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId()); roleIds.add(userRole.getRoleId());
} }
...@@ -140,31 +144,29 @@ public class UserManageServiceImpl implements UserManageService { ...@@ -140,31 +144,29 @@ public class UserManageServiceImpl implements UserManageService {
Authority authority = authorityDao.findByIdInAndName(authorityIds, "查看人员"); Authority authority = authorityDao.findByIdInAndName(authorityIds, "查看人员");
if(authority!=null){ if(authority!=null){
String departmentId = role.getDepartmentId(); String departmentId = role.getDepartmentId();
departmentIds.add(departmentId);
} }
} }
List<String> departmentIdList = new ArrayList<>();
List<Role> roleList = new ArrayList<>(); getDepartments(departmentIdList,departmentIds);
for (Role role : roles) { List<Department> departments = departmentDao.findAllByIdIn(departmentIdList);
List<Authority> authorities = role.getAuthorities();
for (Authority authority : authorities) {
if("查看人员".equals(authority.getName())){
roleList.add(role);
}
}
}
List<Department> departments = new ArrayList<>();
if(roleList!=null){
for (Role role : roleList) {
String departmentId = role.getDepartmentId();
List<Department> departmentList = departmentDao.findAllByParentId(departmentId);
findDepartmentList(departments,departmentList);
}
return departments;
}
return departments; return departments;
}
public void getDepartments(List<String> departmentIdList,List<String> departmentIds) {
for (String string : departmentIds) {
if(departmentIdList.contains(string)){
continue;
}
List<Department> departmentList = departmentDao.findAllByParentId(string);
List<String> departments = new ArrayList<>();
for (Department department : departmentList) {
departments.add(department.getId());
}
getDepartments(departmentIdList,departments);
}
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论