From c27ad3dcb8b67a6c10a99c98b9bd6dd1f08b7967 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期二, 01 三月 2022 10:43:15 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/sc/common/web/UploadController.java |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/zy/sc/common/web/UploadController.java b/src/main/java/com/zy/sc/common/web/UploadController.java
index 0165414..807b74a 100644
--- a/src/main/java/com/zy/sc/common/web/UploadController.java
+++ b/src/main/java/com/zy/sc/common/web/UploadController.java
@@ -8,6 +8,7 @@
 import com.zy.sc.common.service.OssService;
 import com.zy.sc.manager.entity.Issue;
 import com.zy.sc.manager.service.IssueService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -21,6 +22,7 @@
 /**
  * Created by vincent on 2020/10/7
  */
+@Slf4j
 @RestController
 public class UploadController extends BaseController {
 
@@ -31,14 +33,14 @@
 
     @PostMapping("/upload.action")
     public R upload(MultipartFile file) {
-        String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
+        log.info("寮�濮嬩笂浼犳枃浠讹細{}锛涙枃浠跺ぇ灏忥細{}", file.getOriginalFilename(), file.getSize());
         InputStream inputStream = null;
         try {
             inputStream = file.getInputStream();
         } catch (IOException e) {
             e.printStackTrace();
         }
-        String upload=ossService.upload(inputStream,suffix);
+        String upload = ossService.upload(inputStream,file.getOriginalFilename());
         return R.ok(Cools.add("url", upload));
     }
 
@@ -47,7 +49,7 @@
     public R sensorUpload(MultipartFile file, @RequestParam("issueId") Long issueId) {
         Issue issue = issueService.selectById(issueId);
         if (null == issue) {
-            return R.error("璁惧涓嶅瓨鍦�");
+            return R.error("鏁呴殰涓嶅瓨鍦�");
         }
         String img = issue.getImg();
         JSONArray jsonArray = JSON.parseArray(img);
@@ -58,16 +60,23 @@
             return R.error("鍥剧墖涓婁紶鏁伴噺宸插埌涓婇檺");
         }
         // oss
-        String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
         InputStream inputStream = null;
         try {
             inputStream = file.getInputStream();
         } catch (IOException e) {
             e.printStackTrace();
         }
-        String upload = ossService.upload(inputStream,suffix);
+        String upload = ossService.upload(inputStream,file.getOriginalFilename());
         if (Cools.isEmpty(upload)) {
             return R.error("涓婁紶OSS鏈嶅姟澶辫触");
+        }
+        jsonArray.add(upload);
+        // 鎸佷箙鍖�
+        issue.setImg(jsonArray.toJSONString());
+        issue.setUpdateBy(getUserId());
+        issue.setUpdateTime(new Date());
+        if (!issueService.updateById(issue)) {
+            return R.error("涓婁紶鍥剧墖澶辫触");
         }
         return R.ok(Cools.add("src", upload));
     }
@@ -93,7 +102,7 @@
         issue.setUpdateBy(getUserId());
         issue.setUpdateTime(new Date());
         if (!issueService.updateById(issue)) {
-            return R.error("淇濇寔鏁版嵁搴撳け璐�");
+            return R.error("鍒犻櫎鍥剧墖澶辫触");
         }
         return R.ok("鍒犻櫎鎴愬姛");
     }

--
Gitblit v1.9.1