|
|
@@ -1,5 +1,6 @@
|
|
|
package com.dderp.common.servlet.file;
|
|
|
|
|
|
+import com.dderp.common.api.StoreService;
|
|
|
import com.dderp.common.api.SupplierInitService;
|
|
|
import com.dderp.common.api.SystemService;
|
|
|
import com.dderp.common.base.ERPAdminHttpServlet;
|
|
|
@@ -47,6 +48,9 @@ public class FileUploadServlet extends ERPAdminHttpServlet {
|
|
|
@Resource
|
|
|
private QiniuOSSService qiniuOSSService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ StoreService storeService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 使用plupload上传大文件,可分块上传
|
|
|
@@ -140,6 +144,80 @@ public class FileUploadServlet extends ERPAdminHttpServlet {
|
|
|
|
|
|
@HttpMapping(url = "/upload/uploadStoreBrandLogo", auth = true, comment = "门店品牌logo上传")
|
|
|
public void uploadStoreBrandLogo(HttpRequest req, HttpResponse resp) throws IOException {
|
|
|
- //todo 感觉logo只是展示用,需要记录下存放位置即可,不需要下载,待大哥有空的时候详细问下
|
|
|
+ ERPTokenUser currentUser = req.currentUser();
|
|
|
+ long supplierCode = currentUser.getSupplierCode();
|
|
|
+ for (MultiPart part : req.multiParts()) {
|
|
|
+ //plupload会分块上传,name为文件名,chunks为上传总块数,chunk为当前块数
|
|
|
+ //如果chunk=0,表示是第一块,此时需要创建文件,其后是在文件末尾添加内容
|
|
|
+ //文件名的处理,如果在服务端生成,那么分块的时候还需要保存实际文件名和随机名的生成关系,处理相对麻烦
|
|
|
+ //系统这里使用plupload配置unique_names属性,将会得到一个不重复的文件名
|
|
|
+ // String fileName = req.getParameter("name");
|
|
|
+ String srcFileName = req.getParameter("srcfilename");
|
|
|
+ long idStoreBrand = req.getLongParameter("idStoreBrand", 0L);
|
|
|
+
|
|
|
+ if (idStoreBrand <= 0) {
|
|
|
+ resp.finish(500, "门店品牌id未指定");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info(srcFileName);
|
|
|
+
|
|
|
+ int chunks = req.getIntParameter("chunks", 0);
|
|
|
+ int chunk = req.getIntParameter("chunk", 0);
|
|
|
+
|
|
|
+ //由于当前orderRoot不在是本地文件夹,先传到本地,再拷贝到
|
|
|
+ File destPath = new File(bucketFileRoot + File.separator +
|
|
|
+ currentUser.getSupplierCode() + File.separator +
|
|
|
+ "storeBrand" + File.separator + String.valueOf(idStoreBrand) + File.separator + "logo");
|
|
|
+ if (!destPath.exists()) {
|
|
|
+ destPath.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ //String destFile = destPath.getCanonicalPath() + File.separator + srcFileName;
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int second = cal.get(Calendar.SECOND);
|
|
|
+ int millSecond = cal.get(Calendar.MILLISECOND);
|
|
|
+ int minute = cal.get(Calendar.MINUTE);
|
|
|
+ int hour = cal.get(Calendar.HOUR_OF_DAY);
|
|
|
+ //示例:OB2112100022原图162545954.png
|
|
|
+ String targetFileName = String.valueOf(idStoreBrand) + "logo" + String.valueOf(hour) + String.valueOf(minute) +
|
|
|
+ String.valueOf(second) + String.valueOf(millSecond) + srcFileName.substring(srcFileName.lastIndexOf("."));
|
|
|
+ String destFile = destPath.getCanonicalPath() + File.separator + targetFileName;
|
|
|
+ InputStream in = part.getInputStream();
|
|
|
+
|
|
|
+ if ((chunk == 0) && (chunks > 0)) {
|
|
|
+ if (Files.exists(Paths.get(destFile))) {
|
|
|
+ resp.finish(500, "文件已存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Files.deleteIfExists(Paths.get(destFile));
|
|
|
+
|
|
|
+ ERPUtils.createFileFromInStream(destFile, in);
|
|
|
+ } else {
|
|
|
+ ERPUtils.appendFileFromInStream(destFile, in);
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderDownloadHttpUrl = supplierInitService.getDownloadRootUrl(currentUser.getDataSourceId(), currentUser.getSupplierCode());
|
|
|
+ String downloadUrlStr = orderDownloadHttpUrl + currentUser.getSupplierCode() + "/" +
|
|
|
+ "storeBrand/" +
|
|
|
+ String.valueOf(idStoreBrand) + "/" +
|
|
|
+ "logo" + "/" + targetFileName;
|
|
|
+ if (chunk == chunks - 1) {
|
|
|
+ //扔至后台进行处理
|
|
|
+ //上传完成
|
|
|
+ storeService.uploadBrandLogo(idStoreBrand, downloadUrlStr, currentUser,
|
|
|
+ currentUser.getDataSourceId(), currentUser.getSupplierCode());
|
|
|
+ logger.info("文件上传完成name:" + req.getParameter("name") + "总块数:" + req.getParameter("chunks"));
|
|
|
+ }
|
|
|
+
|
|
|
+ FileUploadEntity entity = new FileUploadEntity();
|
|
|
+ entity.setFileName(targetFileName);
|
|
|
+ entity.setUrl(downloadUrlStr);
|
|
|
+ resp.finishJson(entity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ resp.finish("success");
|
|
|
}
|
|
|
}
|