AppointmentPushJob.java 3.94 KB
package com.zteits.pay.job.appointment;


import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.clouds.common.cache.park.ParkingLotCacheUtil;
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.bean.BaseRequest;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.dto.bill.whitelist.WhitelistParkRelPushDTO;
import com.zteits.clouds.api.dto.order.dto.OrderAppointmentDTO;
import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO;
import com.zteits.clouds.api.service.bill.whitelist.WhitelistService;
import com.zteits.clouds.api.service.order.orderappointment.OrderAppointmentService;
import com.zteits.pay.job.vipcardpush.route.VipCardPushRoute;
import com.zteits.pay.job.vipcardpush.service.VipCardPushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 预约车位信息推送
 * Copyright: Copyright (c) 2018
 *
 * @Description:
 * @version: v1.0.0
 * @author: xiejianpeng
 * @date: 2020/11/11 18:13
 * Modification History:
 * Date             Author          Version            Description
 *---------------------------------------------------------*
 * 2020/11/11     xiejianpeng         v1.0.0               创建
 */
@Component
public class AppointmentPushJob {
    private static final Logger logger = LoggerFactory.getLogger(AppointmentPushJob.class);
    @Autowired
    private VipCardPushRoute vipCardPushRoute;
    @Autowired
    private OrderAppointmentService orderAppointmentService;


    @XxlJob(value = "AppointmentPushJob")
    public ReturnT<String> execute(String... arg0) throws Exception {

        int updateCount = 0;
        this.logger("---begin查询未推送预约车新增信息");
        BaseRequest baseRequest = new BaseRequest();
        baseRequest.setSysCode("1001");
        BizResult<List<OrderAppointmentDTO>> rsList = orderAppointmentService.queryNoPustAppointmentCarList(baseRequest);

        this.logger("本次未推送条数=" + (CollectionUtils.isNotEmpty(rsList.getData()) ? rsList.getData().size() : 0));
        if (rsList.isSuccess() && rsList.getData() != null) {
            int index = 1;
            for (OrderAppointmentDTO orderAppointmentDTO : rsList.getData()) {
                if (orderAppointmentDTO == null || StringUtils.isEmpty(orderAppointmentDTO.getPlNo())) {
                    continue;
                }
                ParkingLotDTO parkingLotDTO =  ParkingLotCacheUtil.getParkLotByPlNo(orderAppointmentDTO.getPlNo());
                if (parkingLotDTO == null) {
                    continue;
                }
                this.logger("begin开始推送第" + (index++) + "条,从缓存获取停车场信息=" + JSONObject.toJSON(parkingLotDTO));

                VipCardPushService route = vipCardPushRoute.getRoute(parkingLotDTO.getSourceType());
                if (route == null) {
                    logger("预约车新增同步路由服务失败,未找到sourceType:" + parkingLotDTO.getSourceType() + "对应的服务");
                    continue;
                }
                try {
                    updateCount = route.pushAppointment(orderAppointmentDTO);
                } catch (Exception e) {
                    logger.error("预约车新增同步异常",e);
                    logger(orderAppointmentDTO.getCarNumber()+":预约车新增同步路由服务失败:" + e);
                }
            }
        } else {
            this.logger("---本次没有要推送的预约车新增信息..");
            updateCount = 1;
        }
        return updateCount > 0 ? ReturnT.SUCCESS : ReturnT.FAIL;
    }


    private void logger(String msg) {
        XxlJobHelper.log(msg);
        logger.info(msg);
    }

}