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,13 +122,16 @@ public class CommonService { ...@@ -112,13 +122,16 @@ 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) {
if(isOpen) {
String requestUrl = baseUrl + insertOrderTrackingUri; String requestUrl = baseUrl + insertOrderTrackingUri;
String token = this.getToken(); String token = this.getToken();
Map<String, String> headers = new HashMap<String, String>(); Map<String, String> headers = new HashMap<String, String>();
...@@ -133,6 +146,7 @@ public class CommonService { ...@@ -133,6 +146,7 @@ public class CommonService {
parameters.put("errorMessage", errorMessage); parameters.put("errorMessage", errorMessage);
HttpUtil.post(requestUrl, parameters, headers); HttpUtil.post(requestUrl, parameters, headers);
} }
}
public static class TrackingTokenException extends RuntimeException { public static class TrackingTokenException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -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