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
JeeSpringCloud
Commits
44ad5f47
"eladmin-common/src/git@ustchcs.com:gujinli1118/eladmin.git" did not exist on "76b600eeccc40a561d1a9278134ab9a806f2f9e3"
Commit
44ad5f47
authored
Oct 22, 2018
by
HuangBingGui
Browse files
no commit message
parent
7fa8137a
Changes
41
Hide whitespace changes
Inline
Side-by-side
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/service/FileTplService.java
0 → 100644
View file @
44ad5f47
package
com.jeespring.modules.cms.service
;
import
com.jeespring.modules.cms.entity.FileTpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.ServletContext
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* User: songlai
* Date: 13-8-27
* Time: 下午4:56
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
FileTplService
{
@Autowired
ServletContext
context
;
public
List
<
String
>
getNameListByPrefix
(
String
path
)
{
List
<
FileTpl
>
list
=
getListByPath
(
path
,
false
);
List
<
String
>
result
=
new
ArrayList
<
String
>(
list
.
size
());
for
(
FileTpl
tpl
:
list
)
{
result
.
add
(
tpl
.
getName
());
}
return
result
;
}
public
List
<
FileTpl
>
getListByPath
(
String
path
,
boolean
directory
)
{
File
f
=
new
File
(
context
.
getRealPath
(
path
));
if
(
f
.
exists
())
{
File
[]
files
=
f
.
listFiles
();
if
(
files
!=
null
)
{
List
<
FileTpl
>
list
=
new
ArrayList
<
FileTpl
>();
for
(
File
file
:
files
)
{
if
(
file
.
isFile
()
||
directory
)
{
list
.
add
(
new
FileTpl
(
file
,
context
.
getRealPath
(
""
)));
}
}
return
list
;
}
else
{
return
new
ArrayList
<
FileTpl
>(
0
);
}
}
else
{
return
new
ArrayList
<
FileTpl
>(
0
);
}
}
public
List
<
FileTpl
>
getListForEdit
(
String
path
){
List
<
FileTpl
>
list
=
getListByPath
(
path
,
true
);
List
<
FileTpl
>
result
=
new
ArrayList
<
FileTpl
>();
result
.
add
(
new
FileTpl
(
new
File
(
context
.
getRealPath
(
path
)),
context
.
getRealPath
(
""
)));
getAllDirectory
(
result
,
list
);
return
result
;
}
private
void
getAllDirectory
(
List
<
FileTpl
>
result
,
List
<
FileTpl
>
list
){
for
(
FileTpl
tpl
:
list
)
{
result
.
add
(
tpl
);
if
(
tpl
.
isDirectory
()){
getAllDirectory
(
result
,
getListByPath
(
tpl
.
getName
(),
true
));
}
}
}
public
FileTpl
getFileTpl
(
String
name
)
{
File
f
=
new
File
(
context
.
getRealPath
(
name
));
if
(
f
.
exists
())
{
return
new
FileTpl
(
f
,
""
);
}
else
{
return
null
;
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/service/GuestbookService.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.cms.dao.GuestbookDao
;
import
com.jeespring.modules.cms.entity.Guestbook
;
/**
* 留言Service
* @author JeeSpring
* @version 2013-01-15
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
GuestbookService
extends
AbstractBaseService
<
GuestbookDao
,
Guestbook
>
{
@Override
public
Guestbook
get
(
String
id
)
{
return
dao
.
get
(
id
);
}
@Override
public
Page
<
Guestbook
>
findPage
(
Page
<
Guestbook
>
page
,
Guestbook
guestbook
)
{
// DetachedCriteria dc = dao.createDetachedCriteria();
// if (StringUtils.isNotEmpty(guestbook.getType())){
// dc.add(Restrictions.eq("type", guestbook.getType()));
// }
// if (StringUtils.isNotEmpty(guestbook.getContent())){
// dc.add(Restrictions.like("content", "%"+guestbook.getContent()+"%"));
// }
// dc.add(Restrictions.eq(Guestbook.FIELD_DEL_FLAG, guestbook.getDelFlag()));
// dc.addOrder(Order.desc("createDate"));
// return dao.find(page, dc);
guestbook
.
getSqlMap
().
put
(
"dsf"
,
dataScopeFilter
(
guestbook
.
getCurrentUser
(),
"o"
,
"u"
));
guestbook
.
setPage
(
page
);
page
.
setList
(
dao
.
findList
(
guestbook
));
return
page
;
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Guestbook
guestbook
,
Boolean
isRe
)
{
//dao.updateDelFlag(id, isRe!=null&&isRe?Guestbook.DEL_FLAG_AUDIT:Guestbook.DEL_FLAG_DELETE);
dao
.
delete
(
guestbook
);
}
/**
* 更新索引
*/
public
void
createIndex
(){
//dao.createIndex();
}
/**
* 全文检索
*/
//FIXME 暂不提供
public
Page
<
Guestbook
>
search
(
Page
<
Guestbook
>
page
,
String
q
,
String
beginDate
,
String
endDate
){
// 设置查询条件
// BooleanQuery query = dao.getFullTextQuery(q, "name","content","reContent");
//
// // 设置过滤条件
// List<BooleanClause> bcList = Lists.newArrayList();
//
// bcList.add(new BooleanClause(new TermQuery(new Term(Guestbook.FIELD_DEL_FLAG, Guestbook.DEL_FLAG_NORMAL)), Occur.MUST));
//
// if (StringUtils.isNotBlank(beginDate) && StringUtils.isNotBlank(endDate)) {
// bcList.add(new BooleanClause(new TermRangeQuery("createDate", beginDate.replaceAll("-", ""),
// endDate.replaceAll("-", ""), true, true), Occur.MUST));
// }
//
// bcList.add(new BooleanClause(new TermQuery(new Term("type", "1")), Occur.SHOULD));
// bcList.add(new BooleanClause(new TermQuery(new Term("type", "2")), Occur.SHOULD));
// bcList.add(new BooleanClause(new TermQuery(new Term("type", "3")), Occur.SHOULD));
// bcList.add(new BooleanClause(new TermQuery(new Term("type", "4")), Occur.SHOULD));
//
// BooleanQuery queryFilter = dao.getFullTextQuery((BooleanClause[])bcList.toArray(new BooleanClause[bcList.size()]));
//
// System.out.println(queryFilter);
//
// // 设置排序(默认相识度排序)
// Sort sort = null;//new Sort(new SortField("updateDate", SortField.DOC, true));
// // 全文检索
// dao.search(page, query, queryFilter, sort);
// // 关键字高亮
// dao.keywordsHighlight(query, page.getList(), 30, "name");
// dao.keywordsHighlight(query, page.getList(), 1300, "content");
// dao.keywordsHighlight(query, page.getList(), 1300, "reContent");
return
page
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/service/LinkService.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.service
;
import
java.util.Date
;
import
java.util.List
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.cms.dao.LinkDao
;
import
com.jeespring.modules.cms.entity.Link
;
/**
* 链接Service
* @author JeeSpring
* @version 2013-01-15
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
LinkService
extends
AbstractBaseService
<
LinkDao
,
Link
>
{
@Transactional
(
readOnly
=
false
)
public
Page
<
Link
>
findPage
(
Page
<
Link
>
page
,
Link
link
,
boolean
isDataScopeFilter
)
{
// 更新过期的权重,间隔为“6”个小时
Date
updateExpiredWeightDate
=
(
Date
)
CacheUtils
.
get
(
"updateExpiredWeightDateByLink"
);
if
(
updateExpiredWeightDate
==
null
||
(
updateExpiredWeightDate
!=
null
&&
updateExpiredWeightDate
.
getTime
()
<
new
Date
().
getTime
())){
dao
.
updateExpiredWeight
(
link
);
CacheUtils
.
put
(
"updateExpiredWeightDateByLink"
,
DateUtils
.
addHours
(
new
Date
(),
6
));
}
link
.
getSqlMap
().
put
(
"dsf"
,
dataScopeFilter
(
link
.
getCurrentUser
(),
"o"
,
"u"
));
return
super
.
findPage
(
page
,
link
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Link
link
,
Boolean
isRe
)
{
//dao.updateDelFlag(id, isRe!=null&&isRe?Link.DEL_FLAG_NORMAL:Link.DEL_FLAG_DELETE);
link
.
setDelFlag
(
isRe
!=
null
&&
isRe
?
Link
.
DEL_FLAG_NORMAL
:
Link
.
DEL_FLAG_DELETE
);
dao
.
delete
(
link
);
}
/**
* 通过编号获取内容标题
*/
public
List
<
Object
[]>
findByIds
(
String
ids
)
{
List
<
Object
[]>
list
=
Lists
.
newArrayList
();
String
[]
idss
=
StringUtils
.
split
(
ids
,
","
);
if
(
idss
.
length
>
0
){
List
<
Link
>
l
=
dao
.
findByIdIn
(
idss
);
for
(
Link
e
:
l
){
list
.
add
(
new
Object
[]{
e
.
getId
(),
StringUtils
.
abbr
(
e
.
getTitle
(),
50
)});
}
}
return
list
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/service/SiteService.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.service
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.cms.dao.SiteDao
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.utils.CmsUtils
;
/**
* 站点Service
* @author JeeSpring
* @version 2013-01-15
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SiteService
extends
AbstractBaseService
<
SiteDao
,
Site
>
{
@Override
public
Page
<
Site
>
findPage
(
Page
<
Site
>
page
,
Site
site
)
{
// DetachedCriteria dc = siteDao.createDetachedCriteria();
// if (StringUtils.isNotEmpty(site.getName())){
// dc.add(Restrictions.like("name", "%"+site.getName()+"%"));
// }
// dc.add(Restrictions.eq(Site.FIELD_DEL_FLAG, site.getDelFlag()));
// //dc.addOrder(Order.asc("id"));
// return siteDao.find(page, dc);
site
.
getSqlMap
().
put
(
"site"
,
dataScopeFilter
(
site
.
getCurrentUser
(),
"o"
,
"u"
));
return
super
.
findPage
(
page
,
site
);
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
save
(
Site
site
)
{
if
(
site
.
getCopyright
()!=
null
){
site
.
setCopyright
(
StringEscapeUtils
.
unescapeHtml4
(
site
.
getCopyright
()));
}
super
.
save
(
site
);
CmsUtils
.
removeCache
(
"site_"
+
site
.
getId
());
CmsUtils
.
removeCache
(
"siteList"
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Site
site
,
Boolean
isRe
)
{
//siteDao.updateDelFlag(id, isRe!=null&&isRe?Site.DEL_FLAG_NORMAL:Site.DEL_FLAG_DELETE);
site
.
setDelFlag
(
isRe
!=
null
&&
isRe
?
Site
.
DEL_FLAG_NORMAL
:
Site
.
DEL_FLAG_DELETE
);
super
.
delete
(
site
);
//siteDao.delete(id);
CmsUtils
.
removeCache
(
"site_"
+
site
.
getId
());
CmsUtils
.
removeCache
(
"siteList"
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/service/StatsService.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.service.AbstractService
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.modules.cms.dao.ArticleDao
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.sys.entity.Office
;
/**
* 统计Service
* @author JeeSpring
* @version 2013-05-21
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
StatsService
extends
AbstractService
{
@Autowired
private
ArticleDao
articleDao
;
public
List
<
Category
>
article
(
Map
<
String
,
Object
>
paramMap
)
{
Category
category
=
new
Category
();
Site
site
=
new
Site
();
site
.
setId
(
Site
.
getCurrentSiteId
());
category
.
setSite
(
site
);
Date
beginDate
=
DateUtils
.
parseDate
(
paramMap
.
get
(
"beginDate"
));
if
(
beginDate
==
null
){
beginDate
=
DateUtils
.
setDays
(
new
Date
(),
1
);
paramMap
.
put
(
"beginDate"
,
DateUtils
.
formatDate
(
beginDate
,
"yyyy-MM-dd"
));
}
category
.
setBeginDate
(
beginDate
);
Date
endDate
=
DateUtils
.
parseDate
(
paramMap
.
get
(
"endDate"
));
if
(
endDate
==
null
){
endDate
=
DateUtils
.
addDays
(
DateUtils
.
addMonths
(
beginDate
,
1
),
-
1
);
paramMap
.
put
(
"endDate"
,
DateUtils
.
formatDate
(
endDate
,
"yyyy-MM-dd"
));
}
category
.
setEndDate
(
endDate
);
String
categoryId
=
(
String
)
paramMap
.
get
(
"categoryId"
);
if
(
categoryId
!=
null
&&
!(
""
.
equals
(
categoryId
))){
category
.
setId
(
categoryId
);
category
.
setParentIds
(
categoryId
);
}
String
officeId
=
(
String
)(
paramMap
.
get
(
"officeId"
));
Office
office
=
new
Office
();
if
(
officeId
!=
null
&&
!(
""
.
equals
(
officeId
))){
office
.
setId
(
officeId
);
category
.
setOffice
(
office
);
}
else
{
category
.
setOffice
(
office
);
}
List
<
Category
>
list
=
articleDao
.
findStats
(
category
);
return
list
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/utils/CmsUtils.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.utils
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.mapper.JsonMapper
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.utils.SpringContextHolder
;
import
com.jeespring.modules.cms.entity.Article
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.entity.Link
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.ArticleService
;
import
com.jeespring.modules.cms.service.CategoryService
;
import
com.jeespring.modules.cms.service.LinkService
;
import
com.jeespring.modules.cms.service.SiteService
;
import
javax.servlet.ServletContext
;
import
org.springframework.ui.Model
;
/**
* 内容管理工具类
* @author JeeSpring
* @version 2013-5-29
*/
public
class
CmsUtils
{
private
static
SiteService
siteService
=
SpringContextHolder
.
getBean
(
SiteService
.
class
);
private
static
CategoryService
categoryService
=
SpringContextHolder
.
getBean
(
CategoryService
.
class
);
private
static
ArticleService
articleService
=
SpringContextHolder
.
getBean
(
ArticleService
.
class
);
private
static
LinkService
linkService
=
SpringContextHolder
.
getBean
(
LinkService
.
class
);
private
static
ServletContext
context
=
SpringContextHolder
.
getBean
(
ServletContext
.
class
);
private
static
final
String
CMS_CACHE
=
"cmsCache"
;
/**
* 获得站点列表
*/
public
static
List
<
Site
>
getSiteList
(){
@SuppressWarnings
(
"unchecked"
)
List
<
Site
>
siteList
=
(
List
<
Site
>)
CacheUtils
.
get
(
CMS_CACHE
,
"siteList"
);
if
(
siteList
==
null
){
Page
<
Site
>
page
=
new
Page
<
Site
>(
1
,
-
1
);
page
=
siteService
.
findPage
(
page
,
new
Site
());
siteList
=
page
.
getList
();
CacheUtils
.
put
(
CMS_CACHE
,
"siteList"
,
siteList
);
}
return
siteList
;
}
/**
* 获得站点信息
* @param siteId 站点编号
*/
public
static
Site
getSite
(
String
siteId
){
String
id
=
"1"
;
if
(
StringUtils
.
isNotBlank
(
siteId
)){
id
=
siteId
;
}
for
(
Site
site
:
getSiteList
()){
if
(
site
.
getId
().
equals
(
id
)){
return
site
;
}
}
return
new
Site
(
id
);
}
/**
* 获得主导航列表
* @param siteId 站点编号
*/
public
static
List
<
Category
>
getMainNavList
(
String
siteId
){
@SuppressWarnings
(
"unchecked"
)
List
<
Category
>
mainNavList
=
(
List
<
Category
>)
CacheUtils
.
get
(
CMS_CACHE
,
"mainNavList_"
+
siteId
);
if
(
mainNavList
==
null
){
Category
category
=
new
Category
();
category
.
setSite
(
new
Site
(
siteId
));
category
.
setParent
(
new
Category
(
"1"
));
category
.
setInMenu
(
Global
.
SHOW
);
Page
<
Category
>
page
=
new
Page
<
Category
>(
1
,
-
1
);
page
=
categoryService
.
find
(
page
,
category
);
mainNavList
=
page
.
getList
();
CacheUtils
.
put
(
CMS_CACHE
,
"mainNavList_"
+
siteId
,
mainNavList
);
}
return
mainNavList
;
}
/**
* 获取栏目
* @param categoryId 栏目编号
* @return
*/
public
static
Category
getCategory
(
String
categoryId
){
return
categoryService
.
get
(
categoryId
);
}
/**
* 获得栏目列表
* @param siteId 站点编号
* @param parentId 分类父编号
* @param number 获取数目
* @param param 预留参数,例: key1:'value1', key2:'value2' ...
*/
public
static
List
<
Category
>
getCategoryList
(
String
siteId
,
String
parentId
,
int
number
,
String
param
){
Page
<
Category
>
page
=
new
Page
<
Category
>(
1
,
number
,
-
1
);
Category
category
=
new
Category
();
category
.
setSite
(
new
Site
(
siteId
));
category
.
setParent
(
new
Category
(
parentId
));
if
(
StringUtils
.
isNotBlank
(
param
)){
@SuppressWarnings
({
"unused"
,
"rawtypes"
})
Map
map
=
JsonMapper
.
getInstance
().
fromJson
(
"{"
+
param
+
"}"
,
Map
.
class
);
}
page
=
categoryService
.
find
(
page
,
category
);
return
page
.
getList
();
}
/**
* 获取栏目
* @param categoryIds 栏目编号
* @return
*/
public
static
List
<
Category
>
getCategoryListByIds
(
String
categoryIds
){
return
categoryService
.
findByIds
(
categoryIds
);
}
/**
* 获取文章
* @param articleId 文章编号
* @return
*/
public
static
Article
getArticle
(
String
articleId
){
return
articleService
.
get
(
articleId
);
}
/**
* 获取文章列表
* @param siteId 站点编号
* @param categoryId 分类编号
* @param number 获取数目
* @param param 预留参数,例: key1:'value1', key2:'value2' ...
* posid 推荐位(1:首页焦点图;2:栏目页文章推荐;)
* image 文章图片(1:有图片的文章)
* orderBy 排序字符串
* @return
* ${fnc:getArticleList(category.site.id, category.id, not empty pageSize?pageSize:8, 'posid:2, orderBy: \"hits desc\"')}"
*/
public
static
List
<
Article
>
getArticleList
(
String
siteId
,
String
categoryId
,
int
number
,
String
param
){
Page
<
Article
>
page
=
new
Page
<
Article
>(
1
,
number
,
-
1
);
Category
category
=
new
Category
(
categoryId
,
new
Site
(
siteId
));
category
.
setParentIds
(
categoryId
);
Article
article
=
new
Article
(
category
);
if
(
StringUtils
.
isNotBlank
(
param
)){
@SuppressWarnings
({
"rawtypes"
})
Map
map
=
JsonMapper
.
getInstance
().
fromJson
(
"{"
+
param
+
"}"
,
Map
.
class
);
if
(
new
Integer
(
1
).
equals
(
map
.
get
(
"posid"
))
||
new
Integer
(
2
).
equals
(
map
.
get
(
"posid"
))){
article
.
setPosid
(
String
.
valueOf
(
map
.
get
(
"posid"
)));
}
if
(
new
Integer
(
1
).
equals
(
map
.
get
(
"image"
))){
article
.
setImage
(
Global
.
YES
);
}
if
(
StringUtils
.
isNotBlank
((
String
)
map
.
get
(
"orderBy"
))){
page
.
setOrderBy
((
String
)
map
.
get
(
"orderBy"
));
}
}
article
.
setDelFlag
(
Article
.
DEL_FLAG_NORMAL
);
page
=
articleService
.
findPage
(
page
,
article
,
false
);
return
page
.
getList
();
}
/**
* 获取链接
* @param linkId 文章编号
* @return
*/
public
static
Link
getLink
(
String
linkId
){
return
linkService
.
get
(
linkId
);
}
/**
* 获取链接列表
* @param siteId 站点编号
* @param categoryId 分类编号
* @param number 获取数目
* @param param 预留参数,例: key1:'value1', key2:'value2' ...
* @return
*/
public
static
List
<
Link
>
getLinkList
(
String
siteId
,
String
categoryId
,
int
number
,
String
param
){
Page
<
Link
>
page
=
new
Page
<
Link
>(
1
,
number
,
-
1
);
Link
link
=
new
Link
(
new
Category
(
categoryId
,
new
Site
(
siteId
)));
if
(
StringUtils
.
isNotBlank
(
param
)){
@SuppressWarnings
({
"unused"
,
"rawtypes"
})
Map
map
=
JsonMapper
.
getInstance
().
fromJson
(
"{"
+
param
+
"}"
,
Map
.
class
);
}
link
.
setDelFlag
(
Link
.
DEL_FLAG_NORMAL
);
page
=
linkService
.
findPage
(
page
,
link
,
false
);
return
page
.
getList
();
}
// ============== Cms Cache ==============
public
static
Object
getCache
(
String
key
)
{
return
CacheUtils
.
get
(
CMS_CACHE
,
key
);
}
public
static
void
putCache
(
String
key
,
Object
value
)
{
CacheUtils
.
put
(
CMS_CACHE
,
key
,
value
);
}
public
static
void
removeCache
(
String
key
)
{
CacheUtils
.
remove
(
CMS_CACHE
,
key
);
}
/**
* 获得文章动态URL地址
* @param article
* @return url
*/
public
static
String
getUrlDynamic
(
Article
article
)
{
if
(
StringUtils
.
isNotBlank
(
article
.
getLink
())){
return
article
.
getLink
();
}
StringBuilder
str
=
new
StringBuilder
();
str
.
append
(
context
.
getContextPath
()).
append
(
Global
.
getFrontPath
());
str
.
append
(
"/view-"
).
append
(
article
.
getCategory
().
getId
()).
append
(
"-"
).
append
(
article
.
getId
()).
append
(
Global
.
getUrlSuffix
());
return
str
.
toString
();
}
/**
* 获得栏目动态URL地址
* @param category
* @return url
*/
public
static
String
getUrlDynamic
(
Category
category
)
{
if
(
StringUtils
.
isNotBlank
(
category
.
getHref
())){
if
(!
category
.
getHref
().
contains
(
"://"
)){
return
context
.
getContextPath
()+
Global
.
getFrontPath
()+
category
.
getHref
();
}
else
{
return
category
.
getHref
();
}
}
StringBuilder
str
=
new
StringBuilder
();
str
.
append
(
context
.
getContextPath
()).
append
(
Global
.
getFrontPath
());
str
.
append
(
"/list-"
).
append
(
category
.
getId
()).
append
(
Global
.
getUrlSuffix
());
return
str
.
toString
();
}
/**
* 从图片地址中去除ContextPath地址
* @param src
* @return src
*/
public
static
String
formatImageSrcToDb
(
String
src
)
{
if
(
StringUtils
.
isBlank
(
src
))
{
return
src
;
}
if
(
src
.
startsWith
(
context
.
getContextPath
()
+
"/userfiles"
)){
return
src
.
substring
(
context
.
getContextPath
().
length
());
}
else
{
return
src
;
}
}
/**
* 从图片地址中加入ContextPath地址
* @param src
* @return src
*/
public
static
String
formatImageSrcToWeb
(
String
src
)
{
if
(
StringUtils
.
isBlank
(
src
))
{
return
src
;
}
if
(
src
.
startsWith
(
context
.
getContextPath
()
+
"/userfiles"
)){
return
src
;
}
else
{
return
context
.
getContextPath
()+
src
;
}
}
public
static
void
addViewConfigAttribute
(
Model
model
,
String
param
){
if
(
StringUtils
.
isNotBlank
(
param
)){
@SuppressWarnings
(
"rawtypes"
)
Map
map
=
JsonMapper
.
getInstance
().
fromJson
(
param
,
Map
.
class
);
if
(
map
!=
null
){
for
(
Object
o
:
map
.
keySet
()){
model
.
addAttribute
(
"viewConfig_"
+
o
.
toString
(),
map
.
get
(
o
));
}
}
}
}
public
static
void
addViewConfigAttribute
(
Model
model
,
Category
category
){
List
<
Category
>
categoryList
=
Lists
.
newArrayList
();
Category
c
=
category
;
boolean
goon
=
true
;
do
{
if
(
c
.
getParent
()
==
null
||
c
.
getParent
().
isRoot
()){
goon
=
false
;
}
categoryList
.
add
(
c
);
c
=
c
.
getParent
();
}
while
(
goon
);
Collections
.
reverse
(
categoryList
);
for
(
Category
ca
:
categoryList
){
addViewConfigAttribute
(
model
,
ca
.
getViewConfig
());
}
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/utils/TplUtils.java
0 → 100644
View file @
44ad5f47
package
com.jeespring.modules.cms.utils
;
import
com.jeespring.common.utils.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* User: songlai
* Date: 13-8-22
* Time: 上午10:23
*/
public
class
TplUtils
{
/**
* 去除模板前缀
*
* @param list 模板列表
* @param prefix 模板前缀 例如“frontViewArticle”
* @param include 需包含的模板 例如“/WEB-INF/views/modules/cms/front/themes/jeesite/articleSelectList.jsp”
* @param excludes 需去除的模板 例如“frontViewArticle”
* @return
*/
public
static
List
<
String
>
tplTrim
(
List
<
String
>
list
,
String
prefix
,
String
include
,
String
...
excludes
)
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
if
(!
StringUtils
.
isBlank
(
include
)
&&
!
list
.
contains
(
include
))
{
if
(!
tplContain
(
excludes
,
include
))
{
int
start
=
include
.
lastIndexOf
(
"/"
);
int
end
=
include
.
lastIndexOf
(
"."
);
if
(
start
==
-
1
||
end
==
-
1
)
{
throw
new
RuntimeException
(
"include not contain '/' or '.':"
+
include
);
}
result
.
add
(
include
.
substring
(
start
+
1
,
end
));
}
}
for
(
String
t
:
list
)
{
if
(!
tplContain
(
excludes
,
t
))
{
int
start
=
t
.
lastIndexOf
(
"/"
);
int
end
=
t
.
lastIndexOf
(
"."
);
if
(
start
==
-
1
||
end
==
-
1
)
{
throw
new
RuntimeException
(
"name not contain '/' or '.':"
+
t
);
}
t
=
t
.
substring
(
start
+
1
,
end
);
if
(
t
.
contains
(
prefix
)){
result
.
add
(
t
);
}
}
}
return
result
;
}
/**
* 检查tpl是否存在于excludes里面。
*
* @param excludes
* @param tpl
* @return
*/
private
static
boolean
tplContain
(
String
[]
excludes
,
String
tpl
)
{
int
start
=
tpl
.
lastIndexOf
(
"/"
);
int
end
=
tpl
.
lastIndexOf
(
"."
);
if
(
start
==
-
1
||
end
==
-
1
)
{
throw
new
RuntimeException
(
"tpl not contain '/' or '.':"
+
tpl
);
}
String
name
=
tpl
.
substring
(
start
+
1
,
end
);
for
(
String
e
:
excludes
)
{
if
(
e
.
equals
(
name
))
{
return
true
;
}
}
return
false
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/utils/WiexinSignUtil.java
0 → 100644
View file @
44ad5f47
package
com.jeespring.modules.cms.utils
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Arrays
;
import
org.apache.commons.lang3.StringUtils
;
public
class
WiexinSignUtil
{
// 与接口配置信息中的Token要一致
private
static
String
token
=
"ecjeesitecom"
;
/**
* 验证签名
*
* @param signature
* @param timestamp
* @param nonce
* @return
*/
public
static
boolean
checkSignature
(
String
signature
,
String
timestamp
,
String
nonce
)
{
if
(
StringUtils
.
isNotBlank
(
signature
)
&&
StringUtils
.
isNotBlank
(
timestamp
)
&&
StringUtils
.
isNotBlank
(
nonce
)){
String
[]
arr
=
new
String
[]
{
token
,
timestamp
,
nonce
};
// 将token、timestamp、nonce三个参数进行字典序排序
Arrays
.
sort
(
arr
);
StringBuilder
content
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
content
.
append
(
arr
[
i
]);
}
MessageDigest
md
=
null
;
String
tmpStr
=
null
;
try
{
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
// 将三个参数字符串拼接成一个字符串进行sha1加密
byte
[]
digest
=
md
.
digest
(
content
.
toString
().
getBytes
());
tmpStr
=
byteToStr
(
digest
);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
content
=
null
;
// 将sha1加密后的字符串可与signature对比,标识该请求来源于微信
return
tmpStr
!=
null
?
tmpStr
.
equals
(
signature
.
toUpperCase
())
:
false
;
}
return
false
;
}
/**
* 将字节数组转换为十六进制字符串
*
* @param byteArray
* @return
*/
private
static
String
byteToStr
(
byte
[]
byteArray
)
{
String
strDigest
=
""
;
for
(
int
i
=
0
;
i
<
byteArray
.
length
;
i
++)
{
strDigest
+=
byteToHexStr
(
byteArray
[
i
]);
}
return
strDigest
;
}
/**
* 将字节转换为十六进制字符串
*
* @param mByte
* @return
*/
private
static
String
byteToHexStr
(
byte
mByte
)
{
char
[]
Digit
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
char
[]
tempArr
=
new
char
[
2
];
tempArr
[
0
]
=
Digit
[(
mByte
>>>
4
)
&
0X0F
];
tempArr
[
1
]
=
Digit
[
mByte
&
0X0F
];
String
s
=
new
String
(
tempArr
);
return
s
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/ArticleController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.mapper.JsonMapper
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Article
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.ArticleDataService
;
import
com.jeespring.modules.cms.service.ArticleService
;
import
com.jeespring.modules.cms.service.CategoryService
;
import
com.jeespring.modules.cms.service.FileTplService
;
import
com.jeespring.modules.cms.service.SiteService
;
import
com.jeespring.modules.cms.utils.CmsUtils
;
import
com.jeespring.modules.cms.utils.TplUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 文章Controller
* @author JeeSpring
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/article"
)
public
class
ArticleController
extends
AbstractBaseController
{
@Autowired
private
ArticleService
articleService
;
@Autowired
private
ArticleDataService
articleDataService
;
@Autowired
private
CategoryService
categoryService
;
@Autowired
private
FileTplService
fileTplService
;
@Autowired
private
SiteService
siteService
;
@ModelAttribute
public
Article
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
articleService
.
get
(
id
);
}
else
{
return
new
Article
();
}
}
@RequiresPermissions
(
"cms:article:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Article
article
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
// for (int i=0; i<10000000; i++){
// Article a = new Article();
// a.setCategory(new Category(article.getCategory().getId()));
// a.setTitle("测试测试测试测试测试测试测试测试"+a.getCategory().getId());
// a.setArticleData(new ArticleData());
// a.getArticleData().setContent(a.getTitle());
// articleService.save(a);
// }
Page
<
Article
>
page
=
articleService
.
findPage
(
new
Page
<
Article
>(
request
,
response
),
article
,
true
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/cms/articleList"
;
}
@RequiresPermissions
(
"cms:article:view"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Article
article
,
Model
model
)
{
// 如果当前传参有子节点,则选择取消传参选择
if
(
article
.
getCategory
()!=
null
&&
StringUtils
.
isNotBlank
(
article
.
getCategory
().
getId
())){
List
<
Category
>
list
=
categoryService
.
findByParentId
(
article
.
getCategory
().
getId
(),
Site
.
getCurrentSiteId
());
/*if (list.size() > 0){
article.setCategory(null);
}else{
article.setCategory(categoryService.get(article.getCategory().getId()));
}*/
article
.
setCategory
(
categoryService
.
get
(
article
.
getCategory
().
getId
()));
}
article
.
setArticleData
(
articleDataService
.
get
(
article
.
getId
()));
// if (article.getCategory()=null && StringUtils.isNotBlank(article.getCategory().getId())){
// Category category = categoryService.get(article.getCategory().getId());
// }
model
.
addAttribute
(
"contentViewList"
,
getTplContent
());
model
.
addAttribute
(
"article_DEFAULT_TEMPLATE"
,
Article
.
DEFAULT_TEMPLATE
);
model
.
addAttribute
(
"article"
,
article
);
CmsUtils
.
addViewConfigAttribute
(
model
,
article
.
getCategory
());
return
"modules/cms/articleForm"
;
}
@RequiresPermissions
(
"cms:article:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Article
article
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
article
)){
return
form
(
article
,
model
);
}
articleService
.
save
(
article
);
addMessage
(
redirectAttributes
,
"保存文章'"
+
StringUtils
.
abbr
(
article
.
getTitle
(),
50
)
+
"'成功"
);
String
categoryId
=
article
.
getCategory
()!=
null
?
article
.
getCategory
().
getId
():
null
;
return
"redirect:"
+
adminPath
+
"/cms/article/?repage&category.id="
+(
categoryId
!=
null
?
categoryId:
""
);
}
@RequiresPermissions
(
"cms:article:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Article
article
,
String
categoryId
,
@RequestParam
(
required
=
false
)
Boolean
isRe
,
RedirectAttributes
redirectAttributes
)
{
// 如果没有审核权限,则不允许删除或发布。
if
(!
UserUtils
.
getSubject
().
isPermitted
(
"cms:article:audit"
)){
addMessage
(
redirectAttributes
,
"你没有删除或发布权限"
);
}
articleService
.
delete
(
article
,
isRe
);
addMessage
(
redirectAttributes
,
(
isRe
!=
null
&&
isRe
?
"发布"
:
"删除"
)+
"文章成功"
);
return
"redirect:"
+
adminPath
+
"/cms/article/?repage&category.id="
+(
categoryId
!=
null
?
categoryId:
""
);
}
/**
* 文章选择列表
*/
@RequiresPermissions
(
"cms:article:view"
)
@RequestMapping
(
value
=
"selectList"
)
public
String
selectList
(
Article
article
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
list
(
article
,
request
,
response
,
model
);
return
"modules/cms/articleSelectList"
;
}
/**
* 通过编号获取文章标题
*/
@RequiresPermissions
(
"cms:article:view"
)
@ResponseBody
@RequestMapping
(
value
=
"findByIds"
)
public
String
findByIds
(
String
ids
)
{
List
<
Object
[]>
list
=
articleService
.
findByIds
(
ids
);
return
JsonMapper
.
nonDefaultMapper
().
toJson
(
list
);
}
private
List
<
String
>
getTplContent
()
{
List
<
String
>
tplList
=
fileTplService
.
getNameListByPrefix
(
siteService
.
get
(
Site
.
getCurrentSiteId
()).
getSolutionPath
());
tplList
=
TplUtils
.
tplTrim
(
tplList
,
Article
.
DEFAULT_TEMPLATE
,
""
);
return
tplList
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/CategoryController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.apache.shiro.authz.annotation.RequiresUser
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Article
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.CategoryService
;
import
com.jeespring.modules.cms.service.FileTplService
;
import
com.jeespring.modules.cms.service.SiteService
;
import
com.jeespring.modules.cms.utils.TplUtils
;
/**
* 栏目Controller
* @author JeeSpring
* @version 2013-4-21
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/category"
)
public
class
CategoryController
extends
AbstractBaseController
{
@Autowired
private
CategoryService
categoryService
;
@Autowired
private
FileTplService
fileTplService
;
@Autowired
private
SiteService
siteService
;
@ModelAttribute
(
"category"
)
public
Category
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
categoryService
.
get
(
id
);
}
else
{
return
new
Category
();
}
}
@RequiresPermissions
(
"cms:category:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Model
model
)
{
List
<
Category
>
list
=
Lists
.
newArrayList
();
List
<
Category
>
sourcelist
=
categoryService
.
findByUser
(
true
,
null
);
Category
.
sortList
(
list
,
sourcelist
,
"1"
);
model
.
addAttribute
(
"list"
,
list
);
return
"modules/cms/categoryList"
;
}
@RequiresPermissions
(
"cms:category:view"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Category
category
,
Model
model
)
{
if
(
category
.
getParent
()==
null
||
category
.
getParent
().
getId
()==
null
){
category
.
setParent
(
new
Category
(
"1"
));
}
Category
parent
=
categoryService
.
get
(
category
.
getParent
().
getId
());
category
.
setParent
(
parent
);
if
(
category
.
getOffice
()==
null
||
category
.
getOffice
().
getId
()==
null
){
category
.
setOffice
(
parent
.
getOffice
());
}
model
.
addAttribute
(
"listViewList"
,
getTplContent
(
Category
.
DEFAULT_TEMPLATE
));
model
.
addAttribute
(
"category_DEFAULT_TEMPLATE"
,
Category
.
DEFAULT_TEMPLATE
);
model
.
addAttribute
(
"contentViewList"
,
getTplContent
(
Article
.
DEFAULT_TEMPLATE
));
model
.
addAttribute
(
"article_DEFAULT_TEMPLATE"
,
Article
.
DEFAULT_TEMPLATE
);
model
.
addAttribute
(
"office"
,
category
.
getOffice
());
model
.
addAttribute
(
"category"
,
category
);
return
"modules/cms/categoryForm"
;
}
@RequiresPermissions
(
"cms:category:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Category
category
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
Global
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
"演示模式,不允许操作!"
);
return
"redirect:"
+
adminPath
+
"/cms/category/"
;
}
if
(!
beanValidator
(
model
,
category
)){
return
form
(
category
,
model
);
}
categoryService
.
save
(
category
);
addMessage
(
redirectAttributes
,
"保存栏目'"
+
category
.
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/cms/category/"
;
}
@RequiresPermissions
(
"cms:category:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Category
category
,
RedirectAttributes
redirectAttributes
)
{
if
(
Global
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
"演示模式,不允许操作!"
);
return
"redirect:"
+
adminPath
+
"/cms/category/"
;
}
if
(
Category
.
isRoot
(
category
.
getId
())){
addMessage
(
redirectAttributes
,
"删除栏目失败, 不允许删除顶级栏目或编号为空"
);
}
else
{
categoryService
.
delete
(
category
);
addMessage
(
redirectAttributes
,
"删除栏目成功"
);
}
return
"redirect:"
+
adminPath
+
"/cms/category/"
;
}
/**
* 批量修改栏目排序
*/
@RequiresPermissions
(
"cms:category:edit"
)
@RequestMapping
(
value
=
"updateSort"
)
public
String
updateSort
(
String
[]
ids
,
Integer
[]
sorts
,
RedirectAttributes
redirectAttributes
)
{
int
len
=
ids
.
length
;
Category
[]
entitys
=
new
Category
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
entitys
[
i
]
=
categoryService
.
get
(
ids
[
i
]);
entitys
[
i
].
setSort
(
sorts
[
i
]);
categoryService
.
save
(
entitys
[
i
]);
}
addMessage
(
redirectAttributes
,
"保存栏目排序成功!"
);
return
"redirect:"
+
adminPath
+
"/cms/category/"
;
}
@RequiresUser
@ResponseBody
@RequestMapping
(
value
=
"treeData"
)
public
List
<
Map
<
String
,
Object
>>
treeData
(
String
module
,
@RequestParam
(
required
=
false
)
String
extId
,
HttpServletResponse
response
)
{
response
.
setContentType
(
"application/json; charset=UTF-8"
);
List
<
Map
<
String
,
Object
>>
mapList
=
Lists
.
newArrayList
();
List
<
Category
>
list
=
categoryService
.
findByUser
(
true
,
module
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
Category
e
=
list
.
get
(
i
);
if
(
extId
==
null
||
(
extId
!=
null
&&
!
extId
.
equals
(
e
.
getId
())
&&
e
.
getParentIds
().
indexOf
(
","
+
extId
+
","
)==-
1
)){
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
e
.
getId
());
map
.
put
(
"pId"
,
e
.
getParent
()!=
null
?
e
.
getParent
().
getId
():
0
);
map
.
put
(
"name"
,
e
.
getName
());
map
.
put
(
"module"
,
e
.
getModule
());
mapList
.
add
(
map
);
}
}
return
mapList
;
}
private
List
<
String
>
getTplContent
(
String
prefix
)
{
List
<
String
>
tplList
=
fileTplService
.
getNameListByPrefix
(
siteService
.
get
(
Site
.
getCurrentSiteId
()).
getSolutionPath
());
tplList
=
TplUtils
.
tplTrim
(
tplList
,
prefix
,
""
);
return
tplList
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/CmsController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.service.CategoryService
;
/**
* 内容管理Controller
* @author JeeSpring
* @version 2013-4-21
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms"
)
public
class
CmsController
extends
AbstractBaseController
{
@Autowired
private
CategoryService
categoryService
;
@RequiresPermissions
(
"cms:view"
)
@RequestMapping
(
value
=
""
)
public
String
index
()
{
return
"modules/cms/cmsIndex"
;
}
@RequiresPermissions
(
"cms:view"
)
@RequestMapping
(
value
=
"tree"
)
public
String
tree
(
Model
model
)
{
model
.
addAttribute
(
"categoryList"
,
categoryService
.
findByUser
(
true
,
null
));
return
"modules/cms/cmsTree"
;
}
@RequiresPermissions
(
"cms:view"
)
@RequestMapping
(
value
=
"none"
)
public
String
none
()
{
return
"modules/cms/cmsNone"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/CommentController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
java.util.Date
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Comment
;
import
com.jeespring.modules.cms.service.CommentService
;
import
com.jeespring.modules.sys.utils.DictUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 评论Controller
* @author JeeSpring
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/comment"
)
public
class
CommentController
extends
AbstractBaseController
{
@Autowired
private
CommentService
commentService
;
@ModelAttribute
public
Comment
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
commentService
.
get
(
id
);
}
else
{
return
new
Comment
();
}
}
@RequiresPermissions
(
"cms:comment:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Comment
comment
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
Comment
>
page
=
commentService
.
findPage
(
new
Page
<
Comment
>(
request
,
response
),
comment
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/cms/commentList"
;
}
@RequiresPermissions
(
"cms:comment:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Comment
comment
,
RedirectAttributes
redirectAttributes
)
{
if
(
beanValidator
(
redirectAttributes
,
comment
)){
if
(
comment
.
getAuditUser
()
==
null
){
comment
.
setAuditUser
(
UserUtils
.
getUser
());
comment
.
setAuditDate
(
new
Date
());
}
comment
.
setDelFlag
(
Comment
.
DEL_FLAG_NORMAL
);
commentService
.
save
(
comment
);
addMessage
(
redirectAttributes
,
DictUtils
.
getDictLabel
(
comment
.
getDelFlag
(),
"cms_del_flag"
,
"保存"
)
+
"评论'"
+
StringUtils
.
abbr
(
StringUtils
.
replaceHtml
(
comment
.
getContent
()),
50
)
+
"'成功"
);
}
return
"redirect:"
+
adminPath
+
"/cms/comment/?repage&delFlag=2"
;
}
@RequiresPermissions
(
"cms:comment:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Comment
comment
,
@RequestParam
(
required
=
false
)
Boolean
isRe
,
RedirectAttributes
redirectAttributes
)
{
commentService
.
delete
(
comment
,
isRe
);
addMessage
(
redirectAttributes
,
(
isRe
!=
null
&&
isRe
?
"恢复审核"
:
"删除"
)+
"评论成功"
);
return
"redirect:"
+
adminPath
+
"/cms/comment/?repage&delFlag=2"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/GuestbookController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
java.util.Date
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Guestbook
;
import
com.jeespring.modules.cms.service.GuestbookService
;
import
com.jeespring.modules.sys.utils.DictUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 留言Controller
* @author JeeSpring
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/guestbook"
)
public
class
GuestbookController
extends
AbstractBaseController
{
@Autowired
private
GuestbookService
guestbookService
;
@ModelAttribute
public
Guestbook
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
guestbookService
.
get
(
id
);
}
else
{
return
new
Guestbook
();
}
}
@RequiresPermissions
(
"cms:guestbook:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Guestbook
guestbook
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
Guestbook
>
page
=
guestbookService
.
findPage
(
new
Page
<
Guestbook
>(
request
,
response
),
guestbook
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/cms/guestbookList"
;
}
@RequiresPermissions
(
"cms:guestbook:view"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Guestbook
guestbook
,
Model
model
)
{
model
.
addAttribute
(
"guestbook"
,
guestbook
);
return
"modules/cms/guestbookForm"
;
}
@RequiresPermissions
(
"cms:guestbook:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Guestbook
guestbook
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
guestbook
)){
return
form
(
guestbook
,
model
);
}
if
(
guestbook
.
getReUser
()
==
null
){
guestbook
.
setReUser
(
UserUtils
.
getUser
());
guestbook
.
setReDate
(
new
Date
());
}
guestbookService
.
save
(
guestbook
);
addMessage
(
redirectAttributes
,
DictUtils
.
getDictLabel
(
guestbook
.
getDelFlag
(),
"cms_del_flag"
,
"保存"
)
+
"留言'"
+
guestbook
.
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/cms/guestbook/?repage&status=2"
;
}
@RequiresPermissions
(
"cms:guestbook:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Guestbook
guestbook
,
@RequestParam
(
required
=
false
)
Boolean
isRe
,
RedirectAttributes
redirectAttributes
)
{
guestbookService
.
delete
(
guestbook
,
isRe
);
addMessage
(
redirectAttributes
,
(
isRe
!=
null
&&
isRe
?
"恢复审核"
:
"删除"
)+
"留言成功"
);
return
"redirect:"
+
adminPath
+
"/cms/guestbook/?repage&status=2"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/LinkController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.mapper.JsonMapper
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.entity.Link
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.CategoryService
;
import
com.jeespring.modules.cms.service.LinkService
;
/**
* 链接Controller
* @author JeeSpring
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/link"
)
public
class
LinkController
extends
AbstractBaseController
{
@Autowired
private
LinkService
linkService
;
@Autowired
private
CategoryService
categoryService
;
@ModelAttribute
public
Link
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
linkService
.
get
(
id
);
}
else
{
return
new
Link
();
}
}
@RequiresPermissions
(
"cms:link:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Link
link
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
// User user = UserUtils.getUser();
// if (!user.isAdmin() && !SecurityUtils.getSubject().isPermitted("cms:link:audit")){
// link.setUser(user);
// }
Page
<
Link
>
page
=
linkService
.
findPage
(
new
Page
<
Link
>(
request
,
response
),
link
,
true
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/cms/linkList"
;
}
@RequiresPermissions
(
"cms:link:view"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Link
link
,
Model
model
)
{
// 如果当前传参有子节点,则选择取消传参选择
if
(
link
.
getCategory
()!=
null
&&
StringUtils
.
isNotBlank
(
link
.
getCategory
().
getId
())){
List
<
Category
>
list
=
categoryService
.
findByParentId
(
link
.
getCategory
().
getId
(),
Site
.
getCurrentSiteId
());
if
(
list
.
size
()
>
0
){
link
.
setCategory
(
null
);
}
else
{
link
.
setCategory
(
categoryService
.
get
(
link
.
getCategory
().
getId
()));
}
}
model
.
addAttribute
(
"link"
,
link
);
return
"modules/cms/linkForm"
;
}
@RequiresPermissions
(
"cms:link:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Link
link
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
link
)){
return
form
(
link
,
model
);
}
linkService
.
save
(
link
);
addMessage
(
redirectAttributes
,
"保存链接'"
+
StringUtils
.
abbr
(
link
.
getTitle
(),
50
)
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/cms/link/?repage&category.id="
+
link
.
getCategory
().
getId
();
}
@RequiresPermissions
(
"cms:link:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Link
link
,
String
categoryId
,
@RequestParam
(
required
=
false
)
Boolean
isRe
,
RedirectAttributes
redirectAttributes
)
{
linkService
.
delete
(
link
,
isRe
);
addMessage
(
redirectAttributes
,
(
isRe
!=
null
&&
isRe
?
"发布"
:
"删除"
)+
"链接成功"
);
return
"redirect:"
+
adminPath
+
"/cms/link/?repage&category.id="
+
categoryId
;
}
/**
* 链接选择列表
*/
@RequiresPermissions
(
"cms:link:view"
)
@RequestMapping
(
value
=
"selectList"
)
public
String
selectList
(
Link
link
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
list
(
link
,
request
,
response
,
model
);
return
"modules/cms/linkSelectList"
;
}
/**
* 通过编号获取链接名称
*/
@RequiresPermissions
(
"cms:link:view"
)
@ResponseBody
@RequestMapping
(
value
=
"findByIds"
)
public
String
findByIds
(
String
ids
)
{
List
<
Object
[]>
list
=
linkService
.
findByIds
(
ids
);
return
JsonMapper
.
nonDefaultMapper
().
toJson
(
list
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/SiteController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.CookieUtils
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.SiteService
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 站点Controller
* @author JeeSpring
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/site"
)
public
class
SiteController
extends
AbstractBaseController
{
@Autowired
private
SiteService
siteService
;
@ModelAttribute
public
Site
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
siteService
.
get
(
id
);
}
else
{
return
new
Site
();
}
}
@RequiresPermissions
(
"cms:site:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Site
site
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
Site
>
page
=
siteService
.
findPage
(
new
Page
<
Site
>(
request
,
response
),
site
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/cms/siteList"
;
}
@RequiresPermissions
(
"cms:site:view"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Site
site
,
Model
model
)
{
model
.
addAttribute
(
"site"
,
site
);
return
"modules/cms/siteForm"
;
}
@RequiresPermissions
(
"cms:site:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Site
site
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
Global
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
"演示模式,不允许操作!"
);
return
"redirect:"
+
adminPath
+
"/cms/site/?repage"
;
}
if
(!
beanValidator
(
model
,
site
)){
return
form
(
site
,
model
);
}
siteService
.
save
(
site
);
addMessage
(
redirectAttributes
,
"保存站点'"
+
site
.
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/cms/site/?repage"
;
}
@RequiresPermissions
(
"cms:site:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Site
site
,
@RequestParam
(
required
=
false
)
Boolean
isRe
,
RedirectAttributes
redirectAttributes
)
{
if
(
Global
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
"演示模式,不允许操作!"
);
return
"redirect:"
+
adminPath
+
"/cms/site/?repage"
;
}
if
(
Site
.
isDefault
(
site
.
getId
())){
addMessage
(
redirectAttributes
,
"删除站点失败, 不允许删除默认站点"
);
}
else
{
siteService
.
delete
(
site
,
isRe
);
addMessage
(
redirectAttributes
,
(
isRe
!=
null
&&
isRe
?
"恢复"
:
""
)+
"删除站点成功"
);
}
return
"redirect:"
+
adminPath
+
"/cms/site/?repage"
;
}
/**
* 选择站点
* @param id
* @return
*/
@RequiresPermissions
(
"cms:site:select"
)
@RequestMapping
(
value
=
"select"
)
public
String
select
(
String
id
,
boolean
flag
,
HttpServletResponse
response
){
if
(
id
!=
null
){
UserUtils
.
putCache
(
"siteId"
,
id
);
// 保存到Cookie中,下次登录后自动切换到该站点
CookieUtils
.
setCookie
(
response
,
"siteId"
,
id
);
}
if
(
flag
){
return
"redirect:"
+
adminPath
;
}
return
"modules/cms/siteSelect"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/StatsController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.service.StatsService
;
/**
* 统计Controller
* @author JeeSpring
* @version 2013-5-21
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/stats"
)
public
class
StatsController
extends
AbstractBaseController
{
@Autowired
private
StatsService
statsService
;
/**
* 文章信息量
* @param paramMap
* @param model
* @return
*/
@RequiresPermissions
(
"cms:stats:article"
)
@RequestMapping
(
value
=
"article"
)
public
String
article
(
@RequestParam
Map
<
String
,
Object
>
paramMap
,
Model
model
)
{
List
<
Category
>
list
=
statsService
.
article
(
paramMap
);
model
.
addAttribute
(
"list"
,
list
);
model
.
addAttribute
(
"paramMap"
,
paramMap
);
return
"modules/cms/statsArticle"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/TemplateController.java
0 → 100644
View file @
44ad5f47
package
com.jeespring.modules.cms.web
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.FileTplService
;
import
com.jeespring.modules.cms.service.SiteService
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
/**
* 站点Controller
* @author SongLai
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/cms/template"
)
public
class
TemplateController
extends
AbstractBaseController
{
@Autowired
private
FileTplService
fileTplService
;
@Autowired
private
SiteService
siteService
;
@RequiresPermissions
(
"cms:template:edit"
)
@RequestMapping
(
value
=
""
)
public
String
index
()
{
return
"modules/cms/tplIndex"
;
}
@RequiresPermissions
(
"cms:template:edit"
)
@RequestMapping
(
value
=
"tree"
)
public
String
tree
(
Model
model
)
{
Site
site
=
siteService
.
get
(
Site
.
getCurrentSiteId
());
model
.
addAttribute
(
"templateList"
,
fileTplService
.
getListForEdit
(
site
.
getSolutionPath
()));
return
"modules/cms/tplTree"
;
}
@RequiresPermissions
(
"cms:template:edit"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
String
name
,
Model
model
)
{
model
.
addAttribute
(
"template"
,
fileTplService
.
getFileTpl
(
name
));
return
"modules/cms/tplForm"
;
}
@RequiresPermissions
(
"cms:template:edit"
)
@RequestMapping
(
value
=
"help"
)
public
String
help
()
{
return
"modules/cms/tplHelp"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/front/FrontController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web.front
;
import
java.util.Date
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.servlet.ValidateCodeServlet
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Article
;
import
com.jeespring.modules.cms.entity.Category
;
import
com.jeespring.modules.cms.entity.Comment
;
import
com.jeespring.modules.cms.entity.Link
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.ArticleDataService
;
import
com.jeespring.modules.cms.service.ArticleService
;
import
com.jeespring.modules.cms.service.CategoryService
;
import
com.jeespring.modules.cms.service.CommentService
;
import
com.jeespring.modules.cms.service.LinkService
;
import
com.jeespring.modules.cms.service.SiteService
;
import
com.jeespring.modules.cms.utils.CmsUtils
;
/**
* 网站Controller
* @author JeeSpring
* @version 2013-5-29
*/
@Controller
@RequestMapping
(
value
=
"${frontPath}"
)
public
class
FrontController
extends
AbstractBaseController
{
@Autowired
private
ArticleService
articleService
;
@Autowired
private
ArticleDataService
articleDataService
;
@Autowired
private
LinkService
linkService
;
@Autowired
private
CommentService
commentService
;
@Autowired
private
CategoryService
categoryService
;
@Autowired
private
SiteService
siteService
;
/**
* 网站首页
*/
@RequestMapping
public
String
index
(
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
model
.
addAttribute
(
"isIndex"
,
true
);
if
(
request
.
getParameter
(
"theme"
)!=
null
){
site
.
setTheme
(
request
.
getParameter
(
"theme"
));
}
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontIndex"
;
}
@RequestMapping
(
value
=
"index2"
)
public
String
index2
(
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
model
.
addAttribute
(
"isIndex"
,
true
);
if
(
request
.
getParameter
(
"theme"
)!=
null
){
site
.
setTheme
(
request
.
getParameter
(
"theme"
));
}
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/index"
;
}
/**
* 网站首页
*/
@RequestMapping
(
value
=
"index-{siteId}${urlSuffix}"
)
public
String
index
(
@PathVariable
String
siteId
,
Model
model
)
{
if
(
"1"
.
equals
(
siteId
)){
return
"redirect:"
+
Global
.
getFrontPath
();
}
Site
site
=
CmsUtils
.
getSite
(
siteId
);
// 子站有独立页面,则显示独立页面
if
(
StringUtils
.
isNotBlank
(
site
.
getCustomIndexView
())){
model
.
addAttribute
(
"site"
,
site
);
model
.
addAttribute
(
"isIndex"
,
true
);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontIndex"
+
site
.
getCustomIndexView
();
}
// 否则显示子站第一个栏目
List
<
Category
>
mainNavList
=
CmsUtils
.
getMainNavList
(
siteId
);
if
(
mainNavList
.
size
()
>
0
){
String
firstCategoryId
=
CmsUtils
.
getMainNavList
(
siteId
).
get
(
0
).
getId
();
return
"redirect:"
+
Global
.
getFrontPath
()+
"/list-"
+
firstCategoryId
+
Global
.
getUrlSuffix
();
}
else
{
model
.
addAttribute
(
"site"
,
site
);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontListCategory"
;
}
}
/**
* 内容列表
*/
@RequestMapping
(
value
=
"list-{categoryId}${urlSuffix}"
)
public
String
list
(
@PathVariable
String
categoryId
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
required
=
false
,
defaultValue
=
"15"
)
Integer
pageSize
,
Model
model
)
{
Category
category
=
categoryService
.
get
(
categoryId
);
if
(
category
==
null
){
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
return
"error/404"
;
}
Site
site
=
siteService
.
get
(
category
.
getSite
().
getId
());
model
.
addAttribute
(
"site"
,
site
);
// 2:简介类栏目,栏目第一条内容
if
(
"2"
.
equals
(
category
.
getShowModes
())
&&
"article"
.
equals
(
category
.
getModule
())){
// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
List
<
Category
>
categoryList
=
Lists
.
newArrayList
();
if
(
"1"
.
equals
(
category
.
getParent
().
getId
())){
categoryList
.
add
(
category
);
}
else
{
categoryList
=
categoryService
.
findByParentId
(
category
.
getParent
().
getId
(),
category
.
getSite
().
getId
());
}
model
.
addAttribute
(
"category"
,
category
);
model
.
addAttribute
(
"categoryList"
,
categoryList
);
// 获取文章内容
Page
<
Article
>
page
=
new
Page
<
Article
>(
1
,
1
,
-
1
);
Article
article
=
new
Article
(
category
);
page
=
articleService
.
findPage
(
page
,
article
,
false
);
if
(
page
.
getList
().
size
()>
0
){
article
=
page
.
getList
().
get
(
0
);
article
.
setArticleData
(
articleDataService
.
get
(
article
.
getId
()));
articleService
.
updateHitsAddOne
(
article
.
getId
());
}
model
.
addAttribute
(
"article"
,
article
);
CmsUtils
.
addViewConfigAttribute
(
model
,
category
);
CmsUtils
.
addViewConfigAttribute
(
model
,
article
.
getViewConfig
());
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/"
+
getTpl
(
article
);
}
else
{
List
<
Category
>
categoryList
=
categoryService
.
findByParentId
(
category
.
getId
(),
category
.
getSite
().
getId
());
// 展现方式为1 、无子栏目或公共模型,显示栏目内容列表
if
(
"1"
.
equals
(
category
.
getShowModes
())||
categoryList
.
size
()==
0
){
// 有子栏目并展现方式为1,则获取第一个子栏目;无子栏目,则获取同级分类列表。
if
(
categoryList
.
size
()>
0
){
category
=
categoryList
.
get
(
0
);
}
else
{
// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
if
(
"1"
.
equals
(
category
.
getParent
().
getId
())){
categoryList
.
add
(
category
);
}
else
{
categoryList
=
categoryService
.
findByParentId
(
category
.
getParent
().
getId
(),
category
.
getSite
().
getId
());
}
}
model
.
addAttribute
(
"category"
,
category
);
model
.
addAttribute
(
"categoryList"
,
categoryList
);
// 获取内容列表
if
(
"article"
.
equals
(
category
.
getModule
())){
Page
<
Article
>
page
=
new
Page
<
Article
>(
pageNo
,
pageSize
);
//System.out.println(page.getPageNo());
page
=
articleService
.
findPage
(
page
,
new
Article
(
category
),
false
);
model
.
addAttribute
(
"page"
,
page
);
// 如果第一个子栏目为简介类栏目,则获取该栏目第一篇文章
if
(
"2"
.
equals
(
category
.
getShowModes
())){
Article
article
=
new
Article
(
category
);
if
(
page
.
getList
().
size
()>
0
){
article
=
page
.
getList
().
get
(
0
);
article
.
setArticleData
(
articleDataService
.
get
(
article
.
getId
()));
articleService
.
updateHitsAddOne
(
article
.
getId
());
}
model
.
addAttribute
(
"article"
,
article
);
CmsUtils
.
addViewConfigAttribute
(
model
,
category
);
CmsUtils
.
addViewConfigAttribute
(
model
,
article
.
getViewConfig
());
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/"
+
getTpl
(
article
);
}
}
else
if
(
"link"
.
equals
(
category
.
getModule
())){
Page
<
Link
>
page
=
new
Page
<
Link
>(
1
,
-
1
);
page
=
linkService
.
findPage
(
page
,
new
Link
(
category
),
false
);
model
.
addAttribute
(
"page"
,
page
);
}
String
view
=
"/frontList"
;
if
(
StringUtils
.
isNotBlank
(
category
.
getCustomListView
())){
view
=
"/"
+
category
.
getCustomListView
();
}
CmsUtils
.
addViewConfigAttribute
(
model
,
category
);
site
=
siteService
.
get
(
category
.
getSite
().
getId
());
//System.out.println("else 栏目第一条内容 _2 :"+category.getSite().getTheme()+","+site.getTheme());
return
"modules/cms/front/themes/"
+
siteService
.
get
(
category
.
getSite
().
getId
()).
getTheme
()+
view
;
//return "modules/cms/front/themes/"+category.getSite().getTheme()+view;
}
// 有子栏目:显示子栏目列表
else
{
model
.
addAttribute
(
"category"
,
category
);
model
.
addAttribute
(
"categoryList"
,
categoryList
);
String
view
=
"/frontListCategory"
;
if
(
StringUtils
.
isNotBlank
(
category
.
getCustomListView
())){
view
=
"/"
+
category
.
getCustomListView
();
}
CmsUtils
.
addViewConfigAttribute
(
model
,
category
);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
view
;
}
}
}
/**
* 内容列表(通过url自定义视图)
*/
@RequestMapping
(
value
=
"listc-{categoryId}-{customView}${urlSuffix}"
)
public
String
listCustom
(
@PathVariable
String
categoryId
,
@PathVariable
String
customView
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
required
=
false
,
defaultValue
=
"15"
)
Integer
pageSize
,
Model
model
)
{
Category
category
=
categoryService
.
get
(
categoryId
);
if
(
category
==
null
){
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
return
"error/404"
;
}
Site
site
=
siteService
.
get
(
category
.
getSite
().
getId
());
model
.
addAttribute
(
"site"
,
site
);
List
<
Category
>
categoryList
=
categoryService
.
findByParentId
(
category
.
getId
(),
category
.
getSite
().
getId
());
model
.
addAttribute
(
"category"
,
category
);
model
.
addAttribute
(
"categoryList"
,
categoryList
);
CmsUtils
.
addViewConfigAttribute
(
model
,
category
);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontListCategory"
+
customView
;
}
/**
* 显示内容
*/
@RequestMapping
(
value
=
"view-{categoryId}-{contentId}${urlSuffix}"
)
public
String
view
(
@PathVariable
String
categoryId
,
@PathVariable
String
contentId
,
Model
model
)
{
Category
category
=
categoryService
.
get
(
categoryId
);
if
(
category
==
null
){
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
return
"error/404"
;
}
model
.
addAttribute
(
"site"
,
category
.
getSite
());
if
(
"article"
.
equals
(
category
.
getModule
())){
// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
List
<
Category
>
categoryList
=
Lists
.
newArrayList
();
if
(
"1"
.
equals
(
category
.
getParent
().
getId
())){
categoryList
.
add
(
category
);
}
else
{
categoryList
=
categoryService
.
findByParentId
(
category
.
getParent
().
getId
(),
category
.
getSite
().
getId
());
}
// 获取文章内容
Article
article
=
articleService
.
get
(
contentId
);
if
(
article
==
null
||
!
Article
.
DEL_FLAG_NORMAL
.
equals
(
article
.
getDelFlag
())){
return
"error/404"
;
}
// 文章阅读次数+1
articleService
.
updateHitsAddOne
(
contentId
);
// 获取推荐文章列表
List
<
Object
[]>
relationList
=
articleService
.
findByIds
(
articleDataService
.
get
(
article
.
getId
()).
getRelation
());
// 将数据传递到视图
model
.
addAttribute
(
"category"
,
categoryService
.
get
(
article
.
getCategory
().
getId
()));
model
.
addAttribute
(
"categoryList"
,
categoryList
);
article
.
setArticleData
(
articleDataService
.
get
(
article
.
getId
()));
model
.
addAttribute
(
"article"
,
article
);
model
.
addAttribute
(
"relationList"
,
relationList
);
CmsUtils
.
addViewConfigAttribute
(
model
,
article
.
getCategory
());
CmsUtils
.
addViewConfigAttribute
(
model
,
article
.
getViewConfig
());
Site
site
=
siteService
.
get
(
category
.
getSite
().
getId
());
model
.
addAttribute
(
"site"
,
site
);
// return "modules/cms/front/themes/"+category.getSite().getTheme()+"/"+getTpl(article);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/"
+
getTpl
(
article
);
}
return
"error/404"
;
}
/**
* 内容评论
*/
@RequestMapping
(
value
=
"comment"
,
method
=
RequestMethod
.
GET
)
public
String
comment
(
String
theme
,
Comment
comment
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
Comment
>
page
=
new
Page
<
Comment
>(
request
,
response
);
Comment
c
=
new
Comment
();
c
.
setCategory
(
comment
.
getCategory
());
c
.
setContentId
(
comment
.
getContentId
());
c
.
setDelFlag
(
Comment
.
DEL_FLAG_NORMAL
);
page
=
commentService
.
findPage
(
page
,
c
);
model
.
addAttribute
(
"page"
,
page
);
model
.
addAttribute
(
"comment"
,
comment
);
return
"modules/cms/front/themes/"
+
theme
+
"/frontComment"
;
}
/**
* 内容评论保存
*/
@ResponseBody
@RequestMapping
(
value
=
"comment"
,
method
=
RequestMethod
.
POST
)
public
String
commentSave
(
Comment
comment
,
String
validateCode
,
@RequestParam
(
required
=
false
)
String
replyId
,
HttpServletRequest
request
)
{
if
(
StringUtils
.
isNotBlank
(
validateCode
)){
if
(
ValidateCodeServlet
.
validate
(
request
,
validateCode
)){
if
(
StringUtils
.
isNotBlank
(
replyId
)){
Comment
replyComment
=
commentService
.
get
(
replyId
);
if
(
replyComment
!=
null
){
comment
.
setContent
(
"<div class=\"reply\">"
+
replyComment
.
getName
()+
":<br/>"
+
replyComment
.
getContent
()+
"</div>"
+
comment
.
getContent
());
}
}
comment
.
setIp
(
request
.
getRemoteAddr
());
comment
.
setCreateDate
(
new
Date
());
comment
.
setDelFlag
(
Comment
.
DEL_FLAG_AUDIT
);
commentService
.
save
(
comment
);
return
"{result:1, message:'提交成功。'}"
;
}
else
{
return
"{result:2, message:'验证码不正确。'}"
;
}
}
else
{
return
"{result:2, message:'验证码不能为空。'}"
;
}
}
/**
* 站点地图
*/
@RequestMapping
(
value
=
"map-{siteId}${urlSuffix}"
)
public
String
map
(
@PathVariable
String
siteId
,
Model
model
)
{
Site
site
=
CmsUtils
.
getSite
(
siteId
!=
null
?
siteId:
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontMap"
;
}
private
String
getTpl
(
Article
article
){
if
(
StringUtils
.
isBlank
(
article
.
getCustomContentView
())){
String
view
=
null
;
Category
c
=
article
.
getCategory
();
boolean
goon
=
true
;
do
{
if
(
StringUtils
.
isNotBlank
(
c
.
getCustomContentView
())){
view
=
c
.
getCustomContentView
();
goon
=
false
;
}
else
if
(
c
.
getParent
()
==
null
||
c
.
getParent
().
isRoot
()){
goon
=
false
;
}
else
{
c
=
c
.
getParent
();
}
}
while
(
goon
);
return
StringUtils
.
isBlank
(
view
)
?
Article
.
DEFAULT_TEMPLATE
:
view
;
}
else
{
return
article
.
getCustomContentView
();
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/front/FrontGuestbookController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web.front
;
import
java.util.Date
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Guestbook
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.GuestbookService
;
import
com.jeespring.modules.cms.utils.CmsUtils
;
/**
* 留言板Controller
* @author JeeSpring
* @version 2013-3-15
*/
@Controller
@RequestMapping
(
value
=
"${frontPath}/guestbook"
)
public
class
FrontGuestbookController
extends
AbstractBaseController
{
@Autowired
private
GuestbookService
guestbookService
;
/**
* 留言板
*/
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
)
public
String
guestbook
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
required
=
false
,
defaultValue
=
"30"
)
Integer
pageSize
,
Model
model
)
{
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
Page
<
Guestbook
>
page
=
new
Page
<
Guestbook
>(
pageNo
,
pageSize
);
Guestbook
guestbook
=
new
Guestbook
();
guestbook
.
setDelFlag
(
Guestbook
.
DEL_FLAG_NORMAL
);
page
=
guestbookService
.
findPage
(
page
,
guestbook
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontGuestbook"
;
}
/**
* 留言板-保存留言信息
*/
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
public
String
guestbookSave
(
Guestbook
guestbook
,
String
validateCode
,
HttpServletRequest
request
,
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
// if (StringUtils.isNotBlank(validateCode)){
// if (ValidateCodeServlet.validate(request, validateCode)){
guestbook
.
setIp
(
request
.
getRemoteAddr
());
guestbook
.
setCreateDate
(
new
Date
());
guestbook
.
setDelFlag
(
Guestbook
.
DEL_FLAG_AUDIT
);
guestbookService
.
save
(
guestbook
);
addMessage
(
redirectAttributes
,
"提交成功,谢谢!"
);
// }else{
// addMessage(redirectAttributes, "验证码不正确。");
// }
// }else{
// addMessage(redirectAttributes, "验证码不能为空。");
// }
return
"redirect:"
+
Global
.
getFrontPath
()+
"/guestbook"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/cms/web/front/FrontSearchController.java
0 → 100644
View file @
44ad5f47
/**
* Copyright © 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package
com.jeespring.modules.cms.web.front
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.cms.entity.Article
;
import
com.jeespring.modules.cms.entity.Guestbook
;
import
com.jeespring.modules.cms.entity.Site
;
import
com.jeespring.modules.cms.service.ArticleService
;
import
com.jeespring.modules.cms.service.GuestbookService
;
import
com.jeespring.modules.cms.utils.CmsUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 网站搜索Controller
* @author JeeSpring
* @version 2013-5-29
*/
@Controller
@RequestMapping
(
value
=
"${frontPath}/search"
)
public
class
FrontSearchController
extends
AbstractBaseController
{
@Autowired
private
ArticleService
articleService
;
@Autowired
private
GuestbookService
guestbookService
;
/**
* 全站搜索
*/
@RequestMapping
(
value
=
""
)
public
String
search
(
String
t
,
@RequestParam
(
required
=
false
)
String
q
,
@RequestParam
(
required
=
false
)
String
qand
,
@RequestParam
(
required
=
false
)
String
qnot
,
@RequestParam
(
required
=
false
)
String
a
,
@RequestParam
(
required
=
false
)
String
cid
,
@RequestParam
(
required
=
false
)
String
bd
,
@RequestParam
(
required
=
false
)
String
ed
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
long
start
=
System
.
currentTimeMillis
();
Site
site
=
CmsUtils
.
getSite
(
Site
.
defaultSiteId
());
model
.
addAttribute
(
"site"
,
site
);
// 重建索引(需要超级管理员权限)
if
(
"cmd:reindex"
.
equals
(
q
)){
if
(
UserUtils
.
getUser
().
isAdmin
()){
// 文章模型
if
(
StringUtils
.
isBlank
(
t
)
||
"article"
.
equals
(
t
)){
articleService
.
createIndex
();
}
// 留言模型
else
if
(
"guestbook"
.
equals
(
t
)){
guestbookService
.
createIndex
();
}
model
.
addAttribute
(
"message"
,
"重建索引成功,共耗时 "
+
(
System
.
currentTimeMillis
()
-
start
)
+
"毫秒。"
);
}
else
{
model
.
addAttribute
(
"message"
,
"你没有执行权限。"
);
}
}
// 执行检索
else
{
String
qStr
=
StringUtils
.
replace
(
StringUtils
.
replace
(
q
,
","
,
" "
),
", "
,
" "
);
// 如果是高级搜索
if
(
"1"
.
equals
(
a
)){
if
(
StringUtils
.
isNotBlank
(
qand
)){
qStr
+=
" +"
+
StringUtils
.
replace
(
StringUtils
.
replace
(
StringUtils
.
replace
(
qand
,
","
,
" "
),
", "
,
" "
),
" "
,
" +"
);
}
if
(
StringUtils
.
isNotBlank
(
qnot
)){
qStr
+=
" -"
+
StringUtils
.
replace
(
StringUtils
.
replace
(
StringUtils
.
replace
(
qnot
,
","
,
" "
),
", "
,
" "
),
" "
,
" -"
);
}
}
// 文章检索
if
(
StringUtils
.
isBlank
(
t
)
||
"article"
.
equals
(
t
)){
Page
<
Article
>
page
=
articleService
.
search
(
new
Page
<
Article
>(
request
,
response
),
qStr
,
cid
,
bd
,
ed
);
page
.
setMessage
(
"匹配结果,共耗时 "
+
(
System
.
currentTimeMillis
()
-
start
)
+
"毫秒。"
);
model
.
addAttribute
(
"page"
,
page
);
}
// 留言检索
else
if
(
"guestbook"
.
equals
(
t
)){
Page
<
Guestbook
>
page
=
guestbookService
.
search
(
new
Page
<
Guestbook
>(
request
,
response
),
qStr
,
bd
,
ed
);
page
.
setMessage
(
"匹配结果,共耗时 "
+
(
System
.
currentTimeMillis
()
-
start
)
+
"毫秒。"
);
model
.
addAttribute
(
"page"
,
page
);
}
}
model
.
addAttribute
(
"t"
,
t
);
// 搜索类型
model
.
addAttribute
(
"q"
,
q
);
// 搜索关键字
model
.
addAttribute
(
"qand"
,
qand
);
// 包含以下全部的关键词
model
.
addAttribute
(
"qnot"
,
qnot
);
// 不包含以下关键词
model
.
addAttribute
(
"cid"
,
cid
);
// 搜索类型
return
"modules/cms/front/themes/"
+
site
.
getTheme
()+
"/frontSearch"
;
}
}
Prev
1
2
3
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