Commit d9a1f879 by 张洪旺

coco 模板消息

parent a60313be
...@@ -196,6 +196,7 @@ public class QueryOrdersResponse { ...@@ -196,6 +196,7 @@ public class QueryOrdersResponse {
* 支付凭证 非码流水ID * 支付凭证 非码流水ID
*/ */
private String payVoucher; private String payVoucher;
/** /**
* 手机号 * 手机号
*/ */
......
...@@ -5,8 +5,12 @@ import cn.freemud.base.entity.BaseResponse; ...@@ -5,8 +5,12 @@ import cn.freemud.base.entity.BaseResponse;
import cn.freemud.entities.vo.TakeMealNoticesVO; import cn.freemud.entities.vo.TakeMealNoticesVO;
import cn.freemud.service.CallerService; import cn.freemud.service.CallerService;
import cn.freemud.utils.ResponseUtil; import cn.freemud.utils.ResponseUtil;
import com.freemud.application.sdk.api.log.ApiAnnotation;
import com.freemud.application.sdk.api.log.LogParams;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -29,7 +33,9 @@ private CallerService callerService; ...@@ -29,7 +33,9 @@ private CallerService callerService;
* 取餐通知 * 取餐通知
* @return * @return
*/ */
public BaseResponse takeMealNotices(TakeMealNoticesVO vo){ @PostMapping("/takeMealNotices")
@ApiAnnotation(logMessage = "takeMealNotices")
public BaseResponse takeMealNotices(@Validated @LogParams @RequestBody TakeMealNoticesVO vo){
return callerService.takeMealNotices(vo); return callerService.takeMealNotices(vo);
} }
......
...@@ -10,23 +10,49 @@ import java.util.List; ...@@ -10,23 +10,49 @@ import java.util.List;
public class SubscribeMessageRequest { public class SubscribeMessageRequest {
/**
* 预约单下单成功通知
*/
private BookingOrderPayedScene bookingOrderPayedScene; private BookingOrderPayedScene bookingOrderPayedScene;
/**
* 预约单取单提醒
*/
private BookingOrderPayedScene bookingOrderTakeReminderScene; private BookingOrderPayedScene bookingOrderTakeReminderScene;
/** /**
* 渠道 * 渠道
* 1 微信小程序
* 2 支付宝小程序
* 3 手机app
* 4 线下应用
* 5 字节小程序
* 6 h5
*/ */
private Integer channel; private Integer channel =1;
/**
* 配送异常提醒
*/
private DeliveryErrorReminder deliveryErrorReminder; private DeliveryErrorReminder deliveryErrorReminder;
/**拼单提醒
*
*/
private GroupBuyingStatusReminder groupBuyingStatusReminder; private GroupBuyingStatusReminder groupBuyingStatusReminder;
/**
* 即时单下单成功通知
*/
private InstantOrderPayedScene instantOrderPayedScene; private InstantOrderPayedScene instantOrderPayedScene;
/**
* 即时单取餐通知
*/
private InstantOrderPayedScene instantOrderTakeReminderScene; private InstantOrderPayedScene instantOrderTakeReminderScene;
/**
*
*/
private String messageEventType; private String messageEventType;
/** /**
...@@ -39,10 +65,23 @@ public class SubscribeMessageRequest { ...@@ -39,10 +65,23 @@ public class SubscribeMessageRequest {
*/ */
private List<String> openIdList; private List<String> openIdList;
/**
*自配送配送通知
*/
private OrderDeliveryScene orderDeliveryScene; private OrderDeliveryScene orderDeliveryScene;
/**
*
*/
private SceneCouponRequest sceneCouponExpiredRequest; private SceneCouponRequest sceneCouponExpiredRequest;
/**
* //即时单scene_instant
* //预约单:scene_appoint
* //自配送单:scene_self_delivery
* //拼单提醒:scene_group_buying
*/
private String scene;
private SceneCouponRequest sceneCouponReceiveRequest; private SceneCouponRequest sceneCouponReceiveRequest;
private SceneInviteGiftRequest sceneInviteGiftRequest; private SceneInviteGiftRequest sceneInviteGiftRequest;
......
...@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List;
/** /**
* @author freemud * @author freemud
*/ */
...@@ -25,5 +27,5 @@ public class TakeMealNoticesVO { ...@@ -25,5 +27,5 @@ public class TakeMealNoticesVO {
private Integer cupTotalNum; private Integer cupTotalNum;
@ApiModelProperty(value = "订单") @ApiModelProperty(value = "订单")
private String[] orders; private List<String> orderList;
} }
package cn.freemud.enums;
import lombok.Getter;
@Getter
public enum MessageEventTypeEnum {
INSTANT_ORDER_PAYED(30, "INSTANT_ORDER_PAYED", "即时单下单成功通知"),
BOOKING_ORDER_PAYED(31, "BOOKING_ORDER_PAYED", "预约单下单成功通知"),
SELF_DELIVERY_ORDER_PAYED(32, "SELF_DELIVERY_ORDER_PAYED", "自配送下单成功通知"),
ORDER_DELIVERY(33, "ORDER_DELIVERY", "订单配送通知"),
BOOKING_ORDER_TAKE_REMINDER(34, "BOOKING_ORDER_TAKE_REMINDER", "预约单取单通知"),
INSTANT_ORDER_TAKE_REMINDER(35, "INSTANT_ORDER_TAKE_REMINDER", "即时单取单通知"),
GROUP_BUYING_STATUS_REMINDER(36, "GROUP_BUYING_STATUS_REMINDER", "拼单提醒"),
DELIVERY_ERROR_REMINDER(37, "DELIVERY_ERROR_REMINDER", "配送异常提醒"),
;
private int code;
private String type;
private String name;
MessageEventTypeEnum(int code, String type,String name) {
this.code = code;
this.type = type;
this.name = name;
}
}
package cn.freemud.service; package cn.freemud.service;
import cn.freemud.amp.body.OrderBody;
import cn.freemud.base.entity.BaseResponse; import cn.freemud.base.entity.BaseResponse;
import cn.freemud.base.log.LogTreadLocal;
import cn.freemud.base.util.DateUtil;
import cn.freemud.constant.RedisKeyConstant; import cn.freemud.constant.RedisKeyConstant;
import cn.freemud.constant.ResponseCodeConstant;
import cn.freemud.entities.dto.GetMemberInfoByIdRequestDto;
import cn.freemud.entities.dto.GetMemberInfoByIdResponseDto;
import cn.freemud.entities.dto.ecology.BookingOrderPayedScene;
import cn.freemud.entities.dto.ecology.InstantOrderPayedScene;
import cn.freemud.entities.dto.ecology.SubscribeMessageRequest;
import cn.freemud.entities.dto.ecology.SubscribeMessageResponse;
import cn.freemud.entities.vo.TakeMealNoticesVO; import cn.freemud.entities.vo.TakeMealNoticesVO;
import cn.freemud.enums.MessageEventTypeEnum;
import cn.freemud.service.impl.CheckOrder;
import cn.freemud.service.thirdparty.CustomerClient;
import cn.freemud.service.thirdparty.EcologyAdminApplicationClient;
import cn.freemud.utils.DateTimeUtil;
import cn.freemud.utils.ResponseUtil; import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.freemud.application.sdk.api.ordercenter.request.OrderExtInfoDto;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.sdk.api.assortment.order.request.order.BaseQueryOrderRequest;
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 com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@AllArgsConstructor
@Service @Service
@Slf4j
public class CallerService { public class CallerService {
@Autowired private final RedisTemplate redisTemplate;
private RedisTemplate redisTemplate; private final EcologyAdminApplicationClient ecologyAdminApplicationClient;
private final OrderCenterSdkService orderCenterSdkService;
private final CheckOrder checkOrder;
/** /**
* 缓存 待制作杯数量 * 缓存 待制作杯数量
*
* @param vo * @param vo
*/ */
private void cacheTakeMealNotices(TakeMealNoticesVO vo){ private void cacheTakeMealNotices(TakeMealNoticesVO vo) {
String redisKey = RedisKeyConstant.notMadeGoodsNumber(vo.getPartnerId(), vo.getStoreCode()); String redisKey = RedisKeyConstant.notMadeGoodsNumber(vo.getPartnerId(), vo.getStoreCode());
redisTemplate.boundValueOps(redisKey).set(vo.getCupTotalNum(),1, TimeUnit.DAYS); redisTemplate.boundValueOps(redisKey).set(vo.getCupTotalNum(), 1, TimeUnit.DAYS);
}
/**
* pos -> 推送模板消息
* 即时单
* 预约单
*
* @param vo
* @return
*/
public BaseResponse takeMealNotices(TakeMealNoticesVO vo) {
// cacheTakeMealNotices(vo);
if (Objects.isNull(vo.getOrderList())) {
return ResponseUtil.success();
}
vo.getOrderList().stream().forEach(orderId -> {
BaseQueryOrderRequest baseQueryOrderRequest = new BaseQueryOrderRequest();
baseQueryOrderRequest.setOrderId(orderId);
baseQueryOrderRequest.setTrackingNo(LogTreadLocal.getTrackingNo());
QueryOrderByIdResponse queryOrderByIdResponse = orderCenterSdkService.queryOrderById(baseQueryOrderRequest);
QueryOrdersResponse.DataBean.OrderBean orderBean = queryOrderByIdResponse.getData();
if (Objects.isNull(orderBean)) {
return;
}
OrderExtInfoDto extInfoDto = JSONObject.parseObject(orderBean.getExtInfo(), new TypeReference<OrderExtInfoDto>() {
});
if (Objects.isNull(extInfoDto.getOpenid())) {
log.error("订单号:{},没有openId", orderId);
return;
} }
StoreResponse storeResponse = checkOrder.getStoreInfo(orderBean.getCompanyId(), orderBean.getShopId(), LogTreadLocal.getTrackingNo());
if (storeResponse.getBizVO() == null) {
log.error("订单号:{},商户号:{},没有门店信息", orderId, orderBean.getShopId());
return;
}
orderBean.setShopAddress(storeResponse.getBizVO().getAddress());
SubscribeMessageRequest subscribeMessageRequest = new SubscribeMessageRequest();
subscribeMessageRequest.setMiniAppId(extInfoDto.getAppid());
subscribeMessageRequest.setOpenIdList(Lists.newArrayList(extInfoDto.getOpenid()));
// coco order_client 2微信小程序 3支付宝小程序
subscribeMessageRequest.setChannel(orderBean.getOrderClient().equals("2") ? 1 : 2);
boolean reservationOrder = isReservationOrder(orderBean);
if (reservationOrder) {
//预约单
BookingOrderPayedScene scene = new BookingOrderPayedScene();
scene.setMerchantAddress(orderBean.getShopAddress());
scene.setMerchantName(orderBean.getShopName());
scene.setOrderNo(orderId);
scene.setOrderType(orderBean.getNewOrderType().toString());
scene.setTakeOrderTime(DateTimeUtil.getCurrentTimeStr());
subscribeMessageRequest.setBookingOrderTakeReminderScene(scene);
subscribeMessageRequest.setScene("scene_appoint");
subscribeMessageRequest.setMessageEventType(MessageEventTypeEnum.BOOKING_ORDER_TAKE_REMINDER.getType());
} else {
InstantOrderPayedScene scene = new InstantOrderPayedScene();
scene.setFriendlyTips("饮品已制作完成,请凭取单号及时到店取单哟!");
scene.setOrderType(orderBean.getNewOrderType().toString());
scene.setMerchantAddress(orderBean.getShopAddress());
scene.setMerchantName(orderBean.getShopName());
scene.setOrderNo(orderId);
subscribeMessageRequest.setInstantOrderTakeReminderScene(scene);
subscribeMessageRequest.setScene("scene_instant");
subscribeMessageRequest.setMessageEventType(MessageEventTypeEnum.INSTANT_ORDER_TAKE_REMINDER.getType());
}
SubscribeMessageResponse subscribeMessageResponse = ecologyAdminApplicationClient.subscribeMessage(subscribeMessageRequest);
if (!ResponseCodeConstant.RESPONSE_SUCCESS.equals(subscribeMessageResponse.getCode())) {
log.error("ecologyAdminApplicationClient.subscribeMessage调用失败 ,request:{},body:{}", JSON.toJSONString(subscribeMessageResponse),
JSON.toJSONString(subscribeMessageRequest));
}
});
public BaseResponse takeMealNotices(TakeMealNoticesVO vo){
cacheTakeMealNotices(vo);
//发送取餐通知消息 cc 生态
return ResponseUtil.success(); return ResponseUtil.success();
} }
/**
* 是否预约单
* true 预约单
*
* @return
*/
private boolean isReservationOrder(QueryOrdersResponse.DataBean.OrderBean orderBean) {
if (Objects.nonNull(orderBean.getGmtExpect())) {
return Boolean.TRUE;
}
return Boolean.FALSE;
}
} }
...@@ -30,7 +30,7 @@ public interface EcologyAdminApplicationClient { ...@@ -30,7 +30,7 @@ public interface EcologyAdminApplicationClient {
@PostMapping(value = "/ecology/api/getAuthorizerAccessToken") @PostMapping(value = "/ecology/api/getAuthorizerAccessToken")
GetTokenResponseDto getAuthorizerAccessToken(@RequestBody GetAuthorizerRequestDto request); GetTokenResponseDto getAuthorizerAccessToken(@RequestBody GetAuthorizerRequestDto request);
@PostMapping(value = "/ecology/api/subscribeMessage/send") @PostMapping(value = "/ecology/api/subscribeMessage/send")
SubscribeMessageResponse subscribeMessage(SubscribeMessageRequest request); SubscribeMessageResponse subscribeMessage(SubscribeMessageRequest request);
} }
...@@ -277,4 +277,6 @@ public class OrderInfoReqs { ...@@ -277,4 +277,6 @@ public class OrderInfoReqs {
*/ */
private List<OrderPayItemReqs> orderPayItemCreateReqList; private List<OrderPayItemReqs> orderPayItemCreateReqList;
private String appId;
} }
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