|
|
|
@@ -1,17 +1,25 @@
|
|
|
|
|
package com.accompany.business.service.chat.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.accompany.business.dto.chat.PublicChatTimeConfig;
|
|
|
|
|
import com.accompany.business.model.chat.PublicChatTopRecord;
|
|
|
|
|
import com.accompany.business.mybatismapper.chat.PublicChatTopRecordMapper;
|
|
|
|
|
import com.accompany.business.service.SendSysMsgService;
|
|
|
|
|
import com.accompany.business.service.chat.PublicChatTopRecordService;
|
|
|
|
|
import com.accompany.business.service.room.RoomService;
|
|
|
|
|
import com.accompany.common.config.SystemConfig;
|
|
|
|
|
import com.accompany.common.constant.Constant;
|
|
|
|
|
import com.accompany.common.redis.RedisKey;
|
|
|
|
|
import com.accompany.common.utils.DateTimeUtil;
|
|
|
|
|
import com.accompany.common.utils.GsonUtil;
|
|
|
|
|
import com.accompany.core.base.UidContextHolder;
|
|
|
|
|
import com.accompany.core.model.PartitionInfo;
|
|
|
|
|
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.partition.PartitionInfoService;
|
|
|
|
|
import com.accompany.core.service.user.UsersBaseService;
|
|
|
|
|
import com.accompany.sharding.mapper.UserChatMsgRecordMapper;
|
|
|
|
|
import com.accompany.sharding.model.UserChatMsgRecord;
|
|
|
|
@@ -19,6 +27,7 @@ import com.accompany.sharding.vo.UserChatMsgRecordVo;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.tomcat.util.bcel.Const;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@@ -40,12 +49,24 @@ public class PublicChatTopRecordServiceImpl extends ServiceImpl<PublicChatTopRec
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserChatMsgRecordMapper userChatMsgRecordMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RoomService roomService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UsersBaseService usersBaseService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JedisService jedisService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysConfService sysConfService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PartitionInfoService partitionInfoService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SendSysMsgService sendSysMsgService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void send(String content) {
|
|
|
|
|
Date now = new Date();
|
|
|
|
@@ -54,9 +75,13 @@ public class PublicChatTopRecordServiceImpl extends ServiceImpl<PublicChatTopRec
|
|
|
|
|
if (users == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Room publicChatRoom = roomService.getRoomByRoomId(Long.valueOf(SystemConfig.publicChatMessageRoomId));
|
|
|
|
|
Integer partitionId = users.getPartitionId();
|
|
|
|
|
//头条记录
|
|
|
|
|
PublicChatTopRecord record = new PublicChatTopRecord();
|
|
|
|
|
if (publicChatRoom != null) {
|
|
|
|
|
record.setRoomUid(publicChatRoom.getUid());
|
|
|
|
|
}
|
|
|
|
|
record.setUid(uid);
|
|
|
|
|
record.setContent(content);
|
|
|
|
|
record.setIsTop(Constant.Yes1No0.NO);
|
|
|
|
@@ -66,7 +91,8 @@ public class PublicChatTopRecordServiceImpl extends ServiceImpl<PublicChatTopRec
|
|
|
|
|
record.setUpdateTime(now);
|
|
|
|
|
save(record);
|
|
|
|
|
//头条缓存
|
|
|
|
|
jedisService.lpush(RedisKey.public_chat_list.getKey(), GsonUtil.getDefGson().toJson(record));
|
|
|
|
|
jedisService.lpush(RedisKey.public_chat_list.getKey(partitionId.toString()), GsonUtil.getDefGson().toJson(record));
|
|
|
|
|
execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@@ -117,4 +143,41 @@ public class PublicChatTopRecordServiceImpl extends ServiceImpl<PublicChatTopRec
|
|
|
|
|
}
|
|
|
|
|
return userChatMsgRecordVos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
|
|
|
|
try {
|
|
|
|
|
PublicChatTimeConfig config = sysConfService.getJsonValueById(Constant.SysConfId.PUBLIC_CHAT_TIME, PublicChatTimeConfig.class);
|
|
|
|
|
if (config == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Integer oneTime = config.getOne();
|
|
|
|
|
Integer processTime = config.getProcess();
|
|
|
|
|
if (oneTime == null || processTime == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
List<PartitionInfo> partitionInfoList = partitionInfoService.listAll();
|
|
|
|
|
for (PartitionInfo partitionInfo : partitionInfoList) {
|
|
|
|
|
Integer partitionId = partitionInfo.getId();
|
|
|
|
|
String redisKey = RedisKey.public_chat_list.getKey(partitionId.toString());
|
|
|
|
|
Long size = jedisService.llen(redisKey);
|
|
|
|
|
String recordStr = jedisService.lpop(redisKey);
|
|
|
|
|
if (StrUtil.isEmpty(recordStr)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
PublicChatTopRecord publicChatTopRecord = GsonUtil.getDefGson().fromJson(recordStr, PublicChatTopRecord.class);
|
|
|
|
|
Date endTime = new Date(now.getTime() + ((size == 1) ? oneTime : processTime));
|
|
|
|
|
publicChatTopRecord.setStartTime(now);
|
|
|
|
|
publicChatTopRecord.setEndTime(endTime);
|
|
|
|
|
publicChatTopRecord.setIsTop(Constant.Yes1No0.YES);
|
|
|
|
|
publicChatTopRecord.setRecordStatus(Constant.Yes1No0.YES);
|
|
|
|
|
updateById(publicChatTopRecord);
|
|
|
|
|
log.info("uid : {}, content : {}, 头条置顶...", publicChatTopRecord.getUid(), publicChatTopRecord.getContent());
|
|
|
|
|
sendSysMsgService.sendCustomMsg(Long.valueOf(SystemConfig.systemMessageUid), publicChatTopRecord.getRoomUid(), Constant.DefMsgType.PUBLIC_CHATROOM, Constant.DefMsgType.PUBLIC_CHATROOM_TOP, publicChatTopRecord);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|