NoticeController.java
4.42 KB
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
package com.bsth.controller.realcontrol;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.data.BasicData;
import com.bsth.data.notice.NoticeService;
import com.bsth.data.notice.entity.Notice;
import com.bsth.util.SignUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.WebRequest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 公告
*/
@RestController
@RequestMapping("/notice")
public class NoticeController extends BaseController<Notice, Long>{
Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
NoticeService noticeService;
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
//转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
}
@RequestMapping(value = "/findList", method = RequestMethod.GET)
public Map<String, Object> findList(@RequestParam Map<String, String> map) {
return noticeService.findList(map);
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Notice findById(@PathVariable("id") Long id) {
Notice notice = noticeService.findById(id);
return notice;
}
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Map<String, Object> deleteInfo(Notice t) {
Map<String, Object> map = new HashMap<>();
try{
noticeService.deleteInfo(t);
map.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
log.error(e.toString(), e);
map.put("status", ResponseCode.ERROR);
}
return map;
}
@RequestMapping(method = RequestMethod.POST)
public Map<String, Object> save(Notice t) {
Map<String, Object> map = new HashMap<>();
try{
t.setNOTICE_XLNAME(BasicData.lineCode2NameMap.get(t.getNOTICE_XL()));
t.setNOTICE_STATIONNAME(BasicData.stationCode2NameMap.get(t.getNOTICE_XL()+"_"+t.getNOTICE_XSFX()+"_"+t.getNOTICE_STATION()));
t.setCREATE_BY(t.getNOTICE_BBR());
t.setUPDATE_BY(t.getNOTICE_BBR());
noticeService.save(t);
map.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
log.error(e.toString(), e);
map.put("status", ResponseCode.ERROR);
}
return map;
}
@RequestMapping(value = "/getNotice", method = RequestMethod.POST)
public Map<String, Object> getNotice(@RequestBody JSONObject jsonObject) {
Map<String, Object> map = new HashMap<>();
Map<String, String> params = new HashMap<>();
try{
if(!SignUtils.validation(Long.parseLong(jsonObject.getString("timestamp")),jsonObject.getString("sign"))){
map.put("status", "验证失败");
return map;
}
StringBuffer stations=new StringBuffer();
StringBuffer lineCodes=new StringBuffer();
JSONArray jsonArray = jsonObject.getJSONArray("stations");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject line=jsonArray.getJSONObject(i);
String lineCode = line.get("lineCode").toString();
String stationCode = line.get("stationCode").toString();
stations.append(stationCode+",");
lineCodes.append(lineCode+",");
}
params.put("stations",stations.toString().substring(0,stations.toString().length()-1));
params.put("lineCodes",lineCodes.toString().substring(0,lineCodes.toString().length()-1));
return noticeService.getNotice(params);
} catch (Exception e) {
log.error(e.toString(), e);
map.put("status", ResponseCode.ERROR);
return map;
}
}
}