contentTitleMap = discover.getContentTitleMap(longStr);
+ System.out.println(contentTitleMap);
+//
+// Jsoup.connect("http:// www.github.com");
+ stopWatch.stop();
+ long cost = stopWatch.getTotalTimeMillis();
+ System.out.println(cost);
+ }//{http://mallchat.cn=MallChat, www.baidu.com=百度一下,你就知道, https://mp.weixin.qq.com/s/hwTf4bDck9_tlFpgVDeIKg=超大规模数据库集群保稳系列之二:数据库攻防演练建设实践, http://www.jd.com:80=京东(JD.COM)-正品低价、品质保障、配送及时、轻松购物!}
+}
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/discover/WxUrlTitleDiscover.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/discover/WxUrlTitleDiscover.java
new file mode 100644
index 0000000..29b1172
--- /dev/null
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/discover/WxUrlTitleDiscover.java
@@ -0,0 +1,15 @@
+package com.abin.mallchat.common.common.utils.discover;
+
+import org.jsoup.nodes.Document;
+
+/**
+ * Description: 针对微信公众号文章的标题获取类
+ * Author: abin
+ * Date: 2023-05-27
+ */
+public class WxUrlTitleDiscover extends AbstractUrlTitleDiscover {
+ @Override
+ public String getDocTitle(Document document) {
+ return document.getElementsByAttributeValue("property", "og:title").attr("content");
+ }
+}
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/entity/User.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/entity/User.java
index e4f4993..1eda7b4 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/entity/User.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/entity/User.java
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.util.Date;
+import java.util.Objects;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
@@ -99,11 +100,10 @@ public class User implements Serializable {
@TableField("update_time")
private Date updateTime;
- public IpInfo getIpInfo() {
+ public void refreshIp(String ip) {
if (ipInfo == null) {
ipInfo = new IpInfo();
}
- return ipInfo;
+ ipInfo.refreshIp(ip);
}
-
}
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/IpServiceImpl.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/IpServiceImpl.java
index c41fca5..3868051 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/IpServiceImpl.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/IpServiceImpl.java
@@ -45,6 +45,9 @@ public class IpServiceImpl implements IpService, DisposableBean {
executor.execute(() -> {
User user = userDao.getById(uid);
IpInfo ipInfo = user.getIpInfo();
+ if (Objects.isNull(ipInfo)) {
+ return;
+ }
String ip = ipInfo.needRefreshIp();
if (StrUtil.isBlank(ip)) {
return;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java
index d23af39..16f3220 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java
@@ -27,6 +27,8 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
*
@@ -66,7 +68,7 @@ public class ChatController {
return userCache.getBlackMap().get(BlackTypeEnum.UID.getType());
}
- @GetMapping("/public/member/statistic")
+ @GetMapping("public/member/statistic/")
@ApiOperation("群成员人数统计")
public ApiResult getMemberStatistic() {
return ApiResult.success(chatService.getMemberStatistic());
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/domain/vo/response/ChatMessageResp.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/domain/vo/response/ChatMessageResp.java
index fc011da..ce5a89f 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/domain/vo/response/ChatMessageResp.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/domain/vo/response/ChatMessageResp.java
@@ -1,18 +1,12 @@
package com.abin.mallchat.custom.chat.domain.vo.response;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-
-import java.time.LocalDateTime;
import java.util.Date;
-import java.util.List;
+import java.util.Map;
/**
* Description: 消息
@@ -38,6 +32,8 @@ public class ChatMessageResp {
private Long uid;
@ApiModelProperty("头像")
private String avatar;
+ @ApiModelProperty("归属地")
+ private String locPlace;
@ApiModelProperty("徽章标识,如果没有展示null")
private Badge badge;
}
@@ -50,6 +46,8 @@ public class ChatMessageResp {
private Date sendTime;
@ApiModelProperty("消息内容")
private String content;
+ @ApiModelProperty("消息链接映射")
+ private Map urlTitleMap;
@ApiModelProperty("消息类型 1正常文本 2.爆赞 (点赞超过10)3.危险发言(举报超5)")
private Integer type;
@ApiModelProperty("消息标记")
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MessageAdapter.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MessageAdapter.java
index 22c9f64..9acd0c0 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MessageAdapter.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MessageAdapter.java
@@ -2,11 +2,15 @@ package com.abin.mallchat.custom.chat.service.adapter;
import cn.hutool.core.bean.BeanUtil;
import com.abin.mallchat.common.chat.domain.entity.Message;
+import com.abin.mallchat.common.chat.domain.entity.MessageExtra;
import com.abin.mallchat.common.chat.domain.entity.MessageMark;
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
+import com.abin.mallchat.common.common.utils.discover.PrioritizedUrlTitleDiscover;
+import com.abin.mallchat.common.user.domain.entity.IpDetail;
+import com.abin.mallchat.common.user.domain.entity.IpInfo;
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
import com.abin.mallchat.common.user.domain.entity.User;
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
@@ -23,24 +27,32 @@ import java.util.stream.Collectors;
* Date: 2023-03-26
*/
public class MessageAdapter {
- public static final int CAN_CALLBACK_GAP_COUNT = 100;
+ public static final int CAN_CALLBACK_GAP_COUNT = 50;
+ private static final PrioritizedUrlTitleDiscover URL_TITLE_DISCOVER = new PrioritizedUrlTitleDiscover();
public static Message buildMsgSave(ChatMessageReq request, Long uid) {
+
return Message.builder()
.replyMsgId(request.getReplyMsgId())
.content(request.getContent())
.fromUid(uid)
.roomId(request.getRoomId())
.status(MessageStatusEnum.NORMAL.getStatus())
+ .extra(buildExtra(request))
.build();
}
+ private static MessageExtra buildExtra(ChatMessageReq request) {
+ Map contentTitleMap = URL_TITLE_DISCOVER.getContentTitleMap(request.getContent());
+ return MessageExtra.builder().urlTitleMap(contentTitleMap).build();
+ }
+
public static List buildMsgResp(List messages, Map replyMap, Map userMap, List msgMark, Long receiveUid, Map itemMap) {
Map> markMap = msgMark.stream().collect(Collectors.groupingBy(MessageMark::getMsgId));
return messages.stream().map(a -> {
ChatMessageResp resp = new ChatMessageResp();
- resp.setFromUser(buildFromUser(userMap.get(a.getFromUid()),itemMap));
+ resp.setFromUser(buildFromUser(userMap.get(a.getFromUid()), itemMap));
resp.setMessage(buildMessage(a, replyMap, userMap, markMap.getOrDefault(a.getId(), new ArrayList<>()), receiveUid));
return resp;
})
@@ -52,6 +64,7 @@ public class MessageAdapter {
ChatMessageResp.Message messageVO = new ChatMessageResp.Message();
BeanUtil.copyProperties(message, messageVO);
messageVO.setSendTime(message.getCreateTime());
+ messageVO.setUrlTitleMap(Optional.ofNullable(message.getExtra()).map(MessageExtra::getUrlTitleMap).orElse(null));
Message replyMessage = replyMap.get(message.getReplyMsgId());
//回复消息
if (Objects.nonNull(replyMessage)) {
@@ -85,9 +98,10 @@ public class MessageAdapter {
ChatMessageResp.UserInfo userInfo = new ChatMessageResp.UserInfo();
userInfo.setUsername(fromUser.getName());
userInfo.setAvatar(fromUser.getAvatar());
+ userInfo.setLocPlace(Optional.ofNullable(fromUser.getIpInfo()).map(IpInfo::getUpdateIpDetail).map(IpDetail::getCity).orElse(null));
userInfo.setUid(fromUser.getId());
- if(Objects.nonNull(fromUser.getItemId())){
- ChatMessageResp.Badge badge =new ChatMessageResp.Badge();
+ if (Objects.nonNull(fromUser.getItemId())) {
+ ChatMessageResp.Badge badge = new ChatMessageResp.Badge();
ItemConfig itemConfig = itemMap.get(fromUser.getItemId());
badge.setImg(itemConfig.getImg());
badge.setDescribe(itemConfig.getDescribe());
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java
index 001c26f..92afcb0 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java
@@ -16,6 +16,7 @@ import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
import com.abin.mallchat.common.common.exception.BusinessException;
import com.abin.mallchat.common.common.utils.AssertUtil;
+import com.abin.mallchat.common.common.utils.discover.PrioritizedUrlTitleDiscover;
import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
import com.abin.mallchat.common.user.domain.entity.User;
@@ -76,8 +77,6 @@ public class ChatServiceImpl implements ChatService {
/**
* 发送消息
- *
- * @param request
*/
@Override
@Transactional
@@ -90,6 +89,7 @@ public class ChatServiceImpl implements ChatService {
AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
}
+ //同步获取消息的跳转链接标题
Message insert = MessageAdapter.buildMsgSave(request, uid);
messageDao.save(insert);
//如果有回复消息
@@ -224,10 +224,10 @@ public class ChatServiceImpl implements ChatService {
Set uidSet = Stream.concat(replyMap.values().stream().map(Message::getFromUid), messages.stream().map(Message::getFromUid)).collect(Collectors.toSet());
userMap = userCache.getUserInfoBatch(uidSet);
//批量查询item信息
- itemMap = userMap.values().stream().map(User::getItemId).distinct().filter(Objects::nonNull).map(itemCache::getById).collect(Collectors.toMap(ItemConfig::getId,Function.identity()));
+ itemMap = userMap.values().stream().map(User::getItemId).distinct().filter(Objects::nonNull).map(itemCache::getById).collect(Collectors.toMap(ItemConfig::getId, Function.identity()));
//查询消息标志
List msgMark = messageMarkDao.getValidMarkByMsgIdBatch(messages.stream().map(Message::getId).collect(Collectors.toList()));
- return MessageAdapter.buildMsgResp(messages, replyMap, userMap, msgMark, receiveUid,itemMap);
+ return MessageAdapter.buildMsgResp(messages, replyMap, userMap, msgMark, receiveUid, itemMap);
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java
index 1c203ed..14f916a 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java
@@ -45,7 +45,7 @@ public class LoginServiceImpl implements LoginService {
return false;
}
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
- String realToken = redisUtils.getStr(key);
+ String realToken = RedisUtils.getStr(key);
return token.equals(realToken);//有可能token失效了,需要校验是不是和最新token一致
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java
index cb72515..cc1ddb4 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java
@@ -157,7 +157,7 @@ public class WebSocketServiceImpl implements WebSocketService {
boolean online = userCache.isOnline(user.getId());
if (!online) {
user.setLastOptTime(new Date());
- user.getIpInfo().refreshIp(NettyUtil.getAttr(channel, NettyUtil.IP));
+ user.refreshIp(NettyUtil.getAttr(channel, NettyUtil.IP));
applicationEventPublisher.publishEvent(new UserOnlineEvent(this, user));
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java
index 9d44f2d..4c29c67 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java
@@ -67,7 +67,7 @@ public class NettyWebSocketServer {
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
//30秒客户端没有向服务器发送心跳则关闭连接
- pipeline.addLast(new IdleStateHandler(30, 0, 0));
+// pipeline.addLast(new IdleStateHandler(30, 0, 0));
// 因为使用http协议,所以需要使用http的编码器,解码器
pipeline.addLast(new HttpServerCodec());
// 以块方式写,添加 chunkedWriter 处理器
diff --git a/pom.xml b/pom.xml
index eab49bf..4521335 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,6 +44,7 @@
4.1.76.Final
4.4.0
3.4.0
+ 1.15.3
@@ -53,6 +54,11 @@
mallchat-common
${mallchat-common.version}