代码备份

master
anthonyywj2 3 years ago
parent da6b53ae30
commit 387fcca543

@ -296,6 +296,11 @@
<artifactId>com.lowagie.text</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
</dependency>
<!-- jasperreports end-->
<!-- jasperreports-dependency-end -->

@ -0,0 +1,105 @@
package com.glxp.api.admin.config;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.net.ssl.*;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.concurrent.TimeUnit;
/**
* @author Answer.AI.L
* @date 2019-04-09
*/
@Configuration
public class OkHttpConfiguration {
@Value("${ok.http.connect-timeout}")
private Integer connectTimeout;
@Value("${ok.http.read-timeout}")
private Integer readTimeout;
@Value("${ok.http.write-timeout}")
private Integer writeTimeout;
@Value("${ok.http.max-idle-connections}")
private Integer maxIdleConnections;
@Value("${ok.http.keep-alive-duration}")
private Long keepAliveDuration;
@Bean
public OkHttpClient okHttpClient() {
return new OkHttpClient.Builder()
.sslSocketFactory(sslSocketFactory(), x509TrustManager())
// 是否开启缓存
.retryOnConnectionFailure(false)
.connectionPool(pool())
.connectTimeout(connectTimeout, TimeUnit.SECONDS)
.readTimeout(readTimeout, TimeUnit.SECONDS)
.writeTimeout(writeTimeout, TimeUnit.SECONDS)
.hostnameVerifier((hostname, session) -> true)
// 设置代理
// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)))
// 拦截器
// .addInterceptor()
.build();
}
@Bean
public X509TrustManager x509TrustManager() {
return new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
};
}
@Bean
public SSLSocketFactory sslSocketFactory() {
try {
// 信任任何链接
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{x509TrustManager()}, new SecureRandom());
return sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
e.printStackTrace();
}
return null;
}
@Bean
public ConnectionPool pool() {
return new ConnectionPool(maxIdleConnections, keepAliveDuration, TimeUnit.SECONDS);
}
}

