Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
MCMS
Commits
4682b0ca
Commit
4682b0ca
authored
Oct 29, 2020
by
sgjj
Browse files
添加雪花主键
parent
1c16536f
Changes
21
Hide whitespace changes
Inline
Side-by-side
doc/5.2-patch.sql
View file @
4682b0ca
...
@@ -11,4 +11,7 @@ ALTER TABLE `mdiy_dict`
...
@@ -11,4 +11,7 @@ ALTER TABLE `mdiy_dict`
ADD
COLUMN
`dict_enable`
varchar
(
11
)
CHARACTER
SET
utf8
COLLATE
utf8_bin
NULL
DEFAULT
'1'
COMMENT
'启用状态'
AFTER
`is_child`
;
ADD
COLUMN
`dict_enable`
varchar
(
11
)
CHARACTER
SET
utf8
COLLATE
utf8_bin
NULL
DEFAULT
'1'
COMMENT
'启用状态'
AFTER
`is_child`
;
ALTER
TABLE
`cms_category`
ADD
COLUMN
`leaf`
bigint
(
1
)
NULL
DEFAULT
NULL
COMMENT
'是否是叶子节点'
AFTER
`category_pinyin`
;
ALTER
TABLE
`cms_category`
ADD
COLUMN
`leaf`
bigint
(
1
)
NULL
DEFAULT
NULL
COMMENT
'是否是叶子节点'
AFTER
`category_pinyin`
;
ALTER
TABLE
`cms_category`
ADD
COLUMN
`top_id`
int
(
11
)
NULL
DEFAULT
NULL
COMMENT
'顶级id'
AFTER
`leaf`
;
ALTER
TABLE
`cms_category`
ADD
COLUMN
`top_id`
bigint
(
20
)
NULL
DEFAULT
NULL
COMMENT
'顶级id'
AFTER
`leaf`
;
\ No newline at end of file
ALTER
TABLE
`cms_category`
MODIFY
COLUMN
`id`
bigint
(
20
)
UNSIGNED
NOT
NULL
FIRST
;
ALTER
TABLE
`cms_content`
MODIFY
COLUMN
`id`
bigint
(
20
)
UNSIGNED
NOT
NULL
FIRST
;
ALTER
TABLE
`system_log`
MODIFY
COLUMN
`id`
bigint
(
20
)
UNSIGNED
NOT
NULL
FIRST
;
\ No newline at end of file
pom.xml
View file @
4682b0ca
...
@@ -35,6 +35,12 @@
...
@@ -35,6 +35,12 @@
</repositories>
</repositories>
<dependencies>
<dependencies>
<dependency>
<groupId>
dm
</groupId>
<artifactId>
dm.jdbc.driver
</artifactId>
<version>
7.0.1
</version>
</dependency>
<dependency>
<dependency>
<groupId>
net.mingsoft
</groupId>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-mpeople
</artifactId>
<artifactId>
ms-mpeople
</artifactId>
...
...
src/main/java/net/mingsoft/MSApplication.java
View file @
4682b0ca
...
@@ -13,7 +13,7 @@ import java.util.Locale;
...
@@ -13,7 +13,7 @@ import java.util.Locale;
@SpringBootApplication
@SpringBootApplication
@ComponentScan
(
basePackages
=
{
"net.mingsoft"
})
@ComponentScan
(
basePackages
=
{
"net.mingsoft"
})
@MapperScan
(
basePackages
={
"**.dao"
})
@MapperScan
(
basePackages
={
"**.dao"
,
"**.mapper"
})
@ServletComponentScan
(
basePackages
=
{
"net.mingsoft"
})
@ServletComponentScan
(
basePackages
=
{
"net.mingsoft"
})
public
class
MSApplication
{
public
class
MSApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/net/mingsoft/cms/action/CategoryAction.java
View file @
4682b0ca
...
@@ -4,16 +4,15 @@ import io.swagger.annotations.Api;
...
@@ -4,16 +4,15 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
net.mingsoft.base.entity.BaseEntity
;
import
net.mingsoft.base.entity.ResultData
;
import
net.mingsoft.base.entity.ResultData
;
import
net.mingsoft.basic.annotation.LogAnn
;
import
net.mingsoft.basic.annotation.LogAnn
;
import
net.mingsoft.basic.bean.EUListBean
;
import
net.mingsoft.basic.bean.EUListBean
;
import
net.mingsoft.basic.constant.e.BusinessTypeEnum
;
import
net.mingsoft.basic.constant.e.BusinessTypeEnum
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.PinYinUtil
;
import
net.mingsoft.basic.util.StringUtil
;
import
net.mingsoft.basic.util.StringUtil
;
import
net.mingsoft.cms.biz.ICategoryBiz
;
import
net.mingsoft.cms.biz.ICategoryBiz
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.basic.util.PinYinUtil
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
...
@@ -25,6 +24,7 @@ import springfox.documentation.annotations.ApiIgnore;
...
@@ -25,6 +24,7 @@ import springfox.documentation.annotations.ApiIgnore;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* 分类管理控制层
* 分类管理控制层
* @author 铭飞开发团队
* @author 铭飞开发团队
...
@@ -34,7 +34,7 @@ import java.util.List;
...
@@ -34,7 +34,7 @@ import java.util.List;
@Api
(
value
=
"分类接口"
)
@Api
(
value
=
"分类接口"
)
@Controller
(
"cmsCategoryAction"
)
@Controller
(
"cmsCategoryAction"
)
@RequestMapping
(
"/${ms.manager.path}/cms/category"
)
@RequestMapping
(
"/${ms.manager.path}/cms/category"
)
public
class
CategoryAction
extends
BaseAction
{
public
class
CategoryAction
extends
BaseAction
{
/**
/**
...
@@ -84,23 +84,19 @@ public class CategoryAction extends BaseAction{
...
@@ -84,23 +84,19 @@ public class CategoryAction extends BaseAction{
})
})
@RequestMapping
(
"/list"
)
@RequestMapping
(
"/list"
)
@ResponseBody
@ResponseBody
public
ResultData
list
(
@ModelAttribute
@ApiIgnore
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
,
BindingResult
result
)
{
public
ResultData
list
(
@ModelAttribute
@ApiIgnore
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
,
BindingResult
result
)
{
category
.
setAppId
(
BasicUtil
.
getAppId
());
category
.
setAppId
(
BasicUtil
.
getAppId
());
BasicUtil
.
startPage
();
BasicUtil
.
startPage
();
List
categoryList
=
categoryBiz
.
query
(
category
);
List
categoryList
=
categoryBiz
.
query
(
category
);
return
ResultData
.
build
().
success
(
new
EUListBean
(
categoryList
,(
int
)
BasicUtil
.
endPage
(
categoryList
).
getTotal
()));
return
ResultData
.
build
().
success
(
new
EUListBean
(
categoryList
,(
int
)
BasicUtil
.
endPage
(
categoryList
).
getTotal
()));
}
}
/**
/**
* 返回编辑界面category_form
* 返回编辑界面category_form
*/
*/
@GetMapping
(
"/form"
)
@GetMapping
(
"/form"
)
public
String
form
(
@ModelAttribute
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
,
ModelMap
model
){
public
String
form
(
@ModelAttribute
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
,
ModelMap
model
){
if
(
category
.
getId
()!=
null
){
model
.
addAttribute
(
"appId"
,
BasicUtil
.
getAppId
());
BaseEntity
categoryEntity
=
categoryBiz
.
getEntity
(
Integer
.
parseInt
(
category
.
getId
()));
model
.
addAttribute
(
"categoryEntity"
,
categoryEntity
);
}
model
.
addAttribute
(
"appId"
,
BasicUtil
.
getAppId
());
return
"/cms/category/form"
;
return
"/cms/category/form"
;
}
}
...
@@ -112,12 +108,12 @@ public class CategoryAction extends BaseAction{
...
@@ -112,12 +108,12 @@ public class CategoryAction extends BaseAction{
@ApiImplicitParam
(
name
=
"id"
,
value
=
"编号"
,
required
=
true
,
paramType
=
"query"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"编号"
,
required
=
true
,
paramType
=
"query"
)
@GetMapping
(
"/get"
)
@GetMapping
(
"/get"
)
@ResponseBody
@ResponseBody
public
ResultData
get
(
@ModelAttribute
@ApiIgnore
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
){
public
ResultData
get
(
@ModelAttribute
@ApiIgnore
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
){
if
(
category
.
getId
()==
null
)
{
if
(
category
.
getId
()==
null
)
{
return
ResultData
.
build
().
error
();
return
ResultData
.
build
().
error
();
}
}
category
.
setAppId
(
BasicUtil
.
getAppId
());
category
.
setAppId
(
BasicUtil
.
getAppId
());
CategoryEntity
_category
=
(
CategoryEntity
)
categoryBiz
.
get
Entity
(
Integer
.
parseInt
(
category
.
getId
())
)
;
CategoryEntity
_category
=
(
CategoryEntity
)
categoryBiz
.
get
ById
(
category
.
getId
());
return
ResultData
.
build
().
success
(
_category
);
return
ResultData
.
build
().
success
(
_category
);
}
}
...
@@ -187,7 +183,7 @@ public class CategoryAction extends BaseAction{
...
@@ -187,7 +183,7 @@ public class CategoryAction extends BaseAction{
@ResponseBody
@ResponseBody
@LogAnn
(
title
=
"删除分类"
,
businessType
=
BusinessTypeEnum
.
DELETE
)
@LogAnn
(
title
=
"删除分类"
,
businessType
=
BusinessTypeEnum
.
DELETE
)
@RequiresPermissions
(
"cms:category:del"
)
@RequiresPermissions
(
"cms:category:del"
)
public
ResultData
delete
(
@RequestBody
List
<
CategoryEntity
>
categorys
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
public
ResultData
delete
(
@RequestBody
List
<
CategoryEntity
>
categorys
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
for
(
int
i
=
0
;
i
<
categorys
.
size
();
i
++){
for
(
int
i
=
0
;
i
<
categorys
.
size
();
i
++){
categoryBiz
.
delete
(
Integer
.
parseInt
(
categorys
.
get
(
i
).
getId
()));
categoryBiz
.
delete
(
Integer
.
parseInt
(
categorys
.
get
(
i
).
getId
()));
}
}
...
@@ -230,7 +226,7 @@ public class CategoryAction extends BaseAction{
...
@@ -230,7 +226,7 @@ public class CategoryAction extends BaseAction{
@LogAnn
(
title
=
"更新分类"
,
businessType
=
BusinessTypeEnum
.
UPDATE
)
@LogAnn
(
title
=
"更新分类"
,
businessType
=
BusinessTypeEnum
.
UPDATE
)
@RequiresPermissions
(
"cms:category:update"
)
@RequiresPermissions
(
"cms:category:update"
)
public
ResultData
update
(
@ModelAttribute
@ApiIgnore
CategoryEntity
category
,
HttpServletResponse
response
,
public
ResultData
update
(
@ModelAttribute
@ApiIgnore
CategoryEntity
category
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
HttpServletRequest
request
)
{
//验证栏目管理名称的值是否合法
//验证栏目管理名称的值是否合法
if
(
StringUtil
.
isBlank
(
category
.
getCategoryTitle
())){
if
(
StringUtil
.
isBlank
(
category
.
getCategoryTitle
())){
return
ResultData
.
build
().
error
(
getResString
(
"err.empty"
,
this
.
getResString
(
"category.title"
)));
return
ResultData
.
build
().
error
(
getResString
(
"err.empty"
,
this
.
getResString
(
"category.title"
)));
...
...
src/main/java/net/mingsoft/cms/action/ContentAction.java
View file @
4682b0ca
...
@@ -4,7 +4,6 @@ import io.swagger.annotations.Api;
...
@@ -4,7 +4,6 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
net.mingsoft.base.entity.BaseEntity
;
import
net.mingsoft.base.entity.ResultData
;
import
net.mingsoft.base.entity.ResultData
;
import
net.mingsoft.basic.annotation.LogAnn
;
import
net.mingsoft.basic.annotation.LogAnn
;
import
net.mingsoft.basic.bean.EUListBean
;
import
net.mingsoft.basic.bean.EUListBean
;
...
@@ -24,6 +23,7 @@ import springfox.documentation.annotations.ApiIgnore;
...
@@ -24,6 +23,7 @@ import springfox.documentation.annotations.ApiIgnore;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* 文章管理控制层
* 文章管理控制层
* @author 铭飞开发团队
* @author 铭飞开发团队
...
@@ -33,7 +33,7 @@ import java.util.List;
...
@@ -33,7 +33,7 @@ import java.util.List;
@Api
(
value
=
"文章接口"
)
@Api
(
value
=
"文章接口"
)
@Controller
(
"cmsContentAction"
)
@Controller
(
"cmsContentAction"
)
@RequestMapping
(
"/${ms.manager.path}/cms/content"
)
@RequestMapping
(
"/${ms.manager.path}/cms/content"
)
public
class
ContentAction
extends
BaseAction
{
public
class
ContentAction
extends
BaseAction
{
/**
/**
...
@@ -86,23 +86,19 @@ public class ContentAction extends BaseAction{
...
@@ -86,23 +86,19 @@ public class ContentAction extends BaseAction{
})
})
@RequestMapping
(
"/list"
)
@RequestMapping
(
"/list"
)
@ResponseBody
@ResponseBody
public
ResultData
list
(
@ModelAttribute
@ApiIgnore
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
,
BindingResult
result
)
{
public
ResultData
list
(
@ModelAttribute
@ApiIgnore
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
,
BindingResult
result
)
{
content
.
setAppId
(
BasicUtil
.
getAppId
());
content
.
setAppId
(
BasicUtil
.
getAppId
());
BasicUtil
.
startPage
();
BasicUtil
.
startPage
();
List
contentList
=
contentBiz
.
query
(
content
);
List
contentList
=
contentBiz
.
query
(
content
);
return
ResultData
.
build
().
success
(
new
EUListBean
(
contentList
,(
int
)
BasicUtil
.
endPage
(
contentList
).
getTotal
()));
return
ResultData
.
build
().
success
(
new
EUListBean
(
contentList
,(
int
)
BasicUtil
.
endPage
(
contentList
).
getTotal
()));
}
}
/**
/**
* 返回编辑界面content_form
* 返回编辑界面content_form
*/
*/
@GetMapping
(
"/form"
)
@GetMapping
(
"/form"
)
public
String
form
(
@ModelAttribute
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
,
ModelMap
model
){
public
String
form
(
@ModelAttribute
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
,
ModelMap
model
){
if
(
content
.
getId
()!=
null
){
model
.
addAttribute
(
"appId"
,
BasicUtil
.
getAppId
());
BaseEntity
contentEntity
=
contentBiz
.
getEntity
(
Integer
.
parseInt
(
content
.
getId
()));
model
.
addAttribute
(
"contentEntity"
,
contentEntity
);
}
model
.
addAttribute
(
"appId"
,
BasicUtil
.
getAppId
());
return
"/cms/content/form"
;
return
"/cms/content/form"
;
}
}
...
@@ -114,12 +110,12 @@ public class ContentAction extends BaseAction{
...
@@ -114,12 +110,12 @@ public class ContentAction extends BaseAction{
@ApiImplicitParam
(
name
=
"id"
,
value
=
"编号"
,
required
=
true
,
paramType
=
"query"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"编号"
,
required
=
true
,
paramType
=
"query"
)
@GetMapping
(
"/get"
)
@GetMapping
(
"/get"
)
@ResponseBody
@ResponseBody
public
ResultData
get
(
@ModelAttribute
@ApiIgnore
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
){
public
ResultData
get
(
@ModelAttribute
@ApiIgnore
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
,
@ApiIgnore
ModelMap
model
){
if
(
content
.
getId
()==
null
)
{
if
(
content
.
getId
()==
null
)
{
return
ResultData
.
build
().
error
();
return
ResultData
.
build
().
error
();
}
}
content
.
setAppId
(
BasicUtil
.
getAppId
());
content
.
setAppId
(
BasicUtil
.
getAppId
());
ContentEntity
_content
=
(
ContentEntity
)
contentBiz
.
getEntity
(
Integer
.
parseInt
(
content
.
getId
())
)
;
ContentEntity
_content
=
contentBiz
.
getById
(
content
.
getId
());
return
ResultData
.
build
().
success
(
_content
);
return
ResultData
.
build
().
success
(
_content
);
}
}
...
@@ -177,7 +173,7 @@ public class ContentAction extends BaseAction{
...
@@ -177,7 +173,7 @@ public class ContentAction extends BaseAction{
return
ResultData
.
build
().
error
(
getResString
(
"err.length"
,
this
.
getResString
(
"content.url"
),
"0"
,
"200"
));
return
ResultData
.
build
().
error
(
getResString
(
"err.length"
,
this
.
getResString
(
"content.url"
),
"0"
,
"200"
));
}
}
content
.
setAppId
(
BasicUtil
.
getAppId
());
content
.
setAppId
(
BasicUtil
.
getAppId
());
contentBiz
.
save
Entity
(
content
);
contentBiz
.
save
(
content
);
return
ResultData
.
build
().
success
(
content
);
return
ResultData
.
build
().
success
(
content
);
}
}
...
@@ -189,7 +185,7 @@ public class ContentAction extends BaseAction{
...
@@ -189,7 +185,7 @@ public class ContentAction extends BaseAction{
@ResponseBody
@ResponseBody
@LogAnn
(
title
=
"删除文章"
,
businessType
=
BusinessTypeEnum
.
DELETE
)
@LogAnn
(
title
=
"删除文章"
,
businessType
=
BusinessTypeEnum
.
DELETE
)
@RequiresPermissions
(
"cms:content:del"
)
@RequiresPermissions
(
"cms:content:del"
)
public
ResultData
delete
(
@RequestBody
List
<
ContentEntity
>
contents
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
public
ResultData
delete
(
@RequestBody
List
<
ContentEntity
>
contents
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
int
[]
ids
=
new
int
[
contents
.
size
()];
int
[]
ids
=
new
int
[
contents
.
size
()];
for
(
int
i
=
0
;
i
<
contents
.
size
();
i
++){
for
(
int
i
=
0
;
i
<
contents
.
size
();
i
++){
ids
[
i
]
=
Integer
.
parseInt
(
contents
.
get
(
i
).
getId
())
;
ids
[
i
]
=
Integer
.
parseInt
(
contents
.
get
(
i
).
getId
())
;
...
@@ -230,7 +226,7 @@ public class ContentAction extends BaseAction{
...
@@ -230,7 +226,7 @@ public class ContentAction extends BaseAction{
@LogAnn
(
title
=
"更新文章"
,
businessType
=
BusinessTypeEnum
.
UPDATE
)
@LogAnn
(
title
=
"更新文章"
,
businessType
=
BusinessTypeEnum
.
UPDATE
)
@RequiresPermissions
(
"cms:content:update"
)
@RequiresPermissions
(
"cms:content:update"
)
public
ResultData
update
(
@ModelAttribute
@ApiIgnore
ContentEntity
content
,
HttpServletResponse
response
,
public
ResultData
update
(
@ModelAttribute
@ApiIgnore
ContentEntity
content
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
HttpServletRequest
request
)
{
//验证文章标题的值是否合法
//验证文章标题的值是否合法
if
(
StringUtil
.
isBlank
(
content
.
getContentTitle
())){
if
(
StringUtil
.
isBlank
(
content
.
getContentTitle
())){
return
ResultData
.
build
().
error
(
getResString
(
"err.empty"
,
this
.
getResString
(
"content.title"
)));
return
ResultData
.
build
().
error
(
getResString
(
"err.empty"
,
this
.
getResString
(
"content.title"
)));
...
...
src/main/java/net/mingsoft/cms/action/web/MCmsAction.java
View file @
4682b0ca
...
@@ -26,9 +26,7 @@ import cn.hutool.core.util.PageUtil;
...
@@ -26,9 +26,7 @@ import cn.hutool.core.util.PageUtil;
import
freemarker.core.ParseException
;
import
freemarker.core.ParseException
;
import
freemarker.template.MalformedTemplateNameException
;
import
freemarker.template.MalformedTemplateNameException
;
import
freemarker.template.TemplateNotFoundException
;
import
freemarker.template.TemplateNotFoundException
;
import
net.bytebuddy.implementation.bytecode.Throw
;
import
net.mingsoft.base.constant.Const
;
import
net.mingsoft.base.constant.Const
;
import
net.mingsoft.basic.exception.BusinessException
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.StringUtil
;
import
net.mingsoft.basic.util.StringUtil
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.CategoryBean
;
...
@@ -107,8 +105,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -107,8 +105,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
* 动态列表页
* 动态列表页
*/
*/
@GetMapping
(
"/index.do"
)
@GetMapping
(
"/index.do"
)
@ResponseBody
public
void
index
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
public
String
index
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
Map
map
=
BasicUtil
.
assemblyRequestMap
();
Map
map
=
BasicUtil
.
assemblyRequestMap
();
map
.
forEach
((
k
,
v
)->{
map
.
forEach
((
k
,
v
)->{
map
.
put
(
k
,
v
.
toString
().
replaceAll
(
"('|\"|\\\\)"
,
"\\\\$1"
));
map
.
put
(
k
,
v
.
toString
().
replaceAll
(
"('|\"|\\\\)"
,
"\\\\$1"
));
...
@@ -132,7 +129,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -132,7 +129,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
content
;
this
.
outString
(
resp
,
content
)
;
}
}
/**
/**
...
@@ -140,9 +137,8 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -140,9 +137,8 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
* @param req
* @param req
* @param resp
* @param resp
*/
*/
@ResponseBody
@GetMapping
(
"/list.do"
)
@GetMapping
(
"/list.do"
)
public
String
list
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
public
void
list
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
Map
map
=
BasicUtil
.
assemblyRequestMap
();
Map
map
=
BasicUtil
.
assemblyRequestMap
();
map
.
forEach
((
k
,
v
)->{
map
.
forEach
((
k
,
v
)->{
map
.
put
(
k
,
v
.
toString
().
replaceAll
(
"('|\"|\\\\)"
,
"\\\\$1"
));
map
.
put
(
k
,
v
.
toString
().
replaceAll
(
"('|\"|\\\\)"
,
"\\\\$1"
));
...
@@ -156,7 +152,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -156,7 +152,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
List
<
CategoryBean
>
columnArticles
=
contentBiz
.
queryIdsByCategoryIdForParser
(
contentBean
);
List
<
CategoryBean
>
columnArticles
=
contentBiz
.
queryIdsByCategoryIdForParser
(
contentBean
);
//判断栏目下是否有文章
//判断栏目下是否有文章
if
(
columnArticles
.
size
()==
0
){
if
(
columnArticles
.
size
()==
0
){
return
""
;
this
.
outJson
(
resp
,
false
)
;
}
}
//设置分页类
//设置分页类
PageBean
page
=
new
PageBean
();
PageBean
page
=
new
PageBean
();
...
@@ -189,7 +185,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -189,7 +185,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
content
;
this
.
outString
(
resp
,
content
)
;
}
}
/**
/**
...
@@ -197,17 +193,18 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -197,17 +193,18 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
* @param id 文章编号
* @param id 文章编号
*/
*/
@GetMapping
(
"/view.do"
)
@GetMapping
(
"/view.do"
)
@ResponseBody
public
void
view
(
String
orderby
,
String
order
,
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
public
String
view
(
String
orderby
,
String
order
,
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
//参数文章编号
//参数文章编号
ContentEntity
article
=
(
ContentEntity
)
contentBiz
.
getEntity
(
BasicUtil
.
getInt
(
ParserUtil
.
ID
));
ContentEntity
article
=
(
ContentEntity
)
contentBiz
.
getEntity
(
BasicUtil
.
getInt
(
ParserUtil
.
ID
));
if
(
ObjectUtil
.
isNull
(
article
)){
if
(
ObjectUtil
.
isNull
(
article
)){
throw
new
BusinessException
(
this
.
getResString
(
"err.empty"
,
this
.
getResString
(
"id"
)))
;
this
.
outJson
(
resp
,
null
,
false
,
getResString
(
"err.empty"
,
this
.
getResString
(
"id"
)));
return
;
}
}
if
(
StringUtils
.
isNotBlank
(
order
)){
if
(
StringUtils
.
isNotBlank
(
order
)){
//防注入
//防注入
if
(!
order
.
toLowerCase
().
equals
(
"asc"
)&&!
order
.
toLowerCase
().
equals
(
"desc"
)){
if
(!
order
.
toLowerCase
().
equals
(
"asc"
)&&!
order
.
toLowerCase
().
equals
(
"desc"
)){
throw
new
BusinessException
(
this
.
getResString
(
"err.error"
,
this
.
getResString
(
"order"
)));
this
.
outJson
(
resp
,
null
,
false
,
getResString
(
"err.error"
,
this
.
getResString
(
"order"
)));
return
;
}
}
}
}
...
@@ -242,7 +239,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -242,7 +239,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
ModelEntity
contentModel
=
null
;
ModelEntity
contentModel
=
null
;
for
(
int
artId
=
0
;
artId
<
articleIdList
.
size
();)
{
for
(
int
artId
=
0
;
artId
<
articleIdList
.
size
();)
{
//如果不是当前文章则跳过
//如果不是当前文章则跳过
if
(
articleIdList
.
get
(
artId
).
getArticleId
()
!=
Integer
.
parseInt
(
article
.
getId
())){
if
(
!
articleIdList
.
get
(
artId
).
getArticleId
()
.
equals
(
article
.
getId
())){
artId
++;
artId
++;
continue
;
continue
;
}
}
...
@@ -292,7 +289,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -292,7 +289,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
content
;
this
.
outString
(
resp
,
content
)
;
}
}
...
@@ -306,7 +303,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -306,7 +303,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
*/
*/
@RequestMapping
(
value
=
"search"
)
@RequestMapping
(
value
=
"search"
)
@ResponseBody
@ResponseBody
public
String
search
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
public
void
search
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
// 读取请求字段
// 读取请求字段
...
@@ -450,7 +447,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
...
@@ -450,7 +447,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
content
;
this
.
outString
(
response
,
content
)
;
}
}
// 清除路径中的转义字符
// 清除路径中的转义字符
...
...
src/main/java/net/mingsoft/cms/bean/CategoryBean.java
View file @
4682b0ca
...
@@ -13,16 +13,16 @@ public class CategoryBean extends CategoryEntity {
...
@@ -13,16 +13,16 @@ public class CategoryBean extends CategoryEntity {
/**
/**
* 文章编号
* 文章编号
*/
*/
private
in
t
articleId
;
private
Str
in
g
articleId
;
public
in
t
getArticleId
()
{
public
Str
in
g
getArticleId
()
{
return
articleId
;
return
articleId
;
}
}
public
void
setArticleId
(
in
t
articleId
)
{
public
void
setArticleId
(
Str
in
g
articleId
)
{
this
.
articleId
=
articleId
;
this
.
articleId
=
articleId
;
}
}
}
}
\ No newline at end of file
src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java
View file @
4682b0ca
...
@@ -12,7 +12,7 @@ import java.util.List;
...
@@ -12,7 +12,7 @@ import java.util.List;
* 创建日期:2019-11-28 15:12:32<br/>
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
public
interface
ICategoryBiz
extends
IBaseBiz
{
public
interface
ICategoryBiz
extends
IBaseBiz
<
CategoryEntity
>
{
/**
/**
* 查询当前分类下的所有子分类
* 查询当前分类下的所有子分类
...
...
src/main/java/net/mingsoft/cms/biz/IContentBiz.java
View file @
4682b0ca
...
@@ -3,6 +3,7 @@ package net.mingsoft.cms.biz;
...
@@ -3,6 +3,7 @@ package net.mingsoft.cms.biz;
import
net.mingsoft.base.biz.IBaseBiz
;
import
net.mingsoft.base.biz.IBaseBiz
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.entity.ContentEntity
;
import
net.mingsoft.mdiy.entity.ModelEntity
;
import
net.mingsoft.mdiy.entity.ModelEntity
;
import
java.util.List
;
import
java.util.List
;
...
@@ -15,7 +16,7 @@ import java.util.Map;
...
@@ -15,7 +16,7 @@ import java.util.Map;
* 创建日期:2019-11-28 15:12:32<br/>
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
public
interface
IContentBiz
extends
IBaseBiz
{
public
interface
IContentBiz
extends
IBaseBiz
<
ContentEntity
>
{
/**
/**
* 根据文章属性查询
* 根据文章属性查询
...
...
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java
View file @
4682b0ca
...
@@ -21,18 +21,21 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
...
@@ -21,18 +21,21 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
package
net.mingsoft.cms.biz.impl
;
package
net.mingsoft.cms.biz.impl
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
net.mingsoft.base.biz.impl.BaseBizImpl
;
import
net.mingsoft.base.biz.impl.BaseBizImpl
;
import
net.mingsoft.base.dao.IBaseDao
;
import
net.mingsoft.base.dao.IBaseDao
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.PinYinUtil
;
import
net.mingsoft.cms.biz.ICategoryBiz
;
import
net.mingsoft.cms.biz.ICategoryBiz
;
import
net.mingsoft.cms.dao.ICategoryDao
;
import
net.mingsoft.cms.dao.ICategoryDao
;
import
net.mingsoft.cms.dao.IContentDao
;
import
net.mingsoft.cms.dao.IContentDao
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.basic.util.PinYinUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.List
;
...
@@ -43,7 +46,8 @@ import java.util.List;
...
@@ -43,7 +46,8 @@ import java.util.List;
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
@Service
(
"cmscategoryBizImpl"
)
@Service
(
"cmscategoryBizImpl"
)
public
class
CategoryBizImpl
extends
BaseBizImpl
implements
ICategoryBiz
{
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
class
CategoryBizImpl
extends
BaseBizImpl
<
ICategoryDao
,
CategoryEntity
>
implements
ICategoryBiz
{
@Autowired
@Autowired
...
@@ -74,25 +78,36 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
...
@@ -74,25 +78,36 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
Object
categoryBizEntity
=
getEntity
(
category
);
Object
categoryBizEntity
=
getEntity
(
category
);
setParentId
(
categoryEntity
);
setParentId
(
categoryEntity
);
categoryEntity
.
setCategoryPinyin
(
pingYin
);
categoryEntity
.
setCategoryPinyin
(
pingYin
);
super
.
saveEntity
(
categoryEntity
);
//更新新的父级
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryId
())&&!
"0"
.
equals
(
categoryEntity
.
getCategoryId
())){
CategoryEntity
parent
=
getById
(
categoryEntity
.
getCategoryId
());
//如果之前是叶子节点就更新
if
(
parent
.
getLeaf
()){
parent
.
setLeaf
(
false
);
updateById
(
parent
);
}
}
categoryEntity
.
setLeaf
(
false
);
super
.
save
(
categoryEntity
);
//拼音存在则拼接id
//拼音存在则拼接id
if
(
categoryBizEntity
!=
null
){
if
(
categoryBizEntity
!=
null
){
categoryEntity
.
setCategoryPinyin
(
pingYin
+
categoryEntity
.
getId
());
categoryEntity
.
setCategoryPinyin
(
pingYin
+
categoryEntity
.
getId
());
}
}
CategoryEntity
parentCategory
=
null
;
CategoryEntity
parentCategory
=
null
;
if
(
StringUtils
.
isNotBlank
(
categoryEntity
.
getCategoryId
()))
{
if
(
StringUtils
.
isNotBlank
(
categoryEntity
.
getCategoryId
()))
{
parentCategory
=
(
CategoryEntity
)
categoryDao
.
getEntity
(
Integer
.
parseInt
(
categoryEntity
.
getCategoryId
())
)
;
parentCategory
=
(
CategoryEntity
)
getById
(
categoryEntity
.
getCategoryId
());
}
}
//保存链接地址
//保存链接地址
String
path
=
ObjectUtil
.
isNotNull
(
parentCategory
)?
parentCategory
.
getCategoryPath
():
""
;
String
path
=
ObjectUtil
.
isNotNull
(
parentCategory
)?
parentCategory
.
getCategoryPath
():
""
;
categoryEntity
.
setCategoryPath
(
path
+
"/"
+
categoryEntity
.
getCategoryPinyin
());
categoryEntity
.
setCategoryPath
(
path
+
"/"
+
categoryEntity
.
getCategoryPinyin
());
super
.
updateEntity
(
categoryEntity
);
setTopId
(
categoryEntity
);
super
.
updateById
(
categoryEntity
);
}
}
private
void
setParentId
(
CategoryEntity
categoryEntity
)
{
private
void
setParentId
(
CategoryEntity
categoryEntity
)
{
String
path
=
""
;
String
path
=
""
;
if
(
StringUtils
.
isNotEmpty
(
categoryEntity
.
getCategoryId
())&&
Integer
.
parse
Int
(
categoryEntity
.
getCategoryId
())>
0
)
{
if
(
StringUtils
.
isNotEmpty
(
categoryEntity
.
getCategoryId
())&&
Long
.
parse
Long
(
categoryEntity
.
getCategoryId
())>
0
)
{
CategoryEntity
category
=
(
CategoryEntity
)
categoryDao
.
getEntity
(
Integer
.
parseInt
(
categoryEntity
.
getCategoryId
())
)
;
CategoryEntity
category
=
(
CategoryEntity
)
getById
(
categoryEntity
.
getCategoryId
());
path
=
category
.
getCategoryPath
();
path
=
category
.
getCategoryPath
();
if
(
StringUtils
.
isEmpty
(
category
.
getCategoryParentId
()))
{
if
(
StringUtils
.
isEmpty
(
category
.
getCategoryParentId
()))
{
categoryEntity
.
setCategoryParentId
(
category
.
getId
());
categoryEntity
.
setCategoryParentId
(
category
.
getId
());
...
@@ -138,7 +153,9 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
...
@@ -138,7 +153,9 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
if
(
categoryBizEntity
!=
null
&&!
categoryBizEntity
.
getId
().
equals
(
entity
.
getId
())){
if
(
categoryBizEntity
!=
null
&&!
categoryBizEntity
.
getId
().
equals
(
entity
.
getId
())){
entity
.
setCategoryPinyin
(
pingYin
+
entity
.
getId
());
entity
.
setCategoryPinyin
(
pingYin
+
entity
.
getId
());
}
}
super
.
updateEntity
(
entity
);
setParentLeaf
(
entity
);
setTopId
(
entity
);
super
.
updateById
(
entity
);
setChildParentId
(
entity
);
setChildParentId
(
entity
);
}
}
...
@@ -165,4 +182,54 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
...
@@ -165,4 +182,54 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
contentDao
.
deleteEntityByCategoryIds
(
ids
);
contentDao
.
deleteEntityByCategoryIds
(
ids
);
}
}
}
}
/**
* 设置父级叶子节点
* @param entity
*/
private
void
setParentLeaf
(
CategoryEntity
entity
){
Assert
.
notNull
(
entity
);
CategoryEntity
categoryEntity
=
getById
(
entity
.
getId
());
//如果父级不为空并且修改了父级则需要更新父级
if
(!
entity
.
getCategoryId
().
equals
(
categoryEntity
.
getId
())){
//更新旧的父级
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryId
())&&!
"0"
.
equals
(
categoryEntity
.
getCategoryId
())){
CategoryEntity
parent
=
getById
(
categoryEntity
.
getCategoryId
());
//如果修改了父级则需要判断父级是否还有子节点
boolean
leaf
=
parent
.
getLeaf
();
//查找不等于当前更新的分类子集,有则不是叶子节点
parent
.
setLeaf
(
count
(
lambdaQuery
().
eq
(
CategoryEntity:
:
getCategoryId
,
parent
.
getId
()).
ne
(
CategoryEntity:
:
getId
,
entity
.
getId
()))==
0
);
if
(
leaf
!=
parent
.
getLeaf
()){
updateById
(
parent
);
}
}
//更新新的父级
if
(
StrUtil
.
isNotBlank
(
entity
.
getCategoryId
())&&!
"0"
.
equals
(
entity
.
getCategoryId
())){
CategoryEntity
parent
=
getById
(
entity
.
getCategoryId
());
//如果之前是叶子节点就更新
if
(
parent
.
getLeaf
()){
parent
.
setLeaf
(
false
);
updateById
(
parent
);
}
}
}
}
/**
* 设置顶级id
* @param entity
*/
private
void
setTopId
(
CategoryEntity
entity
){
String
categoryParentId
=
entity
.
getCategoryParentId
();
if
(
StrUtil
.
isNotBlank
(
categoryParentId
)){
String
[]
ids
=
categoryParentId
.
split
(
","
);
//如果有ParentId就取第一个
if
(
ids
.
length
>
0
){
entity
.
setTopId
(
ids
[
0
]);
return
;
}
}
entity
.
setTopId
(
"0"
);
}
}
}
src/main/java/net/mingsoft/cms/biz/impl/ContentBizImpl.java
View file @
4682b0ca
...
@@ -21,35 +21,20 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
...
@@ -21,35 +21,20 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
package
net.mingsoft.cms.biz.impl
;
package
net.mingsoft.cms.biz.impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
net.mingsoft.base.biz.impl.BaseBizImpl
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
net.mingsoft.base.dao.IBaseDao
;
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.basic.util.BasicUtil
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.dao.ICategoryDao
;
import
net.mingsoft.cms.biz.IContentBiz
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.cms.dao.IContentDao
;
import
net.mingsoft.cms.util.CmsParserUtil
;
import
net.mingsoft.cms.entity.ContentEntity
;
import
net.mingsoft.mdiy.bean.AttributeBean
;
import
net.mingsoft.mdiy.bean.PageBean
;
import
net.mingsoft.mdiy.entity.ModelEntity
;
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.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
net.mingsoft.base.biz.impl.BaseBizImpl
;
import
net.mingsoft.base.dao.IBaseDao
;
import
java.io.IOException
;
import
java.util.*
;
import
net.mingsoft.cms.biz.IContentBiz
;
import
java.util.List
;
import
net.mingsoft.cms.dao.IContentDao
;
import
java.util.Map
;
/**
/**
* 文章管理持久化层
* 文章管理持久化层
...
@@ -58,20 +43,11 @@ import net.mingsoft.cms.dao.IContentDao;
...
@@ -58,20 +43,11 @@ import net.mingsoft.cms.dao.IContentDao;
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
@Service
(
"cmscontentBizImpl"
)
@Service
(
"cmscontentBizImpl"
)
public
class
ContentBizImpl
extends
BaseBizImpl
implements
IContentBiz
{
public
class
ContentBizImpl
extends
BaseBizImpl
<
IContentDao
,
ContentEntity
>
implements
IContentBiz
{
/*
* log4j日志记录
*/
protected
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
@Autowired
@Autowired
private
IContentDao
contentDao
;
private
IContentDao
contentDao
;
/**
* 栏目管理业务层
*/
@Autowired
private
ICategoryDao
categoryDao
;
@Override
@Override
...
@@ -93,152 +69,4 @@ public class ContentBizImpl extends BaseBizImpl implements IContentBiz {
...
@@ -93,152 +69,4 @@ public class ContentBizImpl extends BaseBizImpl implements IContentBiz {
}
}
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
;
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/cms/dao/ICategoryDao.java
View file @
4682b0ca
package
net.mingsoft.cms.dao
;
package
net.mingsoft.cms.dao
;
import
net.mingsoft.base.dao.IBaseDao
;
import
net.mingsoft.base.dao.IBaseDao
;
import
java.util.*
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
net.mingsoft.cms.entity.CategoryEntity
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
/**
* 分类持久层
* 分类持久层
* @author 铭飞开发团队
* @author 铭飞开发团队
...
@@ -14,13 +13,13 @@ import org.springframework.stereotype.Component;
...
@@ -14,13 +13,13 @@ import org.springframework.stereotype.Component;
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
@Component
(
"cmsCategoryDao"
)
@Component
(
"cmsCategoryDao"
)
public
interface
ICategoryDao
extends
IBaseDao
{
public
interface
ICategoryDao
extends
IBaseDao
<
CategoryEntity
>
{
/**
/**
* 查询当前分类下面的所有子分类
* 查询当前分类下面的所有子分类
* @param category 必须存在categoryId categoryParentId
* @param category 必须存在categoryId categoryParentId
* @return
* @return
*/
*/
public
List
<
net
.
mingsoft
.
cms
.
entity
.
CategoryEntity
>
queryChildren
(
CategoryEntity
category
);
public
List
<
CategoryEntity
>
queryChildren
(
CategoryEntity
category
);
}
}
\ No newline at end of file
src/main/java/net/mingsoft/cms/dao/IContentDao.java
View file @
4682b0ca
package
net.mingsoft.cms.dao
;
package
net.mingsoft.cms.dao
;
import
net.mingsoft.base.dao.IBaseDao
;
import
net.mingsoft.base.dao.IBaseDao
;
import
java.util.*
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.CategoryBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.bean.ContentBean
;
import
net.mingsoft.cms.entity.ContentEntity
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* 文章持久层
* 文章持久层
* @author 铭飞开发团队
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
public
interface
IContentDao
extends
IBaseDao
{
public
interface
IContentDao
extends
IBaseDao
<
ContentEntity
>
{
/**
/**
* 查询文章编号集合
* 查询文章编号集合
...
@@ -32,7 +34,7 @@ public interface IContentDao extends IBaseDao {
...
@@ -32,7 +34,7 @@ public interface IContentDao extends IBaseDao {
* list[2]:是否是等值查询 list[3]:字段的值
* list[2]:是否是等值查询 list[3]:字段的值
* @return 文章实体总数
* @return 文章实体总数
*/
*/
int
getSearchCount
(
@Param
(
"tableName"
)
String
tableName
,
@Param
(
"diyList"
)
List
diyList
,
@Param
(
"map"
)
Map
<
String
,
Object
>
map
,
int
getSearchCount
(
@Param
(
"tableName"
)
String
tableName
,
@Param
(
"diyList"
)
List
diyList
,
@Param
(
"map"
)
Map
<
String
,
Object
>
map
,
@Param
(
"websiteId"
)
int
websiteId
,
@Param
(
"ids"
)
String
ids
);
@Param
(
"websiteId"
)
int
websiteId
,
@Param
(
"ids"
)
String
ids
);
/**
/**
...
...
src/main/java/net/mingsoft/cms/dao/IContentDao.xml
View file @
4682b0ca
...
@@ -245,7 +245,7 @@
...
@@ -245,7 +245,7 @@
<if
test=
"updateBy > 0"
>
and ct.update_by=#{updateBy}
</if>
<if
test=
"updateBy > 0"
>
and ct.update_by=#{updateBy}
</if>
<if
test=
"updateDate != null"
>
and update_date=#{updateDate}
</if>
<if
test=
"updateDate != null"
>
and update_date=#{updateDate}
</if>
</where>
</where>
)ct ORDER BY
date_format(
ct.content_datetime
,'%Y-%m-%d')
desc,content_sort desc
)ct ORDER BY ct.content_datetime desc,content_sort desc
</select>
</select>
<sql
id=
"queryWhereCategoryId"
databaseId=
"mysql"
>
<sql
id=
"queryWhereCategoryId"
databaseId=
"mysql"
>
...
...
src/main/java/net/mingsoft/cms/entity/CategoryEntity.java
View file @
4682b0ca
...
@@ -4,16 +4,20 @@ import cn.hutool.core.util.StrUtil;
...
@@ -4,16 +4,20 @@ import cn.hutool.core.util.StrUtil;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
net.mingsoft.base.entity.BaseEntity
;
import
net.mingsoft.base.entity.BaseEntity
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
* 分类实体
* 分类实体
* @author 铭飞开发团队
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
@TableName
(
"cms_category"
)
public
class
CategoryEntity
extends
BaseEntity
{
public
class
CategoryEntity
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1574925152750L
;
private
static
final
long
serialVersionUID
=
1574925152750L
;
...
@@ -98,6 +102,31 @@ private static final long serialVersionUID = 1574925152750L;
...
@@ -98,6 +102,31 @@ private static final long serialVersionUID = 1574925152750L;
*/
*/
private
String
categoryParentId
;
private
String
categoryParentId
;
/**
* 叶子节点
*/
private
Boolean
leaf
;
/**
* 顶级id
*/
private
String
topId
;
public
Boolean
getLeaf
()
{
return
leaf
;
}
public
void
setLeaf
(
Boolean
leaf
)
{
this
.
leaf
=
leaf
;
}
public
String
getTopId
()
{
return
topId
;
}
public
void
setTopId
(
String
topId
)
{
this
.
topId
=
topId
;
}
/**
/**
* 设置栏目管理名称
* 设置栏目管理名称
...
@@ -395,6 +424,14 @@ private static final long serialVersionUID = 1574925152750L;
...
@@ -395,6 +424,14 @@ private static final long serialVersionUID = 1574925152750L;
* 获取栏目图片 (标签使用)
* 获取栏目图片 (标签使用)
*/
*/
public
String
getTypelitpic
()
{
public
String
getTypelitpic
()
{
return
categoryImg
;
if
(
StrUtil
.
isNotBlank
(
categoryImg
)){
try
{
JSONArray
objects
=
JSON
.
parseArray
(
categoryImg
);
return
objects
.
getJSONObject
(
0
).
getString
(
"path"
);
}
catch
(
Exception
e
){
}
}
return
""
;
}
}
}
}
src/main/java/net/mingsoft/cms/entity/ContentEntity.java
View file @
4682b0ca
package
net.mingsoft.cms.entity
;
package
net.mingsoft.cms.entity
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
net.mingsoft.base.entity.BaseEntity
;
import
net.mingsoft.base.entity.BaseEntity
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
* 文章实体
* 文章实体
* @author 铭飞开发团队
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
* 历史修订:<br/>
*/
*/
@TableName
(
"cms_content"
)
public
class
ContentEntity
extends
BaseEntity
{
public
class
ContentEntity
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1574925152617L
;
private
static
final
long
serialVersionUID
=
1574925152617L
;
...
...
src/main/java/net/mingsoft/cms/util/CmsParserUtil.java
View file @
4682b0ca
...
@@ -7,7 +7,6 @@ import freemarker.core.ParseException;
...
@@ -7,7 +7,6 @@ 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
;
...
@@ -161,15 +160,15 @@ public class CmsParserUtil extends ParserUtil {
...
@@ -161,15 +160,15 @@ public class CmsParserUtil extends ParserUtil {
Map
<
Object
,
Object
>
contentModelMap
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Object
>
contentModelMap
=
new
HashMap
<
Object
,
Object
>();
ModelEntity
contentModel
=
null
;
ModelEntity
contentModel
=
null
;
// 记录已经生成了文章编号
// 记录已经生成了文章编号
List
<
Integer
>
generateIds
=
new
ArrayList
<>();
List
<
String
>
generateIds
=
new
ArrayList
<>();
ExecutorService
pool
=
SpringUtil
.
getBean
(
ExecutorService
.
class
);
ExecutorService
pool
=
SpringUtil
.
getBean
(
ExecutorService
.
class
);
// 生成文章
// 生成文章
for
(
int
artId
=
0
;
artId
<
articleIdList
.
size
();)
{
for
(
int
artId
=
0
;
artId
<
articleIdList
.
size
();)
{
String
writePath
=
null
;
String
writePath
=
null
;
//设置分页类
//设置分页类
PageBean
page
=
new
PageBean
();
PageBean
page
=
new
PageBean
();
// 文章编号
// 文章编号
in
t
articleId
=
articleIdList
.
get
(
artId
).
getArticleId
();
Str
in
g
articleId
=
articleIdList
.
get
(
artId
).
getArticleId
();
// 文章的栏目路径
// 文章的栏目路径
String
articleColumnPath
=
articleIdList
.
get
(
artId
).
getCategoryPath
();
String
articleColumnPath
=
articleIdList
.
get
(
artId
).
getCategoryPath
();
// 该文章相关分类
// 该文章相关分类
...
@@ -245,12 +244,10 @@ public class CmsParserUtil extends ParserUtil {
...
@@ -245,12 +244,10 @@ public class CmsParserUtil extends ParserUtil {
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
();
Integer
appId
=
(
Integer
)
DataHolder
.
get
(
"appId"
);
pool
.
execute
(()
->
{
pool
.
execute
(()
->
{
String
content
=
null
;
String
content
=
null
;
try
{
try
{
SpringUtil
.
setRequest
(
request
);
SpringUtil
.
setRequest
(
request
);
DataHolder
.
set
(
"appId"
,
appId
);
content
=
CmsParserUtil
.
generate
(
columnUrl
,
cloneMap
);
content
=
CmsParserUtil
.
generate
(
columnUrl
,
cloneMap
);
FileUtil
.
writeString
(
content
,
finalWritePath
,
Const
.
UTF8
);
FileUtil
.
writeString
(
content
,
finalWritePath
,
Const
.
UTF8
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
...
src/main/java/net/mingsoft/config/WebConfig.java
View file @
4682b0ca
package
net.mingsoft.config
;
package
net.mingsoft.config
;
import
java.io.File
;
import
java.io.File
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.*
;
import
java.util.concurrent.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
import
com.baomidou.mybatisplus.extension.toolkit.JdbcUtils
;
import
net.mingsoft.interceptor.DMInnerInterceptor
;
import
net.mingsoft.interceptor.MysqlInnerInterceptor
;
import
org.springframework.aop.Advisor
;
import
org.springframework.aop.Advisor
;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
org.springframework.aop.support.DefaultPointcutAdvisor
;
import
org.springframework.aop.support.DefaultPointcutAdvisor
;
...
@@ -37,6 +43,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
...
@@ -37,6 +43,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
net.mingsoft.basic.interceptor.ActionInterceptor
;
import
net.mingsoft.basic.interceptor.ActionInterceptor
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.mingsoft.basic.util.BasicUtil
;
import
javax.sql.DataSource
;
@Configuration
@Configuration
public
class
WebConfig
implements
WebMvcConfigurer
{
public
class
WebConfig
implements
WebMvcConfigurer
{
...
@@ -59,6 +67,23 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -59,6 +67,23 @@ public class WebConfig implements WebMvcConfigurer {
}
}
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
(
DataSource
dataSource
)
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
try
{
//mysql 添加转换sql
DbType
dbType
=
JdbcUtils
.
getDbType
(
dataSource
.
getConnection
().
getMetaData
().
getURL
());
if
(
DbType
.
MYSQL
==
dbType
){
interceptor
.
addInnerInterceptor
(
new
MysqlInnerInterceptor
());
}
else
if
(
DbType
.
DM
==
dbType
){
interceptor
.
addInnerInterceptor
(
new
DMInnerInterceptor
());
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
interceptor
;
}
/**
/**
* 增加对rest api鉴权的spring mvc拦截器
* 增加对rest api鉴权的spring mvc拦截器
*/
*/
...
...
src/main/java/net/mingsoft/interceptor/DMInnerInterceptor.java
0 → 100644
View file @
4682b0ca
package
net.mingsoft.interceptor
;
import
com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper
;
import
com.baomidou.mybatisplus.core.toolkit.PluginUtils
;
import
com.baomidou.mybatisplus.core.toolkit.TableNameParser
;
import
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlCommandType
;
import
org.apache.ibatis.session.ResultHandler
;
import
org.apache.ibatis.session.RowBounds
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DMInnerInterceptor
implements
InnerInterceptor
{
@Override
public
void
beforeQuery
(
Executor
executor
,
MappedStatement
ms
,
Object
parameter
,
RowBounds
rowBounds
,
ResultHandler
resultHandler
,
BoundSql
boundSql
)
throws
SQLException
{
PluginUtils
.
MPBoundSql
mpBs
=
PluginUtils
.
mpBoundSql
(
boundSql
);
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
mpBs
.
sql
(
this
.
changeTable
(
mpBs
.
sql
()));
}
@Override
public
void
beforePrepare
(
StatementHandler
sh
,
Connection
connection
,
Integer
transactionTimeout
)
{
PluginUtils
.
MPStatementHandler
mpSh
=
PluginUtils
.
mpStatementHandler
(
sh
);
MappedStatement
ms
=
mpSh
.
mappedStatement
();
SqlCommandType
sct
=
ms
.
getSqlCommandType
();
if
(
sct
==
SqlCommandType
.
INSERT
||
sct
==
SqlCommandType
.
UPDATE
||
sct
==
SqlCommandType
.
DELETE
)
{
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
PluginUtils
.
MPBoundSql
mpBs
=
mpSh
.
mPBoundSql
();
mpBs
.
sql
(
this
.
changeTable
(
mpBs
.
sql
()));
}
}
protected
String
changeTable
(
String
sql
)
{
TableNameParser
parser
=
new
TableNameParser
(
sql
);
List
<
TableNameParser
.
SqlToken
>
names
=
new
ArrayList
<>();
parser
.
accept
(
names:
:
add
);
StringBuilder
builder
=
new
StringBuilder
();
int
last
=
0
;
for
(
TableNameParser
.
SqlToken
name
:
names
)
{
int
start
=
name
.
getStart
();
if
(
start
!=
last
)
{
builder
.
append
(
sql
,
last
,
start
);
String
value
=
name
.
getValue
();
builder
.
append
(
String
.
format
(
"\"%s\""
,
value
));
}
last
=
name
.
getEnd
();
}
if
(
last
!=
sql
.
length
())
{
builder
.
append
(
sql
.
substring
(
last
));
}
return
builder
.
toString
();
}
}
src/main/java/net/mingsoft/interceptor/MysqlInnerInterceptor.java
0 → 100644
View file @
4682b0ca
package
net.mingsoft.interceptor
;
import
com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper
;
import
com.baomidou.mybatisplus.core.toolkit.PluginUtils
;
import
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlCommandType
;
import
org.apache.ibatis.session.ResultHandler
;
import
org.apache.ibatis.session.RowBounds
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
/**
* Mysql 适配通用拦截器,主要处理不支持的sql语句
*/
public
class
MysqlInnerInterceptor
implements
InnerInterceptor
{
@Override
public
void
beforeQuery
(
Executor
executor
,
MappedStatement
ms
,
Object
parameter
,
RowBounds
rowBounds
,
ResultHandler
resultHandler
,
BoundSql
boundSql
)
throws
SQLException
{
PluginUtils
.
MPBoundSql
mpBs
=
PluginUtils
.
mpBoundSql
(
boundSql
);
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
mpBs
.
sql
(
this
.
changeSql
(
mpBs
.
sql
()));
}
@Override
public
void
beforePrepare
(
StatementHandler
sh
,
Connection
connection
,
Integer
transactionTimeout
)
{
PluginUtils
.
MPStatementHandler
mpSh
=
PluginUtils
.
mpStatementHandler
(
sh
);
MappedStatement
ms
=
mpSh
.
mappedStatement
();
SqlCommandType
sct
=
ms
.
getSqlCommandType
();
if
(
sct
==
SqlCommandType
.
INSERT
||
sct
==
SqlCommandType
.
UPDATE
||
sct
==
SqlCommandType
.
DELETE
)
{
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
PluginUtils
.
MPBoundSql
mpBs
=
mpSh
.
mPBoundSql
();
mpBs
.
sql
(
this
.
changeSql
(
mpBs
.
sql
()));
}
}
protected
String
changeSql
(
String
sql
)
{
//替换所有"为`
return
sql
.
replaceAll
(
"\""
,
"`"
);
}
}
Prev
1
2
Next
Write
Preview
Supports
Markdown
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