ODServiceImpl.java
3.56 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
package com.bsth.service.od.impl;
import com.bsth.data.gpsdata_v2.entity.PreconditionGeo;
import com.bsth.entity.Kl;
import com.bsth.entity.LineVersions;
import com.bsth.entity.LsStationRoute;
import com.bsth.entity.od.OdMatchData;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.LineVersionsRepository;
import com.bsth.repository.LsStationRouteRepository;
import com.bsth.repository.RefuelRepository;
import com.bsth.service.Kl.KlService;
import com.bsth.service.od.ODService;
import com.bsth.util.db.DBUtils_MS;
import com.bsth.util.db.DBUtils_PassengerFlow;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ODServiceImpl implements ODService {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private RefuelRepository repository;
@Autowired
private LineVersionsRepository lineVersionsRepository;
@Autowired
private LsStationRouteRepository lsStationRouteRepository;
public Map<String,Object> a(String lineCode,int dir,String date){
Map<String,Object> result=new HashMap<>();
List<String> stations=new ArrayList<>();
LineVersions version = lineVersionsRepository.findLineVersionsByLineAndDate(lineCode,Timestamp.valueOf(LocalDate.parse(date).atStartOfDay()).getTime()/1000);
List<LsStationRoute> stationRoutes=lsStationRouteRepository.findByLineVersion(version.getLine().getId(),version.getVersions(),dir);
for (LsStationRoute stationRoute : stationRoutes) {
stations.add(stationRoute.getStationName());
}
result.put("stations",stations);
String end=LocalDate.parse(date).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_PassengerFlow.getDataSource());
String sql="select line_code lineCode,plate_number plateNumber,up_io_time upIoTime,up_station_code upStationCode,down_station_code downStationCode," +
"up_station_no upStationNo,down_station_no downStationNo from t_passenger_od_match_data " +
"where up_station_no is not null and up_station_no<down_station_no and " +
"up_io_date >='"+date+"' and up_io_date <'"+end+"' and line_code='"+lineCode+"' and up_or_down="+dir;
List<OdMatchData> odMatchDataList=jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(OdMatchData.class));
Map<String,List<OdMatchData>> map=odMatchDataList.stream().collect(Collectors.groupingBy(
odMatchData -> odMatchData.getUpStationNo()+"-"+odMatchData.getDownStationNo()));
List<List<Integer>> l=new ArrayList<>();
map.forEach((k,v)->{
List<Integer> integerList = new ArrayList<>();
integerList.add(Integer.parseInt(k.split("-")[0])-1);
integerList.add(Integer.parseInt(k.split("-")[1])-1);
integerList.add(v.size());
l.add(integerList);
});
result.put("kl",l);
return result;
}
}