Browse Source

账户配置列表-上级可查看下级数据信息

yangzian 3 years ago
parent
commit
fa8b4de1d9

+ 6 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/UserAllocationMapper.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.bytedance.common.entity.UserAllocation;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * @Description: 用户分配
@@ -41,4 +42,9 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<UserAllocation> listByMediaId(@Param("mediaId")String mediaId, @Param("accountStatus")Integer accountStatus);
 
     List<JSONObject> getAccountListByProjectList(@Param("list") List list);
+
+
+    Set<String> recursiveQuerySubordinateByLeader(@Param("leaderId") String leaderId);
+    Set<String> recursiveQuerySubordinateByLeaders(@Param("leaderIds") Set<String> leaderId);
+
 }

+ 26 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/xml/UserAllocationMapper.xml

@@ -150,4 +150,30 @@
     </select>
 
 
+
+
+    <select id="recursiveQuerySubordinateByLeader" resultType="java.lang.String">
+        SELECT distinct id
+        FROM sys_user
+        WHERE leader_id = #{leaderId}
+          and status = 1
+          and del_flag = 0
+    </select>
+
+    <select id="recursiveQuerySubordinateByLeaders" resultType="java.lang.String">
+        SELECT distinct id
+        FROM sys_user
+        WHERE
+        status = 1
+        and del_flag = 0
+        and leader_id in
+        <foreach collection="leaderIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+    </select>
+
+
+
+
 </mapper>

+ 5 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/IUserAllocationService.java

@@ -6,6 +6,7 @@ import org.jeecg.modules.bytedance.common.entity.UserAllocation;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @Description: 用户分配
@@ -40,4 +41,8 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     List<Long> getAccountsByDeleteComment();
 
     Map<Long, List<JSONObject>> getAccountListByProjectList(List<JSONObject> projectList);
+
+
+    //递归查询下级
+    Set<String> recursiveQuerySubordinate(String userId);
 }

+ 31 - 4
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/impl/UserAllocationServiceImpl.java

@@ -9,10 +9,7 @@ import org.jeecg.modules.bytedance.common.service.IUserAllocationService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @Description: 用户分配
@@ -139,4 +136,34 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         }
         return map;
     }
+
+
+
+    @Override
+    public Set<String> recursiveQuerySubordinate(String userId) {
+        Set<String> result;
+        //查询当前用户是否存在下级
+        Set<String> subordinate = userAllocationMapper.recursiveQuerySubordinateByLeader(userId);
+        if (subordinate.isEmpty()) {
+            subordinate.add(userId);
+            return subordinate;
+        } else {
+            result = querySubordinate(subordinate, subordinate);
+            result.add(userId);
+        }
+        return result;
+    }
+
+    //递归查询
+    private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result) {
+        if (leaderIds.isEmpty()) {
+            return result;
+        }
+        Set<String> temp = userAllocationMapper.recursiveQuerySubordinateByLeaders(leaderIds);
+        result.addAll(temp);
+        querySubordinate(temp, result);
+        return result;
+    }
+
+
 }

+ 10 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/bytedance/advertise/controller/AiBytedanceAdvertiserStrategyController.java

@@ -24,6 +24,7 @@ import org.jeecg.modules.bytedance.common.entity.CtopOauthToken;
 import org.jeecg.modules.bytedance.common.entity.MaterialImageInfo;
 import org.jeecg.modules.bytedance.common.service.ICtopOauthTokenService;
 import org.jeecg.modules.bytedance.common.service.IMaterialImageInfoService;
+import org.jeecg.modules.bytedance.common.service.IUserAllocationService;
 import org.jeecg.modules.bytedance.common.utils.*;
 import org.jeecg.modules.system.service.ISysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -63,6 +64,8 @@ public class AiBytedanceAdvertiserStrategyController {
 	@Autowired
 	private ICtopOauthTokenService tokenService;
 
+	@Autowired
+	private IUserAllocationService userAllocationService;
 
 	/**
 	  * 分页列表查询
@@ -82,8 +85,13 @@ public class AiBytedanceAdvertiserStrategyController {
 		QueryWrapper<AiBytedanceAdvertiserStrategy> queryWrapper = QueryGenerator.initQueryWrapper(aiBytedanceAdvertiserStrategy, req.getParameterMap());
 		//获取用户角色code
 		String roleCode = sysRoleService.getRoleCodeByUserId(aiBytedanceAdvertiserStrategy.getLoginUserId());
-		if(null != roleCode && !BytedanceConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode)){
-			queryWrapper.eq("user_id", aiBytedanceAdvertiserStrategy.getLoginUserId());
+		if (Check.isNull(roleCode)){
+			return Result.errorMsg("无法查询到该用户角色信息。");
+		}
+		if(!BytedanceConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode)){
+			//查询所有包含自己的下级
+			Set<String> operatorUserIds= userAllocationService.recursiveQuerySubordinate(aiBytedanceAdvertiserStrategy.getLoginUserId());
+			queryWrapper.in("user_id", operatorUserIds);
 		}
 		queryWrapper.orderByDesc("create_time");
 		Page<AiBytedanceAdvertiserStrategy> page = new Page<AiBytedanceAdvertiserStrategy>(pageNo, pageSize);