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.QualFilingEquipmentChangeUpdateCmd;
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 QualFilingEquipmentChangeUpdateCmdExe {
    private final QualFilingEquipmentChangeQueryService qualFilingEquipmentChangeQueryService;
    private final QualFilingEquipmentChangeCmdConvertor qualFilingEquipmentChangeCmdConvertor;
    private final QualFilingEquipmentChangeAbility qualFilingEquipmentChangeAbility;

    /**
     * 修改备案申请装备-变更
     *
     * @param qualFilingEquipmentChangeUpdateCmd 修改备案申请装备-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingEquipmentChangeUpdateCmd qualFilingEquipmentChangeUpdateCmd) {
        QualFilingEquipmentChangeE qualFilingEquipmentChangeE = qualFilingEquipmentChangeCmdConvertor.convertCmdToE(qualFilingEquipmentChangeUpdateCmd);
        Boolean updateRes = qualFilingEquipmentChangeE.update();
        if (!updateRes) {
            throw new BizException("数据已被更新，请刷新重试");
        }
        return true;
    }
}
