|
@@ -15,6 +15,7 @@ import com.yohobuy.ufo.model.request.nfc.ProductInfoReq; |
|
@@ -15,6 +15,7 @@ import com.yohobuy.ufo.model.request.nfc.ProductInfoReq; |
15
|
import org.apache.commons.beanutils.BeanUtils;
|
15
|
import org.apache.commons.beanutils.BeanUtils;
|
16
|
import org.apache.commons.codec.binary.*;
|
16
|
import org.apache.commons.codec.binary.*;
|
17
|
import org.apache.commons.lang3.*;
|
17
|
import org.apache.commons.lang3.*;
|
|
|
18
|
+import org.apache.commons.lang3.StringUtils;
|
18
|
import org.slf4j.Logger;
|
19
|
import org.slf4j.Logger;
|
19
|
import org.slf4j.LoggerFactory;
|
20
|
import org.slf4j.LoggerFactory;
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -70,29 +71,35 @@ public class ProductChainService { |
|
@@ -70,29 +71,35 @@ public class ProductChainService { |
70
|
|
71
|
|
71
|
// curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v
|
72
|
// curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v
|
72
|
public void postQuery(Long chainId, String tagid) {
|
73
|
public void postQuery(Long chainId, String tagid) {
|
73
|
- // (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout)
|
|
|
74
|
- Map<String, Object> request = new HashMap<>(); request.put("id", chainId);
|
74
|
+ try {
|
|
|
75
|
+ // (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout)
|
|
|
76
|
+ Map<String, Object> request = new HashMap<>();
|
|
|
77
|
+ request.put("id", chainId);
|
75
|
|
78
|
|
76
|
- HttpHeaders headers = getHttpHeaders("");
|
|
|
77
|
- HttpEntity<String> formEntity = getStringHttpEntity(request, headers);
|
|
|
78
|
- ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/query", formEntity, String.class);
|
79
|
+ HttpHeaders headers = getHttpHeaders("");
|
|
|
80
|
+ HttpEntity<String> formEntity = getStringHttpEntity(request, headers);
|
|
|
81
|
+ ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/query", formEntity, String.class);
|
79
|
|
82
|
|
80
|
- JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
81
|
- String errorCode = jsonObject.getString("errorCode");
|
|
|
82
|
- JSONObject result = jsonObject.getJSONObject("result");
|
83
|
+ JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
84
|
+ String errorCode = jsonObject.getString("errorCode");
|
|
|
85
|
+ JSONObject result = jsonObject.getJSONObject("result");
|
83
|
|
86
|
|
84
|
- logger.info("postQuery success. chainId is {}, errorCode is {}, result is {}", chainId, errorCode, result);
|
87
|
+ logger.info("postQuery success. chainId is {}, errorCode is {}, result is {}", chainId, errorCode, result);
|
85
|
|
88
|
|
86
|
- if (org.apache.commons.lang3.StringUtils.isEmpty(errorCode) && null != result) {
|
|
|
87
|
- JSONArray yohoInfos = result.getJSONArray("yohoInfos");
|
|
|
88
|
- int size = yohoInfos.size();
|
|
|
89
|
- if (0 >= size) {
|
|
|
90
|
- return;
|
|
|
91
|
- }
|
|
|
92
|
- JSONObject item = (JSONObject)yohoInfos.get(0);
|
|
|
93
|
- String transactionId = item.getString("transactionId");
|
89
|
+ if (org.apache.commons.lang3.StringUtils.isEmpty(errorCode) && null != result) {
|
|
|
90
|
+ JSONArray yohoInfos = result.getJSONArray("yohoInfos");
|
|
|
91
|
+ int size = yohoInfos.size();
|
|
|
92
|
+ if (0 >= size) {
|
|
|
93
|
+ return;
|
|
|
94
|
+ }
|
|
|
95
|
+ JSONObject item = (JSONObject) yohoInfos.get(0);
|
|
|
96
|
+ String transactionId = item.getString("transactionId");
|
|
|
97
|
+ Integer transactionTime = item.getInteger("transaction_time");
|
94
|
|
98
|
|
95
|
- updateProductChain(ProductChain.builder().tagId(tagid).transactionId(transactionId).build());
|
99
|
+ updateProductChain(ProductChain.builder().tagId(tagid).transactionId(transactionId).transactionTime(transactionTime).build());
|
|
|
100
|
+ }
|
|
|
101
|
+ } catch (Exception e) {
|
|
|
102
|
+ logger.error("postQuery find wrong, chainId is " + chainId, e);
|
96
|
}
|
103
|
}
|
97
|
}
|
104
|
}
|
98
|
|
105
|
|
|
@@ -145,7 +152,11 @@ public class ProductChainService { |
|
@@ -145,7 +152,11 @@ public class ProductChainService { |
145
|
|
152
|
|
146
|
public int updateProductChain(ProductChain chain) {
|
153
|
public int updateProductChain(ProductChain chain) {
|
147
|
logger.info("updateProductChain in, chain is {}", chain);
|
154
|
logger.info("updateProductChain in, chain is {}", chain);
|
148
|
-
|
155
|
+ ProductChain productChain = productChainMapper.selectByPrimaryKey(chain.getTagId());
|
|
|
156
|
+ if (null != productChain && StringUtils.isNotEmpty(productChain.getTransactionId())) {
|
|
|
157
|
+ productChain.setTransactionTime(chain.getTransactionTime());
|
|
|
158
|
+ productChainMapper.updateByPrimaryKeySelective(productChain); // 只更新时间
|
|
|
159
|
+ }
|
149
|
return productChainMapper.updateProductChain(chain);
|
160
|
return productChainMapper.updateProductChain(chain);
|
150
|
}
|
161
|
}
|
151
|
|
162
|
|