package cn.newfeifan.mall.module.trade.job.order;

import cn.newfeifan.mall.module.distri.mq.message.order.CalcMessage;
import cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage;
import cn.newfeifan.mall.module.distri.mq.message.order.OrderCalcMessage;
import cn.newfeifan.mall.module.trade.mq.producer.order.DistriOrderProducer;
import cn.newfeifan.mall.module.trade.service.order.TradeOrderQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Component
@Slf4j
public class TestJob {

    @Resource
    private DistriOrderProducer distriOrderProducer;

    @Resource
    private TradeOrderQueryService tradeOrderQueryService;

    @Scheduled(cron = "0 0 3 * * ?")
    public void execute() {
        //发货七天前订单
        List<DistriOrderMessage> appTradeOrderDetailRespVos = tradeOrderQueryService.queryAllOrder();
        List<OrderCalcMessage> orderCalcMessages = tradeOrderQueryService.getOrderCalcMessage(appTradeOrderDetailRespVos);

        //每日订单
        List<DistriOrderMessage> appTradeOrderDetailRespVos2 = tradeOrderQueryService.queryDailyOrder();
        List<OrderCalcMessage> orderCalcMessages2 = tradeOrderQueryService.getOrderCalcMessage(appTradeOrderDetailRespVos2);

        CalcMessage calcMessage = CalcMessage.builder().orderCalcMessages(orderCalcMessages).bonusQuotaOrderDO(orderCalcMessages2).distriOrderMessages(appTradeOrderDetailRespVos).build();
        distriOrderProducer.sendDistriOrderMessage(calcMessage);

        log.info("========执行计算程序============");
        log.info("定时任务执行时间：{}", LocalDateTime.now());
    }
}
