bravo-消息-批量
This commit is contained in:
@@ -3,6 +3,7 @@ package com.accompany.common.netease;
|
||||
import com.accompany.common.config.NetEaseConfig;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.netease.neteaseacc.NetEaseBaseClient;
|
||||
import com.accompany.common.netease.neteaseacc.dto.BaseChatRoomMsg;
|
||||
import com.accompany.common.netease.neteaseacc.result.*;
|
||||
import com.accompany.common.netease.util.NetEaseConstant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
@@ -183,7 +184,7 @@ public class ErBanNetEaseService extends BaseService {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public RoomRet updateRoomInfo(Long roomId, String name, String ext, String notifyExt) throws Exception {
|
||||
public RoomRet updateRoomInfo(Long roomId, String name, String ext, String notifyExt) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.RoomUrl.update;
|
||||
NetEaseBaseClient netEaseBaseClient = new NetEaseBaseClient(NetEaseConfig.neteaseAppKey, NetEaseConfig.neteaseAppSecret, url);
|
||||
Map<String, Object> param = Maps.newHashMap();
|
||||
@@ -338,6 +339,33 @@ public class ErBanNetEaseService extends BaseService {
|
||||
return rubbishRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 往聊天室内发消息
|
||||
*
|
||||
* @param roomId
|
||||
* @param msgList
|
||||
* @param fromAccid
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public BatchChatRoomMsgRet batchSendChatRoomMsg(Long roomId, List<BaseChatRoomMsg> msgList, String fromAccid) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.RoomUrl.batchSendMsg;
|
||||
NetEaseBaseClient netEaseBaseClient = new NetEaseBaseClient(NetEaseConfig.neteaseAppKey, NetEaseConfig.neteaseAppSecret, url);
|
||||
Map<String, Object> param = Maps.newHashMap();
|
||||
param.put("roomid", roomId);
|
||||
String msgListStr = gson.toJson(msgList);
|
||||
param.put("msgList", msgListStr);
|
||||
param.put("fromAccid", fromAccid);
|
||||
param.put("skipHistory", 1);
|
||||
param.put("highPriority", true);
|
||||
String result = netEaseBaseClient.buildHttpPostParam(param).executePost();
|
||||
log.info("batchSendChatRoomMsg(), result={}", result);
|
||||
BatchChatRoomMsgRet ret = gson.fromJson(result, BatchChatRoomMsgRet.class);
|
||||
if (ret.getCode() != 200) {
|
||||
log.error("batchSendChatRoomMsg roomId=" + roomId + "&msgList=" + msgListStr + "&fromAccid=" + fromAccid + "====result=" + result);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public RubbishRet setChatRoomMemberRole(Long roomId, String operator, String target, int opt, String optvalue, String notifyExt) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.RoomUrl.setMemberRole;
|
||||
@@ -537,7 +565,7 @@ public class ErBanNetEaseService extends BaseService {
|
||||
}
|
||||
|
||||
|
||||
public RubbishRet broadcastMsg(String from, String body) throws Exception {
|
||||
public RubbishRet broadcastMsg(String from, String body) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.MsgUrl.broadcastMsg;
|
||||
NetEaseBaseClient netEaseBaseClient = new NetEaseBaseClient(NetEaseConfig.neteaseAppKey, NetEaseConfig.neteaseAppSecret, url);
|
||||
//https://api.netease.im/nimserver/msg/broadcastMsg.action
|
||||
@@ -553,7 +581,7 @@ public class ErBanNetEaseService extends BaseService {
|
||||
|
||||
|
||||
/* 获取房间内在线成员信息 */
|
||||
public RoomUserListRet getRoomMemberListInfo(long roomId, long uid) throws Exception {
|
||||
public RoomUserListRet getRoomMemberListInfo(long roomId, long uid) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.RoomUrl.membersList;
|
||||
NetEaseBaseClient netEaseBaseClient = new NetEaseBaseClient(NetEaseConfig.neteaseAppKey, NetEaseConfig.neteaseAppSecret, url);
|
||||
Map<String, Object> param = Maps.newHashMap();
|
||||
@@ -572,7 +600,7 @@ public class ErBanNetEaseService extends BaseService {
|
||||
return roomListRet;
|
||||
}
|
||||
|
||||
public String addRobotToRoom(long roomId, String accids) throws Exception {
|
||||
public String addRobotToRoom(long roomId, String accids) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.RoomUrl.addRobot;
|
||||
NetEaseBaseClient netEaseBaseClient = new NetEaseBaseClient(NetEaseConfig.neteaseAppKey, NetEaseConfig.neteaseAppSecret, url);
|
||||
Map<String, Object> param = Maps.newHashMap();
|
||||
@@ -759,7 +787,7 @@ public class ErBanNetEaseService extends BaseService {
|
||||
/**
|
||||
* 撤回消息 * @param deleteMsgId 要撤回消息的消息 ID * @param timeTag 待撤回消息的创建时间(创建时间为云信服务端生成的消息发送时间戳),示例:"12514613452" * @param type 待撤回消息的类型,只能传入 13 或 14。13 表示点对点消息撤回,14 表示群消息撤回,传入其他值均判定为参数错误 * @param from 消息发送者的云信 IM 账号(accid) * @param to 消息接收方。如果待撤回消息为单聊消息,则需传入消息接收者的云信 IM 账号(accid)。如果是群消息,则需传入对应群的ID (tid) * @param msg 消息撤回的相应描述,默认值为“撤回了一条信息”。最大长度 128 个字符 * @return ignore * @throws Exception 异常
|
||||
*/
|
||||
public RubbishRet rollbackSysAttachMsg(String deleteMsgId, Long timeTag, String from, String to, String msg) throws Exception {
|
||||
public RubbishRet rollbackSysAttachMsg(String deleteMsgId, Long timeTag, String from, String to, String msg) {
|
||||
String url = NetEaseConstant.basicUrl + NetEaseConstant.MsgUrl.delMsgOneWay;
|
||||
NetEaseBaseClient netEaseBaseClient = new NetEaseBaseClient(NetEaseConfig.neteaseAppKey, NetEaseConfig.neteaseAppSecret, url);
|
||||
Map<String, Object> param = Maps.newHashMap(); //过滤审核账号
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package com.accompany.common.netease.neteaseacc.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BaseChatRoomMsg {
|
||||
private String msgId;
|
||||
/**
|
||||
* 0: 文本消息,1: 图片,2: 语音,3: 视频,4: 地理位置信息,6: 文件,10: 提示消息(Tips),100: 自定义消息
|
||||
*/
|
||||
private int msgType;
|
||||
/**
|
||||
* attach:消息内容,String,除文本消息(msgType=0)和提示消息(msgType=10)外,其他消息类型的内容都为 JSON 格式,具体请参见消息格式示例,最大长度 4096 位字符。
|
||||
* */
|
||||
private String attach;
|
||||
/**
|
||||
* ext:扩展字段,String,
|
||||
* */
|
||||
private String ext;
|
||||
/**
|
||||
* 非必填
|
||||
* subType:自定义消息子类型,Integer,大于 0
|
||||
* */
|
||||
private Integer subType;
|
||||
/**
|
||||
* 非必填
|
||||
* resendFlag:重发消息标记,Integer
|
||||
* 0:非重发消息,1:重发消息,如重发消息会按照 msgId 检查去重逻辑
|
||||
* */
|
||||
private Integer resendFlag;
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.accompany.common.netease.neteaseacc.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class BatchChatRoomMsg {
|
||||
// 必填参数
|
||||
private Long roomid; // 聊天室ID
|
||||
private List<BaseChatRoomMsg> msgList; // 需要发送的消息列表(JSON数组字符串)
|
||||
private String fromAccid; // 发送者账号
|
||||
|
||||
// 非必填参数
|
||||
private Boolean ignoreMute; // 是否忽略禁言(默认false)
|
||||
private Integer skipHistory; // 是否存储云端历史(0存储/1不存储)
|
||||
private Integer route; // 是否需要抄送(0不需要/1需要,默认1)
|
||||
private Integer abandonRatio; // 丢弃概率(0-9999)
|
||||
private Boolean highPriority; // 是否高优先级(默认false)
|
||||
private Boolean needHighPriorityMsgResend; // 高优先级消息是否重发(默认true)
|
||||
private Integer useYidun; // 是否使用安全通(0不使用)
|
||||
private String yidunAntiCheating; // 反作弊参数(JSON)
|
||||
private String yidunAntiSpamExt; // 反垃圾扩展参数(JSON)
|
||||
private String bid; // 自定义反垃圾业务ID
|
||||
private Boolean antispam; // 是否使用自定义反垃圾内容(msgType=100时生效)
|
||||
private String notifyTargetTags; // 目标标签表达式
|
||||
private String antispamCustom; // 自定义反垃圾内容(JSON)
|
||||
private String env; // 自定义抄送环境名称
|
||||
private Integer chatMsgPriority; // CDN通道优先级(0-3)
|
||||
private Integer forbiddenIfHighPriorityMsgFreq; // 高频控制处理方式(0降级/1返回403)
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.accompany.common.netease.neteaseacc.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChatRoomMsg extends BaseChatRoomMsg {
|
||||
|
||||
// 非必填参数
|
||||
private Boolean ignoreMute; // 是否忽略禁言(默认false)
|
||||
private Integer route; // 是否需要抄送(0不需要/1需要,默认1)
|
||||
private Integer skipHistory; // 是否存储云端历史(0存储/1不存储)
|
||||
private Integer abandonRatio; // 丢弃概率(0-9999)
|
||||
private Boolean highPriority; // 是否高优先级(默认false)
|
||||
private Boolean needHighPriorityMsgResend; // 高优先级消息是否重发(默认true)
|
||||
private Integer useYidun; // 是否使用安全通(0不使用)
|
||||
private String yidunAntiCheating; // 反作弊参数(JSON)
|
||||
private String yidunAntiSpamExt; // 反垃圾扩展参数(JSON)
|
||||
private String bid; // 自定义反垃圾业务ID
|
||||
private Boolean antispam; // 是否使用自定义反垃圾内容(msgType=100时生效)
|
||||
private String notifyTargetTags; // 目标标签表达式
|
||||
private String antispamCustom; // 自定义反垃圾内容(JSON)
|
||||
private String env; // 自定义抄送环境名称
|
||||
private Integer chatMsgPriority; // CDN通道优先级(0-3)
|
||||
private Integer forbiddenIfHighPriorityMsgFreq; // 高频控制处理方式(0降级/1返回403)
|
||||
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
package com.accompany.common.netease.neteaseacc.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class BatchChatRoomMsgRet extends BaseNetEaseRet {
|
||||
/**
|
||||
* {
|
||||
* "fail": [
|
||||
* {
|
||||
* "57gadfgsdhlaisfjlaskdmfa": "parameter resendFlag should be used for RESEND!"
|
||||
* }
|
||||
* ],
|
||||
* "code": 200,
|
||||
* "success": [
|
||||
* {
|
||||
* "gsfdgs45hd15h1s56safda": {
|
||||
* "ext": "fadsfag80ad7fg98s9giapo[ga",
|
||||
* "fromNick": "yx2",
|
||||
* "msgid_client": "gsfdgs45hd15h1s56safda",
|
||||
* "fromAccount": "yx2",
|
||||
* "fromClientType": "REST",
|
||||
* "attach": "afsdfaf807sadf98asdfl;ajskdflasd",
|
||||
* "time": "1668566975724",
|
||||
* "type": "2",
|
||||
* "highPriorityFlag": "1",
|
||||
* "roomId": "72"
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* "akdsuhfaiuofyai7syfhakjds": {
|
||||
* "ext": "fadsfag80ad7fg98s9giapo[ga",
|
||||
* "fromNick": "yx2",
|
||||
* "msgid_client": "akdsuhfaiuofyai7syfhakjds",
|
||||
* "fromAccount": "yx2",
|
||||
* "fromClientType": "REST",
|
||||
* "attach": "",
|
||||
* "time": "1668566975825",
|
||||
* "type": "1",
|
||||
* "highPriorityFlag": "1",
|
||||
* "roomId": "72"
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* */
|
||||
private List<Map<String, Object>> success;
|
||||
private List<Map<String, String>> fail;
|
||||
}
|
@@ -59,6 +59,7 @@ public class NetEaseConstant {
|
||||
public static String getBatch = "/chatroom/getBatch.action";
|
||||
public static String update = "/chatroom/update.action";
|
||||
public static String sendMsg = "/chatroom/sendMsg.action";
|
||||
public static String batchSendMsg = "/chatroom/batchSendMsg.action";
|
||||
public static String toggleCloseStat = "/chatroom/toggleCloseStat.action";
|
||||
public static String setMemberRole = "/chatroom/setMemberRole.action";
|
||||
public static String addRobot = "/chatroom/addRobot.action";
|
||||
|
@@ -11,6 +11,7 @@ import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.constant.Attach;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.netease.ErBanNetEaseService;
|
||||
import com.accompany.common.netease.neteaseacc.dto.BaseChatRoomMsg;
|
||||
import com.accompany.common.netease.neteaseacc.result.RubbishRet;
|
||||
import com.accompany.common.utils.GsonUtil;
|
||||
import com.accompany.common.utils.ReplaceAppDomainUtils;
|
||||
@@ -488,6 +489,7 @@ public class SendSysMsgService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendTemplateMessage(MessageTemplate message) {
|
||||
Integer partitionId = message.getPartitionId();
|
||||
long count = this.roomQueryService.countValidRooms();
|
||||
@@ -564,6 +566,13 @@ public class SendSysMsgService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSingleChatRoomBatchMsg(Long roomId, String fromAccId, List<BaseChatRoomMsg> msgList) {
|
||||
try {
|
||||
this.erBanNetEaseService.batchSendChatRoomMsg(roomId, msgList, fromAccId);
|
||||
} catch (Exception e) {
|
||||
log.error("批量发送房间消息失败[roomId : {}, fromAccId : {}, message : {}]", roomId, fromAccId, JSON.toJSONString(msgList), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessageToAllValidRooms(Attach msg, Room playRoom) {
|
||||
Integer partitionId = playRoom.getPartitionId();
|
||||
|
@@ -96,7 +96,7 @@ public class BravoGiftSendService {
|
||||
BigDecimal totalInput = BigDecimal.valueOf(recordMap.size() * everyGiftNum * gift.getGoldPrice());
|
||||
BigDecimal totalOutput = recordMap.values().stream().map(BravoRecord::getWinGoldNum).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal outputMultiple = totalOutput.compareTo(BigDecimal.ZERO) > 0? totalOutput.divide(totalInput, 2, RoundingMode.DOWN): BigDecimal.ZERO;
|
||||
settlementService.sendReward(config, senderUid, room, gift, totalOutput, outputMultiple);
|
||||
settlementService.sendReward(config, senderUid, room, gift, everyGiftNum, recordMap, totalOutput, outputMultiple);
|
||||
}
|
||||
|
||||
public Map<Long, BravoRecord> draw(BravoGiftConfig config, Long senderUid, int partitionId,
|
||||
@@ -157,6 +157,7 @@ public class BravoGiftSendService {
|
||||
String id = idGenerator.nextUUID(null);
|
||||
|
||||
BigDecimal receiverProfit = incomeAllot.getReceiveIncomeMap().get(record.getReceiverUid());
|
||||
record.setReceiverProfit(receiverProfit);
|
||||
|
||||
BravoMessage message = new BravoMessage();
|
||||
message.setMessId(id);
|
||||
|
@@ -1,22 +1,23 @@
|
||||
package com.accompany.business.service.gift;
|
||||
|
||||
import com.accompany.business.enums.lucky.LuckyGiftRewardTypeEnum;
|
||||
import com.accompany.business.enums.message.ContentTypeEnum;
|
||||
import com.accompany.business.dto.lucky.BravoGiftConfig;
|
||||
import com.accompany.business.model.Gift;
|
||||
import com.accompany.business.model.lucky.LuckyGiftReward;
|
||||
import com.accompany.business.service.SendSysMsgService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.message.ImageSpan;
|
||||
import com.accompany.business.vo.message.MessageTemplate;
|
||||
import com.accompany.business.vo.message.TextSpan;
|
||||
import com.accompany.common.constant.Attach;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.netease.neteaseacc.dto.BaseChatRoomMsg;
|
||||
import com.accompany.common.utils.UUIDUtil;
|
||||
import com.accompany.core.enumeration.I18nAlertEnum;
|
||||
import com.accompany.core.model.PartitionInfo;
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.partition.PartitionInfoService;
|
||||
import com.accompany.core.util.I18NMessageSourceUtil;
|
||||
import com.accompany.sharding.model.BravoRecord;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -25,7 +26,6 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -38,168 +38,57 @@ public class BravoMsgSendService {
|
||||
@Autowired
|
||||
private PartitionInfoService partitionInfoService;
|
||||
|
||||
@Async
|
||||
public void sendRoomScreen(long senderUid, Room room, Gift gift, int giftNum, Map<Long, Map<LuckyGiftReward, Integer>> drawResult) {
|
||||
public void sendRoomMsg(BravoGiftConfig config, long senderUid, Room room,
|
||||
Gift gift, int everyGiftNum,
|
||||
Map<Long, BravoRecord> recordMap,
|
||||
BigDecimal winGoldNum, BigDecimal afterMultiple) {
|
||||
|
||||
Users sender = usersService.getUsersByUid(senderUid);
|
||||
if (null == sender) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Long, Users> receiverMap = usersService.getUsersMapByUids(new ArrayList<>(drawResult.keySet()));
|
||||
if (CollectionUtils.isEmpty(receiverMap)) {
|
||||
return;
|
||||
List<BaseChatRoomMsg> msgList = new ArrayList<>();
|
||||
BaseChatRoomMsg tipMsg = buildTipMsg(config, sender, room, recordMap, winGoldNum, afterMultiple);
|
||||
msgList.add(tipMsg);
|
||||
|
||||
sendSysMsgService.sendSingleChatRoomBatchMsg(room.getRoomId(), String.valueOf(senderUid), msgList);
|
||||
}
|
||||
|
||||
private BaseChatRoomMsg buildTipMsg(BravoGiftConfig config, Users sender, Room room,
|
||||
Map<Long, BravoRecord> recordMap,
|
||||
BigDecimal winGoldNum, BigDecimal afterMultiple) {
|
||||
Set<Long> receiverUidList = recordMap.keySet();
|
||||
BigDecimal receiverProfit = recordMap.get(receiverUidList.iterator().next()).getReceiverProfit();
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("roomUid", room.getUid());
|
||||
params.put("roomId", room.getRoomId());
|
||||
params.put("uid", sender.getUid());
|
||||
params.put("receiverUidList", receiverUidList);
|
||||
params.put("receiverProfit", receiverProfit.toPlainString());
|
||||
|
||||
if (winGoldNum.compareTo(BigDecimal.ZERO) > 0){
|
||||
int level = afterMultiple.compareTo(config.getSpecialTipMulti()) >= 0 ? 2 : 1;
|
||||
Map<String, Object> tipParams = new HashMap<>();
|
||||
tipParams.put("times", afterMultiple.toPlainString());
|
||||
tipParams.put("coins", winGoldNum.toPlainString());
|
||||
tipParams.put("level", level);
|
||||
|
||||
params.put("tip", tipParams);
|
||||
}
|
||||
|
||||
List<PartitionInfo> partitionInfoList = partitionInfoService.listAll();
|
||||
if (CollectionUtils.isEmpty(partitionInfoList)){
|
||||
return;
|
||||
}
|
||||
Attach attach = new Attach();
|
||||
attach.setFirst(Constant.DefMsgType.SUPER_LUCKY_GIFT);
|
||||
attach.setSecond(Constant.DefMsgType.BRAVO_GIFT_TIP);
|
||||
attach.setData(JSON.toJSONString(params));
|
||||
|
||||
drawResult.keySet().parallelStream().forEach(receiverUid -> {
|
||||
Users receiver = receiverMap.get(receiverUid);
|
||||
if (null == receiver) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<LuckyGiftReward, Integer> receiverResultMap = drawResult.get(receiverUid);
|
||||
|
||||
List<LuckyGiftReward> rewardList = receiverResultMap.keySet().stream()
|
||||
.filter(key -> LuckyGiftRewardTypeEnum.NONE.ordinal() != key.getRewardType())
|
||||
.sorted(Comparator.comparing(LuckyGiftReward::getRewardType)
|
||||
.thenComparing((l1, l2) -> l2.getRewardPrice().compareTo(l1.getRewardPrice())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
MessageTemplate messageTemplate = new MessageTemplate();
|
||||
|
||||
TextSpan senderNickSpan = new TextSpan();
|
||||
senderNickSpan.setKey("senderNick");
|
||||
senderNickSpan.setMessage("[" + sender.getNick() + "]");
|
||||
senderNickSpan.setTextColor("#FFBC51");
|
||||
messageTemplate.addSpan(senderNickSpan);
|
||||
|
||||
TextSpan receiverNickSpan = new TextSpan();
|
||||
receiverNickSpan.setKey("receiverNick");
|
||||
receiverNickSpan.setMessage("[" + receiver.getNick() + "]");
|
||||
receiverNickSpan.setTextColor("#FFBC51");
|
||||
messageTemplate.addSpan(receiverNickSpan);
|
||||
|
||||
TextSpan giftNameSpan = new TextSpan();
|
||||
giftNameSpan.setKey("giftName");
|
||||
messageTemplate.addSpan(giftNameSpan);
|
||||
|
||||
String giftNameI18nId = String.join(".","Gift", gift.getGiftName());
|
||||
|
||||
TextSpan giftNumSpan = new TextSpan();
|
||||
giftNumSpan.setKey("giftNum");
|
||||
giftNumSpan.setMessage(String.valueOf(giftNum));
|
||||
messageTemplate.addSpan(giftNumSpan);
|
||||
|
||||
for (PartitionInfo partitionInfo : partitionInfoList) {
|
||||
Integer partitionId = partitionInfo.getId();
|
||||
|
||||
Locale locale = partitionInfoService.getDefaultLang(partitionId);
|
||||
|
||||
String giftNameMessage = I18NMessageSourceUtil.getMessage(giftNameI18nId, null, gift.getGiftName(), locale);
|
||||
giftNameSpan.setMessage("[" + giftNameMessage + "]", partitionInfo.getLanguages());
|
||||
|
||||
StringBuilder template = new StringBuilder(I18NMessageSourceUtil.getMessage(I18nAlertEnum.SUPER_LUCKY_GIFT_ROOM_SCREEN, new Object[]{"senderNick", "receiverNick", "giftName", "giftNum"}, partitionId));
|
||||
|
||||
String getPhrase = I18NMessageSourceUtil.getMessage(I18nAlertEnum.SUPER_LUCKY_GIFT_GET_PHRASE, null, locale);
|
||||
String diamondPhrase = I18NMessageSourceUtil.getMessage(I18nAlertEnum.SUPER_LUCKY_GIFT_DIAMOND_PHRASE, null, locale);
|
||||
|
||||
if (!CollectionUtils.isEmpty(rewardList)) {
|
||||
// 合并钻石
|
||||
boolean hasPrintDiamond = false;
|
||||
long diamondNum = 0L;
|
||||
for (LuckyGiftReward reward : rewardList) {
|
||||
if (LuckyGiftRewardTypeEnum.DIAMOND.ordinal() != reward.getRewardType()) {
|
||||
continue;
|
||||
}
|
||||
int num = receiverResultMap.get(reward);
|
||||
diamondNum += reward.getRewardPrice() * num;
|
||||
}
|
||||
|
||||
int index = 1;
|
||||
for (LuckyGiftReward reward : rewardList) {
|
||||
if (LuckyGiftRewardTypeEnum.DIAMOND.ordinal() == reward.getRewardType()) {
|
||||
if (hasPrintDiamond) {
|
||||
continue;
|
||||
}
|
||||
hasPrintDiamond = true;
|
||||
}
|
||||
|
||||
template.append(index == 1 ? getPhrase : "、");
|
||||
|
||||
String rewardIcon = "rewardIcon" + index;
|
||||
String rewardIconTemplate = "{" + rewardIcon + "}";
|
||||
|
||||
template.append(rewardIconTemplate);
|
||||
|
||||
ImageSpan imageSpan = new ImageSpan();
|
||||
imageSpan.setKey(rewardIcon);
|
||||
imageSpan.setType(ContentTypeEnum.IMAGE.name());
|
||||
imageSpan.setImage(reward.getRewardIcon());
|
||||
imageSpan.setWidth(20);
|
||||
imageSpan.setHeight(20);
|
||||
|
||||
messageTemplate.addSpan(imageSpan);
|
||||
|
||||
//
|
||||
if (LuckyGiftRewardTypeEnum.GIFT.ordinal() == reward.getRewardType()) {
|
||||
//
|
||||
String rewardName = "rewardName" + index;
|
||||
String rewardNameTemplate = "{" + rewardName + "}";
|
||||
|
||||
template.append(rewardNameTemplate);
|
||||
|
||||
String rewardNameI18nId = "Gift." + reward.getRewardName();
|
||||
String rewardNameMessage = I18NMessageSourceUtil.getMessage(rewardNameI18nId, null, reward.getRewardName(), locale);
|
||||
|
||||
TextSpan rewardNameSpan = new TextSpan();
|
||||
rewardNameSpan.setKey(rewardName);
|
||||
rewardNameSpan.setType(ContentTypeEnum.TEXT.name());
|
||||
rewardNameSpan.setMessage(rewardNameMessage, partitionInfo.getLanguages());
|
||||
|
||||
messageTemplate.addSpan(rewardNameSpan);
|
||||
|
||||
String rewardValue = "rewardValue" + index;
|
||||
String rewardValueTemplate = "{" + rewardValue + "}";
|
||||
|
||||
template.append("(").append(rewardValueTemplate).append(diamondPhrase).append(")");
|
||||
|
||||
TextSpan rewardValueSpan = new TextSpan();
|
||||
rewardValueSpan.setKey(rewardValue);
|
||||
rewardValueSpan.setType(ContentTypeEnum.TEXT.name());
|
||||
rewardValueSpan.setMessage(reward.getRewardPrice().toString());
|
||||
|
||||
messageTemplate.addSpan(rewardValueSpan);
|
||||
}
|
||||
|
||||
//
|
||||
String rewardNum = "rewardNum" + index;
|
||||
String rewardNumTemplate = "{" + rewardNum + "}";
|
||||
|
||||
template.append("*").append(rewardNumTemplate);
|
||||
|
||||
String num = LuckyGiftRewardTypeEnum.DIAMOND.ordinal() == reward.getRewardType() ?
|
||||
String.valueOf(diamondNum) : receiverResultMap.get(reward).toString();
|
||||
|
||||
TextSpan rewardNumSpan = new TextSpan();
|
||||
rewardNumSpan.setKey(rewardNum);
|
||||
rewardNumSpan.setMessage(num);
|
||||
|
||||
messageTemplate.addSpan(rewardNumSpan);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
messageTemplate.setMessage(template.toString(), partitionInfo.getLanguages());
|
||||
}
|
||||
|
||||
messageTemplate.setPartitionId(room.getPartitionId());
|
||||
sendSysMsgService.sendTemplateMessage(room.getRoomId(), room.getUid(),
|
||||
Constant.DefMsgType.SUPER_LUCKY_GIFT, Constant.DefMsgType.BRAVO_GIFT_ROOM_SCREEN, messageTemplate);
|
||||
});
|
||||
BaseChatRoomMsg tipMsg = new BaseChatRoomMsg();
|
||||
tipMsg.setMsgId(UUIDUtil.get());
|
||||
tipMsg.setMsgType(Constant.DefineProtocol.CUSTOM_MESS_DEFINE);
|
||||
tipMsg.setSubType(1);
|
||||
tipMsg.setAttach(JSON.toJSONString(attach));
|
||||
return tipMsg;
|
||||
}
|
||||
|
||||
@Async
|
||||
@@ -307,5 +196,4 @@ public class BravoMsgSendService {
|
||||
|
||||
sendSysMsgService.sendMessageToAllValidRooms(attach, room);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -30,12 +31,16 @@ public class BravoSettlementService {
|
||||
private BravoMsgSendService msgSendService;
|
||||
|
||||
@Async
|
||||
public void sendReward(BravoGiftConfig config, long senderUid, Room room, Gift gift, BigDecimal winGoldNum, BigDecimal afterMultiple){
|
||||
public void sendReward(BravoGiftConfig config, long senderUid, Room room,
|
||||
Gift gift, int everyGiftNum, Map<Long, BravoRecord> recordMap,
|
||||
BigDecimal winGoldNum, BigDecimal afterMultiple){
|
||||
// 道具奖励
|
||||
userPurseService.addDiamond(senderUid, winGoldNum.doubleValue(), BillObjTypeEnum.BRAVO_GIFT_DIAMOND);
|
||||
|
||||
//飘屏
|
||||
if (null != room){
|
||||
msgSendService.sendRoomMsg(config, senderUid, room, gift, everyGiftNum, recordMap, winGoldNum, afterMultiple);
|
||||
|
||||
msgSendService.sendTip(senderUid, room, winGoldNum, afterMultiple,
|
||||
afterMultiple.compareTo(config.getSpecialTipMulti()) >= 0 ? 2 : 1);
|
||||
|
||||
|
Reference in New Issue
Block a user