去掉统计图无用类

This commit is contained in:
zhanghongqing
2018-07-11 19:05:08 +08:00
parent 34892e5fd8
commit b2d6524279
2 changed files with 300 additions and 188 deletions

View File

@@ -0,0 +1,300 @@
package com.nis.web.controller.dashboard;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
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.util.CodeDicUtils;
import com.nis.util.StringUtil;
import com.nis.util.httpclient.HttpClientUtil;
import com.nis.web.controller.BaseController;
import com.nis.web.dao.dashboard.codedic.CodeResult;
@SuppressWarnings("rawtypes")
@Controller
@RequestMapping(value = "${adminPath}/dashboard")
public class DashboardController extends BaseController{
@RequestMapping(value="logChart")
public String logChart(){
bsList();
systemChart("Google Chrome");
return "/dashboard/dashBoardIndex";
}
/**
* 活跃IP TOP10
*/
@RequestMapping(value="ipActive")
@ResponseBody
public List ipActive(){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List list = new ArrayList();
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficIpActive");
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (ArrayList) fromJsonList.get("data");
logger.info("活跃IP数据"+fromJsonList);
return list;
} catch (Exception e) {
e.printStackTrace();
logger.error("活跃ip错误"+e);
}
return list;
}
/**
* 协议统计
*/
@SuppressWarnings("unchecked")
@RequestMapping(value="protocol")
@ResponseBody
public List protocolChart(){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<Map> list = new ArrayList<Map>();
List<Map> resultList = new ArrayList<Map>();
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficProtocol");
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (List<Map>) fromJsonList.get("data");
//标签集合
List<CodeResult> codeList = CodeDicUtils.getCodeList("protocolCode");
//将数字替换为标签文字
for (Map map : list) {
Double value1 = Double.parseDouble(map.get("protoType").toString());
for (CodeResult code : codeList) {
Double value2 = Double.valueOf(code.getCode());
if(value1.equals(value2)){
map.put("protoType", code.getItem());
break;
}
}
resultList.add(map);
}
logger.info("协议统计"+fromJsonList);
return resultList;
} catch (Exception e) {
e.printStackTrace();
logger.error("协议统计错误"+e);
}
return resultList;
}
/**
* app流量分析
*/
@RequestMapping(value="app")
@ResponseBody
public List appChart(){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<Map> list = new ArrayList<Map>();
List<Map> resultList = new ArrayList<Map>();
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficApp");
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (List<Map>) fromJsonList.get("data");
//标签集合
List<CodeResult> codeList = CodeDicUtils.getCodeList("appCode");
//将数字替换为标签文字
for (Map map : list) {
Double value1 = Double.parseDouble(map.get("appType").toString());
for (CodeResult code : codeList) {
Double value2 = Double.valueOf(code.getCode());
if(value1.equals(value2)){
map.put("appType", code.getItem());
break;
}
}
resultList.add(map);
}
logger.info("app流量分析"+fromJsonList);
return resultList;
} catch (Exception e) {
e.printStackTrace();
logger.error("app流量分析错误"+e);
}
return resultList;
}
/**
* 终端用户-操作系统列表
*/
@RequestMapping(value="osList")
@ResponseBody
public List osList(){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<Map> list = new ArrayList<Map>();
List<Map> resultList = new ArrayList<Map>();
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficOsList");
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (List<Map>) fromJsonList.get("data");
//标签集合
List<CodeResult> codeList = CodeDicUtils.getCodeList("osCode");
//将数字替换为标签文字
for (Map map : list) {
Double value1 = Double.parseDouble(map.get("osType").toString());
for (CodeResult code : codeList) {
Double value2 = Double.valueOf(code.getCode());
if(value1.equals(value2)){
map.put("osType", code.getItem());
break;
}
}
resultList.add(map);
}
logger.info("终端用户-获取操作系统列表"+fromJsonList);
return resultList;
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取操作系统列表错误"+e);
}
return resultList;
}
/**
* 终端用户-指定操作系统下浏览器分类流量统计
*/
@RequestMapping(value="browserChart")
@ResponseBody
public List browserChart(@RequestParam("osType") String osType){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<Map> list = new ArrayList<Map>();
List<Map> resultList = new ArrayList<Map>();
//标签集合
List<CodeResult> codeList1 = CodeDicUtils.getCodeList("osCode");
//将标签文字转为数字
Integer os=null;
for (CodeResult codeResult : codeList1) {
if(osType.equalsIgnoreCase(codeResult.getItem())){
os=Integer.parseInt(codeResult.getCode());
break;
}
}
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficBrowserChart?osType="+os);
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (List<Map>) fromJsonList.get("data");
//标签集合
List<CodeResult> codeList2 = CodeDicUtils.getCodeList("browserCode");
//将数字替换为标签文字
if(null!=list&&!list.isEmpty()){
for (Map map : list) {
Double value1 = Double.parseDouble(map.get("bsType").toString());
for (CodeResult code : codeList2) {
Double value2 = Double.valueOf(code.getCode());
if(value1.equals(value2)){
map.put("bsType", code.getItem());
break;
}
}
resultList.add(map);
}
}
logger.info("终端用户-获取操作系统下浏览器类型"+fromJsonList);
return resultList;
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取操作系统下浏览器类型错误"+e);
}
return resultList;
}
/**
* 终端用户-浏览器列表
*/
@RequestMapping(value="bsList")
@ResponseBody
public List bsList(){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<Map> list = new ArrayList<Map>();
List<Map> resultList = new ArrayList<Map>();
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficBsList");
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (List<Map>) fromJsonList.get("data");
//标签集合
List<CodeResult> codeList = CodeDicUtils.getCodeList("browserCode");
//将数字替换为标签文字
for (Map map : list) {
Double value1 = Double.parseDouble(map.get("bsType").toString());
for (CodeResult code : codeList) {
Double value2 = Double.valueOf(code.getCode());
if(value1.equals(value2)){
map.put("bsType", code.getItem());
break;
}
}
resultList.add(map);
}
logger.info("终端用户-获取浏览器列表"+fromJsonList);
return resultList;
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取浏览器列表错误"+e);
}
return resultList;
}
/**
* 终端用户-指定操作系统下浏览器分类流量统计
*/
@RequestMapping(value="systemChart")
@ResponseBody
public List systemChart(@RequestParam("bsType") String bsType){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<Map> list = new ArrayList<Map>();
List<Map> resultList = new ArrayList<Map>();
//标签集合
List<CodeResult> codeList1 = CodeDicUtils.getCodeList("bsCode");
//将标签文字转为数字
Integer bs=null;
for (CodeResult codeResult : codeList1) {
if(bsType.equalsIgnoreCase(codeResult.getItem())){
bs=Integer.parseInt(codeResult.getCode());
break;
}
}
try {
String string = HttpClientUtil.get("http://10.0.6.101:8080/gwall/service/log/v1/trafficBrowserChart?bsType="+bs);
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (List<Map>) fromJsonList.get("data");
//标签集合
List<CodeResult> codeList2 = CodeDicUtils.getCodeList("osCode");
//将数字替换为标签文字
if(null!=list&&!list.isEmpty()){
for (Map map : list) {
Double value1 = Double.parseDouble(map.get("osType").toString());
for (CodeResult code : codeList2) {
Double value2 = Double.valueOf(code.getCode());
if(value1.equals(value2)){
map.put("osType", code.getItem());
break;
}
}
resultList.add(map);
}
}
logger.info("终端用户-获取浏览器下操作系统类型"+fromJsonList);
return resultList;
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取浏览器下操作系统类型错误"+e);
}
return resultList;
}
}

