package com.zcloud.zcGbsServicer.command;

import com.zcloud.zcGbsServicer.domain.gateway.ResourcePersonGateway;
import com.zcloud.zcGbsServicer.domain.model.ResourcePersonE;
import com.zcloud.zcGbsServicer.dto.ResourcePersonAddCmd;
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:34
*/
@Component
@AllArgsConstructor
public class ResourcePersonAddExe {
    private final ResourcePersonGateway resourcePersonGateway;

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

