From ef5505e22c84a63d966f35cee78afa544ece57df Mon Sep 17 00:00:00 2001
From: wzy <wzy19931122ai@163.com>
Date: Sun, 07 Aug 2022 14:33:32 +0800
Subject: [PATCH] fix

---
 src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
index cad593b..4c2a1bc 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
@@ -15,7 +15,9 @@
 import com.xcong.farmer.cms.modules.system.dto.AdminSaveTemplateInfoDto;
 import com.xcong.farmer.cms.modules.system.dto.TemplateListDto;
 import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity;
+import com.xcong.farmer.cms.modules.system.entity.CompanyEntity;
 import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper;
+import com.xcong.farmer.cms.modules.system.mapper.CompanyMapper;
 import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService;
 import com.xcong.farmer.cms.modules.system.util.LoginUserUtil;
 import org.jsoup.Jsoup;
@@ -46,6 +48,10 @@
     @Autowired
     private CmsProperties properties;
 
+    @Autowired
+    private CompanyMapper companyMapper;
+
+
     private List<String> fileSuffix = Arrays.asList(".zip", ".html");
 
     @Override
@@ -53,6 +59,11 @@
         String templatePath = properties.getTemplatePath();
         String staticPath = properties.getStaticPath();
         Long companyId = LoginUserUtil.getCompanyId();
+        CompanyEntity company = companyMapper.selectById(companyId);
+
+        String companyCode = company.getCode();
+        templatePath = FileUtils.path(templatePath, companyCode);
+        staticPath = FileUtils.path(staticPath, companyCode);
 
         String filename = upload.getOriginalFilename();
         String suffix = filename.substring(filename.lastIndexOf("."));
@@ -91,14 +102,14 @@
                         continue;
                     }
 
-                    insertTemplate(templateFile, companyId);
+                    insertTemplate(templateFile, companyId, companyCode);
                 }
             }
 
             if (".html".equals(suffix)) {
                 FileUtil.touch(file);
 
-                insertTemplate(file, companyId);
+                insertTemplate(file, companyId, companyCode);
             }
         } catch (IOException e) {
             e.printStackTrace();
@@ -106,13 +117,13 @@
         }
     }
 
-    private void insertTemplate(File file, Long companyId) throws IOException {
+    private void insertTemplate(File file, Long companyId, String companyCode) throws IOException {
         Document parse = Jsoup.parse(file, null);
         String attr = parse.head().attr("name");
 
-        staticPathParser(parse, "img", "src");
-        staticPathParser(parse, "link", "href");
-        staticPathParser(parse, "script", "src");
+        staticPathParser(parse, "img", "src", companyCode);
+        staticPathParser(parse, "link", "href", companyCode);
+        staticPathParser(parse, "script", "src", companyCode);
 
         FileOutputStream outputStream = new FileOutputStream(file);
         outputStream.write(parse.html().getBytes());
@@ -133,7 +144,7 @@
         this.baseMapper.insert(cmsTemplate);
     }
 
-    private void staticPathParser(Document document, String tagName, String attrKey) {
+    private void staticPathParser(Document document, String tagName, String attrKey, String companyCode) {
         Elements elements = document.getElementsByTag(tagName);
         if (elements.isEmpty()) {
             return;
@@ -142,7 +153,7 @@
         for (Element element : elements) {
             String attr = element.attr(attrKey);
             if (StrUtil.isNotBlank(attr) && !attr.contains("http://") && !attr.contains("https://")) {
-                element.attr(attrKey, cmsProperties.getStaticPath() + attr);
+                element.attr(attrKey, cmsProperties.getStaticUrl() + companyCode + "/" + attr);
             }
         }
     }
@@ -178,8 +189,10 @@
     @Override
     public Result viewTemplateInfo(Long id) {
         Result result = new Result();
+
+        CompanyEntity companyEntity = companyMapper.selectById(LoginUserUtil.getCompanyId());
         CmsTemplateEntity cmsTemplateEntity = this.baseMapper.selectById(id);
-        String templatePath = cmsProperties.getTemplatePath();
+        String templatePath = FileUtils.path(cmsProperties.getTemplatePath(), companyEntity.getCode());
         String pathName = FileUtils.path(templatePath, cmsTemplateEntity.getPath());
 
         byte[] bytes = new byte[0];

--
Gitblit v1.9.1