Blame view

src/com/fh/controller/api/ApiServer.java 6.47 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
31
  	
  	@RequestMapping(value="/school/list" ,produces="application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
32
  	@ResponseBody
cb39a12d   孙向锦   更新api接口头信息
33
  	public Object schoolList() throws Exception{
92455d76   孙向锦   添加更新到服务器
34
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
35
  		String id = pd.getString("ID");
92455d76   孙向锦   添加更新到服务器
36
  		if(id != null && !"".equals(id)){
92455d76   孙向锦   添加更新到服务器
37
  			PageData ret = schoolService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
38
39
40
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
41
42
  		}else{
  			List<PageData> ret = schoolService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
43
44
45
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
46
  		}
cb39a12d   孙向锦   更新api接口头信息
47
48
49
50
51
  	}
  	@RequestMapping(value="/school/add" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object schoolAdd() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
52
  		ResponseGson<Integer> res = new ResponseGson();
cb39a12d   孙向锦   更新api接口头信息
53
  		try {
b980d59d   孙向锦   修改模板
54
55
56
  			if (pd.get("NAME") != null) {
  				Integer id = schoolService.save(pd);
  				res.setData(id);
cb39a12d   孙向锦   更新api接口头信息
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  			} 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   孙向锦   修改模板
71
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
72
  		if(id != null && !"".equals(id)){
b980d59d   孙向锦   修改模板
73
74
75
76
77
  			try {
  				schoolService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
cb39a12d   孙向锦   更新api接口头信息
78
79
80
81
82
83
84
85
86
87
88
  		}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   孙向锦   修改模板
89
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
90
  		if(id != null && !"".equals(id)){
b980d59d   孙向锦   修改模板
91
92
93
94
95
  			try {
  				schoolService.edit(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
cb39a12d   孙向锦   更新api接口头信息
96
97
98
99
  		}else{
  			res.setDataError();
  		}
  		return res.toJson();
92455d76   孙向锦   添加更新到服务器
100
101
  	}
  	
cb39a12d   孙向锦   更新api接口头信息
102
103
  	
  	@RequestMapping(value="/basestation/list" ,produces="application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
104
105
106
  	@ResponseBody
  	public Object basestation() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
107
  		String id = pd.getString("ID");
92455d76   孙向锦   添加更新到服务器
108
109
110
  		if(id != null && !"".equals(id)){
  			pd.put("BASESTATION_ID", pd.getString("id"));
  			PageData ret = basestationService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
111
112
113
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
114
115
  		}else{
  			List<PageData> ret = basestationService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
116
117
118
119
120
121
122
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
  		}
  		
  	}
  	
b980d59d   孙向锦   修改模板
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
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
  	@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接口头信息
176
177
178
179
  	@RequestMapping(value="/keypad/list" ,produces="application/json;charset=UTF-8")
  	@ResponseBody
  	public Object keypad() throws Exception{
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
180
  		String id = pd.getString("ID");
cb39a12d   孙向锦   更新api接口头信息
181
  		if(id != null && !"".equals(id)){
cb39a12d   孙向锦   更新api接口头信息
182
183
184
185
186
187
188
189
190
  			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   孙向锦   添加更新到服务器
191
  		}
92455d76   孙向锦   添加更新到服务器
192
  	}
b980d59d   孙向锦   修改模板
193
194
195
196
197
198
199
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
  	
  	@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   孙向锦   添加更新到服务器
243
  }