diff --git a/config/application-local.properties b/config/application-local.properties
index 4bc7d67c..71c9bee7 100644
--- a/config/application-local.properties
+++ b/config/application-local.properties
@@ -4,11 +4,11 @@ server.tomcat.basedir=./basedir
# 多个项目放在nginx下同个端口,通过该配置区分
server.servlet.context-path=/dispose
# 配置数据源
-spring.datasource.url=jdbc:mysql://cloud.xajhuang.com:3306/dispose?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
+spring.datasource.url=jdbc:mysql://172.28.72.118:33061/dispose_hx?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.username=xajhuang
-spring.datasource.password=skhXSizrhfkhezy5
+spring.datasource.username=phoenix
+spring.datasource.password=Hy@rfph32
# 配置连接池
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
spring.datasource.dbcp2.max-total=128
diff --git a/pom.xml b/pom.xml
index bc00c4c6..ab6ba551 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,6 +216,20 @@
ipaddress
5.2.1
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-tomcat
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-undertow
+
diff --git a/src/main/java/com/dispose/common/HttpType.java b/src/main/java/com/dispose/common/HttpType.java
index 203fd3a0..2347e980 100644
--- a/src/main/java/com/dispose/common/HttpType.java
+++ b/src/main/java/com/dispose/common/HttpType.java
@@ -8,7 +8,7 @@ package com.dispose.common;
public enum HttpType implements BaseEnum {
/**
- * Http http type.
+ * The Http.
*/
HTTP(0, "HTTP 接口"),
/**
@@ -37,9 +37,9 @@ public enum HttpType implements BaseEnum {
}
/**
- * Gets code.
+ * Gets value.
*
- * @return the code
+ * @return the value
*/
@Override
public Integer getValue() {
@@ -47,12 +47,28 @@ public enum HttpType implements BaseEnum {
}
/**
- * Gets readme.
+ * Gets description.
*
- * @return the readme
+ * @return the description
*/
@Override
public String getDescription() {
return this.readme;
}
+
+ /**
+ * Gets default port.
+ *
+ * @param type the type
+ * @return the default port
+ */
+ public static String getDefaultPort(HttpType type) {
+ if(type == HTTP) {
+ return "80";
+ } else if(type == HTTPS) {
+ return "443";
+ } else {
+ return "";
+ }
+ }
}
diff --git a/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java b/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java
index e6c44519..0ac91725 100644
--- a/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java
+++ b/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java
@@ -12,7 +12,7 @@ import com.dispose.pojo.dto.protocol.base.ValidGroups;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceReq;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRet;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp;
-import com.dispose.pojo.dto.protocol.device.manager.DelDeviceRsp;
+import com.dispose.pojo.dto.protocol.device.manager.DeviceInfoRsp;
import com.dispose.pojo.entity.DisposeCapacity;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -52,23 +53,11 @@ public class DisposeDeviceManagerController {
@Resource
private DisposeDeviceManagerService disposeDeviceManagerService;
- /**
- * Add dispose device protocol resp dto.
- *
- * @param mr the mr
- * @return the protocol resp dto
- */
- @PutMapping("/device")
- @ResponseBody
- @ApiOperation("添加处置能力节点")
- public ProtocolRespDTO extends AddDeviceRsp> addDisposeDevice(
- @Validated(ValidGroups.AddDeviceValid.class)
- @RequestBody ProtocolReqDTO mr) {
-
+ private List requestToDeviceList(AddDeviceReq req) {
List devs = new ArrayList<>();
// 获取请求中的需要添加的设备列表
- mr.getMsgContent().getItems().forEach(v -> {
+ req.getItems().forEach(v -> {
DisposeDevice dev = DisposeDevice.builder()
.ipAddr(v.getIpAddr())
.ipPort(v.getIpPort())
@@ -102,6 +91,25 @@ public class DisposeDeviceManagerController {
devs.add(dev);
});
+ return devs;
+ }
+
+ /**
+ * Add dispose device protocol resp dto.
+ *
+ * @param mr the mr
+ * @return the protocol resp dto
+ */
+ @PutMapping("/device")
+ @ResponseBody
+ @ApiOperation("添加处置能力节点")
+ public ProtocolRespDTO extends AddDeviceRsp> addDisposeDevice(
+ @Validated(ValidGroups.AddDeviceValid.class)
+ @RequestBody ProtocolReqDTO mr) {
+
+ // 请求参数转换
+ List devs = requestToDeviceList(mr.getMsgContent());
+
// 添加设备
List> ret = disposeDeviceManagerService.addDisposeDevice(devs);
@@ -138,7 +146,7 @@ public class DisposeDeviceManagerController {
@DeleteMapping("/device")
@ResponseBody
@ApiOperation("删除处置能力节点")
- public ProtocolRespDTO> removeDisposeDevice(
+ public ProtocolRespDTO> removeDisposeDevice(
@Validated(ValidGroups.ExplicitIdArrayValid.class)
@RequestBody ProtocolReqDTO mr) {
@@ -152,10 +160,10 @@ public class DisposeDeviceManagerController {
List> ret =
disposeDeviceManagerService.removeDisposeDevice(idList);
- List rspInfo = new ArrayList<>();
+ List rspInfo = new ArrayList<>();
ret.forEach(v -> {
- DelDeviceRsp rsp = new DelDeviceRsp();
+ DeviceInfoRsp rsp = new DeviceInfoRsp();
DisposeDevice dev = v.getSecondParam();
rsp.setId(String.valueOf(dev.getId()));
@@ -168,4 +176,33 @@ public class DisposeDeviceManagerController {
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
+
+ @PostMapping("/upgrade")
+ @ResponseBody
+ @ApiOperation("更新处置能力节点")
+ public ProtocolRespDTO> upgradeDisposeDevice(
+ @Validated(ValidGroups.UpgradeDeviceValid.class)
+ @RequestBody ProtocolReqDTO mr) {
+
+ // 请求参数转换
+ List devs = requestToDeviceList(mr.getMsgContent());
+
+ // 更新设备信息
+ List> ret = disposeDeviceManagerService.upgradeDisposeDevice(devs);
+
+ List rspInfo = new ArrayList<>();
+
+ ret.forEach(v -> {
+ DeviceInfoRsp rsp = new DeviceInfoRsp();
+ DisposeDevice dev = v.getSecondParam();
+
+ rsp.setId(String.valueOf(dev.getId()));
+ rsp.setStatus(v.getFirstParam().getCode());
+ rsp.setMessage(new String[] {v.getFirstParam().getMsg()});
+
+ rspInfo.add(rsp);
+ });
+
+ return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
+ }
}
diff --git a/src/main/java/com/dispose/manager/DisposeDeviceManager.java b/src/main/java/com/dispose/manager/DisposeDeviceManager.java
index f8ac025b..06ad35c1 100644
--- a/src/main/java/com/dispose/manager/DisposeDeviceManager.java
+++ b/src/main/java/com/dispose/manager/DisposeDeviceManager.java
@@ -26,15 +26,15 @@ public interface DisposeDeviceManager {
NoSuchMethodException, InvocationTargetException;
/**
- * Upgrade dispose device error code.
+ * Upgrade dispose device mul return type.
*
* @param dev the dev
- * @return the error code
+ * @return the mul return type
* @throws IllegalAccessException the illegal access exception
* @throws NoSuchMethodException the no such method exception
* @throws InvocationTargetException the invocation target exception
*/
- ErrorCode upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
+ MulReturnType upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
InvocationTargetException;
/**
diff --git a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java
index f2157be6..8b46efef 100644
--- a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java
+++ b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java
@@ -1,6 +1,7 @@
package com.dispose.manager.impl;
import com.dispose.common.ErrorCode;
+import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus;
import com.dispose.manager.DisposeDeviceManager;
import com.dispose.mapper.DisposeCapacityMapper;
@@ -8,11 +9,11 @@ import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -44,22 +45,18 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
*
* @param dev the dev
* @return the mul return type
- * @throws IllegalAccessException the illegal access exception
- * @throws NoSuchMethodException the no such method exception
- * @throws InvocationTargetException the invocation target exception
*/
@Override
- public MulReturnType addDisposeDevice(DisposeDevice dev) throws IllegalAccessException,
- NoSuchMethodException, InvocationTargetException {
+ public MulReturnType addDisposeDevice(DisposeDevice dev) {
// 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort());
if (tDev != null) {
// 如果设备是删除状态,则更新设备信息
- if(dev.getStatus() == ObjectStatus.DELETED) {
+ if (dev.getStatus() == ObjectStatus.DELETED) {
// 重置状态
dev.setStatus(ObjectStatus.NORMAL);
- return new MulReturnType<>(upgradeDisposeDevice(dev), tDev.getId());
+ return upgradeDisposeDevice(dev);
}
return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId());
@@ -79,39 +76,83 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
}
/**
- * Upgrade dispose device error code.
+ * Upgrade dispose device properties.
+ *
+ * @param the type parameter
+ * @param destDev the dest dev
+ * @param srcDev the src dev
+ */
+ private void upgradeDisposeDeviceProperties(T destDev, T srcDev) {
+ Field[] field = srcDev.getClass().getDeclaredFields();
+
+ for (Field fdSrc : field) {
+
+ if (Modifier.toString(fdSrc.getModifiers()).indexOf("static") > 0) {
+ continue;
+ }
+
+ fdSrc.setAccessible(true);
+ try {
+ Object obj = fdSrc.get(srcDev);
+ if (obj != null) {
+ Field fdDest = destDev.getClass().getDeclaredField(fdSrc.getName());
+ fdDest.setAccessible(true);
+ if (!obj.equals(fdDest.get(destDev))) {
+ log.debug("Upgrade field [{}] value form [{}] to [{}]",
+ fdSrc.getName(), fdDest.get(destDev), obj);
+ fdDest.set(destDev, obj);
+ }
+ fdDest.setAccessible(false);
+ }
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ log.warn("Copy field maybe occurs some errors: ", e);
+ }
+ fdSrc.setAccessible(false);
+ }
+ }
+
+ /**
+ * Upgrade dispose device mul return type.
*
* @param dev the dev
- * @return the error code
- * @throws IllegalAccessException the illegal access exception
- * @throws NoSuchMethodException the no such method exception
- * @throws InvocationTargetException the invocation target exception
+ * @return the mul return type
*/
@Override
- public ErrorCode upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
- InvocationTargetException {
+ public MulReturnType upgradeDisposeDevice(DisposeDevice dev) {
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort());
+ // 处理默认端口情况
if (tDev == null) {
- return ErrorCode.ERR_NOSUCHDEVICE;
+ if (dev.getIpPort() == null || dev.getIpPort().length() == 0) {
+ // HTTP 默认端口
+ if (dev.getUrlType() == HttpType.HTTP) {
+ tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
+ HttpType.getDefaultPort(HttpType.HTTP));
+ } else if (dev.getUrlType() == HttpType.HTTPS) {
+ // HTTPS 默认端口
+ tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(),
+ HttpType.getDefaultPort(HttpType.HTTPS));
+ }
+ }
}
- // 保存设备ID
- Long devId = tDev.getId();
+ // 实在找不到设备返回错误
+ if (tDev == null) {
+ return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, -1L);
+ }
// 更新值
- PropertyUtils.copyProperties(tDev, dev);
- tDev.setId(devId);
+ upgradeDisposeDeviceProperties(tDev, dev);
// 更新设备数据库
disposeDeviceMapper.upgradeDisposeDevice(tDev);
// 清楚能力数据库中旧的能力信息
- disposeCapacityMapper.delDeviceDisposeCapacity(devId);
+ disposeCapacityMapper.delDeviceDisposeCapacity(tDev.getId());
// 新增能力信息完成更新
disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity());
- return ErrorCode.ERR_OK;
+ return new MulReturnType<>(ErrorCode.ERR_OK, tDev.getId());
}
/**
diff --git a/src/main/java/com/dispose/pojo/dto/protocol/base/ValidGroups.java b/src/main/java/com/dispose/pojo/dto/protocol/base/ValidGroups.java
index 6aedc957..b2a44d92 100644
--- a/src/main/java/com/dispose/pojo/dto/protocol/base/ValidGroups.java
+++ b/src/main/java/com/dispose/pojo/dto/protocol/base/ValidGroups.java
@@ -30,12 +30,15 @@ public class ValidGroups {
public interface LogoutReqValid extends ProtocolCommonValid {
}
+ public interface UpgradeDeviceValid extends ProtocolCommonValid {
+ }
+
/**
* The interface Add device valid.
*
* @author
*/
- public interface AddDeviceValid extends ProtocolCommonValid {
+ public interface AddDeviceValid extends UpgradeDeviceValid {
}
/**
diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/manager/AddDeviceInfo.java b/src/main/java/com/dispose/pojo/dto/protocol/device/manager/AddDeviceInfo.java
index c7fb8f50..b5057be4 100644
--- a/src/main/java/com/dispose/pojo/dto/protocol/device/manager/AddDeviceInfo.java
+++ b/src/main/java/com/dispose/pojo/dto/protocol/device/manager/AddDeviceInfo.java
@@ -28,13 +28,13 @@ public class AddDeviceInfo {
/**
* The Ip addr.
*/
- @NotBlank(message = "ipAddr IP地址不能为空", groups = ValidGroups.AddDeviceValid.class)
+ @NotBlank(message = "ipAddr IP地址不能为空", groups = ValidGroups.UpgradeDeviceValid.class)
private String ipAddr;
/**
* The Ip port.
*/
- @NotNull(message = "ipPort 端口不能为null, 默认端口用空字符串表示", groups = ValidGroups.AddDeviceValid.class)
+ @NotNull(message = "ipPort 端口不能为null, 默认端口用空字符串表示", groups = ValidGroups.UpgradeDeviceValid.class)
private String ipPort;
/**
@@ -86,6 +86,7 @@ public class AddDeviceInfo {
/**
* The Url type.
*/
+ @NotNull(message = "urlType URL类型不能为空", groups = ValidGroups.AddDeviceValid.class)
private HttpType urlType;
/**
diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/manager/DelDeviceRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/device/manager/DeviceInfoRsp.java
similarity index 94%
rename from src/main/java/com/dispose/pojo/dto/protocol/device/manager/DelDeviceRsp.java
rename to src/main/java/com/dispose/pojo/dto/protocol/device/manager/DeviceInfoRsp.java
index 4187f327..de0b0651 100644
--- a/src/main/java/com/dispose/pojo/dto/protocol/device/manager/DelDeviceRsp.java
+++ b/src/main/java/com/dispose/pojo/dto/protocol/device/manager/DeviceInfoRsp.java
@@ -22,7 +22,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"id", "devStatus", "status", "message"})
-public class DelDeviceRsp extends BaseIdResp {
+public class DeviceInfoRsp extends BaseIdResp {
/**
* The Dev status.
*/
diff --git a/src/main/java/com/dispose/service/DisposeDeviceManagerService.java b/src/main/java/com/dispose/service/DisposeDeviceManagerService.java
index 2f1ee36a..3ac93b1e 100644
--- a/src/main/java/com/dispose/service/DisposeDeviceManagerService.java
+++ b/src/main/java/com/dispose/service/DisposeDeviceManagerService.java
@@ -27,4 +27,13 @@ public interface DisposeDeviceManagerService {
* @return the list
*/
List> removeDisposeDevice(List ids);
+
+
+ /**
+ * Upgrade dispose device list.
+ *
+ * @param devs the devs
+ * @return the list
+ */
+ List> upgradeDisposeDevice(List devs);
}
diff --git a/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java
index 62a00360..8771d09e 100644
--- a/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java
+++ b/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java
@@ -40,9 +40,31 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
List> rspList = new ArrayList<>();
devs.forEach(v -> {
- MulReturnType ret = null;
try {
- ret = disposeDeviceManager.addDisposeDevice(v);
+ MulReturnType ret = disposeDeviceManager.addDisposeDevice(v);
+ v.setId(ret.getSecondParam());
+ rspList.add(new MulReturnType<>(ret.getFirstParam(), v));
+ } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
+ rspList.add(new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, v));
+ }
+ });
+
+ return rspList;
+ }
+
+ /**
+ * Upgrade dispose device list.
+ *
+ * @param devs the devs
+ * @return the list
+ */
+ @Override
+ public List> upgradeDisposeDevice(List devs) {
+ List> rspList = new ArrayList<>();
+
+ devs.forEach(v -> {
+ try {
+ MulReturnType ret = disposeDeviceManager.upgradeDisposeDevice(v);
v.setId(ret.getSecondParam());
rspList.add(new MulReturnType<>(ret.getFirstParam(), v));
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java
index a9d0490b..761a59c3 100644
--- a/src/test/java/com/dispose/test/debug/demo.java
+++ b/src/test/java/com/dispose/test/debug/demo.java
@@ -1,9 +1,16 @@
package com.dispose.test.debug;
+import com.dispose.common.DisposeDeviceType;
+import com.dispose.common.HttpType;
+import com.dispose.common.ObjectStatus;
+import com.dispose.pojo.entity.DisposeDevice;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
-import java.text.SimpleDateFormat;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
@@ -59,10 +66,67 @@ public class demo {
Integer v1 = null;
Integer v2 = 1;
- log.info("Current Datetime: {}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+ log.info("Current Datetime: {}",
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//log.info("Current Datetime: {}", new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss").format(LocalDateTime.now()));
log.info("v1: {}", Optional.ofNullable(v1).orElse(0));
log.info("v2: {}", Optional.ofNullable(v2).orElse(0));
}
+
+ private T upgradeDisposeDeviceProperties(T destDev, T srcDev) {
+
+ Field[] field = srcDev.getClass().getDeclaredFields();
+
+ for (Field fdSrc : field) {
+
+ if (Modifier.toString(fdSrc.getModifiers()).indexOf("static") > 0) {
+ continue;
+ }
+
+ fdSrc.setAccessible(true);
+ try {
+ if(fdSrc.get(srcDev) != null) {
+ Field fdDest = destDev.getClass().getDeclaredField(fdSrc.getName());
+ fdDest.setAccessible(true);
+ fdDest.set(destDev, fdSrc.get(srcDev));
+ fdDest.setAccessible(false);
+ }
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ log.warn("Copy field maybe occurs some errors: ", e);
+ }
+
+ fdSrc.setAccessible(false);
+ }
+
+ return destDev;
+ }
+
+ @Test
+ public void classEnumValue() throws JsonProcessingException {
+ DisposeDevice dev = DisposeDevice.builder()
+ .ipAddr("10.88.77.15")
+ .ipPort("")
+ .deviceType(DisposeDeviceType.DPTECH_UMC)
+ .areaCode(0)
+ .deviceName("中移杭研实验室迪普清洗设备")
+ .manufacturer("DPTech")
+ .model("UMC")
+ .version("5.7.13")
+ .userName("admin")
+ .password("UMCAdministrator")
+ .urlPath("UMC/service/AbnormalFlowCleaningService")
+ .urlType(HttpType.HTTP)
+ .readme("实验室测试设备")
+ .status(ObjectStatus.NORMAL)
+ .build();
+
+ DisposeDevice dev2 = DisposeDevice.builder()
+ .version("5.7.135")
+ .build();
+
+ log.debug(new ObjectMapper()
+ .writerWithDefaultPrettyPrinter()
+ .writeValueAsString(upgradeDisposeDeviceProperties(dev, dev2)));
+ }
}
diff --git a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java
index 702a79c4..1dbacb12 100644
--- a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java
+++ b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java
@@ -3,12 +3,35 @@ package com.dispose.test.manager;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus;
+import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.FixMethodOrder;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import java.util.List;
+/**
+ * The type Dispose device manager test.
+ *
+ * @author
+ */
+@RunWith(SpringRunner.class)
+@Slf4j
+@SpringBootTest
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@Transactional
+@Rollback
public class DisposeDeviceManagerTest {
/**
* The Object mapper.
@@ -16,23 +39,56 @@ public class DisposeDeviceManagerTest {
@Resource
private ObjectMapper objectMapper;
+ /**
+ * The Dispose device mapper.
+ */
+ @Resource
+ private DisposeDeviceMapper disposeDeviceMapper;
+
+ /**
+ * A 1 add dispose device.
+ */
@Test
public void a1_addDisposeDevice() {
- DisposeDevice dev = DisposeDevice.builder()
- .ipAddr("10.88.77.15")
- .ipPort("")
- .deviceType(DisposeDeviceType.DPTECH_UMC)
- .areaCode(0)
- .deviceName("中移杭研实验室迪普清洗设备")
- .manufacturer("DPTech")
- .model("UMC")
- .version("5.7.13")
- .userName("admin")
- .password("UMCAdministrator")
- .urlPath("UMC/service/AbnormalFlowCleaningService")
- .urlType(HttpType.HTTP)
- .readme("实验室测试设备")
- .status(ObjectStatus.NORMAL)
- .build();
+
+ for(int i = 1; i < 256; i++) {
+ String ipAddr = "192.168.0." + String.valueOf(i);
+
+ DisposeDevice dev = DisposeDevice.builder()
+ .ipAddr(ipAddr)
+ .ipPort("")
+ .deviceType(DisposeDeviceType.DPTECH_UMC)
+ .areaCode(0)
+ .deviceName("中移杭研实验室迪普清洗设备")
+ .manufacturer("DPTech")
+ .model("UMC")
+ .version("5.7.13")
+ .userName("admin")
+ .password("UMCAdministrator")
+ .urlPath("UMC/service/AbnormalFlowCleaningService")
+ .urlType(HttpType.HTTP)
+ .readme("实验室测试设备")
+ .status(ObjectStatus.NORMAL)
+ .build();
+
+ disposeDeviceMapper.addNewDisposeDevice(dev);
+ }
}
+
+ /**
+ * G 1 get dispose device.
+ */
+ @Test
+ public void g1_getDisposeDevice() {
+ PageHelper.startPage(0, 20);
+
+ List devList = disposeDeviceMapper.selectAll();
+
+ PageInfo pageInfo = new PageInfo<>(devList);
+
+
+ log.debug("Get {} device items", devList.size());
+ log.debug("Page Info: total {}, page {}", pageInfo.getTotal(), pageInfo.getPageNum());
+ }
+
}