Browse Source

报告数据列表添加数据权限控制

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
a0ae02449e
2 changed files with 43 additions and 6 deletions
  1. +7
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/report/QueryReportPageListRequest.java
  2. +36
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/query/QueryReportPageListService.java

+ 7
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/report/QueryReportPageListRequest.java View File

@@ -3,6 +3,8 @@ package com.tuoheng.admin.request.report;
import com.tuoheng.common.core.common.BaseQuery;
import lombok.Data;

import java.util.List;

/**
* 查询报告分页列表请求实体
*
@@ -38,5 +40,10 @@ public class QueryReportPageListRequest extends BaseQuery {
*/
private String tenantId;

/**
* 部门及子部门Id列表
*/
private List<String> deptIdList;


}

+ 36
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/query/QueryReportPageListService.java View File

@@ -9,6 +9,7 @@ import com.tuoheng.admin.entity.InspectionFile;
import com.tuoheng.admin.entity.InspectionFileHandle;
import com.tuoheng.admin.entity.Report;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.DataPermissionEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.request.report.QueryReportPageListRequest;
@@ -73,21 +74,30 @@ public class QueryReportPageListService {
IPage<Report> page = new Page<>(request.getPage(), request.getLimit());
// 用户只能查看自己生成的报告 或者是当前租户下自动生成的报告
//request.setCreateUser(userId);

// 查询结果
IPage<Report> pageData = reportMapper.selectPageList(page, request);

if (null == pageData || pageData.getTotal() == 0) {
log.info("获取任务分页列表为空");
return JsonResult.success(pageData);
}
List<Report> reportList = pageData.getRecords();

List<Report> reportsData = new ArrayList<>();
for (Report report : reportList) {
if(report.getCreateUser().equals(userId) || report.getAutoGenerate() == 2){
reportsData.add(report);
}

if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) {
reportsData = this.getAllList(reportList);
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) {
reportsData = this.getListByDepts(reportList, user);
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) {
reportsData = this.getListByDept(reportList, user);
}
if(CollectionUtil.isEmpty(reportsData) || reportsData.size() == 0){
return JsonResult.success(pageData);
}

// 构造返回结果对象
List<ReportPageListVo> reportPageListVoList = this.buildReportPageListVoList(reportsData);

// 重写返回结果对象
IPage<ReportPageListVo> reportVoPageData = new Page<>();
reportVoPageData.setPages(pageData.getPages());
@@ -99,6 +109,26 @@ public class QueryReportPageListService {
return JsonResult.success(reportVoPageData);
}

//本租户下报告数据
private List<Report> getAllList(List<Report> reportList) {
return reportList;
}

//当前部门及子孙部门报告数据
private List<Report> getListByDepts(List<Report> reportList, User user) {
String deptId = user.getDeptId();
List<String> deptIdList = deptMapper.selectAllChildListById(deptId);
List<Report> collect = reportList.stream().filter((Report r) -> deptIdList.contains(r.getDeptId())).collect(Collectors.toList());
return collect;
}

//当前部门报告数据
private List<Report> getListByDept(List<Report> reportList, User user) {
String deptId = user.getDeptId();
List<Report> collect = reportList.stream().filter(x -> x.getDeptId().equals(deptId)).collect(Collectors.toList());
return collect;
}

/**
* 检查参数
*

Loading…
Cancel
Save