View File

@@ -1,188 +0,0 @@
package com.nis.web.controller.dashboard;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.google.gson.Gson;
import com.nis.util.JsonMapper;
import com.nis.web.controller.BaseController;
import com.nis.web.service.dashboard.DashboardService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
@SuppressWarnings({ "rawtypes", "unchecked" })
@RestController
@RequestMapping(value = "${servicePath}/log/v1")
@Api(value = "DashboardServiceController", description = "首页图表基本服务接口")
public class DashboardServiceController extends BaseController{
@Autowired
public DashboardService dashboardService;
/**
* 协议统计
*/
@RequestMapping(value="trafficProtocol", method = RequestMethod.GET)
@ApiOperation(value = "协议统计", httpMethod = "GET", notes = "对应协议统计实时统计查询服务。")
public String trafficProtocol(){
dashboardService.systemList();
Map map = new HashMap();
try {
List<Map> ipActiveChart = dashboardService.protocolChart();
if (ipActiveChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveChart);
List<HashMap> list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,
HashMap.class);
map.put("data", list);
logger.info(list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
return JsonMapper.toJsonString(map);
}
/**
* 活跃IP TOP10
*/
@RequestMapping(value = "trafficIpActive", method = RequestMethod.GET)
@ApiOperation(value = "活跃IP统计", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。")
public String trafficIpActive(/*Model model, HttpServletRequest request,
HttpServletResponse response*/) {
Map map = new LinkedHashMap();
try {
List<LinkedHashMap> ipActiveChart = dashboardService.ipActiveChart();
if (ipActiveChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveChart);
ArrayList<LinkedHashMap> list = (ArrayList<LinkedHashMap>) JsonMapper.fromJsonList(jsonString,
LinkedHashMap.class);
map.put("data", list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
String jsonString = JsonMapper.toJsonString(map);
return jsonString;
}
/**
* app流量分析 TOP10
*/
@RequestMapping(value = "trafficApp", method = RequestMethod.GET)
@ApiOperation(value = "app流量分析统计", httpMethod = "GET", notes = "对应app流量分析实时统计查询服务。")
public String trafficApp(/*Model model, HttpServletRequest request,
HttpServletResponse response*/) {
Map map = new HashMap();
try {
List<Map> appChart = dashboardService.appChart();
if (appChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(appChart);
List<HashMap> list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,
HashMap.class);
map.put("data", list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
return JsonMapper.toJsonString(map);
}
@RequestMapping(value = "trafficOsList", method = RequestMethod.GET)
@ApiOperation(value = "操作系统流量分析统计", httpMethod = "GET", notes = "对应终端用户的操作系统列表显示")
public String trafficOsList(/*,Model model, HttpServletRequest request,
HttpServletResponse response*/) {
Map map = new HashMap();
try {
List<Map> osChart = dashboardService.systemList();
if (osChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(osChart);
List<HashMap> list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,
HashMap.class);
map.put("data", list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
return JsonMapper.toJsonString(map);
}
@RequestMapping(value = "trafficBrowserChart", method = RequestMethod.GET)
@ApiOperation(value = "操作系统下浏览器流量分析统计", httpMethod = "GET", notes = "对应终端用户某个操作系统的浏览器分类统计显示")
public String trafficBrowserChart(Integer osType/*,Model model, HttpServletRequest request,
HttpServletResponse response*/) {
Map map = new HashMap();
try {
List<Map> osChart = dashboardService.getBrowserBySystem(osType);
if (osChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(osChart);
List<HashMap> list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,
HashMap.class);
map.put("data", list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
return JsonMapper.toJsonString(map);
}
@RequestMapping(value = "trafficBsList", method = RequestMethod.GET)
@ApiOperation(value = "浏览器流量分析统计", httpMethod = "GET", notes = "对应终端用户的浏览器列表显示")
public String trafficBsList(/*,Model model, HttpServletRequest request,
HttpServletResponse response*/) {
Map map = new HashMap();
try {
List<Map> bsChart = dashboardService.browserList();
if (bsChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(bsChart);
List<HashMap> list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,
HashMap.class);
map.put("data", list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
return JsonMapper.toJsonString(map);
}
@RequestMapping(value = "trafficSystemChart", method = RequestMethod.GET)
@ApiOperation(value = "浏览器下操作系统流量分析统计", httpMethod = "GET", notes = "对应终端用户某个浏览器的操作系统分类统计显示")
public String trafficSystemChart(Integer bsType/*,Model model, HttpServletRequest request,
HttpServletResponse response*/) {
Map map = new HashMap();
try {
List<Map> bsChart = dashboardService.getSystemBybrowser(bsType);
if (bsChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(bsChart);
List<HashMap> list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,
HashMap.class);
map.put("data", list);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
return JsonMapper.toJsonString(map);
}
}