package com.yuchen.saas.park.service.listener.inspect;

import cn.hutool.core.bean.BeanUtil;
import com.yuchen.saas.park.api.entity.fire.inspect.SaasParkFireInspectLog;
import com.yuchen.saas.park.service.service.fire.inspect.ISaasParkFireInspectLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

import javax.annotation.Resource;

/**
 * @author zhouhanwei
 * @create 2024/4/10 9:21
 */
@Slf4j
@Component
public class InspectPlanTaskMessageListener {

    @Resource
    private ISaasParkFireInspectLogService inspectLogService;

    @TransactionalEventListener(fallbackExecution = true)
    @Async("parkTaskPoolExecutor")
    public void handleFireInspectLogEvent(FireInspectLogEvent logEvent){
        SaasParkFireInspectLog inspectLog = new SaasParkFireInspectLog();
        BeanUtil.copyProperties(logEvent, inspectLog);
        inspectLog.setCreateOrgUser(logEvent.getInspectUser());
        inspectLogService.save(inspectLog);
    }
}
