Blame view

src/com/fh/controller/api/ApiServer.java 6.87 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
38
39
40
41
42
43
44
45
  	@RequestMapping(value="/*" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object Default() throws Exception{
  		ResponseGson<Void> respone = new ResponseGson();
  		respone.setPathError();
  		return respone.toJson();
  	}
  	
  	@RequestMapping(value="/school" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolDefault() throws Exception{
  		return schoolList();
  	}
  	
  	
cb39a12d   孙向锦   更新api接口头信息
46
  	@RequestMapping(value="/school/list" ,produces="application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
47
  	@ResponseBody
cb39a12d   孙向锦   更新api接口头信息
48
  	public Object schoolList() throws Exception{
92455d76   孙向锦   添加更新到服务器
49
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
50
  		String id = pd.getString("ID");
92455d76   孙向锦   添加更新到服务器
51
  		if(id != null && !"".equals(id)){
92455d76   孙向锦   添加更新到服务器
52
  			PageData ret = schoolService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
53
54
55
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
56
57
  		}else{
  			List<PageData> ret = schoolService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
58
59
60
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
61
  		}
cb39a12d   孙向锦   更新api接口头信息
62
63
64
65
66
  	}
  	@RequestMapping(value="/school/add" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolAdd() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
67
  		ResponseGson<Integer> res = new ResponseGson();
cb39a12d   孙向锦   更新api接口头信息
68
  		try {
b980d59d   孙向锦   修改模板
69
70
71
  			if (pd.get("NAME") != null) {
  				Integer id = schoolService.save(pd);
  				res.setData(id);
cb39a12d   孙向锦   更新api接口头信息
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  			} 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   孙向锦   修改模板
86
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
87
  		if(id != null && !"".equals(id)){
b980d59d   孙向锦   修改模板
88
89
90
91
92
  			try {
  				schoolService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
cb39a12d   孙向锦   更新api接口头信息
93
94
95
96
97
98
99
100
101
102
103
  		}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   孙向锦   修改模板
104
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
105
  		if(id != null && !"".equals(id)){
b980d59d   孙向锦   修改模板
106
107
108
109
110
  			try {
  				schoolService.edit(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
cb39a12d   孙向锦   更新api接口头信息
111
112
113
114
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
92455d76   孙向锦   添加更新到服务器
115
116
  	}
  	
cb39a12d   孙向锦   更新api接口头信息
117
118
  	
  	@RequestMapping(value="/basestation/list" ,produces="application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
119
120
121
  	@ResponseBody
  	public Object basestation() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
122
  		String id = pd.getString("ID");
92455d76   孙向锦   添加更新到服务器
123
124
125
  		if(id != null && !"".equals(id)){
  			pd.put("BASESTATION_ID", pd.getString("id"));
  			PageData ret = basestationService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
126
127
128
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
129
130
  		}else{
  			List<PageData> ret = basestationService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
131
132
133
134
135
136
137
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
  		}
  		
  	}
  	
b980d59d   孙向锦   修改模板
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
183
184
185
186
187
188
189
190
  	@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接口头信息
191
192
193
194
  	@RequestMapping(value="/keypad/list" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object keypad() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
195
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
196
  		if(id != null && !"".equals(id)){
cb39a12d   孙向锦   更新api接口头信息
197
198
199
200
201
202
203
204
205
  			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   孙向锦   添加更新到服务器
206
  		}
92455d76   孙向锦   添加更新到服务器
207
  	}
b980d59d   孙向锦   修改模板
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
250
251
252
253
254
255
256
257
  	
  	@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   孙向锦   添加更新到服务器
258
  }