工业级运维app手机api
沈斌
2018-02-28 10452b5c9fee46e4c0a6bea0da89371d60ec10bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.moral.monitor.controller;
 
import com.alibaba.fastjson.JSON;
import com.moral.monitor.entity.Equipment;
import com.moral.monitor.entity.State;
import com.moral.monitor.service.ScreenApiService;
import com.moral.monitor.util.ScreenApiData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
 
/**
 * Created by a on 2017/7/12.
 */
//@Controller
//@RequestMapping(value = "screen")
public class ScreenApiController {
 
    @Resource
    ScreenApiService screenApiService;
 
    /**
     * 所有区域/指定区域 设备状态:总数,正常,离线,报警。返回数量信息
     * @param area  地区信息,值为空 字符串则查询所有设备
     * @return
     */
     @RequestMapping(value = "equcount")
     @ResponseBody
    public ScreenApiData equstatus(String area){
 
        area = area.trim();
 
        ScreenApiData screenApiData = new ScreenApiData();
        LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
 
        int total = screenApiService.equstatus_total(area);
        int ok = screenApiService.equstatus_online(area);
        int warn = screenApiService.equstatus_warn(area);
        int offline = screenApiService.equstatus_offline(area);
 
        map.put("total",total);
        map.put("ok",ok);
        map.put("warn",warn);
        map.put("offline",offline);
 
        String data = JSON.toJSONString(map);
        screenApiData.setData(data);
        return screenApiData;
    }
 
 
    /**
     * 所有/区域 设备列表:总数,正常,离线,报警。返回实体信息列表。 ,
     * @param area        值为空字符串则查询所有区域
     * @param pageIndex   pageIndex ,pageSize 默认为 1 ,10
     * @param pageSize
     * @param status     status值约定为  在线 离线 报警,为空字符串则为 查询所有状态
     * @return
     */
    @RequestMapping(value = "equlist")
    @ResponseBody
    public ScreenApiData equlist(String area,String pageIndex,String pageSize,String status){
 
        area   = area.trim();
        status = status.trim();
 
        int index=Integer.parseInt(pageIndex);
        int  size=Integer.parseInt(pageSize);
            index =(index-1)*size;
 
        List<Equipment> equlist = screenApiService.equlist(area, index, size, status);
        int total = screenApiService.equlist_size(area, status);
 
        int totalpages;
        if (total % size == 0) {
            totalpages = total / size;
        } else {
            totalpages = total / size + 1;
        }
 
        ScreenApiData screenApiData = new ScreenApiData();
        screenApiData.setData(equlist);
        screenApiData.setExtData(totalpages);
        return screenApiData;
    }
 
 
    /*按名称搜索设备信息。返回实体信息*/
    @RequestMapping(value = "equinfo")
    @ResponseBody
    public ScreenApiData equinfo(String name,String pageIndex,String pageSize){
 
        int index=Integer.parseInt(pageIndex);
        int  size=Integer.parseInt(pageSize);
        index =(index-1)*size;
 
        List<Equipment> equinfo = screenApiService.equinfo(name,index,size);
        int total = screenApiService.equinfo_size(name);
 
        int totalpages;
        if (total % size == 0) {
            totalpages = total / size;
        } else {
            totalpages = total / size + 1;
        }
 
        ScreenApiData screenApiData = new ScreenApiData();
        screenApiData.setData(equinfo);
        screenApiData.setExtData(totalpages);
        return screenApiData;
 
    }
 
 
 
    /* 设备传感器即时数据 */
    @RequestMapping(value = "equsensorstate")
    @ResponseBody
    public ScreenApiData equsensorstate(String mac){
        List<State> equsensorstate = screenApiService.equsensorstate(mac);
        LinkedHashMap<String, Double> map = new LinkedHashMap<String, Double>();
        for (State s: equsensorstate){
            map.put(s.getSensor(),s.getMac_value());
        }
        String data = JSON.toJSONString(map);
        ScreenApiData screenApiData = new ScreenApiData();
        screenApiData.setData(data);
        return screenApiData;
    }
 
 
 
 
 
 
 
 
 
 
 
}