OCT
REM: 1. 更新spring boot web服务依赖 2. 增加更新设备信息接口 3. 增加分页查询调试接口
This commit is contained in:
parent
7a0c58f294
commit
a7b9293a88
|
@ -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
|
||||
|
|
14
pom.xml
14
pom.xml
|
@ -216,6 +216,20 @@
|
|||
<artifactId>ipaddress</artifactId>
|
||||
<version>5.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<AddDeviceReq> mr) {
|
||||
|
||||
private List<DisposeDevice> requestToDeviceList(AddDeviceReq req) {
|
||||
List<DisposeDevice> 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<AddDeviceReq> mr) {
|
||||
|
||||
// 请求参数转换
|
||||
List<DisposeDevice> devs = requestToDeviceList(mr.getMsgContent());
|
||||
|
||||
// 添加设备
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.addDisposeDevice(devs);
|
||||
|
||||
|
@ -138,7 +146,7 @@ public class DisposeDeviceManagerController {
|
|||
@DeleteMapping("/device")
|
||||
@ResponseBody
|
||||
@ApiOperation("删除处置能力节点")
|
||||
public ProtocolRespDTO<List<DelDeviceRsp>> removeDisposeDevice(
|
||||
public ProtocolRespDTO<List<DeviceInfoRsp>> removeDisposeDevice(
|
||||
@Validated(ValidGroups.ExplicitIdArrayValid.class)
|
||||
@RequestBody ProtocolReqDTO<IdArraysReq> mr) {
|
||||
|
||||
|
@ -152,10 +160,10 @@ public class DisposeDeviceManagerController {
|
|||
List<MulReturnType<ErrorCode, DisposeDevice>> ret =
|
||||
disposeDeviceManagerService.removeDisposeDevice(idList);
|
||||
|
||||
List<DelDeviceRsp> rspInfo = new ArrayList<>();
|
||||
List<DeviceInfoRsp> 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<List<DeviceInfoRsp>> upgradeDisposeDevice(
|
||||
@Validated(ValidGroups.UpgradeDeviceValid.class)
|
||||
@RequestBody ProtocolReqDTO<AddDeviceReq> mr) {
|
||||
|
||||
// 请求参数转换
|
||||
List<DisposeDevice> devs = requestToDeviceList(mr.getMsgContent());
|
||||
|
||||
// 更新设备信息
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.upgradeDisposeDevice(devs);
|
||||
|
||||
List<DeviceInfoRsp> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ErrorCode, Long> upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
|
||||
InvocationTargetException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) throws IllegalAccessException,
|
||||
NoSuchMethodException, InvocationTargetException {
|
||||
public MulReturnType<ErrorCode, Long> 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 <T> the type parameter
|
||||
* @param destDev the dest dev
|
||||
* @param srcDev the src dev
|
||||
*/
|
||||
private <T> 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<ErrorCode, Long> 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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,12 +30,15 @@ public class ValidGroups {
|
|||
public interface LogoutReqValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
public interface UpgradeDeviceValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Add device valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface AddDeviceValid extends ProtocolCommonValid {
|
||||
public interface AddDeviceValid extends UpgradeDeviceValid {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*/
|
|
@ -27,4 +27,13 @@ public interface DisposeDeviceManagerService {
|
|||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> removeDisposeDevice(List<Long> ids);
|
||||
|
||||
|
||||
/**
|
||||
* Upgrade dispose device list.
|
||||
*
|
||||
* @param devs the devs
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> upgradeDisposeDevice(List<DisposeDevice> devs);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,31 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
|
|||
List<MulReturnType<ErrorCode, DisposeDevice>> rspList = new ArrayList<>();
|
||||
|
||||
devs.forEach(v -> {
|
||||
MulReturnType<ErrorCode, Long> ret = null;
|
||||
try {
|
||||
ret = disposeDeviceManager.addDisposeDevice(v);
|
||||
MulReturnType<ErrorCode, Long> 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<MulReturnType<ErrorCode, DisposeDevice>> upgradeDisposeDevice(List<DisposeDevice> devs) {
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> rspList = new ArrayList<>();
|
||||
|
||||
devs.forEach(v -> {
|
||||
try {
|
||||
MulReturnType<ErrorCode, Long> ret = disposeDeviceManager.upgradeDisposeDevice(v);
|
||||
v.setId(ret.getSecondParam());
|
||||
rspList.add(new MulReturnType<>(ret.getFirstParam(), v));
|
||||
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
|
|
|
@ -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> 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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@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<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
PageInfo<DisposeDevice> pageInfo = new PageInfo<>(devList);
|
||||
|
||||
|
||||
log.debug("Get {} device items", devList.size());
|
||||
log.debug("Page Info: total {}, page {}", pageInfo.getTotal(), pageInfo.getPageNum());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue