LineVersionsServiceImpl.java
9.38 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
package com.bsth.service.impl;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.drools.core.time.impl.PseudoClockScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.LineVersions;
import com.bsth.entity.LsSectionRoute;
import com.bsth.entity.LsStationRoute;
import com.bsth.entity.SectionRoute;
import com.bsth.entity.StationRoute;
import com.bsth.repository.LineRepository;
import com.bsth.repository.LineVersionsRepository;
import com.bsth.repository.LsSectionRouteRepository;
import com.bsth.repository.LsStationRouteRepository;
import com.bsth.service.LineVersionsService;
import com.bsth.service.SectionRouteService;
import com.bsth.service.StationRouteService;
/**
*
* @ClassName: LineVersionsServiceImpl(线路service业务层实现类)
*
* @Extends : BaseService
*
* @Description: TODO(线路service业务层)
*
* @Author bsth@lq
*
* @Version 公交调度系统BS版 0.1
*
*/
@Service
public class LineVersionsServiceImpl extends BaseServiceImpl<LineVersions, Integer> implements LineVersionsService{
@Autowired
private LineVersionsRepository repository;
@Autowired
LineRepository lineRepository;
@Autowired
SectionRouteService sectionRouteService;
@Autowired
StationRouteService stationRouteService;
@Autowired
com.bsth.repository.SectionRouteRepository sectionRouteRepository ;
@Autowired
com.bsth.repository.StationRouteRepository stationRouteRepository ;
@Autowired
LsSectionRouteRepository lsSectionRouteRepository ;
@Autowired
LsStationRouteRepository lsStationRouteRepository ;
@Override
public List<LineVersions> findByLineCode(int lineId) {
return repository.findBylineCode(lineId);
}
@Override
public Map<String, Object> update(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<>();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date startDate = simpleDateFormat.parse(map.get("startDate").toString());
Date endDate = simpleDateFormat.parse(map.get("endDate").toString());
Integer id = Integer.valueOf(map.get("Id").toString());
Integer lineid = Integer.valueOf(map.get("lineId").toString());
String lineCode = map.get("lineCode").toString();
Integer versions = Integer.valueOf(map.get("versions").toString());
Integer status = Integer.valueOf(map.get("status").toString());
String remark = map.get("remark").toString();
Line line = lineRepository.findOne(lineid);
int statu = repository.update(id,line,lineCode,new java.sql.Date(startDate.getTime()),
new java.sql.Date(endDate.getTime()),versions,status,remark);
if (statu==1) {
resultMap.put("status", ResponseCode.SUCCESS);
} else {
resultMap.put("status", ResponseCode.ERROR);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
resultMap.put("status", ResponseCode.ERROR);
return resultMap;
}
return resultMap;
}
@Override
public List<LineVersions> findupdated() {
return repository.findupdated();
}
@Autowired
JdbcTemplate jdbcTemplate;
// 线路更新
@Transactional
@Override
public List<LineVersions> lineUpdate() {
List<LineVersions> list = findupdated();
for (LineVersions lineVersions : list) {
Integer lineId = lineVersions.getLine().getId();
String lineCode = lineVersions.getLineCode();
Integer versions = lineVersions.getVersions();
// 需要更新线路的路由
List<LsSectionRoute> lsSectionRoutes = lsSectionRouteRepository.findupdated(lineId, lineCode, versions);
List<LsStationRoute> lsStationRoutes = lsStationRouteRepository.findupdated(lineId, lineCode, versions);
if (lsSectionRoutes.size() != 0 && lsStationRoutes.size() != 0) {
// 更新
final List<SectionRoute> sectionRoutes = JSONArray.parseArray(JSON.toJSONString(lsSectionRoutes), SectionRoute.class);
final List<StationRoute> stationRoutes = JSONArray.parseArray(JSON.toJSONString(lsStationRoutes), StationRoute.class);
//sectionRouteService.batchUpdate(lineId, lineCode);
//sectionRouteRepository.batchDelete(lineId, lineCode);
jdbcTemplate.update("delete from bsth_c_stationroute where line = ? and line_code = ?", lineId, lineCode);
String stationSql ="insert into bsth_c_stationroute(id,line,station,station_name,station_route_code,"
+ "line_code,station_code,station_mark,out_station_nmber,directions,distances,"
+ "to_time,first_time,end_time,descriptions,destroy,versions,create_by,create_date,"
+ "update_by,update_date) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
jdbcTemplate.batchUpdate(stationSql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
StationRoute sRoute = stationRoutes.get(i);
sRoute.getStationRouteCode();
ps.setInt(1, sRoute.getId());
ps.setInt(2, sRoute.getLine().getId());
ps.setInt(3, sRoute.getStation().getId());
ps.setString(4, sRoute.getStationName());
ps.setInt(5, sRoute.getStationRouteCode());
ps.setString(6, sRoute.getLineCode());
ps.setString(7, sRoute.getStationCode());
ps.setString(8, sRoute.getStationMark());
ps.setInt(9, sRoute.getOutStationNmber()==null ? 0:sRoute.getOutStationNmber());
ps.setInt(10, sRoute.getDirections());
ps.setDouble(11, sRoute.getDistances());
ps.setDouble(12, sRoute.getToTime());
ps.setString(13, sRoute.getFirstTime()==null ? "":sRoute.getFirstTime());
ps.setString(14, sRoute.getEndTime()==null ? "":sRoute.getEndTime());
ps.setString(15, sRoute.getDescriptions()==null ? "":sRoute.getDescriptions());
ps.setInt(16, sRoute.getDestroy());
ps.setInt(17, sRoute.getVersions());
ps.setInt(18, sRoute.getCreateBy()==null ? 0:sRoute.getCreateBy());
ps.setDate(19, new java.sql.Date(sRoute.getCreateDate().getTime()));
ps.setInt(20, sRoute.getUpdateBy()==null ? 0:sRoute.getUpdateBy());
ps.setDate(21, new java.sql.Date(sRoute.getUpdateDate().getTime()));
}
@Override
public int getBatchSize() {
// TODO Auto-generated method stub
return stationRoutes.size();
}
} );
jdbcTemplate.update("delete from bsth_c_sectionroute where line = ? and line_code = ?", lineId, lineCode);
String sectionSql ="insert into bsth_c_sectionroute(id,line_code,section_code,sectionroute_code,"
+ "directions,line,section,descriptions,create_by,create_date,update_by,update_date,versions,"
+ "destroy,is_roade_speed) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
jdbcTemplate.batchUpdate(sectionSql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
SectionRoute sRoute = sectionRoutes.get(i);
ps.setInt(1, sRoute.getId());
ps.setString(2, sRoute.getLineCode());
ps.setString(3, sRoute.getSectionCode());
ps.setInt(4, sRoute.getSectionrouteCode());
ps.setInt(5, sRoute.getDirections());
ps.setInt(6, sRoute.getLine().getId());
ps.setInt(7, sRoute.getSection().getId());
ps.setString(8, sRoute.getDescriptions()==null ? "":sRoute.getDescriptions());
ps.setInt(9, sRoute.getCreateBy()==null ? 0:sRoute.getCreateBy());
ps.setDate(10, new java.sql.Date(sRoute.getCreateDate().getTime()));
ps.setInt(11, sRoute.getUpdateBy()==null ? 0:sRoute.getUpdateBy());
ps.setDate(12, new java.sql.Date(sRoute.getUpdateDate().getTime()));
ps.setInt(13, sRoute.getVersions());
ps.setInt(14, sRoute.getDestroy());
ps.setInt(15, sRoute.getIsRoadeSpeed()==null ? 0:sRoute.getIsRoadeSpeed());
}
@Override
public int getBatchSize() {
// TODO Auto-generated method stub
return sectionRoutes.size();
}
} );
/*for (SectionRoute sectionRoute : sectionRoutes) {
sectionRouteService.save(sectionRoute);
}*/
// sectionRouteService.bulkSave(sectionRoutes);
//List<StationRoute> stationRoutes = JSONArray.parseArray(JSON.toJSONString(lsStationRoutes), StationRoute.class);
// stationRouteService.batchUpdate(lineId, lineCode);
//stationRouteRepository.batchDelete(lineId, lineCode);
/*for (StationRoute stationRoute : stationRoutes) {
stationRouteService.save(stationRoute);
}*/
// stationRouteService.bulkSave(stationRoutes);
// 更新线路版本
repository.updateOdlVersions(lineId, lineCode);
repository.updateNewVersions(lineId,lineCode,versions);
}
}
return list;
}
}