|
|
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());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|