REM:
1. 增加获取设备信息接口
This commit is contained in:
HuangXin 2020-08-06 16:04:52 +08:00
parent f288e01197
commit a9f1704389
10 changed files with 260 additions and 6 deletions

View File

@ -2,21 +2,29 @@ package com.dispose.controller;
import com.dispose.common.CommonEnumHandler;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType;
import com.dispose.common.IpAddrType;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
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.AddCapacityInfo;
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.DeviceInfoRsp;
import com.dispose.pojo.dto.protocol.device.manager.GetDeviceDetail;
import com.dispose.pojo.dto.protocol.device.manager.GetDeviceReq;
import com.dispose.pojo.dto.protocol.device.manager.GetDeviceRsp;
import com.dispose.pojo.entity.DisposeCapacity;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeDeviceManagerService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -61,7 +69,7 @@ public class DisposeDeviceManagerController {
DisposeDevice dev = DisposeDevice.builder()
.ipAddr(v.getIpAddr())
.ipPort(v.getIpPort())
.deviceType(v.getDeviceType())
.deviceType(CommonEnumHandler.codeOf(DisposeDeviceType.class, v.getDeviceType()))
.areaCode(v.getAreaCode())
.deviceName(v.getDeviceName())
.manufacturer(v.getManufacturer())
@ -70,7 +78,7 @@ public class DisposeDeviceManagerController {
.userName(v.getUserName())
.password(v.getPassword())
.urlPath(v.getUrlPath())
.urlType(v.getUrlType())
.urlType(CommonEnumHandler.codeOf(HttpType.class, v.getUrlType()))
.readme(v.getReadme())
.build();
@ -205,4 +213,60 @@ public class DisposeDeviceManagerController {
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
@PostMapping("/device_list")
@ResponseBody
@ApiOperation("删除处置能力节点")
public ProtocolRespDTO<? extends BaseRespStatus> getAllDisposeDevice(
@Validated(ValidGroups.ProtocolCommonValid.class)
@RequestBody ProtocolReqDTO<GetDeviceReq> mr) {
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> ret =
disposeDeviceManagerService.getAllDisposeDevice(mr.getMsgContent().getStartPage(),
Integer.parseInt(mr.getMsgContent().getPageSize()));
GetDeviceRsp rspInfo = new GetDeviceRsp();
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum());
rspInfo.setPageSize(ret.getFirstParam().getPageSize());
rspInfo.setTotalItems((int)ret.getFirstParam().getTotal());
rspInfo.setTotalPages(ret.getFirstParam().getPages());
ret.getSecondParam().forEach(v -> {
GetDeviceDetail devInfo = new GetDeviceDetail();
devInfo.setId(v.getId().toString());
devInfo.setIpAddr(v.getIpAddr());
devInfo.setIpPort(v.getIpPort());
devInfo.setDeviceType(v.getDeviceType().getValue());
devInfo.setAreaCode(v.getAreaCode());
devInfo.setDeviceName(v.getDeviceName());
devInfo.setManufacturer(v.getManufacturer());
devInfo.setModel(v.getModel());
devInfo.setVersion(v.getVersion());
devInfo.setUrlType(v.getUrlType().getValue());
devInfo.setReadme(v.getReadme());
devInfo.setDevStatus(v.getStatus().getValue());
List<AddCapacityInfo> capList = new ArrayList<>();
v.getDevCapacity().forEach(k -> {
AddCapacityInfo capInfo = AddCapacityInfo.builder()
.capacityType(k.getCapacityType().getValue())
.objectType(k.getObjectType().getValue())
.ipType(k.getIpType().getValue())
.protectIp(k.getProtectIp())
.build();
capList.add(capInfo);
});
devInfo.setCapacity(capList);
rspInfo.getItems().add(devInfo);
});
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
}

View File

@ -4,8 +4,10 @@ import com.dispose.common.ErrorCode;
import com.dispose.common.ObjectStatus;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.github.pagehelper.PageInfo;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
* The interface Dispose device manager.
@ -45,4 +47,14 @@ public interface DisposeDeviceManager {
* @return the mul return type
*/
MulReturnType<ErrorCode, ObjectStatus> changeDisposeDeviceStatus(Long id, ObjectStatus status);
/**
* Gets all devices.
*
* @param startPage the start page
* @param pageSize the page size
* @return the all devices
*/
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDevices(Integer startPage,
Integer pageSize);
}

View File

@ -8,12 +8,15 @@ import com.dispose.mapper.DisposeCapacityMapper;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
@ -196,4 +199,26 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
}
}
}
/**
* Gets all devices.
*
* @param startPage the start page
* @param pageSize the page size
* @return the all devices
*/
@Override
public MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDevices(Integer startPage,
Integer pageSize) {
// 设置分页信息
PageHelper.startPage(startPage, pageSize);
// 获取分页数据
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
// 获取分页信息
PageInfo<DisposeDevice> pageInfo = new PageInfo<>(devList);
return new MulReturnType<>(pageInfo, devList);
}
}

