|
|
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
|
+} |