mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
#61 add myorgans into loginUser
This commit is contained in:
parent
2cdbc8a386
commit
0efb7615e0
@ -16,10 +16,26 @@
|
||||
*/
|
||||
package com.chatopera.cc.webim.web.handler;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.chatopera.cc.core.UKDataContext;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import com.chatopera.cc.util.UKTools;
|
||||
import com.chatopera.cc.webim.service.cache.CacheHelper;
|
||||
import com.chatopera.cc.webim.service.repository.OrganRepository;
|
||||
import com.chatopera.cc.webim.service.repository.RoleAuthRepository;
|
||||
import com.chatopera.cc.webim.service.repository.UserRepository;
|
||||
import com.chatopera.cc.webim.service.repository.UserRoleRepository;
|
||||
import com.chatopera.cc.webim.util.OnlineUserUtils;
|
||||
import com.chatopera.cc.webim.web.model.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
@ -29,49 +45,22 @@ import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import com.chatopera.cc.core.UKDataContext;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import com.chatopera.cc.webim.service.cache.CacheHelper;
|
||||
import com.chatopera.cc.webim.service.repository.OrganRepository;
|
||||
import com.chatopera.cc.webim.service.repository.OrganRoleRepository;
|
||||
import com.chatopera.cc.webim.service.repository.RoleAuthRepository;
|
||||
import com.chatopera.cc.webim.service.repository.UserRoleRepository;
|
||||
import com.chatopera.cc.webim.util.OnlineUserUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.chatopera.cc.util.UKTools;
|
||||
import com.chatopera.cc.webim.service.repository.UserRepository;
|
||||
import com.chatopera.cc.webim.web.model.Organ;
|
||||
import com.chatopera.cc.webim.web.model.OrganRole;
|
||||
import com.chatopera.cc.webim.web.model.Role;
|
||||
import com.chatopera.cc.webim.web.model.RoleAuth;
|
||||
import com.chatopera.cc.webim.web.model.SystemConfig;
|
||||
import com.chatopera.cc.webim.web.model.User;
|
||||
import com.chatopera.cc.webim.web.model.UserRole;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author UK
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class LoginController extends Handler {
|
||||
private final static Logger logger = LoggerFactory.getLogger(LoginController.class);
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private OrganRoleRepository organRoleRes ;
|
||||
|
||||
@Autowired
|
||||
private UserRoleRepository userRoleRes;
|
||||
|
||||
@ -81,6 +70,21 @@ public class LoginController extends Handler{
|
||||
@Autowired
|
||||
private OrganRepository organRepository;
|
||||
|
||||
/**
|
||||
* 获取一个用户所拥有的所有部门ID
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
private void organs(final User user, final String organ) {
|
||||
if (organ == null)
|
||||
return;
|
||||
user.getMyorgans().add(organ);
|
||||
List<Organ> y = organRepository.findByOrgiAndParent(user.getOrgi(), organ);
|
||||
for (Organ x : y) {
|
||||
organs(user, x.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
||||
@Menu(type = "apps", subtype = "user", access = true)
|
||||
public ModelAndView login(HttpServletRequest request, HttpServletResponse response, @RequestHeader(value = "referer", required = false) String referer, @Valid String msg) throws NoSuchAlgorithmException {
|
||||
@ -180,6 +184,9 @@ public class LoginController extends Handler{
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户部门以及下级部门
|
||||
organs(loginUser, loginUser.getOrgan()); // 添加部门到myorgans中
|
||||
|
||||
// 获取用户的角色权限,进行授权
|
||||
List<RoleAuth> roleAuthList = roleAuthRes.findAll(new Specification<RoleAuth>() {
|
||||
@Override
|
||||
@ -194,7 +201,9 @@ public class LoginController extends Handler{
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
cb.and(cb.equal(root.get("orgi").as(String.class), loginUser.getOrgi()));
|
||||
return cb.or(list.toArray(p));
|
||||
}}) ;
|
||||
}
|
||||
});
|
||||
|
||||
if (roleAuthList != null) {
|
||||
for (RoleAuth roleAuth : roleAuthList) {
|
||||
loginUser.getRoleAuthMap().put(roleAuth.getDicvalue(), true);
|
||||
@ -205,6 +214,7 @@ public class LoginController extends Handler{
|
||||
if (!StringUtils.isBlank(loginUser.getId())) {
|
||||
userRepository.save(loginUser);
|
||||
}
|
||||
|
||||
super.setUser(request, loginUser);
|
||||
//当前用户 企业id为空 调到创建企业页面
|
||||
if (StringUtils.isBlank(loginUser.getOrgid())) {
|
||||
|
@ -217,6 +217,7 @@ public class AppsController extends Handler {
|
||||
User sessionUser = super.getUser(request) ;
|
||||
tempUser.setRoleList(sessionUser.getRoleList()) ;
|
||||
tempUser.setRoleAuthMap(sessionUser.getRoleAuthMap());
|
||||
tempUser.setMyorgans(sessionUser.getMyorgans());
|
||||
User u = tempUser;
|
||||
u.setOrgi(super.getOrgi(request));
|
||||
super.setUser(request, u);
|
||||
|
@ -17,11 +17,7 @@
|
||||
package com.chatopera.cc.webim.web.model;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@ -104,6 +100,7 @@ public class User implements java.io.Serializable{
|
||||
private int fans; //粉丝
|
||||
private int follows; //关注
|
||||
private int integral; //积分
|
||||
private HashSet<String> myorgans = new HashSet<>();
|
||||
private List<Role> roleList = new ArrayList<Role>();
|
||||
private Map<String ,Object> roleAuthMap = new HashMap<String ,Object>();
|
||||
|
||||
@ -517,4 +514,13 @@ public class User implements java.io.Serializable{
|
||||
public void setOrdertype(String ordertype) {
|
||||
this.ordertype = ordertype;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public HashSet<String> getMyorgans() {
|
||||
return myorgans;
|
||||
}
|
||||
|
||||
public void setMyorgans(HashSet<String> myorgans) {
|
||||
this.myorgans = myorgans;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user