lzy 3 weeks ago
parent
commit
88761fbbd7

+ 6 - 1
pom.xml

@@ -23,7 +23,12 @@
             <groupId>org.hibernate.validator</groupId>
             <artifactId>hibernate-validator</artifactId>
         </dependency>
-
+        <!-- 阿里云OSS SDK -->
+        <dependency>
+            <groupId>com.aliyun.oss</groupId>
+            <artifactId>aliyun-sdk-oss</artifactId>
+            <version>3.15.1</version>
+        </dependency>
         <dependency>
             <groupId>org.redisson</groupId>
             <artifactId>redisson</artifactId>

+ 17 - 0
src/main/java/com/zhentao/groups/controller/groupsController.java

@@ -0,0 +1,17 @@
+package com.zhentao.groups.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RequestMapping("/groups")
+@RestController
+public class groupsController {
+
+
+
+
+
+
+
+}

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

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

+ 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 lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 群组表
+ * @TableName groups
+ */
+@TableName(value ="groups")
+@Data
+public class Groups implements Serializable {
+    /**
+     * 
+     */
+    @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/GroupsService.java

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

+ 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.mapper.GroupsMapper;
+import com.zhentao.groups.pojo.Groups;
+import com.zhentao.groups.service.GroupsService;
+import org.springframework.stereotype.Service;
+
+/**
+* @author lzy
+* @description 针对表【groups(群组表)】的数据库操作Service实现
+* @createDate 2025-06-04 14:02:51
+*/
+@Service
+public class GroupsServiceImpl extends ServiceImpl<GroupsMapper, Groups>
+    implements GroupsService {
+
+}
+
+
+
+

+ 50 - 0
src/main/java/com/zhentao/oss/OSSService.java

@@ -0,0 +1,50 @@
+package com.zhentao.oss;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.UUID;
+
+@Service
+public class OSSService {
+
+    @Value("${oss.endpoint}")
+    private String endpoint;
+
+    @Value("${oss.accessKeyId}")
+    private String accessKeyId;
+
+    @Value("${oss.accessKeySecret}")
+    private String accessKeySecret;
+
+    @Value("${oss.bucketName}")
+    private String bucketName;
+
+    public String upload(MultipartFile file) throws IOException {
+        // 生成唯一文件名
+        String originalFilename = file.getOriginalFilename();
+        String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
+        String objectName = UUID.randomUUID().toString() ;
+        Date date = new Date();
+        date.setTime(date.getTime() + 1000 * 60 * 60 * 24 * 7);
+        objectName = date.getTime() + objectName.substring(2,10)+ fileExtension;
+        System.out.println(objectName);
+        // 上传到OSS
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        try {
+            ossClient.putObject(bucketName, objectName, file.getInputStream());
+            return generateUrl(objectName);
+        } finally {
+            ossClient.shutdown();
+        }
+    }
+
+    private String generateUrl(String objectName) {
+        return "https://" + bucketName + "." + endpoint.replace("https://", "") + "/" + objectName;
+    }
+}

+ 9 - 0
src/main/resources/application.yml

@@ -33,3 +33,12 @@ spring:
     host: 47.110.46.22
     port: 6379
     database: 0
+oss:
+  endpoint: oss-cn-beijing.aliyuncs.com
+  accessKeyId: LTAI5t8n6ywFPYgaXQZ14Vck
+  accessKeySecret: eBQKmWRrAPMnZ2f8v4aO8PCohnbLyD
+  bucketName: lzytest1
+
+
+
+

+ 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>