package com.fs.event;

import com.fs.his.service.IFsPromotionalActiveLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Slf4j
@Component
public class ActiveClickListener {

    @Autowired
    private IFsPromotionalActiveLogService activeLogService;

    @Async
    @EventListener
    public void handleActiveClick(ActiveClickEvent event) {
        log.debug("用户点击行为: event: {}", event);

        Integer productType = Objects.isNull(event.getProductType()) ? null : event.getProductType().getValue();
        activeLogService.saveClickActionLog(event.getActiveId(), event.getUserId(), event.getType().getValue(), productType, event.getResourceId());
    }
}
