package com.hcycom.controller;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
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.ResponseBody;
import com.hcycom.bean.Vlllink;
import com.hcycom.bean.Vlllinkdelay;
import com.hcycom.service.VlllinkService;
import com.hcycom.service.VlllinkdelayService;
import com.hcycom.util.RandomUtil;
@Controller
public class VilllinkdelayController {
@Autowired
VlllinkdelayService vlllinkdelayService;
@Autowired
VlllinkService vlllinkService;
//查询所有时延信息
@RequestMapping("getVlllinkdelay")
@ResponseBody
public List<Vlllinkdelay> getVlllinkdelay(HttpServletRequest request,HttpSession session){
List<Vlllinkdelay> list1 = vlllinkdelayService.getVlllinkdelay();
return list1;
}
//自动添加一条时延数据到VLL时延表中
@RequestMapping("addVlllinkdelay")
public String addVlllinkdelay(Vlllink vll,Vlllinkdelay vlde){
System.out.println("来了:"+vll.VLL_LINK_NAME);
Vlllink vll3 = vlllinkService.getVlllinkByName(vll);
int vll_link_id = vll3.getVLL_LINK_ID();
int LINK_STATUS=Math.random()>0.5?1:0;
if(LINK_STATUS==0){
vlde.setVll_link_id(vll_link_id);
vlde.setLin_status(0);
vlde.setDelay_average(-1);
vlde.setDelay_maxnum(-1);
vlde.setDelay_minnum(-1);
vlde.setPacket_loss(100);
Date date = new Date();
vlde.setTest_time(date);
vlllinkdelayService.addVlllinkdelay(vlde);
vll.setVLL_LINK_ID(vll_link_id);
vll.setLINK_STATUS(0);
vll.setDelay_average(-1);
vll.setDelay_maxnum(-1);
vll.setDelay_minnum(-1);
vll.setPacket_loss(100);
vll.setLast_test_time(date);
vlllinkService.updateVlllinkTest(vll);
return "true";
}else{
RandomUtil rad = new RandomUtil();
rad.One();
int avg = rad.avg;
int max = rad.max;
int min = rad.min;
vlde.setVll_link_id(vll_link_id);
vlde.setLin_status(1);
vlde.setDelay_average(avg);
vlde.setDelay_maxnum(max);
vlde.setDelay_minnum(min);
vlde.setPacket_loss(0);
Date date = new Date();
vlde.setTest_time(date);
vlllinkdelayService.addVlllinkdelay(vlde);
vll.setVLL_LINK_ID(vll_link_id);
vll.setLINK_STATUS(1);
vll.setDelay_average(avg);
vll.setDelay_maxnum(max);
vll.setDelay_minnum(min);
vll.setPacket_loss(0);
vll.setLast_test_time(date);
vlllinkService.updateVlllinkTest(vll);
return "false";
}
}
//根据日期查询时延信息
@RequestMapping("getVlllinkdelayByDate")
@ResponseBody
public List<Vlllinkdelay> getVlllinkdelayByDate(Vlllinkdelay vlde,HttpServletRequest request){
List<Vlllinkdelay> listvlldelaydate = vlllinkdelayService.getVlllinkdelayByDate(vlde);
return listvlldelaydate;
}
//查询最近24小时的时延记录
@RequestMapping("getVlllinkdellayByNow")
@ResponseBody
public List<Vlllinkdelay> getVlllinkdellayByNow(Vlllinkdelay vlde,HttpServletRequest request){
List<Vlllinkdelay> listvlldelaynow = vlllinkdelayService.getVlllinkdellayByNow(vlde);
return listvlldelaynow;
}
//查询规定时间段内的时延记录
@RequestMapping("getVlllinkdellayByhop")
@ResponseBody
public List<Vlllinkdelay> getVlllinkdellayByhop(Vlllinkdelay vlde){
List<Vlllinkdelay> listvlldelayhop = vlllinkdelayService.getVlllinkdellayByhop(vlde);
return listvlldelayhop;
}
}