提交 848c1d71 编写于 作者: Z zhourui

优先路由未删除待办

上级 77fcc23a
......@@ -10,6 +10,7 @@
"passwordRegexHint": "6位以上,包含数字和字母.",
"register": "disable",
"superPermission": true,
"personUnitOrderByAsc": true,
"###captchaLogin": "是否启用验证码登录,默认值:true###",
"###codeLogin": "是否启用验证码登录,默认值:true###",
"###bindLogin": "是否启用扫描二维码登录,默认值:false###",
......@@ -32,5 +33,6 @@
},
"###failureInterval": "登录限制时间(分钟)###",
"###failureCount": "尝试登录次数###",
"###tokenExpiredMinutes": "token时长,分钟###"
"###tokenExpiredMinutes": "token时长,分钟###",
"###personUnitOrderByAsc": "人员组织排序是否为升序,true为升序(默认),false为降序###"
}
\ No newline at end of file
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
package com.x.calendar.assemble.control;
import com.x.base.core.container.EntityManagerContainer;
import com.x.calendar.core.entity.Calendar_EventComment;
import java.util.Date;
import java.util.List;
public abstract class AbstractFactory {
private Business business;
public AbstractFactory(Business business) throws Exception {
try {
if (null == business) {
throw new Exception("business can not be null.");
}
this.business = business;
} catch (Exception e) {
throw new Exception("can not instantiating factory.");
}
}
public EntityManagerContainer entityManagerContainer() throws Exception {
return this.business.entityManagerContainer();
}
public Business business() throws Exception {
return this.business;
}
}
package com.x.calendar.assemble.control;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.x.base.core.project.Context;
@WebListener
public class ApplicationServletContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
ThisApplication.context = Context.concrete(servletContextEvent);
ThisApplication.init();
ThisApplication.context().regist();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
ThisApplication.destroy();
ThisApplication.context.destrory(servletContextEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.x.calendar.assemble.control;
import com.x.base.core.container.EntityManagerContainer;
import com.x.calendar.assemble.control.factory.*;
import com.x.organization.core.express.Organization;
public class Business {
private EntityManagerContainer emc;
public Business(EntityManagerContainer emc) throws Exception {
this.emc = emc;
}
public EntityManagerContainer entityManagerContainer() {
return this.emc;
}
private Organization organization;
public Organization organization() throws Exception {
if (null == this.organization) {
this.organization = new Organization(ThisApplication.context());
}
return organization;
}
private Calendar_SettingFactory calendar_SettingFactory;
public Calendar_SettingFactory calendar_SettingFactory() throws Exception {
if (null == this.calendar_SettingFactory) {
this.calendar_SettingFactory = new Calendar_SettingFactory( this );
}
return calendar_SettingFactory;
}
private CalendarFactory calendarFactory;
public CalendarFactory calendarFactory() throws Exception {
if (null == this.calendarFactory) {
this.calendarFactory = new CalendarFactory( this );
}
return calendarFactory;
}
private Calendar_EventFactory calendar_EventFactory;
public Calendar_EventFactory calendar_EventFactory() throws Exception {
if (null == this.calendar_EventFactory) {
this.calendar_EventFactory = new Calendar_EventFactory( this );
}
return calendar_EventFactory;
}
private Calendar_EventCommentFactory calendar_EventCommentFactory;
public Calendar_EventCommentFactory calendar_EventCommentFactory() throws Exception {
if (null == this.calendar_EventCommentFactory) {
this.calendar_EventCommentFactory = new Calendar_EventCommentFactory( this );
}
return calendar_EventCommentFactory;
}
private Calendar_EventRepeatMasterFactory calendar_EventRepeatMasterFactory;
public Calendar_EventRepeatMasterFactory calendar_EventRepeatMasterFactory() throws Exception {
if (null == this.calendar_EventRepeatMasterFactory) {
this.calendar_EventRepeatMasterFactory = new Calendar_EventRepeatMasterFactory( this );
}
return calendar_EventRepeatMasterFactory;
}
}
package com.x.calendar.assemble.control;
public enum EnumCalendarSource {
PERSON, LEADER, UNIT, MEETING, BUSINESS_TRIP, HOLIDAY
}
package com.x.calendar.assemble.control;
public enum EnumCalendarTaskType {
CALENDAR, TASK
}
\ No newline at end of file
package com.x.calendar.assemble.control;
public enum EnumRemindPolicy {
NONE, MIN_5, MIN_10, MIN_15, MIN_30, HOUR_1, DAY_1, DAY_2, WEEK_1
}
\ No newline at end of file
package com.x.calendar.assemble.control;
import com.google.gson.JsonElement;
import com.x.base.core.project.exception.PromptException;
public class ExceptionWrapInConvert extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionWrapInConvert( Throwable e, JsonElement jsonElement) {
super( "系统在将JSON信息转换为对象时发生异常。JSON:" + jsonElement.toString(), e);
}
}
package com.x.calendar.assemble.control;
import javax.activation.MimetypesFileTypeMap;
public class MimeTypeDefinition {
public static MimetypesFileTypeMap instance;
}
package com.x.calendar.assemble.control;
import com.x.base.core.project.Context;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.message.MessageConnector;
import com.x.base.core.project.tools.ListTools;
import com.x.calendar.assemble.control.schedule.AlarmTrigger;
import com.x.calendar.assemble.control.schedule.CheckEventComment;
import com.x.calendar.assemble.control.service.UserManagerService;
import com.x.calendar.core.entity.Calendar;
import com.x.calendar.core.entity.Calendar_Event;
import java.util.List;
public class ThisApplication {
protected static Context context;
public static final String CalendarMANAGER = "CalendarManager";
public static Context context() {
return context;
}
public static void init() throws Exception {
try {
MessageConnector.start(context());
//每30秒检查一次需要推送的消息
context.schedule(AlarmTrigger.class, "0/30 * * * * ?");
//每两小时检查一次comment信息的引用情况,删除多余的不必要的数据
context.schedule(CheckEventComment.class, "* * */2 * * ?");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void destroy() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 判断用户是否有Calendar系统管理权限 1、系统管理员Manager或者xadmin 2、拥有CalendarManager角色的人员
*
* @param effectivePerson
* @return
*/
public static Boolean isCalendarSystemManager(EffectivePerson effectivePerson) {
UserManagerService userManagerService = new UserManagerService();
try {
if (userManagerService.isHasPlatformRole(effectivePerson.getDistinguishedName(),
ThisApplication.CalendarMANAGER) || effectivePerson.isManager()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 判断用户是否拥有指定日历的管理权限
*
* @param effectivePerson
* @param calendar
* @return
*/
public static Boolean isCalendarManager(EffectivePerson effectivePerson, Calendar calendar) {
if (isCalendarSystemManager(effectivePerson)) {
return true;
}
if (calendar != null) {
// 判断管理权限
if (calendar.getCreateor().equalsIgnoreCase(effectivePerson.getDistinguishedName())) {
return true;
}
if (ListTools.isNotEmpty(calendar.getManageablePersonList())
&& calendar.getManageablePersonList().contains(effectivePerson.getDistinguishedName())) {
return true;
}
}
return false;
}
/**
* 判断用户是否拥有指定日历的日程事件发布权限
*
* @param effectivePerson
* @param calendar
* @return
*/
public static Boolean isCalendarPublisher(EffectivePerson effectivePerson, List<String> unitNames,
List<String> groupNames, Calendar calendar) {
if (isCalendarSystemManager(effectivePerson)) {
return true;
}
if (calendar != null) {
if (isCalendarManager(effectivePerson, calendar)) {
return true;
}
// 判断发布权限
String personName = effectivePerson.getDistinguishedName();
if (ListTools.isNotEmpty(calendar.getPublishablePersonList())
&& calendar.getPublishablePersonList().contains(personName)) {
return true;
}
if (ListTools.isNotEmpty(calendar.getPublishableUnitList()) && ListTools.isNotEmpty(unitNames)) {
for (String publishUnitName : calendar.getPublishableUnitList()) {
for (String unitName : unitNames) {
if (unitName.equalsIgnoreCase(publishUnitName)) {
return true;
}
}
}
}
if (ListTools.isNotEmpty(calendar.getPublishableGroupList()) && ListTools.isNotEmpty(groupNames)) {
for (String publishGroupName : calendar.getPublishableGroupList()) {
for (String groupName : groupNames) {
if (groupName.equalsIgnoreCase(publishGroupName)) {
return true;
}
}
}
}
}
return false;
}
/**
* 判断用户是否拥有指定日历的日程事件发布权限
*
* @param effectivePerson
* @param calendar
* @return
* @throws Exception
*/
public static Boolean isCalendarPublisher(EffectivePerson effectivePerson, Calendar calendar) throws Exception {
if (isCalendarSystemManager(effectivePerson)) {
return true;
}
List<String> unitNames = null;
List<String> groupNames = null;
if (calendar != null) {
if (isCalendarManager(effectivePerson, calendar)) {
return true;
}
UserManagerService userManagerService = new UserManagerService();
// 判断发布权限
String personName = effectivePerson.getDistinguishedName();
unitNames = userManagerService.listUnitNamesWithPerson(personName);
groupNames = userManagerService.listGroupNamesByPerson(personName);
if (ListTools.isNotEmpty(calendar.getPublishablePersonList())
&& calendar.getPublishablePersonList().contains(personName)) {
return true;
}
if (ListTools.isNotEmpty(calendar.getPublishableUnitList()) && ListTools.isNotEmpty(unitNames)) {
for (String publishUnitName : calendar.getPublishableUnitList()) {
for (String unitName : unitNames) {
if (unitName.equalsIgnoreCase(publishUnitName)) {
return true;
}
}
}
}
if (ListTools.isNotEmpty(calendar.getPublishableGroupList()) && ListTools.isNotEmpty(groupNames)) {
for (String publishGroupName : calendar.getPublishableGroupList()) {
for (String groupName : groupNames) {
if (groupName.equalsIgnoreCase(publishGroupName)) {
return true;
}
}
}
}
}
return false;
}
/**
* 判断用户是否拥有指定日程事件的管理权限
*
* @param effectivePerson
* @param event
* @return
* @throws Exception
*/
public static Boolean isEventManager(EffectivePerson effectivePerson, Calendar calendar, Calendar_Event event)
throws Exception {
if (isCalendarSystemManager(effectivePerson)) {
return true;
}
List<String> unitNames = null;
List<String> groupNames = null;
if (event != null) {
UserManagerService userManagerService = new UserManagerService();
String personName = effectivePerson.getDistinguishedName();
unitNames = userManagerService.listUnitNamesWithPerson(personName);
groupNames = userManagerService.listGroupNamesByPerson(personName);
// 判断日历的发布权限
if (isCalendarPublisher(effectivePerson, unitNames, groupNames, calendar)) {
return true;
}
// 判断事件的管理权限
if (ListTools.isNotEmpty(event.getManageablePersonList())
&& calendar.getManageablePersonList().contains(personName)) {
return true;
}
}
return false;
}
}
package com.x.calendar.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.tools.ListTools;
import com.x.calendar.assemble.control.AbstractFactory;
import com.x.calendar.assemble.control.Business;
import com.x.calendar.core.entity.Calendar;
import com.x.calendar.core.entity.Calendar_;
import com.x.calendar.core.tools.CriteriaBuilderTools;
/**
* 日历账户信息表功能服务类
* @author O2LEE
*/
public class CalendarFactory extends AbstractFactory {
public CalendarFactory( Business business) throws Exception {
super(business);
}
/**
* 获取指定Id的日历账户配置信息对象
* @param id
* @return
* @throws Exception
*/
public Calendar get( String id ) throws Exception {
return this.entityManagerContainer().find(id, Calendar.class );
}
/**
* 列示全部的日历账户配置信息列表
* @return
* @throws Exception
*/
@SuppressWarnings("unused")
public List<Calendar> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar> cq = cb.createQuery(Calendar.class);
Root<Calendar> root = cq.from( Calendar.class);
return em.createQuery(cq).getResultList();
}
/**
* 列示指定Id的日历账户配置信息列表
* @param ids
* @return
* @throws Exception
*/
public List<Calendar> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<Calendar>();
}
EntityManager em = this.entityManagerContainer().get(Calendar.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar> cq = cb.createQuery(Calendar.class);
Root<Calendar> root = cq.from(Calendar.class);
Predicate p = root.get( Calendar_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据条件查询指定的日历信息ID列表
* @param personName
* @param unitNames
* @param groupNames
* @param name
* @param type
* @param source
* @param createor
* @return
* @throws Exception
*/
public List<String> listWithCondition( String name, String type, String source, String createor, List<String> inFilterCalendarIds,
String personName, List<String> unitNames, List<String> groupNames ) throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar> root = cq.from(Calendar.class);
Predicate p = null;
if( ListTools.isNotEmpty( inFilterCalendarIds )) {
p = CriteriaBuilderTools.predicate_and( cb, p, root.get(Calendar_.id).in( inFilterCalendarIds ));
}
if( StringUtils.isNotEmpty( name )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_.name), name));
}
if( StringUtils.isNotEmpty( type )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_.type), type));
}
if( StringUtils.isNotEmpty( source )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_.source), source));
}
if( StringUtils.isNotEmpty( createor )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_.createor), createor));
}
Predicate permission = null;
if( StringUtils.isNotEmpty( personName )) {
permission = CriteriaBuilderTools.predicate_or( cb, permission, cb.isMember(personName, root.get(Calendar_.manageablePersonList)));
permission = CriteriaBuilderTools.predicate_or( cb, permission, cb.isMember(personName, root.get(Calendar_.publishablePersonList)));
permission = CriteriaBuilderTools.predicate_or( cb, permission, cb.isMember(personName, root.get(Calendar_.viewablePersonList)));
permission = CriteriaBuilderTools.predicate_or( cb, permission, cb.isMember(personName, root.get(Calendar_.followers)));
}
if( ListTools.isNotEmpty( unitNames )) {
permission = CriteriaBuilderTools.predicate_or( cb, permission, root.get(Calendar_.publishableUnitList).in( unitNames ));
permission = CriteriaBuilderTools.predicate_or( cb, permission, root.get(Calendar_.viewableUnitList).in( unitNames ));
}
if( ListTools.isNotEmpty( groupNames )) {
permission = CriteriaBuilderTools.predicate_or( cb, permission, root.get(Calendar_.publishableGroupList).in( groupNames ));
permission = CriteriaBuilderTools.predicate_or( cb, permission, root.get(Calendar_.viewableGroupList).in( groupNames ));
}
//permission = CriteriaBuilderTools.predicate_or( cb, permission, cb.isTrue( root.get(Calendar_.isPublic) ));
p = CriteriaBuilderTools.predicate_and( cb, p, permission );
cq.select(root.get(Calendar_.id));
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 查询我自己(可管理)的日历
* @param personName
* @return
* @throws Exception
*/
public List<String> listMyCalender( String personName ) throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar> root = cq.from(Calendar.class);
Predicate permission = cb.equal( root.get(Calendar_.createor), personName );
cq.select(root.get(Calendar_.id));
return em.createQuery(cq.where(permission)).getResultList();
}
public List<String> listPublicCalendar() throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar> root = cq.from(Calendar.class);
Predicate permission = cb.isTrue( root.get(Calendar_.isPublic) );
cq.select(root.get(Calendar_.id));
return em.createQuery(cq.where(permission)).getResultList();
}
}
\ No newline at end of file
package com.x.calendar.assemble.control.factory;
import com.x.base.core.project.tools.ListTools;
import com.x.calendar.assemble.control.AbstractFactory;
import com.x.calendar.assemble.control.Business;
import com.x.calendar.core.entity.*;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.Date;
import java.util.List;
/**
* 日历备注信息信息表功能服务类
* @author O2LEE
*/
public class Calendar_EventCommentFactory extends AbstractFactory {
public Calendar_EventCommentFactory(Business business) throws Exception {
super(business);
}
/**
* 获取指定Id的日历备注信息信息对象
* @param id
* @return
* @throws Exception
*/
public Calendar_EventComment get( String id ) throws Exception {
return this.entityManagerContainer().find(id, Calendar_EventComment.class );
}
/**
* 列示指定Id的日历备注信息信息列表
* @param ids
* @return
* @throws Exception
*/
public List<Calendar_EventComment> list( List<String> ids ) throws Exception {
if( ListTools.isEmpty( ids ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(Calendar_EventComment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar_EventComment> cq = cb.createQuery(Calendar_EventComment.class);
Root<Calendar_EventComment> root = cq.from(Calendar_EventComment.class);
Predicate p = root.get( Calendar_EventComment_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
public Long countEventBundle( String commentId ) throws Exception {
if( StringUtils.isEmpty( commentId ) ) {
return 0L;
}
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = cb.equal( root.get(Calendar_Event_.commentId ), commentId);
cq.select(cb.count(root)).where(p);
return em.createQuery(cq.where(p)).getSingleResult();
}
public Long countRepeatMasterBundle( String commentId ) throws Exception {
if( StringUtils.isEmpty( commentId ) ) {
return 0L;
}
EntityManager em = this.entityManagerContainer().get(Calendar_EventRepeatMaster.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Calendar_EventRepeatMaster> root = cq.from(Calendar_EventRepeatMaster.class);
Predicate p = cb.equal( root.get( Calendar_EventRepeatMaster_.commentId ), commentId);
cq.select(cb.count(root)).where(p);
return em.createQuery(cq.where(p)).getSingleResult();
}
/**
* 查询检查时间早于now的maxCount条记录的ID列表
* @param now
* @param maxCount
* @return
* @throws Exception
*/
public List<String> listNeedCheckCommnetIds( Date now, Integer maxCount) throws Exception {
if( now == null ) {
now = new Date();
}
if( maxCount == null ) {
maxCount = 1000;
}
EntityManager em = this.entityManagerContainer().get(Calendar_EventComment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_EventComment> root = cq.from(Calendar_EventComment.class);
Predicate p = cb.lessThan( root.get( Calendar_EventComment_.checkTime ), now );
cq.select(root.get(Calendar_EventComment_.id));
return em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList();
}
}
\ No newline at end of file
package com.x.calendar.assemble.control.factory;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.tools.ListTools;
import com.x.calendar.assemble.control.AbstractFactory;
import com.x.calendar.assemble.control.Business;
import com.x.calendar.core.entity.Calendar_Event;
import com.x.calendar.core.entity.Calendar_Event_;
import com.x.calendar.core.tools.CriteriaBuilderTools;
/**
* 日历任务记录信息表功能服务类
* @author O2LEE
*/
public class Calendar_EventFactory extends AbstractFactory {
public Calendar_EventFactory( Business business) throws Exception {
super(business);
}
/**
* 获取指定Id的日历任务记录信息对象
* @param id
* @return
* @throws Exception
*/
public Calendar_Event get( String id ) throws Exception {
return this.entityManagerContainer().find(id, Calendar_Event.class );
}
/**
* 列示指定Id的日历任务记录信息列表
* @param ids
* @return
* @throws Exception
*/
public List<Calendar_Event> list(List<String> ids) throws Exception {
if( ListTools.isEmpty( ids ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar_Event> cq = cb.createQuery(Calendar_Event.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = root.get( Calendar_Event_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listWithCalendarId(String calendarId) throws Exception {
if( StringUtils.isEmpty( calendarId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = cb.equal( root.get( Calendar_Event_.calendarId), calendarId);
cq.select(root.get(Calendar_Event_.id));
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据条件查询指定的日历信息ID列表
* @param key
* @param eventType
* @param source
* @param createPerson
* @param calendarIds
* @param personName
* @param unitNames
* @param groupNames
* @param startTime
* @param endTime
* @return
* @throws Exception
*/
public List<String> listWithCondition( String key, String eventType, String source, String createPerson, List<String> calendarIds,
String personName, List<String> unitNames, List<String> groupNames, Date startTime, Date endTime ) throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = null;
if( ListTools.isNotEmpty( calendarIds )) {
p = CriteriaBuilderTools.predicate_and( cb, p, root.get(Calendar_Event_.calendarId).in( calendarIds ));
}
if( StringUtils.isNotEmpty( eventType )) {
p =CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_Event_.eventType), eventType));
}
if( StringUtils.isNotEmpty( source )) {
p =CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_Event_.source), source));
}
if( StringUtils.isNotEmpty( createPerson )) {
p =CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_Event_.createPerson), createPerson));
}
if( startTime != null ) {
if( endTime == null ) {
throw new Exception("endTime is null!");
}else {
p =CriteriaBuilderTools.predicate_and( cb, p, cb.lessThanOrEqualTo( root.get(Calendar_Event_.startTime), endTime ));
p =CriteriaBuilderTools.predicate_and( cb, p, cb.greaterThanOrEqualTo( root.get(Calendar_Event_.endTime), startTime ));
}
}
//权限过滤
Predicate permission = null;
if( StringUtils.isNotEmpty( personName )) {
permission =CriteriaBuilderTools.predicate_or( cb, permission, cb.isMember(personName, root.get(Calendar_Event_.manageablePersonList)));
permission =CriteriaBuilderTools.predicate_or( cb, permission, cb.isMember(personName, root.get(Calendar_Event_.viewablePersonList)));
}
if( ListTools.isNotEmpty( unitNames )) {
permission =CriteriaBuilderTools.predicate_or( cb, permission, root.get(Calendar_Event_.viewableUnitList).in( unitNames ));
}
if( ListTools.isNotEmpty( groupNames )) {
permission =CriteriaBuilderTools.predicate_or( cb, permission, root.get(Calendar_Event_.viewableGroupList).in( groupNames ));
}
if( permission != null ) {
permission = CriteriaBuilderTools.predicate_or( cb, permission, cb.isTrue( root.get(Calendar_Event_.isPublic) ) );
}
p = CriteriaBuilderTools.predicate_and( cb, p, permission );
//模糊搜索
Predicate p_key = null;
if( StringUtils.isNotEmpty( key )) {
p_key = cb.like(root.get(Calendar_Event_.title), key);
p_key = CriteriaBuilderTools.predicate_or( cb, p_key, cb.like(root.get(Calendar_Event_.comment), key) );
}
p = CriteriaBuilderTools.predicate_and( cb, p, p_key );
cq.select(root.get(Calendar_Event_.id));
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据重复主体以及日期查询指定的日历记录信息ID列表
* @param repeatMasterId
* @param startTime
* @param endTime
* @return
* @throws Exception
*/
public List<String> listWithRepeatMaster( String repeatMasterId, Date startTime, Date endTime ) throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = null;
if( StringUtils.isNotEmpty( repeatMasterId )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal(root.get(Calendar_Event_.repeatMasterId), repeatMasterId));
}
if( startTime != null ) {
if( endTime == null ) {
//查询startTime之后的所有记录
p = CriteriaBuilderTools.predicate_and( cb, p, cb.greaterThanOrEqualTo( root.get(Calendar_Event_.startTime), startTime ));
}else {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.lessThanOrEqualTo( root.get(Calendar_Event_.startTime), endTime ));
p = CriteriaBuilderTools.predicate_and( cb, p, cb.greaterThanOrEqualTo( root.get(Calendar_Event_.endTime), startTime ));
}
}
cq.select(root.get(Calendar_Event_.id));
return em.createQuery(cq.where(p)).getResultList();
}
public long countWithRepeatMaster(String repeatMasterId) throws Exception {
if( StringUtils.isEmpty( repeatMasterId ) ){
throw new Exception("repeatMasterId is empty!");
}
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = cb.equal(root.get(Calendar_Event_.repeatMasterId), repeatMasterId);
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
/**
* 根据开始结束时间以及标题和重复主体ID
* @param calendar_Event
* @return
* @throws Exception
*/
public boolean eventExists( Calendar_Event calendar_Event ) throws Exception {
if( calendar_Event == null ){
throw new Exception("calendar_Event is null!");
}
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = cb.equal(root.get(Calendar_Event_.startTimeStr), calendar_Event.getStartTimeStr() );
p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(Calendar_Event_.endTimeStr), calendar_Event.getEndTimeStr() ) );
p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(Calendar_Event_.isAllDayEvent), calendar_Event.getIsAllDayEvent() ) );
p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(Calendar_Event_.title), calendar_Event.getTitle() ) );
if( StringUtils.isNotEmpty( calendar_Event.getRepeatMasterId() )) {
p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(Calendar_Event_.repeatMasterId), calendar_Event.getRepeatMasterId() ) );
}
cq.select( cb.count( root ) );
Long count = em.createQuery(cq.where(p)).getSingleResult();
if( count > 0 ) {
return true;
}
return false;
}
public List<String> listNeedAlarmEventIds(Date date) throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = cb.lessThanOrEqualTo( root.get(Calendar_Event_.alarmTime), date );
p = cb.and( p, cb.isFalse( root.get(Calendar_Event_.alarmAlready ) ));
cq.select(root.get(Calendar_Event_.id));
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listWithBundle(String bundle) throws Exception {
if( StringUtils.isEmpty( bundle ) ) {
throw new Exception("bundle is null!");
}
EntityManager em = this.entityManagerContainer().get(Calendar_Event.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_Event> root = cq.from(Calendar_Event.class);
Predicate p = cb.equal( root.get(Calendar_Event_.bundle ), bundle);
cq.select(root.get(Calendar_Event_.id));
return em.createQuery(cq.where(p)).getResultList();
}
}
\ No newline at end of file
package com.x.calendar.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.calendar.assemble.control.AbstractFactory;
import com.x.calendar.assemble.control.Business;
import com.x.calendar.core.entity.Calendar_Setting;
import com.x.calendar.core.entity.Calendar_Setting_;
/**
* 系统配置信息表基础功能服务类
* @author O2LEE
*/
public class Calendar_SettingFactory extends AbstractFactory {
public Calendar_SettingFactory( Business business) throws Exception {
super(business);
}
/**
* 获取指定Id的Calendar_Setting配置信息对象
* @param id
* @return
* @throws Exception
*/
public Calendar_Setting get( String id ) throws Exception {
return this.entityManagerContainer().find(id, Calendar_Setting.class, ExceptionWhen.none);
}
/**
* 列示全部的Calendar_Setting配置信息列表
* @return
* @throws Exception
*/
@SuppressWarnings("unused")
public List<Calendar_Setting> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(Calendar_Setting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar_Setting> cq = cb.createQuery(Calendar_Setting.class);
Root<Calendar_Setting> root = cq.from( Calendar_Setting.class);
return em.createQuery(cq).getResultList();
}
/**
* 列示指定Id的Calendar_Setting配置信息列表
* @param ids
* @return
* @throws Exception
*/
public List<Calendar_Setting> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<Calendar_Setting>();
}
EntityManager em = this.entityManagerContainer().get(Calendar_Setting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar_Setting> cq = cb.createQuery(Calendar_Setting.class);
Root<Calendar_Setting> root = cq.from(Calendar_Setting.class);
Predicate p = root.get( Calendar_Setting_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据CODE列示指定Id的Calendar_Setting配置信息列表
* @param code
* @return
* @throws Exception
*/
public List<String> listIdsByCode(String code) throws Exception {
if( code == null || code.isEmpty() ){
return null;
}
EntityManager em = this.entityManagerContainer().get(Calendar_Setting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Calendar_Setting> root = cq.from(Calendar_Setting.class);
Predicate p = cb.equal(root.get(Calendar_Setting_.configCode), code);
cq.select(root.get(Calendar_Setting_.id));
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据配置编码查询配置信息对象
* @param configCode
* @return
* @throws Exception
*/
public Calendar_Setting getWithConfigCode( String configCode ) throws Exception {
if( configCode == null || configCode.isEmpty() ){
return null;
}
Calendar_Setting attendanceSetting = null;
List<Calendar_Setting> settingList = null;
EntityManager em = this.entityManagerContainer().get(Calendar_Setting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Calendar_Setting> cq = cb.createQuery(Calendar_Setting.class);
Root<Calendar_Setting> root = cq.from(Calendar_Setting.class);
Predicate p = cb.equal(root.get( Calendar_Setting_.configCode ), configCode );
settingList = em.createQuery(cq.where(p)).getResultList();
if( settingList != null && settingList.size() > 0 ){
attendanceSetting = settingList.get(0);
}
return attendanceSetting;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册