From fd80760bb5e8f949b02e90ea60ee39941d81791a Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sat, 6 Apr 2019 23:10:55 +0800 Subject: [PATCH] =?UTF-8?q?fix[litemall-admin-api,=20litemall-core]:=20?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=AD=98=E5=82=A8=E8=BF=94=E5=9B=9E=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=AD=98=E5=82=A8=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E4=BB=85=E4=BB=85=E6=98=AF=E5=9B=BE=E7=89=87=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../litemall/admin/web/AdminStorageController.java | 6 ++---- .../org/linlinjava/litemall/core/qcode/QCodeService.java | 9 +++++---- .../linlinjava/litemall/core/storage/StorageService.java | 4 ++-- .../linlinjava/litemall/wx/web/WxStorageController.java | 7 ++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java index 4b6e1786..10300882 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java @@ -56,10 +56,8 @@ public class AdminStorageController { @PostMapping("/create") public Object create(@RequestParam("file") MultipartFile file) throws IOException { String originalFilename = file.getOriginalFilename(); - String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename); - Map data = new HashMap<>(); - data.put("url", url); - return ResponseUtil.ok(data); + LitemallStorage litemallStorage = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename); + return ResponseUtil.ok(litemallStorage); } @RequiresPermissions("admin:storage:read") diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java index 0ff39e5a..49ac8cb7 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java @@ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException; import org.linlinjava.litemall.core.storage.StorageService; import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.db.domain.LitemallGroupon; +import org.linlinjava.litemall.db.domain.LitemallStorage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -33,9 +34,9 @@ public class QCodeService { byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); //存储分享图 - String url = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString())); + LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString())); - return url; + return storageInfo.getUrl(); } catch (WxErrorException e) { e.printStackTrace(); } catch (FileNotFoundException e) { @@ -67,9 +68,9 @@ public class QCodeService { byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); //存储分享图 - String url = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId)); + LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId)); - return url; + return litemallStorage.getUrl(); } catch (WxErrorException e) { e.printStackTrace(); } catch (FileNotFoundException e) { diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java index 2b642908..510f4c0c 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java @@ -43,7 +43,7 @@ public class StorageService { * @param contentType 文件类型 * @param fileName 文件索引名 */ - public String store(InputStream inputStream, long contentLength, String contentType, String fileName) { + public LitemallStorage store(InputStream inputStream, long contentLength, String contentType, String fileName) { String key = generateKey(fileName); storage.store(inputStream, contentLength, contentType, key); @@ -56,7 +56,7 @@ public class StorageService { storageInfo.setUrl(url); litemallStorageService.add(storageInfo); - return url; + return storageInfo; } private String generateKey(String originalFilename) { diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java index 637c002e..962f6a6b 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java @@ -53,11 +53,8 @@ public class WxStorageController { @PostMapping("/upload") public Object upload(@RequestParam("file") MultipartFile file) throws IOException { String originalFilename = file.getOriginalFilename(); - String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename); - - Map data = new HashMap<>(); - data.put("url", url); - return ResponseUtil.ok(data); + LitemallStorage litemallStorage = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename); + return ResponseUtil.ok(litemallStorage); } /**