From 2736d16a8b1804f7291a56a147f76ef3584d6619 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Mon, 04 Jul 2022 19:35:31 +0800 Subject: [PATCH] fix 上传模板和查看栏目修改 --- src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 51 insertions(+), 6 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 f1e072f..1110bfb 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 @@ -1,5 +1,7 @@ package com.xcong.farmer.cms.modules.system.service.Impl; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ZipUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -13,6 +15,8 @@ import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper; import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService; import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -48,17 +52,58 @@ } try { + String path = FileUtils.path(templatePath, filename); + File file = new File(path); + upload.transferTo(file); + if (".zip".equals(suffix)) { - String path = FileUtils.path(templatePath, filename); - System.out.println(path); - File file = new File(path); - upload.transferTo(file); - FileUtils.zipUpload(file, templatePath, staticPath); + ZipUtil.unzip(file, new File(templatePath)); + FileUtil.del(file); + + File template = new File(templatePath); + File[] files = template.listFiles(); + if (files == null) { + return; + } + + for (File templateFile : files) { + if (!templateFile.isFile()) { + continue; + } + + if (!"html".equals(FileUtil.extName(templateFile))) { + continue; + } + + String name = templateFile.getName(); + if (!name.endsWith(".list.html") && !name.endsWith(".article.html") && !name.endsWith(".index.html")) { + continue; + } + + Document parse = Jsoup.parse(templateFile, null); + String attr = parse.head().attr("name"); + System.out.println(attr); + CmsTemplateEntity cmsTemplate = new CmsTemplateEntity(); + cmsTemplate.setCompanyId(10L); + if (name.endsWith(".list.html")) { + cmsTemplate.setType(2); + } else if (name.endsWith(".article.html")) { + cmsTemplate.setType(3); + } else { + cmsTemplate.setType(1); + } + cmsTemplate.setName(templateFile.getName()); + cmsTemplate.setPath(templateFile.getName()); + } + + } + + if (".html".equals(suffix)) { + FileUtil.touch(file); } } catch (IOException e) { e.printStackTrace(); } - System.out.println(suffix); } @Override -- Gitblit v1.9.1