|
@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class MgrUserService {
|
|
@@ -26,7 +27,7 @@ public class MgrUserService {
|
|
|
|
|
|
@Autowired
|
|
|
private MgrUserDao mgrUserDao;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private MgrUserRoleDao mgrUserRoleDao;
|
|
|
|
|
@@ -151,7 +152,7 @@ public class MgrUserService {
|
|
|
this.addChatUser(String.valueOf(user.getId()),user.getName());
|
|
|
this.addWorkarkChatUser(String.valueOf(user.getId()),user.getName());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public MgrUser getById(long id) {
|
|
|
return mgrUserDao.getById(id);
|
|
|
}
|
|
@@ -167,6 +168,13 @@ public class MgrUserService {
|
|
|
return mgrOrganizationDao.getById(user.getLastOrganizationId());
|
|
|
}
|
|
|
|
|
|
+ public MgrOrganization getWorkarkLastOrganization(MgrUser user) {
|
|
|
+ if(user == null || user.getLastWorkarkOrganizationId() == -1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return mgrOrganizationDao.getById(user.getLastWorkarkOrganizationId());
|
|
|
+ }
|
|
|
+
|
|
|
public List<MgrOrganization> getOrganizationList(MgrUser user) {
|
|
|
if (this.isSupperAdmin(user)) {
|
|
|
return mgrOrganizationDao.listAll();
|
|
@@ -182,20 +190,45 @@ public class MgrUserService {
|
|
|
mgrOrganizations.forEach(l -> l.setB(map.get(l.getId())));
|
|
|
return mgrOrganizations;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public List<MgrOrganization> getWorkarkOrganizationList(MgrUser user) {
|
|
|
+ List<Long> organizationIds = new ArrayList<>();
|
|
|
+ List<MgrRole> roles = mgrRoleDao.getListByProject(-1);
|
|
|
+ roles.forEach(ls -> organizationIds.add(ls.getOrganizationId()));
|
|
|
+ if (organizationIds.size() > 0) {
|
|
|
+ List<MgrOrganization> organizationList = mgrOrganizationDao.organizationByIds(organizationIds);
|
|
|
+ if (this.isSupperAdmin(user)) {
|
|
|
+ return organizationList;
|
|
|
+ }
|
|
|
+ List<MgrUserRole> userRoleList = getUserRoles(user);
|
|
|
+ List<Long> ids = new LinkedList<Long>();
|
|
|
+ Map<Long, Boolean> map = new HashMap<>();
|
|
|
+ userRoleList.forEach(r -> {
|
|
|
+ ids.add(r.getOrganizationId());
|
|
|
+ map.put(r.getOrganizationId(), r.isAdmin());
|
|
|
+ });
|
|
|
+ // 取交集
|
|
|
+ List<Long> intersection = organizationIds.stream().filter(ids::contains).collect(Collectors.toList());
|
|
|
+ List<MgrOrganization> mgrOrganizations = mgrOrganizationDao.listByIds(intersection);
|
|
|
+ mgrOrganizations.forEach(l -> l.setB(map.get(l.getId())));
|
|
|
+ return mgrOrganizations;
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
public List<MgrUserRole> getUserRoles(MgrUser user){
|
|
|
List<MgrUserRole> roleList = new LinkedList<MgrUserRole>();
|
|
|
- if(user != null ) {
|
|
|
+ if(user != null ) {
|
|
|
return mgrUserRoleDao.getUserRoles(user.getId());
|
|
|
}
|
|
|
return roleList;
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
//-1 means all organization
|
|
|
public boolean isSupperAdmin(MgrUser user) {
|
|
|
return isAdmin(user, -1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public boolean isAdmin(MgrUser user, long organizationId) {
|
|
|
MgrUserRole userRole = getUserRole(user, organizationId);
|
|
|
if(userRole == null) {
|
|
@@ -216,11 +249,16 @@ public class MgrUserService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public void switchWorkarkOrganization(MgrUser user, MgrOrganization organization) {
|
|
|
+ user.setLastWorkarkOrganizationId(organization.getId());
|
|
|
+ mgrUserDao.updateLastWorkarkOrganizationId(user);
|
|
|
+ }
|
|
|
+
|
|
|
public void switchOrganization(MgrUser user, MgrOrganization organization) {
|
|
|
user.setLastOrganizationId(organization.getId());
|
|
|
mgrUserDao.updateLastOrganizationId(user);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void switchProject(MgrUser user, long projectId) {
|
|
|
user.setLastProjectId(projectId);
|
|
|
mgrUserDao.updateLastProjectId(user);
|
|
@@ -376,6 +414,36 @@ public class MgrUserService {
|
|
|
throw new ServiceException("fail to get user", Constant.RET_NO_SPECIFIC_USER);
|
|
|
}
|
|
|
|
|
|
+ List<MgrOrganization> workarkOrganizationList = getWorkarkOrganizationList(user);
|
|
|
+ MgrOrganization workarkCurrentOrganization = null;
|
|
|
+ if(user.getLastWorkarkOrganizationId() != -1) {
|
|
|
+ if(workarkOrganizationList.size() > 0){
|
|
|
+ workarkCurrentOrganization = workarkOrganizationList.get(0);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ workarkCurrentOrganization = getWorkarkLastOrganization(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ MgrUserRole workarkCurrentUserRole = null;
|
|
|
+ if(this.isSupperAdmin(user)) {
|
|
|
+ workarkCurrentUserRole = getUserRole(user, -1);
|
|
|
+ }else {
|
|
|
+ if(workarkCurrentUserRole != null) {
|
|
|
+ workarkCurrentUserRole = getUserRole(user, workarkCurrentOrganization.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(workarkCurrentUserRole!= null && workarkCurrentOrganization!=null && workarkCurrentUserRole.isAdmin()) {
|
|
|
+ MgrResource workarkDefaultResource = getWorkarkDefaultResource();
|
|
|
+ if (workarkCurrentOrganization.getFacilitator() == 0) {
|
|
|
+ workarkCurrentUserRole.setWorkarkResources(workarkDefaultResource.getEnterpriseData());
|
|
|
+ workarkCurrentUserRole.setWorkarkMenus(workarkDefaultResource.getEnterpriseComment());
|
|
|
+ }
|
|
|
+ if (workarkCurrentOrganization.getFacilitator() == 1) {
|
|
|
+ workarkCurrentUserRole.setWorkarkResources(workarkDefaultResource.getProviderData());
|
|
|
+ workarkCurrentUserRole.setWorkarkMenus(workarkDefaultResource.getProviderComment());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//process organization
|
|
|
List<MgrOrganization> organizationList = getOrganizationList(user);
|
|
|
user.setOrganizationList(organizationList);
|
|
@@ -390,12 +458,12 @@ public class MgrUserService {
|
|
|
|
|
|
//load first organization in list if no organization loaded.
|
|
|
if(currentOrganization == null) {
|
|
|
- //Load the first organization default.
|
|
|
+ //Load the first organization default.
|
|
|
if(organizationList.size() > 0) {
|
|
|
currentOrganization = organizationList.get(0);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//process user role
|
|
|
MgrUserRole currentUserRole = null;
|
|
|
if(this.isSupperAdmin(user)) {
|
|
@@ -410,7 +478,6 @@ public class MgrUserService {
|
|
|
if(currentUserRole!= null && currentOrganization!=null && currentUserRole.isAdmin()) {
|
|
|
String resources = "";
|
|
|
String menus = "";
|
|
|
- MgrResource workarkDefaultResource = getWorkarkDefaultResource();
|
|
|
if(currentUserRole.getOrganizationId() == -1) {
|
|
|
MgrResource resource = getDefaultResource();
|
|
|
if(resource != null) {
|
|
@@ -419,18 +486,6 @@ public class MgrUserService {
|
|
|
}
|
|
|
currentUserRole.setResources(resources);
|
|
|
currentUserRole.setMenus(menus);
|
|
|
-
|
|
|
- currentUserRole.setWorkarkResources(workarkDefaultResource.getData());
|
|
|
- currentUserRole.setWorkarkMenus(workarkDefaultResource.getComment());
|
|
|
- } else {
|
|
|
- if (currentOrganization.getFacilitator() == 0) {
|
|
|
- currentUserRole.setWorkarkResources(workarkDefaultResource.getEnterpriseData());
|
|
|
- currentUserRole.setWorkarkMenus(workarkDefaultResource.getEnterpriseComment());
|
|
|
- }
|
|
|
- if (currentOrganization.getFacilitator() == 1) {
|
|
|
- currentUserRole.setWorkarkResources(workarkDefaultResource.getProviderData());
|
|
|
- currentUserRole.setWorkarkMenus(workarkDefaultResource.getProviderComment());
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -439,10 +494,10 @@ public class MgrUserService {
|
|
|
|
|
|
// 当前用户在项目中身份
|
|
|
Map<Long, Set<JSONObject>> projectListIdentity = this.getProjectIdentity(user);
|
|
|
-
|
|
|
- UserContext context = UserContext.getUserContext(user, organizationList, currentOrganization, currentUserRole, projectListIdentity);
|
|
|
+
|
|
|
+ UserContext context = UserContext.getUserContext(user, workarkOrganizationList, organizationList, workarkCurrentOrganization, currentOrganization, workarkCurrentUserRole, currentUserRole, projectListIdentity);
|
|
|
subject.getSession().setAttribute("USERCONTEXT", context);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|