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

import cn.iocoder.yudao.framework.apollo.core.event.OrderNumberLogEvent;
import cn.iocoder.yudao.framework.apollo.core.event.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.beans.BeanUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Objects;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.order.enums.ErrorCodeConstants.ORDER_NUMBER_PARAM_NOT_NULL;

/**
 * 订单其他费用添加监听器
 *
 * @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));
      }

    }
}
