package com.zcloud.primeport.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.primeport.domain.gateway.VehicleMessageGateway;
import com.zcloud.primeport.domain.model.VehicleMessageE;
import com.zcloud.primeport.dto.VehicleMessageAddCmd;
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:27
 */
@Component
@AllArgsConstructor
public class VehicleMessageAddExe {
    private final VehicleMessageGateway vehicleMessageGateway;

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

