Commit ad1620c4 authored by jiawei's avatar jiawei

BUG修改====》》单位管理员可以看到平台用户、本单位人员及下属单位创建的学习内容

parent 22d65a7d
...@@ -25,11 +25,13 @@ import io.swagger.annotations.ApiOperation; ...@@ -25,11 +25,13 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -70,6 +72,8 @@ public class LearningContentController extends BaseController { ...@@ -70,6 +72,8 @@ public class LearningContentController extends BaseController {
private AuditService auditService; private AuditService auditService;
@Resource @Resource
private AssetService assetService; private AssetService assetService;
@Autowired
TOrganService organService;
@PostMapping("/save") @PostMapping("/save")
@RequiresAuthentication //@RequiresPermissions("learning:content:save") @RequiresAuthentication //@RequiresPermissions("learning:content:save")
...@@ -250,6 +254,10 @@ public class LearningContentController extends BaseController { ...@@ -250,6 +254,10 @@ public class LearningContentController extends BaseController {
@MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT) @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam, @RequestParam(value = "learningProjectId", required = false) String learningProjectId) { public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam, @RequestParam(value = "learningProjectId", required = false) String learningProjectId) {
LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
List<String> curUserSubOrgIds = getCurUserSubOrgIds();
if (!CollectionUtils.isEmpty(curUserSubOrgIds)){
queryWrapper.in(LearningContent::getOrganCode, curUserSubOrgIds);
}
// 根据创建时间区间检索 // 根据创建时间区间检索
if (genericPageParam.getIsPublished() != null) { if (genericPageParam.getIsPublished() != null) {
queryWrapper.eq(LearningContent::getPublished, genericPageParam.getIsPublished()); queryWrapper.eq(LearningContent::getPublished, genericPageParam.getIsPublished());
...@@ -307,6 +315,62 @@ public class LearningContentController extends BaseController { ...@@ -307,6 +315,62 @@ public class LearningContentController extends BaseController {
return getResult(page); return getResult(page);
} }
/**
* 获取当前用户的所有子机构
*
* @return
*/
public List<String> getCurUserSubOrgIds() {
TUser tUser = getcurUser();
if (tUser == null || StringUtils.isBlank(tUser.getOrgId())) {
return null;
}
//平台管理员、单位管理员、学习内容管理员
List<String> roleList = tUser.getRoleList();
boolean condition = !CollectionUtils.isEmpty(roleList) //不为空
&& roleList.contains("2") //2是单位管理员
&& !roleList.contains("1") //不包含 1是平台管理员
&& !roleList.contains("8"); //不包含 8是学习内容管理员
//不是这种情况查询全部
if (!condition) {
return null;
}
String orgId = tUser.getOrgId();
LambdaQueryWrapper<TOrgan> wrapper = new QueryWrapper<TOrgan>().lambda()
.select(TOrgan::getId, TOrgan::getParentId, TOrgan::getCode)
.eq(TOrgan::getIsDeleted, false);
List<TOrgan> tOrgans = organService.list(wrapper);
ArrayList<String> strings = new ArrayList<>();
strings.add(orgId);
List<String> result = new ArrayList<>();
List<String> code = tOrgans.stream().filter(a -> a.getId().equals(orgId)).map(TOrgan::getCode).collect(Collectors.toList());
if (code != null && code.size() >= 1) {
result.add(code.get(0));
}
treeCode(strings, tOrgans, result);
return result;
}
private void treeCode(List<String> parentCodes, List<TOrgan> all, List<String> codes) {
if (CollectionUtils.isEmpty(parentCodes)) {
return;
}
ArrayList<String> idArray = new ArrayList<>();
parentCodes.stream().forEach(s -> {
List<TOrgan> subOrgans = all.stream().filter(a -> a.getParentId() != null && a.getParentId().equals(s)).collect(Collectors.toList());
subOrgans.stream().forEach(sub -> {
String code = sub.getCode();
String id = sub.getId();
codes.add(code);
idArray.add(id);
});
});
//递归查询
treeCode(idArray, all, codes);
}
@ApiOperation(value = "获取学习内容详情", notes = "获取学习内容详情") @ApiOperation(value = "获取学习内容详情", notes = "获取学习内容详情")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path") @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment