Commit 22d88483 by huvchao@126.com

订单配送信息变化时推送到mq

parent bcffcadc
package cn.freemud.amp.service;
import cn.freemud.amqp.MQMessage;
import cn.freemud.amqp.MQService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -12,15 +13,14 @@ public class ProduceMQService {
@Autowired
private MQService mqService;
private static final String routeKey = "test";
private static final String exchangeName = "test";
private static final String exchangeName = "topic-Exchange";
private static final String routeKey = "open-platform-order-delivery-routing-key";
/**
* 发送配送状态变更信息
* @param body
*/
public void sendOfDeliveryInfo(String body) {
public void sendOfDeliveryInfo(MQMessage body) {
mqService.convertAndSend(exchangeName, routeKey, body);
}
......
package cn.freemud.service.delivery;
import cn.freemud.amp.service.ProduceMQService;
import cn.freemud.amqp.Header;
import cn.freemud.amqp.MQAction;
import cn.freemud.amqp.MQMessage;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.entities.dto.delivery.CallbackUrlRequestDto;
import cn.freemud.entities.dto.pos.PosBaseRequestDto;
......@@ -109,11 +112,11 @@ public class ThirdDeliveryServiceImpl implements ThirdDeliveryService {
sendPosService(deliveryStatus,posBaseRequestDto);
}
// todo 发送配送信息到mq
// 订单配送状态变化时发送到MQ
if (DeliveryStatus.checkDeliveryStatueForPlatform(deliveryStatus)) {
String deliverDesc = DeliveryStatus.getDeliveryStatusByCode(deliveryStatus).getDesc();
Map deliveryMap = ImmutableMap.of("deliveryStatus", deliveryStatus, "orderCode", request.getOrderId(), "", request);
produceMQService.sendOfDeliveryInfo(deliveryMap.toString());
Header header = new Header(MQAction.UPDATE.getAction(), "delivery/callbackUrl", request.getOrderId(), "open-platform-order-delivery-queue");
MQMessage<CallbackUrlRequestDto> message = new MQMessage<>(header, request);
produceMQService.sendOfDeliveryInfo(message);
}
// else {
// return ResponseUtil.error(ResponseResult.SYSTEM_ERROR.getCode(), "订单回调状态有误");
......
......@@ -30,6 +30,37 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.freemud</groupId>
<artifactId>assortment-ordercenter-sdk</artifactId>
<version>1.1.5.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.freemud.application.service.sdk</groupId>
<artifactId>storecenter-sdk</artifactId>
<version>2.1.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.freemud.application.service.sdk</groupId>
<artifactId>deliverycenter-sdk</artifactId>
<version>1.1.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.freemud.commons</groupId>
<artifactId>commons-base</artifactId>
<version>1.5.1-release</version>
<scope>provided</scope>
</dependency>
<!--freemud类库依赖-->
<dependency>
<groupId>cn.freemud.commons</groupId>
<artifactId>commons-base</artifactId>
</dependency>
</dependencies>
</project>
package cn.freemud.management.enums;
import com.google.common.collect.Lists;
import java.util.List;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @version V1.5.1
* @Title: DeliveryStatus
* @Package cn.freemud.enums
* @Description: 简单描述下这个类是做什么用的
* @author: hang.chai
* @date: 2018/12/12 14:57
* @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
public enum DeliveryStatus {
WATINGORDER(0,"待接单"),
SYSTEMGETORDER(1,"系统接单"),
ALLOTRIDER(2,"分配骑手"),
RIDERARRIVESTORE(3,"骑手到店"),
RIDERGETMEAL(4,"骑手取餐"),
RIDERSTARTDELIVERY(5,"开始配送"),
DELIVERYARRIVED(6,"运单送达"),
DELIVERYERROR(7,"运单异常"),
DELIVERYCANCEL(8,"运单取消");
private int code;
private String desc;
DeliveryStatus(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static DeliveryStatus getDeliveryStatusByCode(int code) {
for (DeliveryStatus obj : values()) {
if (obj.code == code) {
return obj;
}
}
return null;
}
public static boolean checkDeliveryStatueForPlatform(int status) {
DeliveryStatus deliveryStatus = DeliveryStatus.getDeliveryStatusByCode(status);
if (null == deliveryStatus) return false;
List<DeliveryStatus> targetList = Lists.newArrayList(DeliveryStatus.ALLOTRIDER,
DeliveryStatus.RIDERGETMEAL,
DeliveryStatus.RIDERSTARTDELIVERY,
DeliveryStatus.DELIVERYARRIVED,
DeliveryStatus.DELIVERYERROR,
DeliveryStatus.DELIVERYCANCEL
);
if (targetList.contains(deliveryStatus)) {
return true;
}
return false;
}
}
package cn.freemud.management.service;
import cn.freemud.management.enums.DeliveryStatus;
import com.freemud.sdk.api.assortment.order.request.order.AssortmentUpdateDeliveryAbnormalRequest;
import com.freemud.sdk.api.assortment.order.request.order.BaseQueryOrderRequest;
import com.freemud.sdk.api.assortment.order.request.order.UpdateDeliveryInfoByIdRequest;
import com.freemud.sdk.api.assortment.order.response.order.QueryOrderByIdResponse;
import com.freemud.sdk.api.assortment.order.response.order.QueryOrdersResponse;
import com.freemud.sdk.api.assortment.order.service.OrderCenterSdkService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class OrderBaseService {
@Autowired
private OrderCenterSdkService orderCenterSdkService;
public QueryOrdersResponse.DataBean.OrderBean getByOrderCode(String orderCode) {
try {
BaseQueryOrderRequest queryRequest = new BaseQueryOrderRequest();
queryRequest.setOrderId(orderCode);
QueryOrderByIdResponse response = orderCenterSdkService.queryOrderById(queryRequest);
if (response.getErrcode() == 100) {
return response.getData();
}
return response.getData();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
/**
* 创建配送单一车 -> 更新订单为异常单
*
* @param partnerId
* @param orderCode
* @param deliveryId
*/
public void updateDeliveryAbnormal(String partnerId, String orderCode, String deliveryId, String operator) {
AssortmentUpdateDeliveryAbnormalRequest request = AssortmentUpdateDeliveryAbnormalRequest.builder()
.abnormalDesc("配送异常")
.deliveryId(deliveryId)
.orderCode(orderCode)
.partnerId(partnerId)
.operator(StringUtils.isNotBlank(operator) ? operator : "sys")
.build();
orderCenterSdkService.updateDeliveryAbnormal(request);
}
/**
* 创建配送单成功后 -> 更新订单配送信息
*
* @param orderCode
* @param deliveryId
*/
public void updateDeliverySuccess(String orderCode, String deliveryId, String operator) {
// 创建配送单成功
UpdateDeliveryInfoByIdRequest updateDeliveryInfoByIdRequest = new UpdateDeliveryInfoByIdRequest();
updateDeliveryInfoByIdRequest.setDeliveryId(deliveryId);
updateDeliveryInfoByIdRequest.setOrderId(orderCode);
updateDeliveryInfoByIdRequest.setOrderSubState(DeliveryStatus.WATINGORDER.getCode());
operator = StringUtils.isNotBlank(operator) ? operator : "sys";
updateDeliveryInfoByIdRequest.setOperator(operator);
orderCenterSdkService.updateDeliveryInfoById(updateDeliveryInfoByIdRequest);
}
}
package cn.freemud.management.service;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.base.log.LogTreadLocal;
import cn.freemud.management.util.CommonResp;
import com.freemud.application.sdk.api.deliverycenter.dto.CreateDeliveryOrderRequestDto;
import com.freemud.application.sdk.api.deliverycenter.response.CreateDeliveryOrderResponseDto;
import com.freemud.application.sdk.api.deliverycenter.service.DeliveryService;
import com.freemud.application.sdk.api.storecenter.request.StoreInfoRequest;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import com.freemud.sdk.api.assortment.order.enums.OrderSourceType;
import com.freemud.sdk.api.assortment.order.response.order.QueryOrdersResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class OrderDeliveryService {
@Autowired
private StoreCenterService storeCenterService;
@Autowired
private DeliveryService deliveryService;
@Autowired
private OrderBaseService orderBaseService;
@Value("${saas.order.delivery.callBackUrl}")
private String deliveryCallBackUrl;
private int SUCCESS = 100;
private String delivery_type_self = "self";
public BaseResponse createDelivery(String orderCode) {
QueryOrdersResponse.DataBean.OrderBean orderBean = orderBaseService.getByOrderCode(orderCode);
return CommonResp.success(this.createDelivery(orderBean));
}
public Boolean createDelivery(QueryOrdersResponse.DataBean.OrderBean orderBean) {
//判断外卖单
if (1 != orderBean.getType()) {
return true;
}
if (!orderBean.getSource().equalsIgnoreCase(OrderSourceType.SAAS.getCode())) {
return true;
}
//配送信息为空,则不创建配送单
if (orderBean.getAddInfo() == null || orderBean.getAddInfo().getDeliveryType() == null) {
return true;
}
//自配送不创建配送单
if (delivery_type_self.equalsIgnoreCase(orderBean.getAddInfo().getDeliveryType())) {
return true;
}
StoreInfoRequest storeInfoRequestDto = new StoreInfoRequest(orderBean.getCompanyId(), orderBean.getShopId());
StoreResponse storeInfo = storeCenterService.getStoreInfo(storeInfoRequestDto, LogTreadLocal.getTrackingNo());
if (SUCCESS != storeInfo.getStatusCode() || storeInfo.getBizVO() == null) {
return false;
}
// 调用配送系统创建配送单
CreateDeliveryOrderRequestDto requestDto = buildDeliveryOrderRequestDto(orderBean, storeInfo, deliveryCallBackUrl);
CreateDeliveryOrderResponseDto deliveryResponse = deliveryService.deliveryOrderAdd(requestDto, LogTreadLocal.getTrackingNo());
//创建配送单失败,更新订单为异常单
if (deliveryResponse == null || SUCCESS != deliveryResponse.getCode() || deliveryResponse.getData() == null) {
String deliveryId = deliveryResponse != null && deliveryResponse.getData() != null ? deliveryResponse.getData().getDeliveryId() : "";
orderBaseService.updateDeliveryAbnormal(orderBean.getCompanyId(), orderBean.getOid(), deliveryId, "");
return false;
}
// 创建配送单成功
orderBaseService.updateDeliverySuccess(orderBean.getOid(), deliveryResponse.getData().getDeliveryId(), "");
return true;
}
/**
* 创建配送单请求对象
*
* @param order
* @param storeInfo
* @param deliveryCallBackUrl
* @return
*/
private CreateDeliveryOrderRequestDto buildDeliveryOrderRequestDto(QueryOrdersResponse.DataBean.OrderBean order
, StoreResponse storeInfo, String deliveryCallBackUrl) {
CreateDeliveryOrderRequestDto deliveryOrderRequestDto = new CreateDeliveryOrderRequestDto();
deliveryOrderRequestDto.setDepatchWeight(new BigDecimal(1));
deliveryOrderRequestDto.setSerialNumber(order.getDaySeq().toString());
deliveryOrderRequestDto.setOrderId(order.getOid());
deliveryOrderRequestDto.setOrderRemark(order.getRemark());
deliveryOrderRequestDto.setOrderTotalAmount(order.getAmount().intValue());
deliveryOrderRequestDto.setOrderActualAmount(order.getAmount().intValue());
deliveryOrderRequestDto.setPartnerId(order.getCompanyId());
deliveryOrderRequestDto.setOrderChannel(order.getSource());
deliveryOrderRequestDto.setStoreId(storeInfo.getBizVO().getStoreId());
deliveryOrderRequestDto.setStoreCode(storeInfo.getBizVO().getStoreCode());
StringBuffer address = new StringBuffer(storeInfo.getBizVO().getCity())
.append(storeInfo.getBizVO().getProvince())
.append(storeInfo.getBizVO().getRegion())
.append(storeInfo.getBizVO().getAddress());
deliveryOrderRequestDto.setStoreAddress(address.toString());
deliveryOrderRequestDto.setStoreLng(new BigDecimal(storeInfo.getBizVO().getLongitude()));
deliveryOrderRequestDto.setStoreLat(new BigDecimal(storeInfo.getBizVO().getLatitude()));
deliveryOrderRequestDto.setStorePhone(storeInfo.getBizVO().getPhone());
deliveryOrderRequestDto.setStoreName(order.getShopName());
deliveryOrderRequestDto.setCityName(storeInfo.getBizVO().getCity());
deliveryOrderRequestDto.setReceiverName(order.getUserName());
deliveryOrderRequestDto.setReceiverPrimaryPhone(order.getPhone());
deliveryOrderRequestDto.setReceiverAddress(order.getAddress());
deliveryOrderRequestDto.setReceiverLng(new BigDecimal(order.getLongitude()));
deliveryOrderRequestDto.setReceiverLat(new BigDecimal(order.getLatitude()));
deliveryOrderRequestDto.setOrderTime(new Date(order.getGmtCreate()));
deliveryOrderRequestDto.setCallbackUrl(deliveryCallBackUrl);
// 预约单预计送到时间
deliveryOrderRequestDto.setExpectTime(new Date(order.getGmtCreate()));
deliveryOrderRequestDto.setIsPre(order.getGmtExpect() != null ? 1 : 0);
List<CreateDeliveryOrderRequestDto.DeliveryProductInfo> productInfos = new ArrayList<>();
order.getProductList().forEach(productList -> {
if (productList.getPrice() > 0) {
CreateDeliveryOrderRequestDto.DeliveryProductInfo deliveryProductInfo = new CreateDeliveryOrderRequestDto.DeliveryProductInfo();
deliveryProductInfo.setProductCode(productList.getProductId());
deliveryProductInfo.setProductName(productList.getProductName());
deliveryProductInfo.setProductNumber(productList.getNumber());
deliveryProductInfo.setProductPrice(productList.getPrice().intValue());
productInfos.add(deliveryProductInfo);
}
});
deliveryOrderRequestDto.setProductInfos(productInfos);
return deliveryOrderRequestDto;
}
}
package cn.freemud.management.util;
import cn.freemud.base.constant.Version;
import cn.freemud.base.entity.BaseResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class CommonResp<T> extends BaseResponse<T> {
public CommonResp() {
super();
}
public CommonResp(String ver, ResponseCodeEnum codeEnum) {
super(ver, codeEnum.code, codeEnum.msg, (T) new JSONObject());
}
public CommonResp(String ver, ResponseCodeEnum codeEnum, T result) {
super(ver, codeEnum.code, codeEnum.msg, result);
}
public CommonResp(ResponseCodeEnum codeEnum, T result) {
super(Version.VERSION_1, codeEnum.code, codeEnum.msg, result);
}
public CommonResp(ResponseCodeEnum codeEnum) {
super(Version.VERSION_1, codeEnum.code, codeEnum.msg, (T) new JSONObject());
}
public CommonResp(String code, String message) {
super(Version.VERSION_1, code, message, (T) new JSONObject());
}
public static CommonResp success() {
return new CommonResp(ResponseCodeEnum.SUCCESS);
}
public static CommonResp success(Object data) {
return new CommonResp(ResponseCodeEnum.SUCCESS, data);
}
public static CommonResp fail() {
return new CommonResp(ResponseCodeEnum.FAILURE);
}
public static CommonResp fail(Object data) {
return new CommonResp(ResponseCodeEnum.FAILURE, data);
}
}
package cn.freemud.management.util;
public enum ResponseCodeEnum {
SUCCESS("100", "成功"),
FAILURE("1001", "失败"),
;
public String code;
public String msg;
ResponseCodeEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
}
package cn.freemud.service;
public class OrderService {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment