package com.sw.mes.wms.event;

import com.sw.mes.wms.dto.SendFinshOrderDto;
import com.sw.mes.wms.service.RatingResultService;
import com.sw.mes.wms.utils.ResultWmsDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 圆棒评级结果下发监听
 *
 * @Author: GaoXinJian
 * @Date: 2022-02-07 17:46
 */
@Slf4j
@Component
public class FinshOrderEventListener implements SmartApplicationListener {
    @Autowired
    RatingResultService ratingResultService;

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
        return aClass == FinshOrderEvent.class;
    }

    @Override
    public boolean supportsSourceType(Class<?> sourceType) {
        return true;
    }

    @Override
    @Async
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        FinshOrderEvent rankResultEvent = (FinshOrderEvent) applicationEvent;
        SendFinshOrderDto sendFinshOrderDto = rankResultEvent.sendFinshOrderDto;
        //下发wms
        try{
            ResultWmsDto resultWmsDto = ratingResultService.sendFinshOrder(sendFinshOrderDto);
        }catch(Exception e){

        }
    }
}
