package com.zcloud.zcGbsServicer.command;

import com.zcloud.zcGbsServicer.domain.gateway.ResourceDeviceGateway;
import com.zcloud.zcGbsServicer.domain.model.ResourceDeviceE;
import com.zcloud.zcGbsServicer.dto.ResourceDeviceAddCmd;
import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;




/**
* web-app
* @Author makejava
* @Date 2026-01-21 17:23:16
*/
@Component
@AllArgsConstructor
public class ResourceDeviceAddExe {
    private final ResourceDeviceGateway resourceDeviceGateway;

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

