Authored by wujiexiang

Merge branch 'dev-fofp' into test6.9.8

... ... @@ -11,6 +11,7 @@ import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
import com.yohoufo.order.model.bo.ActivityBo;
import com.yohoufo.order.service.proxy.BaseServiceCaller;
import com.yohoufo.order.service.proxy.BargainProxyService;
import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -40,7 +41,10 @@ public class BuyerOrderChangeBusinessPostProcessor {
private BargainProxyService bargainProxyService;
@Resource( name = "ufoExpressInfoProducer")
private YhProducer ufoExpressInfoProducer;
private YhProducer commonProducer;
@Autowired
private BaseServiceCaller baseServiceCaller;
//业务处理器
private List<BusinessProcessor> processors = Lists.newArrayList(
... ... @@ -188,7 +192,6 @@ public class BuyerOrderChangeBusinessPostProcessor {
}
}
/**
* 下单通知
*/
... ... @@ -197,12 +200,26 @@ public class BuyerOrderChangeBusinessPostProcessor {
@Override
public void create(BusinessProcessorContext context) {
//1.mq通知
BuyerOrder buyerOrder = context.buyerOrder;
int uid = buyerOrder.getUid();
//1.清理缓存yohobuy_gateway新客缓存
logger.info("[{}] notify resource to clear user cache", uid);
try {
String url = baseServiceCaller.getYohoGatewayUrl() + "?method=app.resources.clearUserCache&&client_type=h5&uid=" + uid;
baseServiceCaller.proxyPost("app.resources.clearUserCache", url, null);
} catch (Exception ex) {
logger.error("clear user cache for resource,uid:{}", uid, ex);
}
//2.
logger.info("[{}] notify fofp to consume buyer order", uid);
JSONObject jsonObject = new JSONObject();
jsonObject.put("uid", buyerOrder.getUid());
jsonObject.put("uid", uid);
jsonObject.put("orderCode", buyerOrder.getOrderCode());
jsonObject.put("createTime", buyerOrder.getCreateTime());
ufoExpressInfoProducer.send(TOPIC, jsonObject);
commonProducer.send(TOPIC, jsonObject);
}
}
... ...
... ... @@ -8,8 +8,11 @@ import com.yoho.core.transaction.annoation.TxCompensateArgs;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.Data;
import lombok.ToString;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
... ... @@ -22,7 +25,13 @@ import java.util.Objects;
@Component
public class BargainProxyService extends AbsServiceCaller implements Compensator {
public class BargainProxyService implements Compensator {
private final static Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private BaseServiceCaller baseServiceCaller;
/**
* 获取用户砍价商品的最终价格
* 所有的业务校验都在activity服务端实现,如活动时间、是否达成
... ... @@ -33,12 +42,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
*/
public CutDownPriceProductOrderBo queryCutPriceProductForOrder(int uid, int cutRecordId) {
logger.info("getActivityPrice by uid {},cutRecordId {}", uid, cutRecordId);
String url = erpGatewayUrl + "/erp/activity/cutPrice/queryCutPriceProductForOrder";
String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/queryCutPriceProductForOrder";
CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
requestBO.setUserId(uid);
requestBO.setCutRecordId(cutRecordId);
ApiResponse response = proxyPost("activity.queryCutPriceProductForOrder", url, requestBO);
CutDownPriceProductOrderBo cutDownPriceProductOrderBo = getResultFromApiResponse(response, CutDownPriceProductOrderBo.class);
ApiResponse response = baseServiceCaller.proxyPost("activity.queryCutPriceProductForOrder", url, requestBO);
CutDownPriceProductOrderBo cutDownPriceProductOrderBo = baseServiceCaller.getResultFromApiResponse(response, CutDownPriceProductOrderBo.class);
if (Objects.isNull(cutDownPriceProductOrderBo)) {
logger.warn("can't getActivityPrice by uid {},cutRecordId {}", uid, cutRecordId);
throw new UfoServiceException(500, "未查询到用户砍价商品信息");
... ... @@ -59,12 +68,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
public void addCutPriceUseRecord(@TxCompensateArgs("uid") int uid, @TxCompensateArgs("orderCode") long orderCode,
@TxCompensateArgs("cutRecordId") int cutRecordId) throws ServiceException {
logger.debug("addCutPriceUseRecord by uid {},cutRecordId {},orderCode {}", uid, cutRecordId, orderCode);
String url = erpGatewayUrl + "/erp/activity/cutPrice/addCutPriceUseRecord";
String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/addCutPriceUseRecord";
CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
requestBO.setUserId(uid);
requestBO.setCutRecordId(cutRecordId);
requestBO.setOrderCode(orderCode);
ApiResponse response = proxyPost("activity.addCutPriceUseRecord", url, requestBO);
ApiResponse response = baseServiceCaller.proxyPost("activity.addCutPriceUseRecord", url, requestBO);
logger.info("addCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}",
uid, cutRecordId, orderCode, response);
if (response == null || response.getCode() != 200) {
... ... @@ -86,12 +95,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
*/
public void cancelCutPriceUseRecord(int uid, long orderCode, int cutRecordId) throws ServiceException {
logger.debug("cancelCutPriceUseRecord by uid {},orderCode {},cutRecordId {}", uid, orderCode, cutRecordId);
String url = erpGatewayUrl + "/erp/activity/cutPrice/cancelCutPriceUseRecord";
String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/cancelCutPriceUseRecord";
CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
requestBO.setUserId(uid);
requestBO.setCutRecordId(cutRecordId);
requestBO.setOrderCode(orderCode);
ApiResponse response = proxyPost("activity.cancelCutPriceUseRecord", url, requestBO);
ApiResponse response = baseServiceCaller.proxyPost("activity.cancelCutPriceUseRecord", url, requestBO);
logger.info("cancelCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}", uid, cutRecordId, orderCode, response);
if (response != null && response.getCode() == 200) {
logger.info("[{}] cancelCutPriceUseRecord success,cutRecordId {}", orderCode, cutRecordId);
... ... @@ -111,12 +120,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
*/
public void payCutPrice(int uid, long orderCode, int cutRecordId) throws ServiceException {
logger.debug("payCutPrice by uid {},orderCode {},cutRecordId {}", uid, orderCode, cutRecordId);
String url = erpGatewayUrl + "/erp/activity/cutPrice/payCutPrice";
String url = baseServiceCaller.getErpGatewayUrl() + "/erp/activity/cutPrice/payCutPrice";
CutPriceHelpUserRequestBO requestBO = new CutPriceHelpUserRequestBO();
requestBO.setUserId(uid);
requestBO.setCutRecordId(cutRecordId);
requestBO.setOrderCode(orderCode);
ApiResponse response = proxyPost("activity.payCutPrice", url, requestBO);
ApiResponse response = baseServiceCaller.proxyPost("activity.payCutPrice", url, requestBO);
logger.info("payCutPrice(uid:{},cutRecordId:{},orderCode:{}),result is {}", uid, cutRecordId, orderCode, response);
if (response != null && response.getCode() == 200) {
logger.info("[{}] payCutPrice success,cutRecordId {}", orderCode, cutRecordId);
... ...
... ... @@ -9,6 +9,7 @@ import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
... ... @@ -17,21 +18,33 @@ import java.util.concurrent.TimeUnit;
* Created by jiexiang.wu on 2019/5/21.
*/
public abstract class AbsServiceCaller {
@Component
public class BaseServiceCaller {
protected final static Logger logger = LoggerUtils.getBuyerOrderLogger();
private final static Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private ServiceCaller serviceCaller;
@Value("${erp-gateway.url}")
protected String erpGatewayUrl;
private String erpGatewayUrl;
protected ApiResponse proxyPost(String serviceName, String url, Object object) {
@Value("${yoho.gateway.url:http://service.yoho.yohoops.org}")
private String yohoGatewayUrl;
public String getErpGatewayUrl() {
return erpGatewayUrl;
}
public String getYohoGatewayUrl() {
return yohoGatewayUrl;
}
public ApiResponse proxyPost(String serviceName, String url, Object object) {
return doPost(serviceName, url, object);
}
protected ApiResponse doPost(String serviceName, String url, Object object) {
public ApiResponse doPost(String serviceName, String url, Object object) {
try {
return serviceCaller.post(serviceName, url, object, ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
} catch (ServiceException e) {
... ... @@ -43,7 +56,7 @@ public abstract class AbsServiceCaller {
}
protected <T> T getResultFromApiResponse(ApiResponse resp, Class<T> clazz) {
public <T> T getResultFromApiResponse(ApiResponse resp, Class<T> clazz) {
if (resp == null) {
throw new UfoServiceException(500, "服务器访问异常");
}
... ...
... ... @@ -113,7 +113,7 @@ producer:
producers:
- bean: ufoExpressInfoProducer
- address: 192.168.103.58:5672
- address: 192.168.102.45:5672
username: yoho
password: yoho
producers:
... ...