package cn.estsh.i3plus.ext.mes.pcn.apiservice.actor.monitoring;

import akka.actor.AbstractActor;
import cn.estsh.i3plus.mes.pcn.api.iservice.base.IModuleService;
import cn.estsh.i3plus.pojo.mes.model.ActorMessageModel;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author wangjie
 * @date 2020/3/9 15:54
 * @desc
 */
@Slf4j
@Component
@Scope("prototype")
public class SxScanInfoMonitoringSignalActor extends AbstractActor {

    @Override
    public void postStop() throws Exception {
        super.postStop();
        log.error("sxScanInfoMonitoringSignalActor");
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder().match(StationRequestBean.class, requestBean -> {
            IModuleService moduleService = (IModuleService) requestBean.getModuleService();
            boolean monitorResult = moduleService.getMonitorData(requestBean);
            if (monitorResult) {
                getSender().tell(ActorMessageModel.getSuccess(requestBean.getScanInfo()), getSelf());
            }else {
                getSender().tell(ActorMessageModel.getFailure("监听扫描信息失败，请检查返回信息是否有错误"), getSelf());
            }
        }).build();
    }

}
