dcs 11 months ago
parent
commit
78771ade06

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

@@ -97,7 +97,7 @@ public class ProjectService {
 		if (userContext.getUserId() == 1) {
 			Set<JSONObject> set = new HashSet<>();
 			set.add(JSONObject.parseObject(UserContext.IDENTITY_OWNER_DATA));
-			list = getProjectByOrganizationId(userContext.getOrganizationId());
+			list = getAll();
 			for (Project project : list) {
 				project.setProjectListIdentity(set);
 			}

+ 2 - 2
virgo.api/src/main/resources/mapper/ProjectMapper.xml

@@ -70,11 +70,11 @@
 	</select>
 
 	<select id="getAll" resultMap="result">
-		SELECT * FROM project WHERE deleteState = 0
+		SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id where deleteState = 0
 	</select>
 
 	<select id="getIds" resultMap="result">
-		SELECT * FROM project WHERE id in
+		SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id where a.id in
 		<foreach collection="list" open="(" separator="," close=")" item="id">
 			#{id}
 		</foreach>

+ 1 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/dao/MgrRoleDao.java

@@ -18,4 +18,5 @@ public interface MgrRoleDao {
 
     int update(MgrRole mgrRole);
 
+    List<MgrRole> getIds(List<Long> ids);
 }

+ 35 - 11
virgo.core/src/main/java/com/bosshand/virgo/core/service/MgrUserService.java

@@ -3,6 +3,7 @@ package com.bosshand.virgo.core.service;
 import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.core.dao.*;
 import com.bosshand.virgo.core.model.*;
+import com.bosshand.virgo.core.utils.StringUtil;
 import com.bosshand.virgo.core.utils.Utils;
 import com.bosshand.virgo.core.utils.WeChatUtil;
 import com.bosshand.virgo.exception.Constant;
@@ -19,6 +20,9 @@ import java.util.*;
 @Service
 public class MgrUserService {
 
+	@Autowired
+	private MgrRoleDao mgrRoleDao;
+
 	@Autowired
 	private MgrUserDao mgrUserDao;
 	
@@ -250,25 +254,44 @@ public class MgrUserService {
 	 */
 	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());
+
+		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<MgrOrganizationProject> list = mgrOrganizationProjectDao.get(organizationId, userId);
 		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);
+		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);
 			}
+		}
 
+		if (list != null & list.size() > 0) {
 			for (MgrOrganizationProject mop : list) {
 				map.forEach((key, value) -> {
 					if (mop.getProjectId() == key) {
@@ -277,6 +300,7 @@ public class MgrUserService {
 				});
 			}
 		}
+
 		return map;
 	}
 

+ 7 - 0
virgo.core/src/main/resources/mapper/MgrRoleMapper.xml

@@ -21,6 +21,13 @@
         select * from mgr_role where id = #{id}
     </select>
 
+    <select id="getIds" resultMap="mgrRoleResult">
+        select * from mgr_role where id in
+        <foreach collection="list" open="(" separator="," close=")" item="id">
+            #{id}
+        </foreach>
+    </select>
+
     <insert id="insert" parameterType="com.bosshand.virgo.core.model.MgrRole" useGeneratedKeys="true" keyProperty="id">
         INSERT INTO mgr_role(responsible, name, responsibility, projectId, organizationId, parentId, remark) VALUES (#{responsible}, #{name}, #{responsibility}, #{projectId}, #{organizationId}, #{parentId}, #{remark})
     </insert>