diff --git a/docs/version/emojis.sql b/docs/version/emojis.sql deleted file mode 100644 index ea238de..0000000 --- a/docs/version/emojis.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE `mc_emojis` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', - `user_id` 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 '修改时间', - `del_flg` int(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除(0-正常,1-删除)', - PRIMARY KEY (`id`), - KEY `IDX_MC_EMOJIS_USER_ID` (`user_id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='用户表情包'; \ No newline at end of file diff --git a/docs/version/user_emojis.sql b/docs/version/user_emojis.sql new file mode 100644 index 0000000..875edf0 --- /dev/null +++ b/docs/version/user_emojis.sql @@ -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_MC_EMOJIS_USER_ID` (`uid`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='用户表情包'; \ No newline at end of file diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/entity/McEmojis.java b/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/entity/UserEmojis.java similarity index 80% rename from mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/entity/McEmojis.java rename to mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/entity/UserEmojis.java index 09d7ecf..de707ff 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/entity/McEmojis.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/entity/UserEmojis.java @@ -14,8 +14,8 @@ import java.util.Date; * @createTime: 2023/7/2 22:00 */ @Data -@TableName(value = "mc_emojis") -public class McEmojis implements Serializable { +@TableName(value = "user_emojis") +public class UserEmojis implements Serializable { private static final long serialVersionUID = -7690290707154737263L; /** @@ -27,8 +27,8 @@ public class McEmojis implements Serializable { /** * 用户表ID */ - @TableField(value = "user_id") - private Long userId; + @TableField(value = "uid") + private Long uid; /** @@ -50,9 +50,9 @@ public class McEmojis implements Serializable { @TableField("update_time") private Date updateTime; - @TableField(value = "del_flg") + @TableField(value = "delete_status") @TableLogic(value = "0",delval = "1") - private Integer delFlg; + private Integer deleteStatus; } diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/mapper/EmojisMapper.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/mapper/UserEmojisMapper.java similarity index 60% rename from mallchat-common/src/main/java/com/abin/mallchat/common/user/mapper/EmojisMapper.java rename to mallchat-common/src/main/java/com/abin/mallchat/common/user/mapper/UserEmojisMapper.java index 67af9e6..dd6b5b2 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/mapper/EmojisMapper.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/mapper/UserEmojisMapper.java @@ -1,6 +1,6 @@ package com.abin.mallchat.common.user.mapper; -import com.abin.mallchat.common.chat.domain.entity.McEmojis; +import com.abin.mallchat.common.chat.domain.entity.UserEmojis; 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 EmojisMapper extends BaseMapper { +public interface UserEmojisMapper extends BaseMapper { } diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/EmojisController.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/UserEmojisController.java similarity index 65% rename from mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/EmojisController.java rename to mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/UserEmojisController.java index 2121797..f88e69a 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/EmojisController.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/UserEmojisController.java @@ -1,12 +1,11 @@ package com.abin.mallchat.custom.user.controller; -import cn.hutool.core.util.StrUtil; -import com.abin.mallchat.common.chat.domain.entity.McEmojis; +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.EmojisService; +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; @@ -22,15 +21,15 @@ import javax.validation.Valid; * @createTime: 2023/7/3 14:21 */ @RestController -@RequestMapping("/capi/emojis") +@RequestMapping("/capi/userEmojis") @Api(tags = "用户表情包管理相关接口") -public class EmojisController { +public class UserEmojisController { /** * 用户表情包 Service */ @Resource - private EmojisService emojisService; + private UserEmojisService emojisService; /** @@ -43,7 +42,7 @@ public class EmojisController { **/ @GetMapping("/getEmojisPage") @ApiOperation("表情包列表") - public ApiResult> getEmojisPage(@Valid CursorPageBaseReq request) { + public ApiResult> getEmojisPage(@Valid CursorPageBaseReq request) { return ApiResult.success(emojisService.getEmojisPage(request, RequestHolder.get().getUid())); } @@ -57,14 +56,9 @@ public class EmojisController { * @createTime 2023/7/3 14:46 **/ @PostMapping("/insertEmojis") - @ApiOperation("表情包列表") - public ApiResult insertEmojis(@Valid @RequestBody McEmojis emojis) { - emojis.setUserId(RequestHolder.get().getUid()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(McEmojis::getUserId,emojis.getUserId()); - queryWrapper.eq(McEmojis::getExpressionUrl,emojis.getExpressionUrl()); - emojisService.saveOrUpdate(emojis, queryWrapper); - return ApiResult.success(emojis); + @ApiOperation("新增表情包") + public ApiResult insertEmojis(@Valid @RequestBody UserEmojis emojis) { + return emojisService.insertEmojis(emojis,RequestHolder.get().getUid()); } /** @@ -76,7 +70,7 @@ public class EmojisController { * @createTime 2023/7/3 14:46 **/ @GetMapping("/deleteEmojis") - @ApiOperation("表情包列表") + @ApiOperation("删除表情包") public ApiResult deleteEmojis(@RequestParam("id") String id) { emojisService.removeById(id); return ApiResult.success(); diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/EmojisService.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/EmojisService.java deleted file mode 100644 index 89fb81f..0000000 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/EmojisService.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.abin.mallchat.custom.user.service; - -import com.abin.mallchat.common.chat.domain.entity.McEmojis; -import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq; -import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp; -import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp; -import com.baomidou.mybatisplus.extension.service.IService; - -/** - * 用户表情包 Service - * - * @author: WuShiJie - * @createTime: 2023/7/3 14:22 - */ -public interface EmojisService extends IService { - - /** - * 表情包列表 - * - * @param request 游标翻页请求参数 - * @return 表情包列表 - * @author WuShiJie - * @createTime 2023/7/3 14:46 - **/ - CursorPageBaseResp getEmojisPage(CursorPageBaseReq request, Long uid); -} diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/UserEmojisService.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/UserEmojisService.java new file mode 100644 index 0000000..31a8ddd --- /dev/null +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/UserEmojisService.java @@ -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 { + + /** + * 表情包列表 + * + * @param request 游标翻页请求参数 + * @return 表情包列表 + * @author WuShiJie + * @createTime 2023/7/3 14:46 + **/ + CursorPageBaseResp getEmojisPage(CursorPageBaseReq request, Long uid); + + /** + * 新增表情包 + * + * @param emojis 用户表情包 + * @param uid 用户ID + * @return 表情包 + * @author WuShiJie + * @createTime 2023/7/3 14:46 + **/ + ApiResult insertEmojis(UserEmojis emojis, Long uid); +} diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/EmojisServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/EmojisServiceImpl.java deleted file mode 100644 index 26dbe09..0000000 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/EmojisServiceImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.abin.mallchat.custom.user.service.impl; - -import com.abin.mallchat.common.chat.domain.entity.McEmojis; -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.utils.CursorUtils; -import com.abin.mallchat.common.user.mapper.EmojisMapper; -import com.abin.mallchat.custom.chat.service.adapter.RoomAdapter; -import com.abin.mallchat.custom.user.service.EmojisService; -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; - -/** - * 用户表情包 ServiceImpl - * - * @author: WuShiJie - * @createTime: 2023/7/3 14:23 - */ -@Service -@Slf4j -public class EmojisServiceImpl extends ServiceImpl implements EmojisService { - - @Autowired - private CursorUtils cursorUtils; - - /** - * 表情包列表 - * - * @param request 游标翻页请求参数 - * @return 表情包列表 - * @author WuShiJie - * @createTime 2023/7/3 14:46 - **/ - @Override - public CursorPageBaseResp getEmojisPage(CursorPageBaseReq request, Long uid) { - CursorPageBaseResp cursorPageByMysql = cursorUtils.getCursorPageByMysql(this, request, wrapper -> { - wrapper.eq(McEmojis::getUserId, uid); - }, McEmojis::getId); - return cursorPageByMysql; - } -} diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserEmojisServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserEmojisServiceImpl.java new file mode 100644 index 0000000..0f2302d --- /dev/null +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserEmojisServiceImpl.java @@ -0,0 +1,82 @@ +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.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 implements UserEmojisService { + + /** + * 游标分页工具类 + */ + @Resource + private CursorUtils cursorUtils; + + /** + * 表情包列表 + * + * @param request 游标翻页请求参数 + * @return 表情包列表 + * @author WuShiJie + * @createTime 2023/7/3 14:46 + **/ + @Override + public CursorPageBaseResp getEmojisPage(CursorPageBaseReq request, Long uid) { + CursorPageBaseResp 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 insertEmojis(UserEmojis emojis, Long uid) { + //校验表情数量是否超过30 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(UserEmojis::getUid,uid); + int count = this.count(queryWrapper); + if (count>30){ + return ApiResult.fail(-1,"最多只能添加30个表情"); + } + //校验表情是否存在 + queryWrapper.eq(UserEmojis::getExpressionUrl,emojis.getExpressionUrl()); + count = this.count(queryWrapper); + if (count >0){ + return ApiResult.fail(-1,"当前表情已存在"); + } + emojis.setUid(RequestHolder.get().getUid()); + this.saveOrUpdate(emojis, queryWrapper); + return ApiResult.success(emojis); + } +}