Authored by wujiexiang

Merge branch 'dev-fofp' into test6.9.8

@@ -11,6 +11,7 @@ import com.yohoufo.order.constants.ActivityTypeEnum; @@ -11,6 +11,7 @@ import com.yohoufo.order.constants.ActivityTypeEnum;
11 import com.yohoufo.order.constants.MetaKey; 11 import com.yohoufo.order.constants.MetaKey;
12 import com.yohoufo.order.service.listener.BuyerOrderChangeEvent; 12 import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
13 import com.yohoufo.order.model.bo.ActivityBo; 13 import com.yohoufo.order.model.bo.ActivityBo;
  14 +import com.yohoufo.order.service.proxy.BaseServiceCaller;
14 import com.yohoufo.order.service.proxy.BargainProxyService; 15 import com.yohoufo.order.service.proxy.BargainProxyService;
15 import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport; 16 import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport;
16 import com.yohoufo.order.utils.LoggerUtils; 17 import com.yohoufo.order.utils.LoggerUtils;
@@ -40,7 +41,10 @@ public class BuyerOrderChangeBusinessPostProcessor { @@ -40,7 +41,10 @@ public class BuyerOrderChangeBusinessPostProcessor {
40 private BargainProxyService bargainProxyService; 41 private BargainProxyService bargainProxyService;
41 42
42 @Resource( name = "ufoExpressInfoProducer") 43 @Resource( name = "ufoExpressInfoProducer")
43 - private YhProducer ufoExpressInfoProducer; 44 + private YhProducer commonProducer;
  45 +
  46 + @Autowired
  47 + private BaseServiceCaller baseServiceCaller;
44 48
45 //业务处理器 49 //业务处理器
46 private List<BusinessProcessor> processors = Lists.newArrayList( 50 private List<BusinessProcessor> processors = Lists.newArrayList(
@@ -188,7 +192,6 @@ public class BuyerOrderChangeBusinessPostProcessor { @@ -188,7 +192,6 @@ public class BuyerOrderChangeBusinessPostProcessor {
188 } 192 }
189 } 193 }
190 194
191 -  
192 /** 195 /**
193 * 下单通知 196 * 下单通知
194 */ 197 */
@@ -197,12 +200,26 @@ public class BuyerOrderChangeBusinessPostProcessor { @@ -197,12 +200,26 @@ public class BuyerOrderChangeBusinessPostProcessor {
197 200
198 @Override 201 @Override
199 public void create(BusinessProcessorContext context) { 202 public void create(BusinessProcessorContext context) {
  203 + //1.mq通知
200 BuyerOrder buyerOrder = context.buyerOrder; 204 BuyerOrder buyerOrder = context.buyerOrder;
  205 + int uid = buyerOrder.getUid();
  206 + //1.清理缓存yohobuy_gateway新客缓存
  207 + logger.info("[{}] notify resource to clear user cache", uid);
  208 + try {
  209 +
  210 + String url = baseServiceCaller.getYohoGatewayUrl() + "?method=app.resources.clearUserCache&&client_type=h5&uid=" + uid;
  211 + baseServiceCaller.proxyPost("app.resources.clearUserCache", url, null);
  212 + } catch (Exception ex) {
  213 + logger.error("clear user cache for resource,uid:{}", uid, ex);
  214 + }
  215 +
  216 + //2.
  217 + logger.info("[{}] notify fofp to consume buyer order", uid);
201 JSONObject jsonObject = new JSONObject(); 218 JSONObject jsonObject = new JSONObject();
202 - jsonObject.put("uid", buyerOrder.getUid()); 219 + jsonObject.put("uid", uid);
203 jsonObject.put("orderCode", buyerOrder.getOrderCode()); 220 jsonObject.put("orderCode", buyerOrder.getOrderCode());
204 jsonObject.put("createTime", buyerOrder.getCreateTime()); 221 jsonObject.put("createTime", buyerOrder.getCreateTime());
205 - ufoExpressInfoProducer.send(TOPIC, jsonObject); 222 + commonProducer.send(TOPIC, jsonObject);
206 } 223 }
207 } 224 }
208 225
@@ -8,8 +8,11 @@ import com.yoho.core.transaction.annoation.TxCompensateArgs; @@ -8,8 +8,11 @@ import com.yoho.core.transaction.annoation.TxCompensateArgs;
8 import com.yoho.error.exception.ServiceException; 8 import com.yoho.error.exception.ServiceException;
9 import com.yohoufo.common.ApiResponse; 9 import com.yohoufo.common.ApiResponse;
10 import com.yohoufo.common.exception.UfoServiceException; 10 import com.yohoufo.common.exception.UfoServiceException;
  11 +import com.yohoufo.order.utils.LoggerUtils;
11 import lombok.Data; 12 import lombok.Data;
12 import lombok.ToString; 13 import lombok.ToString;
  14 +import org.slf4j.Logger;
  15 +import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Component; 16 import org.springframework.stereotype.Component;
14 17
15 import java.math.BigDecimal; 18 import java.math.BigDecimal;
@@ -22,7 +25,13 @@ import java.util.Objects; @@ -22,7 +25,13 @@ import java.util.Objects;
22 25
23 26
24 @Component 27 @Component
25 -public class BargainProxyService extends AbsServiceCaller implements Compensator { 28 +public class BargainProxyService implements Compensator {
  29 +
  30 + private final static Logger logger = LoggerUtils.getBuyerOrderLogger();
  31 +
  32 + @Autowired
  33 + private BaseServiceCaller baseServiceCaller;
  34 +
26 /** 35 /**
27 * 获取用户砍价商品的最终价格 36 * 获取用户砍价商品的最终价格
28 * 所有的业务校验都在activity服务端实现,如活动时间、是否达成 37 * 所有的业务校验都在activity服务端实现,如活动时间、是否达成
@@ -33,12 +42,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator @@ -33,12 +42,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
33 */ 42 */
34 public CutDownPriceProductOrderBo queryCutPriceProductForOrder(int uid, int cutRecordId) { 43 public CutDownPriceProductOrderBo queryCutPriceProductForOrder(int uid, int cutRecordId) {
35 logger.info("getActivityPrice by uid {},cutRecordId {}", uid, cutRecordId); 44 logger.info("getActivityPrice by uid {},cutRecordId {}", uid, cutRecordId);
36 - String url = erpGatewayUrl + "/erp/activity/cutPrice/queryCutPriceProductForOrder"; 45 + String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/queryCutPriceProductForOrder";
37 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO(); 46 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
38 requestBO.setUserId(uid); 47 requestBO.setUserId(uid);
39 requestBO.setCutRecordId(cutRecordId); 48 requestBO.setCutRecordId(cutRecordId);
40 - ApiResponse response = proxyPost("activity.queryCutPriceProductForOrder", url, requestBO);  
41 - CutDownPriceProductOrderBo cutDownPriceProductOrderBo = getResultFromApiResponse(response, CutDownPriceProductOrderBo.class); 49 + ApiResponse response = baseServiceCaller.proxyPost("activity.queryCutPriceProductForOrder", url, requestBO);
  50 + CutDownPriceProductOrderBo cutDownPriceProductOrderBo = baseServiceCaller.getResultFromApiResponse(response, CutDownPriceProductOrderBo.class);
42 if (Objects.isNull(cutDownPriceProductOrderBo)) { 51 if (Objects.isNull(cutDownPriceProductOrderBo)) {
43 logger.warn("can't getActivityPrice by uid {},cutRecordId {}", uid, cutRecordId); 52 logger.warn("can't getActivityPrice by uid {},cutRecordId {}", uid, cutRecordId);
44 throw new UfoServiceException(500, "未查询到用户砍价商品信息"); 53 throw new UfoServiceException(500, "未查询到用户砍价商品信息");
@@ -59,12 +68,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator @@ -59,12 +68,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
59 public void addCutPriceUseRecord(@TxCompensateArgs("uid") int uid, @TxCompensateArgs("orderCode") long orderCode, 68 public void addCutPriceUseRecord(@TxCompensateArgs("uid") int uid, @TxCompensateArgs("orderCode") long orderCode,
60 @TxCompensateArgs("cutRecordId") int cutRecordId) throws ServiceException { 69 @TxCompensateArgs("cutRecordId") int cutRecordId) throws ServiceException {
61 logger.debug("addCutPriceUseRecord by uid {},cutRecordId {},orderCode {}", uid, cutRecordId, orderCode); 70 logger.debug("addCutPriceUseRecord by uid {},cutRecordId {},orderCode {}", uid, cutRecordId, orderCode);
62 - String url = erpGatewayUrl + "/erp/activity/cutPrice/addCutPriceUseRecord"; 71 + String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/addCutPriceUseRecord";
63 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO(); 72 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
64 requestBO.setUserId(uid); 73 requestBO.setUserId(uid);
65 requestBO.setCutRecordId(cutRecordId); 74 requestBO.setCutRecordId(cutRecordId);
66 requestBO.setOrderCode(orderCode); 75 requestBO.setOrderCode(orderCode);
67 - ApiResponse response = proxyPost("activity.addCutPriceUseRecord", url, requestBO); 76 + ApiResponse response = baseServiceCaller.proxyPost("activity.addCutPriceUseRecord", url, requestBO);
68 logger.info("addCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}", 77 logger.info("addCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}",
69 uid, cutRecordId, orderCode, response); 78 uid, cutRecordId, orderCode, response);
70 if (response == null || response.getCode() != 200) { 79 if (response == null || response.getCode() != 200) {
@@ -86,12 +95,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator @@ -86,12 +95,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
86 */ 95 */
87 public void cancelCutPriceUseRecord(int uid, long orderCode, int cutRecordId) throws ServiceException { 96 public void cancelCutPriceUseRecord(int uid, long orderCode, int cutRecordId) throws ServiceException {
88 logger.debug("cancelCutPriceUseRecord by uid {},orderCode {},cutRecordId {}", uid, orderCode, cutRecordId); 97 logger.debug("cancelCutPriceUseRecord by uid {},orderCode {},cutRecordId {}", uid, orderCode, cutRecordId);
89 - String url = erpGatewayUrl + "/erp/activity/cutPrice/cancelCutPriceUseRecord"; 98 + String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/cancelCutPriceUseRecord";
90 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO(); 99 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
91 requestBO.setUserId(uid); 100 requestBO.setUserId(uid);
92 requestBO.setCutRecordId(cutRecordId); 101 requestBO.setCutRecordId(cutRecordId);
93 requestBO.setOrderCode(orderCode); 102 requestBO.setOrderCode(orderCode);
94 - ApiResponse response = proxyPost("activity.cancelCutPriceUseRecord", url, requestBO); 103 + ApiResponse response = baseServiceCaller.proxyPost("activity.cancelCutPriceUseRecord", url, requestBO);
95 logger.info("cancelCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}", uid, cutRecordId, orderCode, response); 104 logger.info("cancelCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}", uid, cutRecordId, orderCode, response);
96 if (response != null && response.getCode() == 200) { 105 if (response != null && response.getCode() == 200) {
97 logger.info("[{}] cancelCutPriceUseRecord success,cutRecordId {}", orderCode, cutRecordId); 106 logger.info("[{}] cancelCutPriceUseRecord success,cutRecordId {}", orderCode, cutRecordId);
@@ -111,12 +120,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator @@ -111,12 +120,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
111 */ 120 */
112 public void payCutPrice(int uid, long orderCode, int cutRecordId) throws ServiceException { 121 public void payCutPrice(int uid, long orderCode, int cutRecordId) throws ServiceException {
113 logger.debug("payCutPrice by uid {},orderCode {},cutRecordId {}", uid, orderCode, cutRecordId); 122 logger.debug("payCutPrice by uid {},orderCode {},cutRecordId {}", uid, orderCode, cutRecordId);
114 - String url = erpGatewayUrl + "/erp/activity/cutPrice/payCutPrice"; 123 + String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/payCutPrice";
115 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO(); 124 CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
116 requestBO.setUserId(uid); 125 requestBO.setUserId(uid);
117 requestBO.setCutRecordId(cutRecordId); 126 requestBO.setCutRecordId(cutRecordId);
118 requestBO.setOrderCode(orderCode); 127 requestBO.setOrderCode(orderCode);
119 - ApiResponse response = proxyPost("activity.payCutPrice", url, requestBO); 128 + ApiResponse response = baseServiceCaller.proxyPost("activity.payCutPrice", url, requestBO);
120 logger.info("payCutPrice(uid:{},cutRecordId:{},orderCode:{}),result is {}", uid, cutRecordId, orderCode, response); 129 logger.info("payCutPrice(uid:{},cutRecordId:{},orderCode:{}),result is {}", uid, cutRecordId, orderCode, response);
121 if (response != null && response.getCode() == 200) { 130 if (response != null && response.getCode() == 200) {
122 logger.info("[{}] payCutPrice success,cutRecordId {}", orderCode, cutRecordId); 131 logger.info("[{}] payCutPrice success,cutRecordId {}", orderCode, cutRecordId);
@@ -9,6 +9,7 @@ import com.yohoufo.order.utils.LoggerUtils; @@ -9,6 +9,7 @@ import com.yohoufo.order.utils.LoggerUtils;
9 import org.slf4j.Logger; 9 import org.slf4j.Logger;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.beans.factory.annotation.Value; 11 import org.springframework.beans.factory.annotation.Value;
  12 +import org.springframework.stereotype.Component;
12 13
13 import java.util.Objects; 14 import java.util.Objects;
14 import java.util.concurrent.TimeUnit; 15 import java.util.concurrent.TimeUnit;
@@ -17,21 +18,33 @@ import java.util.concurrent.TimeUnit; @@ -17,21 +18,33 @@ import java.util.concurrent.TimeUnit;
17 * Created by jiexiang.wu on 2019/5/21. 18 * Created by jiexiang.wu on 2019/5/21.
18 */ 19 */
19 20
20 -public abstract class AbsServiceCaller { 21 +@Component
  22 +public class BaseServiceCaller {
21 23
22 - protected final static Logger logger = LoggerUtils.getBuyerOrderLogger(); 24 + private final static Logger logger = LoggerUtils.getBuyerOrderLogger();
23 25
24 @Autowired 26 @Autowired
25 private ServiceCaller serviceCaller; 27 private ServiceCaller serviceCaller;
26 28
27 @Value("${erp-gateway.url}") 29 @Value("${erp-gateway.url}")
28 - protected String erpGatewayUrl; 30 + private String erpGatewayUrl;
29 31
30 - protected ApiResponse proxyPost(String serviceName, String url, Object object) { 32 + @Value("${yoho.gateway.url:http://service.yoho.yohoops.org}")
  33 + private String yohoGatewayUrl;
  34 +
  35 + public String getErpGatewayUrl() {
  36 + return erpGatewayUrl;
  37 + }
  38 +
  39 + public String getYohoGatewayUrl() {
  40 + return yohoGatewayUrl;
  41 + }
  42 +
  43 + public ApiResponse proxyPost(String serviceName, String url, Object object) {
31 return doPost(serviceName, url, object); 44 return doPost(serviceName, url, object);
32 } 45 }
33 46
34 - protected ApiResponse doPost(String serviceName, String url, Object object) { 47 + public ApiResponse doPost(String serviceName, String url, Object object) {
35 try { 48 try {
36 return serviceCaller.post(serviceName, url, object, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS); 49 return serviceCaller.post(serviceName, url, object, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
37 } catch (ServiceException e) { 50 } catch (ServiceException e) {
@@ -43,7 +56,7 @@ public abstract class AbsServiceCaller { @@ -43,7 +56,7 @@ public abstract class AbsServiceCaller {
43 } 56 }
44 57
45 58
46 - protected <T> T getResultFromApiResponse(ApiResponse resp, Class<T> clazz) { 59 + public <T> T getResultFromApiResponse(ApiResponse resp, Class<T> clazz) {
47 if (resp == null) { 60 if (resp == null) {
48 throw new UfoServiceException(500, "服务器访问异常"); 61 throw new UfoServiceException(500, "服务器访问异常");
49 } 62 }
@@ -113,7 +113,7 @@ producer: @@ -113,7 +113,7 @@ producer:
113 producers: 113 producers:
114 - bean: ufoExpressInfoProducer 114 - bean: ufoExpressInfoProducer
115 115
116 - - address: 192.168.103.58:5672 116 + - address: 192.168.102.45:5672
117 username: yoho 117 username: yoho
118 password: yoho 118 password: yoho
119 producers: 119 producers: