package com.moral.monitor.controller;
|
|
import com.moral.monitor.entity.*;
|
import com.moral.monitor.service.DashboardService;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.text.DateFormat;
|
import java.text.DecimalFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* Created by a on 2017/6/5.
|
*/
|
@Controller
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
public class Dashboard {
|
@Resource
|
DashboardService dashboardService;
|
|
@RequestMapping(value = "dashboard")
|
@ResponseBody
|
public Map dashBoard(){
|
|
Map<String, Integer> data = new LinkedHashMap<String, Integer>();
|
|
int countuser = dashboardService.countuser();
|
|
int countequipment = dashboardService.countequipment();
|
int countonlineequ = dashboardService.countonlineequ();
|
int countwarnequ = dashboardService.countwarnequ();
|
int countofflineequ = dashboardService.countofflineequ();
|
|
int countnoticelog = dashboardService.countnoticelog();
|
int countmailnotice = dashboardService.countmailnotice();
|
int countwechatnotice = dashboardService.countwechatnotice();
|
int countsmsnotice = dashboardService.countsmsnotice();
|
int countphonenotice = dashboardService.countphonenotice();
|
|
data.put("countuser",countuser);
|
|
data.put("countequipment",countequipment);
|
data.put("countonlineequ",countonlineequ);
|
data.put("countwarnequ",countwarnequ);
|
data.put("countofflineequ",countofflineequ);
|
|
data.put("countnoticelog",countnoticelog);
|
data.put("countmailnotice",countmailnotice);
|
data.put("countwechatnotice",countwechatnotice);
|
data.put("countsmsnotice",countsmsnotice);
|
data.put("countphonenotice",countphonenotice);
|
return data;
|
}
|
|
|
|
@RequestMapping(value = "alarmequAndnoticeuser")
|
@ResponseBody
|
public Map alarmequAndnoticeuser(){
|
Map<String, Object> data = new HashMap<String, Object>();
|
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
List<Alarmlog> latelyalarmequ = dashboardService.latelyalarmequ();
|
for(Alarmlog alarmlog:latelyalarmequ){
|
Date time = alarmlog.getTime();
|
String format = sdf.format(time);
|
alarmlog.setDesctime(format);
|
}
|
|
List<Noticelog> latelynoticeuser = dashboardService.latelynoticeuser();
|
for(Noticelog noticelog:latelynoticeuser){
|
Date time = noticelog.getTime();
|
String format = sdf.format(time);
|
noticelog.setDesctime(format);
|
}
|
|
data.put("latelyalarmequ",latelyalarmequ);
|
data.put("latelynoticeuser",latelynoticeuser);
|
|
int onecount = dashboardService.onecount();
|
int secondcount = dashboardService.secondcount();
|
int thirdcount = dashboardService.thirdcount();
|
|
data.put("onecount",onecount);
|
data.put("secondcount",secondcount);
|
data.put("thirdcount",thirdcount);
|
|
data.put("aaa","aaa");
|
|
return data;
|
}
|
|
|
|
@RequestMapping(value = "allUsers")
|
@ResponseBody
|
public Map allUsers(@RequestBody QueryHelper queryHelper){
|
String trim = queryHelper.getSearch().trim();
|
if(trim.equals("")){
|
queryHelper.setSearch("");
|
}
|
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<User> users = dashboardService.allUsers(queryHelper);
|
s.put("rows",users);
|
|
int total = dashboardService.userscount(queryHelper);
|
s.put("total",total);
|
|
return s;
|
|
}
|
|
|
@RequestMapping(value = "allEqus")
|
@ResponseBody
|
public Map allEqus(@RequestBody QueryHelper queryHelper){
|
String search = queryHelper.getSearch();
|
if(search!=null){
|
String trim = search.trim();
|
if(trim.equals("")){
|
queryHelper.setSearch("");
|
}
|
}
|
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<Equipment> equipments = dashboardService.allEqus(queryHelper);
|
|
for(Equipment e:equipments){
|
int state = e.getState();
|
// if (state==0){
|
// e.setStatedesc("离线");
|
// }else if(state==4){
|
// e.setStatedesc("在线");
|
// }else if(state==1||state==2||state==3){
|
// e.setStatedesc("报警");
|
// }
|
}
|
|
s.put("rows",equipments);
|
|
int total = dashboardService.equscount(queryHelper);
|
s.put("total",total);
|
|
return s;
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "allNotices")
|
@ResponseBody
|
public Map allNotices(@RequestBody QueryHelper queryHelper){
|
String trim = queryHelper.getSearch().trim();
|
if(trim.equals("")){
|
queryHelper.setSearch("");
|
}
|
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<Noticelog> noticelogs = dashboardService.allNotices(queryHelper);
|
|
s.put("rows",noticelogs);
|
int total = dashboardService.noticescount(queryHelper);
|
s.put("total",total);
|
|
return s;
|
|
}
|
|
|
|
@RequestMapping(value = "allAlarmlogs")
|
@ResponseBody
|
public Map allAlarmlogs(@RequestBody QueryHelper queryHelper){
|
String trim = queryHelper.getSearch().trim();
|
if(trim.equals("")){
|
queryHelper.setSearch("");
|
}
|
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<Alarmlog> alarmlogs = dashboardService.allAlarmlogs(queryHelper);
|
|
s.put("rows",alarmlogs);
|
int total = dashboardService.alarmlogscount(queryHelper);
|
s.put("total",total);
|
|
return s;
|
|
}
|
|
|
/*系统报警数据*/
|
@RequestMapping(value = "alarmtime")
|
@ResponseBody
|
public Map alarmtime(){
|
DateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<Alarmlog> alarmlogs = dashboardService.alarmtime();
|
Collections.reverse(alarmlogs);
|
|
ArrayList<String> xtime = new ArrayList<String>();
|
ArrayList<Integer> yvalue = new ArrayList<Integer>();
|
|
for (Alarmlog a:alarmlogs){
|
String format = sdf.format(a.getTime());
|
xtime.add(format);
|
|
String alarm_desc = a.getAlarm_desc();
|
if ("一级".equals(alarm_desc)){
|
a.setSensor_level(3);
|
}else if("二级".equals(alarm_desc)){
|
a.setSensor_level(2);
|
}else if("三级".equals(alarm_desc)){
|
a.setSensor_level(1);
|
}
|
|
int sensor_level = a.getSensor_level();
|
yvalue.add(sensor_level);
|
|
|
}
|
s.put("xtime",xtime);
|
s.put("yvalue",yvalue);
|
return s;
|
|
}
|
|
/*系统报警数据带条件*/
|
@RequestMapping(value = "alarmtimequery")
|
@ResponseBody
|
public Map alarmtimequery(@RequestBody QueryHelper queryHelper){
|
|
DateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<Alarmlog> alarmlogs = dashboardService.alarmtimequery(queryHelper);
|
Collections.reverse(alarmlogs);
|
|
ArrayList<String> xtime = new ArrayList<String>();
|
ArrayList<Integer> yvalue = new ArrayList<Integer>();
|
|
for (Alarmlog a:alarmlogs){
|
String format = sdf.format(a.getTime());
|
xtime.add(format);
|
|
String alarm_desc = a.getAlarm_desc();
|
if ("一级".equals(alarm_desc)){
|
a.setSensor_level(3);
|
}else if("二级".equals(alarm_desc)){
|
a.setSensor_level(2);
|
}else if("三级".equals(alarm_desc)){
|
a.setSensor_level(1);
|
}
|
|
int sensor_level = a.getSensor_level();
|
yvalue.add(sensor_level);
|
|
|
}
|
s.put("xtime",xtime);
|
s.put("yvalue",yvalue);
|
return s;
|
|
}
|
|
|
|
|
@RequestMapping(value = "equlist")
|
@ResponseBody
|
public List equList(){
|
List<Equipment> equipments = dashboardService.equlist();
|
return equipments;
|
}
|
|
|
|
@RequestMapping(value = "equalarms")
|
@ResponseBody
|
public Map equAlarms(@RequestBody QueryHelper queryHelper){
|
DateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
List<Alarmlog> alarmlogs = dashboardService.equalarms(queryHelper);
|
|
Collections.reverse(alarmlogs);
|
DecimalFormat df = new DecimalFormat("#");
|
ArrayList<String> xtime = new ArrayList<String>();
|
ArrayList<Integer> yvalue = new ArrayList<Integer>();
|
|
for (Alarmlog a:alarmlogs){
|
|
String sensor_name = a.getSensor_name();
|
double sensor_data = a.getSensor_data();
|
String data = df.format(sensor_data);
|
String sensor_unit = a.getSensor_unit();
|
String desc=sensor_name+": "+data+sensor_unit;
|
|
String format = sdf.format(a.getTime());
|
xtime.add(format+"_"+desc);
|
|
String alarm_desc = a.getAlarm_desc();
|
if ("一级".equals(alarm_desc)){
|
a.setSensor_level(3);
|
}else if("二级".equals(alarm_desc)){
|
a.setSensor_level(2);
|
}else if("三级".equals(alarm_desc)){
|
a.setSensor_level(1);
|
}
|
int sensor_level = a.getSensor_level();
|
yvalue.add(sensor_level);
|
}
|
|
s.put("xtime",xtime);
|
s.put("yvalue",yvalue);
|
|
return s;
|
|
}
|
|
|
|
@RequestMapping(value = "equsensor")
|
@ResponseBody
|
public List equSensor(HttpServletRequest request){
|
String mac = request.getParameter("mac");
|
List<Sensor> sensors = dashboardService.equsensor(mac);
|
return sensors;
|
|
}
|
|
|
|
@RequestMapping(value = "sensorhistory")
|
@ResponseBody
|
public Map sensorHistory(@RequestBody QueryHelper queryHelper){
|
DateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
|
String sensor = queryHelper.getSensor();
|
Sensor u = dashboardService.units(sensor);
|
String units = u.getUnits();
|
|
|
List<History> historys = dashboardService.sensorhistory(queryHelper);
|
|
Collections.reverse(historys);
|
|
ArrayList<String> xtime = new ArrayList<String>();
|
ArrayList<Double> yvalue = new ArrayList<Double>();
|
|
for (History a:historys){
|
String format = sdf.format(a.getTime());
|
xtime.add(format);
|
yvalue.add(a.getMac_value());
|
}
|
s.put("xtime",xtime);
|
s.put("yvalue",yvalue);
|
s.put("sensor",sensor);
|
s.put("units",units);
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "trend")
|
@ResponseBody
|
public List<Season> trend(){
|
ArrayList<String> seasons = new ArrayList<String>();
|
for (int i = 0; i <=12;) {
|
Calendar c = Calendar.getInstance();
|
c.add(Calendar.MONTH,-i);
|
int m=c.get(Calendar.MONTH)+1;
|
int y = c.get(Calendar.YEAR);
|
String s = getThisSeason(m);
|
String season=y+" "+s;
|
seasons.add(season);
|
i=i+3;
|
}
|
|
List<Season> countseasons = dashboardService.countequseason();
|
HashMap<String, Season> cs = new HashMap<String, Season>();
|
for(Season s:countseasons){
|
String season = s.getSeason();
|
cs.put(season,s);
|
}
|
|
List<Season> web=new ArrayList<Season>();
|
for(String s:seasons){
|
if(cs.containsKey(s)){
|
web.add(cs.get(s));
|
}else{
|
Season season = new Season();
|
season.setSeason(s);
|
season.setCount(0);
|
web.add(season);
|
}
|
|
}
|
return web;
|
}
|
|
|
public static String getThisSeason(int month){
|
String quarter="";
|
if(month>=1&&month<=3){
|
quarter="Q1";
|
}
|
if(month>=4&&month<=6){
|
quarter="Q2";
|
}
|
if(month>=7&&month<=9){
|
quarter = "Q3";
|
}
|
if(month>=10&&month<=12){
|
quarter = "Q4";
|
}
|
return quarter;
|
}
|
|
|
|
|
|
|
|
|
}
|