package com.zcloud.accident.command;

import com.zcloud.accident.domain.gateway.AccidentGateway;
import com.zcloud.accident.domain.model.AccidentE;
import com.zcloud.accident.dto.AccidentAddCmd;
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 fangjiakai
* @Date 2025-10-29 14:28:26
*/
@Component
@AllArgsConstructor
public class AccidentAddExe {
    private final AccidentGateway accidentGateway;

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

