/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.delivery.api.listener;

import com.yami.shop.bean.event.CalculateTransfeeEvent;
import com.yami.shop.delivery.comment.service.TransportManagerService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 计算运费的监听事件
 *
 * @author lhd
 */
@Component("calculateTransFeeListener")
@AllArgsConstructor
public class CalculateTransFeeListener {

    private final TransportManagerService transportManagerService;

    /**
     * 计算运费的监听事件
     */
    @EventListener(CalculateTransfeeEvent.class)
    public void calculateTransFeeEvent(CalculateTransfeeEvent event) {
        double transfee = transportManagerService.calculateTransfee(event.getProductItem(), event.getUserAddr());
        event.setTransfee(transfee);
    }

}
