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
d28c2497
Commit
d28c2497
authored
Jun 19, 2020
by
shanggjj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化文章生成
parent
d48752bd
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
135 additions
and
27 deletions
+135
-27
pom.xml
pom.xml
+20
-8
GeneraterAction.java
src/main/java/net/mingsoft/cms/action/GeneraterAction.java
+0
-5
ICategoryBiz.java
src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java
+8
-0
CategoryBizImpl.java
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java
+5
-0
Upgrade.java
src/main/java/net/mingsoft/cms/upgrade/Upgrade.java
+47
-0
CmsParserUtil.java
src/main/java/net/mingsoft/cms/util/CmsParserUtil.java
+43
-12
WebConfig.java
src/main/java/net/mingsoft/config/WebConfig.java
+11
-1
application-dev.yml
src/main/resources/application-dev.yml
+1
-1
No files found.
pom.xml
View file @
d28c2497
...
...
@@ -2,6 +2,11 @@
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-pom
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-mcms
</artifactId>
...
...
@@ -70,9 +75,17 @@
<dependency>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-mpeople
</artifactId>
<version>
1.0.22
</version>
</dependency>
<dependency>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-basic
</artifactId>
<version>
1.0.27-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-upgrader
</artifactId>
<version>
1.0.17
</version>
</dependency>
</dependencies>
...
...
@@ -158,11 +171,7 @@
<encoding>
${project.build.sourceEncoding}
</encoding>
<showDeprecation>
true
</showDeprecation>
<showWarnings>
true
</showWarnings>
<compilerArguments>
<verbose
/>
<bootclasspath>
${java.home}/lib/rt.jar:${java.home}/lib/jce.jar
</bootclasspath>
</compilerArguments>
<compilerArgument>
-Xlint:unchecked
</compilerArgument>
</configuration>
<dependencies>
<dependency>
...
...
@@ -173,7 +182,10 @@
</dependencies>
</plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
...
...
src/main/java/net/mingsoft/cms/action/GeneraterAction.java
View file @
d28c2497
...
...
@@ -205,7 +205,6 @@ public class GeneraterAction extends BaseAction {
String
dateTime
=
request
.
getParameter
(
"dateTime"
);
// 网站风格物理路径
List
<
ContentBean
>
articleIdList
=
null
;
try
{
// 查出所有文章(根据选择栏目)包括子栏目
articleIdList
=
contentBiz
.
queryIdsByCategoryIdForParser
(
columnId
,
dateTime
,
null
);
// 有符合条件的新闻就更新
...
...
@@ -213,10 +212,6 @@ public class GeneraterAction extends BaseAction {
CmsParserUtil
.
generateBasic
(
articleIdList
);
}
this
.
outJson
(
response
,
true
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
this
.
outJson
(
response
,
false
);
}
}
...
...
src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java
View file @
d28c2497
...
...
@@ -23,7 +23,15 @@ public interface ICategoryBiz extends IBaseBiz {
void
saveEntity
(
CategoryEntity
entity
);
/**更新父级及子集
* @param entity
*/
void
updateEntity
(
CategoryEntity
entity
);
/**只更新自身
* @param entity
*/
void
update
(
CategoryEntity
entity
);
void
delete
(
int
categoryId
);
}
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java
View file @
d28c2497
...
...
@@ -138,6 +138,11 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
setChildParentId
(
entity
);
}
@Override
public
void
update
(
CategoryEntity
entity
)
{
super
.
updateEntity
(
entity
);
}
@Override
public
void
delete
(
int
categoryId
)
{
// TODO Auto-generated method stub
...
...
src/main/java/net/mingsoft/cms/upgrade/Upgrade.java
0 → 100644
View file @
d28c2497
package
net
.
mingsoft
.
cms
.
upgrade
;
import
cn.hutool.core.util.StrUtil
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.SpringUtil
;
import
net.mingsoft.cms.biz.ICategoryBiz
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.cms.util.PinYinUtil
;
import
java.util.List
;
/**
* @author by 铭飞开源团队
* @Description TODO
* @date 2020/6/19 15:58
*/
public
class
Upgrade
{
/**
* 菜单拼音升级
*/
public
void
upgrade
(){
ICategoryBiz
categoryBiz
=
SpringUtil
.
getBean
(
ICategoryBiz
.
class
);
List
<
CategoryEntity
>
list
=
categoryBiz
.
queryAll
();
//先更新所有栏目的拼音
list
.
forEach
(
x
->{
String
pingYin
=
PinYinUtil
.
getPingYin
(
x
.
getCategoryTitle
());
CategoryEntity
category
=
new
CategoryEntity
();
category
.
setCategoryPinyin
(
pingYin
);
category
.
setAppId
(
BasicUtil
.
getAppId
());
CategoryEntity
categoryBizEntity
=
(
CategoryEntity
)
categoryBiz
.
getEntity
(
category
);
x
.
setCategoryPinyin
(
pingYin
);
//拼音存在则拼接id
if
(
categoryBizEntity
!=
null
&&!
categoryBizEntity
.
getId
().
equals
(
x
.
getId
())){
x
.
setCategoryPinyin
(
pingYin
+
x
.
getId
());
}
categoryBiz
.
update
(
x
);
});
//再更新路径
list
.
forEach
(
x
->{
if
(
StrUtil
.
isBlank
(
x
.
getCategoryId
())||
x
.
getCategoryId
().
equals
(
"0"
)){
categoryBiz
.
updateEntity
(
x
);
}
});
}
}
src/main/java/net/mingsoft/cms/util/CmsParserUtil.java
View file @
d28c2497
package
net
.
mingsoft
.
cms
.
util
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.TimeInterval
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.PageUtil
;
import
freemarker.cache.FileTemplateLoader
;
...
...
@@ -20,7 +23,11 @@ import net.mingsoft.mdiy.entity.ModelEntity;
import
net.mingsoft.mdiy.parser.TagParser
;
import
net.mingsoft.mdiy.util.ParserUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.util.WebAppRootListener
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.StringWriter
;
...
...
@@ -28,6 +35,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ExecutorService
;
public
class
CmsParserUtil
extends
ParserUtil
{
...
...
@@ -144,7 +152,7 @@ public class CmsParserUtil extends ParserUtil {
// 将tag.getContent()写入路径
FileUtil
.
writeString
(
tag
.
rendering
(),
mobilePath
,
Const
.
UTF8
);
}
writer
=
new
StringWriter
();
}
else
{
// 遍历分页
for
(
int
i
=
0
;
i
<
totalPageSize
;
i
++)
{
...
...
@@ -176,7 +184,6 @@ public class CmsParserUtil extends ParserUtil {
// 将tag.getContent()写入路径
FileUtil
.
writeString
(
tag
.
rendering
(),
mobilePath
,
Const
.
UTF8
);
}
writer
=
new
StringWriter
();
pageNo
++;
}
}
...
...
@@ -199,16 +206,16 @@ public class CmsParserUtil extends ParserUtil {
* @throws MalformedTemplateNameException
* @throws TemplateNotFoundException
*/
public
static
void
generateBasic
(
List
<
ContentBean
>
articleIdList
)
throws
TemplateNotFoundException
,
MalformedTemplateNameException
,
ParseException
,
IOException
{
public
static
void
generateBasic
(
List
<
ContentBean
>
articleIdList
)
{
Map
<
Object
,
Object
>
contentModelMap
=
new
HashMap
<
Object
,
Object
>();
ModelEntity
contentModel
=
null
;
String
writePath
=
null
;
// 记录已经生成了文章编号
List
<
Integer
>
generateIds
=
new
ArrayList
<>();
ExecutorService
pool
=
SpringUtil
.
getBean
(
ExecutorService
.
class
);
// 生成文档
for
(
int
artId
=
0
;
artId
<
articleIdList
.
size
();)
{
String
writePath
=
null
;
//设置分页类
PageBean
page
=
new
PageBean
();
// 文章编号
...
...
@@ -235,11 +242,12 @@ public class CmsParserUtil extends ParserUtil {
}
// 将
generateIds
.
add
(
articleId
);
// 组合文章路径如:html/站点id/栏目id/文章id.html
writePath
=
ParserUtil
.
buildHtmlPath
(
articleColumnPath
+
File
.
separator
+
articleId
);
//如果是封面就生成index.html
if
(
Integer
.
parseInt
(
articleIdList
.
get
(
artId
).
getCategoryType
())
==
COLUMN_TYPE_COVER
)
{
writePath
=
ParserUtil
.
buildHtmlPath
(
articleColumnPath
+
File
.
separator
+
ParserUtil
.
INDEX
);
}
else
{
// 组合文章路径如:html/站点id/栏目id/文章id.html
writePath
=
ParserUtil
.
buildHtmlPath
(
articleColumnPath
+
File
.
separator
+
articleId
);
}
Map
<
String
,
Object
>
parserParams
=
new
HashMap
<
String
,
Object
>();
parserParams
.
put
(
ParserUtil
.
COLUMN
,
articleIdList
.
get
(
artId
));
...
...
@@ -278,23 +286,46 @@ public class CmsParserUtil extends ParserUtil {
parserParams
.
put
(
IS_DO
,
false
);
parserParams
.
put
(
ParserUtil
.
PAGE
,
page
);
String
content
=
CmsParserUtil
.
generate
(
articleIdList
.
get
(
artId
).
getCategoryUrl
(),
parserParams
,
false
);
FileUtil
.
writeString
(
content
,
writePath
,
Const
.
UTF8
);
String
finalWritePath
=
writePath
;
HashMap
<
Object
,
Object
>
cloneMap
=
CollUtil
.
newHashMap
();
cloneMap
.
putAll
(
parserParams
);
HttpServletRequest
request
=
SpringUtil
.
getRequest
();
pool
.
execute
(()
->
{
String
content
=
null
;
try
{
SpringUtil
.
setRequest
(
request
);
content
=
CmsParserUtil
.
generate
(
columnUrl
,
cloneMap
,
false
);
FileUtil
.
writeString
(
content
,
finalWritePath
,
Const
.
UTF8
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
});
// 手机端
if
(
ParserUtil
.
hasMobileFile
(
columnUrl
))
{
writePath
=
ParserUtil
.
buildMobileHtmlPath
(
articleColumnPath
+
File
.
separator
+
articleId
);
//如果是封面就生成index.html
if
(
Integer
.
parseInt
(
articleIdList
.
get
(
artId
).
getCategoryType
())
==
COLUMN_TYPE_COVER
)
{
writePath
=
ParserUtil
.
buildMobileHtmlPath
(
articleColumnPath
+
File
.
separator
+
ParserUtil
.
INDEX
);
}
else
{
writePath
=
ParserUtil
.
buildMobileHtmlPath
(
articleColumnPath
+
File
.
separator
+
articleId
);
}
// 判断文件是否存在,若不存在弹出返回信息
if
(!
FileUtil
.
exist
(
ParserUtil
.
buildTempletPath
(
MOBILE
+
File
.
separator
+
columnUrl
)))
{
artId
++;
continue
;
}
String
finalWritePath1
=
writePath
;
pool
.
execute
(()
->
{
SpringUtil
.
setRequest
(
request
);
parserParams
.
put
(
MOBILE
,
BasicUtil
.
getApp
().
getAppMobileStyle
());
content
=
CmsParserUtil
.
generate
(
articleIdList
.
get
(
artId
).
getCategoryUrl
(),
parserParams
,
true
);
FileUtil
.
writeString
(
content
,
writePath
,
Const
.
UTF8
);
String
content
=
null
;
try
{
content
=
CmsParserUtil
.
generate
(
columnUrl
,
parserParams
,
true
);
FileUtil
.
writeString
(
content
,
finalWritePath1
,
Const
.
UTF8
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
});
}
artId
++;
}
...
...
src/main/java/net/mingsoft/config/WebConfig.java
View file @
d28c2497
...
...
@@ -2,6 +2,7 @@ package net.mingsoft.config;
import
java.io.File
;
import
java.util.List
;
import
java.util.concurrent.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -139,10 +140,19 @@ public class WebConfig implements WebMvcConfigurer {
public
MappingJackson2HttpMessageConverter
mappingJackson2HttpMessageConverter
(){
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
//添加此配置
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
converter
.
setObjectMapper
(
objectMapper
);
return
converter
;
}
@Bean
public
ExecutorService
crawlExecutorPool
()
{
// 创建线程池
ExecutorService
pool
=
new
ThreadPoolExecutor
(
20
,
20
,
0L
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<
Runnable
>());
return
pool
;
}
}
src/main/resources/application-dev.yml
View file @
d28c2497
...
...
@@ -2,6 +2,6 @@ spring:
datasource
:
url
:
jdbc:mysql://localhost:3306/db-mcms-open?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
username
:
root
password
:
123456
password
:
filters
:
wall,mergeStat
type
:
com.alibaba.druid.pool.DruidDataSource
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