Commit 9e50ac7b by manxiaoqiang

合同

parent 97caee98
......@@ -172,4 +172,13 @@ public class UserController {
public ResultModel validCode(@RequestParam String email, @RequestParam String code, @RequestParam String 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 {
private String roleTypeName;
private String auth;
private Boolean status;
private Long parent;
private Long modifyAccount;
private Long createAccount;
......@@ -152,6 +153,14 @@ public class User {
this.roleName = roleName;
}
public Long getParent() {
return parent;
}
public void setParent(Long parent) {
this.parent = parent;
}
@Override
public String toString() {
return "User{" +
......@@ -160,8 +169,12 @@ public class User {
", password='" + password + '\'' +
", name='" + name + '\'' +
", role=" + role +
", roleName='" + roleName + '\'' +
", roleType=" + roleType +
", roleTypeName='" + roleTypeName + '\'' +
", auth='" + auth + '\'' +
", status=" + status +
", parent=" + parent +
", modifyAccount=" + modifyAccount +
", createAccount=" + createAccount +
", modifyTime=" + modifyTime +
......
......@@ -2,6 +2,7 @@ package common.repository;
import common.model.Auth;
import common.model.Menu;
import common.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
......@@ -12,4 +13,7 @@ import java.util.List;
public interface AuthRepository extends JpaRepository<Auth, Long> {
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> {
@Query(value="select * from user where del_flag is not true and (role = 2 or role = 3)",nativeQuery=true)
List<User> findSales();
@Query(value="select * from user where role = 2 or role = 3",nativeQuery=true)
List<User> findAllSales();
@Query(value="SELECT * from `user` where del_flag is not true and role = ?1 ORDER BY role_type",nativeQuery=true)
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 {
Boolean sendCode(String email);
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;
import common.service.UserService;
import dic.RoleEnum;
import dic.RoleTypeEnum;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import office.service.BussinussManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -101,7 +103,45 @@ public class UserServiceImpl implements UserService {
auth.setModifyAccount(login.getId());
auth.setAuth(resource.getAuth());
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;
}
......@@ -120,6 +160,8 @@ public class UserServiceImpl implements UserService {
userList = userRepository.findList();
} else if(RoleTypeEnum.MANAGER.getKey().equals(login.getRoleType())){
userList = userRepository.findOneDepartment(login.getRole());
}else{
userList = findSonsAlive(login.getId());
}
if(ValidateUtil.isValid(userList)){
for(User u : userList){
......@@ -226,4 +268,85 @@ public class UserServiceImpl implements UserService {
}
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