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

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingMaterialChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingMaterialChangeUpdateCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingMaterialChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingMaterialChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingMaterialChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 修改备案申请材料-变更资源执行器
 *
 * @author ltq
 * @date 2026-07-02 10:04:07
 */
@Component
@AllArgsConstructor
public class QualFilingMaterialChangeUpdateCmdExe {
    private final QualFilingMaterialChangeQueryService qualFilingMaterialChangeQueryService;
    private final QualFilingMaterialChangeCmdConvertor qualFilingMaterialChangeCmdConvertor;
    private final QualFilingMaterialChangeAbility qualFilingMaterialChangeAbility;

    /**
     * 修改备案申请材料-变更
     *
     * @param qualFilingMaterialChangeUpdateCmd 修改备案申请材料-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingMaterialChangeUpdateCmd qualFilingMaterialChangeUpdateCmd) {
        QualFilingMaterialChangeE qualFilingMaterialChangeE = qualFilingMaterialChangeCmdConvertor.convertCmdToE(qualFilingMaterialChangeUpdateCmd);
        Boolean updateRes = qualFilingMaterialChangeE.update();
        if (!updateRes) {
            throw new BizException("数据已被更新，请刷新重试");
        }
        return true;
    }
}
