package com.zcloud.fire.check.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.fire.check.domain.gateway.FireCheckListItemGateway;
import com.zcloud.fire.check.domain.model.FireCheckListItemE;
import com.zcloud.fire.check.dto.FireCheckListItemAddCmd;
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-28 10:32:28
 */
@Component
@AllArgsConstructor
public class FireCheckListItemAddExe {
    private final FireCheckListItemGateway fireCheckListItemGateway;

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

