From 3807b9ed7b24d2b5a75c3477219178f1a8527d3c Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Sat, 8 Apr 2023 15:42:59 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=BF=9D=E5=AD=98=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hzims-service/equipment/pom.xml | 4 ++ .../equipment/controller/EmInfoController.java | 15 ------- .../equipment/service/impl/EmInfoServiceImpl.java | 47 +++++++++++++++++----- .../station/service/impl/StationServiceImpl.java | 2 +- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/hzims-service/equipment/pom.xml b/hzims-service/equipment/pom.xml index 24ad6ad..6f37bf3 100644 --- a/hzims-service/equipment/pom.xml +++ b/hzims-service/equipment/pom.xml @@ -94,6 +94,10 @@ hzims-operational-api compile + + org.apache.commons + commons-collections4 + diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java index 1435528..d2a1d0a 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java @@ -117,21 +117,6 @@ public class EmInfoController extends BladeController { @ApiOperationSupport(order = 4) @ApiOperation(value = "新增", notes = "传入em_info") public R save(@Valid @RequestBody EmInfoAddVo em_info) { - List name = em_infoService.list(new QueryWrapper() {{ - eq("NAME", em_info.getInfo().getName()); - }}); - if (CollectionUtil.isNotEmpty(name)) { - return R.fail("设备名称已存在"); - } - if(Func.isNotEmpty(em_info.getInfo().getEmIndex())) { - List exist = em_infoService.list(Wrappers.lambdaQuery() - .eq(EmInfoEntity::getCreateDept, AuthUtil.getDeptId()) - .eq(EmInfoEntity::getEmIndex, em_info.getInfo().getEmIndex()) - ); - Assert.isTrue(CollectionUtil.isEmpty(exist),() -> { - throw new ServiceException("该设备序号已存在,设备新增失败"); - }); - } return em_infoService.saveInfo(em_info); } 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 1361370..5430d51 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 @@ -23,6 +23,7 @@ import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; import org.springblade.system.vo.CreateTableVO; @@ -103,17 +104,11 @@ public class EmInfoServiceImpl extends BaseServiceImpl existResult = deviceClient.isDeviceCodeExist(em_info.getInfo().getNumber()); - Assert.isTrue(existResult.isSuccess() && !existResult.getData(),() -> { - throw new ServiceException("该设备编码在设备实例中找到对应记录,保存失败!"); - }); - EmInfoEntity emInfoEntity = this.baseMapper.selectEmInfoByCode(em_info.getInfo().getNumber()); - if (ObjectUtil.isNotEmpty(emInfoEntity)) { - return R.fail("设备编号已存在"); - } - - if (this.save(em_info.getInfo())) { + // 验证设备信息 + this.validEmInfo(em_info); + EmInfoEntity infoEntity = em_info.getInfo(); + //infoEntity.setNumber(Func.); + if (this.save(infoEntity)) { this.getStationCodeStoreRedis(); Long infoId = em_info.getInfo().getId(); if (em_info.getAttach() != null) { @@ -469,4 +464,34 @@ public class EmInfoServiceImpl extends BaseServiceImpl Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); } + + private void validEmInfo(EmInfoAddVo em_info) { + // 验证设备名称 + List existName = this.list( + Wrappers.lambdaQuery().eq(EmInfoEntity::getName, em_info.getInfo().getName()) + ); + Assert.isTrue(CollectionUtil.isEmpty(existName),()-> { + throw new ServiceException("设备名称已存在"); + }); + // 验证设备序号 + if(Func.isNotEmpty(em_info.getInfo().getEmIndex())) { + List exist = super.list(Wrappers.lambdaQuery() + .eq(EmInfoEntity::getCreateDept, AuthUtil.getDeptId()) + .eq(EmInfoEntity::getEmIndex, em_info.getInfo().getEmIndex()) + ); + Assert.isTrue(CollectionUtil.isEmpty(exist),() -> { + throw new ServiceException("该设备序号已存在,设备新增失败"); + }); + } + // 查询设备编码设备实例是否已存在 + R existResult = deviceClient.isDeviceCodeExist(em_info.getInfo().getNumber()); + Assert.isTrue(existResult.isSuccess() && !existResult.getData(),() -> { + throw new ServiceException("该设备编码在设备实例中找到对应记录,保存失败!"); + }); + // 验证设备编号是否已存在 + EmInfoEntity emInfoEntity = this.baseMapper.selectEmInfoByCode(em_info.getInfo().getNumber()); + Assert.isTrue(ObjectUtil.isEmpty(emInfoEntity),() -> { + throw new ServiceException("设备编号已存在"); + }); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index 71be197..59aded9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -641,7 +641,7 @@ public class StationServiceImpl extends BaseServiceImpl 1) { throw new ServiceException("获取站点数量超过一条"); } - return Optional.ofNullable(list).map(l -> l.get(0)).orElse(null); + return list.size() > 0 ? list.get(0) : null; } /**