forked from rongchao/epmet-cloud-rizhao
10 changed files with 244 additions and 74 deletions
@ -0,0 +1,19 @@ |
|||
package com.epmet.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: liushaowen |
|||
* @date: 2020/11/17 10:07 |
|||
*/ |
|||
@Data |
|||
public class AccessTokenDTO implements Serializable { |
|||
private String resiToken; |
|||
|
|||
private String workToken; |
|||
|
|||
private String errMsg; |
|||
} |
@ -0,0 +1,53 @@ |
|||
package com.epmet.utils; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.epmet.commons.tools.enums.EnvEnum; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.utils.HttpClientManager; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.dto.AccessTokenDTO; |
|||
import com.epmet.dto.result.CustomerTokensResultDTO; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: liushaowen |
|||
* @date: 2020/11/17 10:04 |
|||
*/ |
|||
|
|||
public class ThirdUtils { |
|||
/** |
|||
* @Description 获取AccessToken公共方法 |
|||
* @param customerId |
|||
* @return com.epmet.dto.AccessTokenDTO |
|||
* @Author liushaowen |
|||
* @Date 2020/11/17 10:09 |
|||
*/ |
|||
public static AccessTokenDTO getAccessToken(String customerId) { |
|||
EnvEnum envEnum = EnvEnum.getCurrentEnv(); |
|||
AccessTokenDTO accessToken = new AccessTokenDTO(); |
|||
|
|||
String url = "https://epmet-cloud.elinkservice.cn/api/third/pacustomer/tokenlist"; |
|||
JSONObject postData = new JSONObject(); |
|||
postData.put("customerId", customerId); |
|||
String data = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(postData)).getData(); |
|||
JSONObject toResult = JSON.parseObject(data); |
|||
Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class); |
|||
if (null != toResult.get("code")) { |
|||
mapToResult.setCode(((Integer) toResult.get("code")).intValue()); |
|||
} |
|||
if (!mapToResult.success()) { |
|||
accessToken.setErrMsg( StringUtils.isBlank(mapToResult.getMsg()) ? mapToResult.getInternalMsg() : mapToResult.getMsg()); |
|||
} |
|||
Object CustomerTokensResultDTO = mapToResult.getData(); |
|||
JSONObject json = JSON.parseObject(CustomerTokensResultDTO.toString()); |
|||
CustomerTokensResultDTO customerTokensResultDTO = ConvertUtils.mapToEntity(json, com.epmet.dto.result.CustomerTokensResultDTO.class); |
|||
accessToken.setResiToken(customerTokensResultDTO.getResiAuthorizerToken()); |
|||
accessToken.setWorkToken(customerTokensResultDTO.getWorkAuthorizerToken()); |
|||
return accessToken; |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
package com.epmet.config; |
|||
|
|||
import com.epmet.properties.ThreadProperties; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.scheduling.annotation.EnableAsync; |
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|||
|
|||
import java.util.concurrent.Executor; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.ThreadPoolExecutor; |
|||
|
|||
/** |
|||
* 线程池配置类 |
|||
*/ |
|||
@Configuration |
|||
@EnableConfigurationProperties(ThreadProperties.class) |
|||
@EnableAsync |
|||
public class AsyncConfig { |
|||
|
|||
@Autowired |
|||
private ThreadProperties threadProperties; |
|||
|
|||
@Bean |
|||
public Executor executor() { |
|||
ThreadProperties.ThreadPoolProperties threadPoolProps = threadProperties.getThreadPool(); |
|||
|
|||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
|||
executor.setCorePoolSize(threadPoolProps.getCorePoolSize()); |
|||
executor.setMaxPoolSize(threadPoolProps.getMaxPoolSize()); |
|||
executor.setQueueCapacity(threadPoolProps.getQueueCapacity()); |
|||
executor.setThreadNamePrefix("epmet-resi-group-"); |
|||
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
|
|||
// CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
|
|||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //对拒绝task的处理策略
|
|||
executor.setKeepAliveSeconds(threadPoolProps.getKeepAlive()); |
|||
executor.initialize(); |
|||
return executor; |
|||
} |
|||
|
|||
@Bean |
|||
public ExecutorService executorService() { |
|||
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) executor(); |
|||
return executor.getThreadPoolExecutor(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
package com.epmet.properties; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
|
|||
/** |
|||
* 线程池属性类 |
|||
*/ |
|||
@ConfigurationProperties(prefix = "thread") |
|||
@Data |
|||
public class ThreadProperties { |
|||
|
|||
private ThreadPoolProperties threadPool; |
|||
|
|||
@Data |
|||
public static class ThreadPoolProperties { |
|||
private int corePoolSize; |
|||
private int maxPoolSize; |
|||
private int queueCapacity; |
|||
private int keepAlive; |
|||
|
|||
public ThreadPoolProperties() { |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue