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.trade.mq.producer.order.DistriOrderProducer;
import cn.newfeifan.mall.module.trade.service.order.TradeOrderQueryService;
import org.springframework.stereotype.Component;

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

/**
 * 交易订单自动计算 Job
 *
 * @author 非繁源码
 */
@Component
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();
        CalcMessage calcMessage = CalcMessage.builder().distriOrderMessages(appTradeOrderDetailRespVos).build();
        distriOrderProducer.sendDistriOrderMessage(calcMessage);
        return String.format("计算订单信息结束");


    }

}
