package com.zcloud.fire.check.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.fire.check.domain.gateway.FireCheckListUserGateway;
import com.zcloud.fire.check.domain.model.FireCheckListUserE;
import com.zcloud.fire.check.dto.FireCheckListUserAddCmd;
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-11 15:32:49
 */
@Component
@AllArgsConstructor
public class FireCheckListUserAddExe {
    private final FireCheckListUserGateway fireCheckListUserGateway;

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

