From 876e250c27eeca4df0c13c3d222103afd9e06b7e Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 04 Aug 2022 16:07:04 +0800
Subject: [PATCH] fix

---
 src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java   |   22 +++
 src/main/java/com/xcong/farmer/cms/core/node/Template.java                             |   15 ---
 src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java      |   11 +
 src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java                             |    5 -
 src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java |  168 +++++++++++++++++++--------------
 src/main/java/com/xcong/farmer/cms/core/tag/model/Include.java                         |   22 ++--
 src/main/java/com/xcong/farmer/cms/core/node/PartNode.java                             |    1 
 7 files changed, 134 insertions(+), 110 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java b/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
index 436b082..8748eef 100644
--- a/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
+++ b/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
@@ -106,7 +106,6 @@
             i++;
 
             try {
-                Template.TAGS.add(tagsEnum.getName());
                 // {id=${col.id}, page=1, limit=5, field=art} ${col.id} 形式需先设置值
                 String tagValue = attributes.get(tagsEnum.getName());
                 tagValue = attrValueFormat(tagValue);
@@ -135,10 +134,6 @@
     public void runDataInject() {
         Attributes attributes = this.element.attributes();
         for (Attribute attribute : attributes) {
-            if (attribute.getKey().startsWith("\\$")) {
-                Template.TAGS.add(attribute.getKey());
-            }
-
             String key = attribute.getKey().replaceAll("\\$", "");
             String value = attribute.getValue();
 
diff --git a/src/main/java/com/xcong/farmer/cms/core/node/PartNode.java b/src/main/java/com/xcong/farmer/cms/core/node/PartNode.java
index 6006d2c..facbbf1 100644
--- a/src/main/java/com/xcong/farmer/cms/core/node/PartNode.java
+++ b/src/main/java/com/xcong/farmer/cms/core/node/PartNode.java
@@ -30,7 +30,6 @@
         AttrNode attrNode = new AttrNode(element, tagDataMap);
         attrNode.systemData(this.system);
         attrNode.parser();
-//        attrNode.runDataInject();
 
         StringBuilder result = new StringBuilder();
         if (CollUtil.isNotEmpty(element.children())) {
diff --git a/src/main/java/com/xcong/farmer/cms/core/node/Template.java b/src/main/java/com/xcong/farmer/cms/core/node/Template.java
index ab9b54e..50a66cc 100644
--- a/src/main/java/com/xcong/farmer/cms/core/node/Template.java
+++ b/src/main/java/com/xcong/farmer/cms/core/node/Template.java
@@ -24,22 +24,15 @@
     private String path = "";
 
     private Document document;
-    private Map<String, Map<String, Object>> params = new HashMap<>();
     private Map<String, Object> system;
     private List<PartNode> partNodes = new ArrayList<>();
 
-
-    // 页面中包含的标签
-    public static Set<String> TAGS;
     public volatile static boolean HAS_PAGING = false;
 
     public Template() {
-        TAGS = new HashSet<>();
     }
 
     public Template(File file, Map<String, Object> system) {
-        TAGS = new HashSet<>();
-
         Document document = null;
         try {
             document = Jsoup.parse(file, "utf-8");
@@ -156,14 +149,6 @@
 
     public List<PartNode> getPartNodes() {
         return partNodes;
-    }
-
-    public Map<String, Map<String, Object>> getParams() {
-        return params;
-    }
-
-    public void putParams(String key, Map<String, Object> value) {
-        this.params.put(key, value);
     }
 
     public void systemData(Map<String, Object> data) {
diff --git a/src/main/java/com/xcong/farmer/cms/core/tag/model/Include.java b/src/main/java/com/xcong/farmer/cms/core/tag/model/Include.java
index 4d5da63..0d05881 100644
--- a/src/main/java/com/xcong/farmer/cms/core/tag/model/Include.java
+++ b/src/main/java/com/xcong/farmer/cms/core/tag/model/Include.java
@@ -1,27 +1,29 @@
 package com.xcong.farmer.cms.core.tag.model;
 
 /**
+ * $("#head").load("com/head.html");
  * @author wzy
  * @date 2022-06-23
  **/
 public class Include {
-    private String field;
 
-    private String repeat = "1";
+    private String id;
 
-    public String getRepeat() {
-        return repeat;
+    private String name;
+
+    public String getId() {
+        return id;
     }
 
-    public void setRepeat(String repeat) {
-        this.repeat = repeat;
+    public void setId(String id) {
+        this.id = id;
     }
 
-    public String getField() {
-        return field;
+    public String getName() {
+        return name;
     }
 
-    public void setField(String field) {
-        this.field = field;
+    public void setName(String name) {
+        this.name = name;
     }
 }
diff --git a/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java b/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
index f65150f..7b46150 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
@@ -18,7 +18,7 @@
  **/
 @Slf4j
 @RestController
-@RequestMapping(value = "/api")
+@RequestMapping(value = "/cms")
 @Api(value = "CmsCoreController", tags = "CMS核心类")
 public class CmsCoreController {
 
@@ -28,7 +28,8 @@
     @ApiOperation(value = "发布文章", notes = "发布文章")
     @PostMapping(value = "releaseArticle/{id}")
     public Result releaseArticle(@PathVariable("id") Long id) {
-        Long companyId = LoginUserUtil.getCompanyId();
+//        Long companyId = LoginUserUtil.getCompanyId();
+        Long companyId = 24L;
         releaseService.releaseArticle(id, companyId);
         return Result.ok("success");
     }
@@ -36,7 +37,8 @@
     @ApiOperation(value = "发布栏目", notes = "发布栏目")
     @PostMapping(value = "releaseColumn/{type}/{id}")
     public Result releaseColumn(@PathVariable("id") Long id, @PathVariable("type") Integer type) {
-        Long companyId = LoginUserUtil.getCompanyId();
+//        Long companyId = LoginUserUtil.getCompanyId();
+        Long companyId = 24L;
         releaseService.releaseColumn(id, type, companyId);
         return Result.ok("success");
     }
@@ -44,7 +46,8 @@
     @ApiOperation(value = "发布首页", notes = "发布首页")
     @PostMapping(value = "/releaseIndex")
     public Result releaseIndex() {
-        Long companyId = LoginUserUtil.getCompanyId();
+//        Long companyId = LoginUserUtil.getCompanyId();
+        Long companyId = 24L;
         releaseService.releaseIndex(companyId, true);
         return Result.ok("success");
     }
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 21dd11e..366a9df 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
@@ -32,6 +32,8 @@
     @Autowired
     private WebSetMapper webSetMapper;
 
+    private final Executor executor = new ThreadPoolExecutor(10, 20, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+
 
     @Override
     public void articleProcess(Map<String, Object> data, String templateName, String templatePath) {
@@ -44,7 +46,10 @@
         }
 
         try {
-            cfg.process(data, templateName);
+            String finalTemplateName = templateName;
+            executor.execute(() -> {
+                cfg.process(data, finalTemplateName);
+            });
         } catch (Exception e) {
             e.printStackTrace();
             log.error("发布文章出错", e);
@@ -85,7 +90,10 @@
         }
 
         try {
-            cfg.process(data, templateName);
+            String finalTemplateName = templateName;
+            executor.execute(() -> {
+                cfg.process(data, finalTemplateName);
+            });
         } catch (Exception e) {
             e.printStackTrace();
             log.error("发布栏目错误", e);
@@ -101,7 +109,10 @@
         }
 
         try {
-            cfg.process(data, templateName);
+            String finalTemplateName = templateName;
+            executor.execute(() -> {
+                cfg.process(data, finalTemplateName);
+            });
         } catch (Exception e) {
             e.printStackTrace();
             log.error("发布首页错误", e);
@@ -122,7 +133,10 @@
         }
 
         try {
-            cfg.process(data, templateName);
+            String finalTemplateName = templateName;
+            executor.execute(() -> {
+                cfg.process(data, finalTemplateName);
+            });
         } catch (Exception e) {
             e.printStackTrace();
             log.error("发布错误", e);
diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java
index 63f984f..a4c021c 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java
@@ -57,6 +57,39 @@
 
     private final Executor executor = new ThreadPoolExecutor(5, 20, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
 
+//    @Override
+//    public void releaseArticle(Long id, Long companyId) {
+//        ArticleEntity article = articleMapper.selectById(id);
+//        ColumnEntity column = columnMapper.selectById(article.getColumnId());
+//
+//        Long beforeColumnId = article.getBeforeColumnId();
+//        article.setBeforeColumnId(-1L);
+//        articleMapper.updateById(article);
+//
+//        Map<String, Object> data = new Hashtable<>();
+//        data.put("id", article.getId());
+//        data.put("companyId", companyId);
+//
+//        executor.execute(() -> {
+//            log.info("执行文章发布");
+//            cmsCoreService.articleProcess(data, column.getArticleTemplate(), column.getPath());
+//            this.releaseColumn(column.getId(), 1, companyId);
+//            if (column.getParentId() != 0L) {
+//                releaseColumn(column.getParentId(), 1, companyId);
+//            }
+//
+//            if (beforeColumnId != null && !article.getColumnId().equals(beforeColumnId)) {
+//                ColumnEntity beforeColumn = columnMapper.selectById(beforeColumnId);
+//                this.releaseColumn(beforeColumnId, 1, companyId);
+//                if (beforeColumn.getParentId() != 0L) {
+//                    this.releaseColumn(beforeColumn.getParentId(), 1, companyId);
+//                }
+//            }
+//
+//            this.releaseIndex(companyId, false);
+//        });
+//    }
+
     @Override
     public void releaseArticle(Long id, Long companyId) {
         ArticleEntity article = articleMapper.selectById(id);
@@ -70,24 +103,23 @@
         data.put("id", article.getId());
         data.put("companyId", companyId);
 
-        executor.execute(() -> {
-            log.info("执行文章发布");
-            cmsCoreService.articleProcess(data, column.getArticleTemplate(), column.getPath());
-            this.releaseColumn(column.getId(), 1, companyId);
-            if (column.getParentId() != 0L) {
-                releaseColumn(column.getParentId(), 1, companyId);
-            }
+        log.info("执行文章发布");
+        cmsCoreService.articleProcess(data, column.getArticleTemplate(), column.getPath());
 
-            if (beforeColumnId != null && !article.getColumnId().equals(beforeColumnId)) {
-                ColumnEntity beforeColumn = columnMapper.selectById(beforeColumnId);
-                this.releaseColumn(beforeColumnId, 1, companyId);
-                if (beforeColumn.getParentId() != 0L) {
-                    this.releaseColumn(beforeColumn.getParentId(), 1, companyId);
-                }
-            }
+        this.releaseColumn(column.getId(), 1, companyId);
+        if (column.getParentId() != 0L) {
+            releaseColumn(column.getParentId(), 1, companyId);
+        }
 
-            this.releaseIndex(companyId, false);
-        });
+        if (beforeColumnId != null && !article.getColumnId().equals(beforeColumnId)) {
+            ColumnEntity beforeColumn = columnMapper.selectById(beforeColumnId);
+            this.releaseColumn(beforeColumnId, 1, companyId);
+            if (beforeColumn.getParentId() != 0L) {
+                this.releaseColumn(beforeColumn.getParentId(), 1, companyId);
+            }
+        }
+
+        this.releaseIndex(companyId, false);
     }
 
     @Override
@@ -95,6 +127,7 @@
         ColumnEntity columnEntity = columnMapper.selectById(id);
         Map<String, Object> map = buildColumnData(columnEntity);
 
+        // 判断栏目是否编辑了栏目编码或者修改了父级栏目
         if (columnEntity.getBeforeParentId() != -1 || !"-1".equals(columnEntity.getBeforeColumnCode())) {
             CompanyEntity company = companyMapper.selectById(companyId);
             if (!"-1".equals(columnEntity.getBeforeColumnCode())) {
@@ -117,65 +150,60 @@
             return;
         }
 
-        executor.execute(() -> {
-            List<ArticleEntity> articles = articleMapper.selectArticleByColumnId(columnEntity.getId(), companyId, type);
-            if (CollUtil.isNotEmpty(articles)) {
-                for (ArticleEntity article : articles) {
-                    if (article.getReleaseStatus() == 0) {
-                        article.setReleaseStatus(1);
-                        articleMapper.updateById(article);
-                    }
+        List<ArticleEntity> articles = articleMapper.selectArticleByColumnId(columnEntity.getId(), companyId, type);
+        if (CollUtil.isNotEmpty(articles)) {
+            for (ArticleEntity article : articles) {
+                if (article.getReleaseStatus() == 0) {
+                    article.setReleaseStatus(1);
+                    articleMapper.updateById(article);
+                }
 
-                    if (article.getType() == 1) {
-                        map.put("id", article.getId());
-                        cmsCoreService.articleProcess(map, columnEntity.getArticleTemplate(), columnEntity.getPath());
-                    }
+                if (article.getType() == 1) {
+                    map.put("id", article.getId());
+                    cmsCoreService.articleProcess(map, columnEntity.getArticleTemplate(), columnEntity.getPath());
                 }
             }
+        }
 
-            map.put("id", columnEntity.getId());
+        map.put("id", columnEntity.getId());
 
-            cmsCoreService.columnProcess(map, columnEntity.getListTemplate());
-            if (columnEntity.getParentId() != 0L) {
-                ColumnEntity parentColumn = columnMapper.selectById(columnEntity.getParentId());
-                Map<String, Object> parentMap = buildColumnData(parentColumn);
-                parentMap.put("id", parentColumn.getId());
-                cmsCoreService.columnProcess(parentMap, parentColumn.getListTemplate());
+        cmsCoreService.columnProcess(map, columnEntity.getListTemplate());
+        if (columnEntity.getParentId() != 0L) {
+            ColumnEntity parentColumn = columnMapper.selectById(columnEntity.getParentId());
+            Map<String, Object> parentMap = buildColumnData(parentColumn);
+            parentMap.put("id", parentColumn.getId());
+            cmsCoreService.columnProcess(parentMap, parentColumn.getListTemplate());
+        }
+
+        releaseIndex(companyId, false);
+
+        if (type != 1) {
+            if (columnEntity.getParentId() == 0L) {
+                List<ColumnEntity> columns = columnMapper.selectColumnByParentId(columnEntity.getId(), companyId, 2);
+                if (CollUtil.isNotEmpty(columns)) {
+                    for (ColumnEntity column : columns) {
+                        List<ArticleEntity> articleList = articleMapper.selectArticleByColumnId(column.getId(), companyId, type);
+                        if (CollUtil.isNotEmpty(articleList)) {
+                            for (ArticleEntity article : articleList) {
+                                if (article.getReleaseStatus() == 0) {
+                                    article.setReleaseStatus(1);
+                                    articleMapper.updateById(article);
+                                }
+
+                                if (article.getType() == 1) {
+                                    map.put("id", article.getId());
+                                    cmsCoreService.articleProcess(map, column.getArticleTemplate(), column.getPath());
+                                }
+                            }
+                        }
+
+                        Map<String, Object> data = buildColumnData(column);
+                        cmsCoreService.columnProcess(data, column.getListTemplate());
+                    }
+                }
             }
 
             releaseIndex(companyId, false);
-        });
-
-        if (type != 1) {
-            executor.execute(() -> {
-                if (columnEntity.getParentId() == 0L) {
-                    List<ColumnEntity> columns = columnMapper.selectColumnByParentId(columnEntity.getId(), companyId, 2);
-                    if (CollUtil.isNotEmpty(columns)) {
-                        for (ColumnEntity column : columns) {
-                            List<ArticleEntity> articles = articleMapper.selectArticleByColumnId(column.getId(), companyId, type);
-                            if (CollUtil.isNotEmpty(articles)) {
-                                for (ArticleEntity article : articles) {
-                                    if (article.getReleaseStatus() == 0) {
-                                        article.setReleaseStatus(1);
-                                        articleMapper.updateById(article);
-                                    }
-
-                                    if (article.getType() == 1) {
-                                        map.put("id", article.getId());
-                                        cmsCoreService.articleProcess(map, column.getArticleTemplate(), column.getPath());
-                                    }
-                                }
-                            }
-
-                            Map<String, Object> data = buildColumnData(column);
-                            cmsCoreService.columnProcess(data, column.getListTemplate());
-                        }
-                    }
-                }
-
-                releaseIndex(companyId, false);
-            });
-
         }
     }
 
@@ -217,10 +245,8 @@
 
         cmsCoreService.indexProcess(map, webSetting.getIndexTemplate());
         if (hasSearch) {
-            executor.execute(() -> {
-                cmsCoreService.process(map, "search", webSetting.getSearchTemplate());
-                cmsCoreService.process(map, "message", webSetting.getMsgTemplate());
-            });
+            cmsCoreService.process(map, "search", webSetting.getSearchTemplate());
+            cmsCoreService.process(map, "message", webSetting.getMsgTemplate());
         }
     }
 

--
Gitblit v1.9.1