package com.zcloud.basic.info.command;

import com.zcloud.basic.info.domain.gateway.ProblemFeedbackGateway;
import com.zcloud.basic.info.domain.model.ProblemFeedbackE;
import com.zcloud.basic.info.dto.ProblemFeedbackAddCmd;
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 SondonYong
 * @Date 2025-12-06 11:26:34
 */
@Component
@AllArgsConstructor
public class ProblemFeedbackAddExe {
    private final ProblemFeedbackGateway problemFeedbackGateway;

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

