Blame view

src/com/fh/controller/api/ApiServer.java 6.64 KB
92455d76   孙向锦   添加更新到服务器
1
2
3
4
5
6
7
8
9
10
11
12
  package com.fh.controller.api;
  
  import java.util.List;
  
  import javax.annotation.Resource;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  import com.fh.controller.base.BaseController;
  import com.fh.service.sunvote.basestation.BasestationManager;
cb39a12d   孙向锦   更新api接口头信息
13
  import com.fh.service.sunvote.keypad.KeypadManager;
92455d76   孙向锦   添加更新到服务器
14
  import com.fh.service.sunvote.school.SchoolManager;
92455d76   孙向锦   添加更新到服务器
15
  import com.fh.util.PageData;
92455d76   孙向锦   添加更新到服务器
16
17
18
19
20
21
22
23
24
25
26
  
  @Controller
  @RequestMapping(value="/api")
  public class ApiServer extends BaseController {
  
  	@Resource(name="schoolService")
  	private SchoolManager schoolService;
  	
  	@Resource(name="basestationService")
  	private BasestationManager basestationService;
  	
cb39a12d   孙向锦   更新api接口头信息
27
28
  	@Resource(name="keypadService")
  	private KeypadManager keypadService;
92455d76   孙向锦   添加更新到服务器
29
  	
cb39a12d   孙向锦   更新api接口头信息
30
  	
7db3ebeb   孙向锦   添加一些模块
31
32
33
34
35
36
37
  	@RequestMapping(value="/school" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolDefault() throws Exception{
  		return schoolList();
  	}
  	
  	
cb39a12d   孙向锦   更新api接口头信息
38
  	@RequestMapping(value="/school/list" ,produces="application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
39
  	@ResponseBody
cb39a12d   孙向锦   更新api接口头信息
40
  	public Object schoolList() throws Exception{
92455d76   孙向锦   添加更新到服务器
41
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
42
  		String id = pd.getString("ID");
92455d76   孙向锦   添加更新到服务器
43
  		if(id != null && !"".equals(id)){
92455d76   孙向锦   添加更新到服务器
44
  			PageData ret = schoolService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
45
46
47
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
48
49
  		}else{
  			List<PageData> ret = schoolService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
50
51
52
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
53
  		}
cb39a12d   孙向锦   更新api接口头信息
54
55
56
57
58
  	}
  	@RequestMapping(value="/school/add" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolAdd() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
59
  		ResponseGson<Integer> res = new ResponseGson();
cb39a12d   孙向锦   更新api接口头信息
60
  		try {
b980d59d   孙向锦   修改模板
61
62
63
  			if (pd.get("NAME") != null) {
  				Integer id = schoolService.save(pd);
  				res.setData(id);
cb39a12d   孙向锦   更新api接口头信息
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  			} else {
  				res.setDataError();
  			}
  		}catch(Exception e){
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
  	@RequestMapping(value="/school/delete" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolDelete() throws Exception{
  		ResponseGson<PageData> res = new ResponseGson();
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
78
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
79
  		if(id != null && !"".equals(id)){
b980d59d   孙向锦   修改模板
80
81
82
83
84
  			try {
  				schoolService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
cb39a12d   孙向锦   更新api接口头信息
85
86
87
88
89
90
91
92
93
94
95
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
  	@RequestMapping(value="/school/update" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolUpdate() throws Exception{
  		ResponseGson<PageData> res = new ResponseGson();
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
96
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
97
  		if(id != null && !"".equals(id)){
b980d59d   孙向锦   修改模板
98
99
100
101
102
  			try {
  				schoolService.edit(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
cb39a12d   孙向锦   更新api接口头信息
103
104
105
106
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
92455d76   孙向锦   添加更新到服务器
107
108
  	}
  	
cb39a12d   孙向锦   更新api接口头信息
109
110
  	
  	@RequestMapping(value="/basestation/list" ,produces="application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
111
112
113
  	@ResponseBody
  	public Object basestation() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
114
  		String id = pd.getString("ID");
92455d76   孙向锦   添加更新到服务器
115
116
117
  		if(id != null && !"".equals(id)){
  			pd.put("BASESTATION_ID", pd.getString("id"));
  			PageData ret = basestationService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
118
119
120
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
121
122
  		}else{
  			List<PageData> ret = basestationService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
123
124
125
126
127
128
129
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
  		}
  		
  	}
  	
b980d59d   孙向锦   修改模板
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  	@RequestMapping(value="/basestation/add" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object basestationAdd() throws Exception {
  		ResponseGson<PageData> res = new ResponseGson();
  		PageData pd = this.getPageData();
  		if (pd.getString("NAME") != null) {
  			try {
  				basestationService.edit(pd);
  			} catch (Exception ex) {
  				res.setDataError();
  			}
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
  	@RequestMapping(value="/basestation/delete" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object basestationDelete() throws Exception{
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
  		if(id != null && !"".equals(id)){
  			try {
  				basestationService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
  	@RequestMapping(value="/basestation/update" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object basestationUpdate() throws Exception{
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
  		if(id != null && !"".equals(id)){
  			try {
  				basestationService.edit(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
cb39a12d   孙向锦   更新api接口头信息
183
184
185
186
  	@RequestMapping(value="/keypad/list" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object keypad() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
187
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
188
  		if(id != null && !"".equals(id)){
cb39a12d   孙向锦   更新api接口头信息
189
190
191
192
193
194
195
196
197
  			PageData ret = keypadService.findById(pd);
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
  		}else{
  			List<PageData> ret = keypadService.listAll(pd);
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
198
  		}
92455d76   孙向锦   添加更新到服务器
199
  	}
b980d59d   孙向锦   修改模板
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  	
  	@RequestMapping(value="/keypad/add" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object keypadAdd() throws Exception {
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		try {
  			keypadService.save(pd);
  		} catch (Exception ex) {
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
  	@RequestMapping(value="/keypad/delete" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object keypadDelete() throws Exception{
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
  		if(id != null && !"".equals(id)){
  			try {
  				keypadService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
  	@RequestMapping(value="/keypad/update" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object keypadUpdate() throws Exception{
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
  		if(id != null && !"".equals(id)){
  			try{
  				keypadService.edit(pd);
  			}catch(Exception ex){
  				res.setDataError();
  			}
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
  	}
  	
92455d76   孙向锦   添加更新到服务器
250
  }