perf(feature/DM/nflg-bom): 同步虚拟物料到OA改为异步,http请求添加日志
This commit is contained in:
parent
83a94ead23
commit
ffcf1d6991
|
|
@ -28,4 +28,17 @@ public class TaskPoolConfig {
|
|||
taskExecutor.setThreadFactory(new ThreadFactoryBuilder().setNamePrefix("plm-searcher-thread-").build());
|
||||
return taskExecutor;
|
||||
}
|
||||
|
||||
@Bean("syncOAThreadPool")
|
||||
public ThreadPoolTaskExecutor syncOAThreadPool() {
|
||||
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
|
||||
taskExecutor.setCorePoolSize(10);
|
||||
taskExecutor.setMaxPoolSize(30);
|
||||
taskExecutor.setQueueCapacity(2000);
|
||||
taskExecutor.setKeepAliveSeconds(100);
|
||||
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//设置线程池的线程名称,方便日志追踪
|
||||
taskExecutor.setThreadFactory(new ThreadFactoryBuilder().setNamePrefix("sync-oa-").build());
|
||||
return taskExecutor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ import javax.annotation.Resource;
|
|||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
|
@ -44,6 +47,10 @@ public class MaterialService {
|
|||
@Resource
|
||||
MaterialMainService materialMainService;
|
||||
|
||||
@Resource
|
||||
@Qualifier("syncOAThreadPool")
|
||||
ThreadPoolTaskExecutor syncOAThreadPool;
|
||||
|
||||
/**
|
||||
* 申请物料
|
||||
*
|
||||
|
|
@ -202,7 +209,7 @@ public class MaterialService {
|
|||
materialMainService.saveOrUpdateBatch(resultList);
|
||||
initCategoryInfo(syncOaEnts);
|
||||
//同步OA
|
||||
sysnToOa(syncOaEnts);
|
||||
CompletableFuture.runAsync(() -> sysnToOa(syncOaEnts),syncOAThreadPool);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package com.nflg.product.bomnew.util;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import okhttp3.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -23,6 +26,8 @@ public class HttpUtils {
|
|||
//请求类
|
||||
private OkHttpClient okHttpClient;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtils.class);
|
||||
|
||||
//请求头类型
|
||||
private final MediaType jsonMediaType = MediaType.parse("application/json;charset=utf-8");
|
||||
|
||||
|
|
@ -210,13 +215,22 @@ public class HttpUtils {
|
|||
* @throws IOException e
|
||||
*/
|
||||
public String doPost(String url, String json) throws IOException {
|
||||
System.out.println(url);
|
||||
System.out.println(json);
|
||||
Response response = doPostRtnRsp(url, json);
|
||||
if (response == null || response.body() == null) {
|
||||
return null;
|
||||
String ret = null;
|
||||
String traceId = IdWorker.getIdStr();
|
||||
LOGGER.info(traceId + ",http请求,地址:" + url + ",参数:" + json);
|
||||
long start = System.currentTimeMillis();
|
||||
try (Response response = doPostRtnRsp(url, json)) {
|
||||
if (response == null || response.body() == null) {
|
||||
return null;
|
||||
}
|
||||
ret = response.body().string();
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(traceId + ",http请求,出错", ex);
|
||||
} finally {
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info(traceId + ",http请求,耗时:" + (end - start) + "毫秒,返回:" + ret);
|
||||
}
|
||||
return response.body().string();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue