package com.zcloud.basic.info.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.gateway.UserCorpGateway;
import com.zcloud.basic.info.domain.model.UserCorpE;
import com.zcloud.basic.info.dto.UserCorpAddCmd;
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-02 11:13:32
 */
@Component
@AllArgsConstructor
public class UserCorpAddExe {
    private final UserCorpGateway userCorpGateway;

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

