package com.zcloud.domain.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.domain.domain.gateway.ProjectTaskInfoGateway;
import com.zcloud.domain.domain.model.ProjectTaskInfoE;
import com.zcloud.domain.dto.ProjectTaskInfoAddCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:30:29
 */
@Component
@AllArgsConstructor
public class ProjectTaskInfoAddExe {
    private final ProjectTaskInfoGateway projectTaskInfoGateway;

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

