From 7676cdcdffa925c857a0c3de83911cd056dfabd5 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sat, 28 Jul 2018 15:48:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?litemall-admin=E5=92=8Clitemall-wx=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0=E4=B8=8D=E5=86=8D=E4=BE=9D?= =?UTF-8?q?=E8=B5=96os=E6=A8=A1=E5=9D=97=EF=BC=8C=E8=80=8C=E6=98=AFlitemal?= =?UTF-8?q?l-admin-api=E5=92=8Clitemall-wx-api=E6=A8=A1=E5=9D=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/web/AdminStorageController.java | 113 ++++++++++++++++++ litemall-admin/config/dep.env.js | 3 +- litemall-admin/config/dev.env.js | 3 +- litemall-admin/config/prod.env.js | 3 +- litemall-admin/src/api/storage.js | 35 ++---- .../litemall/core/storage/LocalStorage.java | 5 +- .../src/main/resources/application-core.yml | 2 +- .../litemall/wx/web/WxStorageController.java | 107 +++++++++++++++++ litemall-wx/config/api.js | 16 +-- 9 files changed, 235 insertions(+), 52 deletions(-) create mode 100644 litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java create mode 100644 litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java 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 new file mode 100644 index 00000000..aaf512a0 --- /dev/null +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java @@ -0,0 +1,113 @@ +package org.linlinjava.litemall.admin.web; + +import org.linlinjava.litemall.core.storage.StorageService; +import org.linlinjava.litemall.core.util.CharUtil; +import org.linlinjava.litemall.core.util.ResponseUtil; +import org.linlinjava.litemall.db.domain.LitemallStorage; +import org.linlinjava.litemall.db.service.LitemallStorageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/admin/storage") +public class AdminStorageController { + + @Autowired + private StorageService storageService; + @Autowired + private LitemallStorageService litemallStorageService; + + private String generateKey(String originalFilename){ + int index = originalFilename.lastIndexOf('.'); + String suffix = originalFilename.substring(index); + + String key = null; + LitemallStorage storageInfo = null; + + do{ + key = CharUtil.getRandomString(20) + suffix; + storageInfo = litemallStorageService.findByKey(key); + } + while(storageInfo != null); + + return key; + } + + @GetMapping("/list") + public Object list(String key, String name, + @RequestParam(value = "page", defaultValue = "1") Integer page, + @RequestParam(value = "limit", defaultValue = "10") Integer limit, + String sort, String order){ + List storageList = litemallStorageService.querySelective(key, name, page, limit, sort, order); + int total = litemallStorageService.countSelective(key, name, page, limit, sort, order); + Map data = new HashMap<>(); + data.put("total", total); + data.put("items", storageList); + + return ResponseUtil.ok(data); + } + + @PostMapping("/create") + public Object create(@RequestParam("file") MultipartFile file) { + String originalFilename = file.getOriginalFilename(); + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + e.printStackTrace(); + return ResponseUtil.badArgumentValue(); + } + String key = generateKey(originalFilename); + storageService.store(file, key); + + String url = storageService.generateUrl(key); + LitemallStorage storageInfo = new LitemallStorage(); + storageInfo.setName(originalFilename); + storageInfo.setSize((int)file.getSize()); + storageInfo.setType(file.getContentType()); + storageInfo.setAddTime(LocalDateTime.now()); + storageInfo.setModified(LocalDateTime.now()); + storageInfo.setKey(key); + storageInfo.setUrl(url); + litemallStorageService.add(storageInfo); + return ResponseUtil.ok(storageInfo); + } + + @PostMapping("/read") + public Object read(Integer id) { + if(id == null){ + return ResponseUtil.badArgument(); + } + LitemallStorage storageInfo = litemallStorageService.findById(id); + if(storageInfo == null){ + return ResponseUtil.badArgumentValue(); + } + return ResponseUtil.ok(storageInfo); + } + + @PostMapping("/update") + public Object update(@RequestBody LitemallStorage litemallStorage) { + + litemallStorageService.update(litemallStorage); + return ResponseUtil.ok(litemallStorage); + } + + @PostMapping("/delete") + public Object delete(@RequestBody LitemallStorage litemallStorage) { + litemallStorageService.deleteByKey(litemallStorage.getKey()); + storageService.delete(litemallStorage.getKey()); + return ResponseUtil.ok(); + } +} diff --git a/litemall-admin/config/dep.env.js b/litemall-admin/config/dep.env.js index 512f55d7..db4d9480 100644 --- a/litemall-admin/config/dep.env.js +++ b/litemall-admin/config/dep.env.js @@ -1,6 +1,5 @@ module.exports = { NODE_ENV: '"production"', ENV_CONFIG: '"dep"', - BASE_API: '"http://122.152.206.172:8083/admin"', - OS_API: '"http://122.152.206.172:8081/os"' + BASE_API: '"http://122.152.206.172:8083/admin"' } diff --git a/litemall-admin/config/dev.env.js b/litemall-admin/config/dev.env.js index b82f20da..4629bf88 100644 --- a/litemall-admin/config/dev.env.js +++ b/litemall-admin/config/dev.env.js @@ -1,6 +1,5 @@ module.exports = { NODE_ENV: '"development"', ENV_CONFIG: '"dev"', - BASE_API: '"http://localhost:8083/admin"', - OS_API: '"http://localhost:8081/os"' + BASE_API: '"http://localhost:8083/admin"' } diff --git a/litemall-admin/config/prod.env.js b/litemall-admin/config/prod.env.js index c41e0a37..7477e14b 100644 --- a/litemall-admin/config/prod.env.js +++ b/litemall-admin/config/prod.env.js @@ -1,6 +1,5 @@ module.exports = { NODE_ENV: '"production"', ENV_CONFIG: '"prod"', - BASE_API: '"https://www.example.com/admin"', - OS_API: '"https://www.example.com/os"' + BASE_API: '"https://www.example.com/admin"' } diff --git a/litemall-admin/src/api/storage.js b/litemall-admin/src/api/storage.js index 07547fc8..be0307ed 100644 --- a/litemall-admin/src/api/storage.js +++ b/litemall-admin/src/api/storage.js @@ -1,28 +1,7 @@ -import axios from 'axios' -import { Message } from 'element-ui' - -// create an axios instance -const service = axios.create({ - baseURL: process.env.OS_API, // api的base_url - timeout: 5000 // request timeout -}) - -// respone interceptor -service.interceptors.response.use( - response => { - return response - }, error => { - console.log('err' + error)// for debug - Message({ - message: '对象存储服务访问超时,请检查链接是否能够访问。', - type: 'error', - duration: 5 * 1000 - }) - return Promise.reject(error) - }) +import request from '@/utils/request' export function listStorage(query) { - return service({ + return request({ url: '/storage/list', method: 'get', params: query @@ -30,7 +9,7 @@ export function listStorage(query) { } export function createStorage(data) { - return service({ + return request({ url: '/storage/create', method: 'post', data @@ -38,7 +17,7 @@ export function createStorage(data) { } export function readStorage(data) { - return service({ + return request({ url: '/storage/read', method: 'get', data @@ -46,7 +25,7 @@ export function readStorage(data) { } export function updateStorage(data) { - return service({ + return request({ url: '/storage/update', method: 'post', data @@ -54,12 +33,12 @@ export function updateStorage(data) { } export function deleteStorage(data) { - return service({ + return request({ url: '/storage/delete', method: 'post', data }) } -const uploadPath = process.env.OS_API + '/storage/create' +const uploadPath = process.env.BASE_API + '/storage/create' export { uploadPath } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java index e2922546..345fff5b 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java @@ -110,10 +110,7 @@ public class LocalStorage implements Storage { @Override public String generateUrl(String keyName) { - String url = address + ":" + port + "/os/storage/fetch/" + keyName; - if (!url.startsWith("http")) { - url = "http://" + url; - } + String url = address + keyName; return url; } } \ No newline at end of file diff --git a/litemall-core/src/main/resources/application-core.yml b/litemall-core/src/main/resources/application-core.yml index 1e2bd9f8..69b561c0 100644 --- a/litemall-core/src/main/resources/application-core.yml +++ b/litemall-core/src/main/resources/application-core.yml @@ -88,7 +88,7 @@ litemall: # 本地对象存储配置信息 local: storagePath: storage - address: http://127.0.0.1 + address: http://localhost:8082/wx/storage/fetch/ port: 8081 # 阿里云对象存储配置信息 aliyun: 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 new file mode 100644 index 00000000..6f19df9d --- /dev/null +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java @@ -0,0 +1,107 @@ +package org.linlinjava.litemall.wx.web; + +import org.linlinjava.litemall.core.storage.StorageService; +import org.linlinjava.litemall.core.util.CharUtil; +import org.linlinjava.litemall.core.util.ResponseUtil; +import org.linlinjava.litemall.db.domain.LitemallStorage; +import org.linlinjava.litemall.db.service.LitemallStorageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/wx/storage") +public class WxStorageController { + + @Autowired + private StorageService storageService; + @Autowired + private LitemallStorageService litemallStorageService; + + private String generateKey(String originalFilename){ + int index = originalFilename.lastIndexOf('.'); + String suffix = originalFilename.substring(index); + + String key = null; + LitemallStorage storageInfo = null; + + do{ + key = CharUtil.getRandomString(20) + suffix; + storageInfo = litemallStorageService.findByKey(key); + } + while(storageInfo != null); + + return key; + } + + @PostMapping("/upload") + public Object upload(@RequestParam("file") MultipartFile file) { + String originalFilename = file.getOriginalFilename(); + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + e.printStackTrace(); + return ResponseUtil.badArgumentValue(); + } + String key = generateKey(originalFilename); + storageService.store(file, key); + + String url = storageService.generateUrl(key); + LitemallStorage storageInfo = new LitemallStorage(); + storageInfo.setName(originalFilename); + storageInfo.setSize((int)file.getSize()); + storageInfo.setType(file.getContentType()); + storageInfo.setAddTime(LocalDateTime.now()); + storageInfo.setModified(LocalDateTime.now()); + storageInfo.setKey(key); + storageInfo.setUrl(url); + litemallStorageService.add(storageInfo); + return ResponseUtil.ok(storageInfo); + } + + @GetMapping("/fetch/{key:.+}") + public ResponseEntity fetch(@PathVariable String key) { + LitemallStorage litemallStorage = litemallStorageService.findByKey(key); + if(key == null){ + ResponseEntity.notFound(); + } + String type = litemallStorage.getType(); + MediaType mediaType = MediaType.parseMediaType(type); + + Resource file = storageService.loadAsResource(key); + if(file == null) { + ResponseEntity.notFound(); + } + return ResponseEntity.ok().contentType(mediaType).body(file); + } + + @GetMapping("/download/{key:.+}") + public ResponseEntity download(@PathVariable String key) { + LitemallStorage litemallStorage = litemallStorageService.findByKey(key); + if(key == null){ + ResponseEntity.notFound(); + } + String type = litemallStorage.getType(); + MediaType mediaType = MediaType.parseMediaType(type); + + Resource file = storageService.loadAsResource(key); + if(file == null) { + ResponseEntity.notFound(); + } + return ResponseEntity.ok().contentType(mediaType).header(HttpHeaders.CONTENT_DISPOSITION, + "attachment; filename=\"" + file.getFilename() + "\"").body(file); + } + +} diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index be425adc..9f722565 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -1,23 +1,13 @@ // 以下是业务服务器API地址 // 本机开发时使用 -// var WxApiRoot = 'http://localhost:8082/wx/'; + var WxApiRoot = 'http://localhost:8082/wx/'; // 局域网测试使用 // var WxApiRoot = 'http://192.168.0.101:8082/wx/'; // 云平台部署时使用 -var WxApiRoot = 'http://122.152.206.172:8082/wx/'; +// var WxApiRoot = 'http://122.152.206.172:8082/wx/'; // 云平台上线时使用 // var WxApiRoot = 'https://www.menethil.com.cn/wx/'; -// 以下是图片存储服务器API地址 -// 本机开发时使用 -// var StorageApi = 'http://localhost:8081/os/storage/create'; -// 局域网测试时使用 -// var StorageApi = 'http://192.168.0.101:8081/os/storage/create'; -// 云平台部署时使用 -var StorageApi = 'http://122.152.206.172:8081/os/storage/create'; -// 云平台上线时使用 -// var StorageApi = 'https://www.menethil.com.cn/os/storage/create'; - module.exports = { IndexUrl: WxApiRoot + 'home/index', //首页数据接口 CatalogList: WxApiRoot + 'catalog/index', //分类目录全部分类数据接口 @@ -89,5 +79,5 @@ module.exports = { UserFormIdCreate: WxApiRoot + 'formid/create', //用户FromId,用于发送模版消息 - StorageUpload: StorageApi, //图片上传 + StorageUpload: WxApiRoot + 'storage/upload' //图片上传 }; \ No newline at end of file From f55fff673f1d1def0e245c328c4034ad1b5cdde6 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sat, 28 Jul 2018 16:28:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=AD=A3=E5=BC=8F?= =?UTF-8?q?=E5=88=A0=E9=99=A4os=E6=A8=A1=E5=9D=97=EF=BC=8C=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 3 - deploy/.gitignore | 3 +- deploy/bin/deploy.sh | 2 - deploy/litemall-api/README.md | 2 +- deploy/litemall-api/config/application-os.yml | 0 deploy/util/package.sh | 1 - litemall-all/pom.xml | 5 - .../org/linlinjava/litemall/Application.java | 1 - .../litemall/allinone/AllinoneConfigTest.java | 3 - litemall-os-api/.gitignore | 4 - litemall-os-api/pom.xml | 83 ---------- .../linlinjava/litemall/os/Application.java | 15 -- .../litemall/os/web/OsIndexController.java | 19 --- .../litemall/os/web/OsStorageController.java | 147 ------------------ .../src/main/resources/application-os.yml | 0 .../src/main/resources/application.yml | 16 -- pom.xml | 6 - 17 files changed, 2 insertions(+), 308 deletions(-) delete mode 100644 deploy/litemall-api/config/application-os.yml delete mode 100644 litemall-os-api/.gitignore delete mode 100644 litemall-os-api/pom.xml delete mode 100644 litemall-os-api/src/main/java/org/linlinjava/litemall/os/Application.java delete mode 100644 litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsIndexController.java delete mode 100644 litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsStorageController.java delete mode 100644 litemall-os-api/src/main/resources/application-os.yml delete mode 100644 litemall-os-api/src/main/resources/application.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7a8f6f10..4d496692 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,13 +8,10 @@ deploy: - rm -rf /root/spring_boot/*.jar - rm -rf /etc/init.d/litemall-* - cp -rf litemall-admin-api/target/litemall-admin-api-*-exec.jar /root/spring_boot/litemall-admin-api.jar - - cp -rf litemall-os-api/target/litemall-os-api-*-exec.jar /root/spring_boot/litemall-os-api.jar - cp -rf litemall-wx-api/target/litemall-wx-api-*-exec.jar /root/spring_boot/litemall-wx-api.jar - sudo chmod 777 /root/spring_boot/*.jar - sudo ln -f -s /root/spring_boot/litemall-admin-api.jar /etc/init.d/litemall-admin-api - - sudo ln -f -s /root/spring_boot/litemall-os-api.jar /etc/init.d/litemall-os-api - sudo ln -f -s /root/spring_boot/litemall-wx-api.jar /etc/init.d/litemall-wx-api - - sudo /etc/init.d/litemall-os-api restart - sudo /etc/init.d/litemall-wx-api restart - sudo /etc/init.d/litemall-admin-api restart - systemctl stop nginx diff --git a/deploy/.gitignore b/deploy/.gitignore index 0c543298..9b6a6735 100644 --- a/deploy/.gitignore +++ b/deploy/.gitignore @@ -3,5 +3,4 @@ /litemall-db/litemall_table.sql /litemall-db/litemall_data.sql /litemall-api/litemall-admin-api.jar -/litemall-api/litemall-wx-api.jar -/litemall-api/litemall-os-api.jar +/litemall-api/litemall-wx-api.jar \ No newline at end of file diff --git a/deploy/bin/deploy.sh b/deploy/bin/deploy.sh index 8019788d..b96570ce 100644 --- a/deploy/bin/deploy.sh +++ b/deploy/bin/deploy.sh @@ -18,12 +18,10 @@ sudo service litemall-wx-api stop sudo service litemall-admin-api stop #部署Spring Boot应用成服务 -sudo ln -f -s /home/ubuntu/deploy/litemall-api/litemall-os-api.jar /etc/init.d/litemall-os-api sudo ln -f -s /home/ubuntu/deploy/litemall-api/litemall-wx-api.jar /etc/init.d/litemall-wx-api sudo ln -f -s /home/ubuntu/deploy/litemall-api/litemall-admin-api.jar /etc/init.d/litemall-admin-api #启动服务 -sudo service litemall-os-api restart sudo service litemall-wx-api restart sudo service litemall-admin-api restart diff --git a/deploy/litemall-api/README.md b/deploy/litemall-api/README.md index 3e0e422a..d65328f1 100644 --- a/deploy/litemall-api/README.md +++ b/deploy/litemall-api/README.md @@ -1,6 +1,6 @@ 开发者需要注意的是 -litemall-os-api.jar、litemall-wx-api.jar和litemall-admin-api.jar三个模块内部 +litemall-wx-api.jar和litemall-admin-api.jar两个模块内部 已经有默认的开发配置文件,但是这些配置文件可能仅仅适用于开发阶段。 为了应用部署阶段时期的配置文件,开发者可以在config文件夹里面的同名配置文件中 diff --git a/deploy/litemall-api/config/application-os.yml b/deploy/litemall-api/config/application-os.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/deploy/util/package.sh b/deploy/util/package.sh index 466dea11..45aac623 100644 --- a/deploy/util/package.sh +++ b/deploy/util/package.sh @@ -31,6 +31,5 @@ tar -zcvf ./deploy/litemall-admin/dist.tar -C ./litemall-admin/dist . # 这里我们需要的是可执行jar mvn clean mvn package -cp -f ./litemall-os-api/target/litemall-os-api-*-exec.jar ./deploy/litemall-api/litemall-os-api.jar cp -f ./litemall-wx-api/target/litemall-wx-api-*-exec.jar ./deploy/litemall-api/litemall-wx-api.jar cp -f ./litemall-admin-api/target/litemall-admin-api-*-exec.jar ./deploy/litemall-api/litemall-admin-api.jar \ No newline at end of file diff --git a/litemall-all/pom.xml b/litemall-all/pom.xml index 7bf3334b..41bf6493 100644 --- a/litemall-all/pom.xml +++ b/litemall-all/pom.xml @@ -28,11 +28,6 @@ litemall-db - - org.linlinjava - litemall-os-api - - org.linlinjava litemall-wx-api diff --git a/litemall-all/src/main/java/org/linlinjava/litemall/Application.java b/litemall-all/src/main/java/org/linlinjava/litemall/Application.java index a3228228..f4988f23 100644 --- a/litemall-all/src/main/java/org/linlinjava/litemall/Application.java +++ b/litemall-all/src/main/java/org/linlinjava/litemall/Application.java @@ -10,7 +10,6 @@ import org.springframework.boot.web.support.SpringBootServletInitializer; "org.linlinjava.litemall", "org.linlinjava.litemall.core", "org.linlinjava.litemall.db", - "org.linlinjava.litemall.os", "org.linlinjava.litemall.wx", "org.linlinjava.litemall.admin"}) @MapperScan("org.linlinjava.litemall.db.dao") diff --git a/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java b/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java index f52724ea..c76785f1 100644 --- a/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java +++ b/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java @@ -24,11 +24,8 @@ public class AllinoneConfigTest { // 测试获取application-wx.yml配置信息 System.out.println(environment.getProperty("litemall.wx.app-id")); // 测试获取application-admin.yml配置信息 -// System.out.println(environment.getProperty("")); - // 测试获取application-os.yml配置信息 // System.out.println(environment.getProperty("")); // 测试获取application.yml配置信息 - System.out.println(environment.getProperty("logging.level.org.linlinjava.litemall.os")); System.out.println(environment.getProperty("logging.level.org.linlinjava.litemall.wx")); System.out.println(environment.getProperty("logging.level.org.linlinjava.litemall.admin")); System.out.println(environment.getProperty("logging.level.org.linlinjava.litemall")); diff --git a/litemall-os-api/.gitignore b/litemall-os-api/.gitignore deleted file mode 100644 index 63b6b474..00000000 --- a/litemall-os-api/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ - -/target/ -/litemall-os-api.iml -/storage/ diff --git a/litemall-os-api/pom.xml b/litemall-os-api/pom.xml deleted file mode 100644 index d3d718bb..00000000 --- a/litemall-os-api/pom.xml +++ /dev/null @@ -1,83 +0,0 @@ - - 4.0.0 - litemall-os-api - jar - - - org.linlinjava - litemall - 0.1.0 - - - - - - org.linlinjava - litemall-core - - - - org.linlinjava - litemall-db - - - - com.qcloud - cos_api - 5.4.4 - - - slf4j-log4j12 - org.slf4j - - - - - - com.aliyun.oss - aliyun-sdk-oss - 2.5.0 - - - - - - - - - src/main/resources - - - - src/main/java - - **/*.properties - **/*.xml - - false - - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - - repackage - - - exec - - - - - - - - \ No newline at end of file diff --git a/litemall-os-api/src/main/java/org/linlinjava/litemall/os/Application.java b/litemall-os-api/src/main/java/org/linlinjava/litemall/os/Application.java deleted file mode 100644 index fdb7fd00..00000000 --- a/litemall-os-api/src/main/java/org/linlinjava/litemall/os/Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.linlinjava.litemall.os; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication(scanBasePackages={"org.linlinjava.litemall.core", "org.linlinjava.litemall.os","org.linlinjava.litemall.db"}) -@MapperScan("org.linlinjava.litemall.db.dao") -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} \ No newline at end of file diff --git a/litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsIndexController.java b/litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsIndexController.java deleted file mode 100644 index 8d79b89d..00000000 --- a/litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsIndexController.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.linlinjava.litemall.os.web; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.linlinjava.litemall.core.util.ResponseUtil; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/os/index") -public class OsIndexController { - private final Log logger = LogFactory.getLog(OsIndexController.class); - - @RequestMapping("/index") - public Object index(){ - return ResponseUtil.ok("hello world, this is os service"); - } - -} diff --git a/litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsStorageController.java b/litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsStorageController.java deleted file mode 100644 index c897d91d..00000000 --- a/litemall-os-api/src/main/java/org/linlinjava/litemall/os/web/OsStorageController.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.linlinjava.litemall.os.web; - -import org.linlinjava.litemall.core.storage.StorageService; -import org.linlinjava.litemall.core.util.CharUtil; -import org.linlinjava.litemall.core.util.ResponseUtil; -import org.linlinjava.litemall.db.domain.LitemallStorage; -import org.linlinjava.litemall.db.service.LitemallStorageService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.io.InputStream; -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@RestController -@RequestMapping("/os/storage") -public class OsStorageController { - - @Autowired - private StorageService storageService; - @Autowired - private LitemallStorageService litemallStorageService; - - private String generateKey(String originalFilename){ - int index = originalFilename.lastIndexOf('.'); - String suffix = originalFilename.substring(index); - - String key = null; - LitemallStorage storageInfo = null; - - do{ - key = CharUtil.getRandomString(20) + suffix; - storageInfo = litemallStorageService.findByKey(key); - } - while(storageInfo != null); - - return key; - } - - @GetMapping("/list") - public Object list(String key, String name, - @RequestParam(value = "page", defaultValue = "1") Integer page, - @RequestParam(value = "limit", defaultValue = "10") Integer limit, - String sort, String order){ - List storageList = litemallStorageService.querySelective(key, name, page, limit, sort, order); - int total = litemallStorageService.countSelective(key, name, page, limit, sort, order); - Map data = new HashMap<>(); - data.put("total", total); - data.put("items", storageList); - - return ResponseUtil.ok(data); - } - - @PostMapping("/create") - public Object create(@RequestParam("file") MultipartFile file) { - String originalFilename = file.getOriginalFilename(); - InputStream inputStream = null; - try { - inputStream = file.getInputStream(); - } catch (IOException e) { - e.printStackTrace(); - return ResponseUtil.badArgumentValue(); - } - String key = generateKey(originalFilename); - storageService.store(file, key); - - String url = storageService.generateUrl(key); - LitemallStorage storageInfo = new LitemallStorage(); - storageInfo.setName(originalFilename); - storageInfo.setSize((int)file.getSize()); - storageInfo.setType(file.getContentType()); - storageInfo.setAddTime(LocalDateTime.now()); - storageInfo.setModified(LocalDateTime.now()); - storageInfo.setKey(key); - storageInfo.setUrl(url); - litemallStorageService.add(storageInfo); - return ResponseUtil.ok(storageInfo); - } - - @PostMapping("/read") - public Object read(Integer id) { - if(id == null){ - return ResponseUtil.badArgument(); - } - LitemallStorage storageInfo = litemallStorageService.findById(id); - if(storageInfo == null){ - return ResponseUtil.badArgumentValue(); - } - return ResponseUtil.ok(storageInfo); - } - - @PostMapping("/update") - public Object update(@RequestBody LitemallStorage litemallStorage) { - - litemallStorageService.update(litemallStorage); - return ResponseUtil.ok(litemallStorage); - } - - @PostMapping("/delete") - public Object delete(@RequestBody LitemallStorage litemallStorage) { - litemallStorageService.deleteByKey(litemallStorage.getKey()); - storageService.delete(litemallStorage.getKey()); - return ResponseUtil.ok(); - } - - @GetMapping("/fetch/{key:.+}") - public ResponseEntity fetch(@PathVariable String key) { - LitemallStorage litemallStorage = litemallStorageService.findByKey(key); - if(key == null){ - ResponseEntity.notFound(); - } - String type = litemallStorage.getType(); - MediaType mediaType = MediaType.parseMediaType(type); - - Resource file = storageService.loadAsResource(key); - if(file == null) { - ResponseEntity.notFound(); - } - return ResponseEntity.ok().contentType(mediaType).body(file); - } - - @GetMapping("/download/{key:.+}") - public ResponseEntity download(@PathVariable String key) { - LitemallStorage litemallStorage = litemallStorageService.findByKey(key); - if(key == null){ - ResponseEntity.notFound(); - } - String type = litemallStorage.getType(); - MediaType mediaType = MediaType.parseMediaType(type); - - Resource file = storageService.loadAsResource(key); - if(file == null) { - ResponseEntity.notFound(); - } - return ResponseEntity.ok().contentType(mediaType).header(HttpHeaders.CONTENT_DISPOSITION, - "attachment; filename=\"" + file.getFilename() + "\"").body(file); - } - -} diff --git a/litemall-os-api/src/main/resources/application-os.yml b/litemall-os-api/src/main/resources/application-os.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/litemall-os-api/src/main/resources/application.yml b/litemall-os-api/src/main/resources/application.yml deleted file mode 100644 index e2057241..00000000 --- a/litemall-os-api/src/main/resources/application.yml +++ /dev/null @@ -1,16 +0,0 @@ -spring: - profiles: - active: db, core, os - message: - encoding: UTF-8 - -server: - port: 8081 - -logging: - level: - root: ERROR - org.springframework: ERROR - org.mybatis: ERROR - org.linlinjava.litemall.os: DEBUG - org.linlinjava.litemall: ERROR \ No newline at end of file diff --git a/pom.xml b/pom.xml index 16dbffa6..aa99675a 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,6 @@ litemall-core litemall-db - litemall-os-api litemall-wx-api litemall-admin-api litemall-all @@ -40,11 +39,6 @@ litemall-db ${project.version} - - org.linlinjava - litemall-os-api - ${project.version} - org.linlinjava litemall-wx-api From 70c32ff9ce1c784036b717834ece5da9cba5c526 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sat, 28 Jul 2018 16:30:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?refact[litemall-all]:=20=E4=BB=8E=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84war=E6=A8=A1=E5=BC=8F=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=88=90=E5=8F=AF=E6=89=A7=E8=A1=8Cjar=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- litemall-all/pom.xml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/litemall-all/pom.xml b/litemall-all/pom.xml index 41bf6493..83262651 100644 --- a/litemall-all/pom.xml +++ b/litemall-all/pom.xml @@ -12,12 +12,6 @@ - - org.springframework.boot - spring-boot-starter-tomcat - provided - - org.linlinjava litemall-core @@ -41,44 +35,7 @@ - - - - src/main/resources - - - - src/main/java - - **/*.properties - **/*.xml - - false - - - - - maven-resources-plugin - - - copy-resources - validate - - copy-resources - - - ${basedir}/target/classes/static - - - ../litemall-admin/dist - - - - - - - org.springframework.boot spring-boot-maven-plugin