package com.zcloud.primeport.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.primeport.domain.gateway.MkmjGateway;
import com.zcloud.primeport.domain.model.MkmjE;
import com.zcloud.primeport.dto.MkmjAddCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:15
 */
@Component
@AllArgsConstructor
public class MkmjAddExe {
    private final MkmjGateway mkmjGateway;

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

