Forráskód Böngészése

同步-获取模板的html时,如果本地获取不到就通过Oss从远程下载到本地

LHB 2 hónapja
szülő
commit
6fc6129e09

+ 15 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousServiceImpl.java

@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
 import org.apache.commons.lang.ObjectUtils;
 import org.springblade.business.entity.InformationQuery;
 import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.log.publisher.ErrorLogPublisher;
@@ -23,7 +24,11 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.rmi.ServerException;
 import java.util.*;
 import java.util.function.Function;
@@ -180,6 +185,7 @@ public class WbsSynchronousServiceImpl {
      * @param wbsTreeSynchronousRecord
      */
     public void insertPrivateNode(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) throws IOException {
+        String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
         //同步类型 1.新增表单,2.新增节点,3.删除节点,4.删除表单,5.修改节点,6.修改表单,7.修改节点表单
         String type = wbsTreeSynchronousRecord.getType();
@@ -403,6 +409,15 @@ public class WbsSynchronousServiceImpl {
                                 String[] split = templateNode.getHtmlUrl().split("/");
                                 String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
                                 File file_in = ResourceUtil.getFile(templateNode.getHtmlUrl());
+                                InputStream fileInputStream;
+                                if (!file_in.exists()) {
+                                    String path = sys_file_net_url + templateNode.getHtmlUrl().replaceAll("//", "/").replaceAll(file_path, "");
+                                    fileInputStream = CommonUtil.getOSSInputStream(path);
+
+                                    file_in.createNewFile();
+                                    Files.copy(fileInputStream, file_in.toPath(), StandardCopyOption.REPLACE_EXISTING);
+                                }
+
                                 if (!file_in.exists() || file_in.length() == 0) {
                                     //如果本地服务器上没有
                                     throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");