dcs 10 meses atrás
pai
commit
c547570c4c

+ 6 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/controller/ProjectController.java

@@ -46,6 +46,12 @@ public class ProjectController {
         return Response.ok(list);
     }
 
+    @ApiOperation("当前登录的用户下项目")
+    @RequestMapping(value = "/projectListIdentity", method = RequestMethod.GET)
+    public Response getProjectListIdentity() {
+        return Response.ok(projectService.getProjectListIdentity());
+    }
+
     @ApiOperation("详情")
     @RequestMapping(value = "/getProject/{id}", method = RequestMethod.GET)
     public Response getProject(@PathVariable long id) {

+ 15 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/Project.java

@@ -1,9 +1,11 @@
 package com.bosshand.virgo.api.model;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.annotation.JsonFormat;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Set;
 
 /**
  * 项目
@@ -88,6 +90,11 @@ public class Project {
      */
     private String data;
 
+    /**
+     * 项目对应的用户的身份
+     */
+    private Set<JSONObject> projectListIdentity;
+
     private List<ProjectItem> projectItemList;
 
     public Integer getGenerateWeeklyDate() {
@@ -218,6 +225,14 @@ public class Project {
         this.data = data;
     }
 
+    public Set<JSONObject> getProjectListIdentity() {
+        return projectListIdentity;
+    }
+
+    public void setProjectListIdentity(Set<JSONObject> projectListIdentity) {
+        this.projectListIdentity = projectListIdentity;
+    }
+
     public List<ProjectItem> getProjectItemList() {
         return projectItemList;
     }

+ 30 - 2
virgo.api/src/main/java/com/bosshand/virgo/api/service/ProjectService.java

@@ -1,16 +1,18 @@
 package com.bosshand.virgo.api.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.api.dao.ProjectDao;
 import com.bosshand.virgo.api.dao.ProjectItemDao;
 import com.bosshand.virgo.api.model.Project;
 import com.bosshand.virgo.api.model.ProjectItem;
 import com.bosshand.virgo.api.util.PositionUtil;
+import com.bosshand.virgo.core.model.UserContext;
+import com.bosshand.virgo.core.utils.ContextUtils;
 import com.bosshand.virgo.core.utils.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class ProjectService {
@@ -88,4 +90,30 @@ public class ProjectService {
 	public List<Project> getIds(List<Long> ids) {
 		return projectDao.getIds(ids);
 	}
+
+	public List<Project> getProjectListIdentity() {
+		UserContext userContext = ContextUtils.getUserContext();
+		List<Project> list = new ArrayList<>();
+		if (userContext.getUserId() == 1) {
+			Set<JSONObject> set = new HashSet<>();
+			set.add(JSONObject.parseObject(UserContext.IDENTITY_OWNER_DATA));
+			list = getProjectByOrganizationId(userContext.getOrganizationId());
+			for (Project project : list) {
+				project.setProjectListIdentity(set);
+			}
+			return list;
+		}
+		Map<Long, Set<JSONObject>> projectListIdentity = userContext.getProjectListIdentity();
+		List<Long> ids = new ArrayList<>();
+		projectListIdentity.forEach((key, value) -> ids.add(key));
+		if (ids.size() > 0) {
+			list = getIds(ids);
+			for (Project project : list) {
+				project.setProjectListIdentity(projectListIdentity.get(project.getId()));
+			}
+			return list;
+		}
+		return list;
+	}
+
 }

+ 2 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/dao/IdentityDao.java

@@ -18,4 +18,6 @@ public interface IdentityDao {
 
     int delete(long id);
 
+    Identity get(long id);
+
 }

+ 10 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/model/Identity.java

@@ -7,6 +7,16 @@ import java.util.List;
  */
 public class Identity {
 
+    /**
+     * 默认所有者身份Id
+     */
+    public static final long DEFAULT_OWNER_ID = 6;
+
+    /**
+     * 默认公司成员身份Id
+     */
+    public static final long DEFAULT_MEMBER_ID = 3;
+
     private long id;
 
     /**

+ 19 - 1
virgo.core/src/main/java/com/bosshand/virgo/core/model/UserContext.java

@@ -1,8 +1,14 @@
 package com.bosshand.virgo.core.model;
 
+import com.alibaba.fastjson.JSONObject;
+
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 public class UserContext implements BaseModel{
+
+	public static final String IDENTITY_OWNER_DATA = "{\"name\": \"所有者\",\"remark\": \"组织的所有者\",\"id\": 1}";
 	
 	private long userId;
 	
@@ -46,6 +52,8 @@ public class UserContext implements BaseModel{
 	
 	private boolean admin;
 
+	private Map<Long, Set<JSONObject>> projectListIdentity;
+
 	public String getOrganizedName() {
 		return organizedName;
 	}
@@ -214,6 +222,14 @@ public class UserContext implements BaseModel{
 		this.practiceSeal = practiceSeal;
 	}
 
+	public Map<Long, Set<JSONObject>> getProjectListIdentity() {
+		return projectListIdentity;
+	}
+
+	public void setProjectListIdentity(Map<Long, Set<JSONObject>> projectListIdentity) {
+		this.projectListIdentity = projectListIdentity;
+	}
+
 	public static UserContext getUserContext(MgrUser user) {
 		if (user != null) {
 			UserContext flowUser = new UserContext();
@@ -233,7 +249,7 @@ public class UserContext implements BaseModel{
 		return null;
 	}
 
-	public static UserContext getUserContext(MgrUser user, List<MgrOrganization> organizationList, MgrOrganization currentOrganization, MgrUserRole userRole) {
+	public static UserContext getUserContext(MgrUser user, List<MgrOrganization> organizationList, MgrOrganization currentOrganization, MgrUserRole userRole, Map<Long, Set<JSONObject>> projectListIdentity) {
 		if (user != null) {
 			UserContext flowUser = new UserContext();
 			flowUser.setUserId(user.getId());
@@ -261,6 +277,8 @@ public class UserContext implements BaseModel{
 				flowUser.setResource(userRole.getResources());
 			}
 			flowUser.setUserRole(userRole);
+
+			flowUser.setProjectListIdentity(projectListIdentity);
 			return flowUser;
 		}
 		return null;

+ 59 - 1
virgo.core/src/main/java/com/bosshand/virgo/core/service/MgrUserService.java

@@ -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);
 		
 	}

+ 4 - 0
virgo.core/src/main/resources/mapper/IdentityMapper.xml

@@ -25,6 +25,10 @@
         from identity a LEFT JOIN identity_resource b ON a.id = b.identityId
     </sql>
 
+    <select id="get" resultMap="result">
+        select * from identity where id = #{id}
+    </select>
+
     <select id="getList" resultMap="identityResult">
         <include refid="query"/>
     </select>