From 3dc1ca272294451ba48277e201a22d596d10e645 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 12 Jul 2022 16:23:35 +0800
Subject: [PATCH] fix

---
 src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java |  103 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 91 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java
index 475c74d..21dd11e 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java
@@ -1,15 +1,22 @@
 package com.xcong.farmer.cms.modules.core.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.xcong.farmer.cms.core.template.TemplateConfiguration;
 import com.xcong.farmer.cms.modules.core.service.ICmsCoreService;
+import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.validation.constraints.NotNull;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author wzy
@@ -22,38 +29,110 @@
     @Autowired
     private TemplateConfiguration cfg;
 
+    @Autowired
+    private WebSetMapper webSetMapper;
+
+
     @Override
-    public void articleProcess(Long id, String templateName, String templatePath) {
-        Map<String, Object> data = new HashMap<>();
-        data.put("id", id);
-        data.put("companyId", 23L);
+    public void articleProcess(Map<String, Object> data, String templateName, String templatePath) {
         data.put("templateType", "article");
         data.put("templatePath", templatePath);
-        data.put("templateName", id);
+        data.put("templateName", data.get("id"));
+        globalData(data);
         if (StrUtil.isEmpty(templateName)) {
-            templateName = "defualt.artile.html";
+            templateName = "defualt.article.html";
         }
-        cfg.process(data, templateName);
+
+        try {
+            cfg.process(data, templateName);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("发布文章出错", e);
+        }
     }
 
     @Override
-    public void columnProcess(Map<String, Object> data, String templateName, boolean article) {
-        data.put("companyId", 23L);
+    public void articlesProcess(Map<String, Object> data, List<Long> ids, String templateName, String templatePath) {
+        if (CollUtil.isEmpty(ids)) {
+            return;
+        }
+
+        for (Long id : ids) {
+            data.put("id", id);
+            articleProcess(data, templateName, templatePath);
+        }
+    }
+
+    @Override
+    public void columnsProcess(Map<String, Object> data, List<Long> ids, String templateName) {
+        if (CollUtil.isEmpty(ids)) {
+            return;
+        }
+
+        for (Long id : ids) {
+            data.put("id", id);
+            columnProcess(data, templateName);
+        }
+    }
+
+    @Override
+    public void columnProcess(Map<String, Object> data, String templateName) {
         data.put("templateType", "column");
         data.put("page", 1);
+        globalData(data);
         if (StrUtil.isEmpty(templateName)) {
             templateName = "defualt.list.html";
         }
-        cfg.process(data, templateName);
+
+        try {
+            cfg.process(data, templateName);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("发布栏目错误", e);
+        }
     }
 
     @Override
     public void indexProcess(@NotNull Map<String, Object> data, String templateName) {
+        data.put("templateType", "index");
+        globalData(data);
         if (StrUtil.isEmpty(templateName)) {
             templateName = "index.html";
         }
 
-        data.put("companyId", 23L);
-        cfg.process(data, templateName);
+        try {
+            cfg.process(data, templateName);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("发布首页错误", e);
+        }
+    }
+
+    @Override
+    public void process(Map<String, Object> data, String templateType, String templateName) {
+        data.put("templateType", templateType);
+        globalData(data);
+
+        if ("search".equals(templateType) && StrUtil.isBlank(templateName)) {
+            templateName = "search.html";
+        }
+
+        if ("message".equals(templateType) && StrUtil.isBlank(templateName)) {
+            templateName = "message.html";
+        }
+
+        try {
+            cfg.process(data, templateName);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("发布错误", e);
+        }
+    }
+
+    private void globalData(Map<String, Object> data) {
+        Long companyId = (Long) data.get("companyId");
+        Map<String, String> globalSetting = webSetMapper.selectSiteGlobalSetting(companyId);
+
+        data.putAll(globalSetting);
     }
 }

--
Gitblit v1.9.1