From 2538c0df1586bf41a5d0b30abcf34629745f2b81 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 14 Aug 2023 14:29:18 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E5=B7=A1=E6=A3=80=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=88=A0=E9=99=A4=E6=97=B6=E5=81=9A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=AE=9A=E4=B9=89=E7=BB=91=E5=AE=9A=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=97=B6=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E9=99=90=E5=88=B6=20#=20=E8=AE=BE=E5=A4=87=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=88=97=E8=A1=A8bug=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../equipment/feign/IEmTreeInspectClient.java | 23 ++++++++++++++++ .../controller/EmDefinitionController.java | 4 +-- .../hzims/equipment/feign/EmTreeInspectClient.java | 31 ++++++++++++++++++++++ .../equipment/mapper/EmTreeInspectMapper.java | 6 +++++ .../hzims/equipment/mapper/EmTreeInspectMapper.xml | 12 ++++++++- .../equipment/service/IEmTreeInspectService.java | 9 +++++++ .../service/impl/EmTreeInspectServiceImpl.java | 8 ++++++ .../obj/services/IContentDefinitionService.java | 4 +++ .../impl/ContentDefinitionServiceImpl.java | 21 +++++++++++++++ .../obj/web/ContentDefinitionController.java | 2 +- 10 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmTreeInspectClient.java create mode 100644 hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmTreeInspectClient.java diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmTreeInspectClient.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmTreeInspectClient.java new file mode 100644 index 0000000..ab3b3a5 --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmTreeInspectClient.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.equipment.feign; + +import com.hnac.hzims.EquipmentConstants; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; + +@FeignClient(value = EquipmentConstants.APP_NAME) +public interface IEmTreeInspectClient { + + String API_PREFIX = "/feign/em/tree/inspect"; + String GET_EM_TREE_CONTENT_ID = API_PREFIX + "/getEmTreeContentId"; + + /** + * 获取设备信息中已绑定的巡检内容定义ID + * @return 巡检内容定义ID + */ + @GetMapping(GET_EM_TREE_CONTENT_ID) + R> getEmTreeContentId(); + +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmDefinitionController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmDefinitionController.java index 8f8c530..3b0cdc6 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmDefinitionController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmDefinitionController.java @@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; +import java.util.Optional; /** * 设备定义控制层 @@ -75,8 +76,7 @@ public class EmDefinitionController extends BladeController { wrapper.orderByDesc(EmDefinitionEntity::getCreateTime); IPage pages = emDefinitionService.page(Condition.getPage(query), wrapper); for (EmDefinitionEntity definition : pages.getRecords()) { - User createUser = UserCache.getUser(definition.getCreateUser()); - definition.setCreateUserName(createUser.getName()); + definition.setCreateUserName(Optional.ofNullable(UserCache.getUser(definition.getCreateUser())).map(User::getName).orElse(String.valueOf(definition.getCreateUser()))); } return R.data(pages); diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmTreeInspectClient.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmTreeInspectClient.java new file mode 100644 index 0000000..ced82d5 --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmTreeInspectClient.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.equipment.feign; + +import com.hnac.hzims.equipment.service.IEmTreeInspectService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @ClassName EmTreeInspectClient + * @description: 设备树与巡检内容定义关联关系client + * @author: hx + * @create: 2023-08-11 17:31 + * @Version 4.0 + **/ +@RestController +@AllArgsConstructor +@Slf4j +public class EmTreeInspectClient implements IEmTreeInspectClient { + + private final IEmTreeInspectService emTreeInspectService; + + @Override + @GetMapping(GET_EM_TREE_CONTENT_ID) + public R> getEmTreeContentId() { + return R.data(emTreeInspectService.selectEmTreeContentId()); + } +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.java index 3e3b868..4f1e3b4 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.java @@ -4,5 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.hzims.equipment.entity.EmTreeInspectEntity; import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; +import java.util.List; +import java.util.Map; + public interface EmTreeInspectMapper extends BaseMapper { + + List selectEmTreeContentId(); + } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.xml b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.xml index d1eab9f..73f1600 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.xml +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmTreeInspectMapper.xml @@ -1,5 +1,15 @@ - + \ No newline at end of file diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmTreeInspectService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmTreeInspectService.java index 9b10228..a5c4975 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmTreeInspectService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmTreeInspectService.java @@ -3,5 +3,14 @@ package com.hnac.hzims.equipment.service; import com.hnac.hzims.equipment.entity.EmTreeInspectEntity; import org.springblade.core.mp.base.BaseService; +import java.util.List; + public interface IEmTreeInspectService extends BaseService { + + /** + * 获取 + * @return 巡检内容定义ID列表 + */ + List selectEmTreeContentId(); + } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmTreeInspectServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmTreeInspectServiceImpl.java index 6ce7b74..ebcd9c3 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmTreeInspectServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmTreeInspectServiceImpl.java @@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; import org.springframework.stereotype.Service; +import java.util.List; + /** * @author tanghaihao * @date 2023年06月15日 9:08 @@ -14,4 +16,10 @@ import org.springframework.stereotype.Service; @Service @Slf4j public class EmTreeInspectServiceImpl extends BaseServiceImpl implements IEmTreeInspectService { + + @Override + public List selectEmTreeContentId() { + return this.baseMapper.selectEmTreeContentId(); + } + } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java index 0d6eaf0..2393be5 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java @@ -6,14 +6,18 @@ import com.hnac.hzims.common.utils.Condition; import com.hnac.hzinfo.inspect.obj.dto.ContentDefinitionDTO; import com.hnac.hzinfo.inspect.obj.entity.ContentDefinitionEntity; import com.hnac.hzinfo.inspect.obj.vo.ContentDefinitionVO; +import net.bytebuddy.matcher.BooleanMatcher; import org.springblade.core.mp.base.BaseService; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; public interface IContentDefinitionService extends BaseService { + Boolean removeByIds(String ids); + /** * 根据筛选条件获取列表 * @param request 筛选条件 diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ContentDefinitionServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ContentDefinitionServiceImpl.java index 58bc5f4..2a66c37 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ContentDefinitionServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ContentDefinitionServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.hnac.hzims.equipment.feign.IEmTreeInspectClient; import com.hnac.hzinfo.inspect.obj.dto.ContentDefinitionDTO; import com.hnac.hzinfo.inspect.obj.entity.ContentDefinitionEntity; import com.hnac.hzinfo.inspect.obj.mapper.ContentDefinitionMapper; @@ -12,16 +13,21 @@ import com.hnac.hzinfo.inspect.obj.vo.ContentDefinitionVO; import com.hnac.hzinfo.inspect.obj.wrapper.ContentDefinitionWrapper; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; +import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; +import java.util.Arrays; import java.util.List; +import java.util.Optional; /** * @ClassName ContentDefinitionServiceImpl @@ -37,6 +43,21 @@ import java.util.List; public class ContentDefinitionServiceImpl extends BaseServiceImpl implements IContentDefinitionService { + private final IEmTreeInspectClient emTreeInspectClient; + + @Override + public Boolean removeByIds(String ids) { + R> contentIdR = emTreeInspectClient.getEmTreeContentId(); + Assert.isTrue(contentIdR.isSuccess(),() -> { + throw new ServiceException("查询设备定义绑定内容失败"); + }); + Optional optional = Func.toLongList(",",ids).stream().filter(id -> contentIdR.getData().contains(id)).findFirst(); + if(optional.isPresent()) { + throw new ServiceException("删除失败,【"+this.getById(optional.get()).getName()+"】内容定义已与设备定义绑定"); + } + return this.removeByIds(Func.toLongList(",",ids)); + } + @Override public List list(ContentDefinitionDTO request) { QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.copy(request, ContentDefinitionEntity.class)); diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java index 589ddc0..a29e06c 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java @@ -78,7 +78,7 @@ public class ContentDefinitionController extends BladeController { @ApiOperation("根据ID删除") @ApiOperationSupport(order = 5) public R removeByIds(@RequestParam String ids) { - return R.status(contentDefinitionService.removeByIds(Func.toLongList(",",ids))); + return R.status(contentDefinitionService.removeByIds(ids)); } @GetMapping("/detail")