package com.zcloud.primeport.command;

import com.zcloud.primeport.domain.gateway.ClosedAreaGateway;
import com.zcloud.primeport.domain.model.ClosedAreaE;
import com.zcloud.primeport.dto.ClosedAreaAddCmd;
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-03-19 10:27:50
*/
@Component
@AllArgsConstructor
public class ClosedAreaAddExe {
    private final ClosedAreaGateway closedAreaGateway;

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

