LineController.java
3.55 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
118
119
120
121
122
123
124
125
126
package com.bsth.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.LineVersions;
import com.bsth.service.LineService;
import com.bsth.service.LineVersionsService;
import com.bsth.util.GetUIDAndCode;
/**
*
* @ClassName: LineController(线路控制器)
*
* @Extends : BaseController
*
* @Description: TODO(线路控制层)
*
* @Author bsth@lq
*
* @Date 2016年4月28日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@RestController
@RequestMapping("line")
public class LineController extends BaseController<Line, Integer> {
@Autowired
private LineService service;
@Autowired
private LineVersionsService lineVersionsService;
/**
* 获取线路编码与ID
*
* @return int <lineCode:线路编码>
*/
@RequestMapping(value = "getLineCode", method = RequestMethod.GET)
public long getLineCode() {
return GetUIDAndCode.getLineId();
}
/**
* 验证线路编码是否存在
*
* @return Map < {valid: true }:是否通过验证>
*/
@RequestMapping(value = "lineCodeVerification", method = RequestMethod.GET)
public String lineCodeVerification(@RequestParam(defaultValue = "lineCode") String lineCode) {
return service.lineCodeVerification(lineCode);
}
/**
*
* 保存
*
*/
@RequestMapping(method = RequestMethod.POST)
public Map<String, Object> save(Line t){
Map<String, Object> map = new HashMap<>();
if(t.getId()==null) {
t.setId(Integer.valueOf(t.getLineCode()));
}
if( (t.getId().toString().length()) > 6 || service.lineCodeVerification(t.getLineCode()).equals("false") ) {
map.put("status", ResponseCode.ERROR);
return map;
}
// 添加线路版本
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date endDate = simpleDateFormat.parse("2088-08-08 00:00:00");
LineVersions lineVersions = new LineVersions();
lineVersions.setName("原始版本");
lineVersions.setLine(t);
lineVersions.setLineCode(t.getLineCode());
lineVersions.setStartDate(t.getCreateDate());
lineVersions.setEndDate(new java.sql.Date(endDate.getTime()));// 2088-8-8 00:00:00
lineVersions.setVersions(1);
lineVersions.setStatus(1);
// 先添加线路再添加版本
service.save(t);
return lineVersionsService.save(lineVersions);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
map.put("status", ResponseCode.ERROR);
return map;
}
}
/**
* 更改
*/
@RequestMapping(value="/update", method = RequestMethod.POST)
public Map<String, Object> update(Line l){
Map<String, Object> map = new HashMap<>();
if((l.getId().toString().length()) > 6 || service.lineCodeVerification(l.getLineCode()).equals("true") ) {
map.put("status", ResponseCode.ERROR);
return map;
}
return service.update(l);
}
@RequestMapping(value ="/findById" , method = RequestMethod.GET)
Line findByID(@RequestParam(defaultValue = "id") Integer id){
return service.findById(id);
}
}