package com.zcloud.basic.info.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.gateway.CorpFormGateway;
import com.zcloud.basic.info.domain.model.CorpFormE;
import com.zcloud.basic.info.dto.CorpFormAddCmd;
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-10-29 16:02:26
 */
@Component
@AllArgsConstructor
public class CorpFormAddExe {
    private final CorpFormGateway corpFormGateway;

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

