...
|
...
|
@@ -15,6 +15,7 @@ import com.yohobuy.ufo.model.request.nfc.ProductInfoReq; |
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.apache.commons.codec.binary.*;
|
|
|
import org.apache.commons.lang3.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -70,29 +71,35 @@ public class ProductChainService { |
|
|
|
|
|
// curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v
|
|
|
public void postQuery(Long chainId, String tagid) {
|
|
|
// (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout)
|
|
|
Map<String, Object> request = new HashMap<>(); request.put("id", chainId);
|
|
|
try {
|
|
|
// (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout)
|
|
|
Map<String, Object> request = new HashMap<>();
|
|
|
request.put("id", chainId);
|
|
|
|
|
|
HttpHeaders headers = getHttpHeaders("");
|
|
|
HttpEntity<String> formEntity = getStringHttpEntity(request, headers);
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/query", formEntity, String.class);
|
|
|
HttpHeaders headers = getHttpHeaders("");
|
|
|
HttpEntity<String> formEntity = getStringHttpEntity(request, headers);
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/query", formEntity, String.class);
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
String errorCode = jsonObject.getString("errorCode");
|
|
|
JSONObject result = jsonObject.getJSONObject("result");
|
|
|
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
String errorCode = jsonObject.getString("errorCode");
|
|
|
JSONObject result = jsonObject.getJSONObject("result");
|
|
|
|
|
|
logger.info("postQuery success. chainId is {}, errorCode is {}, result is {}", chainId, errorCode, result);
|
|
|
logger.info("postQuery success. chainId is {}, errorCode is {}, result is {}", chainId, errorCode, result);
|
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(errorCode) && null != result) {
|
|
|
JSONArray yohoInfos = result.getJSONArray("yohoInfos");
|
|
|
int size = yohoInfos.size();
|
|
|
if (0 >= size) {
|
|
|
return;
|
|
|
}
|
|
|
JSONObject item = (JSONObject)yohoInfos.get(0);
|
|
|
String transactionId = item.getString("transactionId");
|
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(errorCode) && null != result) {
|
|
|
JSONArray yohoInfos = result.getJSONArray("yohoInfos");
|
|
|
int size = yohoInfos.size();
|
|
|
if (0 >= size) {
|
|
|
return;
|
|
|
}
|
|
|
JSONObject item = (JSONObject) yohoInfos.get(0);
|
|
|
String transactionId = item.getString("transactionId");
|
|
|
Integer transactionTime = item.getInteger("transaction_time");
|
|
|
|
|
|
updateProductChain(ProductChain.builder().tagId(tagid).transactionId(transactionId).build());
|
|
|
updateProductChain(ProductChain.builder().tagId(tagid).transactionId(transactionId).transactionTime(transactionTime).build());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("postQuery find wrong, chainId is " + chainId, e);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -145,7 +152,11 @@ public class ProductChainService { |
|
|
|
|
|
public int updateProductChain(ProductChain chain) {
|
|
|
logger.info("updateProductChain in, chain is {}", chain);
|
|
|
|
|
|
ProductChain productChain = productChainMapper.selectByPrimaryKey(chain.getTagId());
|
|
|
if (null != productChain && StringUtils.isNotEmpty(productChain.getTransactionId())) {
|
|
|
productChain.setTransactionTime(chain.getTransactionTime());
|
|
|
productChainMapper.updateByPrimaryKeySelective(productChain); // 只更新时间
|
|
|
}
|
|
|
return productChainMapper.updateProductChain(chain);
|
|
|
}
|
|
|
|
...
|
...
|
|