@ -60,6 +60,8 @@ public class SpsSyncExportStatusController {
@GetMapping("/spssync/basic/udiinfo/filter")
public BaseResponse filterStatus(BasicExportStatusRequest basicExportStatusRequest) {
log.info(Thread.currentThread().getName() + "--" + Thread.currentThread().getId());
List<BasicExportStatusEntity> basicExportStatusEntities = basicExportService.filterExportStatus(basicExportStatusRequest);
PageInfo<BasicExportStatusEntity> pageInfo;
pageInfo = new PageInfo<>(basicExportStatusEntities);

@ -1,5 +1,6 @@
package com.glxp.api.admin.httpclient;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.admin.entity.basic.BasicExportStatusEntity;
@ -16,6 +17,7 @@ import com.glxp.api.admin.res.basic.SpsSyncOrderResponse;
import com.glxp.api.admin.res.basic.SpsSyncScheduleResponse;
import com.glxp.api.admin.res.inout.DlOrderResponse;
import com.glxp.api.admin.service.info.SyncDataSetService;
import com.glxp.api.admin.util.OkHttpCli;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import org.springframework.beans.factory.annotation.Value;
@ -32,8 +34,12 @@ public class SpGetHttpClient {
// @Value("${SPSYNC_IP}")
// private String spsSyncUrl;
@Resource
private OkHttpCli okHttpCli;
@Resource
SyncDataSetService syncDataSetService;
public String getIpUrl() {
SyncDataSetEntity syncDataSetEntity = syncDataSetService.findSet();
return syncDataSetEntity.getSyncIp();
@ -144,7 +150,9 @@ public class SpGetHttpClient {
BasicExportStatusRequest basicExportStatusRequest = new BasicExportStatusRequest();
basicExportStatusRequest.setId(id);
basicExportStatusRequest.setType(type);
String result = UHttpClient.postJson(getIpUrl() + "/spssync/basic/udiinfo/downloadByStatus", basicExportStatusRequest);
String json = JSONUtil.toJsonStr(basicExportStatusRequest);
String result = okHttpCli.doPostJson(getIpUrl() + "/spssync/basic/udiinfo/downloadByStatus", json);
// String result = UHttpClient.postJson(getIpUrl() + "/spssync/basic/udiinfo/downloadByStatus", basicExportStatusRequest);
return result;
}

@ -523,19 +523,29 @@ public class DlBasicService {
public void dlAllUDI() {
// try {
// logger.error("--------执行下载操作");
// Thread.sleep(15 * 1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// logger.error("--------下载失败");
// }
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(BasicProcessStatus.NEW_ALL_DI + "");
List<BasicExportStatusEntity> pageSimpleResponse = baseResponse.getData();
if (pageSimpleResponse != null) {
List<BasicExportStatusEntity> basicExportStatusEntities = pageSimpleResponse;
if (basicExportStatusEntities != null && basicExportStatusEntities.size() > 0) {
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
long curTime = System.currentTimeMillis();
logger.info("--------等待时间------" + curTime);
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), BasicProcessStatus.NEW_ALL_DI);
logger.info("--------等待时间1------" + (System.currentTimeMillis() - curTime) / 1000);
long curTime2 = System.currentTimeMillis();
BaseResponse<SpSyncUdiResponse> response = JSONObject.parseObject(datas, new TypeReference<BaseResponse<SpSyncUdiResponse>>() {
});
logger.info("--------等待时间2------" + (System.currentTimeMillis() - curTime2) / 1000);
if (response.getCode() == 20000 && response.getData() != null) {
SpSyncUdiResponse spSyncUdiResponse = response.getData();
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(spSyncUdiResponse.getTaskId());

@ -46,6 +46,14 @@ public class DlUploadService {
long timeInterval = Long.parseLong(systemParamConfigEntity.getParamValue()) * 60 * 1000;
long curTime = System.currentTimeMillis();
Long lastTime = (Long) redisUtil.get("DL_BASIC_UDIINFO_STATUS");
// try {
// logger.error("--------执行下载操作");
// Thread.sleep(15 * 1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// logger.error("--------下载失败");
// }
if (lastTime == null) {
lastTime = System.currentTimeMillis();
redisUtil.set("DL_BASIC_UDIINFO_STATUS", lastTime);

@ -55,6 +55,7 @@ public class HeartTask implements SchedulingConfigurer {
private void process() {
//查询数据同步设置
logger.error("心跳任务--------------------------------------"+Thread.currentThread().getName());
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
if (syncDataSetEntity.isDownstreamEnable()) {
//定时上传最近更新基础数据至上游轮询时间
@ -100,7 +101,6 @@ public class HeartTask implements SchedulingConfigurer {
}
long timeInterval3 = syncDataSetEntity.getSyncDownloadTime() * 60 * 1000;
long curTime3 = System.currentTimeMillis();
Long lastTime3 = (Long) redisUtil.get("SPS_SYNC_DOWNLOAD_ORDER");

@ -65,6 +65,8 @@ public class OrderSubmitTask implements SchedulingConfigurer {
}
private void process() {
log.error("OrderSubmitTask--------------------------------------" + Thread.currentThread().getName());
SystemParamConfigEntity auto_submit_order = systemParamConfigDao.selectByParamKey("auto_submit_order");
if (auto_submit_order.getParamValue().equals("0")) {
log.info("未开启自动提交单据");

@ -21,7 +21,7 @@ public class TaskExecutorConfig implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(5);//当前线程数
threadPool.setCorePoolSize(10);//当前线程数
threadPool.setMaxPoolSize(120);// 最大线程数
threadPool.setQueueCapacity(5);//线程池所使用的缓冲队列
threadPool.setWaitForTasksToCompleteOnShutdown(true);//等待任务在关机时完成--表明等待所有线程执行完

@ -0,0 +1,175 @@
package com.glxp.api.admin.util;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author Answer.AI.L
* @date 2019-04-09
*/
@Slf4j
@Component
public class OkHttpCli {
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private static final MediaType XML = MediaType.parse("application/xml; charset=utf-8");
@Autowired
private OkHttpClient okHttpClient;
/**
* get
*
* @param url url
* @return string
*/
public String doGet(String url) {
return doGet(url, null, null);
}
/**
* get
*
* @param url url
* @param params map
* @return string
*/
public String doGet(String url, Map<String, String> params) {
return doGet(url, params, null);
}
/**
* get
*
* @param url url
* @param headers {k1, v1 k2, v2, ...}
* @return string
*/
public String doGet(String url, String[] headers) {
return doGet(url, null, headers);
}
/**
* get
*
* @param url url
* @param params map
* @param headers {k1, v1 k2, v2, ...}
* @return string
*/
public String doGet(String url, Map<String, String> params, String[] headers) {
StringBuilder sb = new StringBuilder(url);
if (params != null && params.keySet().size() > 0) {
boolean firstFlag = true;
for (String key : params.keySet()) {
if (firstFlag) {
sb.append("?").append(key).append("=").append(params.get(key));
firstFlag = false;
} else {
sb.append("&").append(key).append("=").append(params.get(key));
}
}
}
Request.Builder builder = new Request.Builder();
if (headers != null && headers.length > 0) {
if (headers.length % 2 == 0) {
for (int i = 0; i < headers.length; i = i + 2) {
builder.addHeader(headers[i], headers[i + 1]);
}
} else {
log.warn("headers's length[{}] is error.", headers.length);
}
}
Request request = builder.url(sb.toString()).build();
log.info("do get request and url[{}]", sb.toString());
return execute(request);
}
/**
* post
*
* @param url url
* @param params map
* @return string
*/
public String doPost(String url, Map<String, String> params) {
FormBody.Builder builder = new FormBody.Builder();
if (params != null && params.keySet().size() > 0) {
for (String key : params.keySet()) {
builder.add(key, params.get(key));
}
}
Request request = new Request.Builder().url(url).post(builder.build()).build();
log.info("do post request and url[{}]", url);
return execute(request);
}
/**
* post , json
*
* @param url url
* @param json , json
* @return string
*/
public String doPostJson(String url, String json) {
log.info("do post request and url[{}]", url);
return exectePost(url, json, JSON);
}
/**
* post , xml
*
* @param url url
* @param xml , xml
* @return string
*/
public String doPostXml(String url, String xml) {
log.info("do post request and url[{}]", url);
return exectePost(url, xml, XML);
}
private String exectePost(String url, String data, MediaType contentType) {
RequestBody requestBody = RequestBody.create(contentType, data);
Request request = new Request.Builder().url(url).post(requestBody).build();
return execute(request);
}
private String execute(Request request) {
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
if (response.isSuccessful()) {
return response.body().string();
}
} catch (Exception e) {
log.error(ExceptionUtils.getStackTrace(e));
} finally {
if (response != null) {
response.close();
}
}
return "";
}
}

@ -1,9 +1,9 @@
# 本地环境
server.port=9991
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.jdbc-url=jdbc:mysql://192.168.0.148:3306/udiwms?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.jdbc-url=jdbc:mysql://127.0.0.1:3306/udiwms?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=Glxp@6066
spring.datasource.password=123456
#spring.datasource.password=89083fb2fc145533
server.servlet.context-path=
#logging.level.com.glxp.api.admin.dao=debug
@ -19,7 +19,6 @@ logging.level.com.glxp.api.admin.erp.second=debug
logging.path=output/logs
# 不指定的情况下默认生成在项目根目录,按照配置生成所需的日志名称
#logging.file=D:/udi.log
#file_path=D:/udi/udiwms/udiwmsfile/
file_path=/home/glxp/udiwms
#UDI数据下载
@ -35,7 +34,7 @@ SPSYNC_IP=http://127.0.0.1:9989
# Redis数据库索引默认为0
spring.redis.database=8
# Redis服务器地址
spring.redis.host=192.168.0.148
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码默认为空
@ -52,9 +51,18 @@ spring.redis.jedis.pool.min-idle=0
spring.redis.jedis.timeout=300
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
ok.http.connect-timeout=3000
ok.http.read-timeout=3000
ok.http.write-timeout=3000
# 连接池中整体的空闲连接的最大数量
ok.http.max-idle-connections=200
# 连接空闲时间最多为 300 秒
ok.http.keep-alive-duration=300

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<property name="log.path" value="/home/glxpdata/udiwms/UDI_WMS_MC/" />
<property name="log.path" value="D:\\udi\\logs\\UDI_WMS_MC\\" />
<!--输出到控制台/home/glxpdata/udiwms/UDI_WMS_MC/-->
<!--D:\\udi\\logs\\UDI_WMS_MC\\-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">

Loading…
Cancel
Save