Commit e9629e7a authored by Sun's avatar Sun
Browse files

no commit message

parent e4054436
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.entity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.AbstractBaseEntity;
/**
* 文章Entity
* @author JeeSpring
* @version 2013-01-15
*/
public class ArticleData extends AbstractBaseEntity<ArticleData> {
private static final long serialVersionUID = 1L;
private String id; // 编号
private String content; // 内容
private String copyfrom;// 来源
private String relation;// 相关文章
private String allowComment;// 是否允许评论
private Article article;
public ArticleData() {
super();
this.allowComment = Global.YES;
}
public ArticleData(String id){
this();
this.id = id;
}
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
@NotBlank
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Length(min=0, max=255)
public String getCopyfrom() {
return copyfrom;
}
public void setCopyfrom(String copyfrom) {
this.copyfrom = copyfrom;
}
@Length(min=0, max=255)
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
@Length(min=1, max=1)
public String getAllowComment() {
return allowComment;
}
public void setAllowComment(String allowComment) {
this.allowComment = allowComment;
}
public Article getArticle() {
return article;
}
public void setArticle(Article article) {
this.article = article;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.entity;
import java.util.Date;
import java.util.List;
import org.hibernate.validator.constraints.Length;
import com.google.common.collect.Lists;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.TreeEntity;
import com.jeespring.modules.cms.utils.CmsUtils;
import com.jeespring.modules.sys.entity.Office;
/**
* 栏目Entity
* @author JeeSpring
* @version 2013-05-15
*/
public class Category extends TreeEntity<Category> {
public static final String DEFAULT_TEMPLATE = "frontList";
private static final long serialVersionUID = 1L;
private Site site; // 归属站点
private Office office; // 归属部门
// private Category parent;// 父级菜单
// private String parentIds;// 所有父级编号
private String module; // 栏目模型(article:文章;picture:图片;download:下载;link:链接;special:专题)
// private String name; // 栏目名称
private String image; // 栏目图片
private String href; // 链接
private String target; // 目标( _blank、_self、_parent、_top)
private String description; // 描述,填写有助于搜索引擎优化
private String keywords; // 关键字,填写有助于搜索引擎优化
// private Integer sort; // 排序(升序)
private String inMenu; // 是否在导航中显示(1:显示;0:不显示)
private String inList; // 是否在分类页中显示列表(1:显示;0:不显示)
private String showModes; // 展现方式(0:有子栏目显示栏目列表,无子栏目显示内容列表;1:首栏目内容列表;2:栏目第一条内容)
private String allowComment;// 是否允许评论
private String isAudit; // 是否需要审核
private String customListView; // 自定义列表视图
private String customContentView; // 自定义内容视图
private String viewConfig; // 视图参数
private Date beginDate; // 开始时间
private Date endDate; // 结束时间
private String cnt;//信息量
private String hits;//点击量
private List<Category> childList = Lists.newArrayList(); // 拥有子分类列表
public Category(){
super();
this.module = "";
this.sort = 30;
this.inMenu = Global.HIDE;
this.inList = Global.SHOW;
this.showModes = "0";
this.allowComment = Global.NO;
this.delFlag = DEL_FLAG_NORMAL;
this.isAudit = Global.NO;
}
public Category(String id){
this();
this.id = id;
}
public Category(String id, Site site){
this();
this.id = id;
this.setSite(site);
}
public Site getSite() {
return site;
}
public String getHits() {
return hits;
}
public void setHits(String hits) {
this.hits = hits;
}
public void setSite(Site site) {
this.site = site;
}
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
// @JsonBackReference
// @NotNull
@Override
public Category getParent() {
return parent;
}
@Override
public void setParent(Category parent) {
this.parent = parent;
}
// @Length(min=1, max=255)
// public String getParentIds() {
// return parentIds;
// }
//
// public void setParentIds(String parentIds) {
// this.parentIds = parentIds;
// }
@Length(min=0, max=20)
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
// @Length(min=0, max=100)
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
@Length(min=0, max=255)
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
@Length(min=0, max=255)
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
@Length(min=0, max=20)
public String getTarget() {
return target;
}
public Date getBeginDate() {
return beginDate;
}
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public void setTarget(String target) {
this.target = target;
}
@Length(min=0, max=255)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Length(min=0, max=255)
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
// @NotNull
// public Integer getSort() {
// return sort;
// }
//
// public void setSort(Integer sort) {
// this.sort = sort;
// }
@Length(min=1, max=1)
public String getInMenu() {
return inMenu;
}
public void setInMenu(String inMenu) {
this.inMenu = inMenu;
}
@Length(min=1, max=1)
public String getInList() {
return inList;
}
public void setInList(String inList) {
this.inList = inList;
}
@Length(min=1, max=1)
public String getShowModes() {
return showModes;
}
public void setShowModes(String showModes) {
this.showModes = showModes;
}
@Length(min=1, max=1)
public String getAllowComment() {
return allowComment;
}
public void setAllowComment(String allowComment) {
this.allowComment = allowComment;
}
@Length(min=1, max=1)
public String getIsAudit() {
return isAudit;
}
public void setIsAudit(String isAudit) {
this.isAudit = isAudit;
}
public String getCustomListView() {
return customListView;
}
public void setCustomListView(String customListView) {
this.customListView = customListView;
}
public String getCustomContentView() {
return customContentView;
}
public void setCustomContentView(String customContentView) {
this.customContentView = customContentView;
}
public String getViewConfig() {
return viewConfig;
}
public void setViewConfig(String viewConfig) {
this.viewConfig = viewConfig;
}
public List<Category> getChildList() {
return childList;
}
public void setChildList(List<Category> childList) {
this.childList = childList;
}
public String getCnt() {
return cnt;
}
public void setCnt(String cnt) {
this.cnt = cnt;
}
public static void sortList(List<Category> list, List<Category> sourcelist, String parentId){
for (int i=0; i<sourcelist.size(); i++){
Category e = sourcelist.get(i);
if (e.getParent()!=null && e.getParent().getId()!=null
&& e.getParent().getId().equals(parentId)){
list.add(e);
// 判断是否还有子节点, 有则继续获取子节点
for (int j=0; j<sourcelist.size(); j++){
Category child = sourcelist.get(j);
if (child.getParent()!=null && child.getParent().getId()!=null
&& child.getParent().getId().equals(e.getId())){
sortList(list, sourcelist, e.getId());
break;
}
}
}
}
}
public String getIds() {
return (this.getParentIds() !=null ? this.getParentIds().replaceAll(",", " ") : "")
+ (this.getId() != null ? this.getId() : "");
}
public boolean isRoot(){
return isRoot(this.id);
}
public static boolean isRoot(String id){
return id != null && "1".equals(id);
}
public String getUrl() {
return CmsUtils.getUrlDynamic(this);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.entity;
import java.util.Date;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import com.jeespring.common.persistence.AbstractBaseEntity;
import com.jeespring.modules.sys.entity.User;
/**
* 评论Entity
* @author JeeSpring
* @version 2013-05-15
*/
public class Comment extends AbstractBaseEntity<Comment> {
private static final long serialVersionUID = 1L;
private Category category;// 分类编号
private String contentId; // 归属分类内容的编号(Article.id、Photo.id、Download.id)
private String title; // 归属分类内容的标题(Article.title、Photo.title、Download.title)
private String content; // 评论内容
private String name; // 评论姓名
private String ip; // 评论IP
private Date createDate;// 评论时间
private User auditUser; // 审核人
private Date auditDate; // 审核时间
private String delFlag; // 删除标记删除标记(0:正常;1:删除;2:审核)
public Comment() {
super();
this.delFlag = DEL_FLAG_AUDIT;
}
public Comment(String id){
this();
this.id = id;
}
public Comment(Category category){
this();
this.category = category;
}
@NotNull
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
@NotNull
public String getContentId() {
return contentId;
}
public void setContentId(String contentId) {
this.contentId = contentId;
}
@Length(min=1, max=255)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Length(min=1, max=255)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Length(min=1, max=100)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public User getAuditUser() {
return auditUser;
}
public void setAuditUser(User auditUser) {
this.auditUser = auditUser;
}
public Date getAuditDate() {
return auditDate;
}
public void setAuditDate(Date auditDate) {
this.auditDate = auditDate;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
@Override
@NotNull
public Date getCreateDate() {
return createDate;
}
@Override
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
@Override
@Length(min=1, max=1)
public String getDelFlag() {
return delFlag;
}
@Override
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
}
\ No newline at end of file
package com.jeespring.modules.cms.entity;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
/**
* User: songlai
* Date: 13-8-22
* Time: 上午9:44
*/
public class FileTpl {
private File file;
// 应用的根目录
private String root;
public FileTpl(File file, String root) {
this.file = file;
this.root = root;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getRoot() {
return root;
}
public void setRoot(String root) {
this.root = root;
}
public String getName() {
String ap = file.getAbsolutePath().substring(root.length());
ap = ap.replace(File.separatorChar, '/');
// 在resin里root的结尾是带'/'的,这样会导致getName返回的名称不以'/'开头。
if (!ap.startsWith("/")) {
ap = "/" + ap;
}
return ap;
}
public String getParent(){
String ap = file.getParent().substring(root.length());
ap = ap.replace(File.separatorChar, '/');
// 在resin里root的结尾是带'/'的,这样会导致getName返回的名称不以'/'开头。
if (!ap.startsWith("/")) {
ap = "/" + ap;
}
return ap;
}
public String getPath() {
String name = getName();
return name.substring(0, name.lastIndexOf('/'));
}
public String getFilename() {
return file.getName();
}
public String getSource() {
if (file.isDirectory()) {
return null;
}
try {
return FileUtils.readFileToString(this.file, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public long getLastModified() {
return file.lastModified();
}
public Date getLastModifiedDate() {
return new Timestamp(getLastModified());
}
public long getLength() {
return file.length();
}
public int getSize() {
return (int) (getLength() / 1024) + 1;
}
public boolean isDirectory() {
return file.isDirectory();
}
}
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.entity;
import java.util.Date;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import com.jeespring.common.persistence.AbstractBaseEntity;
import com.jeespring.common.utils.IdGen;
import com.jeespring.modules.sys.entity.User;
/**
* 留言Entity
* @author JeeSpring
* @version 2013-05-15
*/
public class Guestbook extends AbstractBaseEntity<Guestbook> {
private static final long serialVersionUID = 1L;
private String type; // 留言分类(咨询、建议、投诉、其它)
private String content; // 留言内容
private String name; // 姓名
private String email; // 邮箱
private String phone; // 电话
private String workunit;// 单位
private String ip; // 留言IP
private Date createDate;// 留言时间
private User reUser; // 回复人
private Date reDate; // 回复时间
private String reContent;// 回复内容
private String delFlag; // 删除标记删除标记(0:正常;1:删除;2:审核)
public Guestbook() {
this.delFlag = DEL_FLAG_AUDIT;
}
public Guestbook(String id){
this();
this.id = id;
}
public void prePersist(){
this.id = IdGen.uuid();
this.createDate = new Date();
}
@Length(min=1, max=100)
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Length(min=1, max=2000)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Length(min=1, max=100)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Email @Length(min=0, max=100)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Length(min=0, max=100)
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Length(min=0, max=100)
public String getWorkunit() {
return workunit;
}
public void setWorkunit(String workunit) {
this.workunit = workunit;
}
@Length(min=1, max=100)
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
@Override
@NotNull
public Date getCreateDate() {
return createDate;
}
@Override
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public User getReUser() {
return reUser;
}
public void setReUser(User reUser) {
this.reUser = reUser;
}
public String getReContent() {
return reContent;
}
public void setReContent(String reContent) {
this.reContent = reContent;
}
public Date getReDate() {
return reDate;
}
public void setReDate(Date reDate) {
this.reDate = reDate;
}
@Override
@Length(min=1, max=1)
public String getDelFlag() {
return delFlag;
}
@Override
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
}
/**
\ * Copyright &copy; 2012-2013 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.entity;
import java.util.Date;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import com.jeespring.common.persistence.AbstractBaseEntity;
import com.jeespring.modules.sys.entity.User;
/**
* 链接Entity
* @author JeeSpring
* @version 2013-05-15
*/
public class Link extends AbstractBaseEntity<Link> {
private static final long serialVersionUID = 1L;
private Category category;// 分类编号
private String title; // 链接名称
private String color; // 标题颜色(red:红色;green:绿色;blue:蓝色;yellow:黄色;orange:橙色)
private String image; // 链接图片
private String href; // 链接地址
private Integer weight; // 权重,越大越靠前
private Date weightDate;// 权重期限,超过期限,将weight设置为0
private User user; //关联用户
public Link() {
super();
this.weight = 0;
}
public Link(String id){
this();
this.id = id;
}
public Link(Category category){
this();
this.category = category;
}
@NotNull
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
@Length(min=1, max=255)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Length(min=0, max=50)
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Length(min=0, max=255)
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
@Length(min=0, max=255)
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public Date getWeightDate() {
return weightDate;
}
public void setWeightDate(Date weightDate) {
this.weightDate = weightDate;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.entity;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import com.jeespring.common.persistence.AbstractBaseEntity;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 站点Entity
* @author JeeSpring
* @version 2013-05-15
*/
public class Site extends AbstractBaseEntity<Site> {
private static final long serialVersionUID = 1L;
private String name; // 站点名称
private String title; // 站点标题
private String logo; // 站点logo
private String description;// 描述,填写有助于搜索引擎优化
private String keywords;// 关键字,填写有助于搜索引擎优化
private String theme; // 主题
private String copyright;// 版权信息
private String customIndexView;// 自定义首页视图文件
private String domain;
public Site() {
super();
}
public Site(String id){
this();
this.id = id;
}
@Length(min=1, max=100)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Length(min=1, max=100)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
@Length(min=0, max=255)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Length(min=0, max=255)
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
@Length(min=1, max=255)
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
public String getCustomIndexView() {
return customIndexView;
}
public void setCustomIndexView(String customIndexView) {
this.customIndexView = customIndexView;
}
/**
* 获取默认站点ID
*/
public static String defaultSiteId(){
return "1";
}
/**
* 判断是否为默认(主站)站点
*/
public static boolean isDefault(String id){
return id != null && id.equals(defaultSiteId());
}
/**
* 获取当前编辑的站点编号
*/
public static String getCurrentSiteId(){
String siteId = (String)UserUtils.getCache("siteId");
return StringUtils.isNotBlank(siteId)?siteId:defaultSiteId();
}
/**
* 模板路径
*/
public static final String TPL_BASE = "/WEB-INF/views/modules/cms/front/themes";
/**
* 获得模板方案路径。如:/WEB-INF/views/modules/cms/front/themes/jeesite
*
* @return
*/
public String getSolutionPath() {
return TPL_BASE + "/" + getTheme();
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 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.service.AbstractBaseService;
import com.jeespring.modules.cms.dao.ArticleDataDao;
import com.jeespring.modules.cms.entity.ArticleData;
/**
* 站点Service
* @author JeeSpring
* @version 2013-01-15
*/
@Service
@Transactional(readOnly = true)
public class ArticleDataService extends AbstractBaseService<ArticleDataDao, ArticleData> {
}
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.jeespring.common.redis.RedisUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.jeespring.common.config.Global;
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.ArticleDao;
import com.jeespring.modules.cms.dao.ArticleDataDao;
import com.jeespring.modules.cms.dao.CategoryDao;
import com.jeespring.modules.cms.entity.Article;
import com.jeespring.modules.cms.entity.ArticleData;
import com.jeespring.modules.cms.entity.Category;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 文章Service
* @author JeeSpring
* @version 2013-05-15
*/
@Service
@Transactional(readOnly = true)
public class ArticleService extends AbstractBaseService<ArticleDao, Article> {
@Autowired
private ArticleDataDao articleDataDao;
@Autowired
private CategoryDao categoryDao;
/**
* redis caches
*/
@Autowired
private RedisUtils redisUtils;
@Override
public Article get(String id) {
//获取缓存数据
Article article=(Article)redisUtils.get(RedisUtils.getIdKey(ArticleService.class.getName(),id));
if( article!=null) {
return article;
}
//获取数据库数据
article=super.get(id);
//设置缓存数据
redisUtils.set(RedisUtils.getIdKey(ArticleService.class.getName(),id),article);
return article;
}
@Transactional(readOnly = false)
public Page<Article> findPage(Page<Article> page, Article article, boolean isDataScopeFilter) {
//获取缓存数据
String findPageKey = RedisUtils.getFindPageKey(ArticleService.class.getName(), JSON.toJSONString(page)+JSON.toJSONString(article));
Page<Article> pageReuslt=(Page<Article>)redisUtils.get(findPageKey);
if(pageReuslt!=null) {
return pageReuslt;
}
// 更新过期的权重,间隔为“6”个小时
Date updateExpiredWeightDate = (Date)CacheUtils.get("updateExpiredWeightDateByArticle");
if (updateExpiredWeightDate == null || (updateExpiredWeightDate != null
&& updateExpiredWeightDate.getTime() < new Date().getTime())){
dao.updateExpiredWeight(article);
CacheUtils.put("updateExpiredWeightDateByArticle", DateUtils.addHours(new Date(), 6));
}
// DetachedCriteria dc = dao.createDetachedCriteria();
// dc.createAlias("category", "category");
// dc.createAlias("category.site", "category.site");
if (article.getCategory()!=null && StringUtils.isNotBlank(article.getCategory().getId()) && !Category.isRoot(article.getCategory().getId())){
Category category = categoryDao.get(article.getCategory().getId());
if (category==null){
category = new Category();
}
category.setParentIds(category.getId());
category.setSite(category.getSite());
article.setCategory(category);
}
else{
article.setCategory(new Category());
}
// if (StringUtils.isBlank(page.getOrderBy())){
// page.setOrderBy("a.weight,a.update_date desc");
// }
// return dao.find(page, dc);
// article.getSqlMap().put("dsf", dataScopeFilter(article.getCurrentUser(), "o", "u"));
pageReuslt=super.findPage(page, article);
//设置缓存数据
redisUtils.set(findPageKey,pageReuslt);
return pageReuslt;
}
@Override
@Transactional(readOnly = false)
public void save(Article article) {
if (article.getArticleData().getContent()!=null){
article.getArticleData().setContent(StringEscapeUtils.unescapeHtml4(
article.getArticleData().getContent()));
}
// 如果没有审核权限,则将当前内容改为待审核状态
if (!UserUtils.getSubject().isPermitted("cms:article:audit")){
article.setDelFlag(Article.DEL_FLAG_AUDIT);
}
// 如果栏目不需要审核,则将该内容设为发布状态
if (article.getCategory()!=null&&StringUtils.isNotBlank(article.getCategory().getId())){
Category category = categoryDao.get(article.getCategory().getId());
if (!Global.YES.equals(category.getIsAudit())){
article.setDelFlag(Article.DEL_FLAG_NORMAL);
}
}
article.setUpdateBy(UserUtils.getUser());
article.setUpdateDate(new Date());
if (StringUtils.isNotBlank(article.getViewConfig())){
article.setViewConfig(StringEscapeUtils.unescapeHtml4(article.getViewConfig()));
}
ArticleData articleData = new ArticleData();;
if (StringUtils.isBlank(article.getId())){
article.preInsert();
articleData = article.getArticleData();
articleData.setId(article.getId());
dao.insert(article);
articleDataDao.insert(articleData);
}else{
article.preUpdate();
articleData = article.getArticleData();
articleData.setId(article.getId());
dao.update(article);
articleDataDao.update(article.getArticleData());
}
//设置清除缓存数据
redisUtils.remove(RedisUtils.getIdKey(ArticleService.class.getName(),article.getId()));
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(ArticleService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(ArticleService.class.getName()));
}
@Transactional(readOnly = false)
public void delete(Article article, Boolean isRe) {
// dao.updateDelFlag(id, isRe!=null&&isRe?Article.DEL_FLAG_NORMAL:Article.DEL_FLAG_DELETE);
// 使用下面方法,以便更新索引。
//Article article = dao.get(id);
//article.setDelFlag(isRe!=null&&isRe?Article.DEL_FLAG_NORMAL:Article.DEL_FLAG_DELETE);
//dao.insert(article);
super.delete(article);
}
/**
* 通过编号获取内容标题
* @return new Object[]{栏目Id,文章Id,文章标题}
*/
public List<Object[]> findByIds(String ids) {
if(ids == null){
return new ArrayList<Object[]>();
}
List<Object[]> list = Lists.newArrayList();
String[] idss = StringUtils.split(ids,",");
Article e = null;
for(int i=0;(idss.length-i)>0;i++){
e = dao.get(idss[i]);
list.add(new Object[]{e.getCategory().getId(),e.getId(),StringUtils.abbr(e.getTitle(),50)});
}
return list;
}
/**
* 点击数加一
*/
@Transactional(readOnly = false)
public void updateHitsAddOne(String id) {
dao.updateHitsAddOne(id);
}
/**
* 更新索引
*/
public void createIndex(){
//dao.createIndex();
}
/**
* 全文检索
*/
//FIXME 暂不提供检索功能
public Page<Article> search(Page<Article> page, String q, String categoryId, String beginDate, String endDate){
// 设置查询条件
// BooleanQuery query = dao.getFullTextQuery(q, "title","keywords","description","articleData.content");
//
// // 设置过滤条件
// List<BooleanClause> bcList = Lists.newArrayList();
//
// bcList.add(new BooleanClause(new TermQuery(new Term(Article.FIELD_DEL_FLAG, Article.DEL_FLAG_NORMAL)), Occur.MUST));
// if (StringUtils.isNotBlank(categoryId)){
// bcList.add(new BooleanClause(new TermQuery(new Term("category.ids", categoryId)), Occur.MUST));
// }
//
// if (StringUtils.isNotBlank(beginDate) && StringUtils.isNotBlank(endDate)) {
// bcList.add(new BooleanClause(new TermRangeQuery("updateDate", beginDate.replaceAll("-", ""),
// endDate.replaceAll("-", ""), true, true), Occur.MUST));
// }
//BooleanQuery queryFilter = dao.getFullTextQuery((BooleanClause[])bcList.toArray(new BooleanClause[bcList.size()]));
// System.out.println(queryFilter);
// 设置排序(默认相识度排序)
//FIXME 暂时不提供lucene检索
//Sort sort = null;//new Sort(new SortField("updateDate", SortField.DOC, true));
// 全文检索
//dao.search(page, query, queryFilter, sort);
// 关键字高亮
//dao.keywordsHighlight(query, page.getList(), 30, "title");
//dao.keywordsHighlight(query, page.getList(), 130, "description","articleData.content");
return page;
}
}
/**
* Copyright &copy; 2012-2016 <a href="https://gitee.com/JeeHuangBingGui/jeeSpringCloud">JeeSpring</a>All rights reserved.
*/
package com.jeespring.modules.cms.service;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.service.TreeService;
import com.jeespring.modules.cms.dao.CategoryDao;
import com.jeespring.modules.cms.entity.Category;
import com.jeespring.modules.cms.entity.Site;
import com.jeespring.modules.cms.utils.CmsUtils;
import com.jeespring.modules.sys.entity.Office;
import com.jeespring.modules.sys.entity.User;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 栏目Service
* @author JeeSpring
* @version 2013-5-31
*/
@Service
@Transactional(readOnly = true)
public class CategoryService extends TreeService<CategoryDao, Category> {
public static final String CACHE_CATEGORY_LIST = "categoryList";
private Category entity = new Category();
@SuppressWarnings("unchecked")
public List<Category> findByUser(boolean isCurrentSite, String module){
List<Category> list = (List<Category>)UserUtils.getCache(CACHE_CATEGORY_LIST);
if (list == null){
User user = UserUtils.getUser();
Category category = new Category();
category.setOffice(new Office());
category.getSqlMap().put("dsf", dataScopeFilter(user, "o", "u"));
category.setSite(new Site());
category.setParent(new Category());
list = dao.findList(category);
// 将没有父节点的节点,找到父节点
Set<String> parentIdSet = Sets.newHashSet();
for (Category e : list){
if (e.getParent()!=null && StringUtils.isNotBlank(e.getParent().getId())){
boolean isExistParent = false;
for (Category e2 : list){
if (e.getParent().getId().equals(e2.getId())){
isExistParent = true;
break;
}
}
if (!isExistParent){
parentIdSet.add(e.getParent().getId());
}
}
}
if (parentIdSet.size() > 0){
//FIXME 暂且注释,用于测试
// dc = dao.createDetachedCriteria();
// dc.add(Restrictions.in("id", parentIdSet));
// dc.add(Restrictions.eq("delFlag", Category.DEL_FLAG_NORMAL));
// dc.addOrder(Order.asc("site.id")).addOrder(Order.asc("sort"));
// list.addAll(0, dao.find(dc));
}
UserUtils.putCache(CACHE_CATEGORY_LIST, list);
}
if (isCurrentSite){
List<Category> categoryList = Lists.newArrayList();
for (Category e : list){
if (Category.isRoot(e.getId()) || (e.getSite()!=null && e.getSite().getId() !=null
&& e.getSite().getId().equals(Site.getCurrentSiteId()))){
if (StringUtils.isNotEmpty(module)){
if (module.equals(e.getModule()) || "".equals(e.getModule())){
categoryList.add(e);
}
}else{
categoryList.add(e);
}
}
}
return categoryList;
}
return list;
}
public List<Category> findByParentId(String parentId, String siteId){
Category parent = new Category();
parent.setId(parentId);
entity.setParent(parent);
Site site = new Site();
site.setId(siteId);
entity.setSite(site);
return dao.findByParentIdAndSiteId(entity);
}
public Page<Category> find(Page<Category> page, Category category) {
// DetachedCriteria dc = dao.createDetachedCriteria();
// if (category.getSite()!=null && StringUtils.isNotBlank(category.getSite().getId())){
// dc.createAlias("site", "site");
// dc.add(Restrictions.eq("site.id", category.getSite().getId()));
// }
// if (category.getParent()!=null && StringUtils.isNotBlank(category.getParent().getId())){
// dc.createAlias("parent", "parent");
// dc.add(Restrictions.eq("parent.id", category.getParent().getId()));
// }
// if (StringUtils.isNotBlank(category.getInMenu()) && Category.SHOW.equals(category.getInMenu())){
// dc.add(Restrictions.eq("inMenu", category.getInMenu()));
// }
// dc.add(Restrictions.eq(Category.FIELD_DEL_FLAG, Category.DEL_FLAG_NORMAL));
// dc.addOrder(Order.asc("site.id")).addOrder(Order.asc("sort"));
// return dao.find(page, dc);
// page.setSpringPage(dao.findByParentId(category.getParent().getId(), page.getSpringPage()));
// return page;
category.setPage(page);
category.setInMenu(Global.SHOW);
page.setList(dao.findModule(category));
return page;
}
@Override
@Transactional(readOnly = false)
public void save(Category category) {
category.setSite(new Site(Site.getCurrentSiteId()));
if (StringUtils.isNotBlank(category.getViewConfig())){
category.setViewConfig(StringEscapeUtils.unescapeHtml4(category.getViewConfig()));
}
super.save(category);
UserUtils.removeCache(CACHE_CATEGORY_LIST);
CmsUtils.removeCache("mainNavList_"+category.getSite().getId());
}
@Override
@Transactional(readOnly = false)
public void delete(Category category) {
super.delete(category);
UserUtils.removeCache(CACHE_CATEGORY_LIST);
CmsUtils.removeCache("mainNavList_"+category.getSite().getId());
}
/**
* 通过编号获取栏目列表
*/
public List<Category> findByIds(String ids) {
List<Category> list = Lists.newArrayList();
String[] idss = StringUtils.split(ids,",");
if (idss.length>0){
// List<Category> l = dao.findByIdIn(idss);
// for (String id : idss){
// for (Category e : l){
// if (e.getId().equals(id)){
// list.add(e);
// break;
// }
// }
// }
for(String id : idss){
Category e = dao.get(id);
if(null != e){
//System.out.println("e.id:"+e.getId()+",e.name:"+e.getName());
list.add(e);
}
//list.add(dao.get(id));
}
}
return list;
}
}
/**
* Copyright &copy; 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.CommentDao;
import com.jeespring.modules.cms.entity.Comment;
/**
* 评论Service
* @author JeeSpring
* @version 2013-01-15
*/
@Service
@Transactional(readOnly = true)
public class CommentService extends AbstractBaseService<CommentDao, Comment> {
@Override
public Page<Comment> findPage(Page<Comment> page, Comment comment) {
// DetachedCriteria dc = commentDao.createDetachedCriteria();
// if (StringUtils.isNotBlank(comment.getContentId())){
// dc.add(Restrictions.eq("contentId", comment.getContentId()));
// }
// if (StringUtils.isNotEmpty(comment.getTitle())){
// dc.add(Restrictions.like("title", "%"+comment.getTitle()+"%"));
// }
// dc.add(Restrictions.eq(Comment.FIELD_DEL_FLAG, comment.getDelFlag()));
// dc.addOrder(Order.desc("id"));
// return commentDao.find(page, dc);
comment.getSqlMap().put("dsf", dataScopeFilter(comment.getCurrentUser(), "o", "u"));
return super.findPage(page, comment);
}
@Transactional(readOnly = false)
public void delete(Comment entity, Boolean isRe) {
super.delete(entity);
}
}
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;
}
}
}
/**
* Copyright &copy; 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;
}
}
/**
* Copyright &copy; 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;
}
}
/**
* Copyright &copy; 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");
}
}
/**
* Copyright &copy; 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;
}
}
/**
* Copyright &copy; 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
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;
}
}
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;
}
}
/**
* Copyright &copy; 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;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment