Commit 5570148ad9c73241441d61aef00c19ce112fa86c

Authored by yiming
1 parent afdd1ef3

青浦客流

src/main/java/com/example/demo/SaticScheduleTask.java
1 package com.example.demo; 1 package com.example.demo;
2 2
3 3
4 -import cn.hutool.core.io.FileUtil; 4 +
5 import com.example.demo.model.Scheduling; 5 import com.example.demo.model.Scheduling;
6 -import com.example.demo.model.TJRL;  
7 -import com.example.demo.model.TJRLDB;  
8 -import com.example.demo.service.Analysis;  
9 import com.example.demo.service.Contrast; 6 import com.example.demo.service.Contrast;
10 import org.slf4j.Logger; 7 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
12 -import org.springframework.beans.factory.InitializingBean;  
13 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
14 -import org.springframework.beans.factory.annotation.Value;  
15 import org.springframework.context.annotation.Configuration; 10 import org.springframework.context.annotation.Configuration;
16 import org.springframework.scheduling.annotation.EnableScheduling; 11 import org.springframework.scheduling.annotation.EnableScheduling;
17 -import org.springframework.scheduling.annotation.Scheduled;  
18 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
19 -  
20 import javax.annotation.PostConstruct; 13 import javax.annotation.PostConstruct;
21 -import java.io.*;  
22 -import java.nio.file.*;  
23 import java.time.LocalDateTime; 14 import java.time.LocalDateTime;
24 import java.time.format.DateTimeFormatter; 15 import java.time.format.DateTimeFormatter;
25 import java.util.*; 16 import java.util.*;
@@ -34,155 +25,26 @@ public class SaticScheduleTask { @@ -34,155 +25,26 @@ public class SaticScheduleTask {
34 25
35 private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class); 26 private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class);
36 27
37 - @Value("${ftp.root}")  
38 - private String rootPath;  
39 -  
40 - private WatchService watchService;  
41 28
42 @Autowired 29 @Autowired
43 private Contrast contrast; 30 private Contrast contrast;
44 31
45 - @Autowired  
46 - private Analysis analysis;  
47 -  
48 - private static DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");  
49 -  
50 -  
51 -  
52 32
53 - @Scheduled(cron = "0 0/5 * * * ?") 33 + //@Scheduled(cron = "0 0/5 * * * ?")
54 @PostConstruct 34 @PostConstruct
55 void getArrivalInfos(){ 35 void getArrivalInfos(){
56 logger.info("票务数据缓存加载: " + LocalDateTime.now()); 36 logger.info("票务数据缓存加载: " + LocalDateTime.now());
57 try { 37 try {
58 LocalDateTime now=LocalDateTime.now(); 38 LocalDateTime now=LocalDateTime.now();
59 - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1);  
60 - contrast.getSchedulingS=result.get(0);  
61 - contrast.getSchedulingSSell=result.get(1);  
62 - logger.info("===============================数据存放结束,开始读取文件================================");  
63 - DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyyMMdd");  
64 - String date=now.format(dtf);  
65 - System.out.println(rootPath+File.separator+date);  
66 - List<File> files = FileUtil.loopFiles(Paths.get(rootPath+File.separator+date),1,new wdbFileFilter());  
67 - System.out.println("文件数"+files.size());  
68 - logger.info("===============================文件数"+files.size()+",读取文件结束================================");  
69 - //先把处理上一次没匹配到的  
70 - logger.info("===============================处理上次未匹配到的数据"+contrast.oldData.size()+"================================");  
71 - if(!contrast.oldData.isEmpty()){  
72 - contrast.filterCardList(contrast.oldData,true);  
73 - }  
74 - logger.info("===============================文件解析开始================================");  
75 - List<TJRLDB> allFile = analysis.getAllFile(files);  
76 - logger.info("===============================交易数"+allFile.size()+"文件解析结束================================");  
77 - contrast.filterCardList(allFile,false);  
78 - } catch (Exception e) {  
79 - e.printStackTrace();  
80 - }  
81 - }  
82 -  
83 -  
84 -  
85 - void getArrivalInfos2(String date,String path) {  
86 - LocalDateTime now=LocalDateTime.parse(date,tdf);  
87 - logger.info("票务数据缓存加载: " + now);  
88 - try {  
89 - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1);  
90 - contrast.getSchedulingS=result.get(0);  
91 - contrast.getSchedulingSSell=result.get(1);  
92 - List<File> fl= FileUtil.loopFiles(path);  
93 - System.out.println(fl.size());  
94 - List<List<File>> subList=getSubList(100,fl);  
95 - if(!subList.isEmpty()){  
96 - subList.forEach(fs->{  
97 - if (!fs.isEmpty()) {  
98 - System.out.println("文件数"+fs.size());  
99 - try {  
100 - List<TJRLDB> allFile = analysis.getAllFile(fs);  
101 - System.out.println("交易数"+allFile.size());  
102 - contrast.filterCardList(allFile,true);  
103 - } catch (Exception e) {  
104 - e.printStackTrace();  
105 - }  
106 - }  
107 - });  
108 - }  
109 - logger.info("==============================="+now.minusDays(1)+"数据处理完成================================"); 39 + DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  40 + now=LocalDateTime.parse("2024-08-26 00:00",tdf);
  41 + List<Scheduling> result=contrast.getSchedulingS(now,1);
  42 + contrast.getStationRoutes();
  43 + System.out.println(result.size());
110 } catch (Exception e) { 44 } catch (Exception e) {
111 e.printStackTrace(); 45 e.printStackTrace();
112 } 46 }
113 } 47 }
114 48
115 - //@PostConstruct  
116 - void processingHistory(){  
117 - getArrivalInfos2("2022-11-22 00:00","/home/oldFile/20221121");  
118 - //getArrivalInfos2("2022-11-23 00:00","/home/oldFile/20221122");  
119 - }  
120 -  
121 - /**  
122 - * @Description: 用来计算数据库中的乘车记录  
123 - * @Param:  
124 - * @return:  
125 - * @Author: YM  
126 - * @Date: 2021/10/13  
127 - */  
128 - //@PostConstruct  
129 - private void filterCardListByDB() throws Exception {  
130 - DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");  
131 - LocalDateTime now=LocalDateTime.parse("2021-08-07 00:00",tdf);  
132 -  
133 - int day=1;  
134 - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,day);  
135 - contrast.getSchedulingS=result.get(0);  
136 - contrast.getSchedulingSSell=result.get(1);  
137 - Map<String,Object> map=new HashMap<>();  
138 - map.put("table","pd_control."+"fhtxnjrltb_jtb_copy1");  
139 - LocalDateTime startDate=now.minusDays(day);  
140 - String start=startDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));  
141 - String end=now.format(DateTimeFormatter.ofPattern("yyyyMMdd"));  
142 - map.put("start",start);  
143 - map.put("end",end);  
144 - contrast.filterCardListByDB(map);  
145 - }  
146 -  
147 -  
148 -  
149 -  
150 - public List<List<File>> getSubList(int length, List<File> list){  
151 - int size = list.size();  
152 - int temp = size / length + 1;  
153 - boolean result = size % length == 0;  
154 - List<List<File>> subList = new ArrayList<>();  
155 - for (int i = 0; i < temp; i++) {  
156 - if (i == temp - 1) {  
157 - if (result) {  
158 - break;  
159 - }  
160 - subList.add(list.subList(length * i, size)) ;  
161 - } else {  
162 - subList.add(list.subList(length * i, length * (i + 1))) ;  
163 - }  
164 - }  
165 - return subList;  
166 - }  
167 -  
168 -  
169 - public static class wdbFileFilter implements FileFilter {  
170 - @Override  
171 - public boolean accept(File file) {  
172 - if(file.isDirectory())  
173 - return false;  
174 - String name = file.getName();  
175 - if(name.endsWith(".wdb")) //mp3则返回true  
176 - return true;  
177 - return false;  
178 - }  
179 - }  
180 -  
181 - public static void main(String[] args) {  
182 - List<File> files = FileUtil.loopFiles(Paths.get("E:\\sftp\\home\\sftp\\20220725"),1,new wdbFileFilter());  
183 - files.forEach(file->{  
184 - System.out.println(file.getName());  
185 - });  
186 - }  
187 49
188 } 50 }
189 \ No newline at end of file 51 \ No newline at end of file
src/main/java/com/example/demo/mapper/db1/SiteMapper1.java
@@ -15,18 +15,13 @@ import java.util.Map; @@ -15,18 +15,13 @@ import java.util.Map;
15 public interface SiteMapper1 { 15 public interface SiteMapper1 {
16 16
17 17
18 - @DS("db1")  
19 - void insertResult(List<TJRLDB> list);  
20 18
21 @DS("db1") 19 @DS("db1")
22 - List<Scheduling> getScheduling(Map<String, Object> map);  
23 -  
24 - /* @DS("db2")  
25 - List<ArrivalInfo> getArrivalInfo(Map<String, Object> map);*/ 20 + List<Scheduling> getScheduling(String date);
26 21
27 @DS("db1") 22 @DS("db1")
28 List<StationRoute> getStationRoute(); 23 List<StationRoute> getStationRoute();
29 24
30 @DS("db1") 25 @DS("db1")
31 - List<TJRLDB> getRecords(Map<String, Object> map); 26 + String getMaxTime(String date);
32 } 27 }
33 \ No newline at end of file 28 \ No newline at end of file
src/main/java/com/example/demo/model/InOutStation.java 0 → 100644
  1 +package com.example.demo.model;
  2 +
  3 +import java.time.LocalDateTime;
  4 +import java.time.ZoneOffset;
  5 +import java.time.format.DateTimeFormatter;
  6 +
  7 +public class InOutStation {
  8 + private String stop_no;
  9 + private String inTime;
  10 + private String outTime;
  11 + private String inTimeStr;
  12 + private String outTimeStr;
  13 + private String stationRouteCode;
  14 + private String stationName;
  15 +
  16 +
  17 + public String getStop_no() {
  18 + return stop_no;
  19 + }
  20 +
  21 + public void setStop_no(String stop_no) {
  22 + this.stop_no = stop_no;
  23 + }
  24 +
  25 + public String getInTime() {
  26 + return inTime;
  27 + }
  28 +
  29 + public void setInTime(String inTime) {
  30 + this.inTime = inTime;
  31 + LocalDateTime localDateTime=LocalDateTime.ofEpochSecond(Long.parseLong(inTime)/1000,0, ZoneOffset.of("+8"));
  32 + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmmss");
  33 + this.inTimeStr = localDateTime.format(dtf);
  34 + }
  35 +
  36 + public String getOutTime() {
  37 + return outTime;
  38 + }
  39 +
  40 + public void setOutTime(String outTime) {
  41 + this.outTime = outTime;
  42 + LocalDateTime localDateTime=LocalDateTime.ofEpochSecond(Long.parseLong(outTime)/1000,0, ZoneOffset.of("+8"));
  43 + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmmss");
  44 + this.outTimeStr = localDateTime.format(dtf);
  45 + }
  46 +
  47 + public String getStationRouteCode() {
  48 + return stationRouteCode;
  49 + }
  50 +
  51 + public void setStationRouteCode(String stationRouteCode) {
  52 + this.stationRouteCode = stationRouteCode;
  53 + }
  54 +
  55 + public String getStationName() {
  56 + return stationName;
  57 + }
  58 +
  59 + public void setStationName(String stationName) {
  60 + this.stationName = stationName;
  61 + }
  62 +
  63 + public String getInTimeStr() {
  64 + return inTimeStr;
  65 + }
  66 +
  67 +
  68 +
  69 + public String getOutTimeStr() {
  70 + return outTimeStr;
  71 + }
  72 +
  73 +}
src/main/java/com/example/demo/model/Scheduling.java
1 package com.example.demo.model; 1 package com.example.demo.model;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.Collections;  
5 import java.util.List; 3 import java.util.List;
6 4
7 //bsth_c_s_sp_info_real和 bsth_c_cars 5 //bsth_c_s_sp_info_real和 bsth_c_cars
8 public class Scheduling implements Comparable<Scheduling> ,Cloneable{ 6 public class Scheduling implements Comparable<Scheduling> ,Cloneable{
9 - private String gs_name;  
10 - private String xl_name;  
11 - private String j_gh;//驾驶员工号  
12 - private String j_name;//驾驶员名字  
13 private String schedule_date_str;//日期 7 private String schedule_date_str;//日期
14 - private String xl_bm;  
15 - private String xl_dir;  
16 - private String bc_type; 8 + private String equipment_code;//设备号
17 private String cl_zbh;//车辆编号 9 private String cl_zbh;//车辆编号
18 - private String lp_name; 10 + private String gs_bm;//公司编码
  11 + private String j_gh;//驾驶员工号
  12 + private String xl_bm;//线路编码
  13 + private String car_plate;//车牌
  14 + private String xl_dir;//上下行
19 private String qdz_name; 15 private String qdz_name;
20 private String qdz_code; 16 private String qdz_code;
21 - private String fcsj_actual;//实际发车时间  
22 private String zdz_name; 17 private String zdz_name;
23 private String zdz_code; 18 private String zdz_code;
  19 + private String xl_name;
  20 + private String fcsj_actual;//实际发车时间
24 private String zdsj_actual;//实际到达时间 21 private String zdsj_actual;//实际到达时间
25 - private String equipment_code;  
26 - private String car_plate;  
27 - private String stop_no;  
28 - private String up_down;  
29 - private String line_id;  
30 - private String real_exec_date;  
31 - private String ts;  
32 - private String ts_out;  
33 - private String station_route_code;  
34 - private String station_name;  
35 - private String station_code;  
36 - private String s_gh;//售票员员工号  
37 - private String s_name;//售票员名字 22 + private String shanghai_linecode;
38 23
39 - public String getS_gh() {  
40 - return s_gh;  
41 - } 24 + private List<InOutStation> inOutStations;
42 25
43 - public void setS_gh(String s_gh) {  
44 - this.s_gh = s_gh;  
45 - }  
46 26
47 - public String getS_name() {  
48 - return s_name;  
49 - }  
50 27
51 - public void setS_name(String s_name) {  
52 - this.s_name = s_name; 28 + public String getGs_bm() {
  29 + return gs_bm;
53 } 30 }
54 31
55 - public String getGs_name() {  
56 - return gs_name;  
57 - }  
58 -  
59 - public void setGs_name(String gs_name) {  
60 - this.gs_name = gs_name; 32 + public void setGs_bm(String gs_bm) {
  33 + this.gs_bm = gs_bm;
61 } 34 }
62 35
63 public String getXl_name() { 36 public String getXl_name() {
@@ -76,8 +49,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{ @@ -76,8 +49,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{
76 this.j_gh = j_gh; 49 this.j_gh = j_gh;
77 } 50 }
78 51
79 -  
80 -  
81 public String getXl_bm() { 52 public String getXl_bm() {
82 return xl_bm; 53 return xl_bm;
83 } 54 }
@@ -94,14 +65,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{ @@ -94,14 +65,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{
94 this.xl_dir = xl_dir; 65 this.xl_dir = xl_dir;
95 } 66 }
96 67
97 - public String getBc_type() {  
98 - return bc_type;  
99 - }  
100 -  
101 - public void setBc_type(String bc_type) {  
102 - this.bc_type = bc_type;  
103 - }  
104 -  
105 public String getCl_zbh() { 68 public String getCl_zbh() {
106 return cl_zbh; 69 return cl_zbh;
107 } 70 }
@@ -110,14 +73,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{ @@ -110,14 +73,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{
110 this.cl_zbh = cl_zbh; 73 this.cl_zbh = cl_zbh;
111 } 74 }
112 75
113 - public String getLp_name() {  
114 - return lp_name;  
115 - }  
116 -  
117 - public void setLp_name(String lp_name) {  
118 - this.lp_name = lp_name;  
119 - }  
120 -  
121 public String getQdz_name() { 76 public String getQdz_name() {
122 return qdz_name; 77 return qdz_name;
123 } 78 }
@@ -182,14 +137,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{ @@ -182,14 +137,6 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{
182 this.car_plate = car_plate; 137 this.car_plate = car_plate;
183 } 138 }
184 139
185 - public String getJ_name() {  
186 - return j_name;  
187 - }  
188 -  
189 - public void setJ_name(String j_name) {  
190 - this.j_name = j_name;  
191 - }  
192 -  
193 public String getSchedule_date_str() { 140 public String getSchedule_date_str() {
194 return schedule_date_str; 141 return schedule_date_str;
195 } 142 }
@@ -198,108 +145,41 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{ @@ -198,108 +145,41 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{
198 this.schedule_date_str = schedule_date_str; 145 this.schedule_date_str = schedule_date_str;
199 } 146 }
200 147
201 - public String getStop_no() {  
202 - return stop_no;  
203 - }  
204 -  
205 - public void setStop_no(String stop_no) {  
206 - this.stop_no = stop_no;  
207 - }  
208 -  
209 - public String getUp_down() {  
210 - return up_down;  
211 - }  
212 -  
213 - public void setUp_down(String up_down) {  
214 - this.up_down = up_down;  
215 - }  
216 -  
217 - public String getLine_id() {  
218 - return line_id; 148 + public List<InOutStation> getInOutStations() {
  149 + return inOutStations;
219 } 150 }
220 151
221 - public void setLine_id(String line_id) {  
222 - this.line_id = line_id; 152 + public void setInOutStations(List<InOutStation> inOutStations) {
  153 + this.inOutStations = inOutStations;
223 } 154 }
224 155
225 - public String getReal_exec_date() {  
226 - return real_exec_date; 156 + public String getShanghai_linecode() {
  157 + return shanghai_linecode;
227 } 158 }
228 159
229 - public void setReal_exec_date(String real_exec_date) {  
230 - this.real_exec_date = real_exec_date;  
231 - }  
232 -  
233 - public String getTs() {  
234 - return ts;  
235 - }  
236 -  
237 - public void setTs(String ts) {  
238 - this.ts = ts;  
239 - }  
240 -  
241 - public String getTs_out() {  
242 - return ts_out;  
243 - }  
244 -  
245 - public void setTs_out(String ts_out) {  
246 - this.ts_out = ts_out;  
247 - }  
248 -  
249 - public String getStation_route_code() {  
250 - return station_route_code;  
251 - }  
252 -  
253 - public void setStation_route_code(String station_route_code) {  
254 - this.station_route_code = station_route_code;  
255 - }  
256 -  
257 - public String getStation_name() {  
258 - return station_name;  
259 - }  
260 -  
261 - public void setStation_name(String station_name) {  
262 - this.station_name = station_name;  
263 - }  
264 -  
265 - public String getStation_code() {  
266 - return station_code;  
267 - }  
268 -  
269 - public void setStation_code(String station_code) {  
270 - this.station_code = station_code; 160 + public void setShanghai_linecode(String shanghai_linecode) {
  161 + this.shanghai_linecode = shanghai_linecode;
271 } 162 }
272 163
273 @Override 164 @Override
274 public String toString() { 165 public String toString() {
275 return "Scheduling{" + 166 return "Scheduling{" +
276 - "gs_name='" + gs_name + '\'' +  
277 - ", xl_name='" + xl_name + '\'' + 167 + "schedule_date_str='" + schedule_date_str + '\'' +
  168 + ", equipment_code='" + equipment_code + '\'' +
  169 + ", cl_zbh='" + cl_zbh + '\'' +
  170 + ", gs_name='" + gs_bm + '\'' +
278 ", j_gh='" + j_gh + '\'' + 171 ", j_gh='" + j_gh + '\'' +
279 - ", j_name='" + j_name + '\'' +  
280 - ", schedule_date_str='" + schedule_date_str + '\'' +  
281 ", xl_bm='" + xl_bm + '\'' + 172 ", xl_bm='" + xl_bm + '\'' +
  173 + ", car_plate='" + car_plate + '\'' +
282 ", xl_dir='" + xl_dir + '\'' + 174 ", xl_dir='" + xl_dir + '\'' +
283 - ", bc_type='" + bc_type + '\'' +  
284 - ", cl_zbh='" + cl_zbh + '\'' +  
285 - ", lp_name='" + lp_name + '\'' +  
286 ", qdz_name='" + qdz_name + '\'' + 175 ", qdz_name='" + qdz_name + '\'' +
287 ", qdz_code='" + qdz_code + '\'' + 176 ", qdz_code='" + qdz_code + '\'' +
288 - ", fcsj_actual='" + fcsj_actual + '\'' +  
289 ", zdz_name='" + zdz_name + '\'' + 177 ", zdz_name='" + zdz_name + '\'' +
290 ", zdz_code='" + zdz_code + '\'' + 178 ", zdz_code='" + zdz_code + '\'' +
  179 + ", xl_name='" + xl_name + '\'' +
  180 + ", fcsj_actual='" + fcsj_actual + '\'' +
291 ", zdsj_actual='" + zdsj_actual + '\'' + 181 ", zdsj_actual='" + zdsj_actual + '\'' +
292 - ", equipment_code='" + equipment_code + '\'' +  
293 - ", car_plate='" + car_plate + '\'' +  
294 - ", stop_no='" + stop_no + '\'' +  
295 - ", up_down='" + up_down + '\'' +  
296 - ", line_id='" + line_id + '\'' +  
297 - ", real_exec_date='" + real_exec_date + '\'' +  
298 - ", ts='" + ts + '\'' +  
299 - ", ts_out='" + ts_out + '\'' +  
300 - ", station_route_code='" + station_route_code + '\'' +  
301 - ", station_name='" + station_name + '\'' +  
302 - ", station_code='" + station_code + '\'' + 182 + ", inOutStations=" + inOutStations +
303 '}'; 183 '}';
304 } 184 }
305 185
@@ -325,19 +205,4 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{ @@ -325,19 +205,4 @@ public class Scheduling implements Comparable&lt;Scheduling&gt; ,Cloneable{
325 return super.clone(); 205 return super.clone();
326 } 206 }
327 207
328 - public static void main(String[] args) {  
329 - Scheduling scheduling=new Scheduling();  
330 - scheduling.setSchedule_date_str("2021-10-15");  
331 - scheduling.setFcsj_actual("09:10");  
332 - Scheduling scheduling2=new Scheduling();  
333 - scheduling2.setSchedule_date_str("2021-10-14");  
334 - scheduling2.setFcsj_actual("09:11");  
335 - List<Scheduling> list=new ArrayList();  
336 - list.add(scheduling);  
337 - list.add(scheduling2);  
338 - Collections.sort(list);  
339 - System.out.println(list.get(0).getSchedule_date_str()+list.get(0).getFcsj_actual());  
340 - System.out.println(list.get(1).getSchedule_date_str()+list.get(1).getFcsj_actual());  
341 - }  
342 -  
343 } 208 }
src/main/java/com/example/demo/model/SchedulingKFK.java 0 → 100644
  1 +package com.example.demo.model;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class SchedulingKFK{
  6 + private String date;//日期YYYYMMDD
  7 + private String nbbm;//车辆内部编码
  8 + private String deviceID;//车辆内部编码
  9 + private String company;//公司号
  10 + private String driver;//驾驶员工号
  11 + private String lineCode;//上海市线路编码
  12 + private String carPlate;//车牌 例如D12345不带中文
  13 + private String upDown;//上下行 0上行,1下行
  14 + private String qdzName;//起点站名称
  15 + private String qdzCode;//起点站编码
  16 + private String zdzName;//终点站名称
  17 + private String zdzCode;//终点站编码
  18 + private String fcsj;//实际发车时间hhmmss
  19 + private String zdsj;//实际到达时间hhmmss
  20 +
  21 + private List<InOutStation> inOutStations;//进出站信息
  22 +
  23 +
  24 + public static SchedulingKFK getInstance(Scheduling scheduling){
  25 + SchedulingKFK schedulingKFK=new SchedulingKFK();
  26 + schedulingKFK.setDate(scheduling.getSchedule_date_str()!=null?scheduling.getSchedule_date_str().replace("-",""):null);
  27 + schedulingKFK.setNbbm(scheduling.getCl_zbh());
  28 + schedulingKFK.setDeviceID(scheduling.getEquipment_code());
  29 + schedulingKFK.setCompany(scheduling.getGs_bm());
  30 + schedulingKFK.setDriver(scheduling.getJ_gh());
  31 + schedulingKFK.setLineCode(scheduling.getShanghai_linecode());
  32 + schedulingKFK.setCarPlate(scheduling.getCar_plate()!=null?scheduling.getCar_plate().replace("沪",""):null);
  33 + schedulingKFK.setUpDown(scheduling.getXl_dir());
  34 + schedulingKFK.setQdzName(scheduling.getQdz_name());
  35 + schedulingKFK.setQdzCode(scheduling.getQdz_code());
  36 + schedulingKFK.setZdzName(scheduling.getZdz_name());
  37 + schedulingKFK.setZdzCode(scheduling.getZdz_code());
  38 + schedulingKFK.setFcsj(scheduling.getFcsj_actual()!=null?scheduling.getFcsj_actual().replace(":","")+"00":null);
  39 + schedulingKFK.setZdsj(scheduling.getZdsj_actual()!=null?scheduling.getZdsj_actual().replace(":","")+"00":null);
  40 + schedulingKFK.setInOutStations(scheduling.getInOutStations());
  41 + return schedulingKFK;
  42 + }
  43 +
  44 + public String getDeviceID() {
  45 + return deviceID;
  46 + }
  47 +
  48 + public void setDeviceID(String deviceID) {
  49 + this.deviceID = deviceID;
  50 + }
  51 +
  52 + public String getDate() {
  53 + return date;
  54 + }
  55 +
  56 + public void setDate(String date) {
  57 + this.date = date;
  58 + }
  59 +
  60 + public String getNbbm() {
  61 + return nbbm;
  62 + }
  63 +
  64 + public void setNbbm(String nbbm) {
  65 + this.nbbm = nbbm;
  66 + }
  67 +
  68 + public String getCompany() {
  69 + return company;
  70 + }
  71 +
  72 + public void setCompany(String company) {
  73 + this.company = company;
  74 + }
  75 +
  76 + public String getDriver() {
  77 + return driver;
  78 + }
  79 +
  80 + public void setDriver(String driver) {
  81 + this.driver = driver;
  82 + }
  83 +
  84 + public String getLineCode() {
  85 + return lineCode;
  86 + }
  87 +
  88 + public void setLineCode(String lineCode) {
  89 + this.lineCode = lineCode;
  90 + }
  91 +
  92 + public String getCarPlate() {
  93 + return carPlate;
  94 + }
  95 +
  96 + public void setCarPlate(String carPlate) {
  97 + this.carPlate = carPlate;
  98 + }
  99 +
  100 + public String getUpDown() {
  101 + return upDown;
  102 + }
  103 +
  104 + public void setUpDown(String upDown) {
  105 + this.upDown = upDown;
  106 + }
  107 +
  108 + public String getQdzName() {
  109 + return qdzName;
  110 + }
  111 +
  112 + public void setQdzName(String qdzName) {
  113 + this.qdzName = qdzName;
  114 + }
  115 +
  116 + public String getQdzCode() {
  117 + return qdzCode;
  118 + }
  119 +
  120 + public void setQdzCode(String qdzCode) {
  121 + this.qdzCode = qdzCode;
  122 + }
  123 +
  124 + public String getZdzName() {
  125 + return zdzName;
  126 + }
  127 +
  128 + public void setZdzName(String zdzName) {
  129 + this.zdzName = zdzName;
  130 + }
  131 +
  132 + public String getZdzCode() {
  133 + return zdzCode;
  134 + }
  135 +
  136 + public void setZdzCode(String zdzCode) {
  137 + this.zdzCode = zdzCode;
  138 + }
  139 +
  140 + public String getFcsj() {
  141 + return fcsj;
  142 + }
  143 +
  144 + public void setFcsj(String fcsj) {
  145 + this.fcsj = fcsj;
  146 + }
  147 +
  148 + public String getZdsj() {
  149 + return zdsj;
  150 + }
  151 +
  152 + public void setZdsj(String zdsj) {
  153 + this.zdsj = zdsj;
  154 + }
  155 +
  156 + public List<InOutStation> getInOutStations() {
  157 + return inOutStations;
  158 + }
  159 +
  160 + public void setInOutStations(List<InOutStation> inOutStations) {
  161 + this.inOutStations = inOutStations;
  162 + }
  163 +
  164 +}
src/main/java/com/example/demo/model/TJRL.java deleted 100644 → 0
1 -package com.example.demo.model;  
2 -  
3 -import com.fasterxml.jackson.annotation.JsonProperty;  
4 -  
5 -import java.beans.PropertyDescriptor;  
6 -import java.lang.reflect.Field;  
7 -import java.lang.reflect.Method;  
8 -  
9 -public class TJRL implements Cloneable {  
10 -  
11 - private String TJRLCARDNO;// NUMBER Y 交通卡号  
12 - private String TJRLINSID; // NUMBER Y 行业  
13 - private String TJRLCDKIND;// NUMBER Y 卡类型  
14 - private String TJRLPOSID;// NUMBER(10) POS机号  
15 - private String TJRLRDATE;// CHAR(8) Y 交易日期  
16 - private String TJRLRTIME;// CHAR(6) Y 交易时间  
17 - private String TJRLCDBAL;// NUMBER(10) Y 交易前余额  
18 - private String TJRLAMT;// NUMBER(10) Y 交易金额  
19 - private String TJRLORGAMT;// NUMBER(10) Y 交易原始金额  
20 - private String TJRLSTATID;// VARCHAR2(100) Y 公交线路  
21 - private String TJRLUNITID;// VARCHAR2(100) Y 运营单位  
22 - private String TJRLTXFG;// NUMBER Y 交易类型  
23 - private String STATION_FLAG;// VARCHAR2(100) Y 匹配上电子路单:1;匹配不上:0  
24 - private String ROAD_FORM_TYPE;// VARCHAR2(100) Y 路单类型  
25 - private String UPDOWN;// VARCHAR2(100) Y 上下行:0上1下  
26 - private String BUS_CODE;// VARCHAR2(100) Y 车辆自编号  
27 - private String BUS_PLATE;// VARCHAR2(100) Y 车牌号  
28 - private String ROAD_CODE;// VARCHAR2(100) Y 路牌编号  
29 - private String DEPART_NAME;// VARCHAR2(100) Y 发车站点名称  
30 - private String DEPART_CODE;// VARCHAR2(100) Y 发车站点编码  
31 - private String DEPART_ACTUAL_TIME;// VARCHAR2(100) Y 实际发车时间  
32 - private String REACH_NAME;// VARCHAR2(100) Y 到达站点名称  
33 - private String REACH_CODE;// VARCHAR2(100) Y 到达站点编码  
34 - private String REACH_ACTUAL_TIME;// VARCHAR2(100) Y 实际到达时间  
35 - private String LEVELS_FLAG;// VARCHAR2(100) Y 匹配上到离站:1;匹配不上:0  
36 - private String LEVELS1;// VARCHAR2(100) Y 站序1  
37 - private String LEVELS_NAME1;// VARCHAR2(100) Y 站序1名称  
38 - private String LEVELS1_CODE;// VARCHAR2(100) Y 站序1编码  
39 - private String LEVELS2;// VARCHAR2(100) Y 站序2  
40 - private String LEVELS_NAME2;// VARCHAR2(100) Y 站序2名称  
41 - private String LEVELS2_CODE;// VARCHAR2(100) Y 站序2编码  
42 - private String GPS_DATE_TIME1;// VARCHAR2(100) Y 站序1到站时间  
43 - private String GPS_DATE_TIME2;// VARCHAR2(100) Y 站序2到站时间  
44 - private String B_STATION_ID;// VARCHAR2(100) Y 电子路单id  
45 - private String PLAN_START_TIME;// VARCHAR2(100) Y 计划发车时间  
46 - private String PLAN_ARRIVE_TIME;// VARCHAR2(100) Y 计划到达时间  
47 - private String ACTUAL_START_TIME;// VARCHAR2(100) Y 实际发车时间  
48 - private String ACTUAL_ARRIVE_TIME;// VARCHAR2(100) Y 实际到达时间实际到达时间  
49 - private String TRAD_ID;  
50 - private String COUNT;//计数器  
51 - private String lineId;  
52 - public TJRL(){  
53 -  
54 - }  
55 - public TJRL(TJRLDB tjrldb) {  
56 - try {  
57 - Field[] fields=TJRL.class.getDeclaredFields();  
58 - for(Field f : fields) {  
59 - PropertyDescriptor pd = new PropertyDescriptor(f.getName(), TJRLDB.class);  
60 - Method rM = pd.getReadMethod();//获得读方法  
61 - String v = rM.invoke(tjrldb)==null?"":rM.invoke(tjrldb).toString();  
62 - pd = new PropertyDescriptor(f.getName(), TJRL.class);  
63 - Method wM = pd.getWriteMethod();//获得写方法  
64 - wM.invoke(this, v);  
65 - }  
66 - } catch (Exception e) {  
67 - e.printStackTrace();  
68 - }  
69 - }  
70 -  
71 - public String getTJRLCARDNO() {  
72 - return TJRLCARDNO;  
73 - }  
74 -  
75 - public void setTJRLCARDNO(String TJRLCARDNO) {  
76 - this.TJRLCARDNO = TJRLCARDNO;  
77 - }  
78 -  
79 - public String getTJRLINSID() {  
80 - return TJRLINSID;  
81 - }  
82 -  
83 - public void setTJRLINSID(String TJRLINSID) {  
84 - this.TJRLINSID = TJRLINSID;  
85 - }  
86 -  
87 - public String getTJRLCDKIND() {  
88 - return TJRLCDKIND;  
89 - }  
90 -  
91 - public void setTJRLCDKIND(String TJRLCDKIND) {  
92 - this.TJRLCDKIND = TJRLCDKIND;  
93 - }  
94 -  
95 - public String getTJRLPOSID() {  
96 - return TJRLPOSID;  
97 - }  
98 -  
99 - public void setTJRLPOSID(String TJRLPOSID) {  
100 - this.TJRLPOSID = TJRLPOSID;  
101 - }  
102 -  
103 - public String getTJRLRDATE() {  
104 - return TJRLRDATE;  
105 - }  
106 -  
107 - public void setTJRLRDATE(String TJRLRDATE) {  
108 - this.TJRLRDATE = TJRLRDATE;  
109 - }  
110 -  
111 - public String getTJRLRTIME() {  
112 - return TJRLRTIME;  
113 - }  
114 -  
115 - public void setTJRLRTIME(String TJRLRTIME) {  
116 - this.TJRLRTIME = TJRLRTIME;  
117 - }  
118 -  
119 - public String getTJRLCDBAL() {  
120 - return TJRLCDBAL;  
121 - }  
122 -  
123 - public void setTJRLCDBAL(String TJRLCDBAL) {  
124 - this.TJRLCDBAL = TJRLCDBAL;  
125 - }  
126 -  
127 - public String getTJRLAMT() {  
128 - return TJRLAMT;  
129 - }  
130 -  
131 - public void setTJRLAMT(String TJRLAMT) {  
132 - this.TJRLAMT = TJRLAMT;  
133 - }  
134 -  
135 - public String getTJRLORGAMT() {  
136 - return TJRLORGAMT;  
137 - }  
138 -  
139 - public void setTJRLORGAMT(String TJRLORGAMT) {  
140 - this.TJRLORGAMT = TJRLORGAMT;  
141 - }  
142 -  
143 - public String getTJRLSTATID() {  
144 - return TJRLSTATID;  
145 - }  
146 -  
147 - public void setTJRLSTATID(String TJRLSTATID) {  
148 - this.TJRLSTATID = TJRLSTATID;  
149 - }  
150 -  
151 - public String getTJRLUNITID() {  
152 - return TJRLUNITID;  
153 - }  
154 -  
155 - public void setTJRLUNITID(String TJRLUNITID) {  
156 - this.TJRLUNITID = TJRLUNITID;  
157 - }  
158 -  
159 - public String getTJRLTXFG() {  
160 - return TJRLTXFG;  
161 - }  
162 -  
163 - public void setTJRLTXFG(String TJRLTXFG) {  
164 - this.TJRLTXFG = TJRLTXFG;  
165 - }  
166 -  
167 - public String getSTATION_FLAG() {  
168 - return STATION_FLAG;  
169 - }  
170 -  
171 - public void setSTATION_FLAG(String STATION_FLAG) {  
172 - this.STATION_FLAG = STATION_FLAG;  
173 - }  
174 -  
175 - public String getROAD_FORM_TYPE() {  
176 - return ROAD_FORM_TYPE;  
177 - }  
178 -  
179 - public void setROAD_FORM_TYPE(String ROAD_FORM_TYPE) {  
180 - this.ROAD_FORM_TYPE = ROAD_FORM_TYPE;  
181 - }  
182 -  
183 - public String getUPDOWN() {  
184 - return UPDOWN;  
185 - }  
186 -  
187 - public void setUPDOWN(String UPDOWN) {  
188 - this.UPDOWN = UPDOWN;  
189 - }  
190 -  
191 - public String getBUS_CODE() {  
192 - return BUS_CODE;  
193 - }  
194 -  
195 - public void setBUS_CODE(String BUS_CODE) {  
196 - this.BUS_CODE = BUS_CODE;  
197 - }  
198 -  
199 - public String getBUS_PLATE() {  
200 - return BUS_PLATE;  
201 - }  
202 -  
203 - public void setBUS_PLATE(String BUS_PLATE) {  
204 - this.BUS_PLATE = BUS_PLATE;  
205 - }  
206 -  
207 - public String getROAD_CODE() {  
208 - return ROAD_CODE;  
209 - }  
210 -  
211 - public void setROAD_CODE(String ROAD_CODE) {  
212 - this.ROAD_CODE = ROAD_CODE;  
213 - }  
214 -  
215 - public String getDEPART_NAME() {  
216 - return DEPART_NAME;  
217 - }  
218 -  
219 - public void setDEPART_NAME(String DEPART_NAME) {  
220 - this.DEPART_NAME = DEPART_NAME;  
221 - }  
222 -  
223 - public String getDEPART_CODE() {  
224 - return DEPART_CODE;  
225 - }  
226 -  
227 - public void setDEPART_CODE(String DEPART_CODE) {  
228 - this.DEPART_CODE = DEPART_CODE;  
229 - }  
230 -  
231 - public String getDEPART_ACTUAL_TIME() {  
232 - return DEPART_ACTUAL_TIME;  
233 - }  
234 -  
235 - public void setDEPART_ACTUAL_TIME(String DEPART_ACTUAL_TIME) {  
236 - this.DEPART_ACTUAL_TIME = DEPART_ACTUAL_TIME;  
237 - }  
238 -  
239 - public String getREACH_NAME() {  
240 - return REACH_NAME;  
241 - }  
242 -  
243 - public void setREACH_NAME(String REACH_NAME) {  
244 - this.REACH_NAME = REACH_NAME;  
245 - }  
246 -  
247 - public String getREACH_CODE() {  
248 - return REACH_CODE;  
249 - }  
250 -  
251 - public void setREACH_CODE(String REACH_CODE) {  
252 - this.REACH_CODE = REACH_CODE;  
253 - }  
254 -  
255 - public String getREACH_ACTUAL_TIME() {  
256 - return REACH_ACTUAL_TIME;  
257 - }  
258 -  
259 - public void setREACH_ACTUAL_TIME(String REACH_ACTUAL_TIME) {  
260 - this.REACH_ACTUAL_TIME = REACH_ACTUAL_TIME;  
261 - }  
262 -  
263 - public String getLEVELS_FLAG() {  
264 - return LEVELS_FLAG;  
265 - }  
266 -  
267 - public void setLEVELS_FLAG(String LEVELS_FLAG) {  
268 - this.LEVELS_FLAG = LEVELS_FLAG;  
269 - }  
270 -  
271 - public String getLEVELS1() {  
272 - return LEVELS1;  
273 - }  
274 -  
275 - public void setLEVELS1(String LEVELS1) {  
276 - this.LEVELS1 = LEVELS1;  
277 - }  
278 -  
279 - public String getLEVELS_NAME1() {  
280 - return LEVELS_NAME1;  
281 - }  
282 -  
283 - public void setLEVELS_NAME1(String LEVELS_NAME1) {  
284 - this.LEVELS_NAME1 = LEVELS_NAME1;  
285 - }  
286 -  
287 - public String getLEVELS1_CODE() {  
288 - return LEVELS1_CODE;  
289 - }  
290 -  
291 - public void setLEVELS1_CODE(String LEVELS1_CODE) {  
292 - this.LEVELS1_CODE = LEVELS1_CODE;  
293 - }  
294 -  
295 - public String getLEVELS2() {  
296 - return LEVELS2;  
297 - }  
298 -  
299 - public void setLEVELS2(String LEVELS2) {  
300 - this.LEVELS2 = LEVELS2;  
301 - }  
302 -  
303 - public String getLEVELS_NAME2() {  
304 - return LEVELS_NAME2;  
305 - }  
306 -  
307 - public void setLEVELS_NAME2(String LEVELS_NAME2) {  
308 - this.LEVELS_NAME2 = LEVELS_NAME2;  
309 - }  
310 -  
311 - public String getLEVELS2_CODE() {  
312 - return LEVELS2_CODE;  
313 - }  
314 -  
315 - public void setLEVELS2_CODE(String LEVELS2_CODE) {  
316 - this.LEVELS2_CODE = LEVELS2_CODE;  
317 - }  
318 -  
319 - public String getGPS_DATE_TIME1() {  
320 - return GPS_DATE_TIME1;  
321 - }  
322 -  
323 - public void setGPS_DATE_TIME1(String GPS_DATE_TIME1) {  
324 - this.GPS_DATE_TIME1 = GPS_DATE_TIME1;  
325 - }  
326 -  
327 - public String getGPS_DATE_TIME2() {  
328 - return GPS_DATE_TIME2;  
329 - }  
330 -  
331 - public void setGPS_DATE_TIME2(String GPS_DATE_TIME2) {  
332 - this.GPS_DATE_TIME2 = GPS_DATE_TIME2;  
333 - }  
334 -  
335 - public String getB_STATION_ID() {  
336 - return B_STATION_ID;  
337 - }  
338 -  
339 - public void setB_STATION_ID(String b_STATION_ID) {  
340 - B_STATION_ID = b_STATION_ID;  
341 - }  
342 -  
343 - public String getPLAN_START_TIME() {  
344 - return PLAN_START_TIME;  
345 - }  
346 -  
347 - public void setPLAN_START_TIME(String PLAN_START_TIME) {  
348 - this.PLAN_START_TIME = PLAN_START_TIME;  
349 - }  
350 -  
351 - public String getPLAN_ARRIVE_TIME() {  
352 - return PLAN_ARRIVE_TIME;  
353 - }  
354 -  
355 - public void setPLAN_ARRIVE_TIME(String PLAN_ARRIVE_TIME) {  
356 - this.PLAN_ARRIVE_TIME = PLAN_ARRIVE_TIME;  
357 - }  
358 -  
359 - public String getACTUAL_START_TIME() {  
360 - return ACTUAL_START_TIME;  
361 - }  
362 -  
363 - public void setACTUAL_START_TIME(String ACTUAL_START_TIME) {  
364 - this.ACTUAL_START_TIME = ACTUAL_START_TIME;  
365 - }  
366 -  
367 - public String getACTUAL_ARRIVE_TIME() {  
368 - return ACTUAL_ARRIVE_TIME;  
369 - }  
370 -  
371 - public void setACTUAL_ARRIVE_TIME(String ACTUAL_ARRIVE_TIME) {  
372 - this.ACTUAL_ARRIVE_TIME = ACTUAL_ARRIVE_TIME;  
373 - }  
374 -  
375 - public String getTRAD_ID() {  
376 - return TRAD_ID;  
377 - }  
378 -  
379 - public void setTRAD_ID(String TRAD_ID) {  
380 - this.TRAD_ID = TRAD_ID;  
381 - }  
382 -  
383 - public String getCOUNT() {  
384 - return COUNT;  
385 - }  
386 -  
387 - public void setCOUNT(String COUNT) {  
388 - this.COUNT = COUNT;  
389 - }  
390 -  
391 - @Override  
392 - public Object clone() throws CloneNotSupportedException {  
393 - return super.clone();  
394 - }  
395 -  
396 - public String getLineId() {  
397 - return lineId;  
398 - }  
399 -  
400 - public void setLineId(String lineId) {  
401 - this.lineId = lineId;  
402 - }  
403 -}  
src/main/java/com/example/demo/model/TJRLDB.java deleted 100644 → 0
1 -package com.example.demo.model;  
2 -  
3 -public class TJRLDB extends TJRL{  
4 - private String TJRLDRVCRDID;  
5 - private String MARK;  
6 -  
7 - public TJRLDB(){  
8 - super();  
9 - }  
10 - public TJRLDB(TJRLDB tjrldb) throws Exception {  
11 - super(tjrldb);  
12 - }  
13 -  
14 - public String getTJRLDRVCRDID() {  
15 - return TJRLDRVCRDID;  
16 - }  
17 -  
18 - public void setTJRLDRVCRDID(String TJRLDRVCRDID) {  
19 - this.TJRLDRVCRDID = TJRLDRVCRDID;  
20 - }  
21 -  
22 - public String getMARK() {  
23 - return MARK;  
24 - }  
25 -  
26 - public void setMARK(String MARK) {  
27 - this.MARK = MARK;  
28 - }  
29 -}  
src/main/java/com/example/demo/service/Analysis.java deleted 100644 → 0
1 -package com.example.demo.service;  
2 -  
3 -import com.example.demo.SaticScheduleTask;  
4 -import com.example.demo.model.TJRL;  
5 -import com.example.demo.model.TJRLDB;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.beans.factory.annotation.Value;  
10 -import org.springframework.kafka.core.KafkaTemplate;  
11 -import org.springframework.stereotype.Component;  
12 -  
13 -import java.io.BufferedReader;  
14 -import java.io.File;  
15 -import java.io.FileReader;  
16 -import java.text.ParseException;  
17 -import java.text.SimpleDateFormat;  
18 -import java.util.*;  
19 -  
20 -@Component  
21 -public class Analysis {  
22 - protected final Logger logger = LoggerFactory.getLogger(this.getClass());  
23 -  
24 - private static Date startDate = subtractTime(new Date(), -300000);  
25 -  
26 -  
27 - @Value("${ftp.oldFile}")  
28 - private String oldFile;  
29 -  
30 -  
31 - /**  
32 - * 获取路径下的所有文件/文件夹 /读取文件 返回时间和carid  
33 - *  
34 - * @param files 需要遍历的文件夹路径  
35 - * @return  
36 - */  
37 - public List<TJRLDB> getAllFile(List<File> files) throws Exception {  
38 - List<TJRLDB> listMap = new ArrayList<>();  
39 - List<String> list = new ArrayList<String>();  
40 - for (File file : files) {  
41 - if (!file.isDirectory()) {  
42 - String name=file.getName().substring(2,10);  
43 - String absolutePath = file.getAbsolutePath();  
44 - String time = (absolutePath.substring(absolutePath.indexOf("GJ"), absolutePath.indexOf("GJ") + 16)).replace("GJ", "");  
45 - Date nowTime = null;  
46 - try {  
47 - nowTime = new SimpleDateFormat("yyyyMMddHHmmss").parse(time);  
48 - } catch (ParseException e) {  
49 - e.printStackTrace();  
50 - }  
51 - //if (belongCalendar(nowTime)) { //判断是否在对应时间内  
52 - list.add(file.getAbsolutePath());  
53 - List<String> strings = txt2String(new File(file.getAbsolutePath()));//读取文件  
54 - for (int i = 0; i < strings.size(); i++) {  
55 - String text = strings.get(i);  
56 - Map<String, Object> map = new HashMap<>();  
57 - TJRLDB tjrl=new TJRLDB();  
58 - String POSID=text.substring(0,8);  
59 - tjrl.setTJRLPOSID(POSID);  
60 - Long val = Long.parseLong(text.substring(30, 40));  
61 - String cardId = Long.toHexString(val).toUpperCase();  
62 - tjrl.setTJRLDRVCRDID(cardId);//司售卡号 DriverCardId签到卡片ID号,BCD编码,司售卡卡号  
63 - //map.put("DriverCardType", text.substring(40, 42));//DriverCardType HEX格式,签到卡的卡型,BCD编码  
64 - //map.put("CHECKINDATE", text.substring(42, 54));//签到时间YYYYMMDDhhmm,BCD编码  
65 - //map.put("CHECKOUTCOUNT", text.substring(54, 60));//签到总次数,BCD编码  
66 - tjrl.setTJRLTXFG(text.substring(60, 62));//交易类型 Txn Flag HEX格式,交易标志,其中88为正常交易,99为锁卡交易,BCD编码,定义见附录1交易类型对照表  
67 - String POSSEQID=text.substring(62, 68);//HEX格式,消费交易流水号,BCD编码  
68 - //map.put("CITYCODE", text.substring(68, 72)); //城市代码号,BCD编码  
69 - tjrl.setTJRLCARDNO(text.substring(72, 82));//CARDID消费卡的ID号,BCD编码  
70 - tjrl.setTJRLCDKIND(text.substring(82, 84));//Card Type HEX格式,消费卡卡型,BCD编码  
71 - tjrl.setTJRLCDBAL(text.substring(84, 92));//交易前余额 BalBef消费卡交易前金额,BCD编码 BCD编码之前最高位1表示负数,0表示正数  
72 - tjrl.setTJRLAMT(text.substring(92, 100));//交易金额 TxnAmount本次消费交易金额,BCD编码  
73 - String TJRLRDATE=text.substring(100, 108);  
74 - try {  
75 - tjrl.setTJRLRDATE(new SimpleDateFormat("yyyy-MM-dd").  
76 - format(new SimpleDateFormat("yyyyMMdd").parse(text.substring(100, 108))));  
77 - //交易日期 本次消费交易日期,BCD编码YYYYMMDD  
78 - } catch (ParseException e) {  
79 - e.printStackTrace();  
80 - }  
81 - String TJRLRTIME=text.substring(108, 114);  
82 - try {  
83 - tjrl.setTJRLRTIME(new SimpleDateFormat("HH:mm:ss").  
84 - format(new SimpleDateFormat("HHmmss").parse(text.substring(108, 114))));  
85 - //交易时间 Txn Time本次消费交易时间,BCD编码hhmmss  
86 - } catch (ParseException e) {  
87 - e.printStackTrace();  
88 - }  
89 - tjrl.setCOUNT(text.substring(114, 120));//交易计数器,BCD编码  
90 - tjrl.setTJRLORGAMT(text.substring(120, 124));//交易原始金额Orignal Txn Amount  
91 - //map.put("CARDSPEC", text.substring(124, 126)); //卡规范,BCD编码 01—建设部卡 02—交通部卡 03-交通部二维码  
92 - String TAC=text.substring(126, 134);//HEX格式,交易认证码,BCD编码  
93 - String TRAD_ID=TAC+POSSEQID+TJRLRDATE+TJRLRTIME;  
94 - tjrl.setTRAD_ID(TRAD_ID);////pos交易数据需要加上 trad_id 用tac+pos流水+交易日期+交易时间  
95 -  
96 - listMap.add(tjrl);  
97 - }  
98 - //}  
99 - /* Analysis analysis=new Analysis();  
100 - analysis.setOldFile(oldFile);*/  
101 - File f2=new File(oldFile+File.separator+name);  
102 - if(!f2.exists()&&!f2.isDirectory()){  
103 - f2.mkdir();  
104 - }  
105 - File f=new File(oldFile+File.separator+name+File.separator+file.getName());  
106 - file.renameTo(f);  
107 - }  
108 - }  
109 - return listMap;  
110 - }  
111 -  
112 -  
113 - /**  
114 - * 读取文件内容  
115 - */  
116 - public static List<String> txt2String(File file) {  
117 - List<String> list = new ArrayList<>();  
118 - StringBuilder result = new StringBuilder();  
119 - try {  
120 - BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件  
121 - String s = null;  
122 - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行  
123 - list.add(s);  
124 - }  
125 - br.close();  
126 - } catch (Exception e) {  
127 - e.printStackTrace();  
128 - }  
129 - return list;  
130 - }  
131 -  
132 -  
133 - /**  
134 - * 加减对应时间后的日期  
135 - *  
136 - * @param date 需要加减时间的日期  
137 - * @param amount 加减的时间(毫秒)  
138 - * @return 加减对应时间后的日期  
139 - */  
140 -  
141 - private static Date subtractTime(Date date, int amount) {  
142 - try {  
143 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
144 - String strTime = sdf.format(date.getTime() + amount);  
145 - Date time = sdf.parse(strTime);  
146 - return time;  
147 - } catch (Exception e) {  
148 - e.printStackTrace();  
149 - }  
150 - return null;  
151 - }  
152 -  
153 - /**  
154 - * 判断时间是否在时间段内  
155 - *  
156 - * @param nowTime  
157 - * @return  
158 - */  
159 - public static boolean belongCalendar(Date nowTime) {  
160 - Calendar date = Calendar.getInstance();  
161 - date.setTime(nowTime);  
162 -  
163 - Calendar begin = Calendar.getInstance();  
164 - begin.setTime(startDate);  
165 -  
166 - Calendar end = Calendar.getInstance();  
167 - end.setTime(new Date());  
168 -  
169 - if (date.after(begin) && date.before(end)) {  
170 - return true;  
171 - } else {  
172 - return false;  
173 - }  
174 - }  
175 - /* @Value("${ftp.oldFile}")  
176 - public void setOldFile(String oldFile) {  
177 - Analysis.oldFile = oldFile;  
178 - }*/  
179 -  
180 -  
181 - public static boolean containsWords(String inputString, String[] items) {  
182 - boolean found = false;  
183 - for (String item : items) {  
184 - if (inputString.contains(item)) {  
185 - found = true;  
186 - break;  
187 - }  
188 -  
189 - }  
190 - return found;  
191 - }  
192 -  
193 - public static void main(String[] args) {  
194 - String s="A123";  
195 - String[] arr={"A","B","C","D","E","F"};  
196 - if(containsWords(s,arr)){  
197 - System.out.println(s);  
198 - }  
199 - }  
200 -}  
201 -  
src/main/java/com/example/demo/service/Contrast.java
1 package com.example.demo.service; 1 package com.example.demo.service;
2 2
3 import cn.hutool.json.JSON; 3 import cn.hutool.json.JSON;
4 -import com.alibaba.fastjson.JSONArray;  
5 -import com.alibaba.fastjson.JSONObject;  
6 -import com.bsth.util.HttpUtils;  
7 -import com.example.demo.SaticScheduleTask; 4 +import cn.hutool.json.JSONObject;
8 import com.example.demo.mapper.db1.SiteMapper1; 5 import com.example.demo.mapper.db1.SiteMapper1;
9 import com.example.demo.mapper.db2.SiteMapper2; 6 import com.example.demo.mapper.db2.SiteMapper2;
10 import com.example.demo.model.*; 7 import com.example.demo.model.*;
@@ -12,11 +9,7 @@ import org.slf4j.Logger; @@ -12,11 +9,7 @@ import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.kafka.core.KafkaTemplate; 11 import org.springframework.kafka.core.KafkaTemplate;
15 -import org.springframework.kafka.support.SendResult;  
16 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
17 -import org.springframework.util.concurrent.ListenableFuture;  
18 -import org.springframework.util.concurrent.ListenableFutureCallback;  
19 -import java.text.ParseException;  
20 import java.text.SimpleDateFormat; 13 import java.text.SimpleDateFormat;
21 import java.time.*; 14 import java.time.*;
22 import java.time.format.DateTimeFormatter; 15 import java.time.format.DateTimeFormatter;
@@ -38,37 +31,6 @@ public class Contrast { @@ -38,37 +31,6 @@ public class Contrast {
38 @Autowired 31 @Autowired
39 private KafkaTemplate kafkaTemplate; 32 private KafkaTemplate kafkaTemplate;
40 33
41 - @Autowired  
42 - private SaticScheduleTask saticScheduleTask;  
43 -  
44 - public Map<String,List<Scheduling>> getSchedulingS;  
45 - public Map<String,List<Scheduling>> getSchedulingSSell;  
46 - public List<TJRLDB> oldData=new ArrayList<>();  
47 -  
48 - private final int TIME=5;  
49 - private final int TIME2=0;//刷卡的时间和到站实际允许误差值  
50 -  
51 - public List<Map> getDriverCardList() throws Exception{  
52 - List<Map> list = new ArrayList<>();  
53 - String drivercard = HttpUtils.sendPost("http://112.64.187.3:1080/gjService/gjService/drivercard", null);  
54 - JSONObject obj = JSONObject.parseObject(drivercard);  
55 - String errorCode = obj.get("errorCode").toString();  
56 - if (errorCode.equals("1")) {  
57 - JSONArray dateBeans = obj.getJSONArray("dateBean");  
58 - for (int i = 0; i < dateBeans.size(); i++) {  
59 - Map dataList = new HashMap();  
60 - JSONObject o = (JSONObject) dateBeans.get(i);  
61 - dataList.put("outcardno", o.get("outcardno"));  
62 - dataList.put("cardno", o.get("cardno"));  
63 - dataList.put("jobCode", o.get("jobCode"));  
64 - dataList.put("companyNo", o.get("companyNo"));  
65 - dataList.put("brancheCompanyNo", o.get("brancheCompanyNo"));  
66 - dataList.put("personalName", o.get("personalName"));  
67 - list.add(dataList);  
68 - }  
69 - }  
70 - return list;  
71 - }  
72 34
73 35
74 /** 36 /**
@@ -77,41 +39,42 @@ public class Contrast { @@ -77,41 +39,42 @@ public class Contrast {
77 * @Author: YM 39 * @Author: YM
78 * @Date: 2021/10/12 40 * @Date: 2021/10/12
79 */ 41 */
80 - public List<Map<String,List<Scheduling>>> getSchedulingS(LocalDateTime now,int day) throws Exception{ 42 + public List<Scheduling> getSchedulingS(LocalDateTime now,int day) throws Exception{
81 List<Scheduling> schedulingS=new ArrayList<>(); 43 List<Scheduling> schedulingS=new ArrayList<>();
82 - long start = System.currentTimeMillis();  
83 Map map = new HashMap(); 44 Map map = new HashMap();
84 - //通过驾驶员信息和 刷卡时间 查询 排班表 和车辆表 45 +
  46 + //计算开始结束时间
85 LocalDateTime localDateTimeStart=now.minusDays(day); 47 LocalDateTime localDateTimeStart=now.minusDays(day);
86 - LocalDateTime localDateTimeEnd=now.plusMinutes(60); 48 + DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
  49 + DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  50 + String dateTime = siteMapper1.getMaxTime(localDateTimeStart.format(df));
  51 + LocalDateTime localDateTimeEnd=LocalDateTime.parse(dateTime,dtf).plusMinutes(5);
87 52
88 - DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd");  
89 - map.put("startTime",localDateTimeStart.format(tdf));  
90 - map.put("endTime",localDateTimeEnd.format(tdf));  
91 - List<Scheduling> schedulingList = siteMapper1.getScheduling(map); 53 + //查询路单
  54 + map.put("date",localDateTimeStart.format(df));
  55 + List<Scheduling> schedulingList = siteMapper1.getScheduling(localDateTimeStart.format(df));
92 56
93 //按车辆和方向分组 57 //按车辆和方向分组
94 Map<String, List<Scheduling>> m = schedulingList.stream().collect(Collectors.groupingBy(s->s.getEquipment_code()+"_"+s.getXl_bm()+"_"+s.getXl_dir())); 58 Map<String, List<Scheduling>> m = schedulingList.stream().collect(Collectors.groupingBy(s->s.getEquipment_code()+"_"+s.getXl_bm()+"_"+s.getXl_dir()));
95 - //站点路由 59 +
  60 + //查询站点路由
96 List<StationRoute> StationRouteList=siteMapper1.getStationRoute(); 61 List<StationRoute> StationRouteList=siteMapper1.getStationRoute();
97 Map<String, List<StationRoute>> m2 = StationRouteList.stream().collect(Collectors.groupingBy(s->s.getStation_code()+"_"+s.getDirections()+"_"+s.getLine_code())); 62 Map<String, List<StationRoute>> m2 = StationRouteList.stream().collect(Collectors.groupingBy(s->s.getStation_code()+"_"+s.getDirections()+"_"+s.getLine_code()));
98 63
99 - //合并进出表数据 64 +
  65 + //查询进出站
100 map.clear(); 66 map.clear();
101 map.put("timeStart",localDateTimeStart.toInstant(ZoneOffset.of("+8")).toEpochMilli()); 67 map.put("timeStart",localDateTimeStart.toInstant(ZoneOffset.of("+8")).toEpochMilli());
102 map.put("timeEnd",localDateTimeEnd.toInstant(ZoneOffset.of("+8")).toEpochMilli()); 68 map.put("timeEnd",localDateTimeEnd.toInstant(ZoneOffset.of("+8")).toEpochMilli());
103 -  
104 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 69 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
105 - Date ds = sdf.parse(localDateTimeStart.format(tdf)); 70 + Date ds = sdf.parse(localDateTimeStart.format(df));
106 Calendar cs = Calendar.getInstance(); 71 Calendar cs = Calendar.getInstance();
107 cs.setTime(ds); 72 cs.setTime(ds);
108 int weekStr=cs.get(Calendar.WEEK_OF_YEAR); 73 int weekStr=cs.get(Calendar.WEEK_OF_YEAR);
109 -  
110 - Date de = sdf.parse(localDateTimeEnd.format(tdf)); 74 + Date de = sdf.parse(localDateTimeEnd.format(df));
111 Calendar ce = Calendar.getInstance(); 75 Calendar ce = Calendar.getInstance();
112 ce.setTime(de); 76 ce.setTime(de);
113 int weekEnd=ce.get(Calendar.WEEK_OF_YEAR); 77 int weekEnd=ce.get(Calendar.WEEK_OF_YEAR);
114 -  
115 String weeks=""; 78 String weeks="";
116 if(weekStr==weekEnd){ 79 if(weekStr==weekEnd){
117 weeks="= "+weekStr; 80 weeks="= "+weekStr;
@@ -121,8 +84,8 @@ public class Contrast { @@ -121,8 +84,8 @@ public class Contrast {
121 map.put("weeks",weeks); 84 map.put("weeks",weeks);
122 map.put("year",localDateTimeStart.getYear()); 85 map.put("year",localDateTimeStart.getYear());
123 List<ArrivalInfo> list= siteMapper2.getArrivalInfo(map); 86 List<ArrivalInfo> list= siteMapper2.getArrivalInfo(map);
124 - logger.info("====================map "+map.toString());  
125 - logger.info("====================list "+list.size()); 87 +
  88 + //合并进出站数据
126 List<ArrivalInfo> arrivalInfoList=new ArrayList<>(); 89 List<ArrivalInfo> arrivalInfoList=new ArrayList<>();
127 ArrivalInfo in=null; 90 ArrivalInfo in=null;
128 for (ArrivalInfo arrivalInfo : list) { 91 for (ArrivalInfo arrivalInfo : list) {
@@ -139,194 +102,81 @@ public class Contrast { @@ -139,194 +102,81 @@ public class Contrast {
139 } 102 }
140 } 103 }
141 104
142 -  
143 -  
144 - int b = 0;  
145 - DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");  
146 for (ArrivalInfo arrivalInfo : arrivalInfoList) {//进出表 105 for (ArrivalInfo arrivalInfo : arrivalInfoList) {//进出表
147 //进出站时间 106 //进出站时间
148 LocalDateTime inTime=LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(arrivalInfo.getTs())), ZoneOffset.of("+8")); 107 LocalDateTime inTime=LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(arrivalInfo.getTs())), ZoneOffset.of("+8"));
149 - LocalDateTime outTime=LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(arrivalInfo.getTs_out())), ZoneOffset.of("+8"));  
150 -  
151 108
152 String key=arrivalInfo.getDevice_id()+"_"+arrivalInfo.getLine_id()+"_"+arrivalInfo.getUp_down(); 109 String key=arrivalInfo.getDevice_id()+"_"+arrivalInfo.getLine_id()+"_"+arrivalInfo.getUp_down();
153 List<Scheduling> l=m.get(key); 110 List<Scheduling> l=m.get(key);
  111 +
154 if(l!=null){ 112 if(l!=null){
155 Collections.sort(l); 113 Collections.sort(l);
156 for (Scheduling scheduling : l) { 114 for (Scheduling scheduling : l) {
157 //实际发车到达时间 115 //实际发车到达时间
158 if(scheduling.getFcsj_actual()!=null){ 116 if(scheduling.getFcsj_actual()!=null){
159 - LocalDateTime fcsj_actual=LocalDateTime.parse(scheduling.getReal_exec_date()+" "+scheduling.getFcsj_actual(),dateTimeFormatter).minusMinutes(TIME);  
160 - if(fcsj_actual.isBefore(inTime)){  
161 - Scheduling scheduling1= null;  
162 - try {  
163 - scheduling1 = (Scheduling) scheduling.clone();  
164 - } catch (CloneNotSupportedException e) {  
165 - e.printStackTrace();  
166 - }  
167 - scheduling1.setStop_no(arrivalInfo.getStop_no());  
168 - scheduling1.setTs(arrivalInfo.getTs());  
169 - scheduling1.setTs_out(arrivalInfo.getTs_out()); 117 + LocalDateTime fcsj_actual=LocalDateTime.parse(scheduling.getSchedule_date_str()+" "+scheduling.getFcsj_actual(),dtf);
  118 + LocalDateTime ddsj_actual=LocalDateTime.parse(scheduling.getSchedule_date_str()+" "+scheduling.getZdsj_actual(),dtf);
  119 + if(ddsj_actual.isBefore(fcsj_actual)){
  120 + ddsj_actual=ddsj_actual.plusDays(1);
  121 + }
  122 + if(fcsj_actual.isBefore(inTime) && ddsj_actual.isAfter(inTime) ){
  123 +
170 124
171 //合并路由表 125 //合并路由表
172 - String keyRoute=scheduling1.getStop_no()+"_"+scheduling1.getXl_dir()+"_"+scheduling1.getXl_bm(); 126 + String keyRoute=arrivalInfo.getStop_no()+"_"+scheduling.getXl_dir()+"_"+scheduling.getXl_bm();
173 List<StationRoute> routes=m2.get(keyRoute); 127 List<StationRoute> routes=m2.get(keyRoute);
174 if(routes!=null && routes.size()>0){ 128 if(routes!=null && routes.size()>0){
  129 + InOutStation inOutStation=new InOutStation();
  130 + inOutStation.setStop_no(arrivalInfo.getStop_no());
  131 + inOutStation.setInTime(arrivalInfo.getTs());
  132 + inOutStation.setOutTime(arrivalInfo.getTs_out());
175 StationRoute route=routes.get(0); 133 StationRoute route=routes.get(0);
176 - scheduling1.setStation_route_code(route.getStation_route_code());  
177 - scheduling1.setStation_name(route.getStation_name());  
178 - scheduling1.setStation_code(route.getStation_code()); 134 + inOutStation.setStationRouteCode(route.getStation_route_code());
  135 + inOutStation.setStationName(route.getStation_name());
  136 + List<InOutStation> inOutStations =scheduling.getInOutStations();
  137 + if(inOutStations==null){
  138 + inOutStations =new ArrayList<>();
  139 + }
  140 + inOutStations.add(inOutStation);
  141 + scheduling.setInOutStations(inOutStations);
  142 + schedulingS.add(scheduling);
179 } 143 }
180 - schedulingS.add(scheduling1);  
181 - b++;  
182 break; 144 break;
183 } 145 }
184 } 146 }
185 } 147 }
186 } 148 }
187 } 149 }
188 - Map<String,List<Scheduling>> getSchedulingS=schedulingS.stream().collect(Collectors.groupingBy(s->s.getJ_name()));  
189 - Map<String,List<Scheduling>> getSchedulingSSell=schedulingS.stream().collect(Collectors.groupingBy(s->s.getS_name()));  
190 - List<Map<String,List<Scheduling>>> result=new ArrayList<>();  
191 - result.add(getSchedulingS);  
192 - result.add(getSchedulingSSell);  
193 - logger.info("======匹配"+arrivalInfoList.size()+"条======匹配成功 "+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒");  
194 - logger.info("===============================预加载数据匹配结束================================");  
195 - return result;  
196 - }  
197 -  
198 - /**  
199 - * @Description: 根据carid 获取票务数据  
200 - * @Param: allData交易记录 isOld是否是残余数据(上次未匹配到的数据)  
201 - * @return:  
202 - * @Author: YM  
203 - * @Date: 2021/10/13  
204 - */  
205 - public void filterCardList(List<TJRLDB> allData, Boolean isOld) throws Exception {  
206 - logger.info("===============================票务数据匹配开始================================");  
207 - long start = System.currentTimeMillis();  
208 - List<Map> driverCardList = getDriverCardList();//获取司机信息  
209 - Map<String,List<Scheduling>> schedulingS =getSchedulingS;  
210 - Map<String,List<Scheduling>> schedulingSSell =getSchedulingSSell;  
211 - System.out.println(schedulingS.size());  
212 - System.out.println(schedulingSSell.size());  
213 - DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
214 - int b=0;//用于计算匹配成功的数量  
215 - for (int i = 0; i < allData.size(); i++) {  
216 - TJRLDB data = allData.get(i);  
217 - //通过司售卡找到司机  
218 - String carId = data.getTJRLDRVCRDID().length()>8?  
219 - data.getTJRLDRVCRDID().substring( data.getTJRLDRVCRDID().length()-8):  
220 - data.getTJRLDRVCRDID();  
221 - List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList());  
222 - String mark="";  
223 - String jobCodes = "";  
224 - Boolean flag=false;//用来判断是否没有匹配成功  
225 - Long cardDate = null;  
226 - if (!collect.isEmpty()) {  
227 - if (null != collect.get(0).get("jobCode") && null != collect.get(0).get("personalName")) {  
228 - String personalName = collect.get(0).get("personalName").toString();//姓名  
229 - String[] arr=collect.get(0).get("jobCode").toString().split("-");  
230 - jobCodes =arr.length==0?collect.get(0).get("jobCode").toString():arr[arr.length-1];//工号  
231 - String time=String.valueOf(data.getTJRLRTIME());//时间  
232 - String date=String.valueOf(data.getTJRLRDATE());//日期  
233 - cardDate = LocalDateTime.parse(date+" "+time,dtf).toInstant(ZoneOffset.of("+8")).toEpochMilli(); //刷卡时间(时间戳)  
234 -  
235 - //通过司机姓名获得进出记录  
236 - List<Scheduling> schedulingList1=schedulingS.get(personalName);  
237 - //没匹配到匹配售票员  
238 - if(schedulingList1==null){  
239 - schedulingList1=schedulingSSell.get(personalName);  
240 - }  
241 - Scheduling scheduling = null;  
242 -  
243 - if(schedulingList1!=null){  
244 - Collections.sort(schedulingList1, Comparator.comparing(Scheduling::getTs).reversed());  
245 - for (int i1 = 0; i1 < schedulingList1.size(); i1++) {  
246 - Scheduling s=schedulingList1.get(i1);  
247 - //进站时间小于刷卡时间  
248 - if((Long.parseLong(s.getTs())-TIME2*60*1000)<=cardDate){  
249 - scheduling=s;  
250 - b++;  
251 - flag=true;  
252 - break;  
253 - }  
254 - }  
255 - }else {  
256 - mark="没有匹配的进站记录:"+personalName+" 工号:"+jobCodes;  
257 - }  
258 -  
259 - if (scheduling!=null) {  
260 - data.setLineId(scheduling.getXl_bm());  
261 - data.setSTATION_FLAG("1");  
262 - data.setTJRLUNITID(scheduling.getGs_name());  
263 - data.setTJRLSTATID(scheduling.getXl_name());  
264 - data.setROAD_FORM_TYPE(scheduling.getBc_type());  
265 - data.setUPDOWN(scheduling.getXl_dir());  
266 - data.setBUS_CODE(scheduling.getCl_zbh());  
267 - data.setBUS_PLATE(scheduling.getCar_plate());  
268 - data.setROAD_CODE(scheduling.getLp_name());  
269 - data.setDEPART_NAME(scheduling.getQdz_name());  
270 - data.setDEPART_CODE(scheduling.getQdz_code());  
271 - data.setDEPART_ACTUAL_TIME(scheduling.getFcsj_actual());  
272 - data.setREACH_NAME(scheduling.getZdz_name());  
273 - data.setREACH_CODE(scheduling.getZdz_code());  
274 - data.setREACH_ACTUAL_TIME(scheduling.getZdsj_actual());  
275 - if(scheduling.getStation_name()!=null){  
276 - data.setLEVELS_FLAG("1");  
277 - data.setLEVELS1(scheduling.getStation_route_code());//站点路由序号  
278 - data.setLEVELS_NAME1(scheduling.getStation_name());//站点名  
279 - data.setLEVELS1_CODE(scheduling.getStop_no());//站点编号  
280 - }else {  
281 - data.setLEVELS_FLAG("0");  
282 - }  
283 - } else {  
284 - data.setSTATION_FLAG("0");  
285 - }  
286 - }  
287 - }else {  
288 - mark="未查工号:"+carId;  
289 - data.setSTATION_FLAG("0");  
290 - }  
291 - if(mark.length()==0 && !flag){  
292 - mark="没有匹配的班次 "+jobCodes+"刷卡时间为:"+LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8));  
293 - }  
294 - data.setMARK(mark);  
295 - //如果是新数据 没匹配到 去除这条记录 并放入缓存等到下次继续匹配  
296 - if(!isOld && !flag){  
297 - List<TJRLDB> m =oldData;  
298 - m.add(data);  
299 - allData.set(i,null);  
300 150
  151 + List<Scheduling> schedulings=new ArrayList<>();
  152 + m.forEach((k,v)->{
  153 + schedulings.addAll(v);
  154 + });
  155 + List<Scheduling> schedulings2=new ArrayList<>();
  156 + //SELECT device_id,line_id,stop_no,up_down,ts,DATE_FORMAT(FROM_UNIXTIME(ts/1000), '%Y-%m-%d %H:%i:%s') t FROM `bsth_c_arrival_info_2024` where device_id ='8WBCD149'and up_down=1 and line_id=63073
  157 + for (Scheduling scheduling : schedulings) {
  158 + if (scheduling.getInOutStations()==null){
  159 + logger.info(scheduling.getXl_bm()+"_"+scheduling.getXl_name()+"_"+scheduling.getXl_dir()+"_"+scheduling.getFcsj_actual()+"_"+scheduling.getZdsj_actual()+"_"+scheduling.getEquipment_code());
  160 + schedulings2.add(scheduling);
301 } 161 }
302 } 162 }
303 - int size=allData.size();  
304 - allData.removeIf(Objects::isNull);  
305 - //防止数据过多 分批插入  
306 - List<List<TJRLDB>> subList = getSubList(2000, allData);  
307 - if(!subList.isEmpty()){  
308 - subList.forEach(data->{  
309 - if (!data.isEmpty()) {  
310 - siteMapper1.insertResult(data);  
311 - }  
312 - }); 163 + logger.info("共"+schedulings.size()+"个班次,未匹配进出站班次"+schedulings2.size());
  164 + List<SchedulingKFK> schedulingKFKS=new ArrayList<>();
  165 + for (Scheduling scheduling : schedulings) {
  166 + SchedulingKFK schedulingKFK=SchedulingKFK.getInstance(scheduling);
  167 + schedulingKFKS.add(schedulingKFK);
313 } 168 }
314 169
315 - List<List<TJRLDB>> subList2 = getSubList(500, allData);  
316 - if(!subList2.isEmpty()){  
317 - subList2.forEach(data->{ 170 + List<List<SchedulingKFK>> subList = getSubList(500, schedulingKFKS);
  171 + if(!subList.isEmpty()){
  172 + subList.forEach(data->{
318 if (!data.isEmpty()) { 173 if (!data.isEmpty()) {
319 - Map<String, Object> map = new HashMap<>();  
320 - map.put("datatype", "passengerflow");  
321 - List<TJRL> data2 =new ArrayList<>();  
322 - for (TJRLDB tjrldb : data) {  
323 - TJRL tjrl= new TJRL(tjrldb);  
324 - data2.add(tjrl);  
325 - }  
326 - map.put("datas", data2);  
327 - JSON j=new cn.hutool.json.JSONObject(map); 174 + Map<String, Object> map2 = new HashMap<>();
  175 + map2.put("datatype", "scheduling");
  176 + map2.put("datas", data);
  177 + JSON j=new JSONObject(map2);
328 String json =j.toString(); 178 String json =j.toString();
329 - ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json); 179 + /*ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json);
330 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { 180 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
331 @Override 181 @Override
332 public void onSuccess(SendResult<String, String> result) { 182 public void onSuccess(SendResult<String, String> result) {
@@ -336,71 +186,48 @@ public class Contrast { @@ -336,71 +186,48 @@ public class Contrast {
336 public void onFailure(Throwable ex) { 186 public void onFailure(Throwable ex) {
337 logger.error("kafka发送票务数据异常", ex); 187 logger.error("kafka发送票务数据异常", ex);
338 } 188 }
339 - }); 189 + });*/
340 } 190 }
341 }); 191 });
342 } 192 }
343 - //如果是上次遗留的数据不管这是是否匹配到都清空  
344 - if(isOld){  
345 - oldData.clear();  
346 - }  
347 - logger.warn("======匹配"+size+"条======匹配到"+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒");  
348 - logger.info("===============================票务数据匹配结束================================"); 193 + return schedulings;
349 } 194 }
350 195
351 -  
352 -  
353 -  
354 -  
355 -  
356 -  
357 - public static int getWeek(String today)throws Exception{  
358 - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
359 - Date date = null;  
360 - try {  
361 - date = format.parse(today);  
362 - } catch (ParseException e) {  
363 - // TODO Auto-generated catch block  
364 - e.printStackTrace();  
365 - }  
366 -  
367 - Calendar calendar = Calendar.getInstance();  
368 - calendar.setFirstDayOfWeek(Calendar.MONDAY);  
369 - calendar.setTime(date);  
370 - return calendar.get(Calendar.WEEK_OF_YEAR);  
371 - }  
372 -  
373 - public static String upperHeadChar(String in) {  
374 - String head = in.substring(0, 1);  
375 - String out = head.toUpperCase() + in.substring(1, in.length());  
376 - return out;  
377 - }  
378 -  
379 - public static String getTransTime(String timeStr) throws Exception{  
380 - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd HHmmss");  
381 - LocalDateTime date = LocalDateTime.parse(timeStr, df);  
382 - DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
383 - String transTime = f2.format(date);  
384 - return transTime;  
385 - }  
386 -  
387 -  
388 - public void filterCardListByDB(Map<String,Object> params) throws Exception{  
389 - List<TJRLDB> records=siteMapper1.getRecords(params);  
390 - for (TJRL record : records) {  
391 - String date=record.getTJRLRDATE()+" "+String.format("%06d", Integer.parseInt(record.getTJRLRTIME()));  
392 - String s=this.getTransTime(date);  
393 - record.setTJRLRDATE(s.split(" ")[0]);  
394 - record.setTJRLRTIME(s.split(" ")[1]); 196 + public List<List<StationRoute>> getStationRoutes(){
  197 + List<List<StationRoute>> list = new ArrayList<>();
  198 + List<StationRoute> StationRouteList=siteMapper1.getStationRoute();
  199 + Map<String, List<StationRoute>> StationRoutes = StationRouteList.stream().collect(Collectors.groupingBy(s->s.getLine_code()+"_"+s.getDirections()));
  200 + StationRoutes.forEach((k,v)->{
  201 + list.add(v);
  202 + });
  203 +
  204 + if(!list.isEmpty()){
  205 + Map<String, Object> map = new HashMap<>();
  206 + map.put("datatype", "stationRoute");
  207 + map.put("datas", list);
  208 + JSON j=new JSONObject(map);
  209 + String json =j.toString();
  210 + /*ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json);
  211 + future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
  212 + @Override
  213 + public void onSuccess(SendResult<String, String> result) {
  214 + logger.info("kafka发送票务数据成功");
  215 + }
  216 + @Override
  217 + public void onFailure(Throwable ex) {
  218 + logger.error("kafka发送票务数据异常", ex);
  219 + }
  220 + });*/
395 } 221 }
396 - filterCardList(records,false); 222 + System.out.println(">>>>>>>>>>>>>>>>"+list.size());
  223 + return list;
397 } 224 }
398 225
399 - public List<List<TJRLDB>> getSubList(int length, List<TJRLDB> list)throws Exception{ 226 + public List<List<SchedulingKFK>> getSubList(int length, List<SchedulingKFK> list)throws Exception{
400 int size = list.size(); 227 int size = list.size();
401 int temp = size / length + 1; 228 int temp = size / length + 1;
402 boolean result = size % length == 0; 229 boolean result = size % length == 0;
403 - List<List<TJRLDB>> subList = new ArrayList<>(); 230 + List<List<SchedulingKFK>> subList = new ArrayList<>();
404 for (int i = 0; i < temp; i++) { 231 for (int i = 0; i < temp; i++) {
405 if (i == temp - 1) { 232 if (i == temp - 1) {
406 if (result) { 233 if (result) {
@@ -414,13 +241,5 @@ public class Contrast { @@ -414,13 +241,5 @@ public class Contrast {
414 return subList; 241 return subList;
415 } 242 }
416 243
417 - public static void main(String[] args) throws Exception{  
418 - String carId="B140C906";  
419 - Contrast contrast=new Contrast();  
420 - List<Map> driverCardList = contrast.getDriverCardList();  
421 - List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList());  
422 - System.out.println(collect);  
423 - }  
424 -  
425 244
426 } 245 }
src/main/resources/application.properties
1 -server.port=8088 1 +server.port=8087
2 2
3 -spring.datasource.db1.jdbc-url=jdbc:mysql://192.170.100.132:3306/control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC  
4 -spring.datasource.db1.username=ym  
5 -spring.datasource.db1.password=Ym(12345678) 3 +spring.datasource.db1.jdbc-url=jdbc:mysql://127.0.0.1:3306/control_qp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  4 +spring.datasource.db1.username=root
  5 +spring.datasource.db1.password=123456
6 spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver 6 spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
7 spring.datasource.db1.druid.test-on-borrow=true 7 spring.datasource.db1.druid.test-on-borrow=true
8 spring.datasource.db1.druid.test-while-idle=true 8 spring.datasource.db1.druid.test-while-idle=true
9 9
10 -spring.datasource.db2.jdbc-url=jdbc:mysql://192.170.100.63:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC  
11 -spring.datasource.db2.username=ym  
12 -spring.datasource.db2.password=Ym(12345678) 10 +spring.datasource.db2.jdbc-url=jdbc:mysql://127.0.0.1:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  11 +spring.datasource.db2.username=root
  12 +spring.datasource.db2.password=123456
13 spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver 13 spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver
14 spring.datasource.db2.druid.test-on-borrow=true 14 spring.datasource.db2.druid.test-on-borrow=true
15 spring.datasource.db2.druid.test-while-idle=true 15 spring.datasource.db2.druid.test-while-idle=true
@@ -21,48 +21,3 @@ logging.level.com.example.demo.mapper=info @@ -21,48 +21,3 @@ logging.level.com.example.demo.mapper=info
21 #logging.level.org.mybatis = debug 21 #logging.level.org.mybatis = debug
22 22
23 23
24 -#ftp  
25 -ftp.root= /home/sftp  
26 -ftp.oldFile= /home/oldFile  
27 -  
28 -  
29 -spring.kafka.bootstrap-servers=192.170.100.129:9092  
30 -spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer  
31 -spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer  
32 -spring.kafka.producer.buffer-memory=33554432  
33 -spring.kafka.producer.acks=all  
34 -spring.kafka.producer.properties.max.request.size=20971520  
35 -  
36 -  
37 -#  
38 -#spring.datasource.db1.jdbc-url=jdbc:mysql://192.168.168.240:3306/pd_control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC  
39 -#spring.datasource.db1.username=root  
40 -#spring.datasource.db1.password=root2jsp  
41 -#spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver  
42 -#spring.datasource.db1.druid.test-on-borrow=true  
43 -#spring.datasource.db1.druid.test-while-idle=true  
44 -#  
45 -#spring.datasource.db2.jdbc-url=jdbc:mysql://localhost:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC  
46 -#spring.datasource.db2.username=root  
47 -#spring.datasource.db2.password=1995627a  
48 -#spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver  
49 -#spring.datasource.db2.druid.test-on-borrow=true  
50 -#spring.datasource.db2.druid.test-while-idle=true  
51 -#  
52 -#  
53 -#mybatis.mapperLocations=classpath:mapping/**/*.xml  
54 -#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl  
55 -#logging.level.com.example.demo.mapper=debug  
56 -#  
57 -#  
58 -#ftp.root= E:\\data_test  
59 -#ftp.oldFile= E:\\oldFile  
60 -#  
61 -#  
62 -#spring.kafka.bootstrap-servers=114.80.178.12:9811  
63 -#spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer  
64 -#spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer  
65 -#spring.kafka.producer.buffer-memory=33554432  
66 -#spring.kafka.producer.acks=all  
67 -#spring.kafka.producer.properties.max.request.size=10485760  
68 -  
src/main/resources/mapping/db1/Site-mapper1.xml
@@ -6,32 +6,7 @@ @@ -6,32 +6,7 @@
6 6
7 7
8 8
9 - <insert id="insertResult" parameterType="List">  
10 - INSERT INTO passenger_flow.t_jc_result (  
11 - TJRLCARDNO, TJRLINSID, TJRLCDKIND, TJRLPOSID,TJRLRDATE,  
12 - TJRLRTIME,TJRLCDBAL,TJRLAMT,TJRLORGAMT,  
13 - TJRLTXFG,STATION_FLAG,TJRLUNITID,TJRLSTATID,ROAD_FORM_TYPE, UPDOWN, BUS_CODE,  
14 - BUS_PLATE, ROAD_CODE, DEPART_NAME,DEPART_CODE, DEPART_ACTUAL_TIME,  
15 - REACH_NAME,REACH_CODE,REACH_ACTUAL_TIME,  
16 - LEVELS_FLAG,LEVELS1, LEVELS_NAME1, LEVELS1_CODE,LEVELS2, LEVELS_NAME2,LEVELS2_CODE,MARK,TRAD_ID,  
17 - GPS_DATE_TIME1,GPS_DATE_TIME2,B_STATION_ID,PLAN_START_TIME,PLAN_ARRIVE_TIME,ACTUAL_START_TIME,ACTUAL_ARRIVE_TIME,COUNT,TJRLDRVCRDID  
18 - )  
19 - VALUES  
20 - <foreach collection="list" item="em" index="index" separator=",">  
21 - ( #{em.TJRLCARDNO}, #{em.TJRLINSID}, #{em.TJRLCDKIND}, #{em.TJRLPOSID},#{em.TJRLRDATE},  
22 - #{em.TJRLRTIME},#{em.TJRLCDBAL},#{em.TJRLAMT},#{em.TJRLORGAMT},  
23 - #{em.TJRLTXFG},#{em.STATION_FLAG},#{em.TJRLUNITID},#{em.TJRLSTATID},#{em.ROAD_FORM_TYPE}, #{em.UPDOWN},  
24 - #{em.BUS_CODE},  
25 - #{em.BUS_PLATE}, #{em.ROAD_CODE}, #{em.DEPART_NAME},#{em.DEPART_CODE}, #{em.DEPART_ACTUAL_TIME},  
26 - #{em.REACH_NAME},#{em.REACH_CODE},#{em.REACH_ACTUAL_TIME},  
27 - #{em.LEVELS_FLAG},#{em.LEVELS1}, #{em.LEVELS_NAME1}, #{em.LEVELS1_CODE},#{em.LEVELS2}, #{em.LEVELS_NAME2}, #{em.LEVELS2_CODE}, #{em.MARK},#{em.TRAD_ID},  
28 - #{em.GPS_DATE_TIME1},#{em.GPS_DATE_TIME2},#{em.B_STATION_ID},#{em.PLAN_START_TIME},#{em.PLAN_ARRIVE_TIME},#{em.ACTUAL_START_TIME},#{em.ACTUAL_ARRIVE_TIME},  
29 - #{em.COUNT},#{em.TJRLDRVCRDID})  
30 - </foreach>  
31 - </insert>  
32 -  
33 -  
34 - <select id="getScheduling" resultType="com.example.demo.model.Scheduling"> 9 + <select id="getScheduling" resultType="com.example.demo.model.Scheduling" parameterType="String">
35 SELECT CONCAT(gs_name, fgs_name) gs_name, 10 SELECT CONCAT(gs_name, fgs_name) gs_name,
36 xl_name, 11 xl_name,
37 xl_bm, 12 xl_bm,
@@ -51,23 +26,28 @@ @@ -51,23 +26,28 @@
51 zdz_code, 26 zdz_code,
52 zdsj_actual, 27 zdsj_actual,
53 real_exec_date, 28 real_exec_date,
  29 + gs_bm,
54 cars.equipment_code, 30 cars.equipment_code,
55 - cars.car_plate  
56 - FROM control.bsth_c_s_sp_info_real  
57 - LEFT JOIN control.bsth_c_cars cars ON cars.inside_code = cl_zbh  
58 - WHERE schedule_date_str in ('${startTime}','${endTime}') 31 + cars.car_plate,
  32 + line.shanghai_linecode
  33 + FROM bsth_c_s_sp_info_real
  34 + LEFT JOIN bsth_c_cars cars ON cars.inside_code = cl_zbh
  35 + LEFT JOIN bsth_c_line line ON xl_bm = line.line_code
  36 + WHERE (bc_type ='normal' or bc_type ='venting') and `status`=2 and schedule_date_str = '${date}'
59 order by equipment_code,fcsj_actual 37 order by equipment_code,fcsj_actual
60 </select> 38 </select>
61 39
62 40
63 <select id="getStationRoute" resultType="com.example.demo.model.StationRoute"> 41 <select id="getStationRoute" resultType="com.example.demo.model.StationRoute">
64 - SELECT station_route_code,directions,line_code,station_name,station_code  
65 - from control.bsth_c_stationroute WHERE destroy=0 ORDER BY station_code,directions,line_code 42 + SELECT l.shanghai_linecode,r.station_route_code,r.directions,r.line_code,r.station_name,r.station_code
  43 + from bsth_c_line l LEFT JOIN bsth_c_stationroute r on l.line_code=r.line_code
  44 + WHERE l.destroy=0 and r.destroy=0 ORDER BY line_code,directions,station_route_code
66 </select> 45 </select>
67 46
68 - <select id="getRecords" resultType="com.example.demo.model.TJRLDB">  
69 - SELECT *  
70 - from ${table} where TJRLRDATE >= '${start}' and TJRLRDATE &lt; '${end}' 47 +
  48 + <select id="getMaxTime" resultType="String" parameterType="String">
  49 + SELECT max(CONCAT(real_exec_date,' ', zdsj_actual)) time FROM `bsth_c_s_sp_info_real`
  50 + where (bc_type ='normal' or bc_type ='venting') and schedule_date_str='${date}'
71 </select> 51 </select>
72 52
73 53
src/test/java/com/example/demo/DemoApplicationTests.java
1 package com.example.demo; 1 package com.example.demo;
2 2
3 -import com.example.demo.service.Analysis; 3 +
4 import com.example.demo.service.Contrast; 4 import com.example.demo.service.Contrast;
5 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.boot.test.context.SpringBootTest; 6 import org.springframework.boot.test.context.SpringBootTest;