|
@@ -1,17 +1,23 @@
|
|
|
package cn.iocoder.yudao.module.pms.service.iotprojectinfo;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
|
|
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojectinfo.vo.IotProjectInfoPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojectinfo.vo.IotProjectInfoSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojectinfo.IotProjectInfoDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotprojectinfo.IotProjectInfoMapper;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
|
|
|
+import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_PROJECT_INFO_NOT_EXISTS;
|
|
@@ -27,6 +33,10 @@ public class IotProjectInfoServiceImpl implements IotProjectInfoService {
|
|
|
|
|
|
@Resource
|
|
|
private IotProjectInfoMapper iotProjectInfoMapper;
|
|
|
+ @Resource
|
|
|
+ private DeptMapper deptMapper;
|
|
|
+ @Resource
|
|
|
+ private AdminUserMapper userMapper;
|
|
|
|
|
|
@Override
|
|
|
public Long createIotProjectInfo(IotProjectInfoSaveReqVO createReqVO) {
|
|
@@ -72,12 +82,104 @@ public class IotProjectInfoServiceImpl implements IotProjectInfoService {
|
|
|
|
|
|
@Override
|
|
|
public PageResult<IotProjectInfoDO> getIotProjectInfoPage1(IotProjectInfoPageReqVO pageReqVO, Collection<Long> deptIds) {
|
|
|
- return iotProjectInfoMapper.selectPage1(pageReqVO,deptIds);
|
|
|
+ // 查询当前人所属公司级组织的数据
|
|
|
+ List<DeptDO> depts = companyLevelDepts();
|
|
|
+ Set<Long> departmentIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(depts)) {
|
|
|
+ depts.forEach(dept -> {
|
|
|
+ departmentIds.add(dept.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return iotProjectInfoMapper.selectPage1(pageReqVO,departmentIds);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<IotProjectInfoDO> projectList() {
|
|
|
- return iotProjectInfoMapper.projectList();
|
|
|
+ // 查询当前用户所属部门的公司级组织
|
|
|
+ List<DeptDO> companyLevelDepts = companyLevelDepts();
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(companyLevelDepts)) {
|
|
|
+ companyLevelDepts.forEach(dept -> {
|
|
|
+ deptIds.add(dept.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<IotProjectInfoDO> allProjects = iotProjectInfoMapper.projectList();
|
|
|
+ List<IotProjectInfoDO> resultProjects = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(allProjects)) {
|
|
|
+ allProjects.forEach(project -> {
|
|
|
+ if (deptIds.contains(project.getDeptId())) {
|
|
|
+ resultProjects.add(project);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return resultProjects;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前登录人所属部门的公司级组织
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<DeptDO> companyLevelDepts() {
|
|
|
+ Set<Long> parentIds = new HashSet<>();
|
|
|
+ parentIds.add(DeptDO.PARENT_ID_ROOT);
|
|
|
+
|
|
|
+ // 查询当前登录人所属部门
|
|
|
+ Long userId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
+ AdminUserDO user = userMapper.selectById(userId);
|
|
|
+ Long deptId = user.getDeptId();
|
|
|
+ DeptDO dept = deptMapper.selectById(deptId);
|
|
|
+ System.out.println("当前登录用户所属部门:" + dept.getName());
|
|
|
+
|
|
|
+ // 用于存储最终需要返回的部门列表
|
|
|
+ List<DeptDO> resultDepts = new ArrayList<>();
|
|
|
+
|
|
|
+ DataPermissionUtils.executeIgnore(() -> {
|
|
|
+ // 一级部门
|
|
|
+ List<DeptDO> theFirstLevelDepts = deptMapper.selectListByParentId(parentIds);
|
|
|
+ System.out.println("顶级部门数量:" + theFirstLevelDepts.size());
|
|
|
+ if (CollUtil.isNotEmpty(theFirstLevelDepts)) {
|
|
|
+ theFirstLevelDepts.forEach(department -> {
|
|
|
+ if (dept.getId().equals(department.getId())) {
|
|
|
+ // 当前登录人所属部门是 一级部门
|
|
|
+ // 此时需要返回一级部门的二级公司子部门
|
|
|
+ parentIds.clear();
|
|
|
+ parentIds.add(department.getId());
|
|
|
+ List<DeptDO> theSecondLevelDepts = deptMapper.selectListByParentId(parentIds);
|
|
|
+ System.out.println("二级部门数量:" + theSecondLevelDepts.size());
|
|
|
+ resultDepts.addAll(theSecondLevelDepts);
|
|
|
+ }
|
|
|
+ // 当前登录人所属部门是二级部门或二级部门的子部门
|
|
|
+ if (!dept.getId().equals(department.getId())) {
|
|
|
+ // 查询当前登录人所属部门的父部门 追溯到二级部门
|
|
|
+ // 递归查询当前登录人所属部门的父部门 直到找到 二级部门(parentId=department.getId())
|
|
|
+ // 如果 parentDept.getParentId().equals(department.getId()) 说明parentDept部门已经是二级部门了
|
|
|
+ DeptDO currentDept = dept;
|
|
|
+ if (currentDept.getParentId().equals(department.getId())) {
|
|
|
+ // 当前部门是二级部门(父部门是一级部门)
|
|
|
+ if (!resultDepts.contains(dept)) {
|
|
|
+ resultDepts.add(dept);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ while (currentDept != null && !currentDept.getParentId().equals(DeptDO.PARENT_ID_ROOT)) {
|
|
|
+ DeptDO tempParentDept = deptMapper.selectById(currentDept.getParentId());
|
|
|
+ if (tempParentDept == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (currentDept.getParentId().equals(department.getId())) {
|
|
|
+ // 当前部门是二级部门(父部门是一级部门)
|
|
|
+ if (!resultDepts.contains(dept)) {
|
|
|
+ resultDepts.add(currentDept);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ currentDept = tempParentDept;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ return resultDepts;
|
|
|
}
|
|
|
|
|
|
}
|