package org.qinan.safetyeval.app.change.executor.command;

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingCommitmentChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingCommitmentChangeUpdateCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingCommitmentChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingCommitmentChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingCommitmentChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 修改法定代人承诺书-变更资源执行器
 *
 * @author ltq
 * @date 2026-07-02 09:38:30
 */
@Component
@AllArgsConstructor
public class QualFilingCommitmentChangeUpdateCmdExe {
    private final QualFilingCommitmentChangeQueryService qualFilingCommitmentChangeQueryService;
    private final QualFilingCommitmentChangeCmdConvertor qualFilingCommitmentChangeCmdConvertor;
    private final QualFilingCommitmentChangeAbility qualFilingCommitmentChangeAbility;

    /**
     * 修改法定代人承诺书-变更
     *
     * @param qualFilingCommitmentChangeUpdateCmd 修改法定代人承诺书-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingCommitmentChangeUpdateCmd qualFilingCommitmentChangeUpdateCmd) {
        QualFilingCommitmentChangeE qualFilingCommitmentChangeE = qualFilingCommitmentChangeCmdConvertor.convertCmdToE(qualFilingCommitmentChangeUpdateCmd);
        Boolean updateRes = qualFilingCommitmentChangeE.update();
        if (!updateRes) {
            throw new BizException("数据已被更新，请刷新重试");
        }
        return true;
    }
}
