package com.hfkj.schedule;

import com.hfkj.service.order.BsOrderService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 订单结算业务
 * @className: OrderSettleService
 * @author: HuRui
 * @date: 2024/6/25
 **/
@Component
public class OrderSchedule {
    @Resource
    private BsOrderService orderService;

    @Scheduled(cron="0 0/1 * * * ?")   //每分钟执行一次
    public void cancel() {
        List<Map<String, Object>> orderList = orderService.getNeedCancelOrderList();
        for (Map<String,Object> param : orderList) {
            try {
                // 取消订单
                orderService.cancel(MapUtils.getString(param, "orderNo"));

            } catch (Exception e) {
                System.out.println(MapUtils.getString(param, "orderNo")+"，取消订单失败！");
            }
        }
    }
}
