lzy 3 weeks ago
parent
commit
f0901b2b39

+ 52 - 0
src/main/java/com/zhentao/groups/MongoDB/controller/GroupMessageController.java

@@ -0,0 +1,52 @@
+package com.zhentao.groups.MongoDB.controller;
+
+import com.zhentao.config.NullLogin;
+import com.zhentao.groups.MongoDB.pojo.GroupMessage;
+import com.zhentao.groups.MongoDB.pojo.Message;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+
+@RequestMapping("/group")
+@RestController
+public class GroupMessageController {
+
+    @Autowired
+    RedisTemplate<String,String> redisTemplate;
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+
+    @PostMapping("/groupMessage")
+    @NullLogin
+    public String groupMessage(@RequestBody Message message)
+    {
+        GroupMessage groupMessage = new GroupMessage();
+        groupMessage.setGroup_id(message.getGroup_id());
+        groupMessage.setSender_id(message.getSender_id());
+        groupMessage.setContent(message.getContent());
+        groupMessage.setContent_type(message.getContent_type());
+        groupMessage.setCreated_at(new Date());
+
+        mongoTemplate.save(groupMessage);
+
+
+        return "success";
+    }
+
+
+
+
+
+
+
+
+}

+ 36 - 0
src/main/java/com/zhentao/groups/MongoDB/pojo/GroupMessage.java

@@ -0,0 +1,36 @@
+package com.zhentao.groups.MongoDB.pojo;
+
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.index.Indexed;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.Date;
+
+
+@Slf4j
+@Document(collection = "group_messages")
+@Data
+public class GroupMessage {
+
+    @Id
+    private String id;
+
+////    消息唯一id
+//    private String message_id;
+
+//  群id
+    private Long group_id;
+//  发送者ID
+    private Long sender_id;
+//  消息内容
+    private String content;
+//  消息类型
+    private String content_type;
+//  发送时间
+    private Date created_at;
+
+
+
+}

+ 23 - 0
src/main/java/com/zhentao/groups/MongoDB/pojo/Message.java

@@ -0,0 +1,23 @@
+package com.zhentao.groups.MongoDB.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+@Data
+public class Message {
+
+//    //    消息唯一id
+//    private String message_id;
+
+    //  群id
+    private Long group_id;
+    //  发送者ID
+    private Long sender_id;
+    //  消息内容
+    private String content;
+    //  消息类型
+    private String content_type;
+    //  发送时间
+    private Date created_at;
+
+}

+ 18 - 0
src/main/java/com/zhentao/groups/mapper/GroupMembersMapper.java

@@ -0,0 +1,18 @@
+package com.zhentao.groups.mapper;
+
+import com.zhentao.groups.pojo.GroupMembers;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author lzy
+* @description 针对表【group_members(群组成员表)】的数据库操作Mapper
+* @createDate 2025-06-04 16:00:48
+* @Entity com.zhentao.groups.pojo.GroupMembers
+*/
+public interface GroupMembersMapper extends BaseMapper<GroupMembers> {
+
+}
+
+
+
+

+ 18 - 0
src/main/java/com/zhentao/groups/mapper/GroupsMapper.java

@@ -0,0 +1,18 @@
+package com.zhentao.groups.mapper;
+
+import com.zhentao.groups.pojo.Groups;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author lzy
+* @description 针对表【groups(群组表)】的数据库操作Mapper
+* @createDate 2025-06-04 16:00:48
+* @Entity com.zhentao.groups.pojo.Groups
+*/
+public interface GroupsMapper extends BaseMapper<Groups> {
+
+}
+
+
+
+

+ 109 - 0
src/main/java/com/zhentao/groups/pojo/GroupMembers.java

