Blame view

parking-module-park/src/main/java/com/zteits/park/job/datahub/ParkingChargingPilePushJob.java 4.27 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
89
90
91
92
93
94
95
96
97
98
  package com.zteits.park.job.datahub;
  
  import java.time.LocalDateTime;
  import java.util.List;
  
  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 com.jtjt.upload.client.vo.ChargePileVO;
  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.clouds.api.apibase.constants.DataStatusEnum;
  import com.zteits.park.domain.HubEnterpriseInfo;
  import com.zteits.park.domain.HubEnterpriseInfoExample;
  import com.zteits.park.domain.HubParkingChargingPile;
  import com.zteits.park.domain.HubParkingChargingPileExample;
  import com.zteits.park.mapper.HubEnterpriseInfoMapper;
  import com.zteits.park.mapper.HubParkingChargingPileMapper;
  import com.zteits.park.util.ParkInfoUtil;
  
  /**
   * 停车场充电桩信息数据推送JOB
   * @since 2025-08-17
   */
  @Component
  public class ParkingChargingPilePushJob {
      private static final Logger logger = LoggerFactory.getLogger(ParkingChargingPilePushJob.class);
      @Autowired
      private HubParkingChargingPileMapper hubParkingChargingPileMapper;
      @Autowired
      private HubConfig hubConfig;
      @Autowired
      private TokenService tokenService;
      @Autowired
      private HubEnterpriseInfoMapper hubEnterpriseInfoMapper;
  
      @XxlJob("ParkingChargingPilePushJob")
      public ReturnT<String> execute() {
          log("开始推送停车场充电桩信息JOB");
          try {
              this.pushData();
          } catch (Exception e) {
              logger.error("推送停车场充电桩信息JOB异常:" + e.getMessage(), e);
              log("推送停车场充电桩信息JOB异常:" + e.getMessage());
          }
          return ReturnT.SUCCESS;
      }
  
      private void pushData() {
          HubParkingChargingPileExample example = new HubParkingChargingPileExample();
          example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); // 1-生效
          List<HubParkingChargingPile> hubParkingChargingPileList = hubParkingChargingPileMapper.selectByExample(example);
          if (CollectionUtils.isEmpty(hubParkingChargingPileList)) {
              log("没有需要推送的停车场充电桩信息");
              return;
          }
  
          // 查询运营单位信息
          HubEnterpriseInfoExample enterpriseInfoExample = new HubEnterpriseInfoExample();
          enterpriseInfoExample.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
          List<HubEnterpriseInfo> hubEnterpriseInfos = hubEnterpriseInfoMapper.selectByExample(enterpriseInfoExample);
  
          if (CollectionUtils.isEmpty(hubEnterpriseInfos)) {
              log("没有需要推送的运营单位信息");
              return;
          }
  
          HubEnterpriseInfo hubEnterpriseInfo = hubEnterpriseInfos.get(0);
  
          for (HubParkingChargingPile hubParkingChargingPile : hubParkingChargingPileList) {
              ChargePileVO chargePileVO = new ChargePileVO();
              chargePileVO.setBizId(hubEnterpriseInfo.getBizId());
              chargePileVO.setParkCode(hubParkingChargingPile.getParkCode());
              chargePileVO.setChargePileNum(hubParkingChargingPile.getChargePileNum());
              chargePileVO.setDcChargePileNum(hubParkingChargingPile.getDcChargePileNum());
              chargePileVO.setAcChargePileNum(hubParkingChargingPile.getAcChargePileNum());
              chargePileVO.setChargeStationOperationName(hubParkingChargingPile.getChargeStationOperationName());
              java.util.Date sentTime = hubParkingChargingPile.getSentTime();
              chargePileVO.setSentTime(sentTime != null ? LocalDateTime.ofInstant(sentTime.toInstant(), java.time.ZoneId.systemDefault()) : null);
  
              // 发送充电桩信息
              int code = ParkInfoUtil.getSingleInstance().sendChargePile(hubConfig.getUrlPrefix(), tokenService.getToken(false), chargePileVO);
              if (code == 401) {
                  // 重新刷新token,再次尝试发送
                  ParkInfoUtil.getSingleInstance().sendChargePile(hubConfig.getUrlPrefix(), tokenService.getToken(true), chargePileVO);
              }
          }
      }
  
      private void log(String msg) {
          XxlJobHelper.log(msg);
          logger.info(msg);
      }
  }