OCT
REM: 1. 增加获取能力节点列表接口 2. 增加获取能力节点详细信息接口 3. 关闭token认证接口
This commit is contained in:
parent
188a49ae99
commit
b5fe65f728
|
@ -25,6 +25,20 @@ public class ConstValue {
|
||||||
public static final int AUTH_LOGIN = 10;
|
public static final int AUTH_LOGIN = 10;
|
||||||
public static final int AUTH_LOGOUT = 11;
|
public static final int AUTH_LOGOUT = 11;
|
||||||
|
|
||||||
|
public static final int ADD_DISPOSE_POINT = 100;
|
||||||
|
public static final int MOD_DISPOSE_POINT = 101;
|
||||||
|
public static final int DEL_DISPOSE_POINT = 102;
|
||||||
|
|
||||||
|
public static final int GET_DISPOSE_POINT_VERSION = 200;
|
||||||
|
public static final int GET_DISPOSE_POINT_DEV_INFO = 201;
|
||||||
|
public static final int GET_DISPOSE_POINT_LINK_STATUS = 202;
|
||||||
|
public static final int GET_DISPOSE_POINT_CATACITY = 203;
|
||||||
|
public static final int GET_DISPOSE_POINT_PROTECT_IP = 204;
|
||||||
|
|
||||||
|
public static final int GET_DISPOSE_POINT_LIST = 209;
|
||||||
|
public static final int GET_DISPOSE_POINT_DETAILS = 210;
|
||||||
|
|
||||||
|
|
||||||
public static final int START_DISPOSE_CMD = 400;
|
public static final int START_DISPOSE_CMD = 400;
|
||||||
public static final int STOP_DISPOSE_CMD = 401;
|
public static final int STOP_DISPOSE_CMD = 401;
|
||||||
public static final int STOP_DISPOSE_CMD_BY_IP = 402;
|
public static final int STOP_DISPOSE_CMD_BY_IP = 402;
|
||||||
|
@ -56,4 +70,22 @@ public class ConstValue {
|
||||||
public static final int LOCKED = 1;
|
public static final int LOCKED = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DisposeDeviceCapacity {
|
||||||
|
CLEANUP (0, "清洗能力"),
|
||||||
|
HIDEPEND (1, "高防能力"),
|
||||||
|
BLACKHOOL (2, "黑洞能力"),
|
||||||
|
DETECIVE (3, "检测能力");
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
private String readme;
|
||||||
|
|
||||||
|
DisposeDeviceCapacity(int code, String readme) {
|
||||||
|
this.code = code;
|
||||||
|
this.readme = readme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {return this.code;}
|
||||||
|
|
||||||
|
public String getReadme() {return this.readme;}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,10 @@ public class AuthController {
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ApiOperation("获取版本信息")
|
@ApiOperation("登录")
|
||||||
@ReqDec
|
@ReqDec
|
||||||
@Builder
|
@Builder
|
||||||
public ProtocolResp UserLogin(@RequestBody(required = true) ProtocolDTO mr,
|
public ProtocolResp userLogin(@RequestBody(required = true) ProtocolDTO mr,
|
||||||
@RequestHeader HttpHeaders headers) {
|
@RequestHeader HttpHeaders headers) {
|
||||||
String msgCtx = "";
|
String msgCtx = "";
|
||||||
ErrorCode err = ErrorCode.ERR_OK;
|
ErrorCode err = ErrorCode.ERR_OK;
|
||||||
|
@ -46,6 +46,7 @@ public class AuthController {
|
||||||
log.info("请求token: {}", headers.get("Authorization"));
|
log.info("请求token: {}", headers.get("Authorization"));
|
||||||
log.info("请求参数 {}", mr);
|
log.info("请求参数 {}", mr);
|
||||||
|
|
||||||
|
|
||||||
if(mr == null) {
|
if(mr == null) {
|
||||||
err = ErrorCode.ERR_PARAMS;
|
err = ErrorCode.ERR_PARAMS;
|
||||||
return ProtocolResp.result(err, -1, msgCtx);
|
return ProtocolResp.result(err, -1, msgCtx);
|
||||||
|
@ -67,11 +68,9 @@ public class AuthController {
|
||||||
|
|
||||||
err = loginService.authTokenCheck(token);
|
err = loginService.authTokenCheck(token);
|
||||||
|
|
||||||
if(err == ErrorCode.ERR_OK) {
|
EnumMap<ErrorCode, String> loginMap = userLogout(mr, token);
|
||||||
EnumMap<ErrorCode, String> loginMap = userLogout(mr, token);
|
err = loginMap.keySet().iterator().next();
|
||||||
err = loginMap.keySet().iterator().next();
|
msgCtx = loginMap.get(err);
|
||||||
msgCtx = loginMap.get(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
err = ErrorCode.ERR_UNKNOWNCMD;
|
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.cmcc.hy.phoenix.controller;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||||
|
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||||
|
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.vo.ProtocolResp;
|
||||||
|
import com.cmcc.hy.phoenix.service.LoginService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.cmcc.hy.phoenix.common.ErrorCode.ERR_OK;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/handle")
|
||||||
|
@Slf4j
|
||||||
|
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||||
|
@Component
|
||||||
|
public class DispointPointController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LoginService loginService;
|
||||||
|
|
||||||
|
@PostMapping("/manager")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("节点管理")
|
||||||
|
@ReqDec
|
||||||
|
@Builder
|
||||||
|
public ProtocolResp disposePointManager(@RequestBody(required = true) ProtocolDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers){
|
||||||
|
// 存放返回信息Json字符串
|
||||||
|
String msgCtx = "";
|
||||||
|
ErrorCode err = ERR_OK;
|
||||||
|
|
||||||
|
log.info("请求token: {}", headers.get("Authorization"));
|
||||||
|
log.info("请求参数 {}", mr);
|
||||||
|
|
||||||
|
// 参数检测
|
||||||
|
if (mr == null) {
|
||||||
|
err = ErrorCode.ERR_PARAMS;
|
||||||
|
return ProtocolResp.result(err, -1, msgCtx);
|
||||||
|
} else if (mr.IsRequestTimeout()) {
|
||||||
|
err = ErrorCode.ERR_REQTIMEOUT;
|
||||||
|
} else {
|
||||||
|
//try{
|
||||||
|
// 获取 Token
|
||||||
|
String token = Objects.
|
||||||
|
requireNonNull(headers.get("Authorization"))
|
||||||
|
.get(0).replaceFirst("Bearer ", "");
|
||||||
|
|
||||||
|
// 判断Head头是否存在
|
||||||
|
if (headers.get("Authorization") == null) {
|
||||||
|
err = ErrorCode.ERR_MISSAUTHHEAD;
|
||||||
|
} else if ((err = loginService.authTokenCheck(token)) == ERR_OK) {
|
||||||
|
// Token 正确则处理业务
|
||||||
|
switch (mr.getCmdId()) {
|
||||||
|
case ConstValue.ProtocolCmdId.ADD_DISPOSE_POINT:
|
||||||
|
break;
|
||||||
|
case ConstValue.ProtocolCmdId.DEL_DISPOSE_POINT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// } catch (JsonProcessingException | NoSuchAlgorithmException ex) {
|
||||||
|
// log.error(ex.getMessage());
|
||||||
|
// err = ErrorCode.ERR_EXCEPTION;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProtocolResp.result(err, mr.getCmdId(), msgCtx);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,213 @@
|
||||||
|
package com.cmcc.hy.phoenix.controller;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||||
|
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||||
|
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DisposeDeviceInfo;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.vo.*;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DisposeCapacityInfo;
|
||||||
|
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
||||||
|
import com.cmcc.hy.phoenix.service.LoginService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
|
||||||
|
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.cmcc.hy.phoenix.common.ErrorCode.ERR_OK;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/handle")
|
||||||
|
@Slf4j
|
||||||
|
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||||
|
@Component
|
||||||
|
public class DisposeInfoController {
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LoginService loginService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DisposeDeviceManager deviceManager;
|
||||||
|
|
||||||
|
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
|
||||||
|
|
||||||
|
@PostMapping("/information")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("获取节点信息")
|
||||||
|
@ReqDec
|
||||||
|
@Builder
|
||||||
|
public ProtocolResp disposeInfo(@RequestBody(required = true) ProtocolDTO mr,
|
||||||
|
@RequestHeader HttpHeaders headers){
|
||||||
|
// 存放返回信息Json字符串
|
||||||
|
String msgCtx = "";
|
||||||
|
ErrorCode err = ERR_OK;
|
||||||
|
|
||||||
|
log.info("请求token: {}", headers.get("Authorization"));
|
||||||
|
log.info("请求参数 {}", mr);
|
||||||
|
|
||||||
|
// 参数检测
|
||||||
|
if (mr == null) {
|
||||||
|
err = ErrorCode.ERR_PARAMS;
|
||||||
|
return ProtocolResp.result(err, -1, msgCtx);
|
||||||
|
} else if (mr.IsRequestTimeout()) {
|
||||||
|
err = ErrorCode.ERR_REQTIMEOUT;
|
||||||
|
} else {
|
||||||
|
try{
|
||||||
|
// 获取 Token
|
||||||
|
String token = Objects
|
||||||
|
.requireNonNull(headers.get("Authorization"))
|
||||||
|
.get(0).replaceFirst("Bearer ", "");
|
||||||
|
|
||||||
|
// 判断Head头是否存在
|
||||||
|
if (headers.get("Authorization") == null) {
|
||||||
|
err = ErrorCode.ERR_MISSAUTHHEAD;
|
||||||
|
} else if ((err = loginService.authTokenCheck(token)) == ERR_OK) {
|
||||||
|
// Token 正确则处理业务
|
||||||
|
switch (mr.getCmdId()) {
|
||||||
|
case ConstValue.ProtocolCmdId.GET_DISPOSE_POINT_CATACITY:
|
||||||
|
msgCtx = getDevCapInfo(mr);
|
||||||
|
break;
|
||||||
|
case ConstValue.ProtocolCmdId.GET_DISPOSE_POINT_LIST:
|
||||||
|
msgCtx = getDisposeDevicesList();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ConstValue.ProtocolCmdId.GET_DISPOSE_POINT_DETAILS:
|
||||||
|
msgCtx = getDisposeDevicesDetails(mr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JsonProcessingException ex) {
|
||||||
|
log.error(ex.getMessage());
|
||||||
|
ex.printStackTrace();
|
||||||
|
err = ErrorCode.ERR_EXCEPTION;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
err = ErrorCode.ERR_EXCEPTION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err != ERR_OK) {
|
||||||
|
msgCtx = err.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProtocolResp.result(err, mr.getCmdId(), msgCtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDisposeDevicesList() throws IOException {
|
||||||
|
DisposeDevicesResp rspInfo = new DisposeDevicesResp(new ArrayList<>());
|
||||||
|
|
||||||
|
Map<String, DisposeDevice> devs = deviceManager.getAllDisposeDevs();
|
||||||
|
|
||||||
|
devs.forEach((k, v) -> {
|
||||||
|
rspInfo.getItems().add(DisposeDeviceInfo.builder()
|
||||||
|
.id(String.valueOf(v.getId()))
|
||||||
|
.type(v.getType())
|
||||||
|
.name(v.getName())
|
||||||
|
.ip(v.getIpv4()).build());
|
||||||
|
});
|
||||||
|
|
||||||
|
String[] filterItems = new String[] {"areaCode", "readme", "capacity"};
|
||||||
|
filterProvider.addFilter("DeviceInfo", //添加过滤器名称
|
||||||
|
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||||
|
|
||||||
|
objectMapper.setFilterProvider(filterProvider);
|
||||||
|
|
||||||
|
return objectMapper.writeValueAsString(rspInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDisposeDevicesDetails(ProtocolDTO mr) throws JsonProcessingException {
|
||||||
|
DisposeDevicesResp rspInfo = new DisposeDevicesResp(new ArrayList<>());
|
||||||
|
|
||||||
|
GetInfoById reqInfo = objectMapper.readValue(mr.getMsgContent(), GetInfoById.class);
|
||||||
|
|
||||||
|
Map<String, DisposeDevice> devs = deviceManager.getAllDisposeDevs();
|
||||||
|
|
||||||
|
devs.forEach((k, v) -> {
|
||||||
|
if(Arrays.stream(reqInfo.getId()).anyMatch(str -> str.equals(String.valueOf(v.getId())))) {
|
||||||
|
List<DeviceCapacityInfo> devCaps = new ArrayList<>();
|
||||||
|
|
||||||
|
v.getDevCaps().forEach(m -> {
|
||||||
|
DeviceCapacityInfo devCapInfo = DeviceCapacityInfo.builder()
|
||||||
|
.capacity(m.getCapacity())
|
||||||
|
.tolFlowCapacity(m.getTolFlowCapacity())
|
||||||
|
.build();
|
||||||
|
if(m.getCapacity() == ConstValue.DisposeDeviceCapacity.CLEANUP.getCode()) {
|
||||||
|
devCapInfo.setDisposeIp(v.getDisposeIp().toArray(new String[v.getDisposeIp().size()]));
|
||||||
|
}
|
||||||
|
devCaps.add(devCapInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
rspInfo.getItems().add(DisposeDeviceInfo.builder()
|
||||||
|
.id(String.valueOf(v.getId()))
|
||||||
|
.type(v.getType())
|
||||||
|
.name(v.getName())
|
||||||
|
.ip(v.getIpv4())
|
||||||
|
.areaCode(v.getAreaCode())
|
||||||
|
.readme(v.getReadme())
|
||||||
|
.capacity(devCaps)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String[] filterItems = new String[] {};
|
||||||
|
filterProvider.addFilter("DeviceInfo", //添加过滤器名称
|
||||||
|
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||||
|
filterProvider.addFilter("DeviceCapacityInfo", //添加过滤器名称
|
||||||
|
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||||
|
|
||||||
|
objectMapper.setFilterProvider(filterProvider);
|
||||||
|
|
||||||
|
return objectMapper.writeValueAsString(rspInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDevCapInfo(ProtocolDTO mr) throws JsonProcessingException {
|
||||||
|
|
||||||
|
DisposeCapacityResp rspInfo = new DisposeCapacityResp(new ArrayList<>());
|
||||||
|
|
||||||
|
GetInfoById reqInfo = objectMapper.readValue(mr.getMsgContent(), GetInfoById.class);
|
||||||
|
|
||||||
|
for (String v: reqInfo.getId()
|
||||||
|
) {
|
||||||
|
|
||||||
|
List<DeviceCapacityInfo> capInfo = deviceManager.getDeviceCapacityInfoByDeviceId(Long.valueOf(v));
|
||||||
|
|
||||||
|
DisposeCapacityInfo ret = DisposeCapacityInfo.builder()
|
||||||
|
.id(v)
|
||||||
|
.capacity(capInfo).build();
|
||||||
|
|
||||||
|
rspInfo.getItems().add(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] filterItems = new String[] {"disposeIp"};
|
||||||
|
filterProvider.addFilter("DeviceCapacityInfo", //添加过滤器名称
|
||||||
|
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||||
|
|
||||||
|
objectMapper.setFilterProvider(filterProvider);
|
||||||
|
|
||||||
|
return objectMapper.writeValueAsString(rspInfo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.cmcc.hy.phoenix.mapper;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||||
|
import tk.mybatis.mapper.common.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DeviceCapacityMapper extends Mapper<DisposeDevice> {
|
||||||
|
List<DeviceCapacity> getDeviceCapacityByDeviceId(Long id);
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.cmcc.hy.phoenix.mapper;
|
package com.cmcc.hy.phoenix.mapper;
|
||||||
|
|
||||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||||
import tk.mybatis.mapper.common.IdsMapper;
|
import tk.mybatis.mapper.common.IdsMapper;
|
||||||
import tk.mybatis.mapper.common.Mapper;
|
import tk.mybatis.mapper.common.Mapper;
|
||||||
import tk.mybatis.mapper.common.MySqlMapper;
|
import tk.mybatis.mapper.common.MySqlMapper;
|
||||||
|
@ -21,6 +22,7 @@ public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
|
||||||
List<DisposeDevice> getAllDisposeDevice();
|
List<DisposeDevice> getAllDisposeDevice();
|
||||||
|
|
||||||
DisposeDevice getDisposeDisposeDevByIp(String ipv4);
|
DisposeDevice getDisposeDisposeDevByIp(String ipv4);
|
||||||
|
List<DeviceCapacityInfo> getDisposeDisposeDevById(Long devId);
|
||||||
|
|
||||||
void addNewDisposeDevice(DisposeDevice dev);
|
void addNewDisposeDevice(DisposeDevice dev);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.cmcc.hy.phoenix.pojo.po;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@JsonFilter("DeviceCapacityInfo")
|
||||||
|
public class DeviceCapacityInfo {
|
||||||
|
private int capacity;
|
||||||
|
@Nullable
|
||||||
|
private int tolFlowCapacity;
|
||||||
|
private int usedCapacity;
|
||||||
|
private String[] disposeIp;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.cmcc.hy.phoenix.pojo.po;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class DisposeCapacityInfo {
|
||||||
|
private String id;
|
||||||
|
private List<DeviceCapacityInfo> capacity;
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.cmcc.hy.phoenix.pojo.po;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@JsonFilter("DeviceInfo")
|
||||||
|
public class DisposeDeviceInfo {
|
||||||
|
private String id;
|
||||||
|
private int type;
|
||||||
|
private String name;
|
||||||
|
private String ip;
|
||||||
|
private int areaCode;
|
||||||
|
@Nullable
|
||||||
|
private String readme;
|
||||||
|
private List<DeviceCapacityInfo> capacity;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.cmcc.hy.phoenix.pojo.vo;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DisposeCapacityInfo;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Builder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class DisposeCapacityResp {
|
||||||
|
private List<DisposeCapacityInfo> items;
|
||||||
|
|
||||||
|
public DisposeCapacityResp(List<DisposeCapacityInfo> ret) {
|
||||||
|
this.items = ret;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.cmcc.hy.phoenix.pojo.vo;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DisposeDeviceInfo;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class DisposeDevicesResp {
|
||||||
|
List<DisposeDeviceInfo> items;
|
||||||
|
|
||||||
|
public DisposeDevicesResp(List<DisposeDeviceInfo> devInfos){
|
||||||
|
this.items = devInfos;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.cmcc.hy.phoenix.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class GetInfoById {
|
||||||
|
private String[] id;
|
||||||
|
}
|
|
@ -2,8 +2,10 @@ package com.cmcc.hy.phoenix.service;
|
||||||
|
|
||||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface DisposeDeviceManager {
|
public interface DisposeDeviceManager {
|
||||||
|
@ -12,4 +14,7 @@ public interface DisposeDeviceManager {
|
||||||
|
|
||||||
Map<String, DisposeDevice> getAllDisposeDevs();
|
Map<String, DisposeDevice> getAllDisposeDevs();
|
||||||
|
|
||||||
|
List<DeviceCapacityInfo> getDeviceCapacityInfoById(Long id);
|
||||||
|
|
||||||
|
List<DeviceCapacityInfo> getDeviceCapacityInfoByDeviceId(Long deviceId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,20 @@ package com.cmcc.hy.phoenix.service.impl;
|
||||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||||
import com.cmcc.hy.phoenix.dispose.DeviceRouter;
|
import com.cmcc.hy.phoenix.dispose.DeviceRouter;
|
||||||
import com.cmcc.hy.phoenix.dispose.DisposeProcess;
|
import com.cmcc.hy.phoenix.dispose.DisposeProcess;
|
||||||
|
import com.cmcc.hy.phoenix.mapper.DeviceCapacityMapper;
|
||||||
import com.cmcc.hy.phoenix.mapper.DisposeDeviceMapper;
|
import com.cmcc.hy.phoenix.mapper.DisposeDeviceMapper;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||||
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||||
import com.dptech.umc.DetectionObjectDataForService;
|
import com.dptech.umc.DetectionObjectDataForService;
|
||||||
|
import com.dptech.umc.ProtectionObjectDataForService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
|
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -37,8 +41,36 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceMapper disposeDeviceMapper;
|
private DisposeDeviceMapper disposeDeviceMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DeviceCapacityMapper deviceCapacityMapper;
|
||||||
|
|
||||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceCapacityInfo> getDeviceCapacityInfoByDeviceId(Long deviceId) {
|
||||||
|
List<DeviceCapacityInfo> devList = new ArrayList<>();
|
||||||
|
|
||||||
|
List<DeviceCapacity> devCaps = deviceCapacityMapper.getDeviceCapacityByDeviceId(deviceId);
|
||||||
|
|
||||||
|
devCaps.forEach(v -> {
|
||||||
|
devList.add(DeviceCapacityInfo.builder()
|
||||||
|
.capacity(v.getCapacity())
|
||||||
|
.tolFlowCapacity(v.getTolFlowCapacity())
|
||||||
|
.usedCapacity(0)
|
||||||
|
.disposeIp(new String[]{}).build());
|
||||||
|
});
|
||||||
|
|
||||||
|
return devList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceCapacityInfo> getDeviceCapacityInfoById(Long id) {
|
||||||
|
|
||||||
|
List<DeviceCapacityInfo> dev = disposeDeviceMapper.getDisposeDisposeDevById(id);
|
||||||
|
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumMap<ErrorCode, Long> addNewDisposeDevice(DisposeDevice dev) {
|
public EnumMap<ErrorCode, Long> addNewDisposeDevice(DisposeDevice dev) {
|
||||||
TransactionStatus transactionStatus = null;
|
TransactionStatus transactionStatus = null;
|
||||||
|
@ -82,6 +114,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
List<DisposeDevice> dp = disposeDeviceMapper.getAllDisposeDevice();
|
List<DisposeDevice> dp = disposeDeviceMapper.getAllDisposeDevice();
|
||||||
|
|
||||||
dp.forEach(v -> {
|
dp.forEach(v -> {
|
||||||
|
v.setDisposeIp(getDisposeIpFromDevice(v.getType(), v.getIpv4()));
|
||||||
disposeDevMap.put(v.getIpv4(), v);
|
disposeDevMap.put(v.getIpv4(), v);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -107,7 +140,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<DetectionObjectDataForService> detDevs = dptechUMC.getAllDetectionObject();
|
List<ProtectionObjectDataForService> detDevs = dptechUMC.getAllProtectionObject();
|
||||||
|
|
||||||
List<String> ipList = new ArrayList<>();
|
List<String> ipList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -115,13 +148,13 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
String ipSegment = v.getIpSegment().getValue();
|
String ipSegment = v.getIpSegment().getValue();
|
||||||
|
|
||||||
if(ipSegment.length() > 0) {
|
if(ipSegment.length() > 0) {
|
||||||
log.info("Ip: {}", v.getIpSegment().getValue());
|
ipList.addAll(Arrays.asList(v.getIpSegment().getValue().replaceAll("\\d{1,}_", "").split(",")));
|
||||||
ipList.addAll(Arrays.asList(v.getIpSegment().getValue().split(",")));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return ipList;
|
return ipList;
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
|
log.info(ex.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ public class LoginServiceImpl implements LoginService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode authTokenCheck(String token) {
|
public ErrorCode authTokenCheck(String token) {
|
||||||
return userAccountService.verifyToken(token);
|
return ErrorCode.ERR_OK;
|
||||||
|
//return userAccountService.verifyToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class UserAccountCacheServiceImpl implements UserAccountCacheService {
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
if(!findRet.isPresent()) {
|
if(!findRet.isPresent()) {
|
||||||
return ErrorCode.ERR_USERNOTFOUND;
|
return ErrorCode.ERR_LOGOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserAccountCache uc = findRet.get();
|
UserAccountCache uc = findRet.get();
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?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.cmcc.hy.phoenix.mapper.DeviceCapacityMapper">
|
||||||
|
<!-- mapper xml文件中只编写复杂逻辑的SQL SQL单独拿出来写,与代码解耦,SQL的熟练编写是每个研发必备的技能 -->
|
||||||
|
<select id="getDeviceCapacityByDeviceId" resultType="com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity">
|
||||||
|
SELECT * FROM device_capacity WHERE deviceId = #{id}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -70,6 +70,15 @@
|
||||||
d.ipv4 = #{ipv4}
|
d.ipv4 = #{ipv4}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getDisposeDisposeDevById" resultType="com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo">
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
device_capacity
|
||||||
|
WHERE
|
||||||
|
deviceId = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id" parameterType="com.cmcc.hy.phoenix.pojo.entity.DisposeDevice">
|
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id" parameterType="com.cmcc.hy.phoenix.pojo.entity.DisposeDevice">
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
dispose_device(ipv4, ipv6, type,
|
dispose_device(ipv4, ipv6, type,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.cmcc.hy.phoenix.common.ConstValue;
|
||||||
import com.cmcc.hy.phoenix.dispose.DeviceRouter;
|
import com.cmcc.hy.phoenix.dispose.DeviceRouter;
|
||||||
import com.cmcc.hy.phoenix.dispose.DisposeProcess;
|
import com.cmcc.hy.phoenix.dispose.DisposeProcess;
|
||||||
import com.dptech.umc.DetectionObjectDataForService;
|
import com.dptech.umc.DetectionObjectDataForService;
|
||||||
|
import com.dptech.umc.ProtectionObjectDataForService;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -41,14 +42,14 @@ public class DPTechInterfaceTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAllDetectDevices(){
|
public void getAllProtectObjects(){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DisposeProcess dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
DisposeProcess dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
|
|
||||||
String detDevs = dp.getDetectionDevices();
|
List<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject();
|
||||||
|
|
||||||
Assert.assertNotEquals(detDevs.length(), 0);
|
Assert.assertNotEquals(proObjs.size(), 0);
|
||||||
|
|
||||||
} catch (Exception ex){
|
} catch (Exception ex){
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.cmcc.hy.phoenix.mapper;
|
||||||
|
|
||||||
|
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@Slf4j
|
||||||
|
public class DeviceCapacityMapperTest {
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DeviceCapacityMapper deviceCapacityMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUserByNameUsedDefaultMapper() throws JsonProcessingException {
|
||||||
|
List<DeviceCapacity> devCaps = deviceCapacityMapper.getDeviceCapacityByDeviceId(1L);
|
||||||
|
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devCaps));
|
||||||
|
|
||||||
|
Assert.assertNotEquals(devCaps.size(), 0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.cmcc.hy.phoenix.mapper;
|
||||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||||
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||||
|
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -58,6 +59,15 @@ public class DisposeDeviceMapperTest {
|
||||||
Assert.assertNotNull(dev);
|
Assert.assertNotNull(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDisposeDisposeDevById() throws JsonProcessingException {
|
||||||
|
List<DeviceCapacityInfo> dev = disposeDeviceMapper.getDisposeDisposeDevById(1L);
|
||||||
|
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||||
|
|
||||||
|
Assert.assertNotEquals(dev.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addNewDisposeDevice() throws JsonProcessingException {
|
public void addNewDisposeDevice() throws JsonProcessingException {
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class DisposeServiceTest {
|
||||||
|
|
||||||
devCaps.add(new DeviceCapacity(0, 2048));
|
devCaps.add(new DeviceCapacity(0, 2048));
|
||||||
devCaps.add(new DeviceCapacity(2));
|
devCaps.add(new DeviceCapacity(2));
|
||||||
|
devCaps.add(new DeviceCapacity(3));
|
||||||
|
|
||||||
EnumMap<ErrorCode, Long> retMap = dispDevMgr.addNewDisposeDevice(dev);
|
EnumMap<ErrorCode, Long> retMap = dispDevMgr.addNewDisposeDevice(dev);
|
||||||
|
|
||||||
|
@ -61,4 +62,11 @@ public class DisposeServiceTest {
|
||||||
|
|
||||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ipSegmentProcess(){
|
||||||
|
String ip = "1_192.168.3.2-192.168.3.5,2_192.168.5.2-192.168.5.10";
|
||||||
|
|
||||||
|
log.info(ip.replaceAll("\\d{1,}_", ""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue