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.QualFilingPersonnelChangeAddCmd;
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 QualFilingPersonnelChangeAddCmdExe {

    private final QualFilingPersonnelChangeQueryService qualFilingPersonnelChangeQueryService;
    private final QualFilingPersonnelChangeCmdConvertor qualFilingPersonnelChangeCmdConvertor;
    private final QualFilingPersonnelChangeAbility qualFilingPersonnelChangeAbility;

    /**
     * 新增备案申请人员-变更
     *
     * @param qualFilingPersonnelChangeAddCmd 新增备案申请人员-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingPersonnelChangeAddCmd qualFilingPersonnelChangeAddCmd) {
        QualFilingPersonnelChangeE qualFilingPersonnelChangeE = qualFilingPersonnelChangeCmdConvertor.convertCmdToE(qualFilingPersonnelChangeAddCmd);
        boolean res = qualFilingPersonnelChangeE.add();
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}
