package com.zcloud.fire.check.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.fire.check.domain.gateway.FireCheckRecordDeviceGateway;
import com.zcloud.fire.check.domain.model.FireCheckRecordDeviceE;
import com.zcloud.fire.check.dto.FireCheckRecordDeviceAddCmd;
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:10:02
 */
@Component
@AllArgsConstructor
public class FireCheckRecordDeviceAddExe {
    private final FireCheckRecordDeviceGateway fireCheckRecordDeviceGateway;

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

