From a1f1d82158ac37cde7567eb17c661f930d1267f4 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 2 Feb 2021 10:11:12 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=AD=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AE=BE=E5=A4=87=E6=97=B6=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DisposeDeviceManagerController.java | 99 ++++++++++--------- .../impl/DisposeDeviceManagerImpl.java | 20 +++- .../dispose/mapper/DisposeDeviceMapper.java | 10 +- 3 files changed, 74 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java b/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java index 15c62f15..3fcb5e0a 100644 --- a/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java +++ b/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java @@ -80,22 +80,29 @@ public class DisposeDeviceManagerController { // 获取请求中的需要添加的设备列表 req.getItems().forEach(v -> { + HttpType hType = CommonEnumHandler.codeOf(HttpType.class, v.getUrlType()); + String port = v.getIpPort(); + + if (v.getIpPort() == null || v.getIpPort().length() == 0) { + port = HttpType.getDefaultPort(hType); + } + DisposeDevice dev = DisposeDevice.builder() - .ipAddr(v.getIpAddr()) - .ipPort(v.getIpPort()) - .deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class, - v.getDeviceType())) - .areaCode(v.getAreaCode()) - .deviceName(v.getDeviceName()) - .manufacturer(v.getManufacturer()) - .model(v.getModel()) - .version(v.getVersion()) - .userName(v.getUserName()) - .password(v.getPassword()) - .urlPath(v.getUrlPath()) - .urlType(CommonEnumHandler.codeOf(HttpType.class, v.getUrlType())) - .readme(v.getReadme()) - .build(); + .ipAddr(v.getIpAddr()) + .ipPort(port) + .deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class, + v.getDeviceType())) + .areaCode(v.getAreaCode()) + .deviceName(v.getDeviceName()) + .manufacturer(v.getManufacturer()) + .model(v.getModel()) + .version(v.getVersion()) + .userName(v.getUserName()) + .password(v.getPassword()) + .urlPath(v.getUrlPath()) + .urlType(hType) + .readme(v.getReadme()) + .build(); // 初始化设备能力信息 dev.setDevCapacity(new ArrayList<>()); @@ -103,13 +110,13 @@ public class DisposeDeviceManagerController { v.getCapacity().forEach(k -> { // 添加设备能力 DisposeCapacity cap = DisposeCapacity.builder() - .capacityType(CommonEnumHandler.codeOf(DisposeCapacityType.class, k.getCapacityType())) - .ipType(k.getIpType() == null ? IpAddrType.IPV4 : - CommonEnumHandler.codeOf(IpAddrType.class, k.getIpType())) - .objectType(CommonEnumHandler.codeOf(DisposeObjectType.class, k.getObjectType())) - .protectIp(k.getProtectIp() == null ? "" : k.getProtectIp()) - .reserveNetflow(k.getReserveNetflow()) - .build(); + .capacityType(CommonEnumHandler.codeOf(DisposeCapacityType.class, k.getCapacityType())) + .ipType(k.getIpType() == null ? IpAddrType.IPV4 : + CommonEnumHandler.codeOf(IpAddrType.class, k.getIpType())) + .objectType(CommonEnumHandler.codeOf(DisposeObjectType.class, k.getObjectType())) + .protectIp(k.getProtectIp() == null ? "" : k.getProtectIp()) + .reserveNetflow(k.getReserveNetflow()) + .build(); dev.getDevCapacity().add(cap); }); @@ -129,8 +136,8 @@ public class DisposeDeviceManagerController { @ResponseBody @ApiOperation("添加处置能力节点") public ProtocolRespDTO addDisposeDevice( - @Validated(ValidGroups.AddDeviceValid.class) - @RequestBody ProtocolReqDTO mr) { + @Validated(ValidGroups.AddDeviceValid.class) + @RequestBody ProtocolReqDTO mr) { // 请求参数转换 List devs = requestToDeviceList(mr.getMsgContent()); @@ -144,9 +151,9 @@ public class DisposeDeviceManagerController { ret.forEach(v -> { DisposeDevice dev = v.getSecondParam(); AddDeviceRet rsp = AddDeviceRet.builder() - .ipAddr(dev.getIpAddr()) - .ipPort(Helper.ipPortNormalize(dev.getIpPort(), dev.getUrlType())) - .build(); + .ipAddr(dev.getIpAddr()) + .ipPort(Helper.ipPortNormalize(dev.getIpPort(), dev.getUrlType())) + .build(); rsp.setStatus(v.getFirstParam().getCode()); rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); @@ -172,8 +179,8 @@ public class DisposeDeviceManagerController { @ResponseBody @ApiOperation("删除处置能力节点") public ProtocolRespDTO removeDisposeDevice( - @Validated(ValidGroups.ExplicitIdArrayValid.class) - @RequestBody ProtocolReqDTO mr) { + @Validated(ValidGroups.ExplicitIdArrayValid.class) + @RequestBody ProtocolReqDTO mr) { List idList = new ArrayList<>(); @@ -183,7 +190,7 @@ public class DisposeDeviceManagerController { } List> ret = - disposeDeviceManagerService.removeDisposeDevice(idList); + disposeDeviceManagerService.removeDisposeDevice(idList); CommDeviceListRsp rspInfo = new CommDeviceListRsp(); rspInfo.setItems(new ArrayList<>()); @@ -213,8 +220,8 @@ public class DisposeDeviceManagerController { @ResponseBody @ApiOperation("更新处置能力节点") public ProtocolRespDTO upgradeDisposeDevice( - @Validated(ValidGroups.UpgradeDeviceValid.class) - @RequestBody ProtocolReqDTO mr) { + @Validated(ValidGroups.UpgradeDeviceValid.class) + @RequestBody ProtocolReqDTO mr) { // 请求参数转换 List devs = requestToDeviceList(mr.getMsgContent()); @@ -230,8 +237,8 @@ public class DisposeDeviceManagerController { DisposeDevice dev = v.getSecondParam(); disposeDeviceManagerService.getAllDisposeDevice().parallelStream() - .filter(k -> k.getId().equals(dev.getId())) - .findAny().ifPresent(device -> rsp.setDevStatus(device.getStatus().getValue())); + .filter(k -> k.getId().equals(dev.getId())) + .findAny().ifPresent(device -> rsp.setDevStatus(device.getStatus().getValue())); rsp.setId(String.valueOf(dev.getId())); rsp.setStatus(v.getFirstParam().getCode()); @@ -253,12 +260,12 @@ public class DisposeDeviceManagerController { @ResponseBody @ApiOperation("获取处置能力节点") public ProtocolRespDTO getAllDisposeDevice( - @Validated(ValidGroups.ProtocolCommonValid.class) - @RequestBody ProtocolReqDTO mr) { + @Validated(ValidGroups.ProtocolCommonValid.class) + @RequestBody ProtocolReqDTO mr) { MulReturnType, List> ret = - disposeDeviceManagerService.getPageDisposeDevice(mr.getMsgContent().getStartPage(), - mr.getMsgContent().getPageSize()); + disposeDeviceManagerService.getPageDisposeDevice(mr.getMsgContent().getStartPage(), + mr.getMsgContent().getPageSize()); GetDeviceRsp rspInfo = new GetDeviceRsp(); @@ -277,7 +284,7 @@ public class DisposeDeviceManagerController { GetDeviceDetail devInfo = new GetDeviceDetail(); devInfo.setId(v.getId().toString()); devInfo.setIpAddr(DisposeConfigValue.USED_PRIVACY_PROTECT ? - PrivacyHelper.ipAddressPrivacy(v.getIpAddr()) : v.getIpAddr()); + PrivacyHelper.ipAddressPrivacy(v.getIpAddr()) : v.getIpAddr()); devInfo.setIpPort(Helper.ipPortNormalize(v.getIpPort(), v.getUrlType())); devInfo.setDeviceType(v.getDeviceType().getValue()); devInfo.setAreaCode(v.getAreaCode()); @@ -286,7 +293,7 @@ public class DisposeDeviceManagerController { devInfo.setModel(v.getModel()); devInfo.setVersion(v.getVersion()); devInfo.setUserName(DisposeConfigValue.USED_PRIVACY_PROTECT ? - PrivacyHelper.usernamePrivacy(v.getUserName()) : v.getUserName()); + PrivacyHelper.usernamePrivacy(v.getUserName()) : v.getUserName()); devInfo.setUrlType(v.getUrlType().getValue()); devInfo.setReadme(v.getReadme()); devInfo.setDevStatus(v.getStatus().getValue()); @@ -296,12 +303,12 @@ public class DisposeDeviceManagerController { v.getDevCapacity().forEach(k -> { AddCapacityInfo capInfo = AddCapacityInfo.builder() - .capacityType(k.getCapacityType().getValue()) - .objectType(k.getObjectType().getValue()) - .ipType(k.getIpType().getValue()) - .protectIp(k.getProtectIp()) - .reserveNetflow(k.getReserveNetflow()) - .build(); + .capacityType(k.getCapacityType().getValue()) + .objectType(k.getObjectType().getValue()) + .ipType(k.getIpType().getValue()) + .protectIp(k.getProtectIp()) + .reserveNetflow(k.getReserveNetflow()) + .build(); capList.add(capInfo); }); diff --git a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java index 5f6a350d..080ad4fc 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java @@ -2,7 +2,6 @@ package com.dispose.manager.impl; import com.dispose.common.ErrorCode; import com.dispose.common.Helper; -import com.dispose.common.HttpType; import com.dispose.common.IpAddrType; import com.dispose.common.ObjectStatus; import com.dispose.manager.DisposeDeviceManager; @@ -58,7 +57,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { public MulReturnType addDisposeDevice(DisposeDevice dev) { // 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败 DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddrAndType(dev.getIpAddr(), dev.getIpPort(), - dev.getDeviceType().getValue()); + dev.getDeviceType().getValue()); if (tDev != null) { // 如果设备是删除状态,则更新设备信息 @@ -117,7 +116,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { fdDest.setAccessible(true); if (!obj.equals(fdDest.get(destDev))) { log.debug("Upgrade field [{}] value form [{}] to [{}]", fdSrc.getName(), fdDest.get(destDev), - obj); + obj); fdDest.set(destDev, obj); } fdDest.setAccessible(false); @@ -137,8 +136,21 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { */ @Override public MulReturnType upgradeDisposeDevice(DisposeDevice dev) { + DisposeDevice tDev = null; // 根据Ip和设备类型获取设备 - DisposeDevice tDev = disposeDeviceMapper.getDeviceByIpAndType(dev.getIpAddr(), dev.getDeviceType().getValue()); + List devList = disposeDeviceMapper.getDeviceByIpAndType(dev.getIpAddr(), + dev.getDeviceType().getValue()); + + if (devList == null || devList.size() == 0) { + return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, -1L); + } + + for (DisposeDevice v : devList) { + if (Helper.isIpPortMatch(v.getIpPort(), dev.getIpPort(), dev.getUrlType())) { + tDev = v; + break; + } + } // 找不到设备 if (tDev == null || !Helper.isIpPortMatch(tDev.getIpPort(), dev.getIpPort(), dev.getUrlType())) { diff --git a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java index f9c7d9d2..a9f2d306 100644 --- a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java +++ b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java @@ -76,12 +76,12 @@ public interface DisposeDeviceMapper { int availableDisposeDevice(@Param("id") Long id); /** - * Gets device by address. + * Gets device by addr and type. * * @param ipAddr the ip addr * @param ipPort the ip port - * @param devType the device type - * @return the device by address + * @param devType the dev type + * @return the device by addr and type */ DisposeDevice getDeviceByAddrAndType(@Param("ipAddr") String ipAddr, @Param("ipPort") String ipPort, @@ -94,8 +94,8 @@ public interface DisposeDeviceMapper { * @param devType the dev type * @return the device by ip and type */ - DisposeDevice getDeviceByIpAndType(@Param("ipAddr") String ipAddr, - @Param("devType") Integer devType); + List getDeviceByIpAndType(@Param("ipAddr") String ipAddr, + @Param("devType") Integer devType); /**