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")