Blame view

src/com/fh/controller/api/ApiServer.java 9.98 KB
92455d76   孙向锦   添加更新到服务器
1
2
  package com.fh.controller.api;
  
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
3
  import java.io.File;
c83d0804   孙向锦   添加客服反馈
4
5
  import java.io.FileOutputStream;
  import java.io.OutputStream;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
6
  import java.util.Date;
92455d76   孙向锦   添加更新到服务器
7
8
9
  import java.util.List;
  
  import javax.annotation.Resource;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
10
  import javax.servlet.http.HttpServletRequest;
92455d76   孙向锦   添加更新到服务器
11
12
13
14
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
15
  import org.springframework.web.multipart.MultipartFile;
92455d76   孙向锦   添加更新到服务器
16
  
c83d0804   孙向锦   添加客服反馈
17
18
  import Decoder.BASE64Decoder;
  
92455d76   孙向锦   添加更新到服务器
19
  import com.fh.controller.base.BaseController;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
20
  import com.fh.service.feedback.feedback.FeedbackManager;
c83d0804   孙向锦   添加客服反馈
21
  import com.fh.service.feedback.problemphenomenon.ProblemPhenomenonManager;
92455d76   孙向锦   添加更新到服务器
22
  import com.fh.service.sunvote.basestation.BasestationManager;
cb39a12d   孙向锦   更新api接口头信息
23
  import com.fh.service.sunvote.keypad.KeypadManager;
92455d76   孙向锦   添加更新到服务器
24
  import com.fh.service.sunvote.school.SchoolManager;
92455d76   孙向锦   添加更新到服务器
25
  import com.fh.util.PageData;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
26
  import com.fh.util.Tools;
92455d76   孙向锦   添加更新到服务器
27
28
  
  @Controller
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
29
  @RequestMapping(value = "/api")
