提交 3da57f45 authored 作者: gongwenjie's avatar gongwenjie

合并分支 'gwj' 到 'master'

Gwj 查看合并请求 !1
流水线 #5 已失败 于阶段
package com.zjty.tynotes.job.basic.runner; //package com.zjty.tynotes.job.basic.runner;
//
import com.google.common.collect.Lists; //import com.google.common.collect.Lists;
import com.zjty.tynotes.job.basic.entity.database.Attachment; //import com.zjty.tynotes.job.basic.entity.database.Attachment;
import com.zjty.tynotes.job.basic.entity.database.Comment; //import com.zjty.tynotes.job.basic.entity.database.Comment;
import com.zjty.tynotes.job.basic.entity.database.Work; //import com.zjty.tynotes.job.basic.entity.database.Work;
import com.zjty.tynotes.job.basic.service.AttachmentService; //import com.zjty.tynotes.job.basic.service.AttachmentService;
import com.zjty.tynotes.job.basic.service.CommentService; //import com.zjty.tynotes.job.basic.service.CommentService;
import com.zjty.tynotes.job.basic.service.WorkService; //import com.zjty.tynotes.job.basic.service.WorkService;
import com.zjty.tynotes.job.common.constant.AttachmentType; //import com.zjty.tynotes.job.common.constant.AttachmentType;
import com.zjty.tynotes.pas.entity.User; //import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.service.IUserService; //import com.zjty.tynotes.pas.service.IUserService;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; //import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.util.Date; //import java.util.Date;
import java.util.List; //import java.util.List;
//
import static com.zjty.tynotes.job.common.constant.WorkStatus.UNDERWAY; //import static com.zjty.tynotes.job.common.constant.WorkStatus.UNDERWAY;
//
/** ///**
* <p>Description : note // * <p>Description : note
* <p>Date : 2019/4/24 16:42 // * <p>Date : 2019/4/24 16:42
* <p>@author : C // * <p>@author : C
* 在项目启动时运行的一些内容. // * 在项目启动时运行的一些内容.
*/ // */
@SuppressWarnings("SpringAutowiredFieldsWarningInspection") //@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Slf4j //@Slf4j
@Component //@Component
public class JobRunner implements CommandLineRunner { //public class JobRunner implements CommandLineRunner {
//
@Autowired // @Autowired
IUserService userService; // IUserService userService;
//
@Autowired // @Autowired
AttachmentService attachmentService; // AttachmentService attachmentService;
//
@Autowired // @Autowired
CommentService commentService; // CommentService commentService;
//
@Autowired // @Autowired
WorkService workService; // WorkService workService;
//
@Override // @Override
public void run(String... args) throws Exception { // public void run(String... args) throws Exception {
log.info("工作记录模块:启动完毕."); // log.info("工作记录模块:启动完毕.");
// initData(); //// initData();
} // }
//
private void initData() { // private void initData() {
log.info("工作记录模块:开始初始化模拟数据"); // log.info("工作记录模块:开始初始化模拟数据");
attachmentService.deleteAll(); // attachmentService.deleteAll();
commentService.deleteAll(); // commentService.deleteAll();
workService.deleteAll(); // workService.deleteAll();
Integer minSize = 4; // Integer minSize = 4;
if (userService.findAll().size() < minSize) { // if (userService.findAll().size() < minSize) {
userService.registerUser(new User().createUser()); // userService.registerUser(new User().createUser());
userService.registerUser(new User().createUser()); // userService.registerUser(new User().createUser());
userService.registerUser(new User().createUser()); // userService.registerUser(new User().createUser());
userService.registerUser(new User().createUser()); // userService.registerUser(new User().createUser());
} // }
List<User> users = userService.findAll(); // List<User> users = userService.findAll();
Boolean condition = (users.size() >= minSize); // Boolean condition = (users.size() >= minSize);
if (condition) { // if (condition) {
String publisher = users.get(0).getId(); // String publisher = users.get(0).getId();
String executor = users.get(1).getId(); // String executor = users.get(1).getId();
List<String> checker = Lists.newArrayList(users.get(2).getId()); // List<String> checker = Lists.newArrayList(users.get(2).getId());
List<String> follower = Lists.newArrayList(users.get(3).getId()); // List<String> follower = Lists.newArrayList(users.get(3).getId());
Attachment attachment = new Attachment(null, "test file", "doc", publisher, AttachmentType.INIT, new Date(), "abcd"); // Attachment attachment = new Attachment(null, "test file", "doc", publisher, AttachmentType.INIT, new Date(), "abcd");
Comment comment = new Comment(null, follower.get(0), new Date(), new Date(), "some contents"); // Comment comment = new Comment(null, follower.get(0), new Date(), new Date(), "some contents");
Work work = new Work( // Work work = new Work(
null, // null,
"test", // "test",
new Date(), // new Date(),
new Date(), // new Date(),
new Date(), // new Date(),
publisher, // publisher,
executor, // executor,
checker, // checker,
follower, // follower,
null, // null,
null, // null,
"some contents", // "some contents",
true, // true,
UNDERWAY // UNDERWAY
); // );
String workId = workService.add(work); // String workId = workService.add(work);
attachmentService.add(attachment, workId); // attachmentService.add(attachment, workId);
commentService.add(comment, workId); // commentService.add(comment, workId);
log.info("工作记录模块:生成模拟数据完毕."); // log.info("工作记录模块:生成模拟数据完毕.");
} else { // } else {
log.info("工作记录模块:用户模块的数据数量不足(需要至少4个).无法生成模拟工作记录模拟数据."); // log.info("工作记录模块:用户模块的数据数量不足(需要至少4个).无法生成模拟工作记录模拟数据.");
} // }
//
} // }
//
} //}
...@@ -3,7 +3,6 @@ package com.zjty.tynotes.pas.config; ...@@ -3,7 +3,6 @@ package com.zjty.tynotes.pas.config;
import com.zjty.tynotes.pas.config.handler.MyAccessHandler; import com.zjty.tynotes.pas.config.handler.MyAccessHandler;
import com.zjty.tynotes.pas.config.handler.MyFailHandler; import com.zjty.tynotes.pas.config.handler.MyFailHandler;
import com.zjty.tynotes.pas.config.handler.MyLogoutHandler; import com.zjty.tynotes.pas.config.handler.MyLogoutHandler;
import com.zjty.tynotes.pas.config.handler.MySuccessHandler;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -46,8 +45,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -46,8 +45,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
private MyLogoutHandler myLogoutHandler; private MyLogoutHandler myLogoutHandler;
@Autowired
private MySuccessHandler successHandler;
@Autowired @Autowired
private MyFailHandler failHandler; private MyFailHandler failHandler;
...@@ -97,7 +94,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -97,7 +94,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean @Bean
public MyFilter myFilter() throws Exception { public MyFilter myFilter() throws Exception {
MyFilter filter = new MyFilter(); MyFilter filter = new MyFilter();
filter.setAuthenticationSuccessHandler(successHandler);
filter.setAuthenticationFailureHandler(failHandler); filter.setAuthenticationFailureHandler(failHandler);
filter.setFilterProcessesUrl("/userLogin"); filter.setFilterProcessesUrl("/userLogin");
filter.setAuthenticationManager(this.authenticationManager()); filter.setAuthenticationManager(this.authenticationManager());
......
...@@ -44,9 +44,6 @@ ...@@ -44,9 +44,6 @@
// @Autowired // @Autowired
// IRoleService iRoleService; // IRoleService iRoleService;
// //
// @Autowired
// IMenuSerivce iMenuSerivce;
//
// private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); // private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
// //
// @Autowired // @Autowired
......
...@@ -2,6 +2,7 @@ package com.zjty.tynotes.pas.controller; ...@@ -2,6 +2,7 @@ package com.zjty.tynotes.pas.controller;
import com.zjty.tynotes.misc.config.AutoDocument; import com.zjty.tynotes.misc.config.AutoDocument;
import com.zjty.tynotes.pas.entity.User; import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.pas.service.IUserService; import com.zjty.tynotes.pas.service.IUserService;
import com.zjty.tynotes.pas.utils.LogoutUtil; import com.zjty.tynotes.pas.utils.LogoutUtil;
import com.zjty.tynotes.search.subject.service.EsUtil; import com.zjty.tynotes.search.subject.service.EsUtil;
...@@ -92,23 +93,11 @@ public class UserController { ...@@ -92,23 +93,11 @@ public class UserController {
@ApiOperation(value = "根据id查询用户", response = User.class) @ApiOperation(value = "根据id查询用户", response = User.class)
@GetMapping("/findUser/{id}") @GetMapping("/findUser/{id}")
public ResponseEntity addUser(@RequestBody @Valid String id) { public ResponseEntity findUser(@RequestBody @Valid String id) {
return ok(iUserService.findUserById(id)); return ok(iUserService.findUserById(id));
} }
//待完成
@ApiOperation(value = "查询人员列表", response = User.class)
@GetMapping("/findUser/{id}")
public ResponseEntity findUserList(String id,String deId,String sort) {
return ok(iUserService.findUserList(id,deId,sort));
}
@ApiOperation(value = "查询可查看部门列表", response = User.class)
@GetMapping("/findDepartmentList/{id}")
public ResponseEntity findDepartmentList(String id) {
return ok(iUserService.findDepartmentList(id));
}
......
...@@ -68,8 +68,26 @@ public interface PasUserDao extends MongoRepository<User, String> { ...@@ -68,8 +68,26 @@ public interface PasUserDao extends MongoRepository<User, String> {
*/ */
List<User> findAllByIdIn(List<String> ids); List<User> findAllByIdIn(List<String> ids);
/**
* 根绝用户名查询用户
* @param name
* @return
*/
List<User> findAllByUsername(String name); List<User> findAllByUsername(String name);
/**
* 根据部门id查询用户
* @param id
* @return
*/
List<User> findAllByDepartmentId(String id); List<User> findAllByDepartmentId(String id);
/**
* 根据部门列表查询用户
* @param departmentIds
* @return
*/
List<User> findAllByDepartmentIdIn(List<String> departmentIds);
} }
...@@ -12,4 +12,6 @@ import java.util.List; ...@@ -12,4 +12,6 @@ import java.util.List;
*/ */
public interface RoleDao extends MongoRepository<Role, String> { public interface RoleDao extends MongoRepository<Role, String> {
List<Role> findAllByIdIn(List<String> ids); List<Role> findAllByIdIn(List<String> ids);
List<Role> findAllByDepartmentIdAndIsLeader(String departmentIds,String isLeader);
} }
...@@ -15,4 +15,6 @@ public interface UserRoleDao extends MongoRepository<UserRole,String> { ...@@ -15,4 +15,6 @@ public interface UserRoleDao extends MongoRepository<UserRole,String> {
List<UserRole> findAllByUserId(String userId); List<UserRole> findAllByUserId(String userId);
void deleteAllByUserId(String userId); void deleteAllByUserId(String userId);
List<UserRole> findAllByRoleIdIn(List<String> roleIds);
} }
...@@ -91,6 +91,9 @@ public class User implements UserDetails, Serializable { ...@@ -91,6 +91,9 @@ public class User implements UserDetails, Serializable {
@Transient @Transient
private List<Role> roles; private List<Role> roles;
@Transient
private String status;//工作状态(0代表空闲 1代表忙碌)
// @NotNull(message = "角色Id不可为空") // @NotNull(message = "角色Id不可为空")
// @ApiModelProperty(value = "角色id",example = "1") // @ApiModelProperty(value = "角色id",example = "1")
// private Integer roleId; // private Integer roleId;
......
package com.zjty.tynotes.pas.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author gwj
* @create 2020/3/2 11:02
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageRequest {
/**
* 每页显示个数
*/
private int pageSize;
/**
* 当前页数
*/
private int currentPage;
/**
* 总页数
*/
private int totalPage;
/**
* 总记录数
*/
private int totalCount;
/**
* 访问人员id
*/
private String id;
/**
* 查询条件:部门id(默认查询所有可查询的所有人员)
*/
private String deId;
/**
* 查询条件:任务数量升降序(默认降序0 1升序)
*/
private Integer sort;
}
package com.zjty.tynotes.pas.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/2 10:54
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResponse<T> implements Serializable {
private static final long serialVersionUID = 5760097915453738435L;
/**
* 每页显示个数
*/
private int pageSize;
/**
* 当前页数
*/
private int currentPage;
/**
* 总页数
*/
private int totalPage;
/**
* 总记录数
*/
private int totalCount;
/**
* 结果列表
*/
private List<T> rows;
public void setTotalCount(int totalCount) {
//设置了totalCount就可以计算出总totalPage
this.totalCount = totalCount;
int countRecords = this.getTotalCount();
int totalPages = countRecords % pageSize == 0 ? countRecords / pageSize : (countRecords / pageSize + 1);
setTotalPage(totalPages);
}
/**
* 设置结果 及总页数
* @param rows 分页之后查询到的结果
*/
public void build(List<T> rows) {
this.setRows(rows);
int count = this.getTotalCount();
int divisor = count / this.getPageSize();
int remainder = count % this.getPageSize();
//设置总页数, Trash code, confusing.
this.setTotalPage(remainder == 0 ? (divisor == 0 ? 1 : divisor) : divisor + 1);
//已在setTotalCount中进行
int countRecords = this.getTotalCount();
int totalPages = countRecords % pageSize == 0 ? countRecords / pageSize : (countRecords / pageSize + 1);
setTotalPage(totalPages);
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
...@@ -12,13 +12,38 @@ import java.util.List; ...@@ -12,13 +12,38 @@ import java.util.List;
* @create 2020/3/1 9:45 * @create 2020/3/1 9:45
*/ */
public interface ConfigService { public interface ConfigService {
/**
* 保存参数配置
* @param configs
* @return
*/
List<Config> save(List<Config> configs); List<Config> save(List<Config> configs);
/**
* 查找节假日
* @param holidayRequest
* @return
*/
List<Date> findHolidays(HolidayRequest holidayRequest); List<Date> findHolidays(HolidayRequest holidayRequest);
/**
* 批量设置节假日
* @param days
* @return
*/
List<Day> setHolidays(List<Day> days); List<Day> setHolidays(List<Day> days);
/**
* 设置单个节假日
* @param day
* @return
*/
Day setHoliday(Day day); Day setHoliday(Day day);
/**
* 查找某个月的节假日情况
* @param date
* @return
*/
List<Day> findHolidaysByMonth(String date); List<Day> findHolidaysByMonth(String date);
} }
...@@ -9,11 +9,30 @@ import java.util.List; ...@@ -9,11 +9,30 @@ import java.util.List;
* @author mcj * @author mcj
*/ */
public interface IAuthorityService { public interface IAuthorityService {
/**
* 添加权限
* @param authority
* @return
*/
Authority addAuthority(Authority authority); Authority addAuthority(Authority authority);
/**
* 删除权限
* @param id
* @return
*/
boolean deleteAuthority(String id); boolean deleteAuthority(String id);
/**
* 修改权限
* @param authority
* @return
*/
Authority updateAuthority(Authority authority); Authority updateAuthority(Authority authority);
/**
* 查找权限
* @return
*/
List<Authority> findAuthority(); List<Authority> findAuthority();
} }
...@@ -34,8 +34,10 @@ public interface IDepartmentService { ...@@ -34,8 +34,10 @@ public interface IDepartmentService {
*/ */
Department findOne(String id); Department findOne(String id);
/**
* 查找所有部门列表
* @return
*/
List<Department> findList(); List<Department> findList();
void getDepartments(List<Department> departments);
} }
...@@ -34,7 +34,17 @@ public interface IRoleService { ...@@ -34,7 +34,17 @@ public interface IRoleService {
*/ */
void deleteAll(); void deleteAll();
/**
* 修改角色
* @param role
* @return
*/
Boolean updateRole(Role role); Boolean updateRole(Role role);
/**
* 删除角色
* @param id
* @return
*/
boolean deleteRole(String id); boolean deleteRole(String id);
} }
...@@ -2,6 +2,8 @@ package com.zjty.tynotes.pas.service; ...@@ -2,6 +2,8 @@ package com.zjty.tynotes.pas.service;
import com.zjty.tynotes.pas.entity.Department; import com.zjty.tynotes.pas.entity.Department;
import com.zjty.tynotes.pas.entity.User; import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.pas.entity.vo.PageResponse;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import java.util.List; import java.util.List;
...@@ -73,9 +75,26 @@ public interface IUserService { ...@@ -73,9 +75,26 @@ public interface IUserService {
*/ */
String addUserCount(String username); String addUserCount(String username);
/**
* 新增用户
* @param user
* @return
*/
User addUser(User user); User addUser(User user);
List<User> findUserList(String id, String deId, String sort); /**
* 根据用户id判断是否有某个权限
* @param userId
* @param authorityName
* @return
*/
boolean isHaveAuthority(String userId,String authorityName);
/**
* 查询上级管理人员集合
* @param userId
* @return
*/
List<User> findParentManager(String userId);
List<Department> findDepartmentList(String id);
} }
...@@ -54,7 +54,6 @@ public class DepartmentServiceImpl implements IDepartmentService { ...@@ -54,7 +54,6 @@ public class DepartmentServiceImpl implements IDepartmentService {
return departmentList; return departmentList;
} }
@Override
public void getDepartments(List<Department> departments) { public void getDepartments(List<Department> departments) {
for (Department department : departments) { for (Department department : departments) {
List<Department> departmentList = departmentDao.findAllByParentId(department.getId()); List<Department> departmentList = departmentDao.findAllByParentId(department.getId());
......
...@@ -2,6 +2,8 @@ package com.zjty.tynotes.pas.service.impl; ...@@ -2,6 +2,8 @@ package com.zjty.tynotes.pas.service.impl;
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.PageResponse;
import com.zjty.tynotes.pas.service.IDepartmentService; import com.zjty.tynotes.pas.service.IDepartmentService;
import com.zjty.tynotes.pas.service.IUserService; import com.zjty.tynotes.pas.service.IUserService;
import com.zjty.tynotes.search.subject.service.EsUtil; import com.zjty.tynotes.search.subject.service.EsUtil;
...@@ -174,6 +176,12 @@ public class UserServiceImpl implements IUserService { ...@@ -174,6 +176,12 @@ public class UserServiceImpl implements IUserService {
public User addUser(User user) { public User addUser(User user) {
List<Role> roles = user.getRoles(); List<Role> roles = user.getRoles();
List<UserRole> userRoles = new ArrayList<>(); 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); User save = pasUserDao.save(user);
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
if(roles!=null){ if(roles!=null){
...@@ -193,92 +201,73 @@ public class UserServiceImpl implements IUserService { ...@@ -193,92 +201,73 @@ public class UserServiceImpl implements IUserService {
} }
@Override @Override
public List<User> findUserList(String id, String deId, String sort) { public boolean isHaveAuthority(String userId, String authorityName) {
Optional<User> optional = pasUserDao.findById(id); List<UserRole> userRoles = userRoleDao.findAllByUserId(userId);
User user;
if(optional.isPresent()){
user = optional.get();
List<UserRole> userRoles = userRoleDao.findAllByUserId(user.getId());
List<String> roleIds = new ArrayList<>(); List<String> roleIds = new ArrayList<>();
for (UserRole userRole : userRoles) { for (UserRole userRole : userRoles) {
if(!roleIds.contains(userRole.getRoleId())){
roleIds.add(userRole.getRoleId()); roleIds.add(userRole.getRoleId());
} }
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleIdIn(roleIds);
List<String> authorityIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) {
authorityIds.add(roleAuthority.getAuthorityId());
} }
List<Role> roles = roleDao.findAllByIdIn(roleIds); List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
List<String> userIds = new ArrayList<>();
for (Role role : roles) {
String departmentId = role.getDepartmentId();
List<Authority> authorities = role.getAuthorities();
List<User> users2 = new ArrayList<>();
for (Authority authority : authorities) { for (Authority authority : authorities) {
if("查看人员信息".equals(authority.getName())){ if(authorityName.equals(authority.getName())){
users2 = pasUserDao.findAllByDepartmentId(departmentId); return true;
}
}
for (User user1 : users2) {
if(!userIds.contains(user1.getId())){
userIds.add(user1.getId());
}
}
} }
} }
return null; return false;
} }
@Override @Override
public List<Department> findDepartmentList(String id) { public List<User> findParentManager(String userId) {
List<UserRole> userRoles = userRoleDao.findAllByUserId(id); List<User> users = new ArrayList<>();
List<UserRole> userRoles = userRoleDao.findAllByUserId(userId);
List<String> roleIds = new ArrayList<>(); List<String> roleIds = new ArrayList<>();
for (UserRole userRole : userRoles) { for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId()); String roleId = userRole.getRoleId();
roleIds.add(roleId);
} }
List<Role> roles = roleDao.findAllByIdIn(roleIds); List<Role> roles = roleDao.findAllByIdIn(roleIds);
for (Role role : roles) { for (Role role : roles) {
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(role.getId()); List<String> roleIds2 = new ArrayList<>();
List<String> authorityIds = new ArrayList<>(); List<String> userIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) { if(("1").equals(role.getIsLeader())){
authorityIds.add(roleAuthority.getAuthorityId()); List<Role> roles1 = roleDao.findAllByDepartmentIdAndIsLeader(
role.getDepartmentId(), "0");
for (Role role1 : roles1) {
roleIds2.add(role1.getId());
} }
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds); List<UserRole> userRoleList = userRoleDao.findAllByRoleIdIn(roleIds2);
role.setAuthorities(authorities); for (UserRole userRole : userRoleList) {
userIds.add(userRole.getUserId());
} }
List<User> userList = pasUserDao.findAllByIdIn(userIds);
List<Role> roleList = new ArrayList<>(); users.addAll(userList);
for (Role role : roles) { }else{
List<Authority> authorities = role.getAuthorities(); Optional<Department> op = departmentDao.findById(role.getDepartmentId());
for (Authority authority : authorities) { if(op.isPresent()){
if("查看人员".equals(authority.getName())){ Department department = op.get();
roleList.add(role); 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);
} }
if(roleList!=null){
for (Role role : roleList) {
} }
} }
return null; return null;
} }
private List<Department> findDepartmentList(List<Department> des, List<Department> deps){
for (Department department : deps) {
if(!des.contains(department)){
des.add(department);
}
}
for (Department department : deps) {
List<Department> departments = departmentDao.findAllByParentId(department.getId());
if(departments!=null){
findDepartmentList(des,departments);
}
}
return des;
}
} }
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
<dependencies> <dependencies>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-job</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.zjty.tynotes</groupId> <groupId>com.zjty.tynotes</groupId>
<artifactId>notes-misc</artifactId> <artifactId>notes-misc</artifactId>
......
package com.zjty.tynotes.weekly.subject.controller;
import com.zjty.tynotes.misc.config.AutoDocument;
import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.weekly.subject.service.UserManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import static org.springframework.http.ResponseEntity.ok;
/**
* @Author gwj
* @create 2020/3/2 13:04
*/
@Api(tags = "人员管理模块", protocols = "http")
@RestController
@RequestMapping("/manage/user")
@AutoDocument
public class UserManageController {
@Autowired
private UserManageService userManageService;
@ApiOperation(value = "根据id查询用户", response = User.class)
@GetMapping("/findUser/{id}")
public ResponseEntity addUser(@RequestBody @Valid String id) {
return ok(userManageService.findUserById(id));
}
//待完成
@ApiOperation(value = "查询人员列表", response = User.class)
@GetMapping("/findUser/{id}")
public ResponseEntity findUserList(@RequestBody PageRequest pageRequest) {
return ok(userManageService.findUserList(pageRequest));
}
@ApiOperation(value = "查询可查看部门列表", response = User.class)
@GetMapping("/findDepartmentList/{id}")
public ResponseEntity findDepartmentList(@PathVariable("id") String id) {
return ok(userManageService.findDepartmentList(id));
}
@ApiOperation(value = "查询人员任务详情", response = User.class)
@GetMapping("/findUserWork/{id}/{status}")
public ResponseEntity findUserWork(@PathVariable("id") String id,
@PathVariable("status") String status) {
return ok(userManageService.findUserWork(id,status));
}
}
package com.zjty.tynotes.weekly.subject.controller;
import com.zjty.tynotes.misc.config.AutoDocument;
import com.zjty.tynotes.weekly.subject.entity.Weekly;
import com.zjty.tynotes.weekly.subject.entity.WeeklySimple;
import com.zjty.tynotes.weekly.subject.service.WeeklyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author LJJ cnljj1995@gmail.com
* on 2019-07-05
*/
@RestController
@RequestMapping("/weekly")
@AutoDocument
@Api(tags = "周报模块", value = "周报模块")
public class WebWeeklyController {
@Autowired
private WeeklyService weeklyService;
@PutMapping
@ApiOperation(value = "更新周报")
public ResponseEntity update(@RequestParam Weekly weekly) {
weeklyService.updateWeekly(weekly);
return ResponseEntity.ok(weekly);
}
@GetMapping
@ApiOperation(value = "根据id查找周报")
@ApiImplicitParams(
@ApiImplicitParam(name = "id", value = "周报id", dataType = "String",
example = "5cd92cb738693323e8ee3ba9", required = true)
)
public ResponseEntity<Weekly> findOne(@RequestParam String id) {
return ResponseEntity.ok(weeklyService.findOne(id));
}
@GetMapping("/findAll")
@ApiOperation(value = "根据用户id查找所有周报")
@ApiImplicitParams(
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String",
example = "5cd92cb738693323e8ee3ba9", required = true)
)
public ResponseEntity<List<WeeklySimple>> findByUser(@RequestParam String userId) {
return ResponseEntity.ok(weeklyService.findALlByUser(userId));
}
}
package com.zjty.tynotes.weekly.subject.entity;
import com.zjty.tynotes.weekly.misc.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2019-07-05
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "周报对象", description = "一条周报记录")
public class Weekly {
@ApiModelProperty(value = "主键id", name = "id", example = "qwer1234")
private String id = "";
@ApiModelProperty(value = "用户id", name = "userId", example = "qwer1234")
private String userId = "";
@ApiModelProperty(value = "周报标题", name = "taskId", example = "2019年01月01日 周报")
private String title = TimeUtil.longToString("yyyy年MM月dd日", System.currentTimeMillis()) + " 周报";
@ApiModelProperty(value = "创建时间", name = "createTime", example = "1500000000000")
private Long createTime = System.currentTimeMillis();
@ApiModelProperty(value = "更新时间", name = "updateTime", example = "1500000000000")
private Long updateTime = 0L;
@ApiModelProperty(value = "内容", name = "content", example = "这是内容")
private String content = "";
@ApiModelProperty(value = "问题备注", name = "problem", example = "这是问题备注")
private String problem = "";
@ApiModelProperty(value = "下周计划", name = "nextWeekPlan", example = "这是下周计划")
private String nextWeekPlan = "";
@ApiModelProperty(value = "备注", name = "remark", example = "这是备注")
private String remark = "";
}
package com.zjty.tynotes.weekly.subject.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2019-07-05
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "周报简单对象", description = "周报的简单对象")
public class WeeklySimple {
@ApiModelProperty(value = "标题", name = "title", example = "2019年01月01日 周报")
private String title;
@ApiModelProperty(value = "用户id", name = "userId", example = "qweasd1234qqqwe")
private String userId;
@ApiModelProperty(value = "更新时间", name = "updateTime", example = "1560234567")
private Long updateTime;
}
package com.zjty.tynotes.weekly.subject.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zjty.tynotes.pas.entity.Role;
import com.zjty.tynotes.pas.entity.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/3 10:03
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserVo {
@Id
@ApiModelProperty(value = "id",example = "1")
private String id;
@NotEmpty(message = "身份证号码不可为空")
@ApiModelProperty(value = "身份证",example = "48489498131566546")
private String idCard;
@NotEmpty(message = "地址不可为空")
@ApiModelProperty(value = "地址",example = "xx路xx楼xx号")
private String address;
@NotEmpty(message = "联系方式不可为空")
@ApiModelProperty(value = "联系方式",example = "113665465465")
private String phone1;
@NotEmpty(message = "联系方式不可为空")
@ApiModelProperty(value = "联系方式",example = "113665465465")
private String phone2;
@NotEmpty(message = "部门1不可为空")
@ApiModelProperty(value = "部门1",example = "研发部")
private String department1;
@NotEmpty(message = "部门2不可为空")
@ApiModelProperty(value = "部门2",example = "技术中心")
private String department2;
@NotEmpty(message = "部门3不可为空")
@ApiModelProperty(value = "部门3",example = "工作簿项目组")
private String department3;
@NotNull(message = "岗位不可为空")
@ApiModelProperty(value = "岗位",example = "1")
private String jobs;
@NotNull(message = "入职时间不可为空")
@ApiModelProperty(value = "入职时间",example = "2019-01-45 12:12:12")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Integer entryTime;
@NotEmpty(message = "邮箱不可为空")
@ApiModelProperty(value = "邮箱",example = "123456789@qq.com")
private String email;
@NotEmpty(message = "用户名不可为空")
@ApiModelProperty(value = "用户名",example = "username")
private String username;
@NotEmpty(message = "密码不可为空")
@ApiModelProperty(value = "密码",example = "password")
private String password;
@NotEmpty(message = "部门id")
@ApiModelProperty(value = "部门id",example = "1")
private String departmentId;
private List<Role> roles;
private String status;//工作状态(0代表空闲 1代表忙碌)
private Integer workCount;
// @NotNull(message = "角色Id不可为空")
// @ApiModelProperty(value = "角色id",example = "1")
// private Integer roleId;
public UserVo(User user) {
this.id = user.getId();
this.idCard = user.getIdCard();
this.address = user.getAddress();
this.phone1 = user.getPhone1();
this.phone2 = user.getPhone2();
this.department1 = user.getDepartment1();
this.department2 = user.getDepartment2();
this.department3 = user.getDepartment3();
this.jobs = user.getJobs();
this.entryTime = user.getEntryTime();
this.email = user.getEmail();
this.username = user.getUsername();
this.password = user.getPassword();
this.departmentId = user.getDepartmentId();
this.roles = new ArrayList<>();
this.status = null;
this.workCount = null;
}
}
package com.zjty.tynotes.weekly.subject.repository;
import com.zjty.tynotes.weekly.subject.entity.Weekly;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
/**
* @author LJJ cnljj1995@gmail.com
* on 2019-07-05
*/
@Repository
public interface WeeklyRepository extends MongoRepository<Weekly, String> {
}
package com.zjty.tynotes.weekly.subject.service;
import com.zjty.tynotes.pas.entity.Department;
import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.pas.entity.vo.PageResponse;
import com.zjty.tynotes.weekly.subject.entity.vo.UserVo;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/2 13:07
*/
public interface UserManageService {
/**
* 根据id查询用户
* @param id
* @return
*/
User findUserById(String id);
/**
* 分页查询管理用户
* @param pageRequest
* @return
*/
PageResponse<UserVo> findUserList(PageRequest pageRequest);
/**
* 根据用户id查询可管理的部门列表
* @param id
* @return
*/
List<Department> findDepartmentList(String id);
// /**
// * 根据任务状态查询人员任务列表
// * @param id
// * @param status
// * @return
// */
// List<Work> findUserWork(String id, String status);
}
package com.zjty.tynotes.weekly.subject.service;
import com.zjty.tynotes.weekly.subject.entity.Weekly;
import com.zjty.tynotes.weekly.subject.entity.WeeklySimple;
import java.util.List;
/**
* @author LJJ cnljj1995@gmail.com
* on 2019-07-05
*/
public interface WeeklyService {
/**
* 保存更新
* @param weekly
*/
void updateWeekly(Weekly weekly);
/**
* 创建任务
* @param userId
*/
void createWeekly(String userId);
/**
* 根据周报id查找周报
* @param id
* @return
*/
Weekly findOne(String id);
/**
* 根据user查找工作记录
* @param userId
* @return
*/
List<WeeklySimple> findALlByUser(String userId);
}
package com.zjty.tynotes.weekly.subject.service.impl;
import com.zjty.tynotes.job.basic.entity.database.Work;
import com.zjty.tynotes.job.basic.repository.WorkRepository;
import com.zjty.tynotes.job.status.entity.Personnel;
import com.zjty.tynotes.job.status.service.InternalService;
import com.zjty.tynotes.pas.dao.*;
import com.zjty.tynotes.pas.entity.*;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.pas.entity.vo.PageResponse;
import com.zjty.tynotes.weekly.subject.entity.vo.UserVo;
import com.zjty.tynotes.weekly.subject.service.UserManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @Author gwj
* @create 2020/3/2 13:07
*/
@Service
public class UserManageServiceImpl implements UserManageService {
@Autowired
private PasUserDao pasUserDao;
@Autowired
private UserRoleDao userRoleDao;
@Autowired
private RoleDao roleDao;
@Autowired
private RoleAuthorityDao roleAuthorityDao;
@Autowired
private AuthorityDao authorityDao;
@Autowired
private DepartmentDao departmentDao;
@Autowired
private InternalService internalService;
@Override
public User findUserById(String id) {
Optional<User> optional = pasUserDao.findById(id);
User user = null;
if(optional.isPresent()){
user = optional.get();
List<String> roleIds = new ArrayList<>();
List<UserRole> userRoles = userRoleDao.findAllByUserId(user.getId());
for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId());
}
List<Role> roles = roleDao.findAllByIdIn(roleIds);
user.setRoles(roles);
}
return user;
}
/**
* 查询人员列表
* @param pageRequest
* @return
*/
@Override
public PageResponse<UserVo> findUserList(PageRequest pageRequest) {
List<User> users = new ArrayList<>();
PageResponse<UserVo> pageResponse = new PageResponse<>();
pageResponse.setCurrentPage(pageRequest.getCurrentPage());
pageResponse.setPageSize(pageRequest.getPageSize());
if(pageRequest.getDeId()!=null){
users = pasUserDao.findAllByDepartmentId(pageRequest.getId());
}else{
List<Department> departmentList = findDepartmentList(pageRequest.getId());
List<String> departmentIds = new ArrayList<>();
for (Department department : departmentList) {
departmentIds.add(department.getId());
}
users = pasUserDao.findAllByDepartmentIdIn(departmentIds);
}
List<String> userIds = new ArrayList<>();
for (User user : users) {
userIds.add(user.getId());
}
List<Personnel> personnels = internalService.personnels(userIds);
List<UserVo> userVos = new ArrayList<>();
for (User user : users) {
for (Personnel personnel : personnels) {
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) {
return o1.getWorkCount()-o2.getWorkCount();
}
});
}else{
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);
pageResponse.setTotalPage((userVos.size()/pageResponse.getPageSize())+1);
pageResponse.setTotalCount(userVos.size());
return pageResponse;
}
/**
* 查询可查看的部门列表
* @param id
* @return
*/
@Override
public List<Department> findDepartmentList(String id) {
List<UserRole> userRoles = userRoleDao.findAllByUserId(id);
List<String> roleIds = new ArrayList<>();
for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId());
}
List<Role> roles = roleDao.findAllByIdIn(roleIds);
for (Role role : roles) {
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(role.getId());
List<String> authorityIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) {
authorityIds.add(roleAuthority.getAuthorityId());
}
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
role.setAuthorities(authorities);
}
List<Role> roleList = new ArrayList<>();
for (Role role : roles) {
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;
}
private List<Department> findDepartmentList(List<Department> des, List<Department> deps){
for (Department department : deps) {
if(!des.contains(department)){
des.add(department);
}
}
for (Department department : deps) {
List<Department> departments = departmentDao.findAllByParentId(department.getId());
if(departments!=null){
findDepartmentList(des,departments);
}
}
return des;
}
}
package com.zjty.tynotes.weekly.subject.service.impl;
import com.zjty.tynotes.weekly.subject.entity.Weekly;
import com.zjty.tynotes.weekly.subject.entity.WeeklySimple;
import com.zjty.tynotes.weekly.subject.repository.WeeklyRepository;
import com.zjty.tynotes.weekly.subject.service.WeeklyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author LJJ cnljj1995@gmail.com
* on 2019-07-05
*/
@Service
public class WeeklyServiceImpl implements WeeklyService {
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private WeeklyRepository weeklyRepository;
@Override
public void updateWeekly(Weekly weekly) {
weekly.setUpdateTime(System.currentTimeMillis());
weeklyRepository.save(weekly);
}
@Override
public void createWeekly(String userId) {
Weekly weekly = new Weekly();
weekly.setUserId(userId);
weeklyRepository.save(weekly);
}
@Override
public Weekly findOne(String id) {
Criteria criteria = new Criteria();
criteria.and("_id").is(id);
Query query = new Query(criteria);
return mongoTemplate.findOne(query, Weekly.class);
}
@Override
public List<WeeklySimple> findALlByUser(String userId) {
Criteria criteria = new Criteria();
criteria.and("userId").is(userId);
Query query = new Query(criteria);
query.with(new Sort(Sort.Direction.DESC, "createTime"));
List<Weekly> weeklies = mongoTemplate.find(query, Weekly.class);
return weekly2simple(weeklies);
}
private List<WeeklySimple> weekly2simple(List<Weekly> weeklies) {
List<WeeklySimple> rs = new ArrayList<>();
weeklies.forEach(o -> rs.add(new WeeklySimple(o.getTitle(), o.getUserId(), o.getUpdateTime())));
return rs;
}
}
package com.zjty.tynotes.weekly.task; //package com.zjty.tynotes.weekly.task;
//
import com.zjty.tynotes.pas.entity.User; //import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.service.IUserService; //import com.zjty.tynotes.pas.service.IUserService;
import com.zjty.tynotes.weekly.subject.service.WeeklyService; //import com.zjty.tynotes.weekly.subject.service.WeeklyService;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import java.util.List; //import java.util.List;
//
/** ///**
* @author LJJ cnljj1995@gmail.com // * @author LJJ cnljj1995@gmail.com
* on 2019-07-05 // * on 2019-07-05
*/ // */
@Slf4j //@Slf4j
@Service //@Service
public class WeeklyInit { //public class WeeklyInit {
@Autowired // @Autowired
WeeklyService weeklyService; // WeeklyService weeklyService;
//
@Autowired // @Autowired
IUserService iUserService; // IUserService iUserService;
//
// @Scheduled(cron = "0 5 0 ? * MON") //// @Scheduled(cron = "0 5 0 ? * MON")
public void task(){ // public void task(){
List<User> list=iUserService.findAll(); // List<User> list=iUserService.findAll();
for (User user:list){ // for (User user:list){
weeklyService.createWeekly(user.getId()); // weeklyService.createWeekly(user.getId());
} // }
log.info("每周的个人周报生成完成"); // log.info("每周的个人周报生成完成");
} // }
} //}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论