package com.gree.mall.manager.schedule;

import com.gree.mall.manager.enums.OrderShareStatusEnum;
import com.gree.mall.manager.enums.OrderStatusEnum;
import com.gree.mall.manager.logic.tax.TaxLogic;
import com.gree.mall.manager.plus.entity.OrderInfo;
import com.gree.mall.manager.plus.entity.OrderShare;
import com.gree.mall.manager.plus.entity.OrderTax;
import com.gree.mall.manager.plus.service.OrderInfoService;
import com.gree.mall.manager.plus.service.OrderTaxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.List;

@ConditionalOnProperty(name = "schedule.enable", havingValue = "true", matchIfMissing = true)
@Slf4j
@Component
public class TaxSchedule {
    @Autowired
    private TaxLogic taxLogic;
    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    private OrderTaxService orderTaxService;

    @Scheduled(fixedDelay = 5 * 60 * 1000)
    public void orderShareTask() {
        List<OrderTax> OrderTaxList = orderTaxService.lambdaQuery()
                .eq(OrderTax::getStatus,false)
                .list();

        for (OrderTax orderTax : OrderTaxList) {
            OrderInfo orderInfo = orderInfoService.getById(orderTax.getOrderId());
            if(orderInfo==null||!orderInfo.getOrderStatus().equals(OrderStatusEnum.OVER.toString())){
                continue;
            }
            taxLogic.taxHttp(orderTax.getOrderId());
        }
    }

}
