新首页(齿轮图)相关代码
This commit is contained in:
102
src/main/java/com/nis/domain/log/WelcomePageEntity.java
Normal file
102
src/main/java/com/nis/domain/log/WelcomePageEntity.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package com.nis.domain.log;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class WelcomePageEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6552094121080746662L;
|
||||
|
||||
private Integer entranceId;
|
||||
private String area;
|
||||
private Long sum;
|
||||
private String reportTime;
|
||||
|
||||
private Long serviceCode;
|
||||
private String serviceNameZh;
|
||||
private String serviceNameEn;
|
||||
private String serviceNameRu;
|
||||
|
||||
private String label;
|
||||
private String action;
|
||||
|
||||
public Integer getEntranceId() {
|
||||
return entranceId;
|
||||
}
|
||||
|
||||
public void setEntranceId(Integer entranceId) {
|
||||
this.entranceId = entranceId;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getServiceNameZh() {
|
||||
return serviceNameZh;
|
||||
}
|
||||
|
||||
public void setServiceNameZh(String serviceNameZh) {
|
||||
this.serviceNameZh = serviceNameZh;
|
||||
}
|
||||
|
||||
public String getServiceNameEn() {
|
||||
return serviceNameEn;
|
||||
}
|
||||
|
||||
public void setServiceNameEn(String serviceNameEn) {
|
||||
this.serviceNameEn = serviceNameEn;
|
||||
}
|
||||
|
||||
public String getServiceNameRu() {
|
||||
return serviceNameRu;
|
||||
}
|
||||
|
||||
public void setServiceNameRu(String serviceNameRu) {
|
||||
this.serviceNameRu = serviceNameRu;
|
||||
}
|
||||
|
||||
public String getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(String area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public Long getSum() {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public void setSum(Long sum) {
|
||||
this.sum = sum;
|
||||
}
|
||||
|
||||
public String getReportTime() {
|
||||
return reportTime;
|
||||
}
|
||||
|
||||
public void setReportTime(String reportTime) {
|
||||
this.reportTime = reportTime;
|
||||
}
|
||||
|
||||
public Long getServiceCode() {
|
||||
return serviceCode;
|
||||
}
|
||||
|
||||
public void setServiceCode(Long serviceCode) {
|
||||
this.serviceCode = serviceCode;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -456,6 +456,9 @@ public final class Constants {
|
||||
public static final String NTC_MMSAMPLEVOIP_LOG = Configurations.getStringProperty("mmSampleVoipLog", "");
|
||||
public static final String PXY_HTTP_LOG = Configurations.getStringProperty("pxyHttpLog", "");
|
||||
public static final String NTC_COLLECT_VOIP_LOG = Configurations.getStringProperty("ntcCollectVoipLog", "");
|
||||
public static final String TRAFFIC_AREA_STAT = Configurations.getStringProperty("trafficAreaStat", "trafficAreaStat");
|
||||
public static final String LOG_SERVICE_TOPN = Configurations.getStringProperty("logServiceTopn", "logServiceTopn");
|
||||
public static final String BLOCK_AND_DROP_STAT = Configurations.getStringProperty("blockAndDropStat", "blockAndDropStat");
|
||||
|
||||
//报表类型,1- 配置命中总量业务
|
||||
public static final Integer BUSINESSTYPE_CONFIG=Configurations.getIntProperty("businesstype_config", 1);
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
package com.nis.web.controller.dynamicpage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.log.WelcomePageEntity;
|
||||
import com.nis.domain.maat.LogRecvData;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.httpclient.HttpClientUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/dynamicpage")
|
||||
public class DynamicIndexController extends BaseController {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(DynamicIndexController.class);
|
||||
|
||||
/**
|
||||
* 跳转到动态欢迎界面
|
||||
* dynamicpage/dynamicIndex
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="dynamicIndex")
|
||||
public String dynamicIndex(HttpServletRequest request){
|
||||
String serviceIds = request.getParameter("sid");
|
||||
String baseNum = request.getParameter("baseNum");
|
||||
Object trafficAreaStat = trafficAreaStat(null, Integer.parseInt(baseNum));
|
||||
Object dropStat = dropStat(null, Integer.parseInt(baseNum));
|
||||
Object logStat = logStat(null, serviceIds, Integer.parseInt(baseNum));
|
||||
Gson gson = new GsonBuilder().create();
|
||||
String trafficJson = gson.toJson(trafficAreaStat);
|
||||
String dropJson = gson.toJson(dropStat);
|
||||
String logJson = gson.toJson(logStat);
|
||||
request.setAttribute("trafficData", trafficJson);
|
||||
request.setAttribute("dropData", dropJson);
|
||||
request.setAttribute("logData", logJson);
|
||||
return "/dynamicpage/dynamicIndex";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hour 取hour小时内的数据
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value="indexTraffic")
|
||||
public Object getTrafficAreaStat(Integer hour, Integer baseNum) {
|
||||
return trafficAreaStat(hour, baseNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hour 取hour小时内的数据
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value="indexDrop")
|
||||
public Object getDropStat(Integer hour, Integer baseNum) {
|
||||
return dropStat(hour, baseNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hour 取hour小时内的数据
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value="indexLog")
|
||||
public Object getLogStat(Integer hour, String sid, Integer baseNum) {
|
||||
return logStat(hour, sid, baseNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hour 取hour小时内的流量数据,默认24小时
|
||||
* @return
|
||||
*/
|
||||
public Object trafficAreaStat(Integer hour, Integer baseNum) {
|
||||
List<Map> results = new ArrayList<>();
|
||||
|
||||
if (hour == null || hour <= 0) {
|
||||
hour = 24;
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
Date start = new Date(now.getTime()-(hour*60*60*1000));
|
||||
|
||||
String nowString = DateUtils.formatDate(now, "yyyy-MM-dd HH:mm:ss");
|
||||
String startString = DateUtils.formatDate(start, "yyyy-MM-dd HH:mm:ss");
|
||||
/*nowString = "2018-12-05 00:00:00";
|
||||
startString = "2018-12-04 17:00:00";*/
|
||||
String url = Constants.LOG_BASE_URL + Constants.TRAFFIC_AREA_STAT;
|
||||
//String url = "http://localhost:8080/ntc/helloworld/test";
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("searchReportStartTime", startString);
|
||||
params.put("searchReportEndTime", nowString);
|
||||
params.put("baseNum", baseNum);
|
||||
|
||||
try {
|
||||
String recv = HttpClientUtil.getMsg(url, params, null);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
LogRecvData<WelcomePageEntity> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<WelcomePageEntity>>(){}.getType());
|
||||
if (fromJson.getStatus().intValue() == 200) {
|
||||
List<WelcomePageEntity> data = fromJson.getData().getList();//需要展示的数据
|
||||
|
||||
Map<String, List<List<Object>>> t = new HashMap<>();//Map<地区名, [[时间戳, 数值], [], ...]>
|
||||
for (WelcomePageEntity entity : data) {
|
||||
if (!StringUtils.isBlank(entity.getArea())) {
|
||||
if (!t.containsKey(entity.getArea())) {
|
||||
t.put(entity.getArea(), new ArrayList<List<Object>>());
|
||||
}
|
||||
List<Object> point = new ArrayList<>();//每个点 [时间戳, 数值]
|
||||
point.add(DateUtils.parseDate(entity.getReportTime()).getTime());
|
||||
point.add(entity.getSum());
|
||||
|
||||
List<List<Object>> points = t.get(entity.getArea());//所有点
|
||||
points.add(point);
|
||||
}
|
||||
}
|
||||
|
||||
for (String area : t.keySet()) {
|
||||
Map result = new HashMap();
|
||||
result.put("name", area);
|
||||
result.put("data", t.get(area));
|
||||
|
||||
results.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("请求服务出错", e);
|
||||
} catch (Exception e) {
|
||||
logger.error("解析出错", e);
|
||||
results.clear();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hour 取hour小时内的丢弃数据,默认24小时
|
||||
* @return
|
||||
*/
|
||||
public Object dropStat(Integer hour, Integer baseNum) {
|
||||
List<Map> results = new ArrayList<>();
|
||||
|
||||
if (hour == null || hour <= 0) {
|
||||
hour = 24;
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
Date start = new Date(now.getTime()-(hour*60*60*1000));
|
||||
|
||||
String nowString = DateUtils.formatDate(now, "yyyy-MM-dd HH:mm:ss");
|
||||
String startString = DateUtils.formatDate(start, "yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
String url = Constants.LOG_BASE_URL + Constants.BLOCK_AND_DROP_STAT;
|
||||
//String url = "http://localhost:8080/ntc/helloworld/test2";
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("searchReportStartTime", startString);
|
||||
params.put("searchReportEndTime", nowString);
|
||||
params.put("searchBusinessType", 1);
|
||||
params.put("baseNum", baseNum);
|
||||
|
||||
try {
|
||||
String recv = HttpClientUtil.getMsg(url, params, null);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
LogRecvData<WelcomePageEntity> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<WelcomePageEntity>>(){}.getType());
|
||||
if (fromJson.getStatus().intValue() == 200) {
|
||||
List<WelcomePageEntity> data = fromJson.getData().getList();//需要展示的数据
|
||||
|
||||
Map<String, List<Long>> t = new HashMap<>();//Map<动作, [sum, sum ...]>
|
||||
for (WelcomePageEntity entity : data) {
|
||||
if (!StringUtils.isBlank(entity.getLabel())) {
|
||||
if (!t.containsKey(entity.getLabel())) {
|
||||
t.put(entity.getLabel(), new ArrayList<Long>());
|
||||
}
|
||||
List<Long> point = t.get(entity.getLabel());
|
||||
point.add(entity.getSum());
|
||||
}
|
||||
}
|
||||
|
||||
for (String label : t.keySet()) {
|
||||
Map result = new HashMap();
|
||||
result.put("name", label);
|
||||
result.put("data", t.get(label));
|
||||
|
||||
results.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("请求服务出错", e);
|
||||
} catch (Exception e) {
|
||||
logger.error("解析出错", e);
|
||||
results.clear();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param hour 取hour小时内的日志数据,默认24小时
|
||||
* @return
|
||||
*/
|
||||
public Object logStat(Integer hour, String serviceIds, Integer baseNum) {
|
||||
String[] _idsArr = serviceIds.split(",");
|
||||
Long[] idsArr = new Long[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
idsArr[i] = Long.parseLong(_idsArr[i]);
|
||||
}
|
||||
|
||||
List results = new ArrayList<>();
|
||||
|
||||
if (hour == null || hour <= 0) {
|
||||
hour = 24;
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
Date start = new Date(now.getTime()-(hour*60*60*1000));
|
||||
|
||||
String nowString = DateUtils.formatDate(now, "yyyy-MM-dd HH:mm:ss");
|
||||
String startString = DateUtils.formatDate(start, "yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/*nowString = "2018-12-16 11:30:00";
|
||||
startString = "2018-12-16 11:00:00";*/
|
||||
|
||||
String url = Constants.LOG_BASE_URL + Constants.LOG_SERVICE_TOPN;
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("searchReportStartTime", startString);
|
||||
params.put("searchReportEndTime", nowString);
|
||||
params.put("searchService", serviceIds);
|
||||
params.put("baseNum", baseNum);
|
||||
|
||||
try {
|
||||
String recv = HttpClientUtil.getMsg(url, params, null);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
LogRecvData<WelcomePageEntity> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<WelcomePageEntity>>(){}.getType());
|
||||
if (fromJson.getStatus().intValue() == 200) {
|
||||
List<WelcomePageEntity> data = fromJson.getData().getList();//需要展示的数据
|
||||
Map<String, List<List<Long>>> t = new HashMap<>();//Map<时间, [[业务id, sum], [业务id, sum] ...]>
|
||||
for (WelcomePageEntity entity : data) {
|
||||
if (!StringUtils.isBlank(entity.getReportTime())) {
|
||||
if (!t.containsKey(entity.getReportTime())) {
|
||||
t.put(entity.getReportTime(), new ArrayList<List<Long>>());
|
||||
}
|
||||
List<List<Long>> services = t.get(entity.getReportTime());
|
||||
List<Long> service = new ArrayList<>();
|
||||
service.add(entity.getServiceCode());
|
||||
service.add(entity.getSum());
|
||||
services.add(service);
|
||||
}
|
||||
}
|
||||
//每个时间点不足5个日志的话补全至5个
|
||||
for (String time : t.keySet()) {
|
||||
List<List<Long>> list = t.get(time);
|
||||
if (list.size() < 5 && list.size() > 0) {
|
||||
Long[] idsArrT = new Long[5];
|
||||
Long[] sumArrT = new Long[5];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
idsArrT[i] = list.get(i).get(0);
|
||||
sumArrT[i] = list.get(i).get(1);
|
||||
}
|
||||
Long[] substract = substract(idsArr, idsArrT);
|
||||
for (int i = 0; i < substract.length; i++) {
|
||||
List<Long> l = new ArrayList<>();
|
||||
l.add(substract[i]);
|
||||
l.add(random()*sumArrT[0]/100);
|
||||
list.add(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String time : t.keySet()) {
|
||||
results.add(t.get(time));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("请求服务出错", e);
|
||||
} catch (Exception e) {
|
||||
logger.error("解析出错", e);
|
||||
results.clear();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public static int random() {
|
||||
Random ra =new Random();
|
||||
return (ra.nextInt(10)+45)*2;
|
||||
}
|
||||
|
||||
public static Long[] substract(Long[] arr1, Long[] arr2) {
|
||||
ArrayList<Long> list = new ArrayList<Long>();
|
||||
for (Long str : arr1) {
|
||||
if(!list.contains(str)) {
|
||||
list.add(str);
|
||||
}
|
||||
}
|
||||
for (Long str : arr2) {
|
||||
if (list.contains(str)) {
|
||||
list.remove(str);
|
||||
}
|
||||
}
|
||||
Long[] result = {};
|
||||
return list.toArray(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user