dcs 10 mēneši atpakaļ
vecāks
revīzija
377df616fe

+ 42 - 36
virgo.core/src/main/java/com/bosshand/virgo/core/service/MgrUserService.java

@@ -252,52 +252,58 @@ public class MgrUserService {
 	/**
 	 * 获取用户所在项目身份
 	 */
-	private Map<Long, Set<JSONObject>> getProjectIdentity(long organizationId, MgrUser user) {
+	private Map<Long, Set<JSONObject>> getProjectIdentity(MgrUser user) {
 		Map<Long, Set<JSONObject>> map = new HashMap<>();
 
 		Set<Long> projectIds = new HashSet<>();
 
 		long userId = user.getId();
 
-		// 根据部门ids查找出部门树下的项目id
-		MgrUserRole mgrUserRole = mgrUserRoleDao.getUser(userId, organizationId);
-		if (mgrUserRole != null & StringUtil.notBlank(mgrUserRole.getRoles())) {
-			List<Long> roleIds = new ArrayList<>();
-			for (String roleId : mgrUserRole.getRoles().split(",")) {
-				roleIds.add(Long.parseLong(roleId));
-			}
-			List<MgrRole> mgrRoleList = mgrRoleDao.getIds(roleIds);
-			for (MgrRole role : mgrRoleList) {
-				projectIds.add(role.getProjectId());
-			}
-		}
+		List<MgrUserRole> userRoles = mgrUserRoleDao.getUserRoles(userId);
+		if (userRoles != null && userRoles.size() > 0) {
+			for (MgrUserRole mgrUserRole : userRoles) {
+				// 根据部门ids查找出部门树下的项目id
+				if (mgrUserRole != null) {
+					if (StringUtil.notBlank(mgrUserRole.getRoles())) {
+						List<Long> roleIds = new ArrayList<>();
+						for (String roleId : mgrUserRole.getRoles().split(",")) {
+							roleIds.add(Long.parseLong(roleId));
+						}
+						List<MgrRole> mgrRoleList = mgrRoleDao.getIds(roleIds);
+						for (MgrRole role : mgrRoleList) {
+							projectIds.add(role.getProjectId());
+						}
+					}
+				}
 
-		List<MgrOrganizationProject> list = mgrOrganizationProjectDao.get(organizationId, userId);
-		if (list != null & list.size() > 0) {
-			for (MgrOrganizationProject mop : list) {
-				projectIds.add(mop.getProjectId());
-			}
-		}
+				List<MgrOrganizationProject> list = mgrOrganizationProjectDao.get(mgrUserRole.getOrganizationId(), userId);
+				if (list != null & list.size() > 0) {
+					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));
+				if (projectIds.size() > 0) {
+					for (Long projectId : projectIds) {
+						Set<JSONObject> identityList = new HashSet<>();
+						if (isAdmin(user, mgrUserRole.getOrganizationId())) {
+							identityList.add(convert(Identity.DEFAULT_OWNER_ID));
+						} else {
+							identityList.add(convert(Identity.DEFAULT_MEMBER_ID));
+						}
+						map.put(projectId, identityList);
+					}
 				}
-				map.put(projectId, identityList);
-			}
-		}
 
-		if (list != null & list.size() > 0) {
-			for (MgrOrganizationProject mop : list) {
-				map.forEach((key, value) -> {
-					if (mop.getProjectId() == key) {
-						value.add(convert(mop.getIdentityId()));
+				if (list != null & list.size() > 0) {
+					for (MgrOrganizationProject mop : list) {
+						map.forEach((key, value) -> {
+							if (mop.getProjectId() == key) {
+								value.add(convert(mop.getIdentityId()));
+							}
+						});
 					}
-				});
+				}
 			}
 		}
 
@@ -372,7 +378,7 @@ public class MgrUserService {
     	subject.getSession().setAttribute("USER",user);
 
     	// 当前用户在项目中身份
-		Map<Long, Set<JSONObject>> projectListIdentity = this.getProjectIdentity(user.getLastOrganizationId(), user);
+		Map<Long, Set<JSONObject>> projectListIdentity = this.getProjectIdentity(user);
     	
     	UserContext context = UserContext.getUserContext(user, organizationList, currentOrganization, currentUserRole, projectListIdentity);
     	subject.getSession().setAttribute("USERCONTEXT", context);