From 67f61bfc32b8543df8864870d164a082b54af0ad Mon Sep 17 00:00:00 2001 From: thinkgem Date: Thu, 29 Aug 2013 22:47:18 +0800 Subject: [PATCH] update fix --- bin/refresh-db/cms/jeesite_mysql.sql | 14 ++--- bin/refresh-db/cms/jeesite_oracle.sql | 14 ++--- bin/refresh-db/oa/jeesite_mysql.sql | 2 +- bin/refresh-db/oa/jeesite_oracle.sql | 4 +- bin/refresh-db/sys/jeesite_mysql.sql | 20 +++---- bin/refresh-db/sys/jeesite_oracle.sql | 18 +++---- pom.xml | 4 +- .../jeesite/common/utils/DateUtils.java | 7 +++ .../jeesite/modules/cms/entity/Article.java | 7 ++- .../modules/cms/entity/ArticleData.java | 6 ++- .../modules/cms/web/ArticleController.java | 9 ++++ .../jeesite/modules/sys/dao/AreaDao.java | 2 +- .../jeesite/modules/sys/entity/Area.java | 13 +++-- .../jeesite/modules/sys/entity/Menu.java | 5 +- .../jeesite/modules/sys/entity/Office.java | 13 +++-- .../sys/security/SystemAuthorizingRealm.java | 4 +- .../modules/sys/service/SystemService.java | 20 +++---- .../jeesite/modules/sys/utils/UserUtils.java | 54 ++++++++++++++++--- .../WEB-INF/views/modules/sys/dictList.jsp | 2 +- src/main/webapp/WEB-INF/web.xml | 2 +- 20 files changed, 145 insertions(+), 75 deletions(-) diff --git a/bin/refresh-db/cms/jeesite_mysql.sql b/bin/refresh-db/cms/jeesite_mysql.sql index fc619b3865..7135fdab70 100644 --- a/bin/refresh-db/cms/jeesite_mysql.sql +++ b/bin/refresh-db/cms/jeesite_mysql.sql @@ -35,7 +35,7 @@ CREATE TABLE cms_article remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '文章表'; +) ENGINE=InnoDB COMMENT = '文章表'; CREATE TABLE cms_article_data @@ -46,7 +46,7 @@ CREATE TABLE cms_article_data relation varchar(255) COMMENT '相关文章', allow_comment char(1) COMMENT '是否允许评论', PRIMARY KEY (id) -) COMMENT = '文章详表'; +) ENGINE=InnoDB COMMENT = '文章详表'; CREATE TABLE cms_category @@ -78,7 +78,7 @@ CREATE TABLE cms_category remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '栏目表'; +) ENGINE=InnoDB COMMENT = '栏目表'; CREATE TABLE cms_comment @@ -95,7 +95,7 @@ CREATE TABLE cms_comment audit_date datetime COMMENT '审核时间', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '评论表'; +) ENGINE=InnoDB COMMENT = '评论表'; CREATE TABLE cms_guestbook @@ -114,7 +114,7 @@ CREATE TABLE cms_guestbook re_content varchar(100) COMMENT '回复内容', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '留言板'; +) ENGINE=InnoDB COMMENT = '留言板'; CREATE TABLE cms_link @@ -134,7 +134,7 @@ CREATE TABLE cms_link remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '友情链接'; +) ENGINE=InnoDB COMMENT = '友情链接'; CREATE TABLE cms_site @@ -156,7 +156,7 @@ CREATE TABLE cms_site remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '站点表'; +) ENGINE=InnoDB COMMENT = '站点表'; diff --git a/bin/refresh-db/cms/jeesite_oracle.sql b/bin/refresh-db/cms/jeesite_oracle.sql index ffa809cf57..ce204a2504 100644 --- a/bin/refresh-db/cms/jeesite_oracle.sql +++ b/bin/refresh-db/cms/jeesite_oracle.sql @@ -26,13 +26,13 @@ DROP SEQUENCE seq_cms_site; /* Create Sequences */ -CREATE SEQUENCE seq_cms_article INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_cms_article_data INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_cms_category INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_cms_comment INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_cms_guestbook INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_cms_link INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_cms_site INCREMENT BY 1 START WITH 1; +CREATE SEQUENCE seq_cms_article INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_cms_article_data INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_cms_category INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_cms_comment INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_cms_guestbook INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_cms_link INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_cms_site INCREMENT BY 1 START WITH 100; diff --git a/bin/refresh-db/oa/jeesite_mysql.sql b/bin/refresh-db/oa/jeesite_mysql.sql index 33d089a4dc..b837fc6a34 100644 --- a/bin/refresh-db/oa/jeesite_mysql.sql +++ b/bin/refresh-db/oa/jeesite_mysql.sql @@ -27,7 +27,7 @@ CREATE TABLE oa_leave remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -); +) ENGINE=InnoDB ; diff --git a/bin/refresh-db/oa/jeesite_oracle.sql b/bin/refresh-db/oa/jeesite_oracle.sql index e6e0ee3c5d..cfd51e96b7 100644 --- a/bin/refresh-db/oa/jeesite_oracle.sql +++ b/bin/refresh-db/oa/jeesite_oracle.sql @@ -15,8 +15,8 @@ DROP SEQUENCE SEQ_oa_leave_id; /* Create Sequences */ -CREATE SEQUENCE seq_oa_leave INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE SEQ_oa_leave_id INCREMENT BY 1 START WITH 1; +CREATE SEQUENCE seq_oa_leave INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE SEQ_oa_leave_id INCREMENT BY 1 START WITH 100; diff --git a/bin/refresh-db/sys/jeesite_mysql.sql b/bin/refresh-db/sys/jeesite_mysql.sql index 214ba85905..a96885d626 100644 --- a/bin/refresh-db/sys/jeesite_mysql.sql +++ b/bin/refresh-db/sys/jeesite_mysql.sql @@ -34,7 +34,7 @@ CREATE TABLE sys_area remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '区域表'; +) ENGINE=InnoDB COMMENT = '区域表'; CREATE TABLE sys_dict @@ -52,7 +52,7 @@ CREATE TABLE sys_dict remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '字典表'; +) ENGINE=InnoDB COMMENT = '字典表'; CREATE TABLE sys_log @@ -86,7 +86,7 @@ CREATE TABLE sys_mdict remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '区域表'; +) ENGINE=InnoDB COMMENT = '区域表'; CREATE TABLE sys_menu @@ -108,7 +108,7 @@ CREATE TABLE sys_menu remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '菜单表'; +) ENGINE=InnoDB COMMENT = '菜单表'; CREATE TABLE sys_office @@ -134,7 +134,7 @@ CREATE TABLE sys_office remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '部门表'; +) ENGINE=InnoDB COMMENT = '部门表'; CREATE TABLE sys_role @@ -152,7 +152,7 @@ CREATE TABLE sys_role remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '角色表'; +) ENGINE=InnoDB COMMENT = '角色表'; CREATE TABLE sys_role_menu @@ -160,7 +160,7 @@ CREATE TABLE sys_role_menu role_id bigint NOT NULL COMMENT '角色编号', menu_id bigint NOT NULL COMMENT '菜单编号', PRIMARY KEY (role_id, menu_id) -) COMMENT = '角色-菜单'; +) ENGINE=InnoDB COMMENT = '角色-菜单'; CREATE TABLE sys_role_office @@ -168,7 +168,7 @@ CREATE TABLE sys_role_office role_id bigint NOT NULL COMMENT '角色编号', office_id bigint NOT NULL COMMENT '机构编号', PRIMARY KEY (role_id, office_id) -) COMMENT = '角色-机构'; +) ENGINE=InnoDB COMMENT = '角色-机构'; CREATE TABLE sys_user @@ -193,7 +193,7 @@ CREATE TABLE sys_user remarks varchar(255) COMMENT '备注信息', del_flag char(1) DEFAULT '0' NOT NULL COMMENT '删除标记(0:正常;1:删除)', PRIMARY KEY (id) -) COMMENT = '用户表'; +) ENGINE=InnoDB COMMENT = '用户表'; CREATE TABLE sys_user_role @@ -201,7 +201,7 @@ CREATE TABLE sys_user_role user_id bigint NOT NULL COMMENT '用户编号', role_id bigint NOT NULL COMMENT '角色编号', PRIMARY KEY (user_id, role_id) -) COMMENT = '用户-角色'; +) ENGINE=InnoDB COMMENT = '用户-角色'; diff --git a/bin/refresh-db/sys/jeesite_oracle.sql b/bin/refresh-db/sys/jeesite_oracle.sql index 9f8b76bb26..f02a49da8a 100644 --- a/bin/refresh-db/sys/jeesite_oracle.sql +++ b/bin/refresh-db/sys/jeesite_oracle.sql @@ -32,15 +32,15 @@ DROP SEQUENCE seq_sys_user; /* Create Sequences */ -CREATE SEQUENCE hibernate_sequence INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_area INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_dict INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_log INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_mdict INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_menu INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_office INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_role INCREMENT BY 1 START WITH 1; -CREATE SEQUENCE seq_sys_user INCREMENT BY 1 START WITH 1; +CREATE SEQUENCE hibernate_sequence INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_area INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_dict INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_log INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_mdict INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_menu INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_office INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_role INCREMENT BY 1 START WITH 100; +CREATE SEQUENCE seq_sys_user INCREMENT BY 1 START WITH 100; diff --git a/pom.xml b/pom.xml index 1f6e350499..a580435854 100644 --- a/pom.xml +++ b/pom.xml @@ -225,12 +225,12 @@ org.hibernate hibernate-core ${hibernate.version} - + org.hibernate hibernate-ehcache diff --git a/src/main/java/com/thinkgem/jeesite/common/utils/DateUtils.java b/src/main/java/com/thinkgem/jeesite/common/utils/DateUtils.java index a988b3155c..c75ef2e795 100644 --- a/src/main/java/com/thinkgem/jeesite/common/utils/DateUtils.java +++ b/src/main/java/com/thinkgem/jeesite/common/utils/DateUtils.java @@ -46,6 +46,13 @@ public static String formatDate(Date date, Object... pattern) { } return formatDate; } + + /** + * 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss) + */ + public static String formatDateTime(Date date) { + return formatDate(date, "yyyy-MM-dd HH:mm:ss"); + } /** * 得到当前时间字符串 格式(HH:mm:ss) diff --git a/src/main/java/com/thinkgem/jeesite/modules/cms/entity/Article.java b/src/main/java/com/thinkgem/jeesite/modules/cms/entity/Article.java index b31cc603c6..d2380c6da5 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/cms/entity/Article.java +++ b/src/main/java/com/thinkgem/jeesite/modules/cms/entity/Article.java @@ -16,6 +16,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; +import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; import javax.persistence.Transient; import javax.validation.Valid; @@ -50,7 +51,7 @@ @Table(name = "cms_article") @DynamicInsert @DynamicUpdate @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) -@Indexed @Analyzer(impl = IKAnalyzer.class) +//@Indexed @Analyzer(impl = IKAnalyzer.class) public class Article extends DataEntity { private static final long serialVersionUID = 1L; @@ -192,7 +193,9 @@ public void setPosid(String posid) { this.posid = posid; } - @OneToOne(mappedBy="article",cascade=CascadeType.ALL,optional=false) +// @OneToOne(mappedBy="article",cascade=CascadeType.ALL,optional=false) + @OneToOne(cascade=CascadeType.ALL) + @PrimaryKeyJoinColumn @Valid @IndexedEmbedded public ArticleData getArticleData() { diff --git a/src/main/java/com/thinkgem/jeesite/modules/cms/entity/ArticleData.java b/src/main/java/com/thinkgem/jeesite/modules/cms/entity/ArticleData.java index a6a14784ec..24f8522d90 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/cms/entity/ArticleData.java +++ b/src/main/java/com/thinkgem/jeesite/modules/cms/entity/ArticleData.java @@ -106,8 +106,10 @@ public void setAllowComment(String allowComment) { this.allowComment = allowComment; } - @OneToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE},optional=false) - @PrimaryKeyJoinColumn +// @OneToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE},optional=false) +// @PrimaryKeyJoinColumn + @OneToOne(mappedBy="articleData",cascade=CascadeType.ALL) + @PrimaryKeyJoinColumn public Article getArticle() { return article; } diff --git a/src/main/java/com/thinkgem/jeesite/modules/cms/web/ArticleController.java b/src/main/java/com/thinkgem/jeesite/modules/cms/web/ArticleController.java index cee9157ddf..e88038f111 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/cms/web/ArticleController.java +++ b/src/main/java/com/thinkgem/jeesite/modules/cms/web/ArticleController.java @@ -27,6 +27,7 @@ import com.thinkgem.jeesite.common.utils.StringUtils; import com.thinkgem.jeesite.common.web.BaseController; import com.thinkgem.jeesite.modules.cms.entity.Article; +import com.thinkgem.jeesite.modules.cms.entity.ArticleData; import com.thinkgem.jeesite.modules.cms.entity.Category; import com.thinkgem.jeesite.modules.cms.entity.Site; import com.thinkgem.jeesite.modules.cms.service.ArticleService; @@ -58,6 +59,14 @@ public Article get(@RequestParam(required=false) Long id) { @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
page = articleService.find(new Page
(request, response), article, true); model.addAttribute("page", page); return "modules/cms/articleList"; diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/dao/AreaDao.java b/src/main/java/com/thinkgem/jeesite/modules/sys/dao/AreaDao.java index 62764516b0..2fdccc7d92 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/dao/AreaDao.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/dao/AreaDao.java @@ -30,7 +30,7 @@ public List findAllList(){ } public List findAllChild(Long parentId, String likeParentIds){ - return find("from Area where delFlag=:p1 and (id=p2 or parent.id=:p2 or parentIds like :p3) order by code", + return find("from Area where delFlag=:p1 and (id=:p2 or parent.id=:p2 or parentIds like :p3) order by code", new Parameter(Area.DEL_FLAG_NORMAL, parentId, likeParentIds)); } } diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Area.java b/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Area.java index 329410205c..44f17d5d81 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Area.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Area.java @@ -14,6 +14,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; @@ -25,6 +26,8 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.Where; @@ -124,9 +127,10 @@ public void setCode(String code) { this.code = code; } - @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="area") +// @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="area") + @OneToMany(mappedBy = "area", fetch=FetchType.LAZY) @Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'") - @OrderBy(value="code") + @OrderBy(value="code") @Fetch(FetchMode.SUBSELECT) @NotFound(action = NotFoundAction.IGNORE) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public List getOfficeList() { @@ -137,9 +141,10 @@ public void setOfficeList(List officeList) { this.officeList = officeList; } - @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent") +// @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent") + @OneToMany(mappedBy = "parent", fetch=FetchType.LAZY) @Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'") - @OrderBy(value="code") + @OrderBy(value="code") @Fetch(FetchMode.SUBSELECT) @NotFound(action = NotFoundAction.IGNORE) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public List getChildList() { diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Menu.java b/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Menu.java index adfb5538e6..d4c6738e57 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Menu.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Menu.java @@ -168,9 +168,10 @@ public void setPermission(String permission) { this.permission = permission; } - @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent") +// @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent") + @OneToMany(mappedBy = "parent", fetch=FetchType.LAZY) @Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'") - @OrderBy(value="sort") + @OrderBy(value="sort") @Fetch(FetchMode.SUBSELECT) @NotFound(action = NotFoundAction.IGNORE) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public List getChildList() { diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Office.java b/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Office.java index 4dcf9e46c3..0b5e19cb3b 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Office.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/entity/Office.java @@ -14,6 +14,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; @@ -25,6 +26,8 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.Where; @@ -207,9 +210,10 @@ public void setCode(String code) { this.code = code; } - @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="office") +// @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="office") + @OneToMany(mappedBy = "office", fetch=FetchType.LAZY) @Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'") - @OrderBy(value="id") + @OrderBy(value="id") @Fetch(FetchMode.SUBSELECT) @NotFound(action = NotFoundAction.IGNORE) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public List getUserList() { @@ -220,9 +224,10 @@ public void setUserList(List userList) { this.userList = userList; } - @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent") +// @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent") + @OneToMany(mappedBy = "parent", fetch=FetchType.LAZY) @Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'") - @OrderBy(value="code") + @OrderBy(value="code") @Fetch(FetchMode.SUBSELECT) @NotFound(action = NotFoundAction.IGNORE) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public List getChildList() { diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/security/SystemAuthorizingRealm.java b/src/main/java/com/thinkgem/jeesite/modules/sys/security/SystemAuthorizingRealm.java index 8b1e88120a..ac63fec377 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/security/SystemAuthorizingRealm.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/security/SystemAuthorizingRealm.java @@ -90,7 +90,9 @@ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal for (Menu menu : list){ if (StringUtils.isNotBlank(menu.getPermission())){ // 添加基于Permission的权限信息 - info.addStringPermission(menu.getPermission()); + for (String permission : StringUtils.split(menu.getPermission(),",")){ + info.addStringPermission(permission); + } } } // 更新登录IP和时间 diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/service/SystemService.java b/src/main/java/com/thinkgem/jeesite/modules/sys/service/SystemService.java index 491fc446a2..6db6323a9f 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/service/SystemService.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/service/SystemService.java @@ -17,7 +17,6 @@ import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.hibernate.sql.JoinType; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -43,7 +42,7 @@ */ @Service @Transactional(readOnly = true) -public class SystemService extends BaseService implements InitializingBean { +public class SystemService extends BaseService { public static final String HASH_ALGORITHM = "SHA-1"; public static final int HASH_INTERATIONS = 1024; @@ -112,7 +111,9 @@ public void saveUser(User user) { userDao.clear(); userDao.save(user); systemRealm.clearAllCachedAuthorizationInfo(); - // 同步到Activiti + // 如果从未同步过,则与Activiti同步 + synActivitiIndetity(); + // 将当前用户同步到Activiti saveActivitiUser(user, user.getId()==null); } @@ -166,14 +167,7 @@ public Role findRoleByName(String name) { } public List findAllRole(){ - User user = UserUtils.getUser(); - DetachedCriteria dc = roleDao.createDetachedCriteria(); - dc.createAlias("office", "office"); - dc.createAlias("userList", "userList", JoinType.LEFT_OUTER_JOIN); - dc.add(dataScopeFilter(user, "office", "userList")); - dc.add(Restrictions.eq(Role.FIELD_DEL_FLAG, Role.DEL_FLAG_NORMAL)); - dc.addOrder(Order.asc("office.code")).addOrder(Order.asc("name")); - return roleDao.find(dc); + return UserUtils.getRoleList(); } @Transactional(readOnly = false) @@ -183,6 +177,7 @@ public void saveRole(Role role) { systemRealm.clearAllCachedAuthorizationInfo(); // 同步到Activiti saveActivitiGroup(role, role.getId()==null); + UserUtils.removeCache(UserUtils.CACHE_ROLE_LIST); } @Transactional(readOnly = false) @@ -191,6 +186,7 @@ public void deleteRole(Long id) { systemRealm.clearAllCachedAuthorizationInfo(); // 同步到Activiti deleteActivitiGroup(roleDao.get(id)); + UserUtils.removeCache(UserUtils.CACHE_ROLE_LIST); } @Transactional(readOnly = false) @@ -259,7 +255,7 @@ public void deleteMenu(Long id) { * 是需要同步Activiti数据,如果从未同步过,则同步数据。 */ private static boolean isSynActivitiIndetity = true; - public void afterPropertiesSet() throws Exception { + public void synActivitiIndetity() { if (isSynActivitiIndetity){ isSynActivitiIndetity = false; List groupList = identityService.createGroupQuery().list(); diff --git a/src/main/java/com/thinkgem/jeesite/modules/sys/utils/UserUtils.java b/src/main/java/com/thinkgem/jeesite/modules/sys/utils/UserUtils.java index 4235ea837b..f2dafce755 100644 --- a/src/main/java/com/thinkgem/jeesite/modules/sys/utils/UserUtils.java +++ b/src/main/java/com/thinkgem/jeesite/modules/sys/utils/UserUtils.java @@ -10,10 +10,12 @@ import org.apache.shiro.SecurityUtils; import org.apache.shiro.UnavailableSecurityManagerException; +import org.apache.shiro.session.InvalidSessionException; import org.apache.shiro.subject.Subject; import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; +import org.hibernate.sql.JoinType; import com.google.common.collect.Maps; import com.thinkgem.jeesite.common.service.BaseService; @@ -21,10 +23,12 @@ import com.thinkgem.jeesite.modules.sys.dao.AreaDao; import com.thinkgem.jeesite.modules.sys.dao.MenuDao; import com.thinkgem.jeesite.modules.sys.dao.OfficeDao; +import com.thinkgem.jeesite.modules.sys.dao.RoleDao; import com.thinkgem.jeesite.modules.sys.dao.UserDao; import com.thinkgem.jeesite.modules.sys.entity.Area; import com.thinkgem.jeesite.modules.sys.entity.Menu; import com.thinkgem.jeesite.modules.sys.entity.Office; +import com.thinkgem.jeesite.modules.sys.entity.Role; import com.thinkgem.jeesite.modules.sys.entity.User; import com.thinkgem.jeesite.modules.sys.security.SystemAuthorizingRealm.Principal; @@ -34,13 +38,15 @@ * @version 2013-5-29 */ public class UserUtils extends BaseService { - + private static UserDao userDao = SpringContextHolder.getBean(UserDao.class); + private static RoleDao roleDao = SpringContextHolder.getBean(RoleDao.class); private static MenuDao menuDao = SpringContextHolder.getBean(MenuDao.class); private static AreaDao areaDao = SpringContextHolder.getBean(AreaDao.class); private static OfficeDao officeDao = SpringContextHolder.getBean(OfficeDao.class); public static final String CACHE_USER = "user"; + public static final String CACHE_ROLE_LIST = "roleList"; public static final String CACHE_MENU_LIST = "menuList"; public static final String CACHE_AREA_LIST = "areaList"; public static final String CACHE_OFFICE_LIST = "officeList"; @@ -48,15 +54,29 @@ public class UserUtils extends BaseService { public static User getUser(){ User user = (User)getCache(CACHE_USER); if (user == null){ - Principal principal = (Principal)SecurityUtils.getSubject().getPrincipal(); - if (principal!=null){ - user = userDao.get(principal.getId()); - putCache(CACHE_USER, user); + try{ + Subject subject = SecurityUtils.getSubject(); + Principal principal = (Principal)subject.getPrincipal(); + if (principal!=null){ + user = userDao.get(principal.getId()); +// Hibernate.initialize(user.getRoleList()); + putCache(CACHE_USER, user); + } + }catch (UnavailableSecurityManagerException e) { + + }catch (InvalidSessionException e){ + } } if (user == null){ user = new User(); - SecurityUtils.getSubject().logout(); + try{ + SecurityUtils.getSubject().logout(); + }catch (UnavailableSecurityManagerException e) { + + }catch (InvalidSessionException e){ + + } } return user; } @@ -68,6 +88,23 @@ public static User getUser(boolean isRefresh){ return getUser(); } + public static List getRoleList(){ + @SuppressWarnings("unchecked") + List list = (List)getCache(CACHE_ROLE_LIST); + if (list == null){ + User user = getUser(); + DetachedCriteria dc = roleDao.createDetachedCriteria(); + dc.createAlias("office", "office"); + dc.createAlias("userList", "userList", JoinType.LEFT_OUTER_JOIN); + dc.add(dataScopeFilter(user, "office", "userList")); + dc.add(Restrictions.eq(Role.FIELD_DEL_FLAG, Role.DEL_FLAG_NORMAL)); + dc.addOrder(Order.asc("office.code")).addOrder(Order.asc("name")); + list = roleDao.find(dc); + putCache(CACHE_ROLE_LIST, list); + } + return list; + } + public static List getMenuList(){ @SuppressWarnings("unchecked") List menuList = (List)getCache(CACHE_MENU_LIST); @@ -144,8 +181,11 @@ public static Map getCacheMap(){ Principal principal = (Principal)subject.getPrincipal(); return principal!=null?principal.getCacheMap():map; }catch (UnavailableSecurityManagerException e) { - return map; + + }catch (InvalidSessionException e){ + } + return map; } } diff --git a/src/main/webapp/WEB-INF/views/modules/sys/dictList.jsp b/src/main/webapp/WEB-INF/views/modules/sys/dictList.jsp index 76e3d0988d..0c13c20f6c 100644 --- a/src/main/webapp/WEB-INF/views/modules/sys/dictList.jsp +++ b/src/main/webapp/WEB-INF/views/modules/sys/dictList.jsp @@ -27,7 +27,7 @@ - + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 1457232a49..e035769069 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -186,7 +186,7 @@ - 20 + 200
标签键值类型描述排序操作
键值标签类型描述排序操作