package com.njzscloud.dispose.cst.order.service;

import com.njzscloud.common.core.tuple.Tuple2;
import com.njzscloud.dispose.dev.DiscoverTruckMsg;
import com.njzscloud.dispose.dev.ObtainTruckDataResultMsg;
import com.njzscloud.dispose.dev.WbsHandle;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import static com.njzscloud.dispose.dev.DevMittEvent.DISCOVER_TRUCK;
import static com.njzscloud.dispose.dev.DevMittEvent.OBTAIN_TRUCK_DATA_REPLY;

/**
 * 车辆称重事件监听器
 * 负责处理磅房设备的车辆识别和称重数据事件
 *
 * @author ljw
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TruckWeighingEventListener {

    private final TruckWeighingBusinessService businessService;


    /**
     * 初始化事件监听器
     */
    public void init() {
        log.info("初始化车辆称重事件监听器");
        DISCOVER_TRUCK.on(this::requestData);
        OBTAIN_TRUCK_DATA_REPLY.on(this::disposeData);
    }

    /**
     * 请求数据 - 处理车辆识别
     */
    public void requestData(Tuple2<DiscoverTruckMsg, WbsHandle> param) {
        businessService.requestData(param);
    }

    /**
     * 处理数据 - 处理磅重数据
     */
    public void disposeData(Tuple2<ObtainTruckDataResultMsg, WbsHandle> param) {
        businessService.disposeData(param);
    }
}
