bravo-消息-批量-公屏飘屏

This commit is contained in:
khalil
2025-03-25 14:54:37 +08:00
parent 3c5d937ee1
commit 42bc816323
9 changed files with 142 additions and 140 deletions

View File

@@ -26,4 +26,5 @@ public interface RoomMapperExpand {
List<Room> listValidRoomsByParationId(@Param("index") Integer index, @Param("size") Integer size, @Param("parationId") Integer parationId);
List<Room> listValidRoomsByPartitionId(@Param("roomUid") Long roomUid, @Param("partitionId") Integer partitionId);
}

View File

@@ -90,4 +90,9 @@
<select id="listValidRoomsByParationId" resultMap = "RoomResultMap">
select * from room where valid = 1 and online_num > 0 and partition_id = #{parationId} limit #{index}, #{size}
</select>
<select id="listValidRoomsByPartitionId" resultMap="RoomResultMap">
select * from room where uid &lt;&gt; #{roomUid} and partition_id = #{partitionId} and valid = 1 and online_num > 0
</select>
</mapper>

View File

@@ -1,5 +1,9 @@
package com.accompany.common.netease.neteaseacc.dto;
import com.accompany.common.constant.Attach;
import com.accompany.common.constant.Constant;
import com.accompany.common.utils.UUIDUtil;
import com.alibaba.fastjson.JSON;
import lombok.Data;
@Data
@@ -28,4 +32,18 @@ public class BaseChatRoomMsg {
* 0非重发消息1重发消息如重发消息会按照 msgId 检查去重逻辑
* */
private Integer resendFlag;
public static BaseChatRoomMsg buildBaseChatRoomMsg(int first, int second, Object data){
Attach attach = new Attach();
attach.setFirst(first);
attach.setSecond(second);
attach.setData(JSON.toJSONString(data));
BaseChatRoomMsg msg = new BaseChatRoomMsg();
msg.setMsgId(UUIDUtil.get());
msg.setMsgType(Constant.DefineProtocol.CUSTOM_MESS_DEFINE);
msg.setSubType(1);
msg.setAttach(JSON.toJSONString(attach));
return msg;
}
}

View File

@@ -291,6 +291,8 @@ public enum I18nAlertEnum {
AVATAR_PAID_REFUND("你的付费头像涉嫌违规被管理员下架,上传付费的金币已退回"),
BRAVO_GIFT_ALL_ROOM_SCREEN("恭喜{0},在{1}送出 Bravo Gift [{2}],赢得了{3}金币!"),
;
private final String defaultStr;

View File

@@ -67,7 +67,7 @@ public class BaseSendService {
attach.setSecond(second);
attach.setData(data);
Users user = usersService.getUsersByUid(sender);
long count = this.roomQueryService.countValidRoomsByParationId(user.getPartitionId());
long count = this.roomQueryService.countValidRoomsByPartitionId(user.getPartitionId());
long times = count % BATCH_SIZE == 0 ? (count / BATCH_SIZE) : (count / BATCH_SIZE) + 1;
for (int i = 0; i < times; i++) {
Integer index = i * BATCH_SIZE;

View File

@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
@@ -574,6 +575,30 @@ public class SendSysMsgService extends BaseService {
}
}
public void sendPartitionOtherChatRoomBatchMsg(Room room, String fromAccId, List<BaseChatRoomMsg> allRoomMsgList) {
Integer partitionId = room.getPartitionId();
List<Room> validRooms = this.roomQueryService.listValidRoomsByPartitionId(room.getUid(), partitionId);
if (CollectionUtils.isEmpty(validRooms)){
return;
}
List<List<Room>> roomBatchList = Lists.partition(validRooms, BATCH_SIZE);
for (List<Room> roomList: roomBatchList){
roomList.sort(Comparator.comparing(Room::getOnlineNum).reversed());
for (Room r : roomList) {
if (null != partitionId && room.getPartitionId() != null && !partitionId.equals(room.getPartitionId())) {
continue;
}
taskExecutor.execute(() -> {
try {
this.erBanNetEaseService.batchSendChatRoomMsg(r.getRoomId(), allRoomMsgList, fromAccId);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={} {}, message={}]", r.getUid(), r.getTitle(), JSON.toJSONString(allRoomMsgList), e);
}
});
}
}
}
public void sendMessageToAllValidRooms(Attach msg, Room playRoom) {
Integer partitionId = playRoom.getPartitionId();
long count = this.roomQueryService.countValidRooms();

View File

@@ -9,18 +9,15 @@ 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.enumeration.PartitionEnum;
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;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -48,11 +45,90 @@ public class BravoMsgSendService {
return;
}
List<BaseChatRoomMsg> msgList = new ArrayList<>();
List<BaseChatRoomMsg> singleRoomMsgList = new ArrayList<>();
BaseChatRoomMsg tipMsg = buildTipMsg(config, sender, room, recordMap, winGoldNum, afterMultiple);
msgList.add(tipMsg);
singleRoomMsgList.add(tipMsg);
sendSysMsgService.sendSingleChatRoomBatchMsg(room.getRoomId(), String.valueOf(senderUid), msgList);
List<BaseChatRoomMsg> allRoomMsgList = new ArrayList<>();
if (winGoldNum.compareTo(config.getAllRoomChatToastValue()) >= 0){
BaseChatRoomMsg screenMsg = buildRoomScreen(sender, room, gift, winGoldNum);
allRoomMsgList.add(screenMsg);
}
//飘屏
if (winGoldNum.compareTo(config.getSpecialFloatValue()) >= 0
|| afterMultiple.compareTo(config.getSpecialFloatMulti()) >= 0) {
BaseChatRoomMsg floatingMsg = buildFloatingMsg(sender, room, gift, winGoldNum, afterMultiple);
allRoomMsgList.add(floatingMsg);
}
if (!CollectionUtils.isEmpty(allRoomMsgList)){
singleRoomMsgList.addAll(allRoomMsgList);
sendSysMsgService.sendPartitionOtherChatRoomBatchMsg(room, String.valueOf(senderUid), allRoomMsgList);
}
sendSysMsgService.sendSingleChatRoomBatchMsg(room.getRoomId(), String.valueOf(senderUid), singleRoomMsgList);
}
private BaseChatRoomMsg buildFloatingMsg(Users sender, Room room, Gift gift, BigDecimal winGoldNum, BigDecimal afterMultiple) {
Map<String, String> giftNameMap = new HashMap<>();
for (PartitionEnum partitionInfo: PartitionEnum.values()){
Locale locale = partitionInfoService.getDefaultLang(partitionInfo.getId());
String giftNameI18nId = String.join(".", "Gift", gift.getGiftName());
String text = I18NMessageSourceUtil.getMessage(giftNameI18nId, null, gift.getGiftName(), locale);
giftNameMap.put(locale.getLanguage(), text);
}
Map<String, Object> params = new HashMap<>();
params.put("sender", usersService.getSimpleUserVo(sender));
params.put("giftNameMap", giftNameMap);
params.put("roomUid", room.getUid());
params.put("times", afterMultiple.toPlainString());
params.put("coins", winGoldNum.toPlainString());
return BaseChatRoomMsg.buildBaseChatRoomMsg(Constant.DefMsgType.SUPER_LUCKY_GIFT, Constant.DefMsgType.BRAVO_GIFT_FLOAT, params);
}
private BaseChatRoomMsg buildRoomScreen(Users sender, Room room, Gift gift, BigDecimal winGoldNum) {
MessageTemplate allRoomTemplate = new MessageTemplate();
TextSpan senderNickSpan = new TextSpan();
senderNickSpan.setKey("senderNick");
senderNickSpan.setMessage("[" + sender.getNick() + "]");
senderNickSpan.setTextColor("#FFBC51");
allRoomTemplate.addSpan(senderNickSpan);
TextSpan giftNameSpan = new TextSpan();
giftNameSpan.setKey("giftName");
allRoomTemplate.addSpan(giftNameSpan);
String giftNameI18nId = String.join(".","Gift", gift.getGiftName());
TextSpan roomTitleSpan = new TextSpan();
roomTitleSpan.setKey("roomTitle");
roomTitleSpan.setMessage("[" + room.getTitle() + "]");
roomTitleSpan.setTextColor("#FFBC51");
allRoomTemplate.addSpan(roomTitleSpan);
TextSpan outputValueSpan = new TextSpan();
outputValueSpan.setKey("outputValue");
outputValueSpan.setMessage(winGoldNum.toPlainString());
allRoomTemplate.addSpan(outputValueSpan);
for (PartitionEnum partitionInfo : PartitionEnum.values()) {
Locale locale = Locale.forLanguageTag(partitionInfo.getLang());
String giftNameMessage = I18NMessageSourceUtil.getMessage(giftNameI18nId, null, gift.getGiftName(), locale);
giftNameSpan.setMessage("[" + giftNameMessage + "]", partitionInfo.getLang());
String allRoomText = I18NMessageSourceUtil.getMessage(I18nAlertEnum.BRAVO_GIFT_ALL_ROOM_SCREEN,
new Object[]{"senderNick", "roomTitle", "giftName", "outputValue"}, partitionInfo.getId());
allRoomTemplate.setMessage(allRoomText, partitionInfo.getLang());
}
allRoomTemplate.setPartitionId(room.getPartitionId());
return BaseChatRoomMsg.buildBaseChatRoomMsg(Constant.DefMsgType.SUPER_LUCKY_GIFT, Constant.DefMsgType.BRAVO_GIFT_ROOM_SCREEN, allRoomTemplate);
}
private BaseChatRoomMsg buildTipMsg(BravoGiftConfig config, Users sender, Room room,
@@ -78,122 +154,6 @@ public class BravoMsgSendService {
params.put("tip", tipParams);
}
Attach attach = new Attach();
attach.setFirst(Constant.DefMsgType.SUPER_LUCKY_GIFT);
attach.setSecond(Constant.DefMsgType.BRAVO_GIFT_TIP);
attach.setData(JSON.toJSONString(params));
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
public void sendAllRoomScreen(long senderUid, Room room, Gift gift, BigDecimal outputValue) {
Users sender = usersService.getUsersByUid(senderUid);
if (null == sender) {
return;
}
List<PartitionInfo> partitionInfoList = partitionInfoService.listAll();
if (CollectionUtils.isEmpty(partitionInfoList)) {
return;
}
MessageTemplate allRoomTemplate = new MessageTemplate();
TextSpan senderNickSpan = new TextSpan();
senderNickSpan.setKey("senderNick");
senderNickSpan.setMessage("[" + sender.getNick() + "]");
senderNickSpan.setTextColor("#FFBC51");
allRoomTemplate.addSpan(senderNickSpan);
TextSpan giftNameSpan = new TextSpan();
giftNameSpan.setKey("giftName");
allRoomTemplate.addSpan(giftNameSpan);
String giftNameI18nId = String.join(".","Gift", gift.getGiftName());
TextSpan roomTitleSpan = new TextSpan();
roomTitleSpan.setKey("roomTitle");
roomTitleSpan.setMessage("[" + room.getTitle() + "]");
roomTitleSpan.setTextColor("#FFBC51");
allRoomTemplate.addSpan(roomTitleSpan);
TextSpan outputValueSpan = new TextSpan();
outputValueSpan.setKey("outputValue");
outputValueSpan.setMessage(outputValue.toPlainString());
allRoomTemplate.addSpan(outputValueSpan);
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());
String allRoomText = I18NMessageSourceUtil.getMessage(I18nAlertEnum.SUPER_LUCKY_GIFT_ALL_ROOM_SCREEN,
new Object[]{"senderNick", "roomTitle", "giftName", "outputValue"}, partitionInfo.getId());
allRoomTemplate.setMessage(allRoomText, partitionInfo.getLanguages());
}
allRoomTemplate.setPartitionId(room.getPartitionId());
sendSysMsgService.sendTemplateMessage(Constant.DefMsgType.SUPER_LUCKY_GIFT, Constant.DefMsgType.BRAVO_GIFT_ROOM_SCREEN, allRoomTemplate);
}
@Async
public void sendTip(long senderUid, Room room, BigDecimal outputValue, BigDecimal multi, int level) {
Map<String, Object> params = new HashMap<>();
params.put("roomUid", room.getUid());
params.put("roomId", room.getRoomId());
params.put("uid", senderUid);
params.put("times", multi.toPlainString());
params.put("coins", outputValue.toPlainString());
params.put("level", level);
params.put("intratemporals", multi.toPlainString());
params.put("tangerines", outputValue.toPlainString());
sendSysMsgService.sendSingleRoomMessage(room.getRoomId(), String.valueOf(room.getUid()),
Constant.DefMsgType.SUPER_LUCKY_GIFT, Constant.DefMsgType.BRAVO_GIFT_TIP, params);
}
@Async
public void sendFloating(Room room, long senderUid, Gift gift, BigDecimal multi, BigDecimal outputValue) {
Users sender = usersService.getUsersByUid(senderUid);
if (null == sender) {
return;
}
List<PartitionInfo> partitionInfoList = partitionInfoService.listAll();
if (CollectionUtils.isEmpty(partitionInfoList)) {
return;
}
Map<String, String> giftNameMap = new HashMap<>();
for (PartitionInfo partitionInfo: partitionInfoList){
Locale locale = partitionInfoService.getDefaultLang(partitionInfo.getId());
String giftNameI18nId = String.join(".", "Gift", gift.getGiftName());
String text = I18NMessageSourceUtil.getMessage(giftNameI18nId, null, gift.getGiftName(), locale);
giftNameMap.put(locale.getLanguage(), text);
}
Map<String, Object> params = new HashMap<>();
params.put("sender", usersService.getSimpleUserVo(sender));
params.put("giftNameMap", giftNameMap);
params.put("roomUid", room.getUid());
params.put("times", multi.toPlainString());
params.put("coins", outputValue.toPlainString());
params.put("intratemporals", multi.toPlainString());
params.put("tangerines", outputValue.toPlainString());
Attach attach = new Attach();
attach.setFirst(Constant.DefMsgType.SUPER_LUCKY_GIFT);
attach.setSecond(Constant.DefMsgType.BRAVO_GIFT_FLOAT);
attach.setData(params);
sendSysMsgService.sendMessageToAllValidRooms(attach, room);
return BaseChatRoomMsg.buildBaseChatRoomMsg(Constant.DefMsgType.SUPER_LUCKY_GIFT, Constant.DefMsgType.BRAVO_GIFT_TIP, params);
}
}

View File

@@ -40,19 +40,6 @@ public class BravoSettlementService {
//飘屏
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);
if (winGoldNum.compareTo(config.getAllRoomChatToastValue()) > 0){
msgSendService.sendAllRoomScreen(senderUid, room, gift, winGoldNum);
}
//飘屏
if (winGoldNum.compareTo(config.getSpecialFloatValue()) >= 0
|| afterMultiple.compareTo(config.getSpecialFloatMulti()) >= 0) {
msgSendService.sendFloating(room, senderUid, gift, afterMultiple, winGoldNum);
}
}
}

View File

@@ -33,11 +33,15 @@ public class RoomQueryService {
return this.roomExpandMapper.listValidRoomsByTag(index, pageSize, roomTag);
}
public Long countValidRoomsByParationId(Integer parationId){
return this.roomExpandMapper.countValidRoomsByParationId(parationId);
public Long countValidRoomsByPartitionId(Integer partitionId){
return this.roomExpandMapper.countValidRoomsByParationId(partitionId);
}
public List<Room> listValidRoomsByParationId(Integer index, Integer pageSize, Integer parationId){
return this.roomExpandMapper.listValidRoomsByParationId(index, pageSize, parationId);
}
public List<Room> listValidRoomsByPartitionId(Long roomUid, Integer partitionId){
return this.roomExpandMapper.listValidRoomsByPartitionId(roomUid, partitionId);
}
}