package com.jkcredit.invoice.hub.task;

import com.jkcredit.invoice.hub.model.po.carFreeCarrierBillStart.CarFreeCarrierBillStartPo;
import com.jkcredit.invoice.hub.service.apiCarFree.ApiCarFreeChargeService;
import com.jkcredit.invoice.hub.service.carFreeCarrierBillStart.CarFreeCarrierBillStartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @description:
 * @author: xusonglin
 * @create: 2020/1/18 15:49
 * @version: V1.0
 **/
@Component
@Slf4j
public class WayBillTask {
    @Autowired
    CarFreeCarrierBillStartService startService;
    @Autowired
    ApiCarFreeChargeService chargeService;

    @Scheduled(cron = "0 0 23 * * ?", zone = "Asia/Shanghai")
    public void realTimeWayBill() {
        // 查询实时订单，且状态为已结束和开票中
        // 调用运单查询发票接口
        // 解析结果
        // 如果result不为[]，则将结果入库
        // 根据返回transationID去重
        // 每一条放入消息队列，计费
        List<CarFreeCarrierBillStartPo> startPoList = startService.getRealTimeBills();
        for (CarFreeCarrierBillStartPo po : startPoList) {
            chargeService.charge(po);
        }
    }

    @Scheduled(cron = "0 0 * * * ?", zone = "Asia/Shanghai")
    public void historyWayBill() {
        // 查询实时订单，且状态为已结束和开票中
        // 调用运单查询发票接口
        // 解析结果
        // 如果result不为[]，则将结果入库
        // 根据返回transationID去重
        // 每一条放入消息队列，计费
        List<CarFreeCarrierBillStartPo> startPoList = startService.getHistoryBills();
        for (CarFreeCarrierBillStartPo po : startPoList) {
            chargeService.charge(po);
        }
    }
}
