REM:
1. 修正添加设备时异常问题
This commit is contained in:
HuangXin 2021-02-02 10:11:12 +08:00
parent 42cbb0760c
commit a1f1d82158
3 changed files with 74 additions and 55 deletions

View File

@ -80,9 +80,16 @@ public class DisposeDeviceManagerController {
// 获取请求中的需要添加的设备列表 // 获取请求中的需要添加的设备列表
req.getItems().forEach(v -> { 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() DisposeDevice dev = DisposeDevice.builder()
.ipAddr(v.getIpAddr()) .ipAddr(v.getIpAddr())
.ipPort(v.getIpPort()) .ipPort(port)
.deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class, .deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class,
v.getDeviceType())) v.getDeviceType()))
.areaCode(v.getAreaCode()) .areaCode(v.getAreaCode())
@ -93,7 +100,7 @@ public class DisposeDeviceManagerController {
.userName(v.getUserName()) .userName(v.getUserName())
.password(v.getPassword()) .password(v.getPassword())
.urlPath(v.getUrlPath()) .urlPath(v.getUrlPath())
.urlType(CommonEnumHandler.codeOf(HttpType.class, v.getUrlType())) .urlType(hType)
.readme(v.getReadme()) .readme(v.getReadme())
.build(); .build();

View File

@ -2,7 +2,6 @@ package com.dispose.manager.impl;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.Helper; import com.dispose.common.Helper;
import com.dispose.common.HttpType;
import com.dispose.common.IpAddrType; import com.dispose.common.IpAddrType;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
@ -137,8 +136,21 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
*/ */
@Override @Override
public MulReturnType<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) { public MulReturnType<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) {
DisposeDevice tDev = null;
// 根据Ip和设备类型获取设备 // 根据Ip和设备类型获取设备
DisposeDevice tDev = disposeDeviceMapper.getDeviceByIpAndType(dev.getIpAddr(), dev.getDeviceType().getValue()); List<DisposeDevice> 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())) { if (tDev == null || !Helper.isIpPortMatch(tDev.getIpPort(), dev.getIpPort(), dev.getUrlType())) {

View File

@ -76,12 +76,12 @@ public interface DisposeDeviceMapper {
int availableDisposeDevice(@Param("id") Long id); int availableDisposeDevice(@Param("id") Long id);
/** /**
* Gets device by address. * Gets device by addr and type.
* *
* @param ipAddr the ip addr * @param ipAddr the ip addr
* @param ipPort the ip port * @param ipPort the ip port
* @param devType the device type * @param devType the dev type
* @return the device by address * @return the device by addr and type
*/ */
DisposeDevice getDeviceByAddrAndType(@Param("ipAddr") String ipAddr, DisposeDevice getDeviceByAddrAndType(@Param("ipAddr") String ipAddr,
@Param("ipPort") String ipPort, @Param("ipPort") String ipPort,
@ -94,7 +94,7 @@ public interface DisposeDeviceMapper {
* @param devType the dev type * @param devType the dev type
* @return the device by ip and type * @return the device by ip and type
*/ */
DisposeDevice getDeviceByIpAndType(@Param("ipAddr") String ipAddr, List<DisposeDevice> getDeviceByIpAndType(@Param("ipAddr") String ipAddr,
@Param("devType") Integer devType); @Param("devType") Integer devType);