package com.zcloud.fire.check.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.fire.check.domain.gateway.FireCheckRecordHiddenGateway;
import com.zcloud.fire.check.domain.model.FireCheckRecordHiddenE;
import com.zcloud.fire.check.dto.FireCheckRecordHiddenAddCmd;
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:11:15
 */
@Component
@AllArgsConstructor
public class FireCheckRecordHiddenAddExe {
    private final FireCheckRecordHiddenGateway fireCheckRecordHiddenGateway;

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

