package com.zcloud.basic.info.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.gateway.DepartmentSuperviseGateway;
import com.zcloud.basic.info.domain.model.DepartmentSuperviseE;
import com.zcloud.basic.info.dto.DepartmentSuperviseAddCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2025-11-10 14:13:45
 */
@Component
@AllArgsConstructor
public class DepartmentSuperviseAddExe {
    private final DepartmentSuperviseGateway departmentSuperviseGateway;

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

