Commit 9e50ac7b by manxiaoqiang

合同

parent 97caee98
...@@ -172,4 +172,13 @@ public class UserController { ...@@ -172,4 +172,13 @@ public class UserController {
public ResultModel validCode(@RequestParam String email, @RequestParam String code, @RequestParam String pwd) { public ResultModel validCode(@RequestParam String email, @RequestParam String code, @RequestParam String pwd) {
return ResultModel.OK(userService.validCode(email, code, pwd)); return ResultModel.OK(userService.validCode(email, code, pwd));
} }
@RequestMapping(value = "/find/{role}", method = RequestMethod.GET)
@ResponseBody
public ResultModel findByRole(@PathVariable Long role) {
return ResultModel.OK(userService.findbyRole(role));
}
} }
...@@ -20,6 +20,7 @@ public class User { ...@@ -20,6 +20,7 @@ public class User {
private String roleTypeName; private String roleTypeName;
private String auth; private String auth;
private Boolean status; private Boolean status;
private Long parent;
private Long modifyAccount; private Long modifyAccount;
private Long createAccount; private Long createAccount;
...@@ -152,6 +153,14 @@ public class User { ...@@ -152,6 +153,14 @@ public class User {
this.roleName = roleName; this.roleName = roleName;
} }
public Long getParent() {
return parent;
}
public void setParent(Long parent) {
this.parent = parent;
}
@Override @Override
public String toString() { public String toString() {
return "User{" + return "User{" +
...@@ -160,8 +169,12 @@ public class User { ...@@ -160,8 +169,12 @@ public class User {
", password='" + password + '\'' + ", password='" + password + '\'' +
", name='" + name + '\'' + ", name='" + name + '\'' +
", role=" + role + ", role=" + role +
", roleName='" + roleName + '\'' +
", roleType=" + roleType + ", roleType=" + roleType +
", roleTypeName='" + roleTypeName + '\'' +
", auth='" + auth + '\'' + ", auth='" + auth + '\'' +
", status=" + status +
", parent=" + parent +
", modifyAccount=" + modifyAccount + ", modifyAccount=" + modifyAccount +
", createAccount=" + createAccount + ", createAccount=" + createAccount +
", modifyTime=" + modifyTime + ", modifyTime=" + modifyTime +
......
...@@ -2,6 +2,7 @@ package common.repository; ...@@ -2,6 +2,7 @@ package common.repository;
import common.model.Auth; import common.model.Auth;
import common.model.Menu; import common.model.Menu;
import common.model.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -12,4 +13,7 @@ import java.util.List; ...@@ -12,4 +13,7 @@ import java.util.List;
public interface AuthRepository extends JpaRepository<Auth, Long> { public interface AuthRepository extends JpaRepository<Auth, Long> {
Auth findByUser(Long user); Auth findByUser(Long user);
@Query(value="SELECT * from `auth` where user in ?1",nativeQuery=true)
List<Auth> findAllByUsers(List<Long> ids);
} }
...@@ -26,7 +26,27 @@ public interface UserRepository extends JpaRepository<User, Long> { ...@@ -26,7 +26,27 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query(value="select * from user where del_flag is not true and (role = 2 or role = 3)",nativeQuery=true) @Query(value="select * from user where del_flag is not true and (role = 2 or role = 3)",nativeQuery=true)
List<User> findSales(); List<User> findSales();
@Query(value="select * from user where role = 2 or role = 3",nativeQuery=true) @Query(value="SELECT * from `user` where del_flag is not true and role = ?1 ORDER BY role_type",nativeQuery=true)
List<User> findAllSales(); List<User> findAllByRole(Long role);
@Query(value="SELECT * from `user` where role = ?1 ORDER BY role_type",nativeQuery=true)
List<User> findAllUserByRole(Long role);
@Query(value="SELECT * from `user` where del_flag is not true and parent = ?1",nativeQuery=true)
List<User> findAllByParent(Long id);
@Query(value="SELECT * from `user` where parent = ?1",nativeQuery=true)
List<User> findByParent(Long id);
@Query(value="SELECT * from `user` where del_flag is not true and id in ?1",nativeQuery=true)
List<User> findAllByIds(List<Long> ids);
@Query(value="SELECT * from `user` where id in ?1",nativeQuery=true)
List<User> findByIds(List<Long> ids);
@Query(value="SELECT * from `user` where del_flag is not true and parent in ?1",nativeQuery=true)
List<User> findAllByParents(List<Long> ids);
@Query(value="SELECT * from `user` where parent in ?1",nativeQuery=true)
List<User> findByParents(List<Long> ids);
} }
...@@ -33,4 +33,10 @@ public interface UserService { ...@@ -33,4 +33,10 @@ public interface UserService {
Boolean sendCode(String email); Boolean sendCode(String email);
Boolean validCode(String email, String code, String pwd); Boolean validCode(String email, String code, String pwd);
List<User> findbyRole(Long role);
List<User> findSonsAlive(Long user);
List<User> findAllSons(Long user);
} }
...@@ -9,6 +9,8 @@ import common.repository.UserRepository; ...@@ -9,6 +9,8 @@ import common.repository.UserRepository;
import common.service.UserService; import common.service.UserService;
import dic.RoleEnum; import dic.RoleEnum;
import dic.RoleTypeEnum; import dic.RoleTypeEnum;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import office.service.BussinussManService; import office.service.BussinussManService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -101,7 +103,45 @@ public class UserServiceImpl implements UserService { ...@@ -101,7 +103,45 @@ public class UserServiceImpl implements UserService {
auth.setModifyAccount(login.getId()); auth.setModifyAccount(login.getId());
auth.setAuth(resource.getAuth()); auth.setAuth(resource.getAuth());
auth.setUser(save.getId()); auth.setUser(save.getId());
authRepository.save(auth); Auth authSave = authRepository.save(auth);
if(save.getRoleType().equals(RoleTypeEnum.COMMON.getKey())){
JSONArray rootArr = JSONArray.fromObject(authSave.getAuth());
List<String> authList = new ArrayList<>();
if(ValidateUtil.isValid(rootArr)){
for (int i = 0; i < rootArr.size(); i++) {
JSONObject obj = rootArr.getJSONObject(i);
authList.add(obj.getString("id"));
}
}
List<User> userList = findSonsAlive(save.getId());
if(ValidateUtil.isValid(userList)){
List<Long> ids = new ArrayList<>();
for(User u : userList){
ids.add(u.getId());
}
List<Auth> list = authRepository.findAllByUsers(ids);
if(ValidateUtil.isValid(list)){
List<Auth> authListSave = new ArrayList<>();
for(Auth a : list){
String authStr = a.getAuth();
JSONArray arrSave = new JSONArray();
JSONArray arr = JSONArray.fromObject(authStr);
if(ValidateUtil.isValid(arr)){
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
if(authList.contains(obj.getString("id"))){
arrSave.add(obj);
}
}
}
a.setAuth(arrSave.toString());
authListSave.add(a);
}
authRepository.save(authSave);
}
}
}
return save; return save;
} }
...@@ -120,6 +160,8 @@ public class UserServiceImpl implements UserService { ...@@ -120,6 +160,8 @@ public class UserServiceImpl implements UserService {
userList = userRepository.findList(); userList = userRepository.findList();
} else if(RoleTypeEnum.MANAGER.getKey().equals(login.getRoleType())){ } else if(RoleTypeEnum.MANAGER.getKey().equals(login.getRoleType())){
userList = userRepository.findOneDepartment(login.getRole()); userList = userRepository.findOneDepartment(login.getRole());
}else{
userList = findSonsAlive(login.getId());
} }
if(ValidateUtil.isValid(userList)){ if(ValidateUtil.isValid(userList)){
for(User u : userList){ for(User u : userList){
...@@ -226,4 +268,85 @@ public class UserServiceImpl implements UserService { ...@@ -226,4 +268,85 @@ public class UserServiceImpl implements UserService {
} }
return false; return false;
} }
@Override
public List<User> findbyRole(Long role) {
List<Auth> authList = authRepository.findAll();
Map<Long, String> map = new HashMap<>();
if(ValidateUtil.isValid(authList)){
for(Auth a : authList){
map.put(a.getUser(), a.getAuth());
}
}
List<User> result = new ArrayList<>();
List<User> userList = userRepository.findAllByRole(role);
if(ValidateUtil.isValid(userList)){
for(User u : userList){
if(map.containsKey(u.getId())){
u.setAuth(map.get(u.getId()));
}
result.add(u);
}
}
return result;
}
@Override
public List<User> findSonsAlive(Long user) {
List<User> result = new ArrayList<>();
User one = userRepository.findOne(user);
if(one.getRole().equals(RoleEnum.MANAGER.getKey())){
List<User> list = userRepository.findList();
if(ValidateUtil.isValid(list)){
result.addAll(list);
}
} else if(one.getRoleType().equals(RoleTypeEnum.MANAGER.getKey())){
List<User> list = userRepository.findAllByRole(one.getRole());
if(ValidateUtil.isValid(list)){
result.addAll(list);
}
} else{
List<User> list = userRepository.findAllByParent(user);
while(ValidateUtil.isValid(list)){
result.addAll(list);
List<Long> ids = new ArrayList<>();
for(User u : list){
ids.add(u.getId());
}
list = userRepository.findAllByParents(ids);
}
}
return result;
}
@Override
public List<User> findAllSons(Long user) {
List<User> result = new ArrayList<>();
User one = userRepository.findOne(user);
if(one.getRole().equals(RoleEnum.MANAGER.getKey())){
List<User> list = userRepository.findAll();
if(ValidateUtil.isValid(list)){
result.addAll(list);
}
} else if(one.getRoleType().equals(RoleTypeEnum.MANAGER.getKey())){
List<User> list = userRepository.findAllUserByRole(one.getRole());
if(ValidateUtil.isValid(list)){
result.addAll(list);
}
} else{
List<User> list = userRepository.findByParent(user);
while(ValidateUtil.isValid(list)){
result.addAll(list);
List<Long> ids = new ArrayList<>();
for(User u : list){
ids.add(u.getId());
}
list = userRepository.findByParents(ids);
}
}
return result;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment