Blame view

parking-module-park/src/main/java/com/zteits/park/job/PLRealTimeStatusCacheJob.java 3.52 KB
9af4a544   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  package com.zteits.park.job;
  
  import org.apache.commons.lang3.StringUtils;
  import com.alibaba.fastjson.JSONObject;
  import com.xiaoleilu.hutool.date.DateUtil;
  import com.xiaoleilu.hutool.date.TimeInterval;
  import com.xxl.job.core.biz.model.ReturnT;
  import com.xxl.job.core.context.XxlJobHelper;
  import com.xxl.job.core.handler.annotation.XxlJob;
  import com.zteits.park.dao.ParkingLotDao;
  import com.zteits.park.domain.ParkingLot;
  import com.zteits.park.service.parkrealtimecache.oper.PLRealTimeStatusCacheOperService;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  import org.springframework.util.CollectionUtils;
  
  import java.util.*;
  import java.util.concurrent.CountDownLatch;
  import java.util.stream.Collectors;
  
  /**
   * Copyright: Copyright (c) 2018  zteits
   *
   * @ClassName: com.zteits.park.job
   * @Description: 停车场实时状态缓存数据定时任务
   * @version: v1.0.0
   * @author: atao
   * @date: 2018/4/11   上午11:54
   * Modification History:
   * Date         Author          Version      Description
   * ---------------------------------------------------------*
   * 2018/4/11      atao          v1.0.0          创建
   */
  @Component
  public class PLRealTimeStatusCacheJob{
  
      private static final Logger logger = LoggerFactory.getLogger(PLRealTimeStatusCacheJob.class);
      @Autowired
      private ParkingLotDao parkingLotDao;
  
      @Autowired
      private PLRealTimeStatusCacheOperService plRealTimeStatusCacheOperService;
  
      @XxlJob("PLRealTimeStatusCacheJob")
      public ReturnT<String> execute(String... params) throws Exception {
          String param = XxlJobHelper.getJobParam();
          if (StringUtils.isNotEmpty(param) && params == null) {
              params = param.split(",");
          }
  
          String uuid = UUID.randomUUID().toString();
          logger.info("{}校验停车场缓存中的实时运行数据====start====={}", uuid,DateUtil.now());
          TimeInterval timer = DateUtil.timer();
          List<String> plNos;
  
          if (null != params && params.length > 0) {
              plNos = Arrays.asList(params);
          } else {
              List<ParkingLot> parkingLotList = parkingLotDao.queryParkListAll();
              plNos = parkingLotList.stream().map(ParkingLot::getPlNo).collect(Collectors.toList());
          }
  
          if (CollectionUtils.isEmpty(plNos)) {
              return ReturnT.FAIL;
          }
          timer.start();
  
          logger.info("{}校验停车场缓存中的实时运行数据,校验停车场个数为:{}",uuid, plNos.size());
          Map<String, String> failResult = new HashMap<>(16);
          CountDownLatch countDownLatch = new CountDownLatch(plNos.size());
  
          for (String plNo : plNos) {
              //根据停车场编号开始进行校正缓存中停车场的实时运行数据
              plRealTimeStatusCacheOperService.checkPlRealTimeStatusCache(plNo, failResult, countDownLatch);
          }
          countDownLatch.await();
          logger.info("{}校验停车场缓存中的实时运行数据,停车场个数为{},校验停车场失败个数为:{}",uuid, plNos.size(),failResult.size());
          logger.info("{}校验停车场缓存中的实时运行数据====end====={},耗时为:{}分钟{}秒", uuid,DateUtil.now(), timer.intervalMinute(),
              timer.intervalSecond());
          if (CollectionUtils.isEmpty(failResult)) {
              return ReturnT.SUCCESS;
          } else {
              return new ReturnT<>(ReturnT.FAIL_CODE, "失败的数据为:" + JSONObject.toJSONString(failResult));
          }
      }
  }