package com.zcloud.domain.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.domain.domain.gateway.DomainDepartmentUserGateway;
import com.zcloud.domain.domain.model.DomainDepartmentUserE;
import com.zcloud.domain.dto.DomainDepartmentUserAddCmd;
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:09
 */
@Component
@AllArgsConstructor
public class DomainDepartmentUserAddExe {
    private final DomainDepartmentUserGateway domainDepartmentUserGateway;

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

