Commit 1b5e3f59 authored by Quxl's avatar Quxl

x

parent da9c3392
......@@ -48,6 +48,9 @@ public class CommonService {
@Value("${dataTracking.uri.insertOrderTracking}")
private String insertOrderTrackingUri;
@Value("${dataTracking.isOpen}")
private boolean isOpen;
@Transactional(propagation=Propagation.NOT_SUPPORTED)
public Long getNextval(String sName) {
try {
......@@ -100,9 +103,16 @@ public class CommonService {
jdbcTemplate.update(sql, objs);
}
@Value("${dataTracking.tokenExpireMinute}")
private Long tokenExpireMinute;
private static String token;
private static Date tokenCreateTime;
public String getToken() {
Date now = new Date();
if(token != null && tokenCreateTime != null && (tokenCreateTime.getTime() + ((tokenExpireMinute-2)*60L*1000L)) > now.getTime()) {
return token;
}
String requestUrl = baseUrl + tokenUri;
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("appId", appId);
......@@ -112,26 +122,30 @@ public class CommonService {
JSONObject jsonObject = JSONObject.parseObject(resultText);
Boolean isSuccess = jsonObject.getBoolean("success");
if(isSuccess != null && isSuccess) {
return jsonObject.getString("token");
tokenCreateTime = now;
token = jsonObject.getString("token");
return token;
} else {
throw new TrackingTokenException(jsonObject.getString("message"));
}
}
public void saveOrderTracking(String traceNo, String orderType, String orderNo, String disCode, String action, String result, String errorMessage) {
String requestUrl = baseUrl + insertOrderTrackingUri;
String token = this.getToken();
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Bearer "+ token);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("traceNo", traceNo);
parameters.put("orderType", orderType);
parameters.put("orderNo", orderNo);
parameters.put("disCode", disCode);
parameters.put("action", action);
parameters.put("result", result);
parameters.put("errorMessage", errorMessage);
HttpUtil.post(requestUrl, parameters, headers);
if(isOpen) {
String requestUrl = baseUrl + insertOrderTrackingUri;
String token = this.getToken();
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Bearer "+ token);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("traceNo", traceNo);
parameters.put("orderType", orderType);
parameters.put("orderNo", orderNo);
parameters.put("disCode", disCode);
parameters.put("action", action);
parameters.put("result", result);
parameters.put("errorMessage", errorMessage);
HttpUtil.post(requestUrl, parameters, headers);
}
}
public static class TrackingTokenException extends RuntimeException {
......
......@@ -6,6 +6,8 @@ schneider:
password: disbtor@2019
cronSap009: 0 0 0 * * ?
dataTracking:
isOpen: false
tokenExpireMinute: 30
appId: schneider
appSecret: SGVsbG8yQ2xpZW50IQ==
username: schneider
......
......@@ -6,6 +6,8 @@ schneider:
password: disbtor@2019
cronSap009: 0 0 0 * * ?
dataTracking:
isOpen: false
tokenExpireMinute: 30
appId: schneider
appSecret: SGVsbG8yQ2xpZW50IQ==
username: schneider
......
......@@ -6,6 +6,8 @@ schneider:
password: disbtor@2019
cronSap009: 0 0 0 * * ?
dataTracking:
isOpen: false
tokenExpireMinute: 30
appId: schneider
appSecret: SGVsbG8yQ2xpZW50IQ==
username: schneider
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment