mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
10
docs/version/user_emojis.sql
Normal file
10
docs/version/user_emojis.sql
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
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='用户表情包';
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.abin.mallchat.common.chat.domain.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户表情包
|
||||||
|
*
|
||||||
|
* @author: WuShiJie
|
||||||
|
* @createTime: 2023/7/2 22:00
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "user_emojis")
|
||||||
|
public class UserEmojis implements Serializable {
|
||||||
|
private static final long serialVersionUID = -7690290707154737263L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户表ID
|
||||||
|
*/
|
||||||
|
@TableField(value = "uid")
|
||||||
|
private Long uid;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表情地址
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@TableField(value = "expression_url")
|
||||||
|
private String expressionUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField("create_time")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
@TableField("update_time")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@TableField(value = "delete_status")
|
||||||
|
@TableLogic(value = "0",delval = "1")
|
||||||
|
private Integer deleteStatus;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.abin.mallchat.common.chat.domain.entity.msg;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 表情图片消息入参
|
||||||
|
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||||
|
* Date: 2023-06-04
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class EmojisMsgDTO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ApiModelProperty("下载地址")
|
||||||
|
@NotBlank
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -37,4 +37,9 @@ public class MessageExtra implements Serializable {
|
|||||||
private SoundMsgDTO soundMsgDTO;
|
private SoundMsgDTO soundMsgDTO;
|
||||||
//文件消息
|
//文件消息
|
||||||
private VideoMsgDTO videoMsgDTO;
|
private VideoMsgDTO videoMsgDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表情图片信息
|
||||||
|
*/
|
||||||
|
private EmojisMsgDTO emojisMsgDTO;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public enum MessageTypeEnum {
|
|||||||
FILE(4, "文件"),
|
FILE(4, "文件"),
|
||||||
SOUND(5, "语音"),
|
SOUND(5, "语音"),
|
||||||
VIDEO(6, "视频"),
|
VIDEO(6, "视频"),
|
||||||
|
EMOJIS(7, "表情"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Integer type;
|
private final Integer type;
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.abin.mallchat.common.user.mapper;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.chat.domain.entity.UserEmojis;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户表情包 Mapper
|
||||||
|
*
|
||||||
|
* @author: WuShiJie
|
||||||
|
* @createTime: 2023/7/3 14:24
|
||||||
|
*/
|
||||||
|
public interface UserEmojisMapper extends BaseMapper<UserEmojis> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.abin.mallchat.custom.chat.service.strategy.msg;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description:表情消息
|
||||||
|
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||||
|
* Date: 2023-06-04
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class EmojisMsgHandler extends AbstractMsgHandler {
|
||||||
|
@Autowired
|
||||||
|
private MessageDao messageDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
MessageTypeEnum getMsgTypeEnum() {
|
||||||
|
return MessageTypeEnum.EMOJIS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||||
|
EmojisMsgDTO body = BeanUtil.toBean(request.getBody(), EmojisMsgDTO.class);
|
||||||
|
AssertUtil.allCheckValidateThrow(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveMsg(Message msg, ChatMessageReq request) {
|
||||||
|
EmojisMsgDTO body = BeanUtil.toBean(request.getBody(), EmojisMsgDTO.class);
|
||||||
|
MessageExtra extra = Optional.ofNullable(msg.getExtra()).orElse(new MessageExtra());
|
||||||
|
Message update = new Message();
|
||||||
|
update.setId(msg.getId());
|
||||||
|
update.setExtra(extra);
|
||||||
|
extra.setEmojisMsgDTO(body);
|
||||||
|
messageDao.updateById(update);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object showMsg(Message msg) {
|
||||||
|
return msg.getExtra().getEmojisMsgDTO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object showReplyMsg(Message msg) {
|
||||||
|
return "表情";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
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,6 +17,7 @@ import java.util.stream.Collectors;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum OssSceneEnum {
|
public enum OssSceneEnum {
|
||||||
CHAT(1, "聊天", "/chat"),
|
CHAT(1, "聊天", "/chat"),
|
||||||
|
EMOJIS(2, "表情包", "/emojis"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Integer type;
|
private final Integer type;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class UploadUrlReq {
|
|||||||
@ApiModelProperty(value = "文件名(带后缀)")
|
@ApiModelProperty(value = "文件名(带后缀)")
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String fileName;
|
private String fileName;
|
||||||
@ApiModelProperty(value = "上传场景1.聊天室")
|
@ApiModelProperty(value = "上传场景1.聊天室,2.表情包")
|
||||||
@NotNull
|
@NotNull
|
||||||
private Integer scene;
|
private Integer scene;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.abin.mallchat.custom.user.domain.vo.request.user;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述此类的作用
|
||||||
|
*
|
||||||
|
* @author: WuShiJie
|
||||||
|
* @createTime: 2023/7/3 14:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class EmojisPageReq extends CursorPageBaseReq {
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
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