package com.zcloud.zcGbsServicer.command;

import com.zcloud.zcGbsServicer.domain.gateway.WaterSourceGateway;
import com.zcloud.zcGbsServicer.domain.model.WaterSourceE;
import com.zcloud.zcGbsServicer.dto.WaterSourceAddCmd;
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 makejava
* @Date 2026-01-21 17:23:50
*/
@Component
@AllArgsConstructor
public class WaterSourceAddExe {
    private final WaterSourceGateway waterSourceGateway;

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

