package com.zcloud.primeport.command;

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


/**
 * web-app
 *
 * @Author dearLin
 * @Date 2026-04-23 10:04:31
 */
@Component
@AllArgsConstructor
public class EVehicleBasicInfoAddExe {
    private final EVehicleBasicInfoGateway eVehicleBasicInfoGateway;

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

