2 Commits 3b5b602ece ... 61d691e0b0

Author SHA1 Message Date
  xl37192053 61d691e0b0 Merge remote-tracking branch 'origin/master' 2 years ago
  xl37192053 847fa4c2cd 门店品牌logo上传,差nginx配置前端显示。不报错,可编译 2 years ago

+ 1 - 0
conf/application-ddWebOne.xml

@@ -9,6 +9,7 @@
 
         <properties load="redis.properties;workProcess.properties;sftc.properties;platform.properties">
             <property name="orderFileRoot" value="${APP_HOME}/orderFiles"/>
+            <property name="bucketFileRoot" value="${APP_HOME}/bucketFiles"/>
             <!--注入sql脚本的目录-->
             <property name="sqlroot" value="${APP_HOME}/conf/sqlroot/"/>
 

+ 3 - 0
conf/sqlroot/com/dderp/business/dao/StoreDao.dql

@@ -31,6 +31,9 @@ brandMemo = #{brandmemo},updateBy = #{updateby},updateTime = #{updatetime},updat
  update $table$ set voidFlag = #{voidflag},updateBy = #{updateby},
  updateTime = #{updatetime},updateTimeLong = #{updatetimelong} where id = #{id};
 
+ -- [updateBrandLogoUrl]
+  update $table$ set brandLogoUrl = #{brandlogourl} where id = #{id};
+
  -- [queryStoreInfoList]
  select *
  from $table$

+ 5 - 0
ddBusiness/src/main/java/com/dderp/business/dao/StoreDao.java

@@ -26,6 +26,11 @@ public interface StoreDao extends DaoRepository {
 
     @Sharding(databaseShardingStrategy = SupplierDataBaseShardingStrategy.class, tableShardingStrategy = SupplierTableShardingStrategy.class)
     @DAOMethod(operator = OperatorType.UPDATE, owait = OperatorWait.ASNYC)
+    @SqlId(clazz = StoreDao.class, sql = "updateBrandLogoUrl", table = "tbStoreBrand", params = {1})
+    int updateBrandLogoUrl(StoreBrand storeBrand, @DatabaseShardingBy String dataSourceId, @TableShardingBy Long supplierCode);
+
+    @Sharding(databaseShardingStrategy = SupplierDataBaseShardingStrategy.class, tableShardingStrategy = SupplierTableShardingStrategy.class)
+    @DAOMethod(operator = OperatorType.UPDATE, owait = OperatorWait.ASNYC)
     @SqlId(clazz = StoreDao.class, sql = "voidStoreBrand", table = "tbStoreBrand", params = {1})
     int voidStoreBrand(StoreBrand storeBrand, @DatabaseShardingBy String dataSourceId, @TableShardingBy Long supplierCode);
     //endregion

+ 20 - 2
ddBusiness/src/main/java/com/dderp/business/service/StoreServiceImpl.java

@@ -147,9 +147,27 @@ public class StoreServiceImpl extends BaseService implements StoreService {
     }
 
     @Override
-    public RetResult<StoreBrand> uploadBrandLogo(long idStoreBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
-        return null;
+    public RetResult<StoreBrand> uploadBrandLogo(long idStoreBrand,String fileLink, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
+        StoreBrand esInfo = this.getStoreBrand(idStoreBrand, supplierCode);
+        if (esInfo == null)
+            return RetResult.<StoreBrand>errorT().retinfo("未找到此门店品牌");
 
+        esInfo.setBrandLogoUrl(fileLink);
+        try {
+            UpdateRequest updateRequest = new UpdateRequest(keysService.getESKey(ESKeys.ES_DELIVER_STORE_BRAND_INDEX, supplierCode),
+                    ESKeys.ES_DELIVER_STORE_BRAND_TYPE, String.valueOf(esInfo.getId()))
+                    .doc(jsonBuilder()
+                            .startObject()
+                            .field("brandLogoUrl", esInfo.getBrandLogoUrl())
+                            .endObject())
+                    .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
+
+            esClient.getClient().update(updateRequest).get();
+        } catch (IOException | InterruptedException | ExecutionException e) {
+            logger.error("修改门店品牌[" + esInfo.getId() + "出错:" + e.getMessage(), e);
+        }
+        storeDao.updateBrandLogoUrl(esInfo, dataSourceId, supplierCode);
+        return RetResult.successT();
     }
 
     @Override

+ 1 - 1
ddCommon/src/main/java/com/dderp/common/api/StoreService.java

@@ -18,7 +18,7 @@ public interface StoreService extends ScriptService {
 
     RetResult<StoreBrand> addStoreBrand(StoreBrand storeBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode);
 
-    RetResult<StoreBrand> uploadBrandLogo(long idStoreBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode);
+    RetResult<StoreBrand> uploadBrandLogo(long idStoreBrand,String fileLink, ERPTokenUser currentUser, String dataSourceId, long supplierCode);
 
     RetResult<StoreBrand> updateStoreBrand(StoreBrand storeBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode);
 

+ 79 - 1
ddCommon/src/main/java/com/dderp/common/servlet/file/FileUploadServlet.java

@@ -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");
     }
 }