package com.zcloud.basic.info.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.gateway.UserCorpRecordGateway;
import com.zcloud.basic.info.domain.model.UserCorpRecordE;
import com.zcloud.basic.info.dto.UserCorpRecordAddCmd;
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-03 10:21:58
 */
@Component
@AllArgsConstructor
public class UserCorpRecordAddExe {
    private final UserCorpRecordGateway userCorpRecordGateway;

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

