Authored by wujiexiang

UFO求购消息通知

@@ -25,11 +25,12 @@ @@ -25,11 +25,12 @@
25 13、限定商品发售通知,UFO更低出售价提醒 2019-03-21 ADD BY LM 1.1.3 25 13、限定商品发售通知,UFO更低出售价提醒 2019-03-21 ADD BY LM 1.1.3
26 14、UFO卖家取消和平台鉴定不通过交易关闭提醒 2019-04-24 ADD BY LM 1.1.4 26 14、UFO卖家取消和平台鉴定不通过交易关闭提醒 2019-04-24 ADD BY LM 1.1.4
27 15、UFO交易相关七个场景提醒 2019-05-08 ADD BY LM 1.1.5 27 15、UFO交易相关七个场景提醒 2019-05-08 ADD BY LM 1.1.5
  28 + 16、UFO求购相关消息提醒 2019-10-08
28 --> 29 -->
29 <groupId>com.yoho.dsf</groupId> 30 <groupId>com.yoho.dsf</groupId>
30 <artifactId>yoho-message-sdk</artifactId> 31 <artifactId>yoho-message-sdk</artifactId>
31 <name>yoho-message-sdk</name> 32 <name>yoho-message-sdk</name>
32 - <version>1.1.5-SNAPSHOT</version> 33 + <version>1.1.6-SNAPSHOT</version>
33 <packaging>jar</packaging> 34 <packaging>jar</packaging>
34 35
35 <dependencies> 36 <dependencies>
  1 +package com.yoho.message.sdk.service.ufo;
  2 +
  3 +import com.yoho.message.sdk.common.handler.MessageCenterMqHandler;
  4 +import com.yoho.message.sdk.common.model.MessageCenterCommonEvent;
  5 +import com.yoho.message.sdk.common.model.SendMessageRspBo;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.Arrays;
  12 +import java.util.Collections;
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +
  16 +/**
  17 + * ufo 求购 相关通知
  18 + */
  19 +@Service
  20 +public class UFOBidMessageService {
  21 +
  22 + private Logger logger = LoggerFactory.getLogger(getClass());
  23 +
  24 + @Autowired
  25 + private MessageCenterMqHandler messageCenterMqHandler;
  26 +
  27 + /**
  28 + * 发送消息
  29 + *
  30 + * @param uid
  31 + * @param messageScene
  32 + * @param parameters
  33 + * @return
  34 + */
  35 + public SendMessageRspBo sendMessage(String uid, Scene messageScene, Map<String, Object> parameters) {
  36 + logger.info("in sendMessage,uid:{},messageScene:{},parameters:{}", uid, messageScene, parameters);
  37 + //校验参数
  38 + messageScene.validateParameters(parameters);
  39 + MessageCenterCommonEvent messageCenterCommonEvent = createMessageCenterCommonEvent(messageScene.getSceneName(), uid, 0, uid);
  40 + //添加参数
  41 + parameters.forEach((key, value) -> messageCenterCommonEvent.putInParams(key, value));
  42 + messageCenterMqHandler.sendMessageToMq(messageCenterCommonEvent);
  43 + return new SendMessageRspBo(200, "SUCCESS");
  44 + }
  45 +
  46 + private MessageCenterCommonEvent createMessageCenterCommonEvent(String sendScene, String sendSceneKey, int miniappType, String uid) {
  47 + List<String> uids = Collections.singletonList(uid);
  48 + return new MessageCenterCommonEvent(sendScene, sendSceneKey, miniappType, uids);
  49 + }
  50 +
  51 + public static enum Scene {
  52 + //支付定金
  53 + UFO_BUYER_DEPOSIT_PAY_FINISHED("UFO_BUYER_DEPOSIT_PAY_FINISHED", new String[]{"productName", "sizeName", "productCode"}),
  54 + //下架成功
  55 + UFO_BUYER_CLOSE_BID("UFO_BUYER_CLOSE_BID", new String[]{"productName", "sizeName", "productCode", "orderCode"}),
  56 + //求购超时
  57 + UFO_SYSTEM_CLOSE_BID("UFO_SYSTEM_CLOSE_BID", new String[]{"productName", "sizeName", "productCode", "orderCode"}),
  58 + //平台下架
  59 + UFO_PLATFORM_CLOSE_BID("UFO_PLATFORM_CLOSE_BID", new String[]{"productName", "sizeName", "productCode", "orderCode"}),
  60 + //求购成功
  61 + UFO_BID_SUCCESS("UFO_BID_SUCCESS", new String[]{"productName", "sizeName", "productCode", "orderCode","goodsPrice"}),
  62 + //买家取消支付
  63 + UFO_BUYER_BID_CANCEL_PAY("UFO_BUYER_BID_CANCEL_PAY", new String[]{"productName", "sizeName", "productCode", "orderCode","goodsPrice"}),
  64 + //买家支付超时
  65 + UFO_BUYER_BID_PAY_TIMEOUT("UFO_BUYER_BID_PAY_TIMEOUT", new String[]{"productName", "sizeName", "productCode", "orderCode","goodsPrice"}),
  66 + //买家支付提醒
  67 + UFO_BUYER_BID_PAY_REMINDER("UFO_BUYER_BID_PAY_REMINDER", new String[]{"productName", "sizeName", "productCode", "orderCode","remainingHour"});
  68 +
  69 + //对应message_scene_def中的send_scene
  70 + private String sceneName;
  71 +
  72 + //需要的参数名称
  73 + private String[] parameterNames;
  74 +
  75 + Scene(String sceneName, String[] parameterNames) {
  76 + this.sceneName = sceneName;
  77 + this.parameterNames = parameterNames;
  78 + }
  79 +
  80 + public String getSceneName() {
  81 + return sceneName;
  82 + }
  83 +
  84 + public void validateParameters(Map<String, Object> parameters) {
  85 + if (parameterNames == null || parameterNames.length == 0) {
  86 + return;
  87 + }
  88 +
  89 + Arrays.stream(parameterNames).forEach(name -> {
  90 + Object value = parameters.get(name);
  91 + if (value == null) {
  92 + throw new IllegalArgumentException("parameter value is null for name:" + name + " in scene:" + getSceneName());
  93 + }
  94 + });
  95 + }
  96 + }
  97 +}
  1 +package com.yoho.message.sdk.test;
  2 +
  3 +import com.yoho.message.sdk.service.ufo.UFOBidMessageService;
  4 +import org.junit.Test;
  5 +import org.junit.runner.RunWith;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.test.context.ContextConfiguration;
  8 +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  9 +
  10 +import java.util.HashMap;
  11 +import java.util.Map;
  12 +import java.util.concurrent.TimeUnit;
  13 +
  14 +import static com.yoho.message.sdk.service.ufo.UFOBidMessageService.Scene.*;
  15 +
  16 +@RunWith(SpringJUnit4ClassRunner.class)
  17 +@ContextConfiguration(locations = { "classpath*:META-INF/spring/test-message-sdk-*.xml" })
  18 +public class UFOBidMessageServiceTest {
  19 +
  20 + @Autowired
  21 + private UFOBidMessageService ufoBidMessageService;
  22 +
  23 + String uid = "500031116";
  24 +
  25 + @Test
  26 + public void test_ufo_buyer_deposit_pay_finished() throws Exception{
  27 + Map<String,Object> parameters = new HashMap<>();
  28 + parameters.put("productName","test");
  29 + parameters.put("sizeName","35");
  30 + parameters.put("productCode","XJ123456");
  31 + ufoBidMessageService.sendMessage(uid, UFO_BUYER_DEPOSIT_PAY_FINISHED, parameters);
  32 +
  33 + TimeUnit.SECONDS.sleep(100);
  34 + }
  35 +}