package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.domain.gateway.OpenapiConfigGateway;
import com.alibaba.cola.exception.BizException;
import com.zcloud.personnel.positioning.integration.finds.OpenapiConfigCache;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * web-app
 *
 * @Author fangjiakai
 * @Date 2026-07-07
 */
@Component
@AllArgsConstructor
public class OpenapiConfigRemoveExe {
    private final OpenapiConfigGateway openapiConfigGateway;
    private final OpenapiConfigCache openapiConfigCache;

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long id) {
        boolean res = openapiConfigGateway.deletedOpenapiConfigById(id);
        if (res) {
            openapiConfigCache.evictAll();
        }
        if (!res) {
            throw new BizException("删除失败");
        }
        return true;
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long[] ids) {
        boolean res = openapiConfigGateway.deletedOpenapiConfigByIds(ids);
        if (res) {
            openapiConfigCache.evictAll();
        }
        if (!res) {
            throw new BizException("删除失败");
        }
        return true;
    }
}
