From cf68ee0531ebadbc7b27b8e6e56b9f3c4e893e05 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 09 Jan 2024 16:25:21 +0800
Subject: [PATCH] 首页菜单的首页二字改成英文的Main

---
 src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 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 2467205..df4c3b5 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
@@ -20,6 +20,7 @@
 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 lombok.extern.slf4j.Slf4j;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -30,6 +31,7 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
@@ -42,6 +44,7 @@
  * @author wzy
  * @date 2022-07-04
  **/
+@Slf4j
 @Service
 public class CmsTemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTemplateEntity> implements ICmsTemplateService {
 
@@ -87,6 +90,7 @@
                     return;
                 }
 
+                FileUtil.touch(new File(staticPath + "/empty.txt"));
                 for (File templateFile : files) {
                     if (!templateFile.isFile()) {
                         FileUtil.move(templateFile, new File(staticPath), true);
@@ -178,7 +182,7 @@
     public Result dropdownList() {
         Long companyId = LoginUserUtil.getCompanyId();
         QueryWrapper<CmsTemplateEntity> objectQueryWrapper = new QueryWrapper<>();
-        objectQueryWrapper.eq("company_id",companyId);
+        objectQueryWrapper.eq("company_id", companyId);
         List<CmsTemplateEntity> cmsTemplateEntities = this.baseMapper.selectList(objectQueryWrapper);
         return Result.ok(cmsTemplateEntities);
     }
@@ -189,8 +193,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];
@@ -211,14 +217,17 @@
     public Result saveTemplateInfo(AdminSaveTemplateInfoDto adminSaveTemplateInfoDto) {
         Long companyId = LoginUserUtil.getCompanyId();
         Long id = adminSaveTemplateInfoDto.getId();
-        CmsTemplateEntity cmsTemplateEntity = this.baseMapper.selectByIdAndCompanyId(id,companyId);
+
+        CompanyEntity company = this.companyMapper.selectById(companyId);
+        CmsTemplateEntity cmsTemplateEntity = this.baseMapper.selectByIdAndCompanyId(id, companyId);
         String name = cmsTemplateEntity.getName();
         Integer type = cmsTemplateEntity.getType();
-        String templatePath = cmsProperties.getTemplatePath();
+        String templatePath = FileUtils.path(cmsProperties.getTemplatePath(), company.getCode());
         String path = cmsTemplateEntity.getPath();
 
-        this.baseMapper.delete(id,companyId);
+        this.baseMapper.delete(id, companyId);
         String pathNew = FileUtils.path(templatePath, path);
+        log.info("模板写入地址:{}", pathNew);
         File file = new File(pathNew);
         FileUtil.touch(file);
 
@@ -236,4 +245,18 @@
         return Result.ok("保存成功");
     }
 
+    @Override
+    public Result downloadTemplate() {
+        Long companyId = LoginUserUtil.getCompanyId();
+        CompanyEntity company = this.companyMapper.selectById(companyId);
+
+        String templatePath = FileUtils.path(cmsProperties.getTemplatePath(), company.getCode());
+        String staticPath = FileUtils.path(cmsProperties.getStaticPath(), company.getCode());
+        String downloadPath = FileUtils.path(cmsProperties.getDownloadPath(), company.getCode());
+
+        String fileName = "template.zip";
+        ZipUtil.zip(FileUtil.file(downloadPath + "/template.zip"), true, FileUtil.file(templatePath), FileUtil.file(staticPath));
+        String url = cmsProperties.getStaticUrl() + "download/" + company.getCode();
+        return Result.ok("success", url +"/" + fileName);
+    }
 }

--
Gitblit v1.9.1