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

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingEquipmentChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingEquipmentChangeAddCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingEquipmentChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingEquipmentChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingEquipmentChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 新增备案申请装备-变更执行器
 *
 * @author ltq
 * @date 2026-07-02 10:03:59
 */
@Component
@AllArgsConstructor
public class QualFilingEquipmentChangeAddCmdExe {

    private final QualFilingEquipmentChangeQueryService qualFilingEquipmentChangeQueryService;
    private final QualFilingEquipmentChangeCmdConvertor qualFilingEquipmentChangeCmdConvertor;
    private final QualFilingEquipmentChangeAbility qualFilingEquipmentChangeAbility;

    /**
     * 新增备案申请装备-变更
     *
     * @param qualFilingEquipmentChangeAddCmd 新增备案申请装备-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingEquipmentChangeAddCmd qualFilingEquipmentChangeAddCmd) {
        QualFilingEquipmentChangeE qualFilingEquipmentChangeE = qualFilingEquipmentChangeCmdConvertor.convertCmdToE(qualFilingEquipmentChangeAddCmd);
        boolean res = qualFilingEquipmentChangeE.add();
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}
