Authored by caoyan

Merge branch 'test6.10.0' of http://git.yoho.cn/ufo/ufo-platform into test6.10.0

@@ -45,4 +45,8 @@ public interface BuyerOrderMapper { @@ -45,4 +45,8 @@ public interface BuyerOrderMapper {
45 int selectCountByStatusForFastDelivery(@Param("currentSecondMinus36Hours")Integer currentSecondMinus24Hours); 45 int selectCountByStatusForFastDelivery(@Param("currentSecondMinus36Hours")Integer currentSecondMinus24Hours);
46 46
47 List<BuyerOrder> selectMinFalultList(@Param("buyerOrderReq") BuyerOrderReq req); 47 List<BuyerOrder> selectMinFalultList(@Param("buyerOrderReq") BuyerOrderReq req);
  48 +
  49 +
  50 + List<BuyerOrder> selectByStatusAndUpdateTimeLess(@Param("status")int status, @Param("updateTime")int updateTime);
  51 +
48 } 52 }
@@ -366,4 +366,11 @@ @@ -366,4 +366,11 @@
366 limit #{buyerOrderReq.start},#{buyerOrderReq.size} 366 limit #{buyerOrderReq.start},#{buyerOrderReq.size}
367 </if> 367 </if>
368 </select> 368 </select>
  369 +
  370 +
  371 + <select id="selectByStatusAndUpdateTimeLess" resultMap="BaseResultMap">
  372 + select <include refid="Base_Column_List"></include>
  373 + from buyer_order
  374 + where status = #{status} and update_time < #{updateTime}
  375 + </select>
369 </mapper> 376 </mapper>
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 <insert id="updateProductChain" parameterType="com.yoho.product.model.ProductChain" > 23 <insert id="updateProductChain" parameterType="com.yoho.product.model.ProductChain" >
24 insert into product_chain (tag_id, chain_id, transaction_id, transaction_time) 24 insert into product_chain (tag_id, chain_id, transaction_id, transaction_time)
25 values (#{tagId,jdbcType=VARCHAR}, #{chainId,jdbcType=BIGINT}, #{transactionId,jdbcType=VARCHAR}, #{transactionTime,jdbcType=INTEGER}) 25 values (#{tagId,jdbcType=VARCHAR}, #{chainId,jdbcType=BIGINT}, #{transactionId,jdbcType=VARCHAR}, #{transactionTime,jdbcType=INTEGER})
26 - ON DUPLICATE KEY UPDATE transaction_time=#{transactionTime, jdbcType=INTEGER} 26 + ON DUPLICATE KEY UPDATE transaction_time=#{transactionTime, jdbcType=INTEGER}, transaction_id = #{transactionId,jdbcType=VARCHAR}
27 </insert> 27 </insert>
28 <insert id="insertSelective" parameterType="com.yoho.product.model.ProductChain" > 28 <insert id="insertSelective" parameterType="com.yoho.product.model.ProductChain" >
29 insert into product_chain 29 insert into product_chain
  1 +package com.yoho.ufo.order.controller;
  2 +
  3 +import com.yoho.core.rabbitmq.YhProducer;
  4 +import com.yoho.order.dal.BuyerOrderMapper;
  5 +import com.yoho.ufo.util.DateUtil;
  6 +import org.apache.ibatis.annotations.Param;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import javax.annotation.Resource;
  13 +import java.util.Objects;
  14 +import java.util.Optional;
  15 +
  16 +@RestController
  17 +@RequestMapping(value = "/help")
  18 +public class OrderHelpController {
  19 +
  20 + @Autowired
  21 + private BuyerOrderMapper buyerOrderMapper;
  22 +
  23 + @Resource(name = "yhProducer")
  24 + private YhProducer yhProducer;
  25 +
  26 + @RequestMapping(value = "/fixTimeoutNonConfirmOrder")
  27 + public void fixTimeoutNonConfirmOrder(
  28 + @RequestParam(value = "updateTime", required = false) String updateTime
  29 + , @RequestParam(value = "orderCode", required = false) String orderCode) {
  30 + String topic = "buyerOrder.autoConfirm";
  31 + if (Objects.nonNull(orderCode)) {
  32 + Optional.ofNullable(buyerOrderMapper.selectByOrderCode(orderCode))
  33 + .ifPresent(order -> yhProducer.send(topic, order));
  34 + } else if (Objects.nonNull(updateTime)) {
  35 + int updateTimeSeconds = DateUtil.getTimeSecondsFromStr(updateTime, "yyyyMMddHHmmss");
  36 + int maxUpdateTimeSeconds = DateUtil.getCurrentTimeSeconds() - 7 * 24 * 3600;
  37 + if (updateTimeSeconds > maxUpdateTimeSeconds) {
  38 + return;
  39 + }
  40 + buyerOrderMapper.selectByStatusAndUpdateTimeLess(4, updateTimeSeconds)
  41 + .forEach(order -> yhProducer.send(topic, order));
  42 + }
  43 +
  44 + }
  45 +
  46 +}
@@ -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