92455d76   孙向锦   添加更新到服务器
30
31
  public class ApiServer extends BaseController {
  
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
32
  	@Resource(name = "schoolService")
92455d76   孙向锦   添加更新到服务器
33
  	private SchoolManager schoolService;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
34
35
  
  	@Resource(name = "basestationService")
92455d76   孙向锦   添加更新到服务器
36
  	private BasestationManager basestationService;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
37
38
  
  	@Resource(name = "keypadService")
cb39a12d   孙向锦   更新api接口头信息
39
  	private KeypadManager keypadService;
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
40
41
42
43
  
  	@Resource(name = "feedbackService")
  	private FeedbackManager feedbackService;
  
c83d0804   孙向锦   添加客服反馈
44
45
46
  	@Resource(name = "problemphenomenonService")
  	private ProblemPhenomenonManager problemphenomenonService;
  
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
47
  	@RequestMapping(value = "/school", produces = "application/json;charset=UTF-8")
7db3ebeb   孙向锦   添加一些模块
48
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
49
  	public Object schoolDefault() throws Exception {
7db3ebeb   孙向锦   添加一些模块
50
51
  		return schoolList();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
52
53
  
  	@RequestMapping(value = "/school/list", produces = "application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
54
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
55
  	public Object schoolList() throws Exception {
92455d76   孙向锦   添加更新到服务器
56
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
57
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
58
  		if (id != null && !"".equals(id)) {
92455d76   孙向锦   添加更新到服务器
59
  			PageData ret = schoolService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
60
61
62
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
63
  		} else {
92455d76   孙向锦   添加更新到服务器
64
  			List<PageData> ret = schoolService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
65
66
67
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
68
  		}
cb39a12d   孙向锦   更新api接口头信息
69
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
70
71
  
  	@RequestMapping(value = "/school/add", produces = "application/json;charset=UTF-8")
cb39a12d   孙向锦   更新api接口头信息
72
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
73
  	public Object schoolAdd() throws Exception {
cb39a12d   孙向锦   更新api接口头信息
74
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
75
  		ResponseGson<Integer> res = new ResponseGson();
cb39a12d   孙向锦   更新api接口头信息
76
  		try {
b980d59d   孙向锦   修改模板
77
78
79
  			if (pd.get("NAME") != null) {
  				Integer id = schoolService.save(pd);
  				res.setData(id);
cb39a12d   孙向锦   更新api接口头信息
80
81
82
  			} else {
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
83
  		} catch (Exception e) {
cb39a12d   孙向锦   更新api接口头信息
84
85
86
87
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
88
89
  
  	@RequestMapping(value = "/school/delete", produces = "application/json;charset=UTF-8")
cb39a12d   孙向锦   更新api接口头信息
90
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
91
  	public Object schoolDelete() throws Exception {
cb39a12d   孙向锦   更新api接口头信息
92
93
  		ResponseGson<PageData> res = new ResponseGson();
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
94
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
95
  		if (id != null && !"".equals(id)) {
b980d59d   孙向锦   修改模板
96
97
98
99
100
  			try {
  				schoolService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
101
  		} else {
cb39a12d   孙向锦   更新api接口头信息
102
103
104
105
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
106
107
  
  	@RequestMapping(value = "/school/update", produces = "application/json;charset=UTF-8")
cb39a12d   孙向锦   更新api接口头信息
108
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
109
  	public Object schoolUpdate() throws Exception {
cb39a12d   孙向锦   更新api接口头信息
110
111
  		ResponseGson<PageData> res = new ResponseGson();
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
112
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
113
  		if (id != null && !"".equals(id)) {
b980d59d   孙向锦   修改模板
114
115
116
117
118
  			try {
  				schoolService.edit(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
119
  		} else {
cb39a12d   孙向锦   更新api接口头信息
120
121
122
  			res.setDataError();
  		}
  		return res.toJson();
92455d76   孙向锦   添加更新到服务器
123
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
124
125
  
  	@RequestMapping(value = "/basestation/list", produces = "application/json;charset=UTF-8")
92455d76   孙向锦   添加更新到服务器
126
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
127
  	public Object basestation() throws Exception {
92455d76   孙向锦   添加更新到服务器
128
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
129
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
130
  		if (id != null && !"".equals(id)) {
92455d76   孙向锦   添加更新到服务器
131
132
  			pd.put("BASESTATION_ID", pd.getString("id"));
  			PageData ret = basestationService.findById(pd);
cb39a12d   孙向锦   更新api接口头信息
133
134
135
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
136
  		} else {
92455d76   孙向锦   添加更新到服务器
137
  			List<PageData> ret = basestationService.listAll(pd);
cb39a12d   孙向锦   更新api接口头信息
138
139
140
141
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
  		}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
142
  
cb39a12d   孙向锦   更新api接口头信息
143
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
144
145
  
  	@RequestMapping(value = "/basestation/add", produces = "application/json;charset=UTF-8")
b980d59d   孙向锦   修改模板
146
147
148
149
150
151
152
153
154
155
  	@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();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
156
  		} else {
b980d59d   孙向锦   修改模板
157
158
159
160
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
161
162
  
  	@RequestMapping(value = "/basestation/delete", produces = "application/json;charset=UTF-8")
b980d59d   孙向锦   修改模板
163
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
164
  	public Object basestationDelete() throws Exception {
b980d59d   孙向锦   修改模板
165
166
167
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
168
  		if (id != null && !"".equals(id)) {
b980d59d   孙向锦   修改模板
169
170
171
172
173
  			try {
  				basestationService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
174
  		} else {
b980d59d   孙向锦   修改模板
175
176
177
178
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
179
180
  
  	@RequestMapping(value = "/basestation/update", produces = "application/json;charset=UTF-8")
b980d59d   孙向锦   修改模板
181
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
182
  	public Object basestationUpdate() throws Exception {
b980d59d   孙向锦   修改模板
183
184
185
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
186
  		if (id != null && !"".equals(id)) {
b980d59d   孙向锦   修改模板
187
188
189
190
191
  			try {
  				basestationService.edit(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
192
  		} else {
b980d59d   孙向锦   修改模板
193
194
195
196
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
197
198
  
  	@RequestMapping(value = "/keypad/list", produces = "application/json;charset=UTF-8")
cb39a12d   孙向锦   更新api接口头信息
199
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
200
  	public Object keypad() throws Exception {
cb39a12d   孙向锦   更新api接口头信息
201
  		PageData pd = this.getPageData();
b980d59d   孙向锦   修改模板
202
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
203
  		if (id != null && !"".equals(id)) {
cb39a12d   孙向锦   更新api接口头信息
204
205
206
207
  			PageData ret = keypadService.findById(pd);
  			ResponseGson<PageData> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
208
  		} else {
cb39a12d   孙向锦   更新api接口头信息
209
210
211
212
  			List<PageData> ret = keypadService.listAll(pd);
  			ResponseGson<List<PageData>> res = new ResponseGson();
  			res.setData(ret);
  			return res.toJson();
92455d76   孙向锦   添加更新到服务器
213
  		}
92455d76   孙向锦   添加更新到服务器
214
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
215
216
  
  	@RequestMapping(value = "/keypad/add", produces = "application/json;charset=UTF-8")
b980d59d   孙向锦   修改模板
217
218
219
220
221
222
223
224
225
226
227
  	@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();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
228
229
  
  	@RequestMapping(value = "/keypad/delete", produces = "application/json;charset=UTF-8")
b980d59d   孙向锦   修改模板
230
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
231
  	public Object keypadDelete() throws Exception {
b980d59d   孙向锦   修改模板
232
233
234
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
235
  		if (id != null && !"".equals(id)) {
b980d59d   孙向锦   修改模板
236
237
238
239
240
  			try {
  				keypadService.delete(pd);
  			} catch (Exception e) {
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
241
  		} else {
b980d59d   孙向锦   修改模板
242
243
244
245
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
246
247
  
  	@RequestMapping(value = "/keypad/update", produces = "application/json;charset=UTF-8")
b980d59d   孙向锦   修改模板
248
  	@ResponseBody
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
249
  	public Object keypadUpdate() throws Exception {
b980d59d   孙向锦   修改模板
250
251
252
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String id = pd.getString("ID");
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
253
254
  		if (id != null && !"".equals(id)) {
  			try {
b980d59d   孙向锦   修改模板
255
  				keypadService.edit(pd);
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
256
  			} catch (Exception ex) {
b980d59d   孙向锦   修改模板
257
258
  				res.setDataError();
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
259
  		} else {
b980d59d   孙向锦   修改模板
260
261
262
263
  			res.setDataError();
  		}
  		return res.toJson();
  	}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
264
265
266
267
268
269
270
271
272
  
  	@RequestMapping(value = "/feedback/add", produces = "application/json;charset=UTF-8")
  	@ResponseBody
  	public Object feedbackAdd(MultipartFile file, HttpServletRequest request)
  			throws Exception {
  		PageData pd = this.getPageData();
  		ResponseGson<PageData> res = new ResponseGson();
  		String path = request.getSession().getServletContext()
  				.getRealPath("/images");
c83d0804   孙向锦   添加客服反馈
273
274
275
276
277
  		File pathFile = new File(path);
  		if(!pathFile.exists()){
  			pathFile.mkdirs();
  		}
  		logger.info(path);
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
278
279
280
281
282
283
284
  		if (file != null) {
  			String fileName = file.getOriginalFilename();
  			File dir = new File(path, Tools.date2Str(new Date()) + fileName);
  			if (!dir.exists()) {
  				dir.mkdirs();
  			}
  			file.transferTo(dir);
c83d0804   孙向锦   添加客服反馈
285
  
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
286
  			pd.put("PROBLEM_PATH", dir.getAbsolutePath());
c83d0804   孙向锦   添加客服反馈
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  			logger.info(dir.getAbsolutePath());
  		} else {
  			if (pd.get("PROBLEM_PATH") != null) {
  				String imgStr = pd.getString("PROBLEM_PATH");
  				String[] content = imgStr.split(";base64,");
  				if (content.length >= 2) {
  					String fileType = ".file";
  					if (content[0].contains("image")) {
  						fileType = content[0].substring(11,content[0].length());
  					}
  					File dir = new File(path + File.separator +  "fb_"
  							+ System.currentTimeMillis() + "." + fileType);
  					if (!dir.exists()) {
  						dir.createNewFile();
  					}
  					generateImage(content[1], dir.getAbsolutePath());
  					pd.put("PROBLEM_PATH", dir.getAbsolutePath());
  				}
  			}
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
306
307
308
309
  		}
  		String id = pd.getString("ID");
  		if (id != null && !"".equals(id)) {
  			try {
c83d0804   孙向锦   添加客服反馈
310
  				logger.info(pd);
6cdfeaf1   孙向锦   修改相关信息,添加反馈模块
311
312
313
314
315
316
317
318
319
320
321
322
323
324
  				feedbackService.edit(pd);
  			} catch (Exception ex) {
  				res.setDataError();
  			}
  		} else {
  			pd.put("CREATE_DATE", Tools.date2Str(new Date()));
  			try {
  				feedbackService.save(pd);
  			} catch (Exception ex) {
  				res.setDataError();
  			}
  		}
  		return res.toJson();
  	}
c83d0804   孙向锦   添加客服反馈
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
  
  	@RequestMapping(value = "/problem", produces = "application/json;charset=UTF-8")
  	@ResponseBody
  	public Object problem() throws Exception {
  		PageData pd = getPageData();
  		List<PageData> ret = null;
  		if (pd.get("TYPE") != null && !"".equals(pd.get("TYPE"))) {
  			ret = problemphenomenonService.listAllByType(pd);
  		} else {
  			ret = problemphenomenonService.listAll(pd);
  		}
  		ResponseGson<List<PageData>> res = new ResponseGson();
  		res.setData(ret);
  		return res.toJson();
  	}
  
  	public static boolean generateImage(String imgStr, String path) {
  		if (imgStr == null)
  			return false;
  		BASE64Decoder decoder = new BASE64Decoder();
  		try {
  			byte[] b = decoder.decodeBuffer(imgStr);
  			// 处理数据
  			for (int i = 0; i < b.length; ++i) {
  				if (b[i] < 0) {
  					b[i] += 256;
  				}
  			}
  			OutputStream out = new FileOutputStream(path);
  			out.write(b);
  			out.flush();
  			out.close();
  			return true;
  		} catch (Exception e) {
  			return false;
  		}
  	}
92455d76   孙向锦   添加更新到服务器
362
  }