mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 14:13:42 +08:00
@@ -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
|
||||
public enum OssSceneEnum {
|
||||
CHAT(1, "聊天", "/chat"),
|
||||
EMOJIS(2, "表情包", "/emojis"),
|
||||
;
|
||||
|
||||
private final Integer type;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class UploadUrlReq {
|
||||
@ApiModelProperty(value = "文件名(带后缀)")
|
||||
@NotBlank
|
||||
private String fileName;
|
||||
@ApiModelProperty(value = "上传场景1.聊天室")
|
||||
@ApiModelProperty(value = "上传场景1.聊天室,2.表情包")
|
||||
@NotNull
|
||||
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