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

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingPersonnelChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingPersonnelChangeUpdateCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingPersonnelChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingPersonnelChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingPersonnelChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 修改备案申请人员-变更资源执行器
 *
 * @author ltq
 * @date 2026-07-02 10:04:33
 */
@Component
@AllArgsConstructor
public class QualFilingPersonnelChangeUpdateCmdExe {
    private final QualFilingPersonnelChangeQueryService qualFilingPersonnelChangeQueryService;
    private final QualFilingPersonnelChangeCmdConvertor qualFilingPersonnelChangeCmdConvertor;
    private final QualFilingPersonnelChangeAbility qualFilingPersonnelChangeAbility;

    /**
     * 修改备案申请人员-变更
     *
     * @param qualFilingPersonnelChangeUpdateCmd 修改备案申请人员-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingPersonnelChangeUpdateCmd qualFilingPersonnelChangeUpdateCmd) {
        QualFilingPersonnelChangeE qualFilingPersonnelChangeE = qualFilingPersonnelChangeCmdConvertor.convertCmdToE(qualFilingPersonnelChangeUpdateCmd);
        Boolean updateRes = qualFilingPersonnelChangeE.update();
        if (!updateRes) {
            throw new BizException("数据已被更新，请刷新重试");
        }
        return true;
    }
}
