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

import cn.newfeifan.mall.framework.quartz.core.handler.JobHandler;
import cn.newfeifan.mall.framework.tenant.core.job.TenantJob;
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 org.quartz.DisallowConcurrentExecution;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

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

/**
 * 交易订单自动计算 Job
 *
 * @author 非繁源码
 */
@Component
@DisallowConcurrentExecution
@Lazy(false)
public class TradeOrderAutoCalcJob implements JobHandler {

    @Resource
    private DistriOrderProducer distriOrderProducer;

    @Resource
    private TradeOrderQueryService tradeOrderQueryService;

    @Override
    @TenantJob
    public String execute(String param) {
        //发货七天前订单
        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);
        return "计算订单信息结束";


    }

}
