Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
fa9cd60c2d
1194
doc/mcms-5.2.sql
1194
doc/mcms-5.2.sql
File diff suppressed because one or more lines are too long
|
@ -135,6 +135,7 @@ public class GeneraterAction extends BaseAction {
|
||||||
if (!FileUtil.exist(ParserUtil.buildTempletPath())) {
|
if (!FileUtil.exist(ParserUtil.buildTempletPath())) {
|
||||||
return ResultData.build().error(getResString("templet.file"));
|
return ResultData.build().error(getResString("templet.file"));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
CmsParserUtil.generate(tmpFileName, generateFileName,htmlDir);
|
CmsParserUtil.generate(tmpFileName, generateFileName,htmlDir);
|
||||||
return ResultData.build().success();
|
return ResultData.build().success();
|
||||||
}
|
}
|
||||||
|
@ -225,14 +226,7 @@ public class GeneraterAction extends BaseAction {
|
||||||
List<CategoryEntity> categoryList = new ArrayList<CategoryEntity>();
|
List<CategoryEntity> categoryList = new ArrayList<CategoryEntity>();
|
||||||
ContentBean contentBean = new ContentBean();
|
ContentBean contentBean = new ContentBean();
|
||||||
contentBean.setBeginTime(dateTime);
|
contentBean.setBeginTime(dateTime);
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
if (BasicUtil.getWebsiteApp() != null) {
|
|
||||||
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
|
||||||
}
|
|
||||||
PageBean page = new PageBean();
|
|
||||||
map.put(ParserUtil.HTML, htmlDir);
|
|
||||||
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
|
||||||
map.put(ParserUtil.PAGE, page);
|
|
||||||
// 生成所有栏目的文章
|
// 生成所有栏目的文章
|
||||||
if ("0".equals(columnId)) {
|
if ("0".equals(columnId)) {
|
||||||
categoryList = categoryBiz.list(Wrappers.<CategoryEntity>lambdaQuery()
|
categoryList = categoryBiz.list(Wrappers.<CategoryEntity>lambdaQuery()
|
||||||
|
|
|
@ -128,11 +128,12 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
map.put(ParserUtil.IS_DO, true);
|
map.put(ParserUtil.IS_DO, true);
|
||||||
//设置动态请求的模块路径
|
//设置动态请求的模块路径
|
||||||
map.put(ParserUtil.MODEL_NAME, "mcms");
|
map.put(ParserUtil.MODEL_NAME, "mcms");
|
||||||
|
map.put(ParserUtil.HTML,htmlDir);
|
||||||
//解析后的内容
|
//解析后的内容
|
||||||
String content = "";
|
String content = "";
|
||||||
try {
|
try {
|
||||||
//根据模板路径,参数生成
|
//根据模板路径,参数生成
|
||||||
content = CmsParserUtil.generate(ParserUtil.INDEX + ParserUtil.HTM_SUFFIX, map, htmlDir);
|
content = ParserUtil.rendering(ParserUtil.INDEX + ParserUtil.HTM_SUFFIX, map);
|
||||||
} catch (TemplateNotFoundException e) {
|
} catch (TemplateNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (MalformedTemplateNameException e) {
|
} catch (MalformedTemplateNameException e) {
|
||||||
|
@ -186,11 +187,12 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
map.put(ParserUtil.IS_DO, true);
|
map.put(ParserUtil.IS_DO, true);
|
||||||
//设置动态请求的模块路径
|
//设置动态请求的模块路径
|
||||||
map.put(ParserUtil.MODEL_NAME, "mcms");
|
map.put(ParserUtil.MODEL_NAME, "mcms");
|
||||||
|
map.put(ParserUtil.HTML, htmlDir);
|
||||||
//解析后的内容
|
//解析后的内容
|
||||||
String content = "";
|
String content = "";
|
||||||
try {
|
try {
|
||||||
//根据模板路径,参数生成
|
//根据模板路径,参数生成
|
||||||
content = CmsParserUtil.generate(columnArticles.get(0).getCategoryListUrl(), map, htmlDir);
|
content = ParserUtil.rendering(columnArticles.get(0).getCategoryListUrl(), map);
|
||||||
} catch (TemplateNotFoundException e) {
|
} catch (TemplateNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (MalformedTemplateNameException e) {
|
} catch (MalformedTemplateNameException e) {
|
||||||
|
@ -243,6 +245,8 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
||||||
map.put(ParserUtil.PAGE, page);
|
map.put(ParserUtil.PAGE, page);
|
||||||
map.put(ParserUtil.ID, article.getId());
|
map.put(ParserUtil.ID, article.getId());
|
||||||
|
map.put(ParserUtil.HTML,htmlDir);
|
||||||
|
|
||||||
ContentBean contentBean = new ContentBean();
|
ContentBean contentBean = new ContentBean();
|
||||||
contentBean.setCategoryId(String.valueOf(typeId));
|
contentBean.setCategoryId(String.valueOf(typeId));
|
||||||
contentBean.setOrderBy(orderby);
|
contentBean.setOrderBy(orderby);
|
||||||
|
@ -292,7 +296,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
//根据模板路径,参数生成
|
//根据模板路径,参数生成
|
||||||
content = CmsParserUtil.generate(column.getCategoryUrl(), map, htmlDir);
|
content = ParserUtil.rendering(column.getCategoryUrl(), map);
|
||||||
} catch (TemplateNotFoundException e) {
|
} catch (TemplateNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (MalformedTemplateNameException e) {
|
} catch (MalformedTemplateNameException e) {
|
||||||
|
@ -340,12 +344,12 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
|
|
||||||
|
|
||||||
//获取栏目信息
|
//获取栏目信息
|
||||||
int typeId = 0;
|
String typeId = null;
|
||||||
String categoryIds = BasicUtil.getString("categoryIds");
|
String categoryIds = BasicUtil.getString("categoryIds");
|
||||||
List categoryIdList = CollectionUtil.newArrayList();
|
List categoryIdList = CollectionUtil.newArrayList();
|
||||||
//当传递了栏目编号,但不是栏目集合
|
//当传递了栏目编号,但不是栏目集合
|
||||||
if (StringUtils.isNotBlank(categoryIds) && !categoryIds.contains(",")) {
|
if (StringUtils.isNotBlank(categoryIds) && !categoryIds.contains(",")) {
|
||||||
typeId = Integer.parseInt(categoryIds);
|
typeId = categoryIds;
|
||||||
} else {
|
} else {
|
||||||
//取出所有的子栏目
|
//取出所有的子栏目
|
||||||
String[] ids = categoryIds.split(",");
|
String[] ids = categoryIds.split(",");
|
||||||
|
@ -366,12 +370,11 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
|
|
||||||
//重新组织 ID
|
//重新组织 ID
|
||||||
categoryIds = StringUtils.join(categoryIdList, ",");
|
categoryIds = StringUtils.join(categoryIdList, ",");
|
||||||
//当前访问的项目地址
|
|
||||||
String url = BasicUtil.getUrl();
|
|
||||||
|
|
||||||
//根据栏目确定自定义模型
|
//根据栏目确定自定义模型
|
||||||
if (typeId > 0) {
|
if (typeId != null) {
|
||||||
column = (CategoryEntity) categoryBiz.getEntity(typeId);
|
column = (CategoryEntity) categoryBiz.getById(typeId);
|
||||||
// 获取表单类型的id
|
// 获取表单类型的id
|
||||||
if (column != null && ObjectUtil.isNotNull(column.getMdiyModelId())) {
|
if (column != null && ObjectUtil.isNotNull(column.getMdiyModelId())) {
|
||||||
contentModel = (ModelEntity) modelBiz.getEntity(column.getMdiyModelId());
|
contentModel = (ModelEntity) modelBiz.getEntity(column.getMdiyModelId());
|
||||||
|
@ -454,11 +457,18 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
//查询数量
|
//查询数量
|
||||||
int count = contentBiz.getSearchCount(contentModel, fieldValueList, searchMap, BasicUtil.getApp().getAppId(), categoryIds);
|
int count = contentBiz.getSearchCount(contentModel, fieldValueList, searchMap, BasicUtil.getApp().getAppId(), categoryIds);
|
||||||
page.setRcount(count);
|
page.setRcount(count);
|
||||||
params.put(ParserUtil.URL, url);
|
|
||||||
params.put(SEARCH, searchMap);
|
params.put(SEARCH, searchMap);
|
||||||
|
|
||||||
|
//站点编号
|
||||||
if (BasicUtil.getWebsiteApp() != null) {
|
if (BasicUtil.getWebsiteApp() != null) {
|
||||||
params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
||||||
|
params.put(ParserUtil.URL, BasicUtil.getWebsiteApp().getAppHostUrl());
|
||||||
|
params.put(ParserUtil.APP_ID, BasicUtil.getWebsiteApp().getAppId());
|
||||||
|
} else {
|
||||||
|
params.put(ParserUtil.URL, BasicUtil.getUrl());
|
||||||
|
params.put(ParserUtil.APP_DIR, BasicUtil.getApp().getAppDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
params.put(ParserUtil.PAGE, page);
|
params.put(ParserUtil.PAGE, page);
|
||||||
params.put(ParserUtil.HTML, htmlDir);
|
params.put(ParserUtil.HTML, htmlDir);
|
||||||
//动态解析
|
//动态解析
|
||||||
|
@ -481,6 +491,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
page.setPageNo(pageNo);
|
page.setPageNo(pageNo);
|
||||||
|
|
||||||
//设置分页的统一链接
|
//设置分页的统一链接
|
||||||
|
String url = params.get(ParserUtil.URL).toString();
|
||||||
url = url + request.getServletPath() + "?" + urlParams;
|
url = url + request.getServletPath() + "?" + urlParams;
|
||||||
String pageNoStr = "size=" + page.getSize() + "&pageNo=";
|
String pageNoStr = "size=" + page.getSize() + "&pageNo=";
|
||||||
//下一页
|
//下一页
|
||||||
|
@ -497,7 +508,6 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
page.setPreUrl(preUrl);
|
page.setPreUrl(preUrl);
|
||||||
page.setLastUrl(lastUrl);
|
page.setLastUrl(lastUrl);
|
||||||
|
|
||||||
params.put(ParserUtil.URL, url);
|
|
||||||
params.put(SEARCH, searchMap);
|
params.put(SEARCH, searchMap);
|
||||||
if (BasicUtil.getWebsiteApp() != null) {
|
if (BasicUtil.getWebsiteApp() != null) {
|
||||||
params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
||||||
|
@ -513,7 +523,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
|
||||||
String content = "";
|
String content = "";
|
||||||
try {
|
try {
|
||||||
//根据模板路径,参数生成
|
//根据模板路径,参数生成
|
||||||
content = CmsParserUtil.generate(SEARCH + ParserUtil.HTM_SUFFIX, params, htmlDir);
|
content = ParserUtil.rendering(SEARCH + ParserUtil.HTM_SUFFIX, params);
|
||||||
} catch (TemplateNotFoundException e) {
|
} catch (TemplateNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (MalformedTemplateNameException e) {
|
} catch (MalformedTemplateNameException e) {
|
||||||
|
|
|
@ -98,144 +98,5 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
|
||||||
return contentDao.getSearchCount(null,null,whereMap, appId,categoryIds);
|
return contentDao.getSearchCount(null,null,whereMap, appId,categoryIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* 任务调度静态化任务
|
|
||||||
*/
|
|
||||||
public void staticizeTask(Integer appId, String tmpFileName, String generateFileName) {
|
|
||||||
LOG.info("定时静态化任务", new Date());
|
|
||||||
try {
|
|
||||||
//将任务采集传过来的appId导入到线程变量中
|
|
||||||
//当前线程使用appId时优先使用此数据
|
|
||||||
DataHolder.set(ParserUtil.APP_ID, appId);
|
|
||||||
//调用三种静态化
|
|
||||||
genernateColumn();
|
|
||||||
generaterIndex(tmpFileName, generateFileName);
|
|
||||||
//生成文章日期默认为执行日期的上一天
|
|
||||||
generateArticle(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"));
|
|
||||||
LOG.info("静态化完成", new Date());
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.info("静态化失败", new Date());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 生成文章逻辑
|
|
||||||
*/
|
|
||||||
private void generateArticle(String dateTime) throws IOException {
|
|
||||||
// 网站风格物理路径
|
|
||||||
List<CategoryBean> articleIdList = null;
|
|
||||||
List<CategoryEntity> categoryList = null;
|
|
||||||
ContentBean contentBean = new ContentBean();
|
|
||||||
contentBean.setBeginTime(dateTime);
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
if(BasicUtil.getWebsiteApp() != null){
|
|
||||||
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
|
||||||
}
|
|
||||||
PageBean page = new PageBean();
|
|
||||||
map.put(ParserUtil.HTML, htmlDir);
|
|
||||||
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
|
||||||
map.put(ParserUtil.PAGE, page);
|
|
||||||
|
|
||||||
CategoryEntity categoryEntity = new CategoryEntity();
|
|
||||||
categoryList = categoryDao.query(categoryEntity);
|
|
||||||
for(CategoryEntity category : categoryList){
|
|
||||||
contentBean.setCategoryId(category.getId());
|
|
||||||
// 分类是列表
|
|
||||||
if(category.getCategoryType().equals(CategoryTypeEnum.LIST.toString())){
|
|
||||||
// 判断模板文件是否存在
|
|
||||||
if (!FileUtil.exist(ParserUtil.buildTempletPath(category.getCategoryListUrl())) || StringUtils.isEmpty(category.getCategoryListUrl())) {
|
|
||||||
LOG.error("模板不存在:{}",category.getCategoryUrl());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
articleIdList = queryIdsByCategoryIdForParser(contentBean);
|
|
||||||
// 有符合条件的就更新
|
|
||||||
if (articleIdList.size() > 0) {
|
|
||||||
CmsParserUtil.generateBasic(articleIdList,htmlDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 生成栏目逻辑
|
|
||||||
*/
|
|
||||||
private void genernateColumn() throws IOException {
|
|
||||||
List<CategoryEntity> columns = new ArrayList<>();
|
|
||||||
// 获取所有的内容管理栏目
|
|
||||||
CategoryEntity categoryEntity=new CategoryEntity();
|
|
||||||
columns = categoryDao.query(categoryEntity);
|
|
||||||
List<CategoryBean> articleIdList = null;
|
|
||||||
// 1、设置模板文件夹路径
|
|
||||||
// 获取栏目列表模版
|
|
||||||
for (CategoryEntity column : columns) {
|
|
||||||
ContentBean contentBean = new ContentBean();
|
|
||||||
contentBean.setCategoryId(column.getId());
|
|
||||||
// 分类是列表
|
|
||||||
if(column.getCategoryType().equals(CategoryTypeEnum.LIST.toString())) {
|
|
||||||
// 判断模板文件是否存在
|
|
||||||
if (!FileUtil.exist(ParserUtil.buildTempletPath(column.getCategoryListUrl()))) {
|
|
||||||
LOG.error("模板不存在:{}", column.getCategoryUrl());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//获取模板中列表标签中的条件
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
if(BasicUtil.getWebsiteApp() != null){
|
|
||||||
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
|
||||||
}
|
|
||||||
PageBean page = new PageBean();
|
|
||||||
map.put(ParserUtil.HTML, htmlDir);
|
|
||||||
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
|
||||||
map.put(ParserUtil.PAGE, page);
|
|
||||||
|
|
||||||
}
|
|
||||||
articleIdList = contentDao.queryIdsByCategoryIdForParser(contentBean);
|
|
||||||
// 判断列表类型
|
|
||||||
switch (CategoryTypeEnum.get(column.getCategoryType())) {
|
|
||||||
//TODO 暂时先用字符串代替
|
|
||||||
case LIST: // 列表
|
|
||||||
CmsParserUtil.generateList(column, articleIdList.size(),htmlDir);
|
|
||||||
break;
|
|
||||||
case COVER:// 单页
|
|
||||||
if(articleIdList.size()==0){
|
|
||||||
CategoryBean columnArticleIdBean=new CategoryBean();
|
|
||||||
CopyOptions copyOptions=CopyOptions.create();
|
|
||||||
copyOptions.setIgnoreError(true);
|
|
||||||
BeanUtil.copyProperties(column,columnArticleIdBean,copyOptions);
|
|
||||||
articleIdList.add(columnArticleIdBean);
|
|
||||||
}
|
|
||||||
CmsParserUtil.generateBasic(articleIdList,htmlDir);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 生成主页逻辑
|
|
||||||
*/
|
|
||||||
private void generaterIndex(String templatePath, String targetPath) throws IOException {
|
|
||||||
if (!FileUtil.exist(ParserUtil.buildTempletPath())) {
|
|
||||||
LOG.info("模板文件不存在");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
map.put(ParserUtil.IS_DO, false);
|
|
||||||
CategoryEntity column = new CategoryEntity();
|
|
||||||
//内容管理栏目编码
|
|
||||||
map.put(ParserUtil.COLUMN, column);
|
|
||||||
//如果单站点,就废弃站点地址
|
|
||||||
if (ParserUtil.IS_SINGLE) {
|
|
||||||
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
|
||||||
}
|
|
||||||
//设置生成的路径
|
|
||||||
map.put(ParserUtil.HTML, htmlDir);
|
|
||||||
//设置站点编号
|
|
||||||
if(BasicUtil.getWebsiteApp() !=null){
|
|
||||||
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
|
||||||
}
|
|
||||||
String read = ParserUtil.rendering(templatePath, map);
|
|
||||||
FileUtil.writeString(read, ParserUtil.buildHtmlPath(targetPath,htmlDir), net.mingsoft.base.constant.Const.UTF8);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import freemarker.core.ParseException;
|
||||||
import freemarker.template.MalformedTemplateNameException;
|
import freemarker.template.MalformedTemplateNameException;
|
||||||
import freemarker.template.TemplateNotFoundException;
|
import freemarker.template.TemplateNotFoundException;
|
||||||
import net.mingsoft.base.constant.Const;
|
import net.mingsoft.base.constant.Const;
|
||||||
|
import net.mingsoft.basic.holder.DataHolder;
|
||||||
import net.mingsoft.basic.util.BasicUtil;
|
import net.mingsoft.basic.util.BasicUtil;
|
||||||
import net.mingsoft.basic.util.SpringUtil;
|
import net.mingsoft.basic.util.SpringUtil;
|
||||||
import net.mingsoft.cms.bean.CategoryBean;
|
import net.mingsoft.cms.bean.CategoryBean;
|
||||||
|
@ -31,7 +32,7 @@ import java.util.concurrent.ExecutorService;
|
||||||
/**
|
/**
|
||||||
* 文章解析工具类
|
* 文章解析工具类
|
||||||
*/
|
*/
|
||||||
public class CmsParserUtil extends ParserUtil {
|
public class CmsParserUtil {
|
||||||
|
|
||||||
|
|
||||||
private final static String FIELD = "field";
|
private final static String FIELD = "field";
|
||||||
|
@ -45,12 +46,24 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
*/
|
*/
|
||||||
public static void generate(String templatePath, String targetPath, String htmlDir) throws IOException {
|
public static void generate(String templatePath, String targetPath, String htmlDir) throws IOException {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put(IS_DO, false);
|
map.put(ParserUtil.IS_DO, false);
|
||||||
CategoryEntity column = new CategoryEntity();
|
CategoryEntity column = new CategoryEntity();
|
||||||
//内容管理栏目编码
|
//内容管理栏目编码
|
||||||
map.put(COLUMN, column);
|
map.put(ParserUtil.COLUMN, column);
|
||||||
String content = CmsParserUtil.generate(templatePath, map, htmlDir);
|
map.put(ParserUtil.HTML, htmlDir);
|
||||||
FileUtil.writeString(content, ParserUtil.buildHtmlPath(targetPath, htmlDir), Const.UTF8);
|
|
||||||
|
//站点编号
|
||||||
|
if (BasicUtil.getWebsiteApp() != null) {
|
||||||
|
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
||||||
|
map.put(ParserUtil.URL, BasicUtil.getWebsiteApp().getAppHostUrl());
|
||||||
|
map.put(ParserUtil.APP_ID, BasicUtil.getWebsiteApp().getAppId());
|
||||||
|
} else {
|
||||||
|
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
||||||
|
map.put(ParserUtil.APP_DIR, BasicUtil.getApp().getAppDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
String content = ParserUtil.rendering(templatePath, map);
|
||||||
|
FileUtil.writeString(content, ParserUtil.buildHtmlPath(targetPath, htmlDir, map.get(ParserUtil.APP_DIR).toString()), Const.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,15 +89,26 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
int totalPageSize = PageUtil.totalPage(articleIdTotal, page.getSize());
|
int totalPageSize = PageUtil.totalPage(articleIdTotal, page.getSize());
|
||||||
page.setTotal(totalPageSize);
|
page.setTotal(totalPageSize);
|
||||||
|
|
||||||
//获取模板中列表标签中的条件
|
//全局参数设置
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> parserParams = new HashMap<String, Object>();
|
||||||
|
parserParams.put(ParserUtil.IS_DO, false);
|
||||||
|
parserParams.put(ParserUtil.HTML, htmlDir);
|
||||||
|
parserParams.put(ParserUtil.PAGE, page);
|
||||||
|
|
||||||
|
//站点编号
|
||||||
if (BasicUtil.getWebsiteApp() != null) {
|
if (BasicUtil.getWebsiteApp() != null) {
|
||||||
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
parserParams.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
||||||
|
parserParams.put(ParserUtil.URL, BasicUtil.getWebsiteApp().getAppHostUrl());
|
||||||
|
parserParams.put(ParserUtil.APP_ID, BasicUtil.getWebsiteApp().getAppId());
|
||||||
|
} else {
|
||||||
|
parserParams.put(ParserUtil.URL, BasicUtil.getUrl());
|
||||||
|
parserParams.put(ParserUtil.APP_DIR, BasicUtil.getApp().getAppDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
map.put(ParserUtil.HTML, htmlDir);
|
parserParams.put(ParserUtil.COLUMN, column);
|
||||||
map.put(ParserUtil.URL, BasicUtil.getUrl());
|
//标签中使用field获取当前栏目
|
||||||
map.put(ParserUtil.PAGE, page);
|
parserParams.put(ParserUtil.FIELD, column);
|
||||||
|
|
||||||
|
|
||||||
String columnListPath;
|
String columnListPath;
|
||||||
ModelEntity contentModel = null;
|
ModelEntity contentModel = null;
|
||||||
|
@ -94,31 +118,16 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
contentModel = (ModelEntity) SpringUtil.getBean(ModelBizImpl.class).getEntity(column.getMdiyModelId());
|
contentModel = (ModelEntity) SpringUtil.getBean(ModelBizImpl.class).getEntity(column.getMdiyModelId());
|
||||||
}
|
}
|
||||||
|
|
||||||
//全局参数设置
|
|
||||||
Map<String, Object> parserParams = new HashMap<String, Object>();
|
|
||||||
parserParams.put(ParserUtil.PAGE, page);
|
|
||||||
parserParams.put(COLUMN, column);
|
|
||||||
//标签中使用field获取当前栏目
|
|
||||||
parserParams.put(FIELD, column);
|
|
||||||
parserParams.put(IS_DO, false);
|
|
||||||
parserParams.put(HTML, htmlDir);
|
|
||||||
if (BasicUtil.getWebsiteApp() != null) {
|
|
||||||
parserParams.put(APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
|
||||||
}
|
|
||||||
if (contentModel != null) {
|
if (contentModel != null) {
|
||||||
// 将自定义模型编号设置为key值
|
// 将自定义模型编号设置为key值
|
||||||
parserParams.put(TABLE_NAME, contentModel.getModelTableName());
|
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
|
||||||
}
|
|
||||||
//如果单站点,就废弃站点地址
|
|
||||||
if (ParserUtil.IS_SINGLE) {
|
|
||||||
parserParams.put(ParserUtil.URL, BasicUtil.getUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pageNo = 1;
|
int pageNo = 1;
|
||||||
//文章列表页没有写文章列表标签,总数为0
|
//文章列表页没有写文章列表标签,总数为0
|
||||||
if (totalPageSize <= 0) {
|
if (totalPageSize <= 0) {
|
||||||
// 数据库中第一页是从开始0*size
|
// 数据库中第一页是从开始0*size
|
||||||
columnListPath = ParserUtil.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX, htmlDir);
|
columnListPath = ParserUtil.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX, htmlDir, parserParams.get(ParserUtil.APP_DIR).toString());
|
||||||
// 设置分页的起始位置
|
// 设置分页的起始位置
|
||||||
page.setPageNo(pageNo);
|
page.setPageNo(pageNo);
|
||||||
String read = ParserUtil.rendering(File.separator + column.getCategoryListUrl(), parserParams);
|
String read = ParserUtil.rendering(File.separator + column.getCategoryListUrl(), parserParams);
|
||||||
|
@ -131,11 +140,11 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
// 数据库中第一页是从开始0*size
|
// 数据库中第一页是从开始0*size
|
||||||
// 首页路径index.html
|
// 首页路径index.html
|
||||||
columnListPath = ParserUtil
|
columnListPath = ParserUtil
|
||||||
.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX, htmlDir);
|
.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX, htmlDir, parserParams.get(ParserUtil.APP_DIR).toString());
|
||||||
} else {
|
} else {
|
||||||
// 其他路径list-2.html
|
// 其他路径list-2.html
|
||||||
columnListPath = ParserUtil
|
columnListPath = ParserUtil
|
||||||
.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.PAGE_LIST + pageNo, htmlDir);
|
.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.PAGE_LIST + pageNo, htmlDir, parserParams.get(ParserUtil.APP_DIR).toString());
|
||||||
}
|
}
|
||||||
// 设置分页的起始位置
|
// 设置分页的起始位置
|
||||||
page.setPageNo(pageNo);
|
page.setPageNo(pageNo);
|
||||||
|
@ -161,11 +170,24 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
*/
|
*/
|
||||||
public static void generateBasic(List<CategoryBean> articleIdList, String htmlDir) {
|
public static void generateBasic(List<CategoryBean> articleIdList, String htmlDir) {
|
||||||
|
|
||||||
|
Map<String, Object> parserParams = new HashMap<String, Object>();
|
||||||
|
parserParams.put(ParserUtil.IS_DO, false);
|
||||||
|
if (BasicUtil.getWebsiteApp() != null) {
|
||||||
|
parserParams.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
|
||||||
|
parserParams.put(ParserUtil.URL, BasicUtil.getWebsiteApp().getAppHostUrl());
|
||||||
|
parserParams.put(ParserUtil.APP_ID, BasicUtil.getWebsiteApp().getAppId());
|
||||||
|
} else {
|
||||||
|
parserParams.put(ParserUtil.URL, BasicUtil.getUrl());
|
||||||
|
parserParams.put(ParserUtil.APP_DIR, BasicUtil.getApp().getAppDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
parserParams.put(ParserUtil.HTML, htmlDir);
|
||||||
|
|
||||||
|
|
||||||
Map<Object, Object> contentModelMap = new HashMap<Object, Object>();
|
Map<Object, Object> contentModelMap = new HashMap<Object, Object>();
|
||||||
ModelEntity contentModel = null;
|
ModelEntity contentModel = null;
|
||||||
// 记录已经生成了文章编号
|
// 记录已经生成了文章编号
|
||||||
List<String> generateIds = new ArrayList<>();
|
List<String> generateIds = new ArrayList<>();
|
||||||
ExecutorService pool = SpringUtil.getBean(ExecutorService.class);
|
|
||||||
// 生成文章
|
// 生成文章
|
||||||
for (int artId = 0; artId < articleIdList.size(); ) {
|
for (int artId = 0; artId < articleIdList.size(); ) {
|
||||||
|
|
||||||
|
@ -206,30 +228,32 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
generateIds.add(articleId);
|
generateIds.add(articleId);
|
||||||
//如果是封面就生成index.html
|
//如果是封面就生成index.html
|
||||||
if (categoryBean.getCategoryType().equals(CategoryTypeEnum.COVER.toString())) {
|
if (categoryBean.getCategoryType().equals(CategoryTypeEnum.COVER.toString())) {
|
||||||
writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX, htmlDir);
|
writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX, htmlDir, parserParams.get(ParserUtil.APP_DIR).toString());
|
||||||
} else {
|
} else {
|
||||||
// 组合文章路径如:html/站点id/栏目id/文章id.html
|
// 组合文章路径如:html/站点id/栏目id/文章id.html
|
||||||
writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId, htmlDir);
|
writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId, htmlDir, parserParams.get(ParserUtil.APP_DIR).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> parserParams = new HashMap<String, Object>();
|
|
||||||
parserParams.put(ParserUtil.COLUMN, categoryBean);
|
parserParams.put(ParserUtil.COLUMN, categoryBean);
|
||||||
|
|
||||||
|
|
||||||
// 判断当前栏目是否有自定义模型
|
// 判断当前栏目是否有自定义模型
|
||||||
if (columnContentModelId != null) {
|
if (columnContentModelId != null) {
|
||||||
// 通过当前栏目的模型编号获取,自定义模型表名
|
// 通过当前栏目的模型编号获取,自定义模型表名
|
||||||
if (contentModelMap.containsKey(columnContentModelId)) {
|
if (contentModelMap.containsKey(columnContentModelId)) {
|
||||||
parserParams.put(TABLE_NAME, contentModel.getModelTableName());
|
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
|
||||||
} else {
|
} else {
|
||||||
// 通过栏目模型编号获取自定义模型实体
|
// 通过栏目模型编号获取自定义模型实体
|
||||||
contentModel = (ModelEntity) SpringUtil.getBean(IModelBiz.class)
|
contentModel = (ModelEntity) SpringUtil.getBean(IModelBiz.class)
|
||||||
.getEntity(columnContentModelId);
|
.getEntity(columnContentModelId);
|
||||||
// 将自定义模型编号设置为key值
|
// 将自定义模型编号设置为key值
|
||||||
contentModelMap.put(columnContentModelId, contentModel.getModelTableName());
|
contentModelMap.put(columnContentModelId, contentModel.getModelTableName());
|
||||||
parserParams.put(TABLE_NAME, contentModel.getModelTableName());
|
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parserParams.put(ID, articleId);
|
parserParams.put(ParserUtil.ID, articleId);
|
||||||
// 第一篇文章没有上一篇
|
// 第一篇文章没有上一篇
|
||||||
if (artId > 0) {
|
if (artId > 0) {
|
||||||
CategoryBean preCaBean = articleIdList.get(artId - 1);
|
CategoryBean preCaBean = articleIdList.get(artId - 1);
|
||||||
|
@ -247,22 +271,19 @@ public class CmsParserUtil extends ParserUtil {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
parserParams.put(IS_DO, false);
|
|
||||||
parserParams.put(ParserUtil.PAGE, page);
|
parserParams.put(ParserUtil.PAGE, page);
|
||||||
String finalWritePath = writePath;
|
String finalWritePath = writePath;
|
||||||
HashMap<Object, Object> cloneMap = CollUtil.newHashMap();
|
HashMap<Object, Object> cloneMap = CollUtil.newHashMap();
|
||||||
cloneMap.putAll(parserParams);
|
cloneMap.putAll(parserParams);
|
||||||
HttpServletRequest request = SpringUtil.getRequest();
|
HttpServletRequest request = SpringUtil.getRequest();
|
||||||
pool.execute(() -> {
|
|
||||||
String content = null;
|
String content = null;
|
||||||
try {
|
try {
|
||||||
SpringUtil.setRequest(request);
|
content = ParserUtil.rendering(columnUrl, cloneMap);
|
||||||
content = CmsParserUtil.generate(columnUrl, cloneMap, htmlDir);
|
|
||||||
FileUtil.writeString(content, finalWritePath, Const.UTF8);
|
FileUtil.writeString(content, finalWritePath, Const.UTF8);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
artId++;
|
artId++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue