From 03eee141b93b3c7250d569514324bce8ca507d8c Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 27 Jul 2023 08:16:26 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E5=B7=A1=E6=A3=80=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=A0=91=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspect/obj/services/ProjectService.java | 7 ++++ .../obj/services/impl/ProjectServiceImpl.java | 43 ++++++++++++++++++++-- .../hzinfo/inspect/obj/web/ProjectController.java | 8 +--- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/ProjectService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/ProjectService.java index 48d1c54..ea4c63b 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/ProjectService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/ProjectService.java @@ -49,4 +49,11 @@ public interface ProjectService extends BaseService{ * @return Map key-emCode value-projectVO */ List getProjectAndContentByEmCodes(String emCodes); + + /** + * 获取项目树 - 一级:机构 二级:项目(设备) + * @param project - isNewModel 是否只查询emCode不为空情况下的项目树 + * @return 机构-项目树 + */ + List> deptProjectTree(ProjectDTO project); } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ProjectServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ProjectServiceImpl.java index 18b78ca..beda076 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ProjectServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ProjectServiceImpl.java @@ -3,8 +3,10 @@ package com.hnac.hzinfo.inspect.obj.services.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; import com.hnac.hzinfo.inspect.Constants; import com.hnac.hzinfo.inspect.obj.ObjectConstants; import com.hnac.hzinfo.inspect.obj.dto.ContentDTO; @@ -27,14 +29,13 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; +import org.springblade.system.feign.ISysClient; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -47,6 +48,7 @@ import java.util.stream.Stream; public class ProjectServiceImpl extends BaseServiceImpl implements ProjectService { private final ContentService contentService; + private final ISysClient sysClient; //private final ProjectContentService projectContentService; @Override @@ -139,4 +141,37 @@ public class ProjectServiceImpl extends BaseServiceImpl this.getProjectAndContentByEmCode(emCode, new ContentDTO(), query)).collect(Collectors.toList()); } + + @Override + public List> deptProjectTree(ProjectDTO project) { + // 获取第一层机构 + QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.copy(project, ProjectEntity.class)); + queryWrapper.select("create_dept deptId") + .isNotNull(project.getIsNewModel(), "em_code") + .ne(project.getIsNewModel(), "em_code", "") + .groupBy("create_dept"); + List> list = this.getBaseMapper().selectMaps(queryWrapper); + return list.stream().filter(Func::isNotEmpty).peek(deptMap -> { + Long deptId = (Long) deptMap.get("deptId"); + // 获取机构名称 + deptMap.put("deptName",Optional.ofNullable(sysClient.getDeptName(deptId).getData()).orElse(String.valueOf(deptId))); + // 获取机构下的项目 + deptMap.put("children",this.getProjectTreeChildren(project,deptId)); + }).collect(Collectors.toList()); + } + + /** + * 获取项目树中 机构下巡检项目的子集 + * @param project 筛选条件 + * @param deptId 机构ID + * @return 巡检项目子集 + */ + private List> getProjectTreeChildren(ProjectDTO project,Long deptId) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.copy(project, ProjectEntity.class)); + queryWrapper.eq(Func.isNotEmpty(deptId),"create_dept",deptId); + queryWrapper.isNotNull(project.getIsNewModel(), "em_code"); + queryWrapper.ne(project.getIsNewModel(), "em_code", ""); + queryWrapper.select("em_code","name"); + return this.listMaps(queryWrapper); + } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ProjectController.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ProjectController.java index 24d0086..bf4cfa5 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ProjectController.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ProjectController.java @@ -84,12 +84,8 @@ public class ProjectController { @GetMapping("/selectProject") @ApiOperation(value = "巡检项目列表-下拉框", notes = "巡检项目列表-下拉框") @ApiOperationSupport(order = 2) - public R> selectProject(ProjectDTO project) { - LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(new ProjectEntity(),project); - queryWrapper.isNotNull(project.getIsNewModel(),ProjectEntity::getEmCode); - queryWrapper.ne(project.getIsNewModel(),ProjectEntity::getEmCode,""); - List projectList = projectService.list(queryWrapper); - return R.data(ProjectWrapper.build().listVO(projectList)); + public R>> selectProject(ProjectDTO project) { + return R.data(projectService.deptProjectTree(project)); } /**