All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.woodwhales.common.webhook.executor.WebhookExecutorFactory Maven / Gradle / Ivy

There is a newer version: 3.8.3
Show newest version
package cn.woodwhales.common.webhook.executor;


import cn.woodwhales.common.webhook.enums.WebhookProductEnum;
import cn.woodwhales.common.webhook.model.request.BaseWebhookRequestBody;
import cn.woodwhales.common.webhook.model.request.WebhookRequestBodyFactory;

import java.util.List;
import java.util.function.Consumer;

/**
 * @author woodwhales on 2021-07-20 9:26
 */
public class WebhookExecutorFactory {

    public static  BaseWebhookExecutor newInstance(WebhookProductEnum webhookProductEnum) {
        BaseWebhookExecutor baseWebhookExecutor = null;
        switch (webhookProductEnum) {
            case WE_COM :
                baseWebhookExecutor = WeComWebhookExecutor.newInstance();
                break;

            case DING_TALK :
                baseWebhookExecutor = DingTalkWebhookExecutor.newInstance();
                break;

            case FEI_SHU :
                baseWebhookExecutor = FeiShuWebhookExecutor.newInstance();
                break;
        }
        return baseWebhookExecutor;
    }

    /**
     * 请求执行
     * @param url 请求地址
     * @param requestBody 请求报文
     */
    public static void execute(String url, BaseWebhookRequestBody requestBody) {
        newInstance(requestBody.getWebhookProductEnum()).execute(url, requestBody);
    }

    /**
     * 请求执行
     * @param webhookProductEnum webhook 类型枚举
     * @param url 请求地址
     * @param title 报文标题
     * @param consumer consumer
     */
    public static void execute(WebhookProductEnum webhookProductEnum,
                               String url,
                               String title,
                               Consumer consumer) {
        execute(webhookProductEnum, url, title, consumer, null, null);
    }

    public static void execute(WebhookProductEnum webhookProductEnum,
                               String url,
                               String title,
                               Consumer consumer,
                               List userIdList,
                               List userMobileList) {
        BaseWebhookRequestBody requestBody = WebhookRequestBodyFactory.newInstance(webhookProductEnum, title, userIdList, userMobileList);
        consumer.accept(requestBody);
        newInstance(requestBody.getWebhookProductEnum()).execute(url, requestBody);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy