Commit 1b5e3f59 authored by Quxl's avatar Quxl

x

parent da9c3392
...@@ -48,6 +48,9 @@ public class CommonService { ...@@ -48,6 +48,9 @@ public class CommonService {
@Value("${dataTracking.uri.insertOrderTracking}") @Value("${dataTracking.uri.insertOrderTracking}")
private String insertOrderTrackingUri; private String insertOrderTrackingUri;
@Value("${dataTracking.isOpen}")
private boolean isOpen;
@Transactional(propagation=Propagation.NOT_SUPPORTED) @Transactional(propagation=Propagation.NOT_SUPPORTED)
public Long getNextval(String sName) { public Long getNextval(String sName) {
try { try {
...@@ -100,9 +103,16 @@ public class CommonService { ...@@ -100,9 +103,16 @@ public class CommonService {
jdbcTemplate.update(sql, objs); jdbcTemplate.update(sql, objs);
} }
@Value("${dataTracking.tokenExpireMinute}")
private Long tokenExpireMinute;
private static String token;
private static Date tokenCreateTime;
public String getToken() { 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; String requestUrl = baseUrl + tokenUri;
Map<String, Object> parameters = new HashMap<String, Object>(); Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("appId", appId); parameters.put("appId", appId);
...@@ -112,26 +122,30 @@ public class CommonService { ...@@ -112,26 +122,30 @@ public class CommonService {
JSONObject jsonObject = JSONObject.parseObject(resultText); JSONObject jsonObject = JSONObject.parseObject(resultText);
Boolean isSuccess = jsonObject.getBoolean("success"); Boolean isSuccess = jsonObject.getBoolean("success");
if(isSuccess != null && isSuccess) { if(isSuccess != null && isSuccess) {
return jsonObject.getString("token"); tokenCreateTime = now;
token = jsonObject.getString("token");
return token;
} else { } else {
throw new TrackingTokenException(jsonObject.getString("message")); throw new TrackingTokenException(jsonObject.getString("message"));
} }
} }
public void saveOrderTracking(String traceNo, String orderType, String orderNo, String disCode, String action, String result, String errorMessage) { public void saveOrderTracking(String traceNo, String orderType, String orderNo, String disCode, String action, String result, String errorMessage) {
String requestUrl = baseUrl + insertOrderTrackingUri; if(isOpen) {
String token = this.getToken(); String requestUrl = baseUrl + insertOrderTrackingUri;
Map<String, String> headers = new HashMap<String, String>(); String token = this.getToken();
headers.put("Authorization", "Bearer "+ token); Map<String, String> headers = new HashMap<String, String>();
Map<String, Object> parameters = new HashMap<String, Object>(); headers.put("Authorization", "Bearer "+ token);
parameters.put("traceNo", traceNo); Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("orderType", orderType); parameters.put("traceNo", traceNo);
parameters.put("orderNo", orderNo); parameters.put("orderType", orderType);
parameters.put("disCode", disCode); parameters.put("orderNo", orderNo);
parameters.put("action", action); parameters.put("disCode", disCode);
parameters.put("result", result); parameters.put("action", action);
parameters.put("errorMessage", errorMessage); parameters.put("result", result);
HttpUtil.post(requestUrl, parameters, headers); parameters.put("errorMessage", errorMessage);
HttpUtil.post(requestUrl, parameters, headers);
}
} }
public static class TrackingTokenException extends RuntimeException { public static class TrackingTokenException extends RuntimeException {
......
...@@ -6,6 +6,8 @@ schneider: ...@@ -6,6 +6,8 @@ schneider:
password: disbtor@2019 password: disbtor@2019
cronSap009: 0 0 0 * * ? cronSap009: 0 0 0 * * ?
dataTracking: dataTracking:
isOpen: false
tokenExpireMinute: 30
appId: schneider appId: schneider
appSecret: SGVsbG8yQ2xpZW50IQ== appSecret: SGVsbG8yQ2xpZW50IQ==
username: schneider username: schneider
......
...@@ -6,6 +6,8 @@ schneider: ...@@ -6,6 +6,8 @@ schneider:
password: disbtor@2019 password: disbtor@2019
cronSap009: 0 0 0 * * ? cronSap009: 0 0 0 * * ?
dataTracking: dataTracking:
isOpen: false
tokenExpireMinute: 30
appId: schneider appId: schneider
appSecret: SGVsbG8yQ2xpZW50IQ== appSecret: SGVsbG8yQ2xpZW50IQ==
username: schneider username: schneider
......
...@@ -6,6 +6,8 @@ schneider: ...@@ -6,6 +6,8 @@ schneider:
password: disbtor@2019 password: disbtor@2019
cronSap009: 0 0 0 * * ? cronSap009: 0 0 0 * * ?
dataTracking: dataTracking:
isOpen: false
tokenExpireMinute: 30
appId: schneider appId: schneider
appSecret: SGVsbG8yQ2xpZW50IQ== appSecret: SGVsbG8yQ2xpZW50IQ==
username: schneider 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