package com.hfkj.schedule;

import com.hfkj.channel.gas.newlink.NewLinkGasService;
import com.hfkj.channel.gas.shell.CqShellPetroleumGasService;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.entity.BsGasOrder;
import com.hfkj.service.gas.BsGasOrderService;
import com.hfkj.sysenum.gas.OrderOilStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;

/**
 * @className: GasOrderSchedule
 * @author: HuRui
 * @date: 2025/11/13
 **/
@Component
public class GasOrderSchedule {

    @Resource
    private BsGasOrderService gasOrderService;

    /**
     * 补推异常订单，补推已支付的异常。30秒执行查询一次
     */
    @Scheduled(fixedDelay = 30000)
    public void repairOrder() {
        try {

            Map<String,Object> param = new HashMap<>();
            param.put("abnormal", true);
            param.put("status", OrderOilStatus.STATUS2.getNumber());

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(Calendar.SECOND, -60); // 60秒前的数据
            param.put("payTimeS", calendar.getTimeInMillis());

            List<BsGasOrder> orderList = gasOrderService.getGasOrderList(param);
            for (BsGasOrder gasOrder : orderList) {
                // 补推
                gasOrderService.repairOrder(gasOrder.getOrderNo());
            }

        } catch (Exception e) {
            System.out.println("能链【团油】油站获取失败！！！");
        }
    }

}
