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.QualFilingPersonnelCertChangeAddCmd;
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 QualFilingPersonnelCertChangeAddCmdExe {

    private final QualFilingPersonnelCertChangeQueryService qualFilingPersonnelCertChangeQueryService;
    private final QualFilingPersonnelCertChangeCmdConvertor qualFilingPersonnelCertChangeCmdConvertor;
    private final QualFilingPersonnelCertChangeAbility qualFilingPersonnelCertChangeAbility;

    /**
     * 新增备案申请人员证书
     *
     * @param qualFilingPersonnelCertChangeAddCmd 新增备案申请人员证书对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingPersonnelCertChangeAddCmd qualFilingPersonnelCertChangeAddCmd) {
        QualFilingPersonnelCertChangeE qualFilingPersonnelCertChangeE = qualFilingPersonnelCertChangeCmdConvertor.convertCmdToE(qualFilingPersonnelCertChangeAddCmd);
        boolean res = qualFilingPersonnelCertChangeE.add();
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}
