Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cms_sys
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
西魏
cms_sys
Commits
6b271adb
Commit
6b271adb
authored
Oct 30, 2020
by
sgjj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
恢复代码
parent
8f6ff12d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
206 additions
and
31 deletions
+206
-31
ContentBizImpl.java
src/main/java/net/mingsoft/cms/biz/impl/ContentBizImpl.java
+181
-6
WebConfig.java
src/main/java/net/mingsoft/config/WebConfig.java
+25
-25
No files found.
src/main/java/net/mingsoft/cms/biz/impl/ContentBizImpl.java
View file @
6b271adb
...
...
@@ -21,20 +21,36 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
package
net
.
mingsoft
.
cms
.
biz
.
impl
;
import
net.mingsoft.base.biz.impl.BaseBizImpl
;
import
net.mingsoft.base.dao.IBaseDao
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.io.FileUtil
;
import
net.mingsoft.base.constant.Const
;
import
net.mingsoft.basic.holder.DataHolder
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.
biz.IContentBiz
;
import
net.mingsoft.cms.
dao.IContentDao
;
import
net.mingsoft.cms.
dao.ICategoryDao
;
import
net.mingsoft.cms.
entity.CategoryEntity
;
import
net.mingsoft.cms.entity.ContentEntity
;
import
net.mingsoft.cms.util.CmsParserUtil
;
import
net.mingsoft.mdiy.bean.AttributeBean
;
import
net.mingsoft.mdiy.bean.PageBean
;
import
net.mingsoft.mdiy.entity.ModelEntity
;
import
net.mingsoft.mdiy.util.ParserUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
net.mingsoft.base.biz.impl.BaseBizImpl
;
import
net.mingsoft.base.dao.IBaseDao
;
import
java.util.List
;
import
java.util.Map
;
import
java.io.IOException
;
import
java.util.*
;
import
net.mingsoft.cms.biz.IContentBiz
;
import
net.mingsoft.cms.dao.IContentDao
;
/**
* 文章管理持久化层
...
...
@@ -45,9 +61,18 @@ import java.util.Map;
@Service
(
"cmscontentBizImpl"
)
public
class
ContentBizImpl
extends
BaseBizImpl
<
IContentDao
,
ContentEntity
>
implements
IContentBiz
{
/*
* log4j日志记录
*/
protected
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
@Autowired
private
IContentDao
contentDao
;
/**
* 栏目管理业务层
*/
@Autowired
private
ICategoryDao
categoryDao
;
@Override
...
...
@@ -58,6 +83,7 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> impl
@Override
public
List
<
CategoryBean
>
queryIdsByCategoryIdForParser
(
ContentBean
contentBean
)
{
contentBean
.
setAppId
(
BasicUtil
.
getAppId
());
return
this
.
contentDao
.
queryIdsByCategoryIdForParser
(
contentBean
);
}
...
...
@@ -68,4 +94,152 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> impl
}
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
;
AttributeBean
attributeBean
=
new
AttributeBean
();
ContentBean
contentBean
=
new
ContentBean
();
contentBean
.
setBeginTime
(
dateTime
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
ParserUtil
.
APP_ID
,
BasicUtil
.
getAppId
());
PageBean
page
=
new
PageBean
();
map
.
put
(
ParserUtil
.
HTML
,
ParserUtil
.
HTML
);
map
.
put
(
ParserUtil
.
URL
,
BasicUtil
.
getUrl
());
map
.
put
(
ParserUtil
.
PAGE
,
page
);
CategoryEntity
categoryEntity
=
new
CategoryEntity
();
categoryList
=
categoryDao
.
query
(
categoryEntity
);
for
(
CategoryEntity
category
:
categoryList
){
contentBean
.
setContentCategoryId
(
category
.
getId
());
// 分类是列表
if
(
category
.
getCategoryType
().
equals
(
"1"
)){
// 判断模板文件是否存在
if
(!
FileUtil
.
exist
(
ParserUtil
.
buildTempletPath
(
category
.
getCategoryListUrl
()))
||
StringUtils
.
isEmpty
(
category
.
getCategoryListUrl
()))
{
LOG
.
error
(
"模板不存在:{}"
,
category
.
getCategoryUrl
());
continue
;
}
// 获取文章列表表属性
ParserUtil
.
read
(
category
.
getCategoryListUrl
(),
map
,
page
,
attributeBean
);
contentBean
.
setFlag
(
attributeBean
.
getFlag
());
contentBean
.
setNoflag
(
attributeBean
.
getNoflag
());
contentBean
.
setOrder
(
attributeBean
.
getOrder
());
contentBean
.
setOrderBy
(
attributeBean
.
getOrderby
());
}
articleIdList
=
queryIdsByCategoryIdForParser
(
contentBean
);
// 有符合条件的就更新
if
(
articleIdList
.
size
()
>
0
)
{
CmsParserUtil
.
generateBasic
(
articleIdList
);
}
}
}
/*
* 生成栏目逻辑
*/
private
void
genernateColumn
()
throws
IOException
{
List
<
CategoryEntity
>
columns
=
new
ArrayList
<>();
// 获取所有的内容管理栏目
CategoryEntity
categoryEntity
=
new
CategoryEntity
();
categoryEntity
.
setAppId
(
BasicUtil
.
getAppId
());
columns
=
categoryDao
.
query
(
categoryEntity
);
List
<
CategoryBean
>
articleIdList
=
null
;
// 1、设置模板文件夹路径
// 获取栏目列表模版
for
(
CategoryEntity
column
:
columns
)
{
ContentBean
contentBean
=
new
ContentBean
();
contentBean
.
setContentCategoryId
(
column
.
getId
());
// 分类是列表
if
(
column
.
getCategoryType
().
equals
(
"1"
))
{
// 判断模板文件是否存在
if
(!
FileUtil
.
exist
(
ParserUtil
.
buildTempletPath
(
column
.
getCategoryListUrl
())))
{
LOG
.
error
(
"模板不存在:{}"
,
column
.
getCategoryUrl
());
continue
;
}
//获取模板中列表标签中的条件
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
ParserUtil
.
APP_ID
,
BasicUtil
.
getAppId
());
PageBean
page
=
new
PageBean
();
map
.
put
(
ParserUtil
.
HTML
,
ParserUtil
.
HTML
);
map
.
put
(
ParserUtil
.
URL
,
BasicUtil
.
getUrl
());
map
.
put
(
ParserUtil
.
PAGE
,
page
);
AttributeBean
attributeBean
=
new
AttributeBean
();
// 获取文章列表模板标签属性
ParserUtil
.
read
(
column
.
getCategoryListUrl
(),
map
,
page
,
attributeBean
);
contentBean
.
setFlag
(
attributeBean
.
getFlag
());
contentBean
.
setNoflag
(
attributeBean
.
getNoflag
());
contentBean
.
setOrder
(
attributeBean
.
getOrder
());
contentBean
.
setOrderBy
(
attributeBean
.
getOrderby
());
}
articleIdList
=
contentDao
.
queryIdsByCategoryIdForParser
(
contentBean
);
// 判断列表类型
switch
(
column
.
getCategoryType
())
{
//TODO 暂时先用字符串代替
case
"1"
:
// 列表
CmsParserUtil
.
generateList
(
column
,
articleIdList
.
size
());
break
;
case
"2"
:
// 单页
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
);
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
,
ParserUtil
.
HTML
);
//设置站点编号
map
.
put
(
ParserUtil
.
APP_ID
,
BasicUtil
.
getAppId
());
String
read
=
ParserUtil
.
read
(
templatePath
,
map
);
FileUtil
.
writeString
(
read
,
ParserUtil
.
buildHtmlPath
(
targetPath
),
Const
.
UTF8
);
}
}
\ No newline at end of file
src/main/java/net/mingsoft/config/WebConfig.java
View file @
6b271adb
package
net
.
mingsoft
.
config
;
import
java.io.File
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.concurrent.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor
;
import
com.baomidou.mybatisplus.extension.toolkit.JdbcUtils
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
net.mingsoft.basic.interceptor.ActionInterceptor
;
import
net.mingsoft.handler.AppHandler
;
import
net.mingsoft.interceptor.DMInnerInterceptor
;
import
net.mingsoft.interceptor.MysqlInnerInterceptor
;
import
org.springframework.aop.Advisor
;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
org.springframework.aop.support.DefaultPointcutAdvisor
;
import
org.springframework.aop.support.JdkRegexpMethodPointcut
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletListenerRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
...
...
@@ -27,23 +24,18 @@ import org.springframework.http.converter.HttpMessageConverter;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.context.request.RequestContextListener
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.PathMatchConfigurer
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.support.http.StatViewServlet
;
import
com.alibaba.druid.support.http.WebStatFilter
;
import
com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator
;
import
com.alibaba.druid.support.spring.stat.DruidStatInterceptor
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
net.mingsoft.basic.interceptor.ActionInterceptor
;
import
net.mingsoft.basic.util.BasicUtil
;
import
javax.sql.DataSource
;
import
java.io.File
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
@Configuration
public
class
WebConfig
implements
WebMvcConfigurer
{
...
...
@@ -65,11 +57,15 @@ public class WebConfig implements WebMvcConfigurer {
public
ActionInterceptor
actionInterceptor
()
{
return
new
ActionInterceptor
();
}
@Bean
public
AppHandler
appHandler
()
{
return
new
AppHandler
();
}
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
(
DataSource
dataSource
)
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
interceptor
.
addInnerInterceptor
(
new
TenantLineInnerInterceptor
(
appHandler
()));
try
{
//mysql 添加转换sql
DbType
dbType
=
JdbcUtils
.
getDbType
(
dataSource
.
getConnection
().
getMetaData
().
getURL
());
...
...
@@ -84,6 +80,10 @@ public class WebConfig implements WebMvcConfigurer {
return
interceptor
;
}
@Bean
public
ConfigurationCustomizer
configurationCustomizer
()
{
return
configuration
->
configuration
.
setUseDeprecatedExecutor
(
false
);
}
/**
* 增加对rest api鉴权的spring mvc拦截器
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment