代码块。

@RequestMapping(value="/record/makeNow",method=RequestMethod.POST)
	@ApiOperation(value = "获取当前格节点记录",notes="获取当前格节点记录")
	public List Now(){
		
		List nodeList = networkNodeService.findAllNode();
		List recordList = new ArrayList();
		
		List nameList = new ArrayList();
		nameList.add("接口 $1 入访流量");
		nameList.add("接口 $1 Up/Down状态"); 
		nameList.add("接口 $1 出访流量");
		
		String token = zabbixService.get_token(zabbix_url);
		
		Date now = new Date();
		
		for (NetworkNodeInformation networkNodeInformation : nodeList) {
			if (null!=networkNodeInformation.getIp()&&!"".equals(networkNodeInformation.getIp())) {
				
				String hostid = zabbixService.get_hostid(networkNodeInformation.getIp(),token,zabbix_url);
				String rs = zabbixService.get_itemid_detail(hostid, token, zabbix_url);
				JSONObject result = JSONObject.fromObject(rs);
				JSONArray arr = JSONArray.fromObject(result.get("result"));
				
				
				List portList = networkNodeService.findPortsByNodeId(networkNodeInformation.getNodeId());
				for (NetworkNodePort networkNodePort : portList) {
					String pattern = ".*[A-Za-z]"+networkNodePort.getPort()+"]$";
					Map map = new HashMap();
					
					
					
					for (Object object : arr) {
						JSONObject information = JSONObject.fromObject(object);	
						String key = information.getString("key_");
						String name = information.getString("name");
						
						if (Pattern.matches(pattern, key)&&nameList.contains(name)) {
							map.put(name, information);
						}
					}
					
					
					if (map.size()>0) {
						NodeTrafficRecord record = new NodeTrafficRecord();
						record.setExportFlow(Long.parseLong(map.get("接口 $1 出访流量").getString("lastvalue")));
						record.setInletFlow(Long.parseLong(map.get("接口 $1 入访流量").getString("lastvalue")));
						record.setState(Integer.parseInt(map.get("接口 $1 Up/Down状态").getString("lastvalue")));
						record.setPortId(networkNodePort.getPortId());
						record.setRecordTime(now);
						recordList.add(record);
					}
					
					
				}
			}			
		}
		
		
		
		
		
		
		return networkNodeService.addNodeTrafficRecordList(recordList);
		
	}
	
	@RequestMapping(value="/record/getNodeNow",method=RequestMethod.GET)
	@ApiOperation(value = "获取全部节点最新记录",notes="获取全部节点最新记录")
	public List getNodeNow(){
		List recordList = networkNodeService.findAllRecordNow();
		List list = new ArrayList();
		BigDecimal b = new BigDecimal(1024*1024);
		for (NodeTrafficRecord record : recordList) {
			//out
			JSONObject entry = new JSONObject();
			NetworkNodePort port = record.getPort();
			NetworkNodeInformation source = port.getNode();
			NetworkNodeInformation dest = port.getDest();
			
			JSONArray coords = new JSONArray();
			String sourceCoords = "["+source.get_x()+","+source.get_y()+"]";
			String destCoords = "["+dest.get_x()+","+dest.get_y()+"]";
			coords.add(JSONArray.fromObject(sourceCoords));
			coords.add(JSONArray.fromObject(destCoords));
			entry.element("coords", coords);
			
			JSONObject label = new JSONObject();
			label.element("show", true);
			label.element("position", "middle");
			label.element("color", "white");
			label.element("formatter", new BigDecimal(record.getExportFlow()).divide(b,2,RoundingMode.HALF_UP)+"m/s");
			entry.element("label", label);
			
			JSONObject lineStyle = new JSONObject();
			lineStyle.element("width", 3);
			lineStyle.element("opacity", 1);
			lineStyle.element("curveness", port.getCurveness());
			JSONObject color = new JSONObject();
			color.element("type", "linear");
			color.element("x", 0);
			color.element("y", 0);
			color.element("x2", 0);
			color.element("y2", 1);
			
			if (record.getState()==1) {
				JSONArray colorStops = JSONArray.fromObject("[{offset: 0, color: \"#EEEE00\"},{offset: 1, color: \"#32CD32\"}]");
				color.element("colorStops", colorStops);
			}else {
				JSONArray colorStops = JSONArray.fromObject("[{offset: 0, color: \"#CCCCCC\"},{offset: 1, color: \"#CCCCCC\"}]");
				color.element("colorStops", colorStops);
			}
			lineStyle.element("color", color);
			entry.element("lineStyle", lineStyle);
			list.add(entry);
			
			//in
			JSONObject entry_in = new JSONObject();
			
			JSONArray coords_in = new JSONArray();
			coords_in.add(JSONArray.fromObject(destCoords));
			coords_in.add(JSONArray.fromObject(sourceCoords));
			
			entry_in.element("coords", coords_in);
			
			JSONObject label_in = new JSONObject();
			label_in.element("show", true);
			label_in.element("position", "middle");
			label_in.element("color", "white");
			label_in.element("formatter", new BigDecimal(record.getInletFlow()).divide(b,2,RoundingMode.HALF_UP)+"m/s");
			entry_in.element("label", label_in);
			
			JSONObject lineStyle_in = new JSONObject();
			lineStyle_in.element("width", 3);
			lineStyle_in.element("opacity", 1);
			lineStyle_in.element("color", color);
			lineStyle_in.element("curveness", port.getCurveness());
			entry_in.element("lineStyle", lineStyle_in);
			list.add(entry_in);
		}
		
		
		return list;
	}

  

你可能感兴趣的:(代码块。)