EnterpriseInfoPushJob.java 2.58 KB
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);
    }
}