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

import cn.iocoder.yudao.framework.apollo.core.event.Order.OrderOperateLogEvent;
import cn.iocoder.yudao.module.order.service.order.OrderBusinessService;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
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;

/**
 * 订单相关操作日志监听
 *
 * @author zhengYi
 */
@Component("OrderOperateLogListener")
@AllArgsConstructor
public class OrderOperateLogListener {

    private final OrderBusinessService orderBusinessService;

    /**
     * 添加订单操作日志监听
     *
     * @param event 操作日志参数
     */
    @EventListener(OrderOperateLogEvent.class)
    public void orderOperateLogEvent(OrderOperateLogEvent event) {
        orderBusinessService.addOrderOperateLog(event.getOrderId(), event.getType(), event.getMsg(),
                Objects.isNull(event.getApplyInfoVOList()) ? null : JSONObject.toJSONString(event.getApplyInfoVOList()));
    }
}
