package cn.iocoder.yudao.module.order.listener;

import cn.iocoder.yudao.framework.apollo.core.event.Order.OrderOtherFeeEvent;
import cn.iocoder.yudao.module.order.service.order.OrderService;
import cn.iocoder.yudao.module.product.dto.FeeDto;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 订单其他费用添加监听器
 *
 * @author zhengYi
 */
@Component("OrderOtherFeeListener")
@AllArgsConstructor
public class OrderOtherFeeListener {

    private final OrderService orderService;
    /**
     * 执行添加订单其他费用合计
     *
     * @param event 订单费用
     */
    @EventListener(OrderOtherFeeEvent.class)
    public void orderOtherFeeEvent(OrderOtherFeeEvent event) {
      if (null != event.getOrderId() && StringUtils.isNotBlank(event.getFeeDtoList())){
            orderService.addOrderOtherFee(event.getOrderId(), JSONObject.parseArray(event.getFeeDtoList(), FeeDto.class));
      }

    }
}
