Authored by wujiexiang

UFO求购消息通知

... ... @@ -25,11 +25,12 @@
13、限定商品发售通知,UFO更低出售价提醒 2019-03-21 ADD BY LM 1.1.3
14、UFO卖家取消和平台鉴定不通过交易关闭提醒 2019-04-24 ADD BY LM 1.1.4
15、UFO交易相关七个场景提醒 2019-05-08 ADD BY LM 1.1.5
16、UFO求购相关消息提醒 2019-10-08
-->
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-message-sdk</artifactId>
<name>yoho-message-sdk</name>
<version>1.1.5-SNAPSHOT</version>
<version>1.1.6-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
... ...
package com.yoho.message.sdk.service.ufo;
import com.yoho.message.sdk.common.handler.MessageCenterMqHandler;
import com.yoho.message.sdk.common.model.MessageCenterCommonEvent;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* ufo 求购 相关通知
*/
@Service
public class UFOBidMessageService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private MessageCenterMqHandler messageCenterMqHandler;
/**
* 发送消息
*
* @param uid
* @param messageScene
* @param parameters
* @return
*/
public SendMessageRspBo sendMessage(String uid, Scene messageScene, Map<String, Object> parameters) {
logger.info("in sendMessage,uid:{},messageScene:{},parameters:{}", uid, messageScene, parameters);
//校验参数
messageScene.validateParameters(parameters);
MessageCenterCommonEvent messageCenterCommonEvent = createMessageCenterCommonEvent(messageScene.getSceneName(), uid, 0, uid);
//添加参数
parameters.forEach((key, value) -> messageCenterCommonEvent.putInParams(key, value));
messageCenterMqHandler.sendMessageToMq(messageCenterCommonEvent);
return new SendMessageRspBo(200, "SUCCESS");
}
private MessageCenterCommonEvent createMessageCenterCommonEvent(String sendScene, String sendSceneKey, int miniappType, String uid) {
List<String> uids = Collections.singletonList(uid);
return new MessageCenterCommonEvent(sendScene, sendSceneKey, miniappType, uids);
}
public static enum Scene {
//支付定金
UFO_BUYER_DEPOSIT_PAY_FINISHED("UFO_BUYER_DEPOSIT_PAY_FINISHED", new String[]{"productName", "sizeName", "productCode"}),
//下架成功
UFO_BUYER_CLOSE_BID("UFO_BUYER_CLOSE_BID", new String[]{"productName", "sizeName", "productCode", "orderCode"}),
//求购超时
UFO_SYSTEM_CLOSE_BID("UFO_SYSTEM_CLOSE_BID", new String[]{"productName", "sizeName", "productCode", "orderCode"}),
//平台下架
UFO_PLATFORM_CLOSE_BID("UFO_PLATFORM_CLOSE_BID", new String[]{"productName", "sizeName", "productCode", "orderCode"}),
//求购成功
UFO_BID_SUCCESS("UFO_BID_SUCCESS", new String[]{"productName", "sizeName", "productCode", "orderCode","goodsPrice"}),
//买家取消支付
UFO_BUYER_BID_CANCEL_PAY("UFO_BUYER_BID_CANCEL_PAY", new String[]{"productName", "sizeName", "productCode", "orderCode","goodsPrice"}),
//买家支付超时
UFO_BUYER_BID_PAY_TIMEOUT("UFO_BUYER_BID_PAY_TIMEOUT", new String[]{"productName", "sizeName", "productCode", "orderCode","goodsPrice"}),
//买家支付提醒
UFO_BUYER_BID_PAY_REMINDER("UFO_BUYER_BID_PAY_REMINDER", new String[]{"productName", "sizeName", "productCode", "orderCode","remainingHour"});
//对应message_scene_def中的send_scene
private String sceneName;
//需要的参数名称
private String[] parameterNames;
Scene(String sceneName, String[] parameterNames) {
this.sceneName = sceneName;
this.parameterNames = parameterNames;
}
public String getSceneName() {
return sceneName;
}
public void validateParameters(Map<String, Object> parameters) {
if (parameterNames == null || parameterNames.length == 0) {
return;
}
Arrays.stream(parameterNames).forEach(name -> {
Object value = parameters.get(name);
if (value == null) {
throw new IllegalArgumentException("parameter value is null for name:" + name + " in scene:" + getSceneName());
}
});
}
}
}
... ...
package com.yoho.message.sdk.test;
import com.yoho.message.sdk.service.ufo.UFOBidMessageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static com.yoho.message.sdk.service.ufo.UFOBidMessageService.Scene.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:META-INF/spring/test-message-sdk-*.xml" })
public class UFOBidMessageServiceTest {
@Autowired
private UFOBidMessageService ufoBidMessageService;
String uid = "500031116";
@Test
public void test_ufo_buyer_deposit_pay_finished() throws Exception{
Map<String,Object> parameters = new HashMap<>();
parameters.put("productName","test");
parameters.put("sizeName","35");
parameters.put("productCode","XJ123456");
ufoBidMessageService.sendMessage(uid, UFO_BUYER_DEPOSIT_PAY_FINISHED, parameters);
TimeUnit.SECONDS.sleep(100);
}
}
... ...