|
@@ -199,6 +199,21 @@ public class MgrUserService {
|
|
|
mgrUserDao.updateLastProjectId(user);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 缓存身份列表
|
|
|
+ */
|
|
|
+ public Map<Long, Identity> identityCache = new HashMap<Long, Identity>();
|
|
|
+
|
|
|
+ public Identity getIdentity(Long pk) {
|
|
|
+ Identity identity = identityCache.get(pk);
|
|
|
+ if (identity == null) {
|
|
|
+ identity = identityDao.get(pk);
|
|
|
+ identityCache.put((Long) pk, identity);
|
|
|
+ }
|
|
|
+ return identity;
|
|
|
+ }
|
|
|
+
|
|
|
public List<Identity> getIdentityList(long projectId, long userId) {
|
|
|
List<MgrOrganizationProject> list = mgrOrganizationProjectDao.getProject(projectId, userId);
|
|
|
Set<Long> identityIds = new HashSet<>();
|
|
@@ -230,6 +245,46 @@ public class MgrUserService {
|
|
|
return new ArrayList<Long>(projectIds);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取用户所在项目身份
|
|
|
+ */
|
|
|
+ private Map<Long, Set<JSONObject>> getProjectIdentity(long organizationId, MgrUser user) {
|
|
|
+ Map<Long, Set<JSONObject>> map = new HashMap<>();
|
|
|
+ List<MgrOrganizationProject> list = mgrOrganizationProjectDao.get(organizationId, user.getId());
|
|
|
+ if (list != null & list.size() > 0) {
|
|
|
+ Set<Long> projectIds = new HashSet<>();
|
|
|
+ for (MgrOrganizationProject mop : list) {
|
|
|
+ projectIds.add(mop.getProjectId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (projectIds.size() > 0) {
|
|
|
+ for (Long projectId : projectIds) {
|
|
|
+ Set<JSONObject> identityList = new HashSet<>();
|
|
|
+ if (isAdmin(user, organizationId)) {
|
|
|
+ identityList.add(convert(Identity.DEFAULT_OWNER_ID));
|
|
|
+ } else {
|
|
|
+ identityList.add(convert(Identity.DEFAULT_MEMBER_ID));
|
|
|
+ }
|
|
|
+ map.put(projectId, identityList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (MgrOrganizationProject mop : list) {
|
|
|
+ map.forEach((key, value) -> {
|
|
|
+ if (mop.getProjectId() == key) {
|
|
|
+ value.add(convert(mop.getIdentityId()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject convert(long id) {
|
|
|
+ String s = JSONObject.toJSONString(this.getIdentity(id));
|
|
|
+ return JSONObject.parseObject(s);
|
|
|
+ }
|
|
|
+
|
|
|
public MgrResource getDefaultResource() {
|
|
|
return mgrResourceDao.defaultResource();
|
|
|
}
|
|
@@ -291,8 +346,11 @@ public class MgrUserService {
|
|
|
|
|
|
subject.getSession().setTimeout(25920000000L);
|
|
|
subject.getSession().setAttribute("USER",user);
|
|
|
+
|
|
|
+ // 当前用户在项目中身份
|
|
|
+ Map<Long, Set<JSONObject>> projectListIdentity = this.getProjectIdentity(user.getLastOrganizationId(), user);
|
|
|
|
|
|
- UserContext context = UserContext.getUserContext(user, organizationList, currentOrganization, currentUserRole);
|
|
|
+ UserContext context = UserContext.getUserContext(user, organizationList, currentOrganization, currentUserRole, projectListIdentity);
|
|
|
subject.getSession().setAttribute("USERCONTEXT", context);
|
|
|
|
|
|
}
|