Commit 8546da38 by xmh

<fix> caffeine 版本号

<fix> 更好地获取鉴权信息
<feat> 运维服务注册时的默认IP以及注册信息打印
<fix> 数据概览数据无任务id情况
1 parent 9392020c
......@@ -112,7 +112,6 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -13,6 +13,7 @@ import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -31,7 +32,7 @@ public class CacheUtils {
@Resource
private OpsClient opsClient;
@LocalCache(value = "task_map", duration = 1)
@LocalCache(value = "task_map", duration = 20, timeunit = TimeUnit.SECONDS)
public synchronized Map<String, Task> getTaskMap() {
JsonMessageUtil.JsonMessage<List<Task>> response = null;
try {
......
......@@ -23,10 +23,7 @@ import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
......@@ -134,12 +131,12 @@ public class AuthorizationFilter implements GlobalFilter {
if (StringUtils.isNotEmpty(token)) {
return token;
}
token = headers.getFirst("authorization");
token = Optional.ofNullable(headers.getFirst("Authorization")).orElse(headers.getFirst("authorization"));
if (StringUtils.isNotBlank(token)) {
return token;
}
MultiValueMap<String, String> queryParams = request.getQueryParams();
token = queryParams.getFirst("authorization");
token = Optional.ofNullable(queryParams.getFirst("Authorization")).orElse(queryParams.getFirst("authorization"));
if (StringUtils.isNotBlank(token)) {
return token;
}
......@@ -148,7 +145,7 @@ public class AuthorizationFilter implements GlobalFilter {
return token;
}
MultiValueMap<String, HttpCookie> cookies = request.getCookies();
HttpCookie auc = cookies.getFirst("authorization");
HttpCookie auc = Optional.ofNullable(cookies.getFirst("Authorization")).orElse(cookies.getFirst("authorization"));
if (auc != null) {
token = auc.getValue();
if (StringUtils.isNotBlank(token)) {
......
......@@ -3,10 +3,12 @@ package com.viontech.fanxing.ops.controller.main;
import com.viontech.fanxing.commons.base.BaseController;
import com.viontech.fanxing.ops.model.OpsServer;
import com.viontech.fanxing.ops.service.main.OpsServerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* .
......@@ -23,7 +25,10 @@ public class OpsController {
private OpsServerService opsServerService;
@PostMapping("register")
public Object register(@RequestBody OpsServer opsServer) {
public Object register(@RequestBody OpsServer opsServer, HttpServletRequest httpServletRequest) {
if (StringUtils.isEmpty(opsServer.getIp())) {
opsServer.setIp(httpServletRequest.getRemoteHost());
}
opsServerService.register(opsServer);
return BaseController.success();
}
......
......@@ -19,4 +19,12 @@ public class OpsServer {
private String name;
private Long lastHeartBeat;
@Override
public String toString() {
return "OpsServer{" +
"ip='" + ip + '\'' +
", port=" + port +
", name='" + name + '\'' +
'}';
}
}
......@@ -31,6 +31,7 @@ public class OpsServerService {
private RedissonClient redissonClient;
public void register(OpsServer opsServer) {
log.info("收到运维注册信息:{}",opsServer.toString());
opsServer.setLastHeartBeat(System.currentTimeMillis());
addOrUpdateOpsServer(opsServer);
}
......
......@@ -87,6 +87,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
List<Traffic> traffic = trafficMapper.selectByExample(trafficExample);
for (Traffic t : traffic) {
if (t.getTaskId() != null) {
DataOverViewModel dov = resultMap.computeIfAbsent(t.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
......@@ -95,6 +96,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
});
dov.setTraffic(t.getCount());
}
}
FlowEventExample flowEventExample = new FlowEventExample();
FlowEventExample.Criteria criteria1 = flowEventExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
......@@ -106,6 +108,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
flowEventExample.setOrderByClause("task_id");
List<FlowEvent> flowEvents = flowEventService.getMapper().selectByExample(flowEventExample);
for (FlowEvent f : flowEvents) {
if (f.getTaskId() != null) {
DataOverViewModel dov = resultMap.computeIfAbsent(f.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
......@@ -114,6 +117,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
});
dov.setFlow(f.getCount());
}
}
BehaviorExample behaviorExample = new BehaviorExample();
BehaviorExample.Criteria criteria2 = behaviorExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
......@@ -125,6 +129,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
behaviorExample.setOrderByClause("task_id");
List<Behavior> behaviors = behaviorService.getMapper().selectByExample(behaviorExample);
for (Behavior b : behaviors) {
if (b.getTaskId() != null) {
DataOverViewModel dov = resultMap.computeIfAbsent(b.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
......@@ -133,6 +138,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
});
dov.setBehavior(b.getCount());
}
}
Collection<DataOverViewModel> values = resultMap.values();
List<DataOverViewModel> collect = values.stream().filter(x -> x.getTaskId() != null).sorted(Comparator.comparingLong(DataOverViewModel::getTaskId)).collect(Collectors.toList());
List<List<DataOverViewModel>> partition = ListUtil.partition(collect, pageSize);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!