@@ -0,0 +1,109 @@
+package com.zhentao.groups.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 群组成员表
+ * @TableName group_members
+ */
+@TableName(value ="group_members")
+@Data
+public class GroupMembers implements Serializable {
+    /**
+     * 
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 群ID
+     */
+    private Long groupId;
+
+    /**
+     * 用户ID
+     */
+    private Long userId;
+
+    /**
+     * 群昵称
+     */
+    private String nickname;
+
+    /**
+     * 角色(0-成员,1-管理员,2-群主)
+     */
+    private Integer role;
+
+    /**
+     * 加入时间
+     */
+    private Date joinTime;
+
+    /**
+     * 最后确认的消息ID
+     */
+    private Long lastAckMsgId;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        GroupMembers other = (GroupMembers) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getGroupId() == null ? other.getGroupId() == null : this.getGroupId().equals(other.getGroupId()))
+            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+            && (this.getNickname() == null ? other.getNickname() == null : this.getNickname().equals(other.getNickname()))
+            && (this.getRole() == null ? other.getRole() == null : this.getRole().equals(other.getRole()))
+            && (this.getJoinTime() == null ? other.getJoinTime() == null : this.getJoinTime().equals(other.getJoinTime()))
+            && (this.getLastAckMsgId() == null ? other.getLastAckMsgId() == null : this.getLastAckMsgId().equals(other.getLastAckMsgId()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getGroupId() == null) ? 0 : getGroupId().hashCode());
+        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+        result = prime * result + ((getNickname() == null) ? 0 : getNickname().hashCode());
+        result = prime * result + ((getRole() == null) ? 0 : getRole().hashCode());
+        result = prime * result + ((getJoinTime() == null) ? 0 : getJoinTime().hashCode());
+        result = prime * result + ((getLastAckMsgId() == null) ? 0 : getLastAckMsgId().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", groupId=").append(groupId);
+        sb.append(", userId=").append(userId);
+        sb.append(", nickname=").append(nickname);
+        sb.append(", role=").append(role);
+        sb.append(", joinTime=").append(joinTime);
+        sb.append(", lastAckMsgId=").append(lastAckMsgId);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 134 - 0
src/main/java/com/zhentao/groups/pojo/Groups.java

@@ -0,0 +1,134 @@
+package com.zhentao.groups.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 群组表
+ * @TableName groups
+ */
+@TableName(value ="groups")
+@Data
+public class Groups implements Serializable {
+    /**
+     * id
+
+     */
+    @TableId(type = IdType.AUTO)
+    private Long groupId;
+
+    /**
+     * 群名称
+     */
+    private String name;
+
+    /**
+     * 创建者ID
+     */
+    private Long creatorId;
+
+    /**
+     * 群头像
+     */
+    private String avatar;
+
+    /**
+     * 群公告
+     */
+    private String announcement;
+
+    /**
+     * 群描述
+     */
+    private String description;
+
+    /**
+     * 最大成员数
+     */
+    private Integer maxMembers;
+
+    /**
+     * 状态(0-解散,1-正常)
+     */
+    private Integer status;
+
+    /**
+     * 创建时间
+     */
+    private Date createdAt;
+
+    /**
+     * 修改时间
+     */
+    private Date updatedAt;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        Groups other = (Groups) that;
+        return (this.getGroupId() == null ? other.getGroupId() == null : this.getGroupId().equals(other.getGroupId()))
+            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+            && (this.getCreatorId() == null ? other.getCreatorId() == null : this.getCreatorId().equals(other.getCreatorId()))
+            && (this.getAvatar() == null ? other.getAvatar() == null : this.getAvatar().equals(other.getAvatar()))
+            && (this.getAnnouncement() == null ? other.getAnnouncement() == null : this.getAnnouncement().equals(other.getAnnouncement()))
+            && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
+            && (this.getMaxMembers() == null ? other.getMaxMembers() == null : this.getMaxMembers().equals(other.getMaxMembers()))
+            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
+            && (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
+            && (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getGroupId() == null) ? 0 : getGroupId().hashCode());
+        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+        result = prime * result + ((getCreatorId() == null) ? 0 : getCreatorId().hashCode());
+        result = prime * result + ((getAvatar() == null) ? 0 : getAvatar().hashCode());
+        result = prime * result + ((getAnnouncement() == null) ? 0 : getAnnouncement().hashCode());
+        result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
+        result = prime * result + ((getMaxMembers() == null) ? 0 : getMaxMembers().hashCode());
+        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
+        result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
+        result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", groupId=").append(groupId);
+        sb.append(", name=").append(name);
+        sb.append(", creatorId=").append(creatorId);
+        sb.append(", avatar=").append(avatar);
+        sb.append(", announcement=").append(announcement);
+        sb.append(", description=").append(description);
+        sb.append(", maxMembers=").append(maxMembers);
+        sb.append(", status=").append(status);
+        sb.append(", createdAt=").append(createdAt);
+        sb.append(", updatedAt=").append(updatedAt);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 13 - 0
src/main/java/com/zhentao/groups/service/GroupMembersService.java

@@ -0,0 +1,13 @@
+package com.zhentao.groups.service;
+
+import com.zhentao.groups.pojo.GroupMembers;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author lzy
+* @description 针对表【group_members(群组成员表)】的数据库操作Service
+* @createDate 2025-06-04 16:00:48
+*/
+public interface GroupMembersService extends IService<GroupMembers> {
+
+}

+ 13 - 0
src/main/java/com/zhentao/groups/service/GroupsService.java

@@ -0,0 +1,13 @@
+package com.zhentao.groups.service;
+
+import com.zhentao.groups.pojo.Groups;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author lzy
+* @description 针对表【groups(群组表)】的数据库操作Service
+* @createDate 2025-06-04 16:00:48
+*/
+public interface GroupsService extends IService<Groups> {
+
+}

+ 22 - 0
src/main/java/com/zhentao/groups/service/impl/GroupMembersServiceImpl.java

@@ -0,0 +1,22 @@
+package com.zhentao.groups.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zhentao.groups.pojo.GroupMembers;
+import com.zhentao.groups.service.GroupMembersService;
+import com.zhentao.groups.mapper.GroupMembersMapper;
+import org.springframework.stereotype.Service;
+
+/**
+* @author lzy
+* @description 针对表【group_members(群组成员表)】的数据库操作Service实现
+* @createDate 2025-06-04 16:00:48
+*/
+@Service
+public class GroupMembersServiceImpl extends ServiceImpl<GroupMembersMapper, GroupMembers>
+    implements GroupMembersService{
+
+}
+
+
+
+

+ 22 - 0
src/main/java/com/zhentao/groups/service/impl/GroupsServiceImpl.java

@@ -0,0 +1,22 @@
+package com.zhentao.groups.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zhentao.groups.pojo.Groups;
+import com.zhentao.groups.service.GroupsService;
+import com.zhentao.groups.mapper.GroupsMapper;
+import org.springframework.stereotype.Service;
+
+/**
+* @author lzy
+* @description 针对表【groups(群组表)】的数据库操作Service实现
+* @createDate 2025-06-04 16:00:48
+*/
+@Service
+public class GroupsServiceImpl extends ServiceImpl<GroupsMapper, Groups>
+    implements GroupsService{
+
+}
+
+
+
+

+ 22 - 0
src/main/resources/mapper/GroupMembersMapper.xml

@@ -0,0 +1,22 @@
+<?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.zhentao.groups.mapper.GroupMembersMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.groups.pojo.GroupMembers">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="groupId" column="group_id" jdbcType="BIGINT"/>
+            <result property="userId" column="user_id" jdbcType="BIGINT"/>
+            <result property="nickname" column="nickname" jdbcType="VARCHAR"/>
+            <result property="role" column="role" jdbcType="TINYINT"/>
+            <result property="joinTime" column="join_time" jdbcType="TIMESTAMP"/>
+            <result property="lastAckMsgId" column="last_ack_msg_id" jdbcType="BIGINT"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,group_id,user_id,
+        nickname,role,join_time,
+        last_ack_msg_id
+    </sql>
+</mapper>

+ 26 - 0
src/main/resources/mapper/GroupsMapper.xml

@@ -0,0 +1,26 @@
+<?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.zhentao.groups.mapper.GroupsMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.groups.pojo.Groups">
+            <id property="groupId" column="group_id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
+            <result property="creatorId" column="creator_id" jdbcType="BIGINT"/>
+            <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
+            <result property="announcement" column="announcement" jdbcType="VARCHAR"/>
+            <result property="description" column="description" jdbcType="VARCHAR"/>
+            <result property="maxMembers" column="max_members" jdbcType="INTEGER"/>
+            <result property="status" column="status" jdbcType="TINYINT"/>
+            <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
+            <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        group_id,name,creator_id,
+        avatar,announcement,description,
+        max_members,status,created_at,
+        updated_at
+    </sql>
+</mapper>