Sfoglia il codice sorgente

feat(system):优化文件上传与查询逻辑

- 修改数据库连接URL为game_admin库
- 增加数据库连接超时时间至60000ms
- 新增uploadInputstream方法支持流式上传MultipartFile
- OssClient增加uploadStream方法用于流式上传
- PlayersItemsLogMapper查询条件增加type=1过滤- SysOssServiceImpl实现uploadInputstream方法并使用流式上传
- TournamentsServiceImpl调用新的流式上传接口
- UserCheckRecordBo新增flagType字段用于日期类型标识
- UserCheckRecordServiceImpl根据flagType动态计算查询时间范围
fugui001 2 mesi fa
parent
commit
2597ac08e4

+ 2 - 2
ruoyi-admin/src/main/resources/application-prod.yml

@@ -52,7 +52,7 @@ spring:
           driverClassName: com.mysql.cj.jdbc.Driver
           # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
           # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
-          url: jdbc:mysql://39.96.219.239:3306/db_ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
+          url: jdbc:mysql://39.96.219.239:3306/game_admin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
           username: root
           password: StrongP@ssw0rd!
         mysql2:
@@ -95,7 +95,7 @@ spring:
         # 最小空闲线程数量
         minIdle: 10
         # 配置获取连接等待超时的时间
-        connectionTimeout: 30000
+        connectionTimeout: 60000
         # 校验超时时间
         validationTimeout: 5000
         # 空闲连接存活最大时间,默认10分钟

+ 20 - 0
ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java

@@ -313,6 +313,26 @@ public class OssClient {
         return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length), contentType);
     }
 
+    /**
+     * 上传 InputStream 数据到 S3/OSS,使用指定后缀构造对象键(流式上传,推荐用于大文件)
+     *
+     * @param inputStream 要上传的输入流(调用方负责关闭)
+     * @param suffix      对象键的后缀(如 ".jpg")
+     * @param contentType 内容类型(如 "image/jpeg")
+     * @param size        文件大小(用于 Content-Length,-1 表示未知)
+     * @return UploadResult 上传结果
+     * @throws OssException 上传失败时抛出
+     */
+    public UploadResult uploadStream(InputStream inputStream, String suffix, String contentType, long size) {
+        String objectKey = getPath(properties.getPrefix(), suffix);
+
+        try {
+            return upload(inputStream, objectKey, size, contentType);
+        } catch (Exception e) {
+            throw new OssException("文件上传失败: " + e.getMessage());
+        }
+    }
+
     /**
      * 上传 InputStream 到 Amazon S3,使用指定的后缀构造对象键。
      *

+ 4 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/bo/UserCheckRecordBo.java

@@ -76,4 +76,8 @@ public class UserCheckRecordBo extends BaseEntity {
     private String endTime;
 
 
+    /**
+     *  日周月 三天  日期
+     */
+    private String flagType;
 }

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/TournamentsServiceImpl.java

@@ -612,7 +612,7 @@ public class TournamentsServiceImpl implements ITournamentsService {
     @Override
     public SysOssVo uploadTournament(MultipartFile file) {
         // 1. 上传文件到 OSS
-        SysOssVo sysOssVo = ossService.upload(file);
+        SysOssVo sysOssVo = ossService.uploadInputstream(file);
         return sysOssVo;
     }
 

+ 15 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/UserCheckRecordServiceImpl.java

@@ -11,6 +11,7 @@ import org.dromara.business.mapper.PlayerItemsMapper;
 import org.dromara.business.mapper.UserCheckRecordMapper;
 import org.dromara.business.service.IUserCheckRecordService;
 import org.dromara.business.service.IUserService;
+import org.dromara.business.utils.DateTimeRangeUtils;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -62,6 +63,20 @@ public class UserCheckRecordServiceImpl implements IUserCheckRecordService {
      */
     @Override
     public TableDataInfo<UserCheckRecordVo> queryPageList(UserCheckRecordBo bo, PageQuery pageQuery) {
+
+        String startDate = "";
+        String endDate = "";
+        String flagType = bo.getFlagType();
+        if(StringUtils.isNotBlank(flagType) && (flagType.equals("day") || flagType.equals("week") || flagType.equals("month") || flagType.equals("three"))){
+            startDate = DateTimeRangeUtils.getStartString(flagType);
+            endDate = DateTimeRangeUtils.getEndString(flagType);
+        } else {
+            startDate = bo.getBeginTime();
+            endDate = bo.getEndTime();
+        }
+        bo.setBeginTime(startDate);
+        bo.setEndTime(endDate);
+
         Wrapper<UserCheckRecord> lqw = buildQueryWrapper(bo);
         Page<UserCheckRecordVo> result = baseMapper.selectCheckRecordList(pageQuery.build(), lqw);
         return TableDataInfo.build(result);

+ 7 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java

@@ -79,8 +79,13 @@ public interface ISysOssService {
 
 
 
-
-
+    /**
+     * 上传 MultipartFile 到对象存储服务,并保存文件信息到数据库
+     *
+     * @param file 要上传的 MultipartFile 输入流对象
+     * @return 上传成功后的 SysOssVo 输入流对象,包含文件信息
+     */
+    SysOssVo uploadInputstream(MultipartFile file);
 
 
 

+ 27 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java

@@ -22,6 +22,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.oss.core.OssClient;
 import org.dromara.common.oss.entity.UploadResult;
 import org.dromara.common.oss.enums.AccessPolicyType;
+import org.dromara.common.oss.exception.OssException;
 import org.dromara.common.oss.factory.OssFactory;
 import org.dromara.system.domain.SysOss;
 import org.dromara.system.domain.bo.SysOssBo;
@@ -33,9 +34,12 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
+import software.amazon.awssdk.core.exception.SdkClientException;
+import software.amazon.awssdk.services.s3.model.PutObjectRequest;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -252,6 +256,29 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
         return baseMapper.deleteByIds(ids) > 0;
     }
 
+    @Override
+    public SysOssVo uploadInputstream(MultipartFile file) {
+        String originalFilename = file.getOriginalFilename();
+        String suffix = StringUtils.substring(originalFilename, originalFilename.lastIndexOf("."));
+
+        OssClient storage = OssFactory.instance();
+
+        UploadResult uploadResult;
+        try (InputStream inputStream = file.getInputStream()) {
+            // ✅ 使用流式上传,避免 getBytes()
+            uploadResult = storage.uploadStream(
+                inputStream,
+                suffix,
+                file.getContentType(),
+                file.getSize()  // 传大小,便于分片
+            );
+        } catch (IOException e) {
+            throw new ServiceException("文件上传失败: " + e.getMessage());
+        }
+
+        return buildResultEntity(originalFilename, suffix, storage.getConfigKey(), uploadResult);
+    }
+
     /**
      * 桶类型为 private 的URL 修改为临时URL时长为120s
      *

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/PlayersItemsLogMapper.xml

@@ -119,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
             players_items_log
         where  created_at >= #{beginTime} and created_at &lt; #{endTime}
-        and item_id=1001
+        and item_id=1001 and type=1
     </select>
 
     <select id="selectPlayerItermGraphSanXianCardByTime" resultType="org.dromara.business.domain.vo.PlayersItemsLogVo">
@@ -131,7 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             created_at >= #{beginTime}
           AND created_at &lt; #{endTime}
-          AND item_id = 1001
+          AND item_id = 1001 and type=1
         GROUP BY
             DATE(created_at)
         ORDER BY