Commit 2c896e2992ee809b4cb816159ba6c5a17f2af7b7

Authored by yiming
1 parent dd63f6bb

修改的定时器时间

src/main/java/com/example/demo/SaticScheduleTask.java
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value; @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
12 import org.springframework.context.annotation.Configuration; 12 import org.springframework.context.annotation.Configuration;
13 import org.springframework.scheduling.annotation.EnableScheduling; 13 import org.springframework.scheduling.annotation.EnableScheduling;
14 import org.springframework.scheduling.annotation.Scheduled; 14 import org.springframework.scheduling.annotation.Scheduled;
  15 +import org.springframework.stereotype.Component;
15 16
16 import javax.annotation.PostConstruct; 17 import javax.annotation.PostConstruct;
17 import java.io.*; 18 import java.io.*;
@@ -25,6 +26,7 @@ import java.util.*; @@ -25,6 +26,7 @@ import java.util.*;
25 */ 26 */
26 @Configuration 27 @Configuration
27 @EnableScheduling 28 @EnableScheduling
  29 +@Component
28 public class SaticScheduleTask implements InitializingBean { 30 public class SaticScheduleTask implements InitializingBean {
29 31
30 private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class); 32 private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class);
@@ -78,16 +80,19 @@ public class SaticScheduleTask implements InitializingBean { @@ -78,16 +80,19 @@ public class SaticScheduleTask implements InitializingBean {
78 contrast.filterCardList(allFile,false); 80 contrast.filterCardList(allFile,false);
79 } 81 }
80 82
81 - @Scheduled(cron = "0 0/10 * * * ?") 83 + @Scheduled(cron = "0 0/5 * * * ?")
82 @PostConstruct 84 @PostConstruct
83 void getArrivalInfos() { 85 void getArrivalInfos() {
84 logger.info("票务数据缓存加载: " + LocalDateTime.now()); 86 logger.info("票务数据缓存加载: " + LocalDateTime.now());
85 LocalDateTime now=LocalDateTime.now(); 87 LocalDateTime now=LocalDateTime.now();
86 //测试 88 //测试
87 - /* DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");  
88 - now=LocalDateTime.parse("2021-07-11 00:00",tdf);*/  
89 -  
90 - contrast.getSchedulingS(now,1); 89 + DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  90 + now=LocalDateTime.parse("2021-08-01 00:00",tdf);
  91 + List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1);
  92 + getSchedulingS=result.get(0);
  93 + getSchedulingSSell=result.get(1);
  94 + System.out.println(getSchedulingS.size());
  95 + System.out.println(getSchedulingSSell.size());
91 } 96 }
92 97
93 98
src/main/java/com/example/demo/service/Contrast.java
@@ -48,7 +48,7 @@ public class Contrast { @@ -48,7 +48,7 @@ public class Contrast {
48 private SaticScheduleTask saticScheduleTask; 48 private SaticScheduleTask saticScheduleTask;
49 49
50 private final int TIME=5; 50 private final int TIME=5;
51 - private final int TIME2=3;//刷卡的时间和到站实际允许误差值 51 + private final int TIME2=0;//刷卡的时间和到站实际允许误差值
52 52
53 public List<Map> getDriverCardList() { 53 public List<Map> getDriverCardList() {
54 List<Map> list = new ArrayList<>(); 54 List<Map> list = new ArrayList<>();
@@ -79,7 +79,7 @@ public class Contrast { @@ -79,7 +79,7 @@ public class Contrast {
79 * @Author: YM 79 * @Author: YM
80 * @Date: 2021/10/12 80 * @Date: 2021/10/12
81 */ 81 */
82 - public void getSchedulingS(LocalDateTime now,int day) { 82 + public List<Map<String,List<Scheduling>>> getSchedulingS(LocalDateTime now,int day) {
83 List<Scheduling> schedulingS=new ArrayList<>(); 83 List<Scheduling> schedulingS=new ArrayList<>();
84 long start = System.currentTimeMillis(); 84 long start = System.currentTimeMillis();
85 Map map = new HashMap(); 85 Map map = new HashMap();
@@ -175,11 +175,14 @@ public class Contrast { @@ -175,11 +175,14 @@ public class Contrast {
175 } 175 }
176 } 176 }
177 } 177 }
178 -  
179 - saticScheduleTask.getSchedulingS= schedulingS.stream().collect(Collectors.groupingBy(s->s.getJ_name()));  
180 - saticScheduleTask.getSchedulingSSell=schedulingS.stream().collect(Collectors.groupingBy(s->s.getS_name())); 178 + Map<String,List<Scheduling>> getSchedulingS=schedulingS.stream().collect(Collectors.groupingBy(s->s.getJ_name()));
  179 + Map<String,List<Scheduling>> getSchedulingSSell=schedulingS.stream().collect(Collectors.groupingBy(s->s.getS_name()));
  180 + List<Map<String,List<Scheduling>>> result=new ArrayList<>();
  181 + result.add(getSchedulingS);
  182 + result.add(getSchedulingSSell);
181 183
182 logger.warn("======匹配"+arrivalInfoList.size()+"条======匹配成功 "+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒"); 184 logger.warn("======匹配"+arrivalInfoList.size()+"条======匹配成功 "+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒");
  185 + return result;
183 } 186 }
184 187
185 188
@@ -209,13 +212,14 @@ public class Contrast { @@ -209,13 +212,14 @@ public class Contrast {
209 List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList()); 212 List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList());
210 213
211 String mark=""; 214 String mark="";
  215 + String jobCodes = "";
212 Boolean flag=false;//用来判断是否没有匹配成功 216 Boolean flag=false;//用来判断是否没有匹配成功
213 Long cardDate = null; 217 Long cardDate = null;
214 if (!collect.isEmpty()) { 218 if (!collect.isEmpty()) {
215 if (null != collect.get(0).get("jobCode") && null != collect.get(0).get("personalName")) { 219 if (null != collect.get(0).get("jobCode") && null != collect.get(0).get("personalName")) {
216 String personalName = collect.get(0).get("personalName").toString();//姓名 220 String personalName = collect.get(0).get("personalName").toString();//姓名
217 String[] arr=collect.get(0).get("jobCode").toString().split("-"); 221 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];//工号 222 + jobCodes =arr.length==0?collect.get(0).get("jobCode").toString():arr[arr.length-1];//工号
219 String time=String.valueOf(data.get("TJRLRTIME"));//时间 223 String time=String.valueOf(data.get("TJRLRTIME"));//时间
220 String date=String.valueOf(data.get("TJRLRDATE"));//日期 224 String date=String.valueOf(data.get("TJRLRDATE"));//日期
221 225
@@ -231,20 +235,14 @@ public class Contrast { @@ -231,20 +235,14 @@ public class Contrast {
231 235
232 236
233 if(schedulingList1!=null){ 237 if(schedulingList1!=null){
234 - Collections.sort(schedulingList1);  
235 - for (Scheduling s : schedulingList1) {  
236 - if (jobCodes.contains(s.getJ_gh()) || s.getJ_gh().contains(jobCodes)){//防止同名 筛选工号 刷卡时间在进出站时间之间  
237 - if((Long.parseLong(s.getTs())-TIME2*60*1000)<=cardDate && (Long.parseLong(s.getTs_out())+TIME2*60*1000)>=cardDate){  
238 - scheduling=s;  
239 - b++;  
240 - flag=true;  
241 - break;  
242 - }/*else {  
243 - LocalDateTime card = LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8));  
244 - LocalDateTime in = LocalDateTime.ofEpochSecond(Long.parseLong(s.getTs())/1000, 0, ZoneOffset.ofHours(8));  
245 - LocalDateTime out = LocalDateTime.ofEpochSecond(Long.parseLong(s.getTs_out())/1000, 0, ZoneOffset.ofHours(8));  
246 - System.out.println("进站时间: "+in+" 出站时间:"+out+" 刷卡时间:"+card );  
247 - }*/ 238 + Collections.sort(schedulingList1, Comparator.comparing(Scheduling::getTs).reversed());
  239 + for (int i1 = 0; i1 < schedulingList1.size(); i1++) {
  240 + Scheduling s=schedulingList1.get(i1);
  241 + if((Long.parseLong(s.getTs())-TIME2*60*1000)<=cardDate){
  242 + scheduling=s;
  243 + b++;
  244 + flag=true;
  245 + break;
248 } 246 }
249 } 247 }
250 }else { 248 }else {
@@ -285,7 +283,7 @@ public class Contrast { @@ -285,7 +283,7 @@ public class Contrast {
285 data.put("STATION_FLAG", 0); 283 data.put("STATION_FLAG", 0);
286 } 284 }
287 if(mark.length()==0 && !flag){ 285 if(mark.length()==0 && !flag){
288 - mark="未匹配到班次 刷卡时间为:"+LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8)); 286 + mark="未匹配到班次 "+jobCodes+"刷卡时间为:"+LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8));
289 } 287 }
290 data.put("MARK",mark); 288 data.put("MARK",mark);
291 289