线程池-云信发批量房间消息-针对幸运礼物消息,先使用bizExecutor发送球球,提高玩法正反馈消息的及时性,再使用asyncExecutor慢处理全房间飘屏公屏

This commit is contained in:
khalil
2025-05-08 14:51:16 +08:00
parent db3e0ea539
commit 86e6bdc064
24 changed files with 112 additions and 530 deletions

View File

@@ -5,13 +5,13 @@ import com.accompany.admin.mapper.FloatingScreenRecordMapper;
import com.accompany.admin.model.FloatingScreenRecord;
import com.accompany.admin.service.floating.FloatingScreenAdminService;
import com.accompany.business.service.SendSysMsgService;
import com.accompany.business.service.room.RoomQueryService;
import com.accompany.business.service.room.RoomService;
import com.accompany.common.config.SystemConfig;
import com.accompany.common.constant.Attach;
import com.accompany.common.constant.Constant;
import com.accompany.common.netease.ErBanNetEaseService;
import com.accompany.common.utils.UUIDUtil;
import com.accompany.core.enumeration.PartitionEnum;
import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.accompany.core.service.user.UsersBaseService;
@@ -50,21 +50,10 @@ public class FloatingScreenAdminServiceImpl implements FloatingScreenAdminServic
private UsersBaseService usersBaseService;
@Autowired
private SendSysMsgService sendSysMsgService;
@Autowired
private RoomQueryService roomQueryService;
@Resource(name = "async-executor")
private ThreadPoolExecutor asyncExecutor;
@Autowired
private ErBanNetEaseService erBanNetEaseService;
/**
* 一次性批量发送的房间数量
**/
private static final Integer BATCH_SIZE = 100;
@Override
public Page<FloatingScreenRecord> page(Integer currentPage, Integer pageSize) {
return (Page<FloatingScreenRecord>) floatingScreenRecordMapper.selectPage(new Page<>(currentPage, pageSize), Wrappers.<FloatingScreenRecord>lambdaQuery()
return floatingScreenRecordMapper.selectPage(new Page<>(currentPage, pageSize), Wrappers.<FloatingScreenRecord>lambdaQuery()
.orderByDesc(FloatingScreenRecord::getCreateTime));
}
@@ -99,9 +88,11 @@ public class FloatingScreenAdminServiceImpl implements FloatingScreenAdminServic
if (type == FLOATING_SCREEN_TYPE_FOR_ROOM) {
attach.setSecond(Constant.DefineProtocol.CUSTOM_MSG_FLOATING_SCREEN_FOR_ROOM);
if (room == null) {
sendMessageToAllValidRooms(JSON.toJSONString(attach));
for (PartitionEnum partitionEnum: PartitionEnum.values()){
sendSysMsgService.sendMessageToPartition(partitionEnum.getId(), attach);
}
} else {
sendMessageToAllValidRoomsV2(JSON.toJSONString(attach), room);
sendSysMsgService.sendMessageToPartition(room, attach);
}
} else if (type == FLOATING_SCREEN_TYPE_FOR_ALL) {
attach.setSecond(Constant.DefineProtocol.CUSTOM_MSG_FLOATING_SCREEN_FOR_ALL);
@@ -109,59 +100,4 @@ public class FloatingScreenAdminServiceImpl implements FloatingScreenAdminServic
}
}
/**
* 发送所有有效房间消息
*
* @param msg
*/
public long sendMessageToAllValidRooms(final String msg) {
long count = this.roomQueryService.countValidRooms();
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;
List<Room> validRooms = this.roomQueryService.listValidRooms(index, BATCH_SIZE);
validRooms.sort(Comparator.comparing(Room::getOnlineNum).reversed());
for (Room room : validRooms) {
asyncExecutor.execute(() -> {
try {
this.erBanNetEaseService.sendChatRoomMsg(room.getRoomId(), UUIDUtil.get(), room.getUid().toString(), Constant.DefineProtocol.CUSTOM_MESS_DEFINE, msg, null);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={}, message={}]", JSON.toJSONString(room), msg, e);
}
});
}
}
log.info("发送所有有效房间消息,房间数:{}", count);
return count;
}
@Deprecated
public void sendMessageToAllValidRoomsV2(String msg, Room playRoom) {
long count = this.roomQueryService.countValidRoomsExcludePlayroom(playRoom.getRoomId());
// 由于用户在玩的房间一定是要发消息的, 所以预留一个位置给这个房间
int pageSize = BATCH_SIZE - 1;
long times = count % pageSize == 0 ? (count / pageSize) : (count / pageSize) + 1;
boolean hasSendPlayroom = false;
for (int i = 0; i < times; i++) {
Integer index = i * pageSize;
List<Room> validRooms = this.roomQueryService.listValidRoomsExcludePlayroom(playRoom.getRoomId(), index, pageSize);
if (!hasSendPlayroom) {
if (validRooms == null) {
validRooms = new ArrayList<>();
}
validRooms.add(playRoom);
hasSendPlayroom = true;
}
for (Room room : validRooms) {
asyncExecutor.execute(() -> {
try {
this.erBanNetEaseService.sendChatRoomMsg(room.getRoomId(), UUIDUtil.get(), room.getUid().toString(), Constant.DefineProtocol.CUSTOM_MESS_DEFINE, msg, null);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={}, message={}]", JSON.toJSONString(room), msg, e);
}
});
}
}
log.info("发送所有有效房间消息,房间数:{}", count);
}
}

View File

