mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
feat(新版发布): 开发Springboot-starter方便集成方调用,修复获取token本地时间和服务器时间有差异而导致的报错问题
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.jhinno.sdk.openapi.autoconfigure;
|
||||
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* openapi客户端自动配置
|
||||
* @author yanlongqi
|
||||
* @date 2024/6/4 16:01
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(JHOpenapiProperties.class)
|
||||
public class JHOpenapiClientAutoConfigure {
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHApiClient jhApiClient(JHOpenapiProperties properties){
|
||||
return JHApiClient.build(
|
||||
properties.getServerUrl(),
|
||||
properties.getMaxTotal(),
|
||||
properties.getMaxPerRout(),
|
||||
properties.getSocketTimeout(),
|
||||
properties.getConnectTimeout(),
|
||||
properties.getConnectRequestTimeout()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.jhinno.sdk.openapi.autoconfigure;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.app.JHAppApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.data.JHDataApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.file.JHFileApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.job.JHJobApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHUserApiExecution;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* openapi执行器自动配置
|
||||
*
|
||||
* @author yanlongqi
|
||||
* @date 2024/6/4 17:27
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class JHOpenapiExecutionAutoconfigure {
|
||||
|
||||
|
||||
private final JHOpenapiProperties properties;
|
||||
private final JHApiClient client;
|
||||
|
||||
@Bean
|
||||
public JHAppApiExecution appApiExecution() {
|
||||
JHAppApiExecution execution = new JHAppApiExecution(client);
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JHDataApiExecution dataApiExecution() {
|
||||
JHDataApiExecution execution = new JHDataApiExecution(client);
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public JHFileApiExecution fileApiExecution() {
|
||||
JHFileApiExecution execution = new JHFileApiExecution(client);
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JHJobApiExecution jobApiExecution() {
|
||||
JHJobApiExecution execution = new JHJobApiExecution(client);
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public JHDepartmentApiExecution departmentApiExecution() {
|
||||
JHDepartmentApiExecution execution = new JHDepartmentApiExecution(client);
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public JHUserApiExecution userApiExecution() {
|
||||
JHUserApiExecution execution = new JHUserApiExecution(client);
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.jhinno.sdk.openapi.autoconfigure;
|
||||
|
||||
import com.jhinno.sdk.openapi.CommonConstant;
|
||||
import com.jhinno.sdk.openapi.client.DefaultHttpClientConfig;
|
||||
import com.jhinno.sdk.openapi.constant.CommonConstants;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
* @date 2024/6/4 16:03
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = CommonConstants.CONFIG_PREFIX)
|
||||
public class JHOpenapiProperties {
|
||||
|
||||
/**
|
||||
* 接口服务的BaseURL, 列如:https://192.168.87.20/appform
|
||||
*/
|
||||
private String serverUrl;
|
||||
|
||||
/**
|
||||
* 设置连接池的最大连接数,默认{@link DefaultHttpClientConfig#MAX_TOTAL}
|
||||
*/
|
||||
private int maxTotal = DefaultHttpClientConfig.MAX_TOTAL;
|
||||
|
||||
|
||||
/**
|
||||
* 设置服务每次能并行接收的请求数量,默认{@link DefaultHttpClientConfig#MAX_PER_ROUT}
|
||||
*/
|
||||
private int maxPerRout = DefaultHttpClientConfig.MAX_PER_ROUT;
|
||||
|
||||
/**
|
||||
* 设置服务socket连接超时的时间(单位:毫秒),默认{@link DefaultHttpClientConfig#SOCKET_TIMEOUT}
|
||||
*/
|
||||
private int socketTimeout = DefaultHttpClientConfig.SOCKET_TIMEOUT;
|
||||
|
||||
/**
|
||||
* 设置服务连接超时的时间(单位:毫秒),默认{@link DefaultHttpClientConfig#CONNECT_TIMEOUT}
|
||||
*/
|
||||
private int connectTimeout = DefaultHttpClientConfig.CONNECT_TIMEOUT;
|
||||
|
||||
|
||||
/**
|
||||
* 设置服务请求超时的时间(单位:毫秒),默认{@link DefaultHttpClientConfig#CONNECTION_REQUEST_TIMEOUT}
|
||||
*/
|
||||
private int connectRequestTimeout = DefaultHttpClientConfig.CONNECTION_REQUEST_TIMEOUT;
|
||||
|
||||
|
||||
/**
|
||||
* token的超时时间(单位:分钟)
|
||||
*/
|
||||
private int tokenTimeout = CommonConstant.DEFAULT_TOKEN_EFFECTIVE_TIME;
|
||||
|
||||
/**
|
||||
* token提前获取的时间(单位:分钟)
|
||||
*/
|
||||
private int tokenResidueTime = CommonConstant.DEFAULT_TOKEN_RESIDUE_TIME;
|
||||
|
||||
|
||||
/**
|
||||
* 是否使用服务器时间
|
||||
*/
|
||||
private boolean usedServerTime = CommonConstant.DEFAULT_IS_USED_SERVER_TIME;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.jhinno.sdk.openapi.constant;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
* @date 2024/6/4 16:12
|
||||
*/
|
||||
public class CommonConstants {
|
||||
|
||||
|
||||
/**
|
||||
* 配置的前缀
|
||||
*/
|
||||
public static final String CONFIG_PREFIX = "jhinno.openapi";
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.jhinno.sdk.openapi.autoconfigure.JHOpenapiClientAutoConfigure,\
|
||||
com.jhinno.sdk.openapi.autoconfigure.JHOpenapiExecutionAutoconfigure
|
||||
@@ -0,0 +1,2 @@
|
||||
com.jhinno.sdk.openapi.autoconfigure.JHOpenapiClientAutoConfigure
|
||||
com.jhinno.sdk.openapi.autoconfigure.JHOpenapiExecutionAutoconfigure
|
||||
Reference in New Issue
Block a user