mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix:1.优化表情包功能
2.优化oss存储路径 3.删除兼容历史代码
This commit is contained in:
@@ -191,3 +191,15 @@ CREATE TABLE `sensitive_word` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='敏感词库';
|
||||
INSERT INTO `sensitive_word` (`word`) VALUES ('TMD');
|
||||
INSERT INTO `sensitive_word` (`word`) VALUES ('tmd');
|
||||
|
||||
DROP TABLE IF EXISTS `user_emoji`;
|
||||
CREATE TABLE `user_emoji` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
`uid` bigint(20) NOT NULL COMMENT '用户表ID',
|
||||
`expression_url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '表情地址',
|
||||
`delete_status` int(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除(0-正常,1-删除)',
|
||||
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `IDX_USER_EMOJIS_UID` (`uid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户表情包';
|
||||
10
docs/version/2023-07-09.sql
Normal file
10
docs/version/2023-07-09.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE `user_emoji` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
`uid` bigint(20) NOT NULL COMMENT '用户表ID',
|
||||
`expression_url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '表情地址',
|
||||
`delete_status` int(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除(0-正常,1-删除)',
|
||||
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `IDX_USER_EMOJIS_UID` (`uid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户表情包';
|
||||
@@ -1,10 +0,0 @@
|
||||
CREATE TABLE `user_emojis` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
`uid` bigint(20) NOT NULL COMMENT '用户表ID',
|
||||
`expression_url` varchar(255) NOT NULL COMMENT '表情地址',
|
||||
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
||||
`delete_status` int(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除(0-正常,1-删除)',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `IDX_USER_EMOJIS_UID` (`uid`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='用户表情包';
|
||||
@@ -22,7 +22,7 @@ public enum MessageTypeEnum {
|
||||
FILE(4, "文件"),
|
||||
SOUND(5, "语音"),
|
||||
VIDEO(6, "视频"),
|
||||
EMOJIS(7, "表情"),
|
||||
EMOJI(7, "表情"),
|
||||
;
|
||||
|
||||
private final Integer type;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.abin.mallchat.common.common.domain.vo.request;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author zhongzb create on 2021/05/31
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IdReqVO {
|
||||
@ApiModelProperty("id")
|
||||
@NotNull
|
||||
private long id;
|
||||
}
|
||||
@@ -136,8 +136,8 @@ public class MinIOTemplate {
|
||||
String uid = Optional.ofNullable(req.getUid()).map(String::valueOf).orElse("000000");
|
||||
cn.hutool.core.lang.UUID uuid = cn.hutool.core.lang.UUID.fastUUID();
|
||||
String suffix = FileNameUtil.getSuffix(req.getFileName());
|
||||
String year = DateUtil.format(new Date(), DatePattern.NORM_YEAR_PATTERN);
|
||||
return req.getFilePath() + StrUtil.SLASH + year + StrUtil.SLASH + uid + StrUtil.SLASH + uuid + StrUtil.DOT + suffix;
|
||||
String yearAndMonth = DateUtil.format(new Date(), DatePattern.NORM_MONTH_PATTERN);
|
||||
return req.getFilePath() + StrUtil.SLASH + yearAndMonth + StrUtil.SLASH + uid + StrUtil.SLASH + uuid + StrUtil.DOT + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.abin.mallchat.common.user.dao;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.abin.mallchat.common.user.mapper.UserEmojiMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表情包 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* @since 2023-07-09
|
||||
*/
|
||||
@Service
|
||||
public class UserEmojiDao extends ServiceImpl<UserEmojiMapper, UserEmoji> {
|
||||
|
||||
public List<UserEmoji> listByUid(Long uid) {
|
||||
return lambdaQuery().eq(UserEmoji::getUid, uid).list();
|
||||
}
|
||||
|
||||
public int countByUid(Long uid) {
|
||||
return lambdaQuery().eq(UserEmoji::getUid, uid).count();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,28 @@
|
||||
package com.abin.mallchat.common.chat.domain.entity;
|
||||
package com.abin.mallchat.common.user.domain.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表情包
|
||||
* </p>
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/2 22:00
|
||||
* @author <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* @since 2023-07-09
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "user_emojis")
|
||||
public class UserEmojis implements Serializable {
|
||||
private static final long serialVersionUID = -7690290707154737263L;
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("user_emoji")
|
||||
public class UserEmoji implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
@@ -27,17 +33,22 @@ public class UserEmojis implements Serializable {
|
||||
/**
|
||||
* 用户表ID
|
||||
*/
|
||||
@TableField(value = "uid")
|
||||
@TableField("uid")
|
||||
private Long uid;
|
||||
|
||||
|
||||
/**
|
||||
* 表情地址
|
||||
*/
|
||||
@NotNull
|
||||
@TableField(value = "expression_url")
|
||||
@TableField("expression_url")
|
||||
private String expressionUrl;
|
||||
|
||||
/**
|
||||
* 逻辑删除(0-正常,1-删除)
|
||||
*/
|
||||
@TableField("delete_status")
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer deleteStatus;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@@ -50,9 +61,5 @@ public class UserEmojis implements Serializable {
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(value = "delete_status")
|
||||
@TableLogic(value = "0",delval = "1")
|
||||
private Integer deleteStatus;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.abin.mallchat.common.user.mapper;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表情包 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* @since 2023-07-09
|
||||
*/
|
||||
public interface UserEmojiMapper extends BaseMapper<UserEmoji> {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.abin.mallchat.common.user.mapper;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.entity.UserEmojis;
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
@@ -9,5 +9,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:24
|
||||
*/
|
||||
public interface UserEmojisMapper extends BaseMapper<UserEmojis> {
|
||||
public interface UserEmojisMapper extends BaseMapper<UserEmoji> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.abin.mallchat.common.user.mapper.UserEmojiMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -84,7 +84,7 @@ public class ChatController {
|
||||
@GetMapping("/public/msg/page")
|
||||
@ApiOperation("消息列表")
|
||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage1(@Valid ChatMessagePageReq request) {
|
||||
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage(@Valid ChatMessagePageReq request) {
|
||||
// black(request);
|
||||
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
||||
filterBlackMsg(msgPage);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.abin.mallchat.custom.chat.domain.vo.request;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -30,7 +29,7 @@ public class ChatMessageReq {
|
||||
|
||||
@ApiModelProperty("消息类型")
|
||||
@NotNull
|
||||
private Integer msgType = MessageTypeEnum.TEXT.getType();
|
||||
private Integer msgType;
|
||||
|
||||
@ApiModelProperty("消息内容,类型不同传值不同,见https://www.yuque.com/snab/mallcaht/rkb2uz5k1qqdmcmd")
|
||||
@NotNull
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.abin.mallchat.custom.chat.domain.vo.response;
|
||||
|
||||
import com.abin.mallchat.common.common.utils.discover.domain.UrlInfo;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -8,7 +7,6 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description: 消息
|
||||
@@ -28,16 +26,8 @@ public class ChatMessageResp {
|
||||
|
||||
@Data
|
||||
public static class UserInfo {
|
||||
@ApiModelProperty("用户名称")
|
||||
private String username;
|
||||
@ApiModelProperty("用户id")
|
||||
private Long uid;
|
||||
@ApiModelProperty("头像")
|
||||
private String avatar;
|
||||
@ApiModelProperty("归属地")
|
||||
private String locPlace;
|
||||
@ApiModelProperty("徽章标识,如果没有展示null")
|
||||
private Badge badge;
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -46,36 +36,12 @@ public class ChatMessageResp {
|
||||
private Long id;
|
||||
@ApiModelProperty("消息发送时间")
|
||||
private Date sendTime;
|
||||
@ApiModelProperty("消息内容-废弃")
|
||||
@Deprecated
|
||||
private String content;
|
||||
@ApiModelProperty("消息链接映射-废弃")
|
||||
@Deprecated
|
||||
private Map<String, UrlInfo> urlContentMap;
|
||||
@ApiModelProperty("消息类型 1正常文本 2.撤回消息")
|
||||
private Integer type;
|
||||
@ApiModelProperty("消息内容不同的消息类型,内容体不同,见https://www.yuque.com/snab/mallcaht/rkb2uz5k1qqdmcmd")
|
||||
private Object body;
|
||||
@ApiModelProperty("消息标记")
|
||||
private MessageMark messageMark;
|
||||
@ApiModelProperty("父消息,如果没有父消息,返回的是null")
|
||||
private ReplyMsg reply;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@Deprecated
|
||||
public static class ReplyMsg {
|
||||
@ApiModelProperty("消息id")
|
||||
private Long id;
|
||||
@ApiModelProperty("用户名称")
|
||||
private String username;
|
||||
@ApiModelProperty("消息内容")
|
||||
private String content;
|
||||
@ApiModelProperty("是否可消息跳转 0否 1是")
|
||||
private Integer canCallback;
|
||||
@ApiModelProperty("跳转间隔的消息条数")
|
||||
private Integer gapCount;
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -89,12 +55,4 @@ public class ChatMessageResp {
|
||||
@ApiModelProperty("该用户是否已经举报 0否 1是")
|
||||
private Integer userDislike;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Badge {
|
||||
@ApiModelProperty("徽章图像")
|
||||
private String img;
|
||||
@ApiModelProperty("徽章说明")
|
||||
private String describe;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,9 @@ 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.MessageMark;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
|
||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||
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;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||
import com.abin.mallchat.custom.chat.service.strategy.msg.AbstractMsgHandler;
|
||||
@@ -38,37 +33,25 @@ public class MessageAdapter {
|
||||
|
||||
}
|
||||
|
||||
public static List<ChatMessageResp> buildMsgResp(List<Message> messages, Map<Long, Message> replyMap, Map<Long, User> userMap, List<MessageMark> msgMark, Long receiveUid, Map<Long, ItemConfig> itemMap) {
|
||||
public static List<ChatMessageResp> buildMsgResp(List<Message> messages, Map<Long, Message> replyMap, List<MessageMark> msgMark, Long receiveUid) {
|
||||
Map<Long, List<MessageMark>> 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.setMessage(buildMessage(a, replyMap, userMap, markMap.getOrDefault(a.getId(), new ArrayList<>()), receiveUid));
|
||||
resp.setFromUser(buildFromUser(a.getFromUid()));
|
||||
resp.setMessage(buildMessage(a, replyMap, markMap.getOrDefault(a.getId(), new ArrayList<>()), receiveUid));
|
||||
return resp;
|
||||
})
|
||||
.sorted(Comparator.comparing(a -> a.getMessage().getSendTime()))//帮前端排好序,更方便它展示
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static ChatMessageResp.Message buildMessage(Message message, Map<Long, Message> replyMap, Map<Long, User> userMap, List<MessageMark> marks, Long receiveUid) {
|
||||
private static ChatMessageResp.Message buildMessage(Message message, Map<Long, Message> replyMap, List<MessageMark> marks, Long receiveUid) {
|
||||
ChatMessageResp.Message messageVO = new ChatMessageResp.Message();
|
||||
BeanUtil.copyProperties(message, messageVO);
|
||||
messageVO.setSendTime(message.getCreateTime());
|
||||
AbstractMsgHandler msgHandler = MsgHandlerFactory.getStrategyNoNull(message.getType());
|
||||
messageVO.setBody(msgHandler.showMsg(message));
|
||||
messageVO.setUrlContentMap(Optional.ofNullable(message.getExtra()).map(MessageExtra::getUrlContentMap).orElse(null));
|
||||
Message replyMessage = replyMap.get(message.getReplyMsgId());
|
||||
|
||||
//回复消息
|
||||
if (Objects.nonNull(replyMessage)) {
|
||||
ChatMessageResp.ReplyMsg replyMsgVO = new ChatMessageResp.ReplyMsg();
|
||||
replyMsgVO.setId(replyMessage.getId());
|
||||
replyMsgVO.setContent(replyMessage.getContent());
|
||||
User replyUser = userMap.get(replyMessage.getFromUid());
|
||||
replyMsgVO.setUsername(replyUser.getName());
|
||||
replyMsgVO.setCanCallback(YesOrNoEnum.toStatus(Objects.nonNull(message.getGapCount()) && message.getGapCount() <= CAN_CALLBACK_GAP_COUNT));
|
||||
replyMsgVO.setGapCount(message.getGapCount());
|
||||
messageVO.setReply(replyMsgVO);
|
||||
if (Objects.nonNull(msgHandler)) {
|
||||
messageVO.setBody(msgHandler.showMsg(message));
|
||||
}
|
||||
//消息标记
|
||||
messageVO.setMessageMark(buildMsgMark(marks, receiveUid));
|
||||
@@ -87,19 +70,9 @@ public class MessageAdapter {
|
||||
return mark;
|
||||
}
|
||||
|
||||
private static ChatMessageResp.UserInfo buildFromUser(User fromUser, Map<Long, ItemConfig> itemMap) {
|
||||
private static ChatMessageResp.UserInfo buildFromUser(Long fromUid) {
|
||||
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();
|
||||
ItemConfig itemConfig = itemMap.get(fromUser.getItemId());
|
||||
badge.setImg(itemConfig.getImg());
|
||||
badge.setDescribe(itemConfig.getDescribe());
|
||||
userInfo.setBadge(badge);
|
||||
}
|
||||
userInfo.setUid(fromUid);
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.common.common.event.MessageSendEvent;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
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;
|
||||
import com.abin.mallchat.common.user.domain.enums.ChatActiveStatusEnum;
|
||||
import com.abin.mallchat.common.user.domain.enums.RoleEnum;
|
||||
import com.abin.mallchat.common.user.service.IRoleService;
|
||||
@@ -49,7 +47,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Description: 消息处理类
|
||||
@@ -226,21 +223,14 @@ public class ChatServiceImpl implements ChatService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Map<Long, Message> replyMap = new HashMap<>();
|
||||
Map<Long, User> userMap;
|
||||
Map<Long, ItemConfig> itemMap;
|
||||
//批量查出回复的消息
|
||||
List<Long> replyIds = messages.stream().map(Message::getReplyMsgId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(replyIds)) {
|
||||
replyMap = messageDao.listByIds(replyIds).stream().collect(Collectors.toMap(Message::getId, Function.identity()));
|
||||
}
|
||||
//批量查询消息关联用户
|
||||
Set<Long> 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()));
|
||||
//查询消息标志
|
||||
List<MessageMark> 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, msgMark, receiveUid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import com.abin.mallchat.common.chat.dao.MessageDao;
|
||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.EmojisMsgDTO;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.ImgMsgDTO;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
@@ -26,7 +25,7 @@ public class EmojisMsgHandler extends AbstractMsgHandler {
|
||||
|
||||
@Override
|
||||
MessageTypeEnum getMsgTypeEnum() {
|
||||
return MessageTypeEnum.EMOJIS;
|
||||
return MessageTypeEnum.EMOJI;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.abin.mallchat.custom.user.controller;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.vo.request.IdReqVO;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.IdRespVO;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.UserEmojiReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.UserEmojiResp;
|
||||
import com.abin.mallchat.custom.user.service.UserEmojiService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户表情包
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/capi/user/emoji")
|
||||
@Api(tags = "用户表情包管理相关接口")
|
||||
public class UserEmojiController {
|
||||
|
||||
/**
|
||||
* 用户表情包 Service
|
||||
*/
|
||||
@Resource
|
||||
private UserEmojiService emojiService;
|
||||
|
||||
|
||||
/**
|
||||
* 表情包列表
|
||||
*
|
||||
* @return 表情包列表
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("表情包列表")
|
||||
public ApiResult<List<UserEmojiResp>> getEmojisPage() {
|
||||
return ApiResult.success(emojiService.list(RequestHolder.get().getUid()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增表情包
|
||||
*
|
||||
* @param req 用户表情包
|
||||
* @return 表情包
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@PostMapping()
|
||||
@ApiOperation("新增表情包")
|
||||
public ApiResult<IdRespVO> insertEmojis(@Valid @RequestBody UserEmojiReq req) {
|
||||
return emojiService.insert(req, RequestHolder.get().getUid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除表情包
|
||||
*
|
||||
* @return 删除结果
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@DeleteMapping()
|
||||
@ApiOperation("删除表情包")
|
||||
public ApiResult<Void> deleteEmojis(@Valid @RequestBody IdReqVO reqVO) {
|
||||
emojiService.remove(reqVO.getId(), RequestHolder.get().getUid());
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.abin.mallchat.custom.user.controller;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.entity.UserEmojis;
|
||||
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.custom.user.service.UserEmojisService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 用户表情包
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/capi/userEmojis")
|
||||
@Api(tags = "用户表情包管理相关接口")
|
||||
public class UserEmojisController {
|
||||
|
||||
/**
|
||||
* 用户表情包 Service
|
||||
*/
|
||||
@Resource
|
||||
private UserEmojisService emojisService;
|
||||
|
||||
|
||||
/**
|
||||
* 表情包列表
|
||||
*
|
||||
* @param request 游标翻页请求参数
|
||||
* @return 表情包列表
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@GetMapping("/getEmojisPage")
|
||||
@ApiOperation("表情包列表")
|
||||
public ApiResult<CursorPageBaseResp<UserEmojis>> getEmojisPage(@Valid CursorPageBaseReq request) {
|
||||
return ApiResult.success(emojisService.getEmojisPage(request, RequestHolder.get().getUid()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增表情包
|
||||
*
|
||||
* @param emojis 用户表情包
|
||||
* @return 表情包
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@PostMapping("/insertEmojis")
|
||||
@ApiOperation("新增表情包")
|
||||
public ApiResult<UserEmojis> insertEmojis(@Valid @RequestBody UserEmojis emojis) {
|
||||
return emojisService.insertEmojis(emojis,RequestHolder.get().getUid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除表情包
|
||||
*
|
||||
* @param id 用户表情包ID
|
||||
* @return 删除结果
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@GetMapping("/deleteEmojis")
|
||||
@ApiOperation("删除表情包")
|
||||
public ApiResult<Void> deleteEmojis(@RequestParam("id") String id) {
|
||||
emojisService.removeById(id);
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import java.util.stream.Collectors;
|
||||
@Getter
|
||||
public enum OssSceneEnum {
|
||||
CHAT(1, "聊天", "/chat"),
|
||||
EMOJIS(2, "表情包", "/emojis"),
|
||||
EMOJI(2, "表情包", "/emoji"),
|
||||
;
|
||||
|
||||
private final Integer type;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.abin.mallchat.custom.user.domain.vo.request.user;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* Description: 表情包反参
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-07-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserEmojiReq {
|
||||
/**
|
||||
* 表情地址
|
||||
*/
|
||||
@ApiModelProperty(value = "新增的表情url")
|
||||
private String expressionUrl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.abin.mallchat.custom.user.domain.vo.response.user;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* Description: 表情包反参
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-07-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserEmojiResp {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表情地址
|
||||
*/
|
||||
@ApiModelProperty(value = "表情url")
|
||||
private String expressionUrl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.abin.mallchat.custom.user.service;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.IdRespVO;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.UserEmojiReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.UserEmojiResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户表情包 Service
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:22
|
||||
*/
|
||||
public interface UserEmojiService {
|
||||
|
||||
/**
|
||||
* 表情包列表
|
||||
*
|
||||
* @return 表情包列表
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
List<UserEmojiResp> list(Long uid);
|
||||
|
||||
/**
|
||||
* 新增表情包
|
||||
*
|
||||
* @param emojis 用户表情包
|
||||
* @param uid 用户ID
|
||||
* @return 表情包
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
ApiResult<IdRespVO> insert(UserEmojiReq emojis, Long uid);
|
||||
|
||||
/**
|
||||
* 删除表情包
|
||||
*
|
||||
* @param id
|
||||
* @param uid
|
||||
*/
|
||||
void remove(Long id, Long uid);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.abin.mallchat.custom.user.service;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.entity.UserEmojis;
|
||||
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 用户表情包 Service
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:22
|
||||
*/
|
||||
public interface UserEmojisService extends IService<UserEmojis> {
|
||||
|
||||
/**
|
||||
* 表情包列表
|
||||
*
|
||||
* @param request 游标翻页请求参数
|
||||
* @return 表情包列表
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
CursorPageBaseResp<UserEmojis> getEmojisPage(CursorPageBaseReq request, Long uid);
|
||||
|
||||
/**
|
||||
* 新增表情包
|
||||
*
|
||||
* @param emojis 用户表情包
|
||||
* @param uid 用户ID
|
||||
* @return 表情包
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
ApiResult<UserEmojis> insertEmojis(UserEmojis emojis, Long uid);
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class OssServiceImpl implements OssService {
|
||||
private static final String BUCKET_NAME = "mallchat";
|
||||
@Autowired
|
||||
private MinIOTemplate minIOTemplate;
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.abin.mallchat.custom.user.service.impl;
|
||||
|
||||
import com.abin.mallchat.common.common.annotation.RedissonLock;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.IdRespVO;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.user.dao.UserEmojiDao;
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.UserEmojiReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.UserEmojiResp;
|
||||
import com.abin.mallchat.custom.user.service.UserEmojiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户表情包 ServiceImpl
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:23
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserEmojiServiceImpl implements UserEmojiService {
|
||||
|
||||
@Autowired
|
||||
private UserEmojiDao userEmojiDao;
|
||||
|
||||
@Override
|
||||
public List<UserEmojiResp> list(Long uid) {
|
||||
return userEmojiDao.listByUid(uid).
|
||||
stream()
|
||||
.map(a -> UserEmojiResp.builder()
|
||||
.id(a.getId())
|
||||
.expressionUrl(a.getExpressionUrl())
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增表情包
|
||||
*
|
||||
* @param uid 用户ID
|
||||
* @return 表情包
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@Override
|
||||
@RedissonLock(key = "#uid")
|
||||
public ApiResult<IdRespVO> insert(UserEmojiReq req, Long uid) {
|
||||
//校验表情数量是否超过30
|
||||
int count = userEmojiDao.countByUid(uid);
|
||||
AssertUtil.isFalse(count > 30, "最多只能添加30个表情哦~~");
|
||||
//校验表情是否存在
|
||||
Integer existsCount = userEmojiDao.lambdaQuery()
|
||||
.eq(UserEmoji::getExpressionUrl, req.getExpressionUrl())
|
||||
.eq(UserEmoji::getUid, uid)
|
||||
.count();
|
||||
AssertUtil.isFalse(existsCount > 0, "当前表情已存在哦~~");
|
||||
UserEmoji insert = UserEmoji.builder().uid(uid).expressionUrl(req.getExpressionUrl()).build();
|
||||
userEmojiDao.save(insert);
|
||||
return ApiResult.success(IdRespVO.id(insert.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Long id, Long uid) {
|
||||
UserEmoji userEmoji = userEmojiDao.getById(id);
|
||||
AssertUtil.isNotEmpty(userEmoji, "表情不能为空");
|
||||
AssertUtil.equal(userEmoji.getUid(), uid, "小黑子,别人表情不是你能删的");
|
||||
userEmojiDao.removeById(id);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.abin.mallchat.custom.user.service.impl;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.entity.UserEmojis;
|
||||
import com.abin.mallchat.common.common.annotation.RedissonLock;
|
||||
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.common.utils.CursorUtils;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.common.user.mapper.UserEmojisMapper;
|
||||
import com.abin.mallchat.custom.user.service.UserEmojisService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 用户表情包 ServiceImpl
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:23
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserEmojisServiceImpl extends ServiceImpl<UserEmojisMapper, UserEmojis> implements UserEmojisService {
|
||||
|
||||
/**
|
||||
* 游标分页工具类
|
||||
*/
|
||||
@Resource
|
||||
private CursorUtils cursorUtils;
|
||||
|
||||
/**
|
||||
* 表情包列表
|
||||
*
|
||||
* @param request 游标翻页请求参数
|
||||
* @return 表情包列表
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@Override
|
||||
public CursorPageBaseResp<UserEmojis> getEmojisPage(CursorPageBaseReq request, Long uid) {
|
||||
CursorPageBaseResp<UserEmojis> cursorPageByMysql = cursorUtils.getCursorPageByMysql(this, request, wrapper -> {
|
||||
wrapper.eq(UserEmojis::getUid, uid);
|
||||
}, UserEmojis::getId);
|
||||
return cursorPageByMysql;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增表情包
|
||||
*
|
||||
* @param emojis 用户表情包
|
||||
* @param uid 用户ID
|
||||
* @return 表情包
|
||||
* @author WuShiJie
|
||||
* @createTime 2023/7/3 14:46
|
||||
**/
|
||||
@Override
|
||||
@RedissonLock(key = "#uid")
|
||||
public ApiResult<UserEmojis> insertEmojis(UserEmojis emojis, Long uid) {
|
||||
//校验表情数量是否超过30
|
||||
LambdaQueryWrapper<UserEmojis> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserEmojis::getUid,uid);
|
||||
int count = this.count(queryWrapper);
|
||||
AssertUtil.isFalse(count>30, "最多只能添加30个表情哦~~");
|
||||
//校验表情是否存在
|
||||
queryWrapper.eq(UserEmojis::getExpressionUrl,emojis.getExpressionUrl());
|
||||
count = this.count(queryWrapper);
|
||||
AssertUtil.isFalse(count >0, "当前表情已存在哦~~");
|
||||
emojis.setUid(RequestHolder.get().getUid());
|
||||
this.saveOrUpdate(emojis, queryWrapper);
|
||||
return ApiResult.success(emojis);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user