From 13a31edf7f569cdcf15d3c43a476a2c947f47fbf Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 09 十一月 2025 22:33:24 +0800
Subject: [PATCH] feat: 增加hospdata表,同步sqlserver过来

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java |   89 +++++++++++++++++++++++++++++++-------------
 1 files changed, 62 insertions(+), 27 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
index 593f13c..508eb71 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
@@ -1,15 +1,12 @@
 package com.ruoyi.system.service.impl;
 
+import java.io.*;
 import java.math.BigDecimal;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.stream.Collectors;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 
@@ -518,7 +515,9 @@
     public Long uploadAttachment(Long taskId, MultipartFile file, String category) {
         try {
             // 涓婁紶鏂囦欢锛岃繑鍥炵浉瀵硅矾寰勶紙濡傦細/task/2025/01/15/xxx.jpg锛�
-            String fileName = FileUploadUtils.upload("/task", file);
+            String fileName = category+"_"+System.currentTimeMillis()+"_"+file.getOriginalFilename();
+
+            fileName=saveLocalPath(fileName,file.getInputStream());
             
             SysTaskAttachment attachment = new SysTaskAttachment();
             attachment.setTaskId(taskId);
@@ -543,7 +542,7 @@
 
             }
             
-            return result;
+            return attachment.getAttachmentId();
         } catch (IOException e) {
             throw new RuntimeException("鏂囦欢涓婁紶澶辫触锛�" + e.getMessage());
         }
@@ -577,26 +576,8 @@
             String fileName = "wx_" + mediaId.substring(0, Math.min(20, mediaId.length())) + "_" + System.currentTimeMillis() + ".jpg";
             
             // 淇濆瓨鍒版湰鍦�
-            String baseDir = FileUploadUtils.getDefaultBaseDir();
-            String datePath = DateUtils.datePath();
-            String uploadDir = baseDir + "/task/" + datePath;
-            
-            // 鍒涘缓鐩綍
-            File uploadPath = new File(uploadDir);
-            if (!uploadPath.exists()) {
-                uploadPath.mkdirs();
-            }
-            
-            // 淇濆瓨鏂囦欢
-            String filePath = uploadDir + "/" + fileName;
-            File file = new File(filePath);
-            try (FileOutputStream fos = new FileOutputStream(file)) {
-                fos.write(fileBytes);
-            }
-            
-            // 鐢熸垚鐩稿璺緞锛堜笉鍖呭惈baseDir锛�
-            String relativeFilePath = "/task/" + datePath + "/" + fileName;
-            
+            String relativeFilePath = saveLocalPath(fileName, fileBytes);
+
             // 淇濆瓨闄勪欢璁板綍
             SysTaskAttachment attachment = new SysTaskAttachment();
             attachment.setTaskId(taskId);
@@ -626,7 +607,61 @@
             throw new RuntimeException("浠庡井淇′笂浼犳枃浠跺け璐ワ細" + e.getMessage());
         }
     }
-    
+
+    private static String saveLocalPath(String fileName, byte[] fileBytes) throws IOException {
+        String baseDir = FileUploadUtils.getDefaultBaseDir();
+        String datePath = DateUtils.datePath();
+        String uploadDir = baseDir + "/task/" + datePath;
+
+        // 鍒涘缓鐩綍
+        File uploadPath = new File(uploadDir);
+        if (!uploadPath.exists()) {
+            uploadPath.mkdirs();
+        }
+
+        // 淇濆瓨鏂囦欢
+        String filePath = uploadDir + "/" + fileName;
+        File file = new File(filePath);
+        try (FileOutputStream fos = new FileOutputStream(file)) {
+            fos.write(fileBytes);
+        }
+
+        // 鐢熸垚鐩稿璺緞锛堜笉鍖呭惈baseDir锛�
+        String relativeFilePath = "/task/" + datePath + "/" + fileName;
+        return relativeFilePath;
+    }
+
+    private String saveLocalPath(String fileName,InputStream stream){
+        String baseDir = FileUploadUtils.getDefaultBaseDir();
+        String datePath = DateUtils.datePath();
+        String uploadDir = baseDir + "/task/" + datePath;
+
+        // 鍒涘缓鐩綍
+        File uploadPath = new File(uploadDir);
+        if (!uploadPath.exists()) {
+            uploadPath.mkdirs();
+        }
+
+        // 淇濆瓨鏂囦欢
+        String filePath = uploadDir + "/" + fileName;
+       //灏唅nputstream鍐欏叆鏂囦欢
+        try (OutputStream os = new FileOutputStream(filePath)) {
+            byte[] buffer = new byte[1024]; // 缂撳啿鍖猴紝鍑忓皯 IO 娆℃暟
+            int bytesRead;
+            // 寰幆璇诲彇杈撳叆娴佷腑鐨勬暟鎹紝鍐欏叆杈撳嚭娴�
+            while ((bytesRead = stream.read(buffer)) != -1) {
+                os.write(buffer, 0, bytesRead);
+            }
+            os.flush(); // 寮哄埗鍒锋柊缂撳啿鍖猴紝纭繚鏁版嵁鍐欏叆鏂囦欢
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        // 鐢熸垚鐩稿璺緞锛堜笉鍖呭惈baseDir锛�
+        String relativeFilePath = "/task/" + datePath + "/" + fileName;
+        return relativeFilePath;
+    }
+
     /**
      * 浠� URL 涓嬭浇鏂囦欢
      */

--
Gitblit v1.9.1