package com.zcloud.fire.check.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.fire.check.domain.gateway.FireCheckStandardGateway;
import com.zcloud.fire.check.domain.model.FireCheckStandardE;
import com.zcloud.fire.check.dto.FireCheckStandardAddCmd;
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-11-26 10:12:14
 */
@Component
@AllArgsConstructor
public class FireCheckStandardAddExe {
    private final FireCheckStandardGateway fireCheckStandardGateway;

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