@@ -22,9 +22,5 @@ public interface RoomMapperExpand {
List<Room> listValidRoomsByTag(@Param("index") Integer index, @Param("size") Integer size, @Param("roomTag") String roomTag);
Long countValidRoomsByParationId(@Param("parationId") Integer parationId);
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

@@ -84,13 +84,6 @@
select * from room where valid = 1 and online_num > 0 and room_tag = #{roomTag} limit #{index}, #{size}
</select>
<select id="countValidRoomsByParationId" resultType="java.lang.Long">
select count(1) from room where valid = 1 and online_num > 0 and partition_id = #{parationId}
</select>
<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 1=1
<if test="null != roomUid" > and uid &lt;&gt; #{roomUid} </if>

View File

@@ -23,6 +23,7 @@ import com.accompany.common.constant.GiftConstant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.StringUtils;
import com.accompany.core.base.SpringContextHolder;
import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.accompany.core.service.common.JedisService;
import com.alibaba.fastjson.JSONObject;
@@ -260,6 +261,10 @@ public class GiftNotifyListener implements ApplicationListener<GiftMessageEvent>
if (roomUid == null) {
return;
}
Room room = roomService.getRoomByUid(roomUid);
if (room == null){
return;
}
Integer giftId = giftMessage.getGiftId();
Gift gift = giftService.getGiftById(giftId);
if (gift.getNotifyFull() == null || GiftConstant.GiftNotifyFull.notifyAll != gift.getNotifyFull()) {//发送全服房间
@@ -285,11 +290,7 @@ public class GiftNotifyListener implements ApplicationListener<GiftMessageEvent>
giftNotifyVo.setTargetUsers(new Users[]{recvUser});
giftNotifyVo.setTargetUid(recvUser.getUid());
giftNotifyVo.setTargetUids(new Long[] {giftMessage.getRecvUid()});
baseSendService.sendMessageToAllValidRooms(sendUserUid, Constant.DefMsgType.Gift, Constant.DefMsgType.NewGiftSend, giftNotifyVo);
// else {//发送单个房间
// Room roomByUid = roomService.getRoomByUid(roomUid);
// sendSysMsgService.sendSingleRoomMessage(roomByUid.getRoomId(), sendUserUid.toString(), Constant.DefMsgType.Gift, Constant.DefMsgType.NewGiftSend, giftNotifyVo);
// }
sendSysMsgService.sendMessageToPartition(room, Constant.DefMsgType.Gift, Constant.DefMsgType.NewGiftSend, giftNotifyVo);
} catch (Exception e) {
logger.error("sendAvatarGiftNotify error:{}, giftMessage:{}", e.getMessage(), JSONObject.toJSONString(giftMessage), e);
}

View File

@@ -1,40 +1,19 @@
package com.accompany.business.service;
import com.accompany.business.param.neteasepush.NeteaseSendMsgParam;
import com.accompany.business.service.room.RoomQueryService;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.message.MessageLayoutV2;
import com.accompany.common.config.SystemConfig;
import com.accompany.common.constant.Attach;
import com.accompany.common.constant.Constant;
import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@Service
public class BaseSendService {
@Autowired
private SendSysMsgService sendSysMsgService;
@Autowired
private UsersService usersService;
@Autowired
private RoomQueryService roomQueryService;
@Resource(name = "async-executor")
private ThreadPoolExecutor asyncExecutor;
// 一次性批量发送的房间数量
private static final Integer BATCH_SIZE = 100;
/**
* 系统消息,普通文本消息
@@ -61,29 +40,6 @@ public class BaseSendService {
sendSysMsgService.sendPersonTextMsg(SystemConfig.secretaryUid, toUid, message);
}
public void sendMessageToAllValidRooms(final Long sender, Integer first, Integer second, final Object data) {
Attach attach = new Attach();
attach.setFirst(first);
attach.setSecond(second);
attach.setData(data);
Users user = usersService.getUsersByUid(sender);
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;
List<Room> validRooms = this.roomQueryService.listValidRoomsByParationId(index, BATCH_SIZE, user.getPartitionId());
for (Room room : validRooms) {
asyncExecutor.execute(() -> {
try {
sendSysMsgService.sendSingleRoomMessage(room.getRoomId(), sender.toString(), attach);
} catch (Exception e) {
log.error("BaseSendService-批量发送房间消息失败[room={}, message={}]", JSON.toJSONString(room), JSONObject.toJSONString(attach), e);
}
});
}
}
}
/**
* 发送通用聊天处理窗口,
* @param senderUid

View File

@@ -3,7 +3,6 @@ package com.accompany.business.service;
import cn.hutool.core.util.StrUtil;
import com.accompany.business.enums.message.ResourceTypeEnum;
import com.accompany.business.param.neteasepush.*;
import com.accompany.business.service.room.RoomQueryService;
import com.accompany.business.vo.message.FloatingMessageTemplate;
import com.accompany.business.vo.message.MessageTemplate;
import com.accompany.common.config.SystemConfig;
@@ -20,6 +19,7 @@ import com.accompany.core.base.SpringContextHolder;
import com.accompany.core.enumeration.I18nAlertEnum;
import com.accompany.core.model.Account;
import com.accompany.core.model.Room;
import com.accompany.core.mybatismapper.RoomMapperExpand;
import com.accompany.core.service.account.AccountService;
import com.accompany.core.service.base.BaseService;
import com.accompany.core.util.I18NMessageSourceUtil;
@@ -36,7 +36,6 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
@@ -55,11 +54,6 @@ public class SendSysMsgService extends BaseService {
public static final int MSG_TYPE_FOR_CUSTOM = 100;
/**
* 一次性批量发送的房间数量
**/
private static final Integer BATCH_SIZE = 100;
@Autowired
private ErBanNetEaseService erBanNetEaseService;
@@ -67,7 +61,7 @@ public class SendSysMsgService extends BaseService {
private ThreadPoolExecutor asyncExecutor;
@Autowired
private RoomQueryService roomQueryService;
private RoomMapperExpand roomMapperExpand;
/**
* 发送系统通知,捕获异常不抛出。
@@ -479,65 +473,17 @@ public class SendSysMsgService extends BaseService {
}
public void sendTemplateMessage(Long roomId, Long fromAccId, Integer first, Integer second, MessageTemplate message) {
String msgId = UUIDUtil.get();
Attach attach = new Attach();
attach.setFirst(first);
attach.setSecond(second);
attach.setData(message);
try {
erBanNetEaseService.sendChatRoomMsg(roomId, msgId, String.valueOf(fromAccId), Constant.DefineProtocol.CUSTOM_MESS_DEFINE, JSON.toJSONString(attach), null);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
sendSingleRoomMessage(roomId, fromAccId.toString(), first, second, message);
}
public void sendTemplateMessage(MessageTemplate message) {
Integer partitionId = message.getPartitionId();
long count = this.roomQueryService.countValidRooms();
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;
List<Room> validRooms = this.roomQueryService.listValidRooms(index, BATCH_SIZE);
validRooms.sort(Comparator.comparing(Room::getOnlineNum).reversed());
for (Room room : validRooms) {
if (partitionId != null && room.getPartitionId() != null && !partitionId.equals(room.getPartitionId())) {
continue;
}
asyncExecutor.execute(() -> {
try {
sendTemplateMessage(room.getRoomId(), room.getUid(), Constant.DefMsgType.GENERAL_MESSAGE, Constant.DefMsgType.GENERAL_MESSAGE_ALL_ROOM, message);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={}, message={}]", JSON.toJSONString(room), message, e);
}
});
}
}
log.info("发送所有有效房间消息,房间数:{}", count);
sendTemplateMessage(Constant.DefMsgType.GENERAL_MESSAGE, Constant.DefMsgType.GENERAL_MESSAGE_ALL_ROOM, message);
}
public void sendTemplateMessage(Integer first, Integer second, MessageTemplate message) {
Integer partitionId = message.getPartitionId();
long count = this.roomQueryService.countValidRooms();
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;
List<Room> validRooms = this.roomQueryService.listValidRooms(index, BATCH_SIZE);
validRooms.sort(Comparator.comparing(Room::getOnlineNum).reversed());
for (Room room : validRooms) {
if (partitionId != null && room.getPartitionId() != null && !partitionId.equals(room.getPartitionId())) {
continue;
}
asyncExecutor.execute(() -> {
try {
sendTemplateMessage(room.getRoomId(), room.getUid(), first, second, message);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={}, message={}]", JSON.toJSONString(room), message, e);
}
});
}
}
log.info("发送所有有效房间消息,房间数:{}", count);
Attach attach = new Attach(first, second, message);
sendMessageToPartition(message.getPartitionId(), attach);
}
public void sendSingleRoomMessage(Room room, Integer first, Integer second, Object data) {
@@ -578,25 +524,36 @@ public class SendSysMsgService extends BaseService {
public void sendSingleRoomMessage(Long roomId, String fromAccId, Attach attach) {
asyncExecutor.execute(()->{
try {
this.erBanNetEaseService.sendChatRoomMsg(roomId, UUIDUtil.get(), fromAccId, Constant.DefineProtocol.CUSTOM_MESS_DEFINE, JSON.toJSONString(attach), null);
String msgId = UUIDUtil.get();
this.erBanNetEaseService.sendChatRoomMsg(roomId, msgId, fromAccId, Constant.DefineProtocol.CUSTOM_MESS_DEFINE, JSON.toJSONString(attach));
} catch (Exception e) {
log.error("发送房间消息失败[roomId : {}, fromAccId : {}, message : {}]", roomId, fromAccId, JSON.toJSONString(attach), e);
}
});
}
public void sendMessageToPartition(Integer partitionId, int first, int second, Object data) {
Attach attach = new Attach(first, second, data);
sendMessageToPartition(partitionId, attach);
}
public void sendMessageToPartition(Integer partitionId, Attach attach) {
BaseChatRoomMsg msg = BaseChatRoomMsg.buildBaseChatRoomMsg(attach);
sendMessageToPartition(partitionId, msg);
}
public void sendMessageToPartition(Room curRoom, int first, int second, Object data) {
Attach attach = new Attach(first, second, data);
sendMessageToPartition(curRoom, attach);
}
public void sendMessageToPartition(Room curRoom, Attach attach) {
BaseChatRoomMsg msg = BaseChatRoomMsg.buildBaseChatRoomMsg(attach);
sendMessageToPartition(curRoom, msg);
}
public void sendMessageToPartition(Room curRoom, BaseChatRoomMsg msg) {
List<Room> validRooms = this.roomQueryService.listValidRoomsByPartitionId(curRoom.getUid(), curRoom.getPartitionId());
List<Room> validRooms = this.roomMapperExpand.listValidRoomsByPartitionId(curRoom.getUid(), curRoom.getPartitionId());
if (CollectionUtils.isEmpty(validRooms)){
validRooms = new ArrayList<>();
}
@@ -620,7 +577,7 @@ public class SendSysMsgService extends BaseService {
}
public void sendMessageToPartition(Integer partitionId, BaseChatRoomMsg msg) {
List<Room> validRooms = this.roomQueryService.listValidRoomsByPartitionId(null, partitionId);
List<Room> validRooms = this.roomMapperExpand.listValidRoomsByPartitionId(null, partitionId);
if (CollectionUtils.isEmpty(validRooms)){
return;
}
@@ -643,7 +600,7 @@ public class SendSysMsgService extends BaseService {
}
public void sendFloatingMessageForRoom(FloatingMessageTemplate message) {
List<Room> validRooms = this.roomQueryService.listValidRoomsByPartitionId(null, message.getPartitionId());
List<Room> validRooms = this.roomMapperExpand.listValidRoomsByPartitionId(null, message.getPartitionId());
if (CollectionUtils.isEmpty(validRooms)){
return;
}

View File

@@ -11,29 +11,21 @@ import com.accompany.business.service.SendSysMsgService;
import com.accompany.business.service.findlove.FindLoveMsgService;
import com.accompany.business.service.prize.PrizeContext;
import com.accompany.business.service.prize.PrizeStrategyFactory;
import com.accompany.business.service.room.RoomQueryService;
import com.accompany.business.service.room.RoomService;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.openbox.BoxPrizePushMsg;
import com.accompany.common.config.WebSecurityConfig;
import com.accompany.common.constant.Attach;
import com.accompany.common.constant.Constant;
import com.accompany.common.netease.neteaseacc.constant.NetEaseCode;
import com.accompany.common.netease.neteaseacc.result.RubbishRet;
import com.accompany.common.push.MarkdownMessage;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.common.utils.HttpUtils;
import com.accompany.common.utils.UUIDUtil;
import com.accompany.core.base.SpringContextHolder;
import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.accompany.core.service.SysConfService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.message.MessageRobotPushService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -54,12 +46,8 @@ public class BoxPrizeMessageService {
@Autowired
private RoomService roomService;
@Autowired
private RoomQueryService roomQueryService;
@Autowired
private UsersService usersService;
@Autowired
private JedisService jedisService;
@Autowired
private SysConfService sysConfService;
@Autowired
private ApplicationContext applicationContext;
@@ -74,13 +62,6 @@ public class BoxPrizeMessageService {
@Autowired
private SendSysMsgService sendSysMsgService;
/**
* 一次性批量发送的房间数量
**/
private static final Integer BATCH_SIZE = 100;
private Gson gson = new Gson();
/**
* 处理中奖消息逻辑
*

View File

@@ -21,9 +21,7 @@ import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
@@ -81,11 +79,10 @@ public class BravoGiftSendService {
sendMq(recordMap, incomeAllot);
asyncSettlement(config, senderUid, gift, everyGiftNum, recordMap, room);
settlement(config, senderUid, gift, everyGiftNum, recordMap, room);
}
@Async
public void asyncSettlement(BravoGiftConfig config, long senderUid, Gift gift, int everyGiftNum,
public void settlement(BravoGiftConfig config, long senderUid, Gift gift, int everyGiftNum,
Map<Long, BravoRecord> recordMap, Room room) {
BigDecimal totalInput = BigDecimal.valueOf(recordMap.size() * everyGiftNum * gift.getGoldPrice());
BigDecimal totalOutput = recordMap.values().stream().map(BravoRecord::getWinGoldNum).reduce(BigDecimal.ZERO, BigDecimal::add);

View File

@@ -19,8 +19,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@Service
@@ -32,6 +34,8 @@ public class BravoMsgSendService {
private UsersService usersService;
@Autowired
private PartitionInfoService partitionInfoService;
@Resource(name = "async-executor")
private ThreadPoolExecutor asyncExecutor;
public void sendRoomMsg(BravoGiftConfig config, long senderUid, Room room,
Gift gift, Map<Long, BravoRecord> recordMap,
@@ -47,13 +51,17 @@ public class BravoMsgSendService {
//飘屏
if (winGoldNum.compareTo(config.getSpecialFloatValue()) >= 0) {
BaseChatRoomMsg floatingMsg = buildFloatingMsg(sender, room, gift, winGoldNum, afterMultiple);
sendSysMsgService.sendMessageToPartition(room, floatingMsg);
asyncExecutor.execute(()->{
BaseChatRoomMsg floatingMsg = buildFloatingMsg(sender, room, gift, winGoldNum, afterMultiple);
sendSysMsgService.sendMessageToPartition(room, floatingMsg);
});
}
if (winGoldNum.compareTo(config.getAllRoomChatToastValue()) >= 0){
BaseChatRoomMsg screenMsg = buildRoomScreen(sender, room, gift, winGoldNum);
sendSysMsgService.sendMessageToPartition(room, screenMsg);
asyncExecutor.execute(()->{
BaseChatRoomMsg screenMsg = buildRoomScreen(sender, room, gift, winGoldNum);
sendSysMsgService.sendMessageToPartition(room, screenMsg);
});
}
}

View File

@@ -230,7 +230,7 @@ public class Lucky24GiftSendService {
userMetaService.updateUserMeta(senderUid, partitionId, everyoneGoldNum, winGoldNum);
if (winGoldNum > 0L){
settlementService.syncSendReward(config, senderUid, room, gift, winGoldNum, afterMultiple);
settlementService.sendReward(config, senderUid, room, gift, winGoldNum, afterMultiple);
}
return recordService.buildRecord(senderUid, partitionId, gift, giftNum, null != room? room.getUid(): null,

View File

@@ -5,45 +5,24 @@ import com.accompany.business.dto.linearlypool.LinearlyPoolConfigDTO;
import com.accompany.business.event.linearlypool.LinearlyPoolPrizeEvent;
import com.accompany.business.message.PrizeEntity;
import com.accompany.business.message.linearlypool.LinearlyPoolPrizeMessage;
import com.accompany.business.param.neteasepush.Payload;
import com.accompany.business.service.SendSysMsgService;
import com.accompany.business.service.prize.PrizeContext;
import com.accompany.business.service.prize.PrizeStrategyFactory;
import com.accompany.business.service.room.RoomQueryService;
import com.accompany.business.service.room.RoomService;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.linearlypool.PrizePushMsg;
import com.accompany.common.config.SystemConfig;
import com.accompany.common.constant.Attach;
import com.accompany.common.constant.Constant;
import com.accompany.common.netease.ErBanNetEaseService;
import com.accompany.common.netease.neteaseacc.constant.NetEaseCode;
import com.accompany.common.netease.neteaseacc.result.RubbishRet;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.common.utils.HttpUtils;
import com.accompany.common.utils.UUIDUtil;
import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
/**
* Created by PaperCut on 2018/7/16.
@@ -55,25 +34,13 @@ public class LinearlyPoolPrizeMessageService {
@Autowired
PrizeStrategyFactory factory;
@Autowired
ErBanNetEaseService erBanNetEaseService;
@Autowired
RoomService roomService;
@Autowired
RoomQueryService roomQueryService;
@Autowired
UsersService usersService;
@Resource(name = "async-executor")
private ThreadPoolExecutor asyncExecutor;
@Autowired
JedisService jedisService;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private LinearlyPrizePoolService linearlyPrizePoolService;
/** 一次性批量发送的房间数量 **/
private static final Integer BATCH_SIZE = 100;
private Gson gson = new Gson();
@Autowired
private SendSysMsgService sendSysMsgService;

View File

@@ -30,7 +30,7 @@ public class BravoSettlementService {
@Autowired
private BravoMsgSendService msgSendService;
@Async
@Async("bizExecutor")
public void sendReward(BravoGiftConfig config, long senderUid, Room room,
Gift gift, Map<Long, BravoRecord> recordMap,
BigDecimal winGoldNum, BigDecimal afterMultiple){

View File

@@ -25,11 +25,7 @@ public class Lucky24SettlementService {
@Autowired
private SuperLuckyGiftSendService superLuckyGiftSendService;
public void syncSendReward(Lucky24GiftConfig config, long senderUid, Room room, Gift gift, long winGoldNum, long afterMultiple){
sendReward(config, senderUid, room, gift, winGoldNum, afterMultiple);
}
@Async
@Async("bizExecutor")
public void sendReward(Lucky24GiftConfig config, long senderUid, Room room, Gift gift, long winGoldNum, long afterMultiple){
// 道具奖励
double winGoldNumD = (double) winGoldNum;

View File

@@ -1,15 +1,12 @@
package com.accompany.business.service.redenvelope.strategv2;
import com.accompany.business.constant.redenvelope.RedEnvelopeRedisKey;
import com.accompany.business.dto.redenvelope.RedEnvelopeV2NotifyDTO;
import com.accompany.business.model.UserPurse;
import com.accompany.business.model.redenvelope.RedEnvelope;
import com.accompany.business.service.BaseSendService;
import com.accompany.business.service.SendSysMsgService;
import com.accompany.business.service.purse.UserPurseService;
import com.accompany.business.service.record.BillRecordService;
import com.accompany.business.service.redenvelope.RedEnvelopeService;
import com.accompany.business.service.redenvelope.RedEnvelopeV2Service;
import com.accompany.business.service.room.RoomService;
import com.accompany.business.service.user.UsersService;
import com.accompany.common.constant.Constant;
@@ -20,7 +17,6 @@ import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RDeque;
import org.redisson.api.RSet;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.LongCodec;
@@ -45,12 +41,6 @@ public abstract class AbstractRedEnvelopeV2Strategy implements IRedEnvelopeV2Str
@Autowired
protected RedEnvelopeService redEnvelopeService;
@Autowired
protected RedEnvelopeV2Service redEnvelopeV2Service;
@Autowired
protected BaseSendService baseSendService;
@Autowired
protected SendSysMsgService sendSysMsgService;
@@ -126,7 +116,7 @@ public abstract class AbstractRedEnvelopeV2Strategy implements IRedEnvelopeV2Str
sendRedEnvelopeNotify.setRoomTitle(room.getTitle());
}
sendRedEnvelopeNotify.setRedEnvelopeNum(redEnvelopes.size());
baseSendService.sendMessageToAllValidRooms(context.getUid(), Constant.DefMsgType.RedPackage, Constant.DefMsgType.newRedPackage, sendRedEnvelopeNotify);
sendSysMsgService.sendMessageToPartition(room, Constant.DefMsgType.RedPackage, Constant.DefMsgType.newRedPackage, sendRedEnvelopeNotify);
}
protected RedEnvelope buildRedEnvelope(RedEnvelopeV2Context context) {

View File

@@ -6,15 +6,12 @@ import com.accompany.business.constant.redenvelope.RedEnvelopTypeEnum;
import com.accompany.business.dto.redenvelope.RedEnvelopeGiftItemDTO;
import com.accompany.business.enums.redenvelope.RedEnvelopeKindEnum;
import com.accompany.business.model.Gift;
import com.accompany.business.model.redenvelope.RedEnvelope;
import com.accompany.business.model.redenvelope.RedEnvelopeGift;
import com.accompany.business.model.redenvelope.RedEnvelopeItem;
import com.accompany.business.service.BaseSendService;
import com.accompany.business.service.gift.GiftService;
import com.accompany.business.service.redenvelope.RedEnvelopeGiftItemService;
import com.accompany.business.service.redenvelope.RedEnvelopeGiftService;
import com.accompany.business.service.user.UserBackpackService;
import com.accompany.business.vo.GiftVo;
import com.accompany.business.vo.redenvelope.OpenRedEnvelopeResponse;
import com.accompany.business.vo.redenvelope.SendRedEnvelopeV2Request;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.enumeration.I18nAlertEnum;
@@ -37,7 +34,6 @@ import java.util.Date;
import java.util.List;
import static com.accompany.business.constant.redenvelope.RedEnvelopeRedisKey.red_envelop_gift_list;
import static com.accompany.business.constant.redenvelope.RedEnvelopeRedisKey.red_envelop_list;
@Slf4j
@Component
@@ -51,9 +47,10 @@ public class ServerGiftRedEnvelopeV2Strategy extends AbstractRedEnvelopeV2Strate
private RedEnvelopeGiftService redEnvelopeGiftService;
@Autowired
private RedEnvelopeGiftItemService redEnvelopeGiftItemService;
@Autowired
private UserBackpackService userBackpackService;
@Autowired
private BaseSendService baseSendService;
@Override
public Long calRedEnvelopeTotalGoldNum(RedEnvelopeV2Context context) {

View File

@@ -5,6 +5,7 @@ import com.accompany.business.constant.redenvelope.RedEnvelopStateEnum;
import com.accompany.business.constant.redenvelope.RedEnvelopTypeEnum;
import com.accompany.business.enums.redenvelope.RedEnvelopeKindEnum;
import com.accompany.business.model.redenvelope.RedEnvelope;
import com.accompany.business.service.BaseSendService;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.enumeration.BillObjTypeEnum;
import com.accompany.core.enumeration.I18nAlertEnum;
@@ -16,6 +17,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.redisson.api.RDeque;
import org.redisson.api.RSet;
import org.redisson.client.codec.IntegerCodec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -29,6 +31,9 @@ import static com.accompany.business.constant.redenvelope.RedEnvelopeRedisKey.re
@Qualifier("serverGoldRedEnvelopeV2Strategy")
public class ServerGoldRedEnvelopeV2Strategy extends AbstractRedEnvelopeV2Strategy {
@Autowired
private BaseSendService baseSendService;
@Override
public Long calRedEnvelopeTotalGoldNum(RedEnvelopeV2Context context) {
return context.getGoldNum();

View File

@@ -13,6 +13,7 @@ import com.accompany.business.model.relation.RelationUser;
import com.accompany.business.model.user.UserSetting;
import com.accompany.business.mybatismapper.relation.RelationUserMapper;
import com.accompany.business.service.BaseSendService;
import com.accompany.business.service.SendSysMsgService;
import com.accompany.business.service.activity.h5.ActivityOfCpService;
import com.accompany.business.service.gift.GiftService;
import com.accompany.business.service.purse.UserPurseService;
@@ -94,6 +95,8 @@ public class RelationUserServiceImpl extends ServiceImpl<RelationUserMapper, Rel
private ActivityOfCpService activityOfCpService;
@Autowired
private RelationNameChangeRecordService relationNameChangeRecordService;
@Autowired
private SendSysMsgService sendSysMsgService;
public void calCpInfo(GiftMessage message) {
Long sendUid = message.getSendUid();
@@ -168,7 +171,7 @@ public class RelationUserServiceImpl extends ServiceImpl<RelationUserMapper, Rel
.roomUid(roomUid)
.giftUrl(gift.getPicUrl())
.build();
baseSendService.sendMessageToAllValidRooms(sendUid, CP_FIRST, CP_SECOND_GIFT, build);
sendSysMsgService.sendMessageToPartition(users.getPartitionId(), CP_FIRST, CP_SECOND_GIFT, build);
}
if (beginCp) {
CPGiftScreenDTO build = CPGiftScreenDTO.builder()
@@ -180,7 +183,7 @@ public class RelationUserServiceImpl extends ServiceImpl<RelationUserMapper, Rel
.roomUid(roomUid)
.giftUrl(gift.getPicUrl())
.build();
baseSendService.sendMessageToAllValidRooms(sendUid, CP_FIRST, CP_SECOND_BIND, build);
sendSysMsgService.sendMessageToPartition(users.getPartitionId(), CP_FIRST, CP_SECOND_BIND, build);
}
if (plusLevel > 0) {//642
String sendSys = I18NMessageSourceUtil.getMessage(I18nAlertEnum.CP_LEVEL_UPGRADE_SYS, new Object[]{recvUser.getNick(), totalLevel}, recvUser.getPartitionId());
@@ -198,7 +201,7 @@ public class RelationUserServiceImpl extends ServiceImpl<RelationUserMapper, Rel
.roomUid(roomUid)
.cpLevel(totalLevel)
.build();
baseSendService.sendMessageToAllValidRooms(sendUid, CP_FIRST, CP_SECOND_UPGRADE, build);
sendSysMsgService.sendMessageToPartition(users.getPartitionId(), CP_FIRST, CP_SECOND_UPGRADE, build);
}
}

View File

@@ -89,7 +89,7 @@ public interface CrossRoomPkRoundService extends IService<CrossRoomPkRound> {
void loadCrossRoomPkTask(Long roundId, Date planEndTime);
void sendCrossRoomPkResultMsg(Room winRoom, Room anotherRoom, Room room, Byte pkType);
void sendCrossRoomPkResultMsg(Room winRoom, Room anotherRoom, Byte pkType);
/**
* 结束个播PK的惩罚阶段

View File

@@ -1,19 +1,13 @@
package com.accompany.business.service.room;
import com.accompany.common.netease.ErBanNetEaseService;
import com.accompany.common.netease.neteaseacc.constant.NetEaseCode;
import com.accompany.common.netease.neteaseacc.result.RoomRet;
import com.accompany.common.netease.neteaseacc.result.RoomUserListRet;
import com.accompany.common.netease.neteaseacc.result.RubbishRet;
import com.accompany.common.utils.BlankUtil;
import com.accompany.core.model.Room;
import com.accompany.core.service.base.BaseService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -33,12 +27,8 @@ public class RoomCleanService extends BaseService {
*/
private static final int ROOM_RELUSER_PERMIT = 0;
@Autowired
private RoomService roomService;
@Autowired
private ErBanNetEaseService erBanNetEaseService;
@Autowired
private RoomQueryService roomQueryService;
/**
* 判断是否有真实用户在房间内
@@ -88,45 +78,6 @@ public class RoomCleanService extends BaseService {
return false;
}
/**
* 同步房间状态
*
* 部分房间数据库的状态与云信状态不一致,由此处理
*
* @return
*/
public long syncRoomStatus() {
int batchSize = 1000;
long result = 0;
long count = this.roomQueryService.countValidRooms();
long times = count % batchSize == 0 ? (count / batchSize) : (count / batchSize) + 1;
for (int i = 0; i < times; i++) {
int index = i * batchSize;
List<Room> rooms = roomQueryService.listValidRooms(index, batchSize);
for (Room room : rooms) {
try {
RoomRet roomRet = erBanNetEaseService.getRoomMessage(room.getRoomId());
logger.info("查询返回结果:{}", gson.toJson(roomRet));
if (null == roomRet || roomRet.getCode() != NetEaseCode.SUCCESS.value()
|| null == roomRet.getChatroom()) {
continue;
}
Object obj = roomRet.getChatroom().get("valid");
if (null != obj && Boolean.FALSE.equals(obj)) {
room.setValid(false);
room.setUpdateTime(new Date());
roomService.updateDbAndCacheRoomInfo(room);
result++;
}
} catch (Exception e) {
logger.error("查询房间信息异常房间id:{},异常信息:\n{}", room.getRoomId(), ExceptionUtils.getStackTrace(e));
}
}
}
return result;
}
private boolean hasRealUserCount(List<Map<String, Object>> list, int onlineNum, int limitCount) throws Exception {
for (Map<String, Object> userMap : list) {
if (userMap.get("isRobot") != null) {

View File

@@ -1,47 +0,0 @@
package com.accompany.business.service.room;
import com.accompany.core.model.Room;
import com.accompany.core.mybatismapper.RoomMapperExpand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RoomQueryService {
@Autowired
private RoomMapperExpand roomExpandMapper;
public Long countValidRooms(){
return this.roomExpandMapper.countValidRooms();
}
public List<Room> listValidRooms(Integer index, Integer pageSize){
return this.roomExpandMapper.listValidRooms(index, pageSize);
}
public long countValidRoomsExcludePlayroom(Long roomId) {
return this.roomExpandMapper.countValidRoomsExcludePlayroom(roomId);
}
public List<Room> listValidRoomsExcludePlayroom(Long roomId, Integer index, Integer pageSize) {
return this.roomExpandMapper.listValidRoomsExcludePlayroom(roomId, index, pageSize);
}
public List<Room> listValidRoomsByTag(Integer index, Integer pageSize, String roomTag){
return this.roomExpandMapper.listValidRoomsByTag(index, pageSize, roomTag);
}
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);
}
}

View File

@@ -1799,6 +1799,12 @@ public class RoomService extends BaseService {
if (null == roomVo) {
continue;
}
if (Boolean.FALSE.equals(roomInfo.getVaild())){
closeRoom(roomVo.getUid());
continue;
}
int personNum = roomInfo.getOnlineusercount();
RunningRoomVo runningRoomVo = new RunningRoomVo();
if (personNum > 0) {
@@ -1823,7 +1829,7 @@ public class RoomService extends BaseService {
//5分钟一次7天
if (runningRoomVo.getCount() >= 288 * 7) {
closeRoom(roomVo.getUid());
return;
continue;
}
runningRoomVo.setRoomId(roomVo.getRoomId());

View File

@@ -44,7 +44,6 @@ import com.accompany.core.service.SysConfService;
import com.accompany.core.service.common.JedisLockService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.util.I18NMessageSourceUtil;
import com.accompany.core.util.PartitionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -103,9 +102,6 @@ public class CrossRoomPkRoundServiceImpl extends ServiceImpl<CrossRoomPkRoundMap
@Autowired
private UsersService usersService;
@Autowired
private RoomQueryService roomQueryService;
@Autowired
private RoomQueueMicroService roomQueueMicroService;
@@ -121,11 +117,6 @@ public class CrossRoomPkRoundServiceImpl extends ServiceImpl<CrossRoomPkRoundMap
@Autowired
private CrossRoomPkRoundMapper crossRoomPkRoundMapper;
/**
* 一次性批量发送的房间数量
**/
private static final Integer BATCH_SIZE = 800;
protected Gson gson = new Gson();
@Override
@@ -787,14 +778,14 @@ public class CrossRoomPkRoundServiceImpl extends ServiceImpl<CrossRoomPkRoundMap
if (ObjectUtil.isNotNull(winRoom) && ObjectUtil.isNotNull(failRoom)
&& (sumScore >= crossRoomPkNotifyDto.getAllRoomMinScore() || diffScore >= crossRoomPkNotifyDto.getAllRoomGapScore())) {
//按当前产品给出的数据此处条件会覆盖下面的条件避免重复发送直接return
log.info("结束跨房pk场次{}所有房间飘屏通知", roundId, winRoomUid);
sendMessageToAllValidRooms(winRoom, failRoom, round.getPkType());
log.info("结束跨房pk场次{}所有房间飘屏通知", roundId);
SpringContextHolder.getBean(CrossRoomPkRoundService.class).sendCrossRoomPkResultMsg(winRoom, anotherRoom, pkType);
return;
}
if (ObjectUtil.isNotNull(winRoom) && ObjectUtil.isNotNull(failRoom)
&& (sumScore >= crossRoomPkNotifyDto.getSameTypeMinScore() || diffScore >= crossRoomPkNotifyDto.getSameTypeGapScore())) {
log.info("结束跨房pk场次{}触发同类型房间飘屏通知", roundId, winRoomUid);
sendMessageToSameTag(winRoom, failRoom, round.getPkType());
log.info("结束跨房pk场次{}触发同类型房间飘屏通知", roundId);
SpringContextHolder.getBean(CrossRoomPkRoundService.class).sendCrossRoomPkResultMsg(winRoom, anotherRoom, pkType);
return;
}
@@ -1003,7 +994,6 @@ public class CrossRoomPkRoundServiceImpl extends ServiceImpl<CrossRoomPkRoundMap
}
}
public CrossRoomPkPanelDto initPkPanel(Room currentRoom, Room anotherRoom, Long beginTime, Long endTime, Byte pkType) {
CrossRoomPkPanelDto panelDto = new CrossRoomPkPanelDto();
panelDto.setInit(true);
@@ -1160,115 +1150,51 @@ public class CrossRoomPkRoundServiceImpl extends ServiceImpl<CrossRoomPkRoundMap
}
/**
* 发送所有有效房间消息
*
* @param winRoom
* @param anotherRoom
* @param pkType
*/
public long sendMessageToAllValidRooms(Room winRoom, Room anotherRoom, Byte pkType) {
long count = roomQueryService.countValidRooms();
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;
List<Room> validRooms = roomQueryService.listValidRooms(index, BATCH_SIZE);
validRooms.sort(Comparator.comparing(Room::getOnlineNum).reversed());
for (Room room : validRooms) {
if (!PartitionUtil.equalsPartition(winRoom.getPartitionId(), room.getPartitionId())){
continue;
}
//if (room.getRoomId().equals(winRoom.getRoomId())) continue;
//if (room.getRoomId().equals(anotherRoom.getRoomId())) continue;
SpringContextHolder.getBean(CrossRoomPkRoundService.class).sendCrossRoomPkResultMsg(winRoom, anotherRoom, room, pkType);
}
List<Long> roomUidList = validRooms.stream().map(Room::getUid).collect(Collectors.toList());
log.info("给以下有效房间发送飘屏消息{}", gson.toJson(roomUidList));
}
log.info("跨房PK发送所有有效房间消息房间数{}", count);
return count;
}
/**
* 发送所有有效房间消息
*
* @param winRoom
* @param anotherRoom
* @param pkType
*/
public long sendMessageToSameTag(Room winRoom, Room anotherRoom, Byte pkType) {
if (StringUtils.isEmpty(winRoom.getRoomTag())) return 0;
long count = roomQueryService.countValidRooms();
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;
List<Room> validRooms = roomQueryService.listValidRoomsByTag(index, BATCH_SIZE, winRoom.getRoomTag());
for (Room room : validRooms) {
if (!PartitionUtil.equalsPartition(winRoom.getPartitionId(), room.getPartitionId())){
continue;
}
//if (room.getRoomId().equals(winRoom.getRoomId())) continue;
//if (room.getRoomId().equals(anotherRoom.getRoomId())) continue;
SpringContextHolder.getBean(CrossRoomPkRoundService.class).sendCrossRoomPkResultMsg(winRoom, anotherRoom, room, pkType);
}
List<Long> roomUidList = validRooms.stream().map(Room::getUid).collect(Collectors.toList());
log.info("给以下房间{}发送相同标签类型有效有效房间消息", gson.toJson(roomUidList));
}
log.info("发送相同标签类型有效有效房间消息,房间数:{}", count);
return count;
}
@Async
public void sendCrossRoomPkResultMsg(Room winRoom, Room anotherRoom, Room room, Byte pkType) {
public void sendCrossRoomPkResultMsg(Room winRoom, Room anotherRoom, Byte pkType) {
String title = winRoom.getTitle();
Integer maxWordsNum = Integer.valueOf(sysConfService.getDefaultSysConfValueById(Constant.SysConfId.CROSS_ROOM_PK_NOTIFY_TITLE_MAX_NUM, String.valueOf(Constant.CrossRoomPkConstant.room_notify_title_max_num)));
if (title.length() > maxWordsNum) {
title = title.substring(0, maxWordsNum) + "...";
}
String msg = I18NMessageSourceUtil.getMessage(I18nAlertEnum.CROSS_ROOM_PK_ROOM_NOTIFY_MSG, new Object[]{title}, winRoom.getUid());
try {
Users winUsers = usersService.getUsersByUid(winRoom.getUid());
Users anotherUsers = usersService.getUsersByUid(anotherRoom.getUid());
Attach attach = new Attach();
attach.setFirst(Constant.DefineProtocol.CROSS_ROOM_PK_MSG);
int second;
if (Constant.RoomPkType.SINGLE_ROOM_PK.equals(pkType)) {
second = Constant.DefineProtocol.CROSS_ROOM_PK_SINGLE_ROOM_RESULT_MSG;
} else {
second = Constant.DefineProtocol.CROSS_ROOM_PK_RESULT_MSG;
}
attach.setSecond(second);
Users winUsers = usersService.getUsersByUid(winRoom.getUid());
Users anotherUsers = usersService.getUsersByUid(anotherRoom.getUid());
JSONObject jsonObject = new JSONObject();
//获胜方房间uid
jsonObject.put("winUid", winRoom.getUid());
//获胜方房间名称
jsonObject.put("winTitle", winRoom.getTitle());
//获胜方房间头像
jsonObject.put("winAvatar", winUsers.getAvatar());
jsonObject.put("winNick", winUsers.getNick());
//另一方房间uid
jsonObject.put("failUid", anotherRoom.getUid());
//另一方房间名称
jsonObject.put("failTitle", anotherRoom.getTitle());
//另一方房间头像
jsonObject.put("failAvatar", anotherUsers.getAvatar());
jsonObject.put("failNick", anotherUsers.getNick());
//消息内容
jsonObject.put("msg", msg);
attach.setData(jsonObject);
String attachStr = gson.toJson(attach);
erBanNetEaseService.sendChatRoomMsg(room.getRoomId(), UUIDUtil.get(), room.getUid().toString(), Constant.DefineProtocol.CUSTOM_MESS_DEFINE, attachStr, 1);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={}, message={}]", gson.toJson(room), msg, e);
Attach attach = new Attach();
attach.setFirst(Constant.DefineProtocol.CROSS_ROOM_PK_MSG);
int second;
if (Constant.RoomPkType.SINGLE_ROOM_PK.equals(pkType)) {
second = Constant.DefineProtocol.CROSS_ROOM_PK_SINGLE_ROOM_RESULT_MSG;
} else {
second = Constant.DefineProtocol.CROSS_ROOM_PK_RESULT_MSG;
}
attach.setSecond(second);
JSONObject jsonObject = new JSONObject();
//获胜方房间uid
jsonObject.put("winUid", winRoom.getUid());
//获胜方房间名称
jsonObject.put("winTitle", winRoom.getTitle());
//获胜方房间头像
jsonObject.put("winAvatar", winUsers.getAvatar());
jsonObject.put("winNick", winUsers.getNick());
//另一方房间uid
jsonObject.put("failUid", anotherRoom.getUid());
//另一方房间名称
jsonObject.put("failTitle", anotherRoom.getTitle());
//另一方房间头像
jsonObject.put("failAvatar", anotherUsers.getAvatar());
jsonObject.put("failNick", anotherUsers.getNick());
//消息内容
jsonObject.put("msg", msg);
attach.setData(jsonObject);
sendSysMsgService.sendMessageToPartition(winRoom, attach);
}
@Override

View File

@@ -35,7 +35,6 @@ import com.accompany.core.model.Room;
import com.accompany.core.model.Users;
import com.accompany.core.service.SysConfService;
import com.accompany.core.util.I18NMessageSourceUtil;
import com.accompany.core.util.MD5;
import com.accompany.core.util.StringUtils;
import com.accompany.sharding.vo.RoomSerialVo;
import com.alibaba.fastjson.JSONObject;
@@ -75,8 +74,6 @@ public class RoomController extends BaseController {
@Autowired
private LiveAttestationService liveAttestationService;
@Autowired
private RoomCleanService roomCleanService;
@Autowired
private BoxCommonService boxCommonService;
@Autowired
private RedEnvelopeService redEnvelopeService;
@@ -487,27 +484,6 @@ public class RoomController extends BaseController {
return new BusiResult(BusiStatus.SUCCESS);
}
@RequestMapping(value = "/syncRoomStatus", method = RequestMethod.POST)
@ResponseBody
public String syncRoomStatus(Long timestamp, String token) {
if (null == timestamp) {
logger.warn("手动同步失败timestamp为空");
return "清理数房间数: 0";
}
if (timestamp + 1800000 < System.currentTimeMillis()) {
logger.warn("手动同步失败timestamp[{}]过期!", timestamp);
return "清理数房间数: 0";
}
String genToken = MD5.getMD5(timestamp + "kR$9i3");
if (!StringUtils.equalsIgnoreCase(token, genToken)) {
logger.warn("手动同步失败token[{}]不正确生成的token:{}", token, genToken);
return "清理数房间数: 0";
}
long result = roomCleanService.syncRoomStatus();
logger.info("同步房间状态完成,清理数:{}", result);
return "清理数房间数:" + result;
}
@ApiOperation("房间可用红包列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "uid", value = "房间UID", required = true),

View File

@@ -2,7 +2,6 @@ package com.accompany.scheduler.task.room;
import com.accompany.business.service.rank.PermitRoomTaskService;
import com.accompany.business.service.room.RoomBackgroundService;
import com.accompany.business.service.room.RoomCleanService;
import com.accompany.scheduler.base.BaseTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -14,23 +13,11 @@ import org.springframework.stereotype.Component;
public class RoomTask extends BaseTask {
private static final Logger logger = LoggerFactory.getLogger(RoomTask.class);
@Autowired
private RoomCleanService roomCleanService;
@Autowired
private PermitRoomTaskService permitRoomTaskService;
@Autowired
private RoomBackgroundService roomBackgroundService;
/**
* 同步房间状态
*/
@Scheduled(cron = "0 15 3 * * ?")
public void syncRoomStatus() {
logger.info("syncRoomStatus start==============");
long result = roomCleanService.syncRoomStatus();
logger.info("syncRoomStatus end============== clean room: {}", result);
}
/**
* 发送牌照房上小时榜单TOP1通知 (每一小时扫描一次)
*/