package com.zcloud.domain.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.domain.domain.gateway.DomainGroupUserGateway;
import com.zcloud.domain.domain.model.DomainGroupUserE;
import com.zcloud.domain.dto.DomainGroupUserAddCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:29:42
 */
@Component
@AllArgsConstructor
public class DomainGroupUserAddExe {
    private final DomainGroupUserGateway domainGroupUserGateway;

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

