OCT
REM: 1. 增加枚举与数据库类型统一转换 2. 增加设备管理mapper 3. 增加设备管理manager 4. 增加设备管理service 5. 增加设备管理相关接口 6. 增加相关功能、接口测试用例
This commit is contained in:
parent
e6420a641b
commit
f616a50a5a
config
src
main
java/com/dispose
common
BaseEnum.javaCommonEnumHandler.javaDisposeCapacityType.javaDisposeDeviceType.javaDisposeObjectType.javaErrorCode.javaHttpType.javaIpAddrType.javaObjectStatus.java
controller
manager
mapper
pojo
dto/protocol/device/manager
entity
service
resources/mappers
test/java/com/dispose/test
|
@ -8,7 +8,7 @@ spring.datasource.url=jdbc:mysql://cloud.xajhuang.com:3306/dispose?serverTimezon
|
|||
=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.username=xajhuang
|
||||
spring.datasource.password=eHkGjtTnkFSDHHA7
|
||||
spring.datasource.password=skhXSizrhfkhezy5
|
||||
# 配置连接池
|
||||
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
|
||||
spring.datasource.dbcp2.max-total=128
|
||||
|
@ -24,6 +24,7 @@ spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
|
|||
#mybatis.configuration.map-underscore-to-camel-case: true
|
||||
mybatis.mapper-locations=classpath*:mappers/*.xml
|
||||
mybatis.type-aliases-package=com.dispose.pojo.entity
|
||||
mybatis.configuration.default-enum-type-handler=com.dispose.common.CommonEnumHandler
|
||||
#config log
|
||||
logging.config=file:config/logback.xml
|
||||
#config tomcat
|
||||
|
|
|
@ -11,12 +11,12 @@ public interface BaseEnum {
|
|||
*
|
||||
* @return the value
|
||||
*/
|
||||
Integer getValue();
|
||||
Integer getCode();
|
||||
|
||||
/**
|
||||
* Gets description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
String getDescription();
|
||||
String getReadme();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public final class CommonEnumHandler<E extends BaseEnum> extends BaseTypeHandler
|
|||
/**
|
||||
* The Enums.
|
||||
*/
|
||||
private List<E> enums;
|
||||
private final List<E> enums;
|
||||
|
||||
/**
|
||||
* Instantiates a new Common enum handler.
|
||||
|
@ -51,7 +51,7 @@ public final class CommonEnumHandler<E extends BaseEnum> extends BaseTypeHandler
|
|||
*/
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement preparedStatement, int i, E e, JdbcType jdbcType) throws SQLException {
|
||||
preparedStatement.setInt(i, e.getValue());
|
||||
preparedStatement.setInt(i, e.getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +116,7 @@ public final class CommonEnumHandler<E extends BaseEnum> extends BaseTypeHandler
|
|||
*/
|
||||
private E locateEnumStatus(int index) {
|
||||
for (E e : enums) {
|
||||
if (e.getValue() == index) {
|
||||
if (e.getCode() == index) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package com.dispose.common;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DisposeCapacityType {
|
||||
public enum DisposeCapacityType implements BaseEnum {
|
||||
/**
|
||||
* The Cleanup.
|
||||
*/
|
||||
|
@ -31,7 +31,7 @@ public enum DisposeCapacityType {
|
|||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
|
@ -53,7 +53,8 @@ public enum DisposeCapacityType {
|
|||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
|
@ -62,6 +63,7 @@ public enum DisposeCapacityType {
|
|||
*
|
||||
* @return the readme
|
||||
*/
|
||||
@Override
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package com.dispose.common;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DisposeDeviceType {
|
||||
public enum DisposeDeviceType implements BaseEnum {
|
||||
/**
|
||||
* Dptech umc dispose device type.
|
||||
*/
|
||||
|
@ -33,7 +33,8 @@ public enum DisposeDeviceType {
|
|||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
|
@ -42,6 +43,7 @@ public enum DisposeDeviceType {
|
|||
*
|
||||
* @return the readme
|
||||
*/
|
||||
@Override
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package com.dispose.common;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum DisposeObjectType {
|
||||
public enum DisposeObjectType implements BaseEnum {
|
||||
/**
|
||||
* The Ip.
|
||||
*/
|
||||
|
@ -15,15 +15,30 @@ public enum DisposeObjectType {
|
|||
*/
|
||||
DOMAIN(1 << 1, "域名"),
|
||||
|
||||
/**
|
||||
* Ip domain dispose object type.
|
||||
*/
|
||||
IP_DOMAIN((1 << 1 | 1), "IP地址和域名"),
|
||||
|
||||
/**
|
||||
* Ip domain url dispose object type.
|
||||
*/
|
||||
IP_DOMAIN_URL((1 << 2 | 1 << 1 | 1), "IP地址,域名,URL"),
|
||||
|
||||
/**
|
||||
* Domain url dispose object type.
|
||||
*/
|
||||
DOMAIN_URL((1 << 2 | 1 << 1), "域名和URL"),
|
||||
/**
|
||||
* The Url.
|
||||
*/
|
||||
URL(1 << 2, "URL");
|
||||
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
|
@ -45,7 +60,8 @@ public enum DisposeObjectType {
|
|||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
|
@ -54,6 +70,7 @@ public enum DisposeObjectType {
|
|||
*
|
||||
* @return the readme
|
||||
*/
|
||||
@Override
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
|
|
|
@ -94,6 +94,11 @@ public enum ErrorCode {
|
|||
* The Err paramexception.
|
||||
*/
|
||||
ERR_PARAMEXCEPTION(21, "参数异常"),
|
||||
|
||||
/**
|
||||
* The Err devicelocked.
|
||||
*/
|
||||
ERR_DEVICELOCKED(22, "设备已锁定"),
|
||||
/**
|
||||
* The Err version.
|
||||
*/
|
||||
|
@ -151,6 +156,11 @@ public enum ErrorCode {
|
|||
* The Err haohan error.
|
||||
*/
|
||||
ERR_HAOHAN_ERROR(34, "浩瀚设备返回错误"),
|
||||
|
||||
/**
|
||||
* Err database error code.
|
||||
*/
|
||||
ERR_DATABASE(35, "操作数据库失败"),
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,7 @@ package com.dispose.common;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum HttpType {
|
||||
public enum HttpType implements BaseEnum {
|
||||
|
||||
/**
|
||||
* Http http type.
|
||||
|
@ -19,7 +19,7 @@ public enum HttpType {
|
|||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
|
@ -41,7 +41,7 @@ public enum HttpType {
|
|||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ public enum HttpType {
|
|||
*
|
||||
* @return the readme
|
||||
*/
|
||||
@Override
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
|
|
|
@ -5,20 +5,25 @@ package com.dispose.common;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum IpAddrType {
|
||||
public enum IpAddrType implements BaseEnum {
|
||||
/**
|
||||
* Ip v 4 ip addr type.
|
||||
* The Ipv 4.
|
||||
*/
|
||||
IPV4(1, "禁用"),
|
||||
IPV4(1, "IPv4"),
|
||||
/**
|
||||
* Ip v 6 ip addr type.
|
||||
* The Ipv 6.
|
||||
*/
|
||||
IPV6(1 << 1, "禁用");
|
||||
IPV6(1 << 1, "IPv6"),
|
||||
|
||||
/**
|
||||
* Ipv 4 ipv 6 ip addr type.
|
||||
*/
|
||||
IPV4_IPV6((1 << 1 | 1), "IPv4与IPv6");
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
|
@ -40,7 +45,8 @@ public enum IpAddrType {
|
|||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
|
@ -49,6 +55,7 @@ public enum IpAddrType {
|
|||
*
|
||||
* @return the readme
|
||||
*/
|
||||
@Override
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum User account status.
|
||||
* The enum Object status.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public enum ObjectStatus {
|
||||
public enum ObjectStatus implements BaseEnum {
|
||||
/**
|
||||
* Normal user account status.
|
||||
* The Normal.
|
||||
*/
|
||||
NORMAL(0, "正常"),
|
||||
/**
|
||||
* Locked user account status.
|
||||
* The Locked.
|
||||
*/
|
||||
LOCKED(1, "锁定"),
|
||||
/**
|
||||
* Disabled user account status.
|
||||
* The Disabled.
|
||||
*/
|
||||
DISABLED(2, "禁用"),
|
||||
/**
|
||||
* Deleted user account status.
|
||||
* The Deleted.
|
||||
*/
|
||||
DELETED(3, "删除");
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private final String readme;
|
||||
|
||||
/**
|
||||
* Instantiates a new User account status.
|
||||
* Instantiates a new Object status.
|
||||
*
|
||||
* @param code the code
|
||||
* @param readme the readme
|
||||
|
@ -48,7 +48,8 @@ public enum ObjectStatus {
|
|||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
|
@ -57,6 +58,7 @@ public enum ObjectStatus {
|
|||
*
|
||||
* @return the readme
|
||||
*/
|
||||
@Override
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.dispose.controller;
|
||||
|
||||
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceReq;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* The type Dispose device manager controller.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/manager")
|
||||
@Slf4j
|
||||
@Api(value = "处置平台设备管理接口", tags = "处置平台设备管理接口")
|
||||
@Component
|
||||
@Validated
|
||||
public class DisposeDeviceManagerController {
|
||||
/**
|
||||
* Add dispose device protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @return the protocol resp dto
|
||||
*/
|
||||
@PutMapping("/device")
|
||||
@ResponseBody
|
||||
@ApiOperation("添加处置能力节点")
|
||||
public ProtocolRespDTO<? extends BaseRespStatus> addDisposeDevice(
|
||||
@Validated
|
||||
@RequestBody ProtocolReqDTO<AddDeviceReq> mr) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* The interface Dispose device manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeDeviceManager {
|
||||
/**
|
||||
* Add dispose device mul return type.
|
||||
*
|
||||
* @param dev the dev
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev);
|
||||
|
||||
/**
|
||||
* Upgrade dispose device error code.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
ErrorCode upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
|
||||
InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Change dispose device status mul return type.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the mul return type
|
||||
*/
|
||||
MulReturnType<ErrorCode, ObjectStatus> changeDisposeDeviceStatus(Long id, ObjectStatus status);
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.mapper.DisposeCapacityMapper;
|
||||
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.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The type Dispose device manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||
|
||||
/**
|
||||
* The Dispose device.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevice = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The Dispose capacity mapper.
|
||||
*/
|
||||
@Resource
|
||||
DisposeCapacityMapper disposeCapacityMapper;
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
/**
|
||||
* Add dispose device mul return type.
|
||||
*
|
||||
* @param dev the dev
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) {
|
||||
// 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败
|
||||
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort());
|
||||
|
||||
if (tDev != null) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId());
|
||||
}
|
||||
|
||||
// 添加设备到数据库
|
||||
if (disposeDeviceMapper.addNewDisposeDevice(dev) != 1 || dev.getId() == null) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L);
|
||||
} else {
|
||||
// 添加设备到缓存中,方便调用时查找
|
||||
String devKey = dev.getDeviceName() + ":" + dev.getIpPort();
|
||||
disposeDevice.put(devKey, dev);
|
||||
// 添加设备能力信息
|
||||
disposeCapacityMapper.addNewDisposeCapacity(dev.getDevCapacity());
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, dev.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade dispose device error code.
|
||||
*
|
||||
* @param dev the dev
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
|
||||
InvocationTargetException {
|
||||
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort());
|
||||
|
||||
if (tDev == null) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
// 保存设备ID
|
||||
Long devId = tDev.getId();
|
||||
|
||||
// 更新值
|
||||
PropertyUtils.copyProperties(tDev, dev);
|
||||
tDev.setId(devId);
|
||||
|
||||
// 更新设备数据库
|
||||
disposeDeviceMapper.upgradeDisposeDevice(tDev);
|
||||
|
||||
// 清楚能力数据库中旧的能力信息
|
||||
disposeCapacityMapper.delDeviceDisposeCapacity(devId);
|
||||
// 新增能力信息完成更新
|
||||
disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity());
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change dispose device status mul return type.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the mul return type
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<ErrorCode, ObjectStatus> changeDisposeDeviceStatus(Long id, ObjectStatus status) {
|
||||
int ret;
|
||||
// 通过设备ID获取设备
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceById(id);
|
||||
|
||||
if (dev == null) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, ObjectStatus.NORMAL);
|
||||
} else {
|
||||
switch (status) {
|
||||
// 恢复设备到可用状态
|
||||
case NORMAL:
|
||||
ret = disposeDeviceMapper.availableDisposeDevice(id);
|
||||
break;
|
||||
// 删除设备
|
||||
case DELETED:
|
||||
ret = disposeDeviceMapper.delDisposeDevice(id);
|
||||
break;
|
||||
// 禁用设备
|
||||
case DISABLED:
|
||||
ret = disposeDeviceMapper.disableDisposeDevice(id);
|
||||
break;
|
||||
default:
|
||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, ObjectStatus.NORMAL);
|
||||
}
|
||||
|
||||
// 数据库操作失败
|
||||
if (ret != 1) {
|
||||
return new MulReturnType<>(ErrorCode.ERR_DATABASE, dev.getStatus());
|
||||
} else {
|
||||
return new MulReturnType<>(ErrorCode.ERR_OK, dev.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,9 +2,6 @@ package com.dispose.mapper;
|
|||
|
||||
import com.dispose.pojo.entity.DisposeCapacity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -13,8 +10,14 @@ import java.util.List;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeCapacityMapper extends Mapper<DisposeCapacity>,
|
||||
IdsMapper<DisposeCapacity>, MySqlMapper<DisposeCapacity> {
|
||||
public interface DisposeCapacityMapper {
|
||||
|
||||
/**
|
||||
* Select all list.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
List<DisposeCapacity> selectAll();
|
||||
|
||||
/**
|
||||
* Add new dispose capacity int.
|
||||
|
|
|
@ -2,17 +2,22 @@ package com.dispose.mapper;
|
|||
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Dispose device mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
|
||||
IdsMapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
||||
public interface DisposeDeviceMapper {
|
||||
|
||||
/**
|
||||
* Select all list.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
List<DisposeDevice> selectAll();
|
||||
|
||||
/**
|
||||
* Add new dispose device int.
|
||||
|
@ -22,6 +27,14 @@ public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
|
|||
*/
|
||||
int addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
/**
|
||||
* Upgrade dispose device int.
|
||||
*
|
||||
* @param dev the dev
|
||||
* @return the int
|
||||
*/
|
||||
int upgradeDisposeDevice(DisposeDevice dev);
|
||||
|
||||
|
||||
/**
|
||||
* Del dispose device int.
|
||||
|
@ -40,18 +53,30 @@ public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
|
|||
int disableDisposeDevice(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* Lock dispose device int.
|
||||
* Available dispose device int.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the int
|
||||
*/
|
||||
int lockDisposeDevice(@Param("id") Long id);
|
||||
int availableDisposeDevice(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* Unlock dispose device int.
|
||||
* Gets device by address.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param ipPort the ip port
|
||||
* @return the device by address
|
||||
*/
|
||||
DisposeDevice getDeviceByAddress(@Param("ipAddr") String ipAddr,
|
||||
@Param("ipPort") String ipPort);
|
||||
|
||||
|
||||
/**
|
||||
* Gets device by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the int
|
||||
* @return the device by id
|
||||
*/
|
||||
int unlockDisposeDevice(@Param("id") Long id);
|
||||
DisposeDevice getDeviceById(@Param("id") Long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,17 +2,22 @@ package com.dispose.mapper;
|
|||
|
||||
import com.dispose.pojo.entity.UserAccount;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface User account mapper.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface UserAccountMapper extends Mapper<UserAccount>,
|
||||
IdsMapper<UserAccount>, MySqlMapper<UserAccount> {
|
||||
public interface UserAccountMapper {
|
||||
|
||||
/**
|
||||
* Select all list.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
List<UserAccount> selectAll();
|
||||
|
||||
/**
|
||||
* Add user account user account.
|
||||
|
@ -75,7 +80,7 @@ public interface UserAccountMapper extends Mapper<UserAccount>,
|
|||
void unlockUserAccount(@Param("username") String username);
|
||||
|
||||
/**
|
||||
* Upgrade login time string.
|
||||
* Upgrade login time.
|
||||
*
|
||||
* @param username the username
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package com.dispose.pojo.dto.protocol.device.manager;
|
||||
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddDeviceInfo {
|
||||
/**
|
||||
* The Ip addr.
|
||||
*/
|
||||
@NotBlank(message = "ipAddr IP地址不能为空")
|
||||
private String ipAddr;
|
||||
|
||||
/**
|
||||
* The Ip port.
|
||||
*/
|
||||
@NotNull(message = "ipPort 端口不能为null, 默认端口用空字符串表示")
|
||||
private String ipPort;
|
||||
|
||||
/**
|
||||
* The Device type.
|
||||
*/
|
||||
private DisposeDeviceType deviceType;
|
||||
|
||||
/**
|
||||
* The Area code.
|
||||
*/
|
||||
private Integer areaCode;
|
||||
|
||||
/**
|
||||
* The Device name.
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* The Manufacturer.
|
||||
*/
|
||||
private String manufacturer;
|
||||
|
||||
/**
|
||||
* The Model.
|
||||
*/
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* The Version.
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* The User name.
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* The Password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* The Url path.
|
||||
*/
|
||||
@NotBlank(message = "urlPath URL接口路径不能为空")
|
||||
private String urlPath;
|
||||
|
||||
/**
|
||||
* The Url type.
|
||||
*/
|
||||
private HttpType urlType;
|
||||
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private String readme;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.dispose.pojo.dto.protocol.device.manager;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Add device req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddDeviceReq {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
@NotNull(message = "items 设备列表不能为空")
|
||||
private List<AddDeviceInfo> items;
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package com.dispose.pojo.entity;
|
||||
|
||||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.DisposeObjectType;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
@ -50,17 +53,17 @@ public class DisposeCapacity {
|
|||
/**
|
||||
* The Capacity type.
|
||||
*/
|
||||
private Integer capacityType;
|
||||
private DisposeCapacityType capacityType;
|
||||
|
||||
/**
|
||||
* The Object type.
|
||||
*/
|
||||
private Integer objectType;
|
||||
private DisposeObjectType objectType;
|
||||
|
||||
/**
|
||||
* The Ip type.
|
||||
*/
|
||||
private Integer ipType;
|
||||
private IpAddrType ipType;
|
||||
|
||||
/**
|
||||
* The Protect ip.
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.dispose.pojo.entity;
|
||||
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
@ -29,6 +33,7 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder(alphabetic=true)
|
||||
@Table(name = "dispose_device")
|
||||
@NameStyle(Style.normal)
|
||||
public class DisposeDevice implements Serializable {
|
||||
|
@ -57,7 +62,7 @@ public class DisposeDevice implements Serializable {
|
|||
/**
|
||||
* The Device type.
|
||||
*/
|
||||
private Integer deviceType;
|
||||
private DisposeDeviceType deviceType;
|
||||
|
||||
/**
|
||||
* The Area code.
|
||||
|
@ -102,7 +107,7 @@ public class DisposeDevice implements Serializable {
|
|||
/**
|
||||
* The Url type.
|
||||
*/
|
||||
private Integer urlType;
|
||||
private HttpType urlType;
|
||||
|
||||
/**
|
||||
* The Readme.
|
||||
|
@ -112,7 +117,7 @@ public class DisposeDevice implements Serializable {
|
|||
/**
|
||||
* The Status.
|
||||
*/
|
||||
private Integer status;
|
||||
private ObjectStatus status;
|
||||
|
||||
/**
|
||||
* The Dev capacity.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.dispose.pojo.entity;
|
||||
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
@ -89,5 +90,5 @@ public class UserAccount implements Serializable {
|
|||
/**
|
||||
* The Status.
|
||||
*/
|
||||
private Integer status;
|
||||
private ObjectStatus status;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.dispose.service;
|
||||
|
||||
/**
|
||||
* The interface Dispose device manager service.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeDeviceManagerService {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.service.DisposeDeviceManagerService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* The type Dispose device manager.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerService {
|
||||
}
|
|
@ -71,7 +71,7 @@ public class UserAccountServiceImpl implements UserAccountService {
|
|||
}
|
||||
|
||||
// 用户是否被锁定
|
||||
if (loginUser.getStatus() == ObjectStatus.LOCKED.getCode()) {
|
||||
if (loginUser.getStatus() == ObjectStatus.LOCKED) {
|
||||
log.error("User {} is locked", username);
|
||||
return MulReturnType.<ErrorCode, String>builder().firstParam(ErrorCode.ERR_USERLOCK).build();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.DisposeCapacityMapper">
|
||||
<resultMap id="dispose_capacity" type="com.dispose.pojo.entity.DisposeCapacity">
|
||||
<id column="id" property="id"/>
|
||||
<result column="capacityType" property="capacityType" javaType="com.dispose.common.DisposeCapacityType"/>
|
||||
<result column="objectType" property="objectType" javaType="com.dispose.common.DisposeObjectType"/>
|
||||
<result column="ipType" property="ipType" javaType="com.dispose.common.IpAddrType"/>
|
||||
<result column="protectIp" property="protectIp"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="dispose_capacity">
|
||||
SELECT *
|
||||
FROM dispose_capacity
|
||||
</select>
|
||||
|
||||
<insert id="addNewDisposeCapacity" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.DisposeCapacity">
|
||||
INSERT IGNORE INTO dispose_capacity(deviceId, capacityType, objectType, ipType, protectIp)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<id column="id" property="id"/>
|
||||
<result column="ipAddr" property="ipAddr"/>
|
||||
<result column="ipPort" property="ipPort"/>
|
||||
<result column="deviceType" property="deviceType"/>
|
||||
<result column="deviceType" property="deviceType" javaType="com.dispose.common.DisposeDeviceType"/>
|
||||
<result column="areaCode" property="areaCode"/>
|
||||
<result column="deviceName" property="deviceName"/>
|
||||
<result column="manufacturer" property="manufacturer"/>
|
||||
|
@ -14,19 +14,43 @@
|
|||
<result column="userName" property="userName"/>
|
||||
<result column="password" property="password"/>
|
||||
<result column="urlPath" property="urlPath"/>
|
||||
<result column="urlType" property="urlType"/>
|
||||
<result column="urlType" property="urlType" javaType="com.dispose.common.HttpType"/>
|
||||
<result column="readme" property="readme"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="status" property="status" javaType="com.dispose.common.ObjectStatus"/>
|
||||
<collection property="devCapacity" ofType="com.dispose.pojo.entity.DisposeCapacity">
|
||||
<id column="c_id" property="id"/>
|
||||
<result column="deviceId" property="deviceId"/>
|
||||
<result column="capacityType" property="capacityType"/>
|
||||
<result column="objectType" property="objectType"/>
|
||||
<result column="ipType" property="ipType"/>
|
||||
<result column="capacityType" property="capacityType" javaType="com.dispose.common.DisposeCapacityType"/>
|
||||
<result column="objectType" property="objectType" javaType="com.dispose.common.DisposeObjectType"/>
|
||||
<result column="ipType" property="ipType" javaType="com.dispose.common.IpAddrType"/>
|
||||
<result column="protectIp" property="protectIp"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="dispose_device">
|
||||
SELECT d.*,
|
||||
c.*
|
||||
FROM dispose_device d
|
||||
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||
</select>
|
||||
|
||||
<select id="getDeviceByAddress" resultMap="dispose_device">
|
||||
SELECT d.*,
|
||||
c.*
|
||||
FROM dispose_device d
|
||||
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||
WHERE d.ipAddr = #{ipAddr}
|
||||
AND d.ipPort = #{ipPort}
|
||||
</select>
|
||||
|
||||
<select id="getDeviceById" resultMap="dispose_device">
|
||||
SELECT d.*,
|
||||
c.*
|
||||
FROM dispose_device d
|
||||
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||
WHERE d.id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.DisposeDevice">
|
||||
INSERT IGNORE INTO dispose_device(ipAddr, ipPort, deviceType,
|
||||
|
@ -44,6 +68,25 @@
|
|||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="upgradeDisposeDevice" parameterType="com.dispose.pojo.entity.DisposeDevice">
|
||||
UPDATE dispose_device
|
||||
SET ipAddr = #{ipAddr},
|
||||
ipPort = #{ipPort},
|
||||
deviceType = #{deviceType},
|
||||
areaCode = #{areaCode},
|
||||
deviceName = #{deviceName},
|
||||
manufacturer = #{manufacturer},
|
||||
model = #{model},
|
||||
version = #{version},
|
||||
userName = #{userName},
|
||||
password = #{password},
|
||||
urlPath = #{urlPath},
|
||||
urlType = #{urlType},
|
||||
readme = #{readme},
|
||||
status = #{status}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="disableDisposeDevice">
|
||||
UPDATE
|
||||
dispose_device
|
||||
|
@ -51,14 +94,9 @@
|
|||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="lockDisposeDevice">
|
||||
UPDATE dispose_device
|
||||
SET status = ${@com.dispose.common.ObjectStatus@LOCKED.getCode()}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="unlockDisposeDevice">
|
||||
UPDATE dispose_device
|
||||
<update id="availableDisposeDevice">
|
||||
UPDATE
|
||||
dispose_device
|
||||
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getCode()}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
|
|
@ -1,8 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.UserAccountMapper">
|
||||
<!-- mapper xml文件中只编写复杂逻辑的SQL SQL单独拿出来写,与代码解耦,SQL的熟练编写是每个研发必备的技能 -->
|
||||
<select id="addUserAccount" resultType="com.dispose.pojo.entity.UserAccount">
|
||||
|
||||
<resultMap id="user_account" type="com.dispose.pojo.entity.UserAccount">
|
||||
<id column="id" property="id"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="password" property="password"/>
|
||||
<result column="createTime" property="createTime"/>
|
||||
<result column="operators" property="operators"/>
|
||||
<result column="lastLoginTime" property="lastLoginTime"/>
|
||||
<result column="token" property="token"/>
|
||||
<result column="lastAccess" property="lastAccess"/>
|
||||
<result column="pwdErrTimes" property="pwdErrTimes"/>
|
||||
<result column="lockTime" property="lockTime"/>
|
||||
<result column="status" property="status" javaType="com.dispose.common.ObjectStatus"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="user_account">
|
||||
SELECT *
|
||||
FROM user_account
|
||||
</select>
|
||||
|
||||
<select id="addUserAccount" resultMap="user_account">
|
||||
INSERT INTO user_account(username, password, operators, status)
|
||||
SELECT #{username}, #{password}, #{operators}, ${@com.dispose.common.ObjectStatus@NORMAL.getCode()}
|
||||
FROM DUAL
|
||||
|
@ -17,13 +36,13 @@
|
|||
WHERE username = #{username, jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="getUserByName" resultType="com.dispose.pojo.entity.UserAccount">
|
||||
<select id="getUserByName" resultMap="user_account">
|
||||
SELECT *
|
||||
FROM user_account
|
||||
WHERE username = #{username, jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="getUserByToken" resultType="com.dispose.pojo.entity.UserAccount">
|
||||
<select id="getUserByToken" resultMap="user_account">
|
||||
SELECT *
|
||||
FROM user_account
|
||||
WHERE token = #{token}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class AuthControllerTest extends InitTestEnvironment {
|
|||
|
||||
verifyRespProtocol(rspInfo);
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
|
||||
|
||||
Assert.assertEquals(getLoginToken(), rspInfo.getMsgContent().getToken());
|
||||
Assert.assertEquals(getUSER_NAME(), rspInfo.getMsgContent().getUserName());
|
||||
|
@ -131,7 +131,7 @@ public class AuthControllerTest extends InitTestEnvironment {
|
|||
|
||||
verifyRespProtocol(rspInfo);
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
|
||||
Assert.assertEquals(getUSER_NAME(), rspInfo.getMsgContent().getUserName());
|
||||
Assert.assertEquals(ErrorCode.ERR_OK.getCode(), (long)rspInfo.getMsgContent().getStatus());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.dispose.test.manager;
|
||||
|
||||
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.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
public class DisposeDeviceManagerTest {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
UserAccount user = userAccountManager.getUserByToken(token);
|
||||
|
||||
Assert.assertEquals(user.getUsername(), v.getUsername());
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
} catch (NoSuchAlgorithmException | JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
Assert.fail();
|
||||
|
@ -78,7 +78,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
Assert.assertEquals(user.getStatus(), v.getStatus());
|
||||
|
||||
try {
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
|
@ -93,7 +93,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
String userToken = userAccountManager.getUserToken(v.getUsername());
|
||||
String userToken2 = userAccountManager.getUserToken(v.getUsername());
|
||||
Assert.assertEquals(userToken, userToken2);
|
||||
log.info("{} token : [{}]", v.getUsername(), userToken);
|
||||
log.debug("{} token : [{}]", v.getUsername(), userToken);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.error(e.getMessage());
|
||||
Assert.fail();
|
||||
|
@ -116,7 +116,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
Assert.assertEquals(i, times);
|
||||
|
||||
try {
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
|
@ -139,7 +139,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
|
||||
Assert.assertEquals(ErrorCode.ERR_LOGOUT, userAccountManager.verifyToken(userToken));
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
} catch (JsonProcessingException | NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
|
@ -164,25 +164,25 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
UserAccount user = userAccountMapper.getUserByName(v.getUsername());
|
||||
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals((long) user.getStatus(), ObjectStatus.LOCKED.getCode());
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.LOCKED);
|
||||
|
||||
userAccountManager.unlockUserAccount(v.getUsername());
|
||||
user = userAccountMapper.getUserByName(v.getUsername());
|
||||
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals((long) user.getStatus(), ObjectStatus.NORMAL.getCode());
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.NORMAL);
|
||||
|
||||
userAccountManager.disableUserAccount(v.getUsername(), "admin");
|
||||
user = userAccountMapper.getUserByName(v.getUsername());
|
||||
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals((long) user.getStatus(), ObjectStatus.DISABLED.getCode());
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED);
|
||||
|
||||
userAccountManager.deleteUserAccount(v.getUsername(), "admin");
|
||||
user = userAccountMapper.getUserByName(v.getUsername());
|
||||
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals((long) user.getStatus(), ObjectStatus.DELETED.getCode());
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -57,17 +57,17 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.CLEANUP.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.BLOCKING.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.BLOCKING)
|
||||
.objectType(DisposeObjectType.URL)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
List<DisposeCapacity> capList = disposeCapacityMapper.selectAll();
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,17 +91,17 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.CLEANUP.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.BLOCKING.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.BLOCKING)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
|
@ -111,10 +111,10 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
List<DisposeCapacity> capList = disposeCapacityMapper.selectAll();
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
|
||||
items = disposeCapacityMapper.delDisposeCapacity(capList.get(0).getDeviceId(),
|
||||
capList.get(0).getCapacityType());
|
||||
capList.get(0).getCapacityType().getCode());
|
||||
|
||||
Assert.assertEquals(items, 1);
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
Assert.assertEquals(capList.size(), 1);
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,17 +131,17 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.CLEANUP.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.BLOCKING.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.BLOCKING)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
|
@ -159,17 +159,17 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.CLEANUP.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.CLEANUP)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
newCapList.add(DisposeCapacity.builder()
|
||||
.deviceId(1L)
|
||||
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
|
||||
.capacityType(DisposeCapacityType.BLOCKING.getCode())
|
||||
.objectType(DisposeObjectType.IP.getCode())
|
||||
.ipType(IpAddrType.IPV4_IPV6)
|
||||
.capacityType(DisposeCapacityType.BLOCKING)
|
||||
.objectType(DisposeObjectType.IP)
|
||||
.protectIp("")
|
||||
.build());
|
||||
|
||||
|
@ -179,6 +179,6 @@ public class DisposeCapacityMapperTest {
|
|||
|
||||
Assert.assertEquals(capList.size(), newCapList.size());
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class DisposeDeviceMapperTest {
|
|||
DisposeDevice dev = DisposeDevice.builder()
|
||||
.ipAddr("10.88.77.15")
|
||||
.ipPort("")
|
||||
.deviceType(DisposeDeviceType.DPTECH_UMC.getCode())
|
||||
.deviceType(DisposeDeviceType.DPTECH_UMC)
|
||||
.areaCode(0)
|
||||
.deviceName("中移杭研实验室迪普清洗设备")
|
||||
.manufacturer("DPTech")
|
||||
|
@ -62,9 +62,30 @@ public class DisposeDeviceMapperTest {
|
|||
.userName("admin")
|
||||
.password("UMCAdministrator")
|
||||
.urlPath("UMC/service/AbnormalFlowCleaningService")
|
||||
.urlType(HttpType.HTTP.getCode())
|
||||
.urlType(HttpType.HTTP)
|
||||
.readme("实验室测试设备")
|
||||
.status(ObjectStatus.NORMAL.getCode())
|
||||
.status(ObjectStatus.NORMAL)
|
||||
.build();
|
||||
|
||||
Assert.assertEquals(1, disposeDeviceMapper.addNewDisposeDevice(dev));
|
||||
Assert.assertNotNull(dev.getId());
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
|
||||
dev = DisposeDevice.builder()
|
||||
.ipAddr("10.88.77.88")
|
||||
.ipPort("18080")
|
||||
.deviceType(DisposeDeviceType.HAOHAN_PLATFORM)
|
||||
.areaCode(0)
|
||||
.deviceName("中移杭研实验室浩瀚清洗设备")
|
||||
.manufacturer("Haohan")
|
||||
.model("Unknown")
|
||||
.version("Unknown")
|
||||
.userName("")
|
||||
.password("")
|
||||
.urlPath("DDoSClean/clean")
|
||||
.urlType(HttpType.HTTP)
|
||||
.readme("实验室测试设备")
|
||||
.status(ObjectStatus.NORMAL)
|
||||
.build();
|
||||
|
||||
Assert.assertEquals(1, disposeDeviceMapper.addNewDisposeDevice(dev));
|
||||
|
@ -75,4 +96,17 @@ public class DisposeDeviceMapperTest {
|
|||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void d1_getDeviceByAddress() throws JsonProcessingException {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", "");
|
||||
Assert.assertNotNull(dev);
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
|
||||
dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", "80");
|
||||
Assert.assertNull(dev);
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class UserAccountMapperTest {
|
|||
public void a1_getUserByName() throws JsonProcessingException {
|
||||
UserAccount user = userAccountMapper.getUserByName("admin");
|
||||
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals(user.getUsername(), "admin");
|
||||
|
@ -70,13 +70,13 @@ public class UserAccountMapperTest {
|
|||
userAccountMapper.lockUserAccount("admin");
|
||||
|
||||
UserAccount user = userAccountMapper.getUserByName("admin");
|
||||
Assert.assertEquals(new Long(user.getStatus()), new Long(ObjectStatus.LOCKED.getCode()));
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.LOCKED);
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
|
||||
userAccountMapper.unlockUserAccount("admin");
|
||||
user = userAccountMapper.getUserByName("admin");
|
||||
Assert.assertEquals(new Long(user.getStatus()), new Long(ObjectStatus.NORMAL.getCode()));
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.NORMAL);
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class UserAccountMapperTest {
|
|||
|
||||
UserAccount user = userAccountMapper.getUserByName("admin");
|
||||
Assert.assertNotNull(user);
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,7 @@ public class UserAccountMapperTest {
|
|||
.forEach(v -> {
|
||||
UserAccount user = userAccountMapper.getUserByToken(v.getToken());
|
||||
try {
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class UserAccountMapperTest {
|
|||
public void a5_upgradeUserAccess() {
|
||||
String dt = userAccountMapper.upgradeLastAccessTime("admin");
|
||||
|
||||
log.info("Upgrade datetime: {}", dt);
|
||||
log.debug("Upgrade datetime: {}", dt);
|
||||
|
||||
Assert.assertTrue(Helper.getTimestampDiffNow(dt) < 2);
|
||||
}
|
||||
|
@ -130,8 +130,8 @@ public class UserAccountMapperTest {
|
|||
Assert.assertNotNull(add);
|
||||
UserAccount user = userAccountMapper.getUserByName("xajhuang2");
|
||||
Assert.assertNotNull(user);
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
|
||||
|
||||
add = userAccountMapper.addUserAccount("xajhuang", "test123", "admin");
|
||||
Assert.assertNotNull(add);
|
||||
|
@ -142,12 +142,12 @@ public class UserAccountMapperTest {
|
|||
String username = "xajhuang2";
|
||||
UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin");
|
||||
Assert.assertNotNull(add);
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
|
||||
userAccountMapper.delUserAccount(username, "admin");
|
||||
UserAccount user = userAccountMapper.getUserByName(username);
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals((long)user.getStatus(), ObjectStatus.DELETED.getCode());
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED);
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -155,11 +155,11 @@ public class UserAccountMapperTest {
|
|||
String username = "xajhuang2";
|
||||
UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin");
|
||||
Assert.assertNotNull(add);
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
|
||||
userAccountMapper.disableUserAccount(username, "admin");
|
||||
UserAccount user = userAccountMapper.getUserByName(username);
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals((long)user.getStatus(), ObjectStatus.DISABLED.getCode());
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED);
|
||||
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue