Commit 9c1764e36e8157a137396a05f2285430c7693f1c

Authored by YunaiV
1 parent 04123e59

im:code review 代码风格方面

Showing 17 changed files with 68 additions and 23 deletions
yudao-module-im/pom.xml
... ... @@ -17,6 +17,7 @@
17 17  
18 18 <name>${project.artifactId}</name>
19 19 <description>
  20 + <!-- TODO 芋艿:这块后面再调整下 -->
20 21 im 模块,主要提供能力:
21 22 1. 通讯能力,例如:消息发送、消息接收、消息撤回、消息已读等。
22 23 2. 通讯会话,例如:单聊、群聊、聊天室等。
... ...
yudao-module-im/yudao-module-im-api/src/main/java/cn/iocoder/yudao/module/im/api/package-info.java
1 1 /**
2 2 * @author anhaohao
3   - * @date 2024/3/9 下午8:59
  3 + * @date 2024/3/9 下午8:59 TODO @hao:没有 @date 这个,应该是 @since 哈
4 4 */
5 5 package cn.iocoder.yudao.module.im.api;
6 6 \ No newline at end of file
... ...
yudao-module-im/yudao-module-im-api/src/main/java/cn/iocoder/yudao/module/im/enums/ErrorCodeConstants.java
... ... @@ -23,4 +23,5 @@ public interface ErrorCodeConstants {
23 23  
24 24 // ========== 群成员 (1-040-500-000) ==========
25 25 ErrorCode GROUP_MEMBER_NOT_EXISTS = new ErrorCode(1_040_500_000, "群成员不存在");
  26 +
26 27 }
... ...
yudao-module-im/yudao-module-im-api/src/main/java/cn/iocoder/yudao/module/im/enums/message/ImMessageTypeEnum.java
... ... @@ -6,6 +6,7 @@ import lombok.Getter;
6 6  
7 7 import java.util.Arrays;
8 8  
  9 +// TODO @hao:类型保持和 openim 一致
9 10 /**
10 11 * IM 消息的类型枚举
11 12 * <p>
... ... @@ -42,4 +43,5 @@ public enum ImMessageTypeEnum implements IntArrayValuable {
42 43 public int[] array() {
43 44 return ARRAYS;
44 45 }
  46 +
45 47 }
46 48 \ No newline at end of file
... ...
yudao-module-im/yudao-module-im-api/src/main/java/cn/iocoder/yudao/module/im/enums/package-info.java deleted
1   -/**
2   - * @author anhaohao
3   - * @date 2024/3/9 下午8:59
4   - */
5   -package cn.iocoder.yudao.module.im.enums;
6 0 \ No newline at end of file
yudao-module-im/yudao-module-im-biz/pom.xml
... ... @@ -5,7 +5,7 @@
5 5 <parent>
6 6 <artifactId>yudao-module-im</artifactId>
7 7 <groupId>cn.iocoder.boot</groupId>
8   - <version>${revision}</version> <!-- 1. 修改 version 为 ${revision} -->
  8 + <version>${revision}</version> <!-- 1. 修改 version 为 ${revision} TODO @hao:这种都去掉哈; -->
9 9 </parent>
10 10 <modelVersion>4.0.0</modelVersion>
11 11 <packaging>jar</packaging> <!-- 2. 新增 packaging 为 jar -->
... ... @@ -52,6 +52,9 @@
52 52 <groupId>cn.iocoder.boot</groupId>
53 53 <artifactId>yudao-spring-boot-starter-test</artifactId>
54 54 </dependency>
  55 +
  56 + <!-- TODO @hao:下面几个依赖的位置不太对。主要是它不属于 test,可以参考别的模块,顺序调整下哈 -->
  57 +
55 58 <dependency>
56 59 <groupId>cn.iocoder.boot</groupId>
57 60 <artifactId>yudao-spring-boot-starter-excel</artifactId>
... ... @@ -61,6 +64,7 @@
61 64 <artifactId>yudao-spring-boot-starter-websocket</artifactId>
62 65 </dependency>
63 66  
  67 + <!-- TODO @hao:引入我们自己的 redis starter 哈 -->
64 68 <dependency>
65 69 <groupId>org.redisson</groupId>
66 70 <artifactId>redisson-spring-boot-starter</artifactId>
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/ImConversationController.java
... ... @@ -18,36 +18,41 @@ import java.util.List;
18 18  
19 19 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
20 20  
  21 +// TODO @hao: 管理后台 - IM 会话
21 22 @Tag(name = "管理后台 - 会话")
22 23 @RestController
23 24 @RequestMapping("/im/conversation")
24 25 @Validated
25 26 public class ImConversationController {
26 27  
  28 + // TODO @hao: conversationService 即可
27 29 @Resource
28 30 private ImConversationService imConversationService;
29 31  
  32 + // TODO @hao:/list 会话列表;一般 get 是给单个对象,或者 get-count 这种;然后 conversation 已经是模块名了,所以可以简化
30 33 @GetMapping("/get-conversation")
31 34 @Operation(summary = "获得用户的会话列表")
32   - @PreAuthorize("hasAuthority('im:conversation:query')")
  35 + @PreAuthorize("hasAuthority('im:conversation:query')") // TODO @hao:不用权限哈
33 36 public CommonResult<List<ImConversationRespVO>> getConversationList() {
34 37 List<ImConversationDO> conversationList = imConversationService.getConversationList();
35 38 return success(BeanUtils.toBean(conversationList, ImConversationRespVO.class));
36 39 }
37 40  
38   -
  41 + // TODO @hao:/update-pinned 保持和 db 字段一致哈;
  42 + // TODO @hao:这个接口,需要单独的 VO 哈;
39 43 @PostMapping("/update-top")
40 44 @Operation(summary = "置顶会话")
41   - @PreAuthorize("hasAuthority('im:conversation:update')")
  45 + @PreAuthorize("hasAuthority('im:conversation:update')") // TODO @hao:不用权限哈;因为肯定会判断是不是自己的
42 46 public CommonResult<Boolean> updateTop(@Valid @RequestBody ImConversationSaveReqVO updateReqVO) {
43 47 imConversationService.updateTop(updateReqVO);
44 48 return success(true);
45 49 }
46 50  
47 51  
  52 + // TODO @hao:这个接口,需要单独的 VO 哈;
48 53 @PostMapping("/update-last-read-time")
49 54 @Operation(summary = "更新最后已读时间")
50   - @PreAuthorize("hasAuthority('im:conversation:update')")
  55 + @PreAuthorize("hasAuthority('im:conversation:update')") // TODO @hao:不用权限哈;因为肯定会判断是不是自己的
51 56 public CommonResult<Boolean> updateLastReadTime(@Valid @RequestBody ImConversationSaveReqVO updateReqVO) {
52 57 imConversationService.updateLastReadTime(updateReqVO);
53 58 return success(true);
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationPageReqVO.java
... ... @@ -11,7 +11,8 @@ import java.time.LocalDateTime;
11 11  
12 12 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
13 13  
14   -@Schema(description = "管理后台 - 会话分页 Request VO")
  14 +// TODO @hao:这个貌似业务上,暂时用不到,可以考虑删除哈。
  15 +@Schema(description = "管理后台 - IM 会话分页 Request VO")
15 16 @Data
16 17 @EqualsAndHashCode(callSuper = true)
17 18 @ToString(callSuper = true)
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationRespVO.java
... ... @@ -9,9 +9,11 @@ import java.time.LocalDateTime;
9 9  
10 10 @Schema(description = "管理后台 - 会话 Response VO")
11 11 @Data
12   -@ExcelIgnoreUnannotated
  12 +@ExcelIgnoreUnannotated // TODO @hao:excel 的注解可以先删除
13 13 public class ImConversationRespVO {
14 14  
  15 + // TODO @hao:example 都写下
  16 +
15 17 @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13905")
16 18 @ExcelProperty("编号")
17 19 private Long id;
... ... @@ -20,18 +22,22 @@ public class ImConversationRespVO {
20 22 @ExcelProperty("所属用户")
21 23 private Long userId;
22 24  
  25 + // TODO @hao:@Schema 可以改成“会话类型”,不用把具体的数字写在上面哈。这样后续改动,会比较难改
23 26 @Schema(description = "类型:1 单聊;2 群聊;4 通知会话(预留)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
24 27 @ExcelProperty("类型:1 单聊;2 群聊;4 通知会话(预留)")
25 28 private Integer conversationType;
26 29  
  30 + // TODO @hao:只写,聊天对象编号
27 31 @Schema(description = "单聊时,用户编号;群聊时,群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21454")
28 32 @ExcelProperty("单聊时,用户编号;群聊时,群编号")
29 33 private Long targetId;
30 34  
  35 + // TODO @hao:只写 no 即可。
31 36 @Schema(description = "会话标志 单聊:s_{userId}_{targetId},需要排序 userId 和 targetId 群聊:g_groupId", requiredMode = Schema.RequiredMode.REQUIRED)
32 37 @ExcelProperty("会话标志 单聊:s_{userId}_{targetId},需要排序 userId 和 targetId 群聊:g_groupId")
33 38 private String no;
34 39  
  40 + // TODO @hao:只写 是否置顶;0 1 是数据库的结果哈;
35 41 @Schema(description = "是否置顶 0否 1是", requiredMode = Schema.RequiredMode.REQUIRED)
36 42 @ExcelProperty("是否置顶 0否 1是")
37 43 private Boolean pinned;
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationSaveReqVO.java
... ... @@ -7,6 +7,7 @@ import lombok.Data;
7 7  
8 8 import java.time.LocalDateTime;
9 9  
  10 +// TODO @hao:这个貌似业务上,暂时用不到,可以考虑删除哈。
10 11 @Schema(description = "管理后台 - 会话新增/修改 Request VO")
11 12 @Data
12 13 public class ImConversationSaveReqVO {
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/conversation/ImConversationDO.java
... ... @@ -9,7 +9,7 @@ import lombok.*;
9 9 import java.time.LocalDateTime;
10 10  
11 11 /**
12   - * 会话 DO
  12 + * IM 会话 DO
13 13 *
14 14 * @author 芋道源码
15 15 */
... ... @@ -32,12 +32,21 @@ public class ImConversationDO extends BaseDO {
32 32 * 所属用户
33 33 */
34 34 private Long userId;
  35 + // TODO @hao:注释可以改成,如下
  36 + /**
  37 + * 会话类型
  38 + *
  39 + * 枚举 {@link cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum}
  40 + */
35 41 /**
36 42 * 类型:1 单聊;2 群聊;4 通知会话(预留)
37 43 */
  44 + // TODO @hao:conversationType 改成 type
38 45 private Integer conversationType;
39 46 /**
40   - * 单聊时,用户编号;群聊时,群编号
  47 + * 聊天对象编号
  48 + *
  49 + * 1. 单聊时,用户编号;群聊时,群编号
41 50 */
42 51 private Long targetId;
43 52 /**
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/group/ImGroupDO.java
... ... @@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.*;
5 5 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
6 6  
7 7 /**
8   - * 群 DO
  8 + * IM 群信息 DO
9 9 *
10 10 * @author 芋道源码
11 11 */
... ... @@ -24,14 +24,17 @@ public class ImGroupDO extends BaseDO {
24 24 */
25 25 @TableId
26 26 private Long id;
  27 + // TODO @hao:name,如果这个表已经是 group 了,不用在带额外的
27 28 /**
28 29 * 群名字
29 30 */
30 31 private String groupName;
  32 + // TODO @hao:关联字段;
31 33 /**
32   - * 群主id
  34 + * 群主编号
33 35 */
34 36 private Long ownerId;
  37 + // TODO @hao:头像使用 avatar 好了,整个项目统一;然后 Thumb 是不是不用存,这个更多是文件服务做裁剪
35 38 /**
36 39 * 群头像
37 40 */
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/groupmember/GroupMemberDO.java
... ... @@ -7,8 +7,9 @@ import java.time.LocalDateTime;
7 7 import com.baomidou.mybatisplus.annotation.*;
8 8 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
9 9  
  10 +// TODO @hao:这个挪到 group 包下;
10 11 /**
11   - * 群成员 DO
  12 + * IM 群成员 DO
12 13 *
13 14 * @author 芋道源码
14 15 */
... ... @@ -27,14 +28,16 @@ public class GroupMemberDO extends BaseDO {
27 28 */
28 29 @TableId
29 30 private Long id;
  31 + // TODO @hao:groupId 和 userId 都写下关联字段哈
30 32 /**
31   - * 群 id
  33 + * 群编号
32 34 */
33 35 private Long groupId;
34 36 /**
35   - * 用户id
  37 + * 用户编号
36 38 */
37 39 private Long userId;
  40 + // TODO @hao:nickname 和 avatar 是不是不用存储哈;
38 41 /**
39 42 * 昵称
40 43 */
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/inbox/ImInboxDO.java
... ... @@ -6,8 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
6 6 import com.baomidou.mybatisplus.annotation.TableName;
7 7 import lombok.*;
8 8  
  9 +// TODO 我们要不要改成 ImMessageQueue 队列?从理解上,概念上,可能都更清晰一点哈。每个用户一个消息队列;
9 10 /**
10   - * 收件箱 DO
  11 + * IM 收件箱 DO
11 12 *
12 13 * @author 芋道源码
13 14 */
... ... @@ -28,6 +29,8 @@ public class ImInboxDO extends BaseDO {
28 29 private Long id;
29 30 /**
30 31 * 用户编号
  32 + *
  33 + * TODO @hao:写下 userId 和 messageId 的关联字段
31 34 */
32 35 private Long userId;
33 36 /**
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/message/ImMessageDO.java
... ... @@ -9,7 +9,7 @@ import lombok.*;
9 9 import java.time.LocalDateTime;
10 10  
11 11 /**
12   - * 消息 DO
  12 + * IM 消息 DO
13 13 *
14 14 * @author 芋道源码
15 15 */
... ... @@ -32,6 +32,7 @@ public class ImMessageDO extends BaseDO {
32 32 * 客户端消息编号 uuid,用于排重
33 33 */
34 34 private String clientMessageId;
  35 + // TODO @hao:senderId、receiverId 存储的具体值写下,对应的群之类的
35 36 /**
36 37 * 发送人编号
37 38 */
... ... @@ -40,18 +41,23 @@ public class ImMessageDO extends BaseDO {
40 41 * 接收人编号
41 42 */
42 43 private Long receiverId;
  44 + // TODO @hao:冗余字段,要说明下的。例如说
43 45 /**
44 46 * 发送人昵称
  47 + *
  48 + * 冗余 AdminUserDO 的 nickname 字段
45 49 */
46 50 private String senderNickname;
47 51 /**
48 52 * 发送人头像
49 53 */
50 54 private String senderAvatar;
  55 + // TODO @hao:关联枚举
51 56 /**
52 57 * 会话类型
53 58 */
54 59 private Integer conversationType;
  60 + // TODO @hao:关联字段
55 61 /**
56 62 * 会话标志
57 63 */
... ... @@ -60,6 +66,7 @@ public class ImMessageDO extends BaseDO {
60 66 * 消息类型
61 67 */
62 68 private Integer contentType;
  69 + // TODO @hao:说明下是 json 格式,在哪个包看具体的格式
63 70 /**
64 71 * 消息内容
65 72 */
... ... @@ -68,11 +75,12 @@ public class ImMessageDO extends BaseDO {
68 75 * 发送时间
69 76 */
70 77 private LocalDateTime sendTime;
  78 + // TODO @hao:搞个枚举,然后代码里注释说明下
71 79 /**
72 80 * 消息来源 100-用户发送;200-系统发送(一般是通知);
73 81 */
74 82 private Integer sendFrom;
75   -
  83 + // TODO @hao:搞个枚举,然后代码里注释说明下
76 84 /**
77 85 * 消息状态 1 发送中、2 发送成功、3 发送失败、4 已删除、5 已撤回
78 86 */
... ...
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/jackson/ImMessageBodyDeserializer.java
... ... @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode;
8 8  
9 9 import java.io.IOException;
10 10  
  11 +// TODO @hao:可以讨论下:是不是前端传递 type + content,后端根据 type 判断后,直接 jsonutil 解析到对应的 body 就 ok 了
11 12 public class ImMessageBodyDeserializer extends JsonDeserializer<ImMessageBody> {
12 13  
13 14 @Override
... ... @@ -33,4 +34,5 @@ public class ImMessageBodyDeserializer extends JsonDeserializer&lt;ImMessageBody&gt; {
33 34 // 如果没有匹配的属性,抛出异常
34 35 throw ctxt.mappingException("Cannot deserialize to an instance of ImMessageBody");
35 36 }
  37 +
36 38 }
37 39 \ No newline at end of file
... ...
yudao-module-im/yudao-module-im-biz/src/test/java/cn/iocoder/yudao/module/im/service/conversation/ImConversationServiceImplTest.java
... ... @@ -21,6 +21,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
21 21 import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
22 22 import static org.junit.jupiter.api.Assertions.*;
23 23  
  24 +// TODO @hao:单测可以先都删除,等后面搞了在弄
24 25 /**
25 26 * {@link ImConversationServiceImpl} 的单元测试类
26 27 *
... ...