Commit 2fdcc1f21972102441bc553b2bf3eb505715561e

Authored by yiming
1 parent ec0b8de9

票务管理ym

... ... @@ -78,6 +78,21 @@
78 78 <version>2.3.2</version>
79 79 </dependency>
80 80  
  81 + <dependency>
  82 + <groupId>org.springframework.kafka</groupId>
  83 + <artifactId>spring-kafka</artifactId>
  84 + </dependency>
  85 + <dependency>
  86 + <groupId>com.baomidou</groupId>
  87 + <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
  88 + <version>2.5.6</version>
  89 + </dependency>
  90 +
  91 + <dependency>
  92 + <groupId>com.alibaba</groupId>
  93 + <artifactId>druid-spring-boot-starter</artifactId>
  94 + <version>1.1.20</version>
  95 + </dependency>
81 96 </dependencies>
82 97  
83 98 <build>
... ...
src/main/java/com/example/demo/DemoApplication.java
1 1 package com.example.demo;
2 2  
  3 +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
3 4 import org.slf4j.Logger;
4 5 import org.slf4j.LoggerFactory;
5 6 import org.springframework.boot.SpringApplication;
... ... @@ -7,11 +8,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
7 8 import org.springframework.boot.builder.SpringApplicationBuilder;
8 9 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
9 10  
10   -import java.io.IOException;
11   -import java.nio.file.*;
12   -import java.util.concurrent.TimeUnit;
13 11  
14   -@SpringBootApplication
  12 +
  13 +
  14 +@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
15 15 public class DemoApplication extends SpringBootServletInitializer {
16 16  
17 17 static Logger logger = LoggerFactory.getLogger(DemoApplication.class);
... ...
src/main/java/com/example/demo/SaticScheduleTask.java
1 1 package com.example.demo;
2 2  
3 3  
  4 +import com.example.demo.model.Scheduling;
4 5 import com.example.demo.service.Analysis;
5 6 import com.example.demo.service.Contrast;
6   -import org.junit.Test;
7 7 import org.slf4j.Logger;
8 8 import org.slf4j.LoggerFactory;
9 9 import org.springframework.beans.factory.InitializingBean;
... ... @@ -12,20 +12,13 @@ import org.springframework.beans.factory.annotation.Value;
12 12 import org.springframework.context.annotation.Configuration;
13 13 import org.springframework.scheduling.annotation.EnableScheduling;
14 14 import org.springframework.scheduling.annotation.Scheduled;
15   -import org.springframework.stereotype.Component;
16 15  
17   -import java.io.File;
18   -import java.io.IOException;
  16 +import javax.annotation.PostConstruct;
  17 +import java.io.*;
19 18 import java.nio.file.*;
20   -import java.text.SimpleDateFormat;
21 19 import java.time.LocalDateTime;
22   -import java.util.ArrayList;
23   -import java.util.Date;
24   -import java.util.List;
25   -import java.util.Map;
26   -import java.util.concurrent.LinkedBlockingQueue;
27   -import java.util.concurrent.ThreadPoolExecutor;
28   -import java.util.concurrent.TimeUnit;
  20 +import java.time.format.DateTimeFormatter;
  21 +import java.util.*;
29 22  
30 23 /**
31 24 * @author Hill
... ... @@ -39,31 +32,92 @@ public class SaticScheduleTask implements InitializingBean {
39 32 @Value("${ftp.root}")
40 33 private String rootPath;
41 34  
  35 +
42 36 private WatchService watchService;
43 37  
44 38 @Autowired
45 39 private Contrast contrast;
46 40  
  41 +
  42 + public Map<String,List<Scheduling>> getSchedulingS;
  43 +
  44 + public List<Map> data=new ArrayList<>();
  45 +
47 46 /**
48 47 * 定时任务
49 48 */
50   - @Scheduled(cron = "0/5 * * * * ?")
51   - private void configureTasks() {
  49 + @Scheduled(cron = "0 0/6 * * * ?")
  50 + private void configureTasks() throws Exception{
52 51 logger.info("执行静态定时任务时间: " + LocalDateTime.now());
53 52 WatchKey watchKey = null;
54 53 List<File> files = new ArrayList<>();
55 54 while ((watchKey = watchService.poll()) != null) {
56 55 for (WatchEvent watchEvent : watchKey.pollEvents()) {
57 56 Path path = (Path)watchEvent.context();
58   - files.add(new File(rootPath + File.separator + path.toString()));
  57 + if(path!=null){
  58 + files.add(new File(rootPath + File.separator + path));
  59 + }
  60 +
59 61 }
60 62 watchKey.reset();
61 63 }
62   -
  64 + // "TJRLAMT" -> "00000200" 交易金额
  65 + // "TJRLCDKIND" -> "01" 卡类型
  66 + // "TJRLCDBAL" -> "00000000" 交易前余额
  67 + // "TJRLTXFG" -> "88" 交易类型
  68 + // "TJRLPOSID" -> "00A699" POS机号
  69 + // "TJRLRTIME" -> "23:58:46"
  70 + // "TJRLORGAMT" -> "0200" 交易原始金额
  71 + // "TJRLCARDNO" -> "B1403683" 交通卡号
  72 + // "TJRLRDATE" -> "2021-07-09"
  73 + //先把处理上一次没匹配到的
  74 + if(!data.isEmpty()){
  75 + contrast.filterCardList(data,true);
  76 + }
63 77 List<Map> allFile = Analysis.getAllFile(files);
64   - contrast.filterCardList(allFile);
  78 + contrast.filterCardList(allFile,false);
  79 + }
  80 +
  81 + @Scheduled(cron = "0 0/10 * * * ?")
  82 + @PostConstruct
  83 + void getArrivalInfos() {
  84 + logger.info("票务数据缓存加载: " + LocalDateTime.now());
  85 + LocalDateTime now=LocalDateTime.now();
  86 + //测试
  87 + /* DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  88 + now=LocalDateTime.parse("2021-07-11 00:00",tdf);*/
  89 +
  90 + this.getSchedulingS=contrast.getSchedulingS(now,1);
65 91 }
66 92  
  93 +
  94 + /**
  95 + * @Description: 用来计算数据库中的乘车记录
  96 + * @Param:
  97 + * @return:
  98 + * @Author: YM
  99 + * @Date: 2021/10/13
  100 + */
  101 + //@Scheduled(cron = "0 30 17 * * ?")
  102 + private void filterCardListByDB() throws Exception {
  103 + DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  104 + LocalDateTime now=LocalDateTime.parse("2021-08-01 00:00",tdf);
  105 +
  106 + int day=1;
  107 + this.getSchedulingS=contrast.getSchedulingS(now,day);
  108 +
  109 + Map<String,Object> map=new HashMap<>();
  110 + map.put("table","pd_control."+"ftj20210806");
  111 + LocalDateTime startDate=now.minusDays(day);
  112 + String start=startDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
  113 + String end=now.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
  114 + map.put("start",start);
  115 + map.put("end",end);
  116 + contrast.filterCardListByDB(map);
  117 + }
  118 +
  119 +
  120 +
67 121 @Override
68 122 public void afterPropertiesSet() throws Exception {
69 123 watchService = FileSystems.getDefault().newWatchService();
... ...
src/main/java/com/example/demo/dataSource/DataSourceConfig1.java 0 → 100644
  1 +package com.example.demo.dataSource;
  2 +
  3 +import org.apache.ibatis.session.SqlSessionFactory;
  4 +import org.mybatis.spring.SqlSessionFactoryBean;
  5 +import org.mybatis.spring.SqlSessionTemplate;
  6 +import org.mybatis.spring.annotation.MapperScan;
  7 +import org.springframework.beans.factory.annotation.Qualifier;
  8 +import org.springframework.boot.context.properties.ConfigurationProperties;
  9 +import org.springframework.boot.jdbc.DataSourceBuilder;
  10 +import org.springframework.context.annotation.Bean;
  11 +import org.springframework.context.annotation.Configuration;
  12 +import org.springframework.context.annotation.Primary;
  13 +import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
  14 +
  15 +import javax.sql.DataSource;
  16 +
  17 +
  18 +@Configuration
  19 +@MapperScan(basePackages = "com.example.demo.mapper.db1", sqlSessionFactoryRef = "db1SqlSessionFactory")
  20 +public class DataSourceConfig1 {
  21 +
  22 + @Primary // 表示这个数据源是默认数据源, 这个注解必须要加,因为不加的话spring将分不清楚那个为主数据源(默认数据源)
  23 + @Bean("db1DataSource")
  24 + @ConfigurationProperties(prefix = "spring.datasource.db1") //读取application.yml中的配置参数映射成为一个对象
  25 + public DataSource getDb1DataSource(){
  26 + return DataSourceBuilder.create().build();
  27 + }
  28 +
  29 + @Primary
  30 + @Bean("db1SqlSessionFactory")
  31 + public SqlSessionFactory db1SqlSessionFactory(@Qualifier("db1DataSource") DataSource dataSource) throws Exception {
  32 + SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  33 + bean.setDataSource(dataSource);
  34 + // mapper的xml形式文件位置必须要配置,不然将报错:no statement (这种错误也可能是mapper的xml中,namespace与项目的路径不一致导致)
  35 + bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapping/db1/*.xml"));
  36 + return bean.getObject();
  37 + }
  38 +
  39 + @Primary
  40 + @Bean("db1SqlSessionTemplate")
  41 + public SqlSessionTemplate db1SqlSessionTemplate(@Qualifier("db1SqlSessionFactory") SqlSessionFactory sqlSessionFactory){
  42 + return new SqlSessionTemplate(sqlSessionFactory);
  43 + }
  44 +}
0 45 \ No newline at end of file
... ...
src/main/java/com/example/demo/dataSource/DataSourceConfig2.java 0 → 100644
  1 +package com.example.demo.dataSource;
  2 +import org.apache.ibatis.session.SqlSessionFactory;
  3 +import org.mybatis.spring.SqlSessionFactoryBean;
  4 +import org.mybatis.spring.SqlSessionTemplate;
  5 +import org.mybatis.spring.annotation.MapperScan;
  6 +import org.springframework.beans.factory.annotation.Qualifier;
  7 +import org.springframework.boot.context.properties.ConfigurationProperties;
  8 +import org.springframework.boot.jdbc.DataSourceBuilder;
  9 +import org.springframework.context.annotation.Bean;
  10 +import org.springframework.context.annotation.Configuration;
  11 +import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
  12 +import javax.sql.DataSource;
  13 +
  14 +@Configuration
  15 +@MapperScan(basePackages = "com.example.demo.mapper.db2", sqlSessionFactoryRef = "db2SqlSessionFactory")
  16 +public class DataSourceConfig2 {
  17 +
  18 + @Bean("db2DataSource")
  19 + @ConfigurationProperties(prefix = "spring.datasource.db2")
  20 + public DataSource getDb1DataSource(){
  21 + return DataSourceBuilder.create().build();
  22 + }
  23 +
  24 + @Bean("db2SqlSessionFactory")
  25 + public SqlSessionFactory db1SqlSessionFactory(@Qualifier("db2DataSource") DataSource dataSource) throws Exception {
  26 + SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  27 + bean.setDataSource(dataSource);
  28 + bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapping/db2/*.xml"));
  29 + return bean.getObject();
  30 + }
  31 +
  32 + @Bean("db2SqlSessionTemplate")
  33 + public SqlSessionTemplate db1SqlSessionTemplate(@Qualifier("db2SqlSessionFactory") SqlSessionFactory sqlSessionFactory){
  34 + return new SqlSessionTemplate(sqlSessionFactory);
  35 + }
  36 +}
0 37 \ No newline at end of file
... ...
src/main/java/com/example/demo/mapper/SiteMapper.java deleted 100644 → 0
1   -package com.example.demo.mapper;
2   -
3   -
4   -import org.apache.ibatis.annotations.Mapper;
5   -
6   -import java.util.List;
7   -import java.util.Map;
8   -
9   -/**
10   - * @author sine
11   - */
12   -@Mapper
13   -public interface SiteMapper {
14   -
15   - /**
16   - * 查询排班
17   - */
18   - List<Map> queryScheduling(Map<String, Object> map);
19   -
20   - /**
21   - * 到离站
22   - *
23   - */
24   - List<Map> querydlSite(Map<String, Object> map);
25   -
26   - /**
27   - * 匹配路由
28   - */
29   - List<Map> querylyStie(Map<String, Object> map);
30   -
31   - void insertResult(List<Map> list);
32   -
33   -}
34 0 \ No newline at end of file
src/main/java/com/example/demo/mapper/db1/SiteMapper1.java 0 → 100644
  1 +package com.example.demo.mapper.db1;
  2 +
  3 +
  4 +import com.baomidou.dynamic.datasource.annotation.DS;
  5 +import com.example.demo.model.ArrivalInfo;
  6 +import com.example.demo.model.Scheduling;
  7 +import com.example.demo.model.StationRoute;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * @author sine
  15 + */
  16 +@Mapper
  17 +public interface SiteMapper1 {
  18 +
  19 +
  20 + @DS("db1")
  21 + void insertResult(List<Map> list);
  22 +
  23 + @DS("db1")
  24 + List<Scheduling> getScheduling(Map<String, Object> map);
  25 +
  26 + /* @DS("db2")
  27 + List<ArrivalInfo> getArrivalInfo(Map<String, Object> map);*/
  28 +
  29 + @DS("db1")
  30 + List<StationRoute> getStationRoute();
  31 +
  32 + @DS("db1")
  33 + List<Map> getRecords(Map<String, Object> map);
  34 +}
0 35 \ No newline at end of file
... ...
src/main/java/com/example/demo/mapper/db2/SiteMapper2.java 0 → 100644
  1 +package com.example.demo.mapper.db2;
  2 +
  3 +
  4 +import com.baomidou.dynamic.datasource.annotation.DS;
  5 +import com.example.demo.model.ArrivalInfo;
  6 +import com.example.demo.model.Scheduling;
  7 +import com.example.demo.model.StationRoute;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * @author sine
  15 + */
  16 +@Mapper
  17 +public interface SiteMapper2 {
  18 +
  19 +
  20 +
  21 + /*void insertResult(List<Map> list);
  22 +
  23 +
  24 + List<Scheduling> getScheduling(Map<String, Object> map);*/
  25 +
  26 + @DS("db2")
  27 + List<ArrivalInfo> getArrivalInfo(Map<String, Object> map);
  28 +
  29 +
  30 + /* List<StationRoute> getStationRoute();
  31 +
  32 +
  33 + List<Map> getRecords(Map<String, Object> map);*/
  34 +}
0 35 \ No newline at end of file
... ...
src/main/java/com/example/demo/model/ArrivalInfo.java 0 → 100644
  1 +package com.example.demo.model;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.Objects;
  5 +
  6 +public class ArrivalInfo {
  7 + private String device_id;
  8 + private String line_id;
  9 + private String stop_no;
  10 + private String ts;
  11 + private String up_down;
  12 + private String in_out;
  13 + private String create_date;
  14 + private String weeks_year;
  15 + private String create_timestamp;
  16 + private String ts_out;
  17 + private String J_name;
  18 + private String J_gh;
  19 +
  20 + public String getDevice_id() {
  21 + return device_id;
  22 + }
  23 +
  24 + public void setDevice_id(String device_id) {
  25 + this.device_id = device_id;
  26 + }
  27 +
  28 + public String getLine_id() {
  29 + return line_id;
  30 + }
  31 +
  32 + public void setLine_id(String line_id) {
  33 + this.line_id = line_id;
  34 + }
  35 +
  36 + public String getStop_no() {
  37 + return stop_no;
  38 + }
  39 +
  40 + public void setStop_no(String stop_no) {
  41 + this.stop_no = stop_no;
  42 + }
  43 +
  44 + public String getTs() {
  45 + return ts;
  46 + }
  47 +
  48 + public void setTs(String ts) {
  49 + this.ts = ts;
  50 + }
  51 +
  52 + public String getUp_down() {
  53 + return up_down;
  54 + }
  55 +
  56 + public void setUp_down(String up_down) {
  57 + this.up_down = up_down;
  58 + }
  59 +
  60 + public String getIn_out() {
  61 + return in_out;
  62 + }
  63 +
  64 + public void setIn_out(String in_out) {
  65 + this.in_out = in_out;
  66 + }
  67 +
  68 + public String getCreate_date() {
  69 + return create_date;
  70 + }
  71 +
  72 + public void setCreate_date(String create_date) {
  73 + this.create_date = create_date;
  74 + }
  75 +
  76 + public String getWeeks_year() {
  77 + return weeks_year;
  78 + }
  79 +
  80 + public void setWeeks_year(String weeks_year) {
  81 + this.weeks_year = weeks_year;
  82 + }
  83 +
  84 + public String getCreate_timestamp() {
  85 + return create_timestamp;
  86 + }
  87 +
  88 + public void setCreate_timestamp(String create_timestamp) {
  89 + this.create_timestamp = create_timestamp;
  90 + }
  91 +
  92 + public String getTs_out() {
  93 + return ts_out;
  94 + }
  95 +
  96 + public void setTs_out(String ts_out) {
  97 + this.ts_out = ts_out;
  98 + }
  99 +
  100 + public String getJ_name() {
  101 + return J_name;
  102 + }
  103 +
  104 + public void setJ_name(String j_name) {
  105 + J_name = j_name;
  106 + }
  107 +
  108 + public String getJ_gh() {
  109 + return J_gh;
  110 + }
  111 +
  112 + public void setJ_gh(String j_gh) {
  113 + J_gh = j_gh;
  114 + }
  115 +
  116 + @Override
  117 + public boolean equals(Object o) {
  118 + if (this == o) return true;
  119 + if (o == null || getClass() != o.getClass()) return false;
  120 + ArrivalInfo that = (ArrivalInfo) o;
  121 + return Objects.equals(device_id, that.device_id) && Objects.equals(line_id, that.line_id) && Objects.equals(stop_no, that.stop_no) && Objects.equals(ts, that.ts) && Objects.equals(up_down, that.up_down) && Objects.equals(in_out, that.in_out) && Objects.equals(create_date, that.create_date) && Objects.equals(weeks_year, that.weeks_year) && Objects.equals(create_timestamp, that.create_timestamp) && Objects.equals(ts_out, that.ts_out);
  122 + }
  123 +
  124 + @Override
  125 + public int hashCode() {
  126 + return Objects.hash(device_id, line_id, stop_no, ts, up_down, in_out, create_date, weeks_year, create_timestamp, ts_out);
  127 + }
  128 +
  129 + @Override
  130 + public String toString() {
  131 + return "ArrivalInfo{" +
  132 + "device_id='" + device_id + '\'' +
  133 + ", line_id='" + line_id + '\'' +
  134 + ", stop_no='" + stop_no + '\'' +
  135 + ", ts='" + ts + '\'' +
  136 + ", up_down='" + up_down + '\'' +
  137 + ", in_out='" + in_out + '\'' +
  138 + ", create_date='" + create_date + '\'' +
  139 + ", weeks_year='" + weeks_year + '\'' +
  140 + ", create_timestamp='" + create_timestamp + '\'' +
  141 + ", ts_out='" + ts_out + '\'' +
  142 + '}';
  143 + }
  144 +
  145 +}
... ...
src/main/java/com/example/demo/model/Scheduling.java 0 → 100644
  1 +package com.example.demo.model;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collections;
  5 +import java.util.List;
  6 +
  7 +//bsth_c_s_sp_info_real和 bsth_c_cars
  8 +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;//日期
  14 + private String xl_bm;
  15 + private String xl_dir;
  16 + private String bc_type;
  17 + private String cl_zbh;//车辆编号
  18 + private String lp_name;
  19 + private String qdz_name;
  20 + private String qdz_code;
  21 + private String fcsj_actual;//实际发车时间
  22 + private String zdz_name;
  23 + private String zdz_code;
  24 + 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 +
  37 + public String getGs_name() {
  38 + return gs_name;
  39 + }
  40 +
  41 + public void setGs_name(String gs_name) {
  42 + this.gs_name = gs_name;
  43 + }
  44 +
  45 + public String getXl_name() {
  46 + return xl_name;
  47 + }
  48 +
  49 + public void setXl_name(String xl_name) {
  50 + this.xl_name = xl_name;
  51 + }
  52 +
  53 + public String getJ_gh() {
  54 + return j_gh;
  55 + }
  56 +
  57 + public void setJ_gh(String j_gh) {
  58 + this.j_gh = j_gh;
  59 + }
  60 +
  61 +
  62 +
  63 + public String getXl_bm() {
  64 + return xl_bm;
  65 + }
  66 +
  67 + public void setXl_bm(String xl_bm) {
  68 + this.xl_bm = xl_bm;
  69 + }
  70 +
  71 + public String getXl_dir() {
  72 + return xl_dir;
  73 + }
  74 +
  75 + public void setXl_dir(String xl_dir) {
  76 + this.xl_dir = xl_dir;
  77 + }
  78 +
  79 + public String getBc_type() {
  80 + return bc_type;
  81 + }
  82 +
  83 + public void setBc_type(String bc_type) {
  84 + this.bc_type = bc_type;
  85 + }
  86 +
  87 + public String getCl_zbh() {
  88 + return cl_zbh;
  89 + }
  90 +
  91 + public void setCl_zbh(String cl_zbh) {
  92 + this.cl_zbh = cl_zbh;
  93 + }
  94 +
  95 + public String getLp_name() {
  96 + return lp_name;
  97 + }
  98 +
  99 + public void setLp_name(String lp_name) {
  100 + this.lp_name = lp_name;
  101 + }
  102 +
  103 + public String getQdz_name() {
  104 + return qdz_name;
  105 + }
  106 +
  107 + public void setQdz_name(String qdz_name) {
  108 + this.qdz_name = qdz_name;
  109 + }
  110 +
  111 + public String getQdz_code() {
  112 + return qdz_code;
  113 + }
  114 +
  115 + public void setQdz_code(String qdz_code) {
  116 + this.qdz_code = qdz_code;
  117 + }
  118 +
  119 + public String getFcsj_actual() {
  120 + return fcsj_actual;
  121 + }
  122 +
  123 + public void setFcsj_actual(String fcsj_actual) {
  124 + this.fcsj_actual = fcsj_actual;
  125 + }
  126 +
  127 + public String getZdz_name() {
  128 + return zdz_name;
  129 + }
  130 +
  131 + public void setZdz_name(String zdz_name) {
  132 + this.zdz_name = zdz_name;
  133 + }
  134 +
  135 + public String getZdz_code() {
  136 + return zdz_code;
  137 + }
  138 +
  139 + public void setZdz_code(String zdz_code) {
  140 + this.zdz_code = zdz_code;
  141 + }
  142 +
  143 + public String getZdsj_actual() {
  144 + return zdsj_actual;
  145 + }
  146 +
  147 + public void setZdsj_actual(String zdsj_actual) {
  148 + this.zdsj_actual = zdsj_actual;
  149 + }
  150 +
  151 + public String getEquipment_code() {
  152 + return equipment_code;
  153 + }
  154 +
  155 + public void setEquipment_code(String equipment_code) {
  156 + this.equipment_code = equipment_code;
  157 + }
  158 +
  159 + public String getCar_plate() {
  160 + return car_plate;
  161 + }
  162 +
  163 + public void setCar_plate(String car_plate) {
  164 + this.car_plate = car_plate;
  165 + }
  166 +
  167 + public String getJ_name() {
  168 + return j_name;
  169 + }
  170 +
  171 + public void setJ_name(String j_name) {
  172 + this.j_name = j_name;
  173 + }
  174 +
  175 + public String getSchedule_date_str() {
  176 + return schedule_date_str;
  177 + }
  178 +
  179 + public void setSchedule_date_str(String schedule_date_str) {
  180 + this.schedule_date_str = schedule_date_str;
  181 + }
  182 +
  183 + public String getStop_no() {
  184 + return stop_no;
  185 + }
  186 +
  187 + public void setStop_no(String stop_no) {
  188 + this.stop_no = stop_no;
  189 + }
  190 +
  191 + public String getUp_down() {
  192 + return up_down;
  193 + }
  194 +
  195 + public void setUp_down(String up_down) {
  196 + this.up_down = up_down;
  197 + }
  198 +
  199 + public String getLine_id() {
  200 + return line_id;
  201 + }
  202 +
  203 + public void setLine_id(String line_id) {
  204 + this.line_id = line_id;
  205 + }
  206 +
  207 + public String getReal_exec_date() {
  208 + return real_exec_date;
  209 + }
  210 +
  211 + public void setReal_exec_date(String real_exec_date) {
  212 + this.real_exec_date = real_exec_date;
  213 + }
  214 +
  215 + public String getTs() {
  216 + return ts;
  217 + }
  218 +
  219 + public void setTs(String ts) {
  220 + this.ts = ts;
  221 + }
  222 +
  223 + public String getTs_out() {
  224 + return ts_out;
  225 + }
  226 +
  227 + public void setTs_out(String ts_out) {
  228 + this.ts_out = ts_out;
  229 + }
  230 +
  231 + public String getStation_route_code() {
  232 + return station_route_code;
  233 + }
  234 +
  235 + public void setStation_route_code(String station_route_code) {
  236 + this.station_route_code = station_route_code;
  237 + }
  238 +
  239 + public String getStation_name() {
  240 + return station_name;
  241 + }
  242 +
  243 + public void setStation_name(String station_name) {
  244 + this.station_name = station_name;
  245 + }
  246 +
  247 + public String getStation_code() {
  248 + return station_code;
  249 + }
  250 +
  251 + public void setStation_code(String station_code) {
  252 + this.station_code = station_code;
  253 + }
  254 +
  255 + @Override
  256 + public String toString() {
  257 + return "Scheduling{" +
  258 + "gs_name='" + gs_name + '\'' +
  259 + ", xl_name='" + xl_name + '\'' +
  260 + ", j_gh='" + j_gh + '\'' +
  261 + ", j_name='" + j_name + '\'' +
  262 + ", schedule_date_str='" + schedule_date_str + '\'' +
  263 + ", xl_bm='" + xl_bm + '\'' +
  264 + ", xl_dir='" + xl_dir + '\'' +
  265 + ", bc_type='" + bc_type + '\'' +
  266 + ", cl_zbh='" + cl_zbh + '\'' +
  267 + ", lp_name='" + lp_name + '\'' +
  268 + ", qdz_name='" + qdz_name + '\'' +
  269 + ", qdz_code='" + qdz_code + '\'' +
  270 + ", fcsj_actual='" + fcsj_actual + '\'' +
  271 + ", zdz_name='" + zdz_name + '\'' +
  272 + ", zdz_code='" + zdz_code + '\'' +
  273 + ", zdsj_actual='" + zdsj_actual + '\'' +
  274 + ", equipment_code='" + equipment_code + '\'' +
  275 + ", car_plate='" + car_plate + '\'' +
  276 + ", stop_no='" + stop_no + '\'' +
  277 + ", up_down='" + up_down + '\'' +
  278 + ", line_id='" + line_id + '\'' +
  279 + ", real_exec_date='" + real_exec_date + '\'' +
  280 + ", ts='" + ts + '\'' +
  281 + ", ts_out='" + ts_out + '\'' +
  282 + ", station_route_code='" + station_route_code + '\'' +
  283 + ", station_name='" + station_name + '\'' +
  284 + ", station_code='" + station_code + '\'' +
  285 + '}';
  286 + }
  287 +
  288 + @Override
  289 + public int compareTo(Scheduling o) {
  290 + String t1=this.getSchedule_date_str()+this.getFcsj_actual();
  291 + String t2=o.getSchedule_date_str()+o.getFcsj_actual();
  292 + int i=t1.compareTo(t2);
  293 + int a;
  294 + if(i<0){
  295 + a=1;
  296 + }else if(i==0){
  297 + a=0;
  298 + }else {
  299 + a=-1;
  300 + }
  301 + return a;
  302 +
  303 + }
  304 +
  305 + @Override
  306 + public Object clone() throws CloneNotSupportedException {
  307 + return super.clone();
  308 + }
  309 +
  310 + public static void main(String[] args) {
  311 + Scheduling scheduling=new Scheduling();
  312 + scheduling.setSchedule_date_str("2021-10-15");
  313 + scheduling.setFcsj_actual("09:10");
  314 + Scheduling scheduling2=new Scheduling();
  315 + scheduling2.setSchedule_date_str("2021-10-14");
  316 + scheduling2.setFcsj_actual("09:11");
  317 + List<Scheduling> list=new ArrayList();
  318 + list.add(scheduling);
  319 + list.add(scheduling2);
  320 + Collections.sort(list);
  321 + System.out.println(list.get(0).getSchedule_date_str()+list.get(0).getFcsj_actual());
  322 + System.out.println(list.get(1).getSchedule_date_str()+list.get(1).getFcsj_actual());
  323 + }
  324 +
  325 +}
... ...
src/main/java/com/example/demo/model/StationRoute.java 0 → 100644
  1 +package com.example.demo.model;
  2 +
  3 +public class StationRoute {
  4 + private String station_route_code;
  5 + private String directions;
  6 + private String line_code;
  7 + private String station_name;
  8 + private String station_code;
  9 +
  10 + public String getStation_route_code() {
  11 + return station_route_code;
  12 + }
  13 +
  14 + public void setStation_route_code(String station_route_code) {
  15 + this.station_route_code = station_route_code;
  16 + }
  17 +
  18 + public String getDirections() {
  19 + return directions;
  20 + }
  21 +
  22 + public void setDirections(String directions) {
  23 + this.directions = directions;
  24 + }
  25 +
  26 + public String getLine_code() {
  27 + return line_code;
  28 + }
  29 +
  30 + public void setLine_code(String line_code) {
  31 + this.line_code = line_code;
  32 + }
  33 +
  34 + public String getStation_name() {
  35 + return station_name;
  36 + }
  37 +
  38 + public void setStation_name(String station_name) {
  39 + this.station_name = station_name;
  40 + }
  41 +
  42 + public String getStation_code() {
  43 + return station_code;
  44 + }
  45 +
  46 + public void setStation_code(String station_code) {
  47 + this.station_code = station_code;
  48 + }
  49 +}
... ...
src/main/java/com/example/demo/service/Analysis.java
1 1 package com.example.demo.service;
2 2  
  3 +import com.example.demo.SaticScheduleTask;
3 4 import org.slf4j.Logger;
4 5 import org.slf4j.LoggerFactory;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.beans.factory.annotation.Value;
  8 +import org.springframework.kafka.core.KafkaTemplate;
  9 +import org.springframework.stereotype.Component;
5 10  
6 11 import java.io.BufferedReader;
7 12 import java.io.File;
... ... @@ -10,15 +15,20 @@ import java.text.ParseException;
10 15 import java.text.SimpleDateFormat;
11 16 import java.util.*;
12 17  
  18 +@Component
13 19 public class Analysis {
14 20 protected final Logger logger = LoggerFactory.getLogger(this.getClass());
15 21  
16 22 private static Date startDate = subtractTime(new Date(), -300000);
17 23  
  24 +
  25 + private static String oldFile;
  26 +
  27 +
18 28 /**
19 29 * 获取路径下的所有文件/文件夹 /读取文件 返回时间和carid
20 30 *
21   - * @param directoryPath 需要遍历的文件夹路径
  31 + * @param files 需要遍历的文件夹路径
22 32 * @return
23 33 */
24 34 public static List<Map> getAllFile(List<File> files) {
... ... @@ -64,6 +74,10 @@ public class Analysis {
64 74 listMap.add(map);
65 75 }
66 76 //}
  77 + Analysis analysis=new Analysis();
  78 + analysis.setOldFile(oldFile);
  79 + File f=new File(analysis.oldFile+File.separator+file.getName());
  80 + file.renameTo(f);
67 81 }
68 82 }
69 83 return listMap;
... ... @@ -133,6 +147,10 @@ public class Analysis {
133 147 }
134 148 }
135 149  
  150 + @Value("${ftp.oldFile}")
  151 + public void setOldFile(String oldFile) {
  152 + Analysis.oldFile = oldFile;
  153 + }
136 154  
137 155 }
138 156  
... ...
src/main/java/com/example/demo/service/Contrast.java
... ... @@ -3,21 +3,28 @@ package com.example.demo.service;
3 3 import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.bsth.util.HttpUtils;
6   -import com.example.demo.DemoApplication;
7   -import com.example.demo.mapper.SiteMapper;
8   -import org.junit.Test;
  6 +import com.example.demo.SaticScheduleTask;
  7 +import com.example.demo.mapper.db1.SiteMapper1;
  8 +import com.example.demo.mapper.db2.SiteMapper2;
  9 +import com.example.demo.model.ArrivalInfo;
  10 +import com.example.demo.model.Scheduling;
  11 +import com.example.demo.model.StationRoute;
  12 +import com.fasterxml.jackson.core.JsonProcessingException;
  13 +import com.fasterxml.jackson.databind.ObjectMapper;
9 14 import org.slf4j.Logger;
10 15 import org.slf4j.LoggerFactory;
11 16 import org.springframework.beans.factory.annotation.Autowired;
12   -import org.springframework.stereotype.Component;
  17 +import org.springframework.kafka.core.KafkaTemplate;
  18 +import org.springframework.kafka.support.SendResult;
13 19 import org.springframework.stereotype.Service;
  20 +import org.springframework.util.concurrent.ListenableFuture;
  21 +import org.springframework.util.concurrent.ListenableFutureCallback;
14 22  
15   -import javax.annotation.PostConstruct;
16   -import javax.annotation.Resource;
17 23 import java.text.ParseException;
18 24 import java.text.SimpleDateFormat;
  25 +import java.time.*;
  26 +import java.time.format.DateTimeFormatter;
19 27 import java.util.*;
20   -import java.util.concurrent.TimeUnit;
21 28 import java.util.stream.Collectors;
22 29  
23 30  
... ... @@ -27,8 +34,21 @@ public class Contrast {
27 34 Logger logger = LoggerFactory.getLogger(Contrast.class);
28 35  
29 36 @Autowired
30   - private SiteMapper siteMapper;
  37 + private SiteMapper1 siteMapper1;
31 38  
  39 + @Autowired
  40 + private SiteMapper2 siteMapper2;
  41 +
  42 + @Autowired
  43 + private KafkaTemplate kafkaTemplate;
  44 +
  45 +
  46 +
  47 + @Autowired
  48 + private SaticScheduleTask saticScheduleTask;
  49 +
  50 + private final int TIME=5;
  51 + private final int TIME2=3;//刷卡的时间和到站实际允许误差值
32 52  
33 53 public List<Map> getDriverCardList() {
34 54 List<Map> list = new ArrayList<>();
... ... @@ -52,93 +72,282 @@ public class Contrast {
52 72 return list;
53 73 }
54 74  
  75 +
  76 + /**
  77 + * @Description:车辆、排班、进出站、路由的关联及预加载
  78 + * @Param: now加载的最终时间 day加载几天
  79 + * @return: 关联后的结果集
  80 + * @Author: YM
  81 + * @Date: 2021/10/12
  82 + */
  83 + public Map<String,List<Scheduling>> getSchedulingS(LocalDateTime now,int day) {
  84 + List<Scheduling> schedulingS=new ArrayList<>();
  85 + long start = System.currentTimeMillis();
  86 + Map map = new HashMap();
  87 + //通过驾驶员信息和 刷卡时间 查询 排班表 和车辆表
  88 + LocalDateTime localDateTimeStart=now.minusDays(day);
  89 + LocalDateTime localDateTimeEnd=now.plusMinutes(60);
  90 +
  91 + DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
  92 + map.put("startTime",localDateTimeStart.format(tdf));
  93 + map.put("endTime",localDateTimeEnd.format(tdf));
  94 + List<Scheduling> schedulingList = siteMapper1.getScheduling(map);
  95 +
  96 + //按车辆和方向分组
  97 + Map<String, List<Scheduling>> m = schedulingList.stream().collect(Collectors.groupingBy(s->s.getEquipment_code()+"_"+s.getXl_bm()+"_"+s.getXl_dir()));
  98 + //站点路由
  99 + List<StationRoute> StationRouteList=siteMapper1.getStationRoute();
  100 + Map<String, List<StationRoute>> m2 = StationRouteList.stream().collect(Collectors.groupingBy(s->s.getStation_code()+"_"+s.getDirections()+"_"+s.getLine_code()));
  101 +
  102 + //合并进出表数据
  103 + map.clear();
  104 + map.put("timeStart",localDateTimeStart.toInstant(ZoneOffset.of("+8")).toEpochMilli());
  105 + map.put("timeEnd",localDateTimeEnd.toInstant(ZoneOffset.of("+8")).toEpochMilli());
  106 + int weekStr=getWeek(localDateTimeStart.toString());
  107 + int weekEnd=getWeek(localDateTimeEnd.toString());
  108 + String weeks="";
  109 + if(weekStr==weekEnd){
  110 + weeks="= "+weekStr;
  111 + }else {
  112 + weeks="in ("+weekStr+","+weekEnd+")";
  113 + }
  114 + map.put("weeks",weeks);
  115 + map.put("year",localDateTimeStart.getYear());
  116 + List<ArrivalInfo> list= siteMapper2.getArrivalInfo(map);
  117 + List<ArrivalInfo> arrivalInfoList=new ArrayList<>();
  118 + ArrivalInfo in=null;
  119 + for (ArrivalInfo arrivalInfo : list) {
  120 + if("0".equals(arrivalInfo.getIn_out())){//进站
  121 + in=arrivalInfo;
  122 + }
  123 + //把出站时间合并到进站数据中
  124 + if ("1".equals(arrivalInfo.getIn_out()) && in!=null && in.getDevice_id().equals(arrivalInfo.getDevice_id()) &&
  125 + in.getLine_id().equals(arrivalInfo.getLine_id()) && in.getStop_no().equals(arrivalInfo.getStop_no())){
  126 + in.setTs_out(arrivalInfo.getTs());
  127 + in.setUp_down(arrivalInfo.getUp_down());
  128 + arrivalInfoList.add(in);
  129 + in=null;
  130 + }
  131 + }
  132 +
  133 +
  134 +
  135 + int b = 0;
  136 + DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  137 + for (ArrivalInfo arrivalInfo : arrivalInfoList) {//进出表
  138 + //进出站时间
  139 + LocalDateTime inTime=LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(arrivalInfo.getTs())), ZoneOffset.of("+8"));
  140 + LocalDateTime outTime=LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(arrivalInfo.getTs_out())), ZoneOffset.of("+8"));
  141 +
  142 +
  143 + String key=arrivalInfo.getDevice_id()+"_"+arrivalInfo.getLine_id()+"_"+arrivalInfo.getUp_down();
  144 + List<Scheduling> l=m.get(key);
  145 + if(l!=null){
  146 + Collections.sort(l);
  147 + for (Scheduling scheduling : l) {
  148 + //实际发车到达时间
  149 + if(scheduling.getFcsj_actual()!=null){
  150 + LocalDateTime fcsj_actual=LocalDateTime.parse(scheduling.getReal_exec_date()+" "+scheduling.getFcsj_actual(),dateTimeFormatter).minusMinutes(TIME);
  151 + if(fcsj_actual.isBefore(inTime)){
  152 + Scheduling scheduling1= null;
  153 + try {
  154 + scheduling1 = (Scheduling) scheduling.clone();
  155 + } catch (CloneNotSupportedException e) {
  156 + e.printStackTrace();
  157 + }
  158 + scheduling1.setStop_no(arrivalInfo.getStop_no());
  159 + scheduling1.setTs(arrivalInfo.getTs());
  160 + scheduling1.setTs_out(arrivalInfo.getTs_out());
  161 +
  162 + //合并路由表
  163 + String keyRoute=scheduling1.getStop_no()+"_"+scheduling1.getXl_dir()+"_"+scheduling1.getXl_bm();
  164 + List<StationRoute> routes=m2.get(keyRoute);
  165 + if(routes!=null && routes.size()>0){
  166 + StationRoute route=routes.get(0);
  167 + scheduling1.setStation_route_code(route.getStation_route_code());
  168 + scheduling1.setStation_name(route.getStation_name());
  169 + scheduling1.setStation_code(route.getStation_code());
  170 + }
  171 + schedulingS.add(scheduling1);
  172 + b++;
  173 + break;
  174 + }
  175 + }
  176 + }
  177 + }
  178 + }
  179 +
  180 + Map<String,List<Scheduling>> result= schedulingS.stream().collect(Collectors.groupingBy(s->s.getJ_name()));
  181 +
  182 + logger.warn("======匹配"+arrivalInfoList.size()+"条======匹配成功 "+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒");
  183 + return result;
  184 + }
  185 +
  186 +
  187 +
  188 +
55 189 /**
56   - * 根据当前文件的carid 获取票务数据
57   - *
58   - * @param allData
  190 + * @Description: 根据carid 获取票务数据
  191 + * @Param: allData交易记录 isOld是否是残余数据(上次未匹配到的数据)
  192 + * @return:
  193 + * @Author: YM
  194 + * @Date: 2021/10/13
59 195 */
60   - public void filterCardList(List<Map> allData) {
  196 + public void filterCardList(List<Map> allData,Boolean isOld) {
61 197 long start = System.currentTimeMillis();
  198 + List<Map> driverCardList = getDriverCardList();//获取司机信息
  199 + Map<String,List<Scheduling>> schedulingS =saticScheduleTask.getSchedulingS;
  200 + DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  201 + int b=0;//用于计算匹配成功的数量
62 202 for (int i = 0; i < allData.size(); i++) {
63 203 Map data = allData.get(i);
64   - List<Map> driverCardList = getDriverCardList();
65   - String carId = data.get("TJRLCARDNO").toString();
  204 +
  205 + //通过卡号找到司机
  206 + String carId = data.get("TJRLCARDNO").toString().length()>8?
  207 + data.get("TJRLCARDNO").toString().substring( data.get("TJRLCARDNO").toString().length()-8):
  208 + data.get("TJRLCARDNO").toString();//交通卡号
66 209 List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList());
  210 +
  211 + String mark="";
  212 + Boolean flag=false;//用来判断是否没有匹配成功
  213 + Long cardDate = null;
67 214 if (!collect.isEmpty()) {
68 215 if (null != collect.get(0).get("jobCode") && null != collect.get(0).get("personalName")) {
69   - String personalName = collect.get(0).get("personalName").toString();
70   - String jobCodes = collect.get(0).get("jobCode").toString();//.split("-")[1];
71   - Map map = new HashMap();
72   - map.put("personalName", personalName);
73   - map.put("jobCode", jobCodes);
74   - map.put("date", data.get("TJRLRDATE"));
75   - map.put("time", data.get("TJRLRTIME"));
76   - List<Map> scheduling = siteMapper.queryScheduling(map);
77   - if (!scheduling.isEmpty()) {
78   - Map schedu = scheduling.get(0);
79   - data.put("STATION_FLAG", 1);
80   - data.put("TJRLUNITID", schedu.get("gs_name"));
81   - data.put("TJRLSTATID", schedu.get("xl_name"));
82   - data.put("ROAD_FORM_TYPE", schedu.get("bc_type"));
83   - data.put("UPDOWN", schedu.get("xl_dir"));
84   - data.put("BUS_CODE", schedu.get("cl_zbh"));
85   - data.put("BUS_PLATE", schedu.get("car_plate"));
86   - data.put("ROAD_CODE", schedu.get("lp_name"));
87   - data.put("DEPART_NAME", schedu.get("qdz_name"));
88   - data.put("DEPART_CODE", schedu.get("qdz_code"));
89   - data.put("DEPART_ACTUAL_TIME", schedu.get("fcsj_actual"));
90   - data.put("REACH_NAME", schedu.get("zdz_name"));
91   - data.put("REACH_CODE", schedu.get("zdz_code"));
92   - data.put("REACH_ACTUAL_TIME", schedu.get("zdsj_actual"));
93   -
94   - Map map1=new HashMap();
95   - map1.put("year", data.get("TJRLRDATE").toString().substring(0,4));
96   - map1.put("device_id", schedu.get("equipment_code"));
97   - map1.put("line_id", schedu.get("xl_bm"));
98   - map1.put("up_down", schedu.get("xl_dir"));
99   - map1.put("weeks_year",getWeek(data.get("TJRLRDATE").toString()));
100   - map1.put("dateTime", data.get("TJRLRDATE")+" "+ data.get("TJRLRTIME"));
101   - List<Map> list = siteMapper.querydlSite(map1);
102   - if(!list.isEmpty()){
103   - Map ydmap= list.get(0);
104   - Map dlSiteMap=new HashMap();
105   - dlSiteMap.put("station",ydmap.get("stop_no"));
106   - dlSiteMap.put("directions",ydmap.get("up_down"));
107   - dlSiteMap.put("line",ydmap.get("line_id"));
108   - List<Map> lysiteList = siteMapper.querylyStie(dlSiteMap);
109   - if(!lysiteList.isEmpty()){
110   - if(null !=lysiteList.get(0) && !"null".equals(lysiteList.get(0))){
111   - Map lysiteMap= lysiteList.get(0);
112   - data.put("LEVELS_FLAG",1);
113   - data.put("LEVELS1",lysiteMap.get("station_route_code"));
114   - data.put("LEVELS_NAME1",lysiteMap.get("station_name"));
115   - data.put("LEVELS1_CODE",lysiteMap.get("station_code"));
116   - }else {
117   - data.put("LEVELS_FLAG",0);
118   - }
119   -
120   - }else {
121   - data.put("LEVELS_FLAG",0);
  216 + String personalName = collect.get(0).get("personalName").toString();//姓名
  217 + String[] arr=collect.get(0).get("jobCode").toString().split("-");
  218 + String jobCodes =arr.length==0?collect.get(0).get("jobCode").toString():arr[arr.length-1];//工号
  219 + String time=String.valueOf(data.get("TJRLRTIME"));//时间
  220 + String date=String.valueOf(data.get("TJRLRDATE"));//日期
  221 +
  222 + cardDate = LocalDateTime.parse(date+" "+time,dtf).toInstant(ZoneOffset.of("+8")).toEpochMilli(); //刷卡时间(时间戳)
  223 +
  224 + //通过司机姓名获得进出记录
  225 + List<Scheduling> schedulingList1=schedulingS.get(personalName);
  226 + Scheduling scheduling = null;
  227 +
  228 +
  229 + if(schedulingList1!=null){
  230 + Collections.sort(schedulingList1);
  231 + for (Scheduling s : schedulingList1) {
  232 + if (jobCodes.contains(s.getJ_gh()) || s.getJ_gh().contains(jobCodes)){//防止同名 筛选工号 刷卡时间在进出站时间之间
  233 + if((Long.parseLong(s.getTs())-TIME2*60*1000)<=cardDate && (Long.parseLong(s.getTs_out())+TIME2*60*1000)>=cardDate){
  234 + scheduling=s;
  235 + b++;
  236 + flag=true;
  237 + break;
  238 + }/*else {
  239 + LocalDateTime card = LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8));
  240 + LocalDateTime in = LocalDateTime.ofEpochSecond(Long.parseLong(s.getTs())/1000, 0, ZoneOffset.ofHours(8));
  241 + LocalDateTime out = LocalDateTime.ofEpochSecond(Long.parseLong(s.getTs_out())/1000, 0, ZoneOffset.ofHours(8));
  242 + System.out.println("进站时间: "+in+" 出站时间:"+out+" 刷卡时间:"+card );
  243 + }*/
122 244 }
  245 + }
  246 + }else {
  247 + mark="未查到驾驶员排班:"+personalName+" 工号:"+jobCodes;
  248 + }
  249 +
  250 + if (scheduling!=null) {
  251 + data.put("STATION_FLAG", 1);
  252 + data.put("TJRLUNITID", scheduling.getGs_name());
  253 + data.put("TJRLSTATID", scheduling.getXl_name());
  254 + data.put("ROAD_FORM_TYPE", scheduling.getBc_type());
  255 + data.put("UPDOWN", scheduling.getXl_dir());
  256 + data.put("BUS_CODE", scheduling.getCl_zbh());
  257 + data.put("BUS_PLATE", scheduling.getCar_plate());
  258 + data.put("ROAD_CODE", scheduling.getLp_name());
  259 + data.put("DEPART_NAME", scheduling.getQdz_name());
  260 + data.put("DEPART_CODE", scheduling.getQdz_code());
  261 + data.put("DEPART_ACTUAL_TIME", scheduling.getFcsj_actual());
  262 + data.put("REACH_NAME", scheduling.getZdz_name());
  263 + data.put("REACH_CODE", scheduling.getZdz_code());
  264 + data.put("REACH_ACTUAL_TIME", scheduling.getZdsj_actual());
  265 +
123 266  
  267 + if(scheduling.getStation_name()!=null){
  268 + data.put("LEVELS_FLAG",1);
  269 + data.put("LEVELS1",scheduling.getStation_route_code());//站点路由序号
  270 + data.put("LEVELS_NAME1",scheduling.getStation_name());//站点名
  271 + data.put("LEVELS1_CODE",scheduling.getStop_no());//站点编号
  272 + }else {
  273 + data.put("LEVELS_FLAG",0);
124 274 }
125 275 } else {
126 276 data.put("STATION_FLAG", 0);
127 277 }
128   -
129 278 }
130 279 }else {
  280 + mark="未查到驾驶员 卡号:"+carId;
131 281 data.put("STATION_FLAG", 0);
132 282 }
  283 + if(mark.length()==0 && !flag){
  284 + mark="未匹配到班次 刷卡时间为:"+LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8));
  285 + }
  286 + data.put("MARK",mark);
  287 +
  288 + //如果是新数据 没匹配到 去除这条记录 并放入缓存等到下次继续匹配
  289 + if(!isOld && !flag){
  290 + List<Map> m =saticScheduleTask.data;
  291 + m.add(data);
  292 + allData.set(i,null);
  293 +
  294 + }
133 295 }
134   - if (!allData.isEmpty()) {
135   - siteMapper.insertResult(allData);
  296 + int size=allData.size();
  297 + allData.removeIf(Objects::isNull);
  298 + //防止数据过多 分批插入
  299 + List<List<Map>> subList = getSubList(2000, allData);
  300 + if(!subList.isEmpty()){
  301 + subList.forEach(data->{
  302 + if (!data.isEmpty()) {
  303 + siteMapper1.insertResult(data);
  304 + }
  305 + });
136 306 }
137   - logger.warn("======匹配"+allData.size()+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒");
  307 +
  308 + List<List<Map>> subList2 = getSubList(500, allData);
  309 + if(!subList2.isEmpty()){
  310 + subList2.forEach(data->{
  311 + if (!data.isEmpty()) {
  312 + Map<String, Object> map = new HashMap<>();
  313 + map.put("datatype", "passengerflow");
  314 + map.put("datas", data);
  315 +
  316 + ObjectMapper mapper = new ObjectMapper();
  317 + String json = null;
  318 + try {
  319 + json = mapper.writeValueAsString(map);
  320 + } catch (JsonProcessingException e) {
  321 + e.printStackTrace();
  322 + }
  323 +
  324 + ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json);
  325 + future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
  326 + @Override
  327 + public void onSuccess(SendResult<String, String> result) {
  328 + }
  329 + @Override
  330 + public void onFailure(Throwable ex) {
  331 + logger.error("kafka发送票务数据异常", ex);
  332 + }
  333 + });
  334 + }
  335 + });
  336 + }
  337 +
  338 +
  339 +
  340 + //如果是上次遗留的数据不管这是是否匹配到都清空
  341 + if(isOld){
  342 + saticScheduleTask.data.clear();
  343 + }
  344 +
  345 + logger.warn("======匹配"+size+"条======匹配到"+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒");
138 346 }
139 347  
140 348  
141 349  
  350 +
142 351 public static int getWeek(String today){
143 352 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
144 353 Date date = null;
... ... @@ -154,4 +363,58 @@ public class Contrast {
154 363 calendar.setTime(date);
155 364 return calendar.get(Calendar.WEEK_OF_YEAR);
156 365 }
  366 +
  367 + public static String upperHeadChar(String in) {
  368 + String head = in.substring(0, 1);
  369 + String out = head.toUpperCase() + in.substring(1, in.length());
  370 + return out;
  371 + }
  372 +
  373 + public static String getTransTime(String timeStr) {
  374 + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd HHmmss");
  375 + LocalDateTime date = LocalDateTime.parse(timeStr, df);
  376 + DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  377 + String transTime = f2.format(date);
  378 + return transTime;
  379 + }
  380 +
  381 +
  382 + public void filterCardListByDB(Map<String,Object> params) throws Exception{
  383 + List<Map> records=siteMapper1.getRecords(params);
  384 + for (Map record : records) {
  385 + String date=record.get("TJRLRDATE")+" "+String.format("%06d", Integer.parseInt(record.get("TJRLRTIME").toString()));
  386 + String s=this.getTransTime(date);
  387 + record.put("TJRLRDATE",s.split(" ")[0]);
  388 + record.put("TJRLRTIME",s.split(" ")[1]);
  389 + }
  390 + filterCardList(records,false);
  391 + }
  392 +
  393 + public List<List<Map>> getSubList(int length, List<Map> list){
  394 + int size = list.size();
  395 + int temp = size / length + 1;
  396 + boolean result = size % length == 0;
  397 + List<List<Map>> subList = new ArrayList<>();
  398 + for (int i = 0; i < temp; i++) {
  399 + if (i == temp - 1) {
  400 + if (result) {
  401 + break;
  402 + }
  403 + subList.add(list.subList(length * i, size)) ;
  404 + } else {
  405 + subList.add(list.subList(length * i, length * (i + 1))) ;
  406 + }
  407 + }
  408 + return subList;
  409 + }
  410 +
  411 + public static void main(String[] args) {
  412 + String carId="B140C906";
  413 + Contrast contrast=new Contrast();
  414 + List<Map> driverCardList = contrast.getDriverCardList();
  415 + List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList());
  416 + System.out.println(collect);
  417 + }
  418 +
  419 +
157 420 }
... ...
src/main/resources/application.properties
1 1 server.port=8088
2 2  
3   -spring.datasource.url=jdbc:mysql://192.168.168.240:3306/pd_control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
4   -spring.datasource.username=root
5   -spring.datasource.password=root2jsp
6   -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
7   -spring.datasource.druid.test-on-borrow=true
8   -spring.datasource.druid.test-while-idle=true
9   -
10   -mybatis.mapperLocations=classpath:mapping/*-mapper.xml
  3 +spring.datasource.db1.jdbc-url=jdbc:mysql://10.10.200.121:3306/control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  4 +spring.datasource.db1.username=ym
  5 +spring.datasource.db1.password=Ym(12345678)
  6 +spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
  7 +spring.datasource.db1.druid.test-on-borrow=true
  8 +spring.datasource.db1.druid.test-while-idle=true
  9 +
  10 +spring.datasource.db2.jdbc-url=jdbc:mysql://10.10.150.122:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  11 +spring.datasource.db2.username=ym
  12 +spring.datasource.db2.password=Ym(12345678)
  13 +spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver
  14 +spring.datasource.db2.druid.test-on-borrow=true
  15 +spring.datasource.db2.druid.test-while-idle=true
  16 +
  17 +
  18 +mybatis.mapperLocations=classpath:mapping/**/*.xml
11 19 mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
12   -#logging.level.com.bsth.mapper=DEBUG
13   -logging.level.org.mybatis = INFO
  20 +logging.level.com.example.demo.mapper=debug
  21 +#logging.level.org.mybatis = debug
  22 +
14 23  
15 24 #ftp
16   -ftp.root= E:\\data_test
17 25 \ No newline at end of file
  26 +ftp.root= /home/sftp
  27 +ftp.oldFile= /home/oldFile
  28 +
  29 +
  30 +spring.kafka.bootstrap-servers=10.10.200.45:19092
  31 +spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
  32 +spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
  33 +spring.kafka.producer.buffer-memory=33554432
  34 +spring.kafka.producer.acks=all
  35 +spring.kafka.producer.properties.max.request.size=20971520
  36 +
  37 +
  38 +
  39 +logging.path=/home/demo/log
  40 +
  41 +#??
  42 +#spring.datasource.db1.jdbc-url=jdbc:mysql://192.168.168.240:3306/pd_control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  43 +#spring.datasource.db1.username=root
  44 +#spring.datasource.db1.password=root2jsp
  45 +#spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
  46 +#spring.datasource.db1.druid.test-on-borrow=true
  47 +#spring.datasource.db1.druid.test-while-idle=true
  48 +#
  49 +#spring.datasource.db2.jdbc-url=jdbc:mysql://192.168.168.240:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  50 +#spring.datasource.db2.username=root
  51 +#spring.datasource.db2.password=root2jsp
  52 +#spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver
  53 +#spring.datasource.db2.druid.test-on-borrow=true
  54 +#spring.datasource.db2.druid.test-while-idle=true
  55 +#
  56 +#
  57 +#mybatis.mapperLocations=classpath:mapping/**/*.xml
  58 +#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
  59 +#logging.level.com.example.demo.mapper=debug
  60 +#
  61 +#
  62 +#ftp.root= E:\\data_test
  63 +#ftp.oldFile= E:\\oldFile
  64 +#
  65 +#
  66 +#spring.kafka.bootstrap-servers=114.80.178.12:9811
  67 +#spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
  68 +#spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
  69 +#spring.kafka.producer.buffer-memory=33554432
  70 +#spring.kafka.producer.acks=all
  71 +#spring.kafka.producer.properties.max.request.size=10485760
  72 +#
  73 +#
  74 +#logging.path=E:/log
18 75 \ No newline at end of file
... ...
src/main/resources/mapping/Site-mapper.xml renamed to src/main/resources/mapping/db1/Site-mapper1.xml
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
3   - "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4   -
5   -<mapper namespace="com.example.demo.mapper.SiteMapper">
6   -
7   - <select id="queryScheduling" resultType="map">
8   - SELECT CONCAT(gs_name, fgs_name) gs_name,
9   - xl_name,
10   - xl_bm,
11   - xl_dir,
12   - bc_type,
13   - cl_zbh,
14   - lp_name,
15   - qdz_name,
16   - qdz_code,
17   - fcsj_actual,
18   - zdz_name,
19   - zdz_code,
20   - zdsj_actual,
21   - cars.equipment_code,
22   - cars.car_plate
23   - FROM pd_control.bsth_c_s_sp_info_real
24   - LEFT JOIN pd_control.bsth_c_cars cars ON cars.inside_code = cl_zbh
25   - WHERE schedule_date_str = '${date}'
26   - AND '${jobCode}' LIKE CONCAT('%', j_gh, '%')
27   - AND j_name = '${personalName}'
28   - AND '${time}' BETWEEN fcsj_actual
29   - AND zdsj_actual
30   - </select>
31   -
32   - <select id="querydlSite" resultType="map">
33   - SELECT a.device_id,
34   - a.line_id,
35   - a.stop_no,
36   - a.up_down,
37   - b.ts - a.ts ts
38   - FROM (SELECT *
39   - FROM ms.bsth_c_arrival_info_${year}
40   - WHERE device_id = '${device_id}'
41   - AND line_id = '${line_id}'
42   - AND up_down = '${up_down}'
43   - AND in_out = 0
44   - AND weeks_year = '${weeks_year}') a
45   - JOIN (SELECT *
46   - FROM ms.bsth_c_arrival_info_${year}
47   - WHERE device_id = '${device_id}'
48   - AND line_id = '${line_id}'
49   - AND up_down = '${up_down}'
50   - AND in_out = 1
51   - AND weeks_year = '${weeks_year}') b ON a.device_id = b.device_id
52   - AND a.line_id = b.line_id
53   - AND a.stop_no = b.stop_no
54   - AND a.device_id = b.device_id
55   - WHERE UNIX_TIMESTAMP('${dateTime}') * 1000 BETWEEN a.ts
56   - AND b.ts
57   -
58   - GROUP BY a.stop_no
59   - ORDER BY ts
60   - </select>
61   -
62   - <select id="querylyStie" resultType="map">
63   - SELECT station_name,
64   - MAX(station_route_code) station_route_code,
65   - station_code
66   - FROM (
67   - SELECT l.line_code line_code,
68   - max(versions) versions
69   - FROM bsth_c_line l
70   - LEFT JOIN bsth_c_line_versions v ON l.line_code = v.line_code
71   - WHERE l.destroy = 0
72   - GROUP BY l.line_code
73   - ) b
74   - LEFT JOIN bsth_c_ls_stationroute a ON a.line_code = b.line_code
75   - AND a.versions = b.versions
76   - WHERE a.destroy = 0
77   - AND a.station = '${station}'
78   - AND directions = '${directions}'
79   - AND line = '${line}'
80   - ORDER BY a.line_code,
81   - a.directions,
82   - a.station_route_code
83   - </select>
84   -
85   -
86   - <insert id="insertResult" parameterType="List">
87   - INSERT INTO `pd_control`.`t_jc_result` (
88   - `TJRLCARDNO`, `TJRLINSID`, `TJRLCDKIND`, `TJRLPOSID`,`TJRLRDATE`,
89   - `TJRLRTIME`,`TJRLCDBAL`,`TJRLAMT`,`TJRLORGAMT`,
90   - `TJRLTXFG`,`STATION_FLAG`,`TJRLUNITID`,`TJRLSTATID`,`ROAD_FORM_TYPE`, `UPDOWN`, `BUS_CODE`,
91   - `BUS_PLATE`, `ROAD_CODE`, `DEPART_NAME`,`DEPART_CODE`, `DEPART_ACTUAL_TIME`,
92   - `REACH_NAME`,`REACH_CODE`,`REACH_ACTUAL_TIME`,
93   - `LEVELS_FLAG`,`LEVELS1`, `LEVELS_NAME1`, `LEVELS1_CODE`,`LEVELS2`, `LEVELS_NAME2`
94   - )
95   - VALUES
96   - <foreach collection="list" item="em" index="index" separator=",">
97   - ( #{em.TJRLCARDNO}, #{em.TJRLINSID}, #{em.TJRLCDKIND}, #{em.TJRLPOSID},#{em.TJRLRDATE},
98   - #{em.TJRLRTIME},#{em.TJRLCDBAL},#{em.TJRLAMT},#{em.TJRLORGAMT},
99   - #{em.TJRLTXFG},#{em.STATION_FLAG},#{em.TJRLUNITID},#{em.TJRLSTATID},#{em.ROAD_FORM_TYPE}, #{em.UPDOWN},
100   - #{em.BUS_CODE},
101   - #{em.BUS_PLATE}, #{em.ROAD_CODE}, #{em.DEPART_NAME},#{em.DEPART_CODE}, #{em.DEPART_ACTUAL_TIME},
102   - #{em.REACH_NAME},#{em.REACH_CODE},#{em.REACH_ACTUAL_TIME},
103   - #{em.LEVELS_FLAG},#{em.LEVELS1}, #{em.LEVELS_NAME1}, #{em.LEVELS1_CODE},#{em.LEVELS2}, #{em.LEVELS_NAME2} )
104   - </foreach>
105   - </insert>
106   -
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +
  5 +<mapper namespace="com.example.demo.mapper.db1.SiteMapper1">
  6 +
  7 +
  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`,`MARK`
  17 + )
  18 + VALUES
  19 + <foreach collection="list" item="em" index="index" separator=",">
  20 + ( #{em.TJRLCARDNO}, #{em.TJRLINSID}, #{em.TJRLCDKIND}, #{em.TJRLPOSID},#{em.TJRLRDATE},
  21 + #{em.TJRLRTIME},#{em.TJRLCDBAL},#{em.TJRLAMT},#{em.TJRLORGAMT},
  22 + #{em.TJRLTXFG},#{em.STATION_FLAG},#{em.TJRLUNITID},#{em.TJRLSTATID},#{em.ROAD_FORM_TYPE}, #{em.UPDOWN},
  23 + #{em.BUS_CODE},
  24 + #{em.BUS_PLATE}, #{em.ROAD_CODE}, #{em.DEPART_NAME},#{em.DEPART_CODE}, #{em.DEPART_ACTUAL_TIME},
  25 + #{em.REACH_NAME},#{em.REACH_CODE},#{em.REACH_ACTUAL_TIME},
  26 + #{em.LEVELS_FLAG},#{em.LEVELS1}, #{em.LEVELS_NAME1}, #{em.LEVELS1_CODE},#{em.LEVELS2}, #{em.LEVELS_NAME2}, #{em.MARK} )
  27 + </foreach>
  28 + </insert>
  29 +
  30 +
  31 + <select id="getScheduling" resultType="com.example.demo.model.Scheduling">
  32 + SELECT CONCAT(gs_name, fgs_name) gs_name,
  33 + xl_name,
  34 + xl_bm,
  35 + j_gh,
  36 + j_name,
  37 + schedule_date_str,
  38 + xl_dir,
  39 + bc_type,
  40 + cl_zbh,
  41 + lp_name,
  42 + qdz_name,
  43 + qdz_code,
  44 + fcsj_actual,
  45 + zdz_name,
  46 + zdz_code,
  47 + zdsj_actual,
  48 + real_exec_date,
  49 + cars.equipment_code,
  50 + cars.car_plate
  51 + FROM control.bsth_c_s_sp_info_real
  52 + LEFT JOIN control.bsth_c_cars cars ON cars.inside_code = cl_zbh
  53 + WHERE schedule_date_str in ('${startTime}','${endTime}')
  54 + order by equipment_code,fcsj_actual
  55 + </select>
  56 +
  57 +
  58 + <select id="getStationRoute" resultType="com.example.demo.model.StationRoute">
  59 + SELECT station_route_code,directions,line_code,station_name,station_code
  60 + from control.bsth_c_stationroute WHERE destroy=0 ORDER BY station_code,directions,line_code
  61 + </select>
  62 +
  63 + <select id="getRecords" resultType="map">
  64 + SELECT TJRLPOSID,TJRLRDATE,TJRLRTIME,TJRLCDKIND,TJRLCDBAL,TJRLAMT,TJRLTXFG,TJRLDRVCRDID as TJRLCARDNO
  65 + from ${table} where TJRLRDATE >= '${start}' and TJRLRDATE &lt; '${end}'
  66 + </select>
  67 +
  68 +
107 69 </mapper>
108 70 \ No newline at end of file
... ...
src/main/resources/mapping/db2/Site-mapper2.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +
  5 +<mapper namespace="com.example.demo.mapper.db2.SiteMapper2">
  6 +
  7 +
  8 + <select id="getArrivalInfo" resultType="com.example.demo.model.ArrivalInfo">
  9 + SELECT device_id,line_id,stop_no,ts,up_down,in_out,create_date,weeks_year,create_timestamp
  10 + FROM ms.bsth_c_arrival_info_${year} where weeks_year ${weeks} and ts >= ${timeStart} and ts &lt;= ${timeEnd} ORDER BY device_id,line_id,ts
  11 + </select>
  12 +
  13 +
  14 +</mapper>
0 15 \ No newline at end of file
... ...