工业级运维app手机api
沈斌
2017-11-20 44bfab8ff28cbeb54686f9398699615324ca879b
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
145
146
147
package com.moral.monitor.controller;
 
import com.moral.monitor.entity.Equipment;
import com.moral.monitor.entity.QueryHelper;
import com.moral.monitor.entity.Sensor;
import com.moral.monitor.entity.User;
import com.moral.monitor.service.EquService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
/**
 * Created by a on 2017/7/5.
 */
@Controller
public class EquController {
 
    private static final Log log = LogFactory.getLog(EquController.class);
 
    @Resource
    EquService equService;
 
    @RequestMapping("/findAllEqu")
    @ResponseBody
    public Map findAllUser(@RequestBody QueryHelper queryHelper){
 
        String search = queryHelper.getSearch();
 
        String trim = queryHelper.getSearch().trim();
        if(trim.equals("")){
            queryHelper.setSearch("");
        }
 
        LinkedHashMap<String, Object> s = new LinkedHashMap<String, Object>();
        List<Equipment> equs = equService.allEqus(queryHelper);
        s.put("rows",equs);
 
        int total = equService.equscount(queryHelper);
        s.put("total",total);
 
        return s;
 
    }
 
 
    @RequestMapping("/deleteEqu")
    @ResponseBody
    public String deleteUser(@RequestParam("ids[]") String[] ids){
        try{
            for (String id:ids){
                if (!(id.equals(""))) {
                    equService.deleteEqu(id);
                }
            }
        }
        catch (Exception e){
            log.debug(e.getMessage());
            return "false";
        }
        return "true";
    }
 
 
 
 
    @RequestMapping("/addequ")
    @ResponseBody
    public String adduser(@RequestBody Equipment equipment){
        try {
 
            String mac = equipment.getMac();
            if (mac.trim().equals("")){
                return "false";
            }
 
            String province = equipment.getProvince();
            String city = equipment.getCity();
            String area = equipment.getArea();
            if(province.equals("")){
                equipment.setProvince(null);
            }
            if(city.equals("")){
                equipment.setCity(null);
            }
            if(area.equals("")){
                equipment.setArea(null);
            }
 
 
            equService.deletefrommac(mac);
            equService.addequ(equipment);
            //据版本查找传感器
            int ver=2;
            String type="A";
            List<Sensor> sensors = equService.findsensor(ver, type);
            for(Sensor s:sensors){
                String sensor = s.getSensor();
                equService.insertmac(mac,sensor);
            }
        }catch (Exception e){
            log.debug(e.getMessage());
            return "false";
        }
        return "true";
    }
 
 
 
    @RequestMapping("/editequ")
    @ResponseBody
    public String edituser(@RequestBody Equipment equipment){
 
        try {
 
            String province = equipment.getProvince();
            String city = equipment.getCity();
            String area = equipment.getArea();
            if(province.equals("")){
                equipment.setProvince(null);
            }
            if(city.equals("")){
                equipment.setCity(null);
            }
            if(area.equals("")){
                equipment.setArea(null);
            }
 
            equService.editequ(equipment);
        }catch (Exception e){
         return "false";
        }
        return "true";
    }
 
 
 
 
}