Blame view

parking-module-park/src/main/java/com/zteits/park/job/datahub/EnterpriseInfoPushJob.java 2.58 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
  package com.zteits.park.job.datahub;
  
  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.HubParkingInfoBO;
  import com.zteits.park.mapper.HubEnterpriseInfoMapper;
  import com.zteits.park.mapper.smapper.HubParkingInfoSMapper;
  import com.zteits.park.util.ParkInfoUtil;
  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.List;
  
  /**
   * 运营企业数据推送JOB
   * @since 2025-08-17
   */
  @Component
  public class EnterpriseInfoPushJob {
      private static final Logger logger = LoggerFactory.getLogger(EnterpriseInfoPushJob.class);
      @Autowired
      private HubEnterpriseInfoMapper hubEnterpriseInfoMapper;
      @Autowired
      private HubConfig hubConfig;
      @Autowired
      private TokenService tokenService;
  
      @XxlJob("EnterpriseInfoPushJob")
      public ReturnT<String> execute()
      {
          log("开始推送运营企业信息JOB");
          try{
              this.pushData();
          } catch (Exception e){
              logger.error("推送运营企业信息JOB异常", e);
              log("推送运营企业信息JOB异常"+e.getMessage());
          }
          return ReturnT.SUCCESS;
      }
  
      private void pushData() {
          // 查询运营单位信息
          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);
          int code = ParkInfoUtil.getSingleInstance().sendCompany(hubConfig.getUrlPrefix(), tokenService.getToken(false), hubEnterpriseInfo);
          if (code == 401) {
              // 重新刷新token,再次尝试发送
              ParkInfoUtil.getSingleInstance().sendCompany(hubConfig.getUrlPrefix(), tokenService.getToken(true), hubEnterpriseInfo);
          }
      }
  
      private void log(String msg){
          XxlJobHelper.log(msg);
          logger.info(msg);
      }
  }