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

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingPersonnelCertChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingPersonnelCertChangeUpdateCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingPersonnelCertChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingPersonnelCertChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingPersonnelCertChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 修改备案申请人员证书资源执行器
 *
 * @author ltq
 * @date 2026-07-02 10:04:23
 */
@Component
@AllArgsConstructor
public class QualFilingPersonnelCertChangeUpdateCmdExe {
    private final QualFilingPersonnelCertChangeQueryService qualFilingPersonnelCertChangeQueryService;
    private final QualFilingPersonnelCertChangeCmdConvertor qualFilingPersonnelCertChangeCmdConvertor;
    private final QualFilingPersonnelCertChangeAbility qualFilingPersonnelCertChangeAbility;

    /**
     * 修改备案申请人员证书
     *
     * @param qualFilingPersonnelCertChangeUpdateCmd 修改备案申请人员证书对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingPersonnelCertChangeUpdateCmd qualFilingPersonnelCertChangeUpdateCmd) {
        QualFilingPersonnelCertChangeE qualFilingPersonnelCertChangeE = qualFilingPersonnelCertChangeCmdConvertor.convertCmdToE(qualFilingPersonnelCertChangeUpdateCmd);
        Boolean updateRes = qualFilingPersonnelCertChangeE.update();
        if (!updateRes) {
            throw new BizException("数据已被更新，请刷新重试");
        }
        return true;
    }
}
