package com.zcloud.fire.check.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.fire.check.domain.gateway.FireCheckRecordUserGateway;
import com.zcloud.fire.check.domain.model.FireCheckRecordUserE;
import com.zcloud.fire.check.dto.FireCheckRecordUserAddCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2025-12-12 11:12:04
 */
@Component
@AllArgsConstructor
public class FireCheckRecordUserAddExe {
    private final FireCheckRecordUserGateway fireCheckRecordUserGateway;

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(FireCheckRecordUserAddCmd cmd) {
        FireCheckRecordUserE fireCheckRecordUserE = new FireCheckRecordUserE();
        BeanUtils.copyProperties(cmd, fireCheckRecordUserE);
        boolean res = false;
        try {
            res = fireCheckRecordUserGateway.add(fireCheckRecordUserE);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}

