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

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.domain.change.ability.QualFilingPersonnelCertChangeAbility;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 删除备案申请人员证书询执行器
 *
 * @author ltq
 * @date 2026-07-02 10:04:23
 */
@Component
@AllArgsConstructor
public class QualFilingPersonnelCertChangeDelCmdExe {
    private final QualFilingPersonnelCertChangeAbility qualFilingPersonnelCertChangeAbility;

    /**
     * 根据IDS删除备案申请人员证书对象
     *
     * @param ids 备案申请人员证书ID数组
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long[] ids) {
        if (ObjectUtil.isEmpty(ids)) {
            throw new BizException("请传入正确的ID");
        }
        boolean deleteRes = qualFilingPersonnelCertChangeAbility.deletedQualFilingPersonnelCertChangeByIds(ids);
        if (!deleteRes) {
            throw new BizException("删除失败");
        }
        return true;
    }

    /**
     * 根据ID删除备案申请人员证书对象
     *
     * @param id 删除备案申请人员证书对象ID
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long id) {
        boolean deleteRes = qualFilingPersonnelCertChangeAbility.deletedQualFilingPersonnelCertChangeById(id);
        if (!deleteRes) {
            throw new BizException("删除失败");
        }
        return true;
    }


}