View File

@ -1,6 +1,7 @@
package com.dispose.pojo.dto.protocol.device.manager;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -15,6 +16,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({"capacityType", "objectType", "ipType", "protectIp"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddCapacityInfo {
/**

View File

@ -1,9 +1,8 @@
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 com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -23,6 +22,8 @@ import java.util.List;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({"ipAddr", "ipPort", "deviceType", "areaCode", "deviceName", "manufacturer",
"model", "version", "userName", "password", "urlPath", "urlType", "readme", "capacity"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddDeviceInfo {
/**
@ -40,7 +41,7 @@ public class AddDeviceInfo {
/**
* The Device type.
*/
private DisposeDeviceType deviceType;
private Integer deviceType;
/**
* The Area code.
@ -87,7 +88,7 @@ public class AddDeviceInfo {
* The Url type.
*/
@NotNull(message = "urlType URL类型不能为空", groups = ValidGroups.AddDeviceValid.class)
private HttpType urlType;
private Integer urlType;
/**
* The Readme.

View File

@ -0,0 +1,30 @@
package com.dispose.pojo.dto.protocol.device.manager;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* The type Get device detail.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@JsonPropertyOrder({"id", "ipAddr", "ipPort", "deviceType", "areaCode", "deviceName", "manufacturer",
"model", "version", "userName", "password", "urlPath", "urlType", "readme", "capacity", "status"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetDeviceDetail extends AddDeviceInfo {
/**
* The Id.
*/
private String id;
/**
* The Status.
*/
private Integer devStatus;
}

View File

@ -0,0 +1,40 @@
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;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.PositiveOrZero;
/**
* The type Get device req.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetDeviceReq {
/**
* The Start page.
*/
@PositiveOrZero(message = "startPage 字段值不能小于0", groups = ValidGroups.ProtocolCommonValid.class)
@NotNull(message = "startPage 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
private Integer startPage;
/**
* The Page size.
*/
@Pattern(regexp = "^([1-5]0)$",
message = "pageSize 字段取值为 {10, 20, 30, 40, 50}",
groups = ValidGroups.ProtocolCommonValid.class)
@NotNull(message = "pageSize 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
private String pageSize;
}

View File

@ -0,0 +1,54 @@
package com.dispose.pojo.dto.protocol.device.manager;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
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 java.util.ArrayList;
import java.util.List;
/**
* The type Get device rsp.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@JsonPropertyOrder({"curPageNumber", "pageSize", "totalItems", "totalPages", "status", "message", "items"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetDeviceRsp extends BaseRespStatus {
/**
* The Cur page number.
*/
private Integer curPageNumber;
/**
* The Page size.
*/
private Integer pageSize;
/**
* The Total items.
*/
private Integer totalItems;
/**
* The Total pages.
*/
private Integer totalPages;
/**
* The Items.
*/
private List<GetDeviceDetail> items;
/**
* Instantiates a new Get device rsp.
*/
public GetDeviceRsp() {
this.items = new ArrayList<>();
}
}

View File

@ -3,6 +3,7 @@ package com.dispose.service;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.github.pagehelper.PageInfo;
import java.util.List;
@ -36,4 +37,15 @@ public interface DisposeDeviceManagerService {
* @return the list
*/
List<MulReturnType<ErrorCode, DisposeDevice>> upgradeDisposeDevice(List<DisposeDevice> devs);
/**
* Gets all dispose device.
*
* @param startPage the start page
* @param pageSize the page size
* @return the all dispose device
*/
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDisposeDevice(Integer startPage,
Integer pageSize);
}

View File

@ -6,6 +6,7 @@ import com.dispose.manager.DisposeDeviceManager;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeDeviceManagerService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -100,4 +101,17 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
return rspList;
}
/**
* Gets all dispose device.
*
* @param startPage the start page
* @param pageSize the page size
* @return the all dispose device
*/
@Override
public MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> getAllDisposeDevice(Integer startPage,
Integer pageSize) {
return disposeDeviceManager.getAllDevices(startPage, pageSize);
}
}