From 5a74a045ea94e962ae28a5f97f5274f477d2a3cb Mon Sep 17 00:00:00 2001 From: guwd Date: Tue, 1 Dec 2020 16:05:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E7=AB=A0=E4=B8=8E?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E7=94=9F=E6=88=90=E6=97=B6=E5=80=99=EF=BC=8C?= =?UTF-8?q?=E5=B0=81=E9=9D=A2=E9=A1=B5=E9=9D=A2=E5=86=B2=E7=AA=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mingsoft/cms/action/GeneraterAction.java | 65 ++++++++----------- .../net/mingsoft/cms/util/CmsParserUtil.java | 4 +- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/mingsoft/cms/action/GeneraterAction.java b/src/main/java/net/mingsoft/cms/action/GeneraterAction.java index 20092886..54ff7bbf 100644 --- a/src/main/java/net/mingsoft/cms/action/GeneraterAction.java +++ b/src/main/java/net/mingsoft/cms/action/GeneraterAction.java @@ -24,6 +24,8 @@ package net.mingsoft.cms.action; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import net.mingsoft.base.entity.ResultData; import net.mingsoft.basic.annotation.LogAnn; import net.mingsoft.basic.biz.IModelBiz; @@ -61,12 +63,10 @@ import java.util.List; import java.util.Map; /** - * * @ClassName: GeneraterAction * @Description:TODO 生成器 * @author: 铭飞开发团队 * @date: 2018年1月31日 下午2:52:07 - * * @Copyright: 2018 www.mingsoft.net Inc. All rights reserved. */ @Controller("cmsGenerater") @@ -101,10 +101,7 @@ public class GeneraterAction extends BaseAction { private String managerPath; /** - - - - /** + * /** * 更新主页 * * @return @@ -182,11 +179,11 @@ public class GeneraterAction extends BaseAction { //TODO 暂时先用字符串代替 case "1": // 列表 - // 判断模板文件是否存在 - if (!FileUtil.exist(ParserUtil.buildTempletPath(column.getCategoryListUrl()))) { - LOG.error("模板不存在:{}", column.getCategoryUrl()); - continue; - } + // 判断模板文件是否存在 + if (!FileUtil.exist(ParserUtil.buildTempletPath(column.getCategoryListUrl()))) { + LOG.error("模板不存在:{}", column.getCategoryUrl()); + continue; + } CmsParserUtil.generateList(column, articleIdList.size()); break; @@ -221,7 +218,7 @@ public class GeneraterAction extends BaseAction { String dateTime = request.getParameter("dateTime"); // 网站风格物理路径 List articleIdList = null; - List categoryList = null; + List categoryList = new ArrayList(); ContentBean contentBean = new ContentBean(); contentBean.setBeginTime(dateTime); Map map = new HashMap<>(); @@ -234,44 +231,38 @@ public class GeneraterAction extends BaseAction { map.put(ParserUtil.PAGE, page); // 生成所有栏目的文章 if ("0".equals(columnId)) { - CategoryEntity categoryEntity = new CategoryEntity(); - categoryList = categoryBiz.query(categoryEntity); - for (CategoryEntity category : categoryList) { - contentBean.setCategoryId(category.getId()); - // 分类是列表 - if (category.getCategoryType().equals("1")) { - // 判断模板文件是否存在 - if (!FileUtil.exist(ParserUtil.buildTempletPath(category.getCategoryListUrl())) || StringUtils.isEmpty(category.getCategoryListUrl())) { - LOG.error("模板不存在:{}", category.getCategoryUrl()); - continue; - } - - } - //将文章列表标签中的中的参数 - articleIdList = contentBiz.queryIdsByCategoryIdForParser(contentBean); - // 有符合条件的就更新 - if (articleIdList.size() > 0) { - CmsParserUtil.generateBasic(articleIdList); - } - } + categoryList = categoryBiz.list(Wrappers.lambdaQuery() + .isNull(CategoryEntity::getCategoryParentId)); } else { CategoryEntity category = (CategoryEntity) categoryBiz.getById(columnId); - contentBean.setCategoryId(columnId); + categoryList.add(category); + } + + for (CategoryEntity category : categoryList) { + contentBean.setCategoryId(category.getId()); + //将文章列表标签中的中的参数 + articleIdList = contentBiz.queryIdsByCategoryIdForParser(contentBean); // 分类是列表 if (category.getCategoryType().equals("1")) { - // 获取文章列表表属性 // 判断模板文件是否存在 - if (!FileUtil.exist(ParserUtil.buildTempletPath(category.getCategoryUrl()))) { + if (!FileUtil.exist(ParserUtil.buildTempletPath(category.getCategoryListUrl())) || StringUtils.isEmpty(category.getCategoryListUrl())) { LOG.error("模板不存在:{}", category.getCategoryUrl()); - return ResultData.build().error(getResString("templet.file")); + continue; } + } else if (category.getCategoryType().equals("2")) { + CategoryBean columnArticleIdBean = new CategoryBean(); + CopyOptions copyOptions = CopyOptions.create(); + copyOptions.setIgnoreError(true); + BeanUtil.copyProperties(category, columnArticleIdBean, copyOptions); + articleIdList.add(columnArticleIdBean); } - articleIdList = contentBiz.queryIdsByCategoryIdForParser(contentBean); // 有符合条件的就更新 if (articleIdList.size() > 0) { CmsParserUtil.generateBasic(articleIdList); } } + + return ResultData.build().success(); } diff --git a/src/main/java/net/mingsoft/cms/util/CmsParserUtil.java b/src/main/java/net/mingsoft/cms/util/CmsParserUtil.java index 5b2b5b9c..1c04a700 100644 --- a/src/main/java/net/mingsoft/cms/util/CmsParserUtil.java +++ b/src/main/java/net/mingsoft/cms/util/CmsParserUtil.java @@ -192,6 +192,7 @@ public class CmsParserUtil extends ParserUtil { if(articleIdList.get(artId).getMdiyModelId() != null && articleIdList.get(artId).getMdiyModelId() > 0){ columnContentModelId = articleIdList.get(artId).getMdiyModelId(); } + // 文章是否已经生成了,生成了就跳过 if (generateIds.contains(articleId)) { artId++; @@ -208,10 +209,11 @@ public class CmsParserUtil extends ParserUtil { //如果是封面就生成index.html if(Integer.parseInt(articleIdList.get(artId).getCategoryType()) == COLUMN_TYPE_COVER) { writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX); - }else { + } else { // 组合文章路径如:html/站点id/栏目id/文章id.html writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId); } + Map parserParams = new HashMap(); parserParams.put(ParserUtil.COLUMN, articleIdList.get(artId)); // 判断当前栏目是否有自定义模型