parent
d36aa022d1
commit
86ab4fb8d7
|
@ -122,4 +122,24 @@ public final class CommonEnumHandler<E extends BaseEnum> extends BaseTypeHandler
|
|||
}
|
||||
throw new IllegalArgumentException(enumType.getName() + " unknown enumerated type index:" + index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Code of e.
|
||||
*
|
||||
* @param <E> the type parameter
|
||||
* @param enumClass the enum class
|
||||
* @param code the code
|
||||
* @return the e
|
||||
*/
|
||||
public static <E extends Enum<?> & BaseEnum> E codeOf(Class<E> enumClass, int code) {
|
||||
E[] enumCodes = enumClass.getEnumConstants();
|
||||
|
||||
for(E e : enumCodes) {
|
||||
if(e.getValue() == code) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,19 @@
|
|||
package com.dispose.controller;
|
||||
|
||||
import com.dispose.common.CommonEnumHandler;
|
||||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.DisposeObjectType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.dispose.pojo.dto.protocol.base.IdArraysReq;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||
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.entity.DisposeCapacity;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DisposeDeviceManagerService;
|
||||
|
@ -14,6 +23,7 @@ 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.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -36,6 +46,9 @@ import java.util.List;
|
|||
@Validated
|
||||
public class DisposeDeviceManagerController {
|
||||
|
||||
/**
|
||||
* The Dispose device manager service.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceManagerService disposeDeviceManagerService;
|
||||
|
||||
|
@ -48,12 +61,13 @@ public class DisposeDeviceManagerController {
|
|||
@PutMapping("/device")
|
||||
@ResponseBody
|
||||
@ApiOperation("添加处置能力节点")
|
||||
public ProtocolRespDTO<? extends BaseRespStatus> addDisposeDevice(
|
||||
@Validated
|
||||
public ProtocolRespDTO<? extends AddDeviceRsp> addDisposeDevice(
|
||||
@Validated(ValidGroups.AddDeviceValid.class)
|
||||
@RequestBody ProtocolReqDTO<AddDeviceReq> mr) {
|
||||
|
||||
List<DisposeDevice> devs = new ArrayList<>();
|
||||
|
||||
// 获取请求中的需要添加的设备列表
|
||||
mr.getMsgContent().getItems().forEach(v -> {
|
||||
DisposeDevice dev = DisposeDevice.builder()
|
||||
.ipAddr(v.getIpAddr())
|
||||
|
@ -70,13 +84,87 @@ public class DisposeDeviceManagerController {
|
|||
.urlType(v.getUrlType())
|
||||
.readme(v.getReadme())
|
||||
.build();
|
||||
|
||||
// 初始化设备能力信息
|
||||
dev.setDevCapacity(new ArrayList<>());
|
||||
|
||||
v.getCapacity().forEach(k -> {
|
||||
// 添加设备能力
|
||||
DisposeCapacity cap = DisposeCapacity.builder()
|
||||
.capacityType(CommonEnumHandler.codeOf(DisposeCapacityType.class, k.getCapacityType()))
|
||||
.ipType(CommonEnumHandler.codeOf(IpAddrType.class, k.getIpType()))
|
||||
.objectType(CommonEnumHandler.codeOf(DisposeObjectType.class, k.getObjectType()))
|
||||
.protectIp(k.getProtectIp())
|
||||
.build();
|
||||
dev.getDevCapacity().add(cap);
|
||||
});
|
||||
|
||||
devs.add(dev);
|
||||
});
|
||||
|
||||
// 添加设备
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.addDisposeDevice(devs);
|
||||
|
||||
// 协议响应消息
|
||||
AddDeviceRsp rspInfo = new AddDeviceRsp();
|
||||
|
||||
ret.forEach(v -> {
|
||||
DisposeDevice dev = v.getSecondParam();
|
||||
AddDeviceRet rsp = AddDeviceRet.builder()
|
||||
.ipAddr(dev.getIpAddr())
|
||||
.ipPort(dev.getIpPort())
|
||||
.build();
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK);
|
||||
rsp.setStatus(v.getFirstParam().getCode());
|
||||
rsp.setMessage(new String[] {v.getFirstParam().getMsg()});
|
||||
|
||||
// 添加设备成功,记录新增设备ID
|
||||
if(rsp.getStatus() == ErrorCode.ERR_OK.getCode()) {
|
||||
rsp.setDevId(String.valueOf(dev.getId()));
|
||||
}
|
||||
|
||||
rspInfo.getItems().add(rsp);
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove dispose device protocol resp dto.
|
||||
*
|
||||
* @param mr the mr
|
||||
* @return the protocol resp dto
|
||||
*/
|
||||
@DeleteMapping("/device")
|
||||
@ResponseBody
|
||||
@ApiOperation("删除处置能力节点")
|
||||
public ProtocolRespDTO<List<DelDeviceRsp>> removeDisposeDevice(
|
||||
@Validated(ValidGroups.ExplicitIdArrayValid.class)
|
||||
@RequestBody ProtocolReqDTO<IdArraysReq> mr) {
|
||||
|
||||
List<Long> idList = new ArrayList<>();
|
||||
|
||||
for (String s : mr.getMsgContent().getId()) {
|
||||
idList.add(Long.parseLong(s));
|
||||
}
|
||||
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> ret =
|
||||
disposeDeviceManagerService.removeDisposeDevice(idList);
|
||||
|
||||
List<DelDeviceRsp> rspInfo = new ArrayList<>();
|
||||
|
||||
ret.forEach(v -> {
|
||||
DelDeviceRsp rsp = new DelDeviceRsp();
|
||||
DisposeDevice dev = v.getSecondParam();
|
||||
|
||||
rsp.setId(String.valueOf(dev.getId()));
|
||||
rsp.setDevStatus(dev.getStatus());
|
||||
rsp.setStatus(v.getFirstParam().getCode());
|
||||
rsp.setMessage(new String[] {v.getFirstParam().getMsg()});
|
||||
|
||||
rspInfo.add(rsp);
|
||||
});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class GlobalExceptionHandler {
|
|||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseBody
|
||||
public ProtocolRespDTO<BaseRespStatus> handleException(MethodArgumentNotValidException ex) {
|
||||
log.error("Argument Exception: {}", ex.getMessage());
|
||||
log.error("Argument Exception: ", ex);
|
||||
List<String> exMsg = new ArrayList<>();
|
||||
|
||||
AtomicInteger idx = new AtomicInteger();
|
||||
|
@ -45,4 +45,13 @@ public class GlobalExceptionHandler {
|
|||
HttpStatus.error400().status(),
|
||||
exMsg.toArray(new String[0]));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Throwable.class)
|
||||
@ResponseBody
|
||||
public ProtocolRespDTO<BaseRespStatus> handleException(Throwable ex) {
|
||||
log.error("Throwable Exception: ", ex);
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION,
|
||||
HttpStatus.error400().status(), new String[] {ErrorCode.ERR_PARAMEXCEPTION.getMsg()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,12 @@ public interface 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
|
||||
*/
|
||||
MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev);
|
||||
MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) throws IllegalAccessException,
|
||||
NoSuchMethodException, InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Upgrade dispose device error code.
|
||||
|
|
|
@ -44,13 +44,22 @@ 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) {
|
||||
public MulReturnType<ErrorCode, Long> addDisposeDevice(DisposeDevice dev) throws IllegalAccessException,
|
||||
NoSuchMethodException, InvocationTargetException {
|
||||
// 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败
|
||||
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort());
|
||||
|
||||
if (tDev != null) {
|
||||
|
||||
if(dev.getStatus() == ObjectStatus.DELETED) {
|
||||
return new MulReturnType<>(upgradeDisposeDevice(dev), tDev.getId());
|
||||
}
|
||||
|
||||
return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId());
|
||||
}
|
||||
|
||||
|
@ -72,6 +81,9 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
|||
*
|
||||
* @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
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode upgradeDisposeDevice(DisposeDevice dev) throws IllegalAccessException, NoSuchMethodException,
|
||||
|
|
|
@ -388,7 +388,7 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
|||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
if (ADMIN_USERS.length == 0) {
|
||||
if (ADMIN_USERS == null || ADMIN_USERS.length == 0) {
|
||||
ADMIN_USERS = userPermissionConfigure.getAdminUsers().split(disposeConfigure.getSplitChar());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class LoginReq {
|
|||
/**
|
||||
* The User name.
|
||||
*/
|
||||
@NotBlank(message = "userName 用户名不能为空")
|
||||
@NotBlank(message = "userName 用户名不能为空", groups = ValidGroups.LogoutReqValid.class)
|
||||
@Pattern(regexp = AuthConfigValue.MYSQL_REGEX_CHARS,
|
||||
flags = Pattern.Flag.CASE_INSENSITIVE,
|
||||
message = "userName 用户名存在非法字符串")
|
||||
|
|
|
@ -24,21 +24,21 @@ import lombok.NoArgsConstructor;
|
|||
public class LoginRsp extends BaseRespStatus {
|
||||
|
||||
/**
|
||||
* 登录的用户名
|
||||
* The User name.
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 访问权限token
|
||||
* The Token.
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 登录UTC时间戳(ms)
|
||||
* The Log time.
|
||||
*/
|
||||
private Long logTime;
|
||||
/**
|
||||
* token超时时间 (分钟)
|
||||
* The Expire time.
|
||||
*/
|
||||
private Long expireTime;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import lombok.NoArgsConstructor;
|
|||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonPropertyOrder({"id", "devId", "status", "message"})
|
||||
@JsonPropertyOrder({"ipAddr", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class BaseIdResp extends BaseRespStatus {
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.dispose.pojo.dto.protocol.base;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* The type Id arrays req.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class IdArraysReq {
|
||||
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
@NotNull(message = "id 字段不能为空", groups = ValidGroups.IdArrayValid.class)
|
||||
@Size(min = 1, message = "id 字段必须指定明确id编号", groups = ValidGroups.ExplicitIdArrayValid.class)
|
||||
private String[] id;
|
||||
|
||||
/**
|
||||
* The Task id.
|
||||
*/
|
||||
private String[] taskId;
|
||||
}
|
|
@ -7,7 +7,7 @@ package com.dispose.pojo.dto.protocol.base;
|
|||
*/
|
||||
public class ValidGroups {
|
||||
/**
|
||||
* The interface Protocol common.
|
||||
* The interface Protocol common valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
|
@ -15,18 +15,42 @@ public class ValidGroups {
|
|||
}
|
||||
|
||||
/**
|
||||
* The interface Login req.
|
||||
* The interface Login req valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface LoginReqValid extends ProtocolCommonValid {
|
||||
public interface LoginReqValid extends LogoutReqValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Logout req.
|
||||
* The interface Logout req valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface LogoutReqValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Add device valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface AddDeviceValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Id array valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface IdArrayValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Explicit id array valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface ExplicitIdArrayValid extends IdArrayValid{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dispose.pojo.dto.protocol.device.manager;
|
|||
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.dispose.pojo.dto.protocol.base.ValidGroups;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
@ -27,13 +28,13 @@ public class AddDeviceInfo {
|
|||
/**
|
||||
* The Ip addr.
|
||||
*/
|
||||
@NotBlank(message = "ipAddr IP地址不能为空")
|
||||
@NotBlank(message = "ipAddr IP地址不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||
private String ipAddr;
|
||||
|
||||
/**
|
||||
* The Ip port.
|
||||
*/
|
||||
@NotNull(message = "ipPort 端口不能为null, 默认端口用空字符串表示")
|
||||
@NotNull(message = "ipPort 端口不能为null, 默认端口用空字符串表示", groups = ValidGroups.AddDeviceValid.class)
|
||||
private String ipPort;
|
||||
|
||||
/**
|
||||
|
@ -79,7 +80,7 @@ public class AddDeviceInfo {
|
|||
/**
|
||||
* The Url path.
|
||||
*/
|
||||
@NotBlank(message = "urlPath URL接口路径不能为空")
|
||||
@NotBlank(message = "urlPath URL接口路径不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||
private String urlPath;
|
||||
|
||||
/**
|
||||
|
@ -95,7 +96,7 @@ public class AddDeviceInfo {
|
|||
/**
|
||||
* The Capacity.
|
||||
*/
|
||||
@NotNull(message = "capacity 处置设备能力不能为空")
|
||||
@NotNull(message = "capacity 处置设备能力不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||
@Valid
|
||||
private List<AddCapacityInfo> capacity;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.dispose.pojo.dto.protocol.device.manager;
|
||||
|
||||
import com.dispose.pojo.dto.protocol.base.ValidGroups;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
@ -24,7 +25,7 @@ public class AddDeviceReq {
|
|||
/**
|
||||
* The Items.
|
||||
*/
|
||||
@NotNull(message = "items 设备列表不能为空")
|
||||
@NotNull(message = "items 设备列表不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||
@Valid
|
||||
private List<AddDeviceInfo> items;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.dispose.pojo.dto.protocol.device.manager;
|
||||
|
||||
import com.dispose.pojo.dto.protocol.base.BaseIdResp;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Add device ret.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"ipAddr", "ipPort", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddDeviceRet extends BaseIdResp {
|
||||
/**
|
||||
* The Ip addr.
|
||||
*/
|
||||
private String ipAddr;
|
||||
|
||||
/**
|
||||
* The Ip port.
|
||||
*/
|
||||
private String ipPort;
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
package com.dispose.pojo.dto.protocol.device.manager;
|
||||
|
||||
import com.dispose.pojo.dto.protocol.base.BaseIdResp;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -14,15 +11,13 @@ import java.util.List;
|
|||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@JsonPropertyOrder({"ipAddr", "ipPort", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddDeviceRsp extends BaseIdResp {
|
||||
public class AddDeviceRsp {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
private List<AddDeviceInfo> items;
|
||||
private List<AddDeviceRet> items;
|
||||
|
||||
/**
|
||||
* Instantiates a new Add device rsp.
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.dispose.pojo.dto.protocol.device.manager;
|
||||
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.dispose.pojo.dto.protocol.base.BaseIdResp;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Del device rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"id", "devStatus", "status", "message"})
|
||||
public class DelDeviceRsp extends BaseIdResp {
|
||||
/**
|
||||
* The Dev status.
|
||||
*/
|
||||
private ObjectStatus devStatus;
|
||||
}
|
|
@ -12,5 +12,19 @@ import java.util.List;
|
|||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
public interface DisposeDeviceManagerService {
|
||||
/**
|
||||
* Add dispose device list.
|
||||
*
|
||||
* @param devs the devs
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> addDisposeDevice(List<DisposeDevice> devs);
|
||||
|
||||
/**
|
||||
* Remove dispose device list.
|
||||
*
|
||||
* @param ids the ids
|
||||
* @return the list
|
||||
*/
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> removeDisposeDevice(List<Long> ids);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.ObjectStatus;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
|
@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -38,13 +40,41 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
|
|||
List<MulReturnType<ErrorCode, DisposeDevice>> rspList = new ArrayList<>();
|
||||
|
||||
devs.forEach(v -> {
|
||||
MulReturnType<ErrorCode, Long> ret = disposeDeviceManager.addDisposeDevice(v);
|
||||
|
||||
v.setId(ret.getSecondParam());
|
||||
rspList.add(new MulReturnType<>(ret.getFirstParam(), v));
|
||||
MulReturnType<ErrorCode, Long> ret = null;
|
||||
try {
|
||||
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));
|
||||
}
|
||||
});
|
||||
|
||||
//AddDeviceRsp rspInfo = AddDeviceRsp.b
|
||||
return rspList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove dispose device list.
|
||||
*
|
||||
* @param ids the ids
|
||||
* @return the list
|
||||
*/
|
||||
@Override
|
||||
public List<MulReturnType<ErrorCode, DisposeDevice>> removeDisposeDevice(List<Long> ids) {
|
||||
List<MulReturnType<ErrorCode, DisposeDevice>> rspList = new ArrayList<>();
|
||||
|
||||
for (Long v : ids) {
|
||||
DisposeDevice dev = new DisposeDevice();
|
||||
|
||||
|
||||
MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v,
|
||||
ObjectStatus.DELETED);
|
||||
|
||||
dev.setId(v);
|
||||
dev.setStatus(ret.getSecondParam());
|
||||
|
||||
rspList.add(new MulReturnType<>(ret.getFirstParam(), dev));
|
||||
}
|
||||
|
||||
return rspList;
|
||||
}
|
||||
|
|
|
@ -59,12 +59,12 @@
|
|||
VALUES (#{ipAddr}, #{ipPort}, #{deviceType},
|
||||
#{areaCode}, #{deviceName}, #{manufacturer},
|
||||
#{model}, #{version}, #{userName}, #{password}, #{urlPath}, #{urlType}, #{readme},
|
||||
${@com.dispose.common.ObjectStatus@NORMAL.getCode()})
|
||||
${@com.dispose.common.ObjectStatus@NORMAL.getValue()})
|
||||
</insert>
|
||||
|
||||
<update id="delDisposeDevice">
|
||||
UPDATE dispose_device
|
||||
SET status = ${@com.dispose.common.ObjectStatus@DELETED.getCode()}
|
||||
SET status = ${@com.dispose.common.ObjectStatus@DELETED.getValue()}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
|
@ -90,14 +90,14 @@
|
|||
<update id="disableDisposeDevice">
|
||||
UPDATE
|
||||
dispose_device
|
||||
SET status = ${@com.dispose.common.ObjectStatus@DISABLED.getCode()}
|
||||
SET status = ${@com.dispose.common.ObjectStatus@DISABLED.getValue()}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="availableDisposeDevice">
|
||||
UPDATE
|
||||
dispose_device
|
||||
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getCode()}
|
||||
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
</mapper>
|
|
@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The type Dispose device mapper test.
|
||||
|
@ -106,43 +107,47 @@ public class DisposeDeviceMapperTest {
|
|||
*/
|
||||
@Test
|
||||
public void b1_addNewDisposeDevice() throws JsonProcessingException {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", "");
|
||||
|
||||
String beforeVer = dev.getVersion();
|
||||
if (dev.getVersion().equals("B5.2.27.7")) {
|
||||
dev.setVersion("5.7.13");
|
||||
} else {
|
||||
dev.setVersion("B5.2.27.7");
|
||||
}
|
||||
|
||||
DisposeDevice newDev = DisposeDevice.builder()
|
||||
.id(dev.getId())
|
||||
.ipAddr("10.88.77.15")
|
||||
.ipPort("")
|
||||
.deviceType(DisposeDeviceType.DPTECH_UMC)
|
||||
.areaCode(0)
|
||||
.deviceName("中移杭研实验室迪普清洗设备")
|
||||
.manufacturer("DPTech")
|
||||
.model("UMC")
|
||||
.version(dev.getVersion())
|
||||
.userName("admin")
|
||||
.password("UMCAdministrator")
|
||||
.urlPath("UMC/service/AbnormalFlowCleaningService")
|
||||
.urlType(HttpType.HTTP)
|
||||
.readme("实验室测试设备")
|
||||
.status(ObjectStatus.NORMAL)
|
||||
.build();
|
||||
|
||||
Assert.assertEquals(1, disposeDeviceMapper.upgradeDisposeDevice(newDev));
|
||||
Assert.assertNotNull(dev.getId());
|
||||
Assert.assertNotEquals(disposeDeviceMapper.getDeviceById(newDev.getId()).getVersion(), beforeVer);
|
||||
try {
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
devList.forEach(v -> {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort());
|
||||
|
||||
String beforeVer = dev.getVersion();
|
||||
if (dev.getVersion().equals("B5.2.27.7")) {
|
||||
dev.setVersion("5.7.13");
|
||||
} else {
|
||||
dev.setVersion("B5.2.27.7");
|
||||
}
|
||||
|
||||
DisposeDevice newDev = DisposeDevice.builder()
|
||||
.id(dev.getId())
|
||||
.ipAddr("10.88.77.15")
|
||||
.ipPort("")
|
||||
.deviceType(DisposeDeviceType.DPTECH_UMC)
|
||||
.areaCode(0)
|
||||
.deviceName("中移杭研实验室迪普清洗设备")
|
||||
.manufacturer("DPTech")
|
||||
.model("UMC")
|
||||
.version(dev.getVersion())
|
||||
.userName("admin")
|
||||
.password("UMCAdministrator")
|
||||
.urlPath("UMC/service/AbnormalFlowCleaningService")
|
||||
.urlType(HttpType.HTTP)
|
||||
.readme("实验室测试设备")
|
||||
.status(ObjectStatus.NORMAL)
|
||||
.build();
|
||||
|
||||
Assert.assertEquals(1, disposeDeviceMapper.upgradeDisposeDevice(newDev));
|
||||
Assert.assertNotNull(dev.getId());
|
||||
Assert.assertNotEquals(disposeDeviceMapper.getDeviceById(newDev.getId()).getVersion(), beforeVer);
|
||||
try {
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
devList = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
|
||||
}
|
||||
|
||||
|
@ -152,18 +157,18 @@ public class DisposeDeviceMapperTest {
|
|||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void d1_getDeviceByAddress() throws JsonProcessingException {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", "");
|
||||
Assert.assertNotNull(dev);
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
public void d1_getDeviceByAddress() {
|
||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
|
||||
dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.88", "18080");
|
||||
Assert.assertNotNull(dev);
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
devList.forEach(v -> {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort());
|
||||
Assert.assertNotNull(dev);
|
||||
|
||||
dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", "80");
|
||||
Assert.assertNull(dev);
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(null));
|
||||
dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(),
|
||||
String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1));
|
||||
|
||||
Assert.assertNull(dev);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue