From 8848537254218c166fcffc44c140ae38f07e357c Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 2 Aug 2023 16:47:58 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E8=AE=BE=E5=A4=87=E6=A0=91=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/equipment/service/impl/EmInfoServiceImpl.java | 14 ++++++++++++-- .../com/hnac/hzinfo/inspect/obj/feign/ProjectClient.java | 15 +++++++++++++-- .../inspect/obj/services/impl/ObjectServiceImpl.java | 7 ++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java index 12726bd..e2477b1 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java @@ -599,6 +599,17 @@ public class EmInfoServiceImpl extends BaseServiceImpl Arrays.stream(path.split("/"))).distinct().collect(Collectors.toList()); emCodes.addAll(childrenEmCode); } + return this.getEmInfoTree(deptId,parentCode,emCodes); + } + + /** + * 获取设备树(巡检对象选择专用) + * @param deptId 机构ID + * @param parentCode 父设备编号 + * @param emCodes 巡检项目设备编号集合 + * @return 获取设备树 + */ + private List getEmInfoTree(Long deptId, String parentCode,List emCodes) { EmInfoEntity emInfo = this.getOne(Wrappers.lambdaQuery().eq(EmInfoEntity::getNumber, parentCode)); // 获取parentCode下的子设备集合 LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() @@ -608,13 +619,12 @@ public class EmInfoServiceImpl extends BaseServiceImpl result = emInfoList.stream().map(emInfoEntity -> { JSONObject object = JSONObject.parseObject(JSON.toJSONString(emInfoEntity)); object.put("disabled", emCodes.contains(emInfoEntity.getNumber()) ? false : true); + object.put("children",this.getEmInfoTree(deptId,emInfoEntity.getNumber(),emCodes)); return object; }).collect(Collectors.toList()); return result; } - - /** * 设备信息缓存(ct、pt、installedCapacity、监测点位) */ diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/feign/ProjectClient.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/feign/ProjectClient.java index bbaf72f..2577317 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/feign/ProjectClient.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/feign/ProjectClient.java @@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzinfo.inspect.obj.dto.ContentDTO; import com.hnac.hzinfo.inspect.obj.dto.ProjectDTO; +import com.hnac.hzinfo.inspect.obj.entity.ProjectContentEntity; import com.hnac.hzinfo.inspect.obj.entity.ProjectEntity; import com.hnac.hzinfo.inspect.obj.request.ProjectContentRequest; +import com.hnac.hzinfo.inspect.obj.services.ProjectContentService; import com.hnac.hzinfo.inspect.obj.services.ProjectService; import com.hnac.hzinfo.inspect.obj.vo.ProjectVO; import io.swagger.annotations.ApiOperation; @@ -16,11 +18,14 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.util.List; +import java.util.stream.Collectors; /** * @ClassName ProjectClient @@ -35,6 +40,7 @@ import java.util.List; public class ProjectClient extends BladeController implements IProjectClient { private final ProjectService projectService; + private final ProjectContentService projectContentService; @Override @PostMapping(ADD_PROJECT_AND_CONTENT) @@ -55,8 +61,13 @@ public class ProjectClient extends BladeController implements IProjectClient { @GetMapping(GET_EM_CODES_BY_DEPT_ID) public R> getEmCodesByDeptId(@RequestParam Long deptId) { QueryWrapper queryWrapper = Wrappers.query().eq("create_dept", deptId); - queryWrapper.select("distinct em_code emCode"); queryWrapper.ne("em_code","").isNotNull("em_code"); - return R.data(projectService.listObjs(queryWrapper, String::valueOf)); + List projects = projectService.list(queryWrapper); + if(CollectionUtil.isNotEmpty(projects)) { + QueryWrapper in = Wrappers.query().select("distinct project_id").in("project_id", projects.stream().map(ProjectEntity::getId).collect(Collectors.toList())); + List projectIds = projectContentService.listObjs(in, Func::toLong); + return R.data(projects.stream().filter(project -> projectIds.contains(project.getId())).map(ProjectEntity::getEmCode).collect(Collectors.toList())); + } + return R.data(projects.stream().map(ProjectEntity::getEmCode).collect(Collectors.toList())); } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java index 0614870..153cb48 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java @@ -276,10 +276,15 @@ public class ObjectServiceImpl extends BaseServiceImpl projectContentWrapper = Wrappers.lambdaQuery().eq(ProjectContentEntity::getProjectId, one.getId()); + if(CollectionUtil.isEmpty(projectContentService.list(projectContentWrapper))) { + return null; + } return TemplateProjectEntity.builder().templateId(template.getId()).projectId(one.getId()).build(); }; List templateProjectList = Stream.iterate(0,n -> n + 1).limit(emCodeList.size()) - .flatMap(index -> emInfoClient.getChildrenByEmCode(emCodeList.get(index)).getData().stream()).map(getTemplateProjectByEmCode).collect(Collectors.toList()); + .flatMap(index -> emInfoClient.getChildrenByEmCode(emCodeList.get(index)).getData().stream()).map(getTemplateProjectByEmCode).filter(ObjectUtil::isNotEmpty).collect(Collectors.toList()); templateProjectService.saveBatch(templateProjectList); } }