@@ -3,6 +3,8 @@ package com.tuoheng.admin.request.report; | |||
import com.tuoheng.common.core.common.BaseQuery; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* 查询报告分页列表请求实体 | |||
* | |||
@@ -28,15 +30,14 @@ public class QueryReportPageListRequest extends BaseQuery { | |||
*/ | |||
private Integer airportId; | |||
/** | |||
* 创建人 | |||
*/ | |||
private String createUser; | |||
/** | |||
* 租户Id | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 部门集合 | |||
*/ | |||
private List<String> deptIdList; | |||
} |
@@ -5,11 +5,14 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.entity.Accident; | |||
import com.tuoheng.admin.entity.AccidentRead; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.AccidentStatusEnum; | |||
import com.tuoheng.admin.enums.DataPermissionEnum; | |||
import com.tuoheng.admin.enums.FlagEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.AccidentMapper; | |||
import com.tuoheng.admin.mapper.AccidentReadMapper; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -37,6 +40,8 @@ public class AccidentNoticeService { | |||
@Autowired | |||
private AccidentReadMapper accidentReadMapper; | |||
@Autowired | |||
private DeptMapper deptMapper; | |||
/** | |||
* 告警弹窗通知下发 | |||
@@ -44,17 +49,16 @@ public class AccidentNoticeService { | |||
*/ | |||
public JsonResult notice() { | |||
//当前登录用户 | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
String userId = CurrentUserUtil.getUserId(); | |||
if(StringUtils.isEmpty(userId)){ | |||
throw new ServiceException("当前用户id为空"); | |||
} | |||
if(StringUtils.isEmpty(tenantId)){ | |||
throw new ServiceException("当前用户的租户id为空"); | |||
} | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String tenantId = user.getId(); | |||
String userId = user.getId(); | |||
List<String> deptIdList = this.getDeptIdList(user); | |||
//查询应急表是否有应急数据 | |||
List<Accident> accidentList = accidentMapper.selectList(new LambdaQueryWrapper<Accident>() | |||
.eq(Accident::getTenantId, tenantId) | |||
.in(CollectionUtils.isNotEmpty(deptIdList), Accident::getDeptId, deptIdList) | |||
.eq(Accident::getStatus, AccidentStatusEnum.UNTREATED.getCode()) | |||
.eq(Accident::getFlag, FlagEnum.INSPECTION_ACCIDENT.getCode()) | |||
.eq(Accident::getMark, MarkEnum.VALID.getCode()) | |||
@@ -103,4 +107,22 @@ public class AccidentNoticeService { | |||
return JsonResult.success(accidentList); | |||
} | |||
/** | |||
* 根据用户自己的数据权限,查询对应部门的数据 | |||
* | |||
* @param user | |||
* @return | |||
*/ | |||
private List<String> getDeptIdList(User user) { | |||
List<String> deptIdList = new ArrayList<>(); | |||
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) { | |||
return null; | |||
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) { | |||
deptIdList = deptMapper.selectAllChildListById(user.getDeptId()); | |||
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) { | |||
deptIdList.add(user.getDeptId()); | |||
} | |||
return deptIdList; | |||
} | |||
} |
@@ -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; | |||
@@ -19,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
@@ -60,7 +62,6 @@ public class QueryReportPageListService { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String userId = user.getId(); | |||
String tenantId = user.getTenantId(); | |||
request.setTenantId(tenantId); | |||
JsonResult result = this.check(tenantId, request); | |||
if (0 != result.getCode()) { | |||
@@ -68,10 +69,14 @@ public class QueryReportPageListService { | |||
return result; | |||
} | |||
List<String> deptIdList = this.getDeptIdList(user); | |||
request.setDeptIdList(deptIdList); | |||
request.setTenantId(tenantId); | |||
// 设置分页参数 | |||
IPage<Report> page = new Page<>(request.getPage(), request.getLimit()); | |||
// 用户只能查看自己生成的报告 | |||
request.setCreateUser(userId); | |||
// 用户只能查看自己生成的报告, 2023-11-07,改为由数据权限控制 | |||
// request.setCreateUser(userId); | |||
// 查询结果 | |||
IPage<Report> pageData = reportMapper.selectPageList(page, request); | |||
@@ -98,21 +103,27 @@ public class QueryReportPageListService { | |||
*/ | |||
private JsonResult check(String tenantId, QueryReportPageListRequest request) { | |||
// 判断部门id是否为空 | |||
// if (StringUtils.isEmpty(queryInspectionRequest.getDeptId())) { | |||
// return JsonResult.error(QueryInspectionPageListCodeEnum.DEPT_ID_IS_NULL.getCode(), QueryInspectionPageListCodeEnum.DEPT_ID_IS_NULL.getMsg()); | |||
// } | |||
// | |||
// // 判断部门是否存在 | |||
// Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>() | |||
// .eq(Dept::getTenantId, tenantId) | |||
// .eq(Dept::getId, queryInspectionRequest.getDeptId()) | |||
// .eq(Dept::getMark, 1)); | |||
// if (null == dept) { | |||
// return JsonResult.error(QueryInspectionPageListCodeEnum.DEPT_IS_NOT_EXIST.getCode(), QueryInspectionPageListCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); | |||
// } | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 根据用户自己的数据权限,查询对应部门的数据 | |||
* | |||
* @param user | |||
* @return | |||
*/ | |||
private List<String> getDeptIdList(User user) { | |||
List<String> deptIdList = new ArrayList<>(); | |||
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) { | |||
return null; | |||
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) { | |||
deptIdList = deptMapper.selectAllChildListById(user.getDeptId()); | |||
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) { | |||
deptIdList.add(user.getDeptId()); | |||
} | |||
return deptIdList; | |||
} | |||
/** | |||
* 构造返回的数据列表 | |||
* |
@@ -75,7 +75,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<if test="request.inspectionCode!= null and request.inspectionCode != ''"> and inspection_code like concat('%', #{request.inspectionCode}, '%') </if> | |||
<if test="request.airportId != null and request.airportId != 0"> and airport_id = #{request.airportId} </if> | |||
<if test="request.type != null and request.type != 0"> and type = #{request.type} </if> | |||
<if test="request.createUser != null and request.createUser != ''"> and create_user = #{request.createUser} </if> | |||
<if test="request.deptIdList != null and request.deptIdList.size() > 0"> | |||
and dept_id in | |||
<foreach item="deptId" collection="request.deptIdList" open="(" separator="," close=")"> | |||
#{deptId} | |||
</foreach> | |||
</if> | |||
</where> | |||
order by create_time desc | |||
</select> |