LineServiceImpl.java
4.33 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
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
package com.bsth.service.impl;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.repository.LineRepository;
import com.bsth.service.LineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @ClassName: LineServiceImpl(线路service业务层实现类)
*
* @Extends : BaseService
*
* @Description: TODO(线路service业务层)
*
* @Author bsth@lq
*
* @Date 2016年4月28日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@Service
public class LineServiceImpl extends BaseServiceImpl<Line, Integer> implements LineService {
@Autowired
private LineRepository repository;
@Autowired
JdbcTemplate jdbcTemplate;
/**
* 获取线路编码
*
* @return int <lineCode:线路编码>
*/
public long selectMaxIdToLineCode() {
// TODO Auto-generated method stub
return repository.selectMaxIdToLineCode();
}
@Override
public Line findByLineCode(String lineCode) {
return repository.findByLineCode(lineCode);
}
@Override
public Line findById(Integer id) {
// TODO Auto-generated method stub
return repository.findById(id).get();
}
@Override
public String lineCodeVerification(String lineCode) {
String state = "true";
Line line = repository.findByLineCode(lineCode);
if (line != null) {
state = "false";
}
return state;
}
@Transactional
@Override
public Map<String, Object> update(Line l) {
Map<String, Object> map = new HashMap<>();
if(l.getDestroy() == 0){
l.setInUse(1);
} else
l.setInUse(0);
int status = repository.update(l.getName(), l.getCompany(), l.getBrancheCompany(), l.getLevel(), l.getNature(),
l.getStartStationName(), l.getEndStationName(), l.getStartStationFirstTime(),
l.getStartStationEndTime(), l.getEndStationFirstTime(), l.getEndStationEndTime(), l.getLinePlayType(),
l.getOpenDate(), l.getEs(), l.getShortName(), l.getShanghaiLinecode(), l.getEqLinecode(),
l.getStartPhone(), l.getEndPhone(), l.getCarSumNumber(), l.getHvacCarNumber(), l.getOrdCarNumber(),
l.getHistory(), l.getDescriptions(), l.getDestroy(), l.getSupperLine(), l.getSpacGrade(),
l.getWarrantCar(), l.getLineCode(), l.getRegion(),l.getInUse(),l.getTicketPrice());
if (status==1) {
map.put("status", ResponseCode.SUCCESS);
} else {
map.put("status", ResponseCode.ERROR);
}
return map;
}
@Override
public Map<String, Object> remove(Integer id) {
Map<String, Object> map = new HashMap<>();
try{
if(null == id){
map.put("status", ResponseCode.ERROR);
map.put("msg", "$$$$$${txt-2425}");
return map;
}
int destroy = jdbcTemplate.queryForObject("select destroy from bsth_c_line where id=" + id, Integer.class);
if(destroy==0){
map.put("status", ResponseCode.ERROR);
map.put("msg", "你只能删除已撤销的线路!");
return map;
}
jdbcTemplate.update("update bsth_c_line set `remove`=1 where id=?", id);
map.put("status", ResponseCode.SUCCESS);
}catch (Exception e){
logger.error("", e);
map.put("status", ResponseCode.ERROR);
map.put("msg", e.getMessage());
}
return map;
}
/*获取线路性质*/
@Override
public Map<String, Boolean> lineNature() {
// TODO Auto-generated method stub
// List<Line> lineList=repository.findLineBygsBm(gsBm, fgsBm, line);
String sql="select * from bsth_c_line ";
List<Line> lineList=jdbcTemplate.query(sql,
new RowMapper<Line>(){
@Override
public Line mapRow(ResultSet rs, int rowNum) throws SQLException {
Line l=new Line();
l.setLineCode(rs.getString("line_code"));
l.setNature(rs.getString("nature"));
return l;
}
});
Map<String, Boolean> map=new HashMap<String,Boolean>();
for (int i = 0; i < lineList.size(); i++) {
Line t=lineList.get(i);
String nature=t.getNature()==null?"":t.getNature();
if(nature.equals("yxl")||nature.equals("cgxl")||nature.equals("gjxl")
||nature.equals("csbs")||nature.equals("cctxl")){
map.put(t.getLineCode(), true);
}else{
map.put(t.getLineCode(), false);
}
}
return map;
}
}