From 51ea662e22121f9a0ddb5b40c4a8e93e098b34ec Mon Sep 17 00:00:00 2001 From: Hentua <wangdoubleone@gmail.com> Date: Wed, 10 Jan 2024 22:22:44 +0800 Subject: [PATCH] fxi --- src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java | 48 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java index b3f748a..e4ca7ce 100644 --- a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java +++ b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java @@ -1,7 +1,10 @@ package com.xcong.farmer.cms.core.template; +import com.xcong.farmer.cms.common.exception.GlobalException; +import com.xcong.farmer.cms.common.utils.FileUtils; import com.xcong.farmer.cms.core.node.PartNode; import com.xcong.farmer.cms.core.node.Template; +import lombok.extern.slf4j.Slf4j; import org.jsoup.nodes.Document; import java.io.File; @@ -14,12 +17,13 @@ * @author wzy * @date 2022-07-01 **/ -public class TemplateConfiguration extends Configuration{ +@Slf4j +public class TemplateConfiguration extends Configuration { private TemplateLoader templateLoader; - public TemplateConfiguration(String templatePath, String staticPath, String outputPath) { - super(templatePath, staticPath, outputPath); + public TemplateConfiguration(String templatePath, String staticPath, String outputPath, String baseUrl, String staticUrl) { + super(templatePath, staticPath, outputPath, baseUrl, staticUrl); } public void templateLoader(TemplateLoader templateLoader) { @@ -30,24 +34,38 @@ if (this.templateLoader == null) { throw new RuntimeException("TemplateLoader do not able to be null"); } + map.put("apiUrl", API_URL); - this.templateLoader.data(map); - Template template = template(templateName); - template.output(this.outputPath); + try { + String companyCode = (String) map.get("companyCode"); - // 判断是否有分页,有则执行。从第二页开始 - int i = 2; - while(Template.HAS_PAGING) { - map.put("page", i); + log.info("解析开始执行--#类型:{}#--#模板名称:{}#--#ID:{}#", map.get("templateType"), templateName, map.get("id")); this.templateLoader.data(map); - Template pageTemplate = template(templateName); - pageTemplate.output(this.outputPath); - i++; + Template template = template(FileUtils.path(templatePath, companyCode), templateName); + template.output(outputPath); + + // 判断是否有分页,有则执行。从第二页开始 + int i = 2; + while (Template.HAS_PAGING) { + map.put("page", i); + this.templateLoader.data(map); + Template pageTemplate = template(FileUtils.path(templatePath, companyCode), templateName); + pageTemplate.output(outputPath); + i++; + } + } catch (Exception e) { + log.error("页面编译异常", e); } } - public Template template(String templateName) { - return template(new File(path(this.templatePath) + templateName)); + public Template template(String templatePath, String templateName) { + File file = new File(path(templatePath) + templateName); + if (!file.exists()) { + log.info("模板文件不存在 : {}", templateName); + throw new GlobalException("模板文件不存在:" + templateName); + } + + return template(file); } public Template template(File file) { -- Gitblit v1.9.1