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 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;
15 16  
16 17 import javax.annotation.PostConstruct;
17 18 import java.io.*;
... ... @@ -25,6 +26,7 @@ import java.util.*;
25 26 */
26 27 @Configuration
27 28 @EnableScheduling
  29 +@Component
28 30 public class SaticScheduleTask implements InitializingBean {
29 31  
30 32 private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class);
... ... @@ -78,16 +80,19 @@ public class SaticScheduleTask implements InitializingBean {
78 80 contrast.filterCardList(allFile,false);
79 81 }
80 82  
81   - @Scheduled(cron = "0 0/10 * * * ?")
  83 + @Scheduled(cron = "0 0/5 * * * ?")
82 84 @PostConstruct
83 85 void getArrivalInfos() {
84 86 logger.info("票务数据缓存加载: " + LocalDateTime.now());
85 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 48 private SaticScheduleTask saticScheduleTask;
49 49  
50 50 private final int TIME=5;
51   - private final int TIME2=3;//刷卡的时间和到站实际允许误差值
  51 + private final int TIME2=0;//刷卡的时间和到站实际允许误差值
52 52  
53 53 public List<Map> getDriverCardList() {
54 54 List<Map> list = new ArrayList<>();
... ... @@ -79,7 +79,7 @@ public class Contrast {
79 79 * @Author: YM
80 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 83 List<Scheduling> schedulingS=new ArrayList<>();
84 84 long start = System.currentTimeMillis();
85 85 Map map = new HashMap();
... ... @@ -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 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 212 List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList());
210 213  
211 214 String mark="";
  215 + String jobCodes = "";
212 216 Boolean flag=false;//用来判断是否没有匹配成功
213 217 Long cardDate = null;
214 218 if (!collect.isEmpty()) {
215 219 if (null != collect.get(0).get("jobCode") && null != collect.get(0).get("personalName")) {
216 220 String personalName = collect.get(0).get("personalName").toString();//姓名
217 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 223 String time=String.valueOf(data.get("TJRLRTIME"));//时间
220 224 String date=String.valueOf(data.get("TJRLRDATE"));//日期
221 225  
... ... @@ -231,20 +235,14 @@ public class Contrast {
231 235  
232 236  
233 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 248 }else {
... ... @@ -285,7 +283,7 @@ public class Contrast {
285 283 data.put("STATION_FLAG", 0);
286 284 }
287 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 288 data.put("MARK",mark);
291 289  
... ...