Java Code Examples for javax.persistence.criteria.CriteriaBuilder#isNotNull()

The following examples show how to use javax.persistence.criteria.CriteriaBuilder#isNotNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OkrCenterWorkInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 8 votes vote down vote up
/**
 * 查询中心工作创建者身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctCreatorIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrCenterWorkInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrCenterWorkInfo> root = cq.from(OkrCenterWorkInfo.class);
	
	Predicate p = cb.isNotNull( root.get( OkrCenterWorkInfo_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrCenterWorkInfo_.creatorIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrCenterWorkInfo_.creatorIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrCenterWorkInfo_.creatorIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 2
Source File: OkrWorkReportPersonLinkFactory.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * 根据身份名称,从工作汇报处理者信息中查询与该身份有关的所有信息列表
 * @param identity
 * @param recordId 
 * @return
 * @throws Exception 
 */
public List<OkrWorkReportPersonLink> listErrorIdentitiesInReportPersonInfo(String identity, String recordId) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkReportPersonLink.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<OkrWorkReportPersonLink> cq = cb.createQuery( OkrWorkReportPersonLink.class );
	Root<OkrWorkReportPersonLink> root = cq.from( OkrWorkReportPersonLink.class );
	Predicate p = cb.isNotNull(root.get( OkrWorkReportPersonLink_.id ));
	
	if( recordId != null && !recordId.isEmpty() && !"all".equals( recordId ) ){
		p = cb.and( p, cb.equal( root.get( OkrWorkReportPersonLink_.id ), recordId ) );
	}
	
	Predicate p_processorIdentity = cb.isNotNull(root.get( OkrWorkReportPersonLink_.processorIdentity ));
	p_processorIdentity = cb.and( p_processorIdentity, cb.equal( root.get( OkrWorkReportPersonLink_.processorIdentity ), identity ) );		
	p = cb.and( p, p_processorIdentity );
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 3
Source File: OkrWorkChatFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询工作交流信息发送者身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctSenderIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkChat.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrWorkChat> root = cq.from(OkrWorkChat.class);
	
	Predicate p = cb.isNotNull( root.get( OkrWorkChat_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkChat_.senderIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkChat_.senderIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrWorkChat_.senderIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 4
Source File: OkrStatisticReportStatusFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据身份名称,从工作汇报状态统计信息中查询与该身份有关的所有信息列表
 * @param identity
 * @param recordId 
 * @return
 * @throws Exception 
 */
public List<OkrStatisticReportStatus> listErrorIdentitiesInStReportStatus(String identity, String recordId) throws Exception {
	EntityManager em = this.entityManagerContainer().get( OkrStatisticReportStatus.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<OkrStatisticReportStatus> cq = cb.createQuery( OkrStatisticReportStatus.class );
	Root<OkrStatisticReportStatus> root = cq.from( OkrStatisticReportStatus.class );
	Predicate p = cb.isNotNull(root.get( OkrStatisticReportStatus_.id ));
	
	if( recordId != null && !recordId.isEmpty() && !"all".equals( recordId ) ){
		p = cb.and( p, cb.equal( root.get( OkrStatisticReportStatus_.id ), recordId ) );
	}
	
	Predicate p_responsibilityIdentity = cb.isNotNull(root.get( OkrStatisticReportStatus_.responsibilityIdentity ));
	p_responsibilityIdentity = cb.and( p_responsibilityIdentity, cb.equal( root.get( OkrStatisticReportStatus_.responsibilityIdentity ), identity ) );		
	p = cb.and( p, p_responsibilityIdentity );
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 5
Source File: OkrStatisticReportStatusFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询统计数据中工作责任者身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctResponsibilityIdentity( List<String> identities_ok, List<String> identities_error ) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrStatisticReportStatus.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrStatisticReportStatus> root = cq.from(OkrStatisticReportStatus.class);
	
	Predicate p = cb.isNotNull( root.get( OkrStatisticReportStatus_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrStatisticReportStatus_.responsibilityIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrStatisticReportStatus_.responsibilityIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrStatisticReportStatus_.responsibilityIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 6
Source File: MindBaseInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据条件搜索符合条件的脑图信息ID列表
 * @param folderId  所属目录ID
 * @param name	  脑图的名称(模糊搜索)
 * @param person  脑图的创建者
 * @param unit       脑图创建的组织
 * @param hasShared  是否已经分享过了
 * @return
 * @throws Exception
 */
public List<String> list( String folderId, String name, String person, String unit, Boolean hasShared ) throws Exception {
	EntityManager em = this.entityManagerContainer().get(MindBaseInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<MindBaseInfo> root = cq.from(MindBaseInfo.class);
	Predicate p = cb.isNotNull( root.get(MindBaseInfo_.id ) );
	if( folderId != null && !folderId.isEmpty() ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.id), folderId));
	}
	if( person != null && !person.isEmpty() ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.creator), person));
	}
	if( unit != null && !unit.isEmpty() ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.creatorUnit), unit));
	}
	if( hasShared != null ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.shared), hasShared));
	}
	if( name != null && !name.isEmpty() ){
		p = cb.and( p, cb.like( root.get( MindBaseInfo_.name ), "%" + name + "%" ));
	}
	cq.orderBy( cb.asc( root.get( MindBaseInfo_.updateTime ) ) );
	cq.select( root.get(MindBaseInfo_.id ) );
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 7
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据工作类别和登录身份来查询用户可以访问到的所有中心工作数量
 * 
 * @param workTypeName
 * @param loginIdentity
 * @return
 * @throws Exception
 */
public List<String> listCenterWorkIdsByWorkType(List<String> workTypeNames, String loginIdentity,
		String processIdentity) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	Predicate p = cb.isNotNull(root.get(OkrWorkPerson_.id));
	if (workTypeNames != null && !workTypeNames.isEmpty()) {
		p = cb.and(p, root.get(OkrWorkPerson_.workType).in(workTypeNames));
	}
	if (loginIdentity != null && !loginIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.employeeIdentity), loginIdentity));
	}
	if (processIdentity != null && !processIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), processIdentity));
	}
	cq.distinct(true).select(root.get(OkrWorkPerson_.centerId));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 8
Source File: MindBaseInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据条件搜索符合条件的脑图信息条目数量
 * @param folderId  所属目录ID
 * @param name	  脑图的名称(模糊搜索)
 * @param person  脑图的创建者
 * @param unit       脑图创建的组织
 * @param hasShared  是否已经分享过了
 * @return
 * @throws Exception
 */
public Long count( String folderId, String name, String person, String unit, Boolean hasShared ) throws Exception {
	EntityManager em = this.entityManagerContainer().get(MindBaseInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<MindBaseInfo> root = cq.from(MindBaseInfo.class);
	Predicate p = cb.isNotNull( root.get(MindBaseInfo_.id ) );
	if( folderId != null && !folderId.isEmpty() ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.id), folderId));
	}
	if( person != null && !person.isEmpty() ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.creator), person));
	}
	if( unit != null && !unit.isEmpty() ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.creatorUnit), unit));
	}
	if( hasShared != null ){
		p = cb.and( p, cb.equal( root.get( MindBaseInfo_.shared), hasShared));
	}
	if( name != null && !name.isEmpty() ){
		p = cb.and( p, cb.like( root.get( MindBaseInfo_.name ), "%" + name + "%" ));
	}
	cq.select( cb.count( root ) );
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 9
Source File: OkrTaskHandledFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询已办处理者身份列表(去重复)
 * @param identities_ok 排除身份
 * @param identities_error 排除身份
 * @return
 * @throws Exception 
 */
public List<String> listAllDistinctTargetIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrTaskHandled.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrTaskHandled> root = cq.from(OkrTaskHandled.class);
	
	Predicate p = cb.isNotNull( root.get( OkrTaskHandled_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrTaskHandled_.targetIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrTaskHandled_.targetIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrTaskHandled_.targetIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 10
Source File: NotEqualSpecification.java    From jpa-spec with MIT License 6 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    From from = getRoot(property, root);
    String field = getProperty(property);
    if (values == null) {
        return cb.isNotNull(from.get(field));
    }
    if (values.length == 1) {
        return getPredicate(from, cb, values[0], field);
    }
    Predicate[] predicates = new Predicate[values.length];
    for (int i = 0; i < values.length; i++) {
        predicates[i] = getPredicate(root, cb, values[i], field);
    }
    return cb.or(predicates);
}
 
Example 11
Source File: OkrWorkDynamicsFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询工作动态信息操作者身份列表(去重复)
 * 
 * @param identities_ok
 *            排除身份
 * @param identities_error
 *            排除身份
 * @return
 * @throws Exception
 */
public List<String> listAllDistinctTargetIdentity(List<String> identities_ok, List<String> identities_error)
		throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkDynamics.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkDynamics> root = cq.from(OkrWorkDynamics.class);

	Predicate p = cb.isNotNull(root.get(OkrWorkDynamics_.id));
	if (identities_ok != null && identities_ok.size() > 0) {
		p = cb.and(p, cb.not(root.get(OkrWorkDynamics_.targetIdentity).in(identities_ok)));
	}
	if (identities_error != null && identities_error.size() > 0) {
		p = cb.and(p, cb.not(root.get(OkrWorkDynamics_.targetIdentity).in(identities_error)));
	}
	cq.distinct(true).select(root.get(OkrWorkDynamics_.targetIdentity));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 12
Source File: OkrConfigSecretaryFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据身份名称,从领导秘书配置信息中查询与该身份有关的所有信息列表
 * @param identity
 * @param recordId 
 * @return
 * @throws Exception 
 */
public List<OkrConfigSecretary> listErrorIdentitiesInConfigSecretary(String identity, String recordId) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrConfigSecretary.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<OkrConfigSecretary> cq = cb.createQuery( OkrConfigSecretary.class );
	Root<OkrConfigSecretary> root = cq.from( OkrConfigSecretary.class );
	Predicate p = cb.isNotNull(root.get( OkrConfigSecretary_.id ));
	
	if( recordId != null && !recordId.isEmpty() && !"all".equals( recordId ) ){
		p = cb.and( p, cb.equal( root.get( OkrConfigSecretary_.id ), recordId ) );
	}
	
	Predicate p_leaderIdentity = cb.isNotNull(root.get( OkrConfigSecretary_.leaderIdentity ));
	p_leaderIdentity = cb.and( p_leaderIdentity, cb.equal( root.get( OkrConfigSecretary_.leaderIdentity ), identity ) );
	Predicate p_secretaryIdentity = cb.isNotNull(root.get( OkrConfigSecretary_.secretaryIdentity ));
	p_secretaryIdentity = cb.and( p_secretaryIdentity, cb.equal( root.get( OkrConfigSecretary_.secretaryIdentity ), identity ) );
	Predicate p_identity = cb.or( p_leaderIdentity, p_secretaryIdentity );
	p = cb.and( p, p_identity );
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 13
Source File: OkrWorkBaseInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listNeedReportWorkIds() throws Exception {
	EntityManager em = this.entityManagerContainer().get( OkrWorkBaseInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkBaseInfo> root = cq.from( OkrWorkBaseInfo.class);
	cq.select( root.get( OkrWorkBaseInfo_.id ) );
	Predicate p = cb.isNotNull( root.get( OkrWorkBaseInfo_.nextReportTime) );
	//下一次汇报时间早于当前时间
	p = cb.and( p, cb.lessThanOrEqualTo(root.get( OkrWorkBaseInfo_.nextReportTime ), new Date()));
	//未完成的工作
	p = cb.and( p, cb.isFalse( root.get( OkrWorkBaseInfo_.isCompleted ) ));
	p = cb.and( p, cb.equal( root.get( OkrWorkBaseInfo_.status ), "正常" ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 14
Source File: AttendanceDetailStatisticFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 根据员工,年月,统计签退次数
 * @param employeeNames
 * @param cycleYear
 * @param cycleMonth
 * @return
 * @throws Exception
 */
public Long countOffDutyByEmployeeCycleYearAndMonth( List<String> employeeNames, String cycleYear, String cycleMonth) throws Exception{
	if( employeeNames == null || employeeNames.size() == 0 ){
		logger.error( new EmployeeNamesEmptyException() );
		return null;
	}		
	EntityManager em = this.entityManagerContainer().get( AttendanceDetail.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<AttendanceDetail> root = cq.from( AttendanceDetail.class);
	Predicate p = cb.isNotNull(root.get( AttendanceDetail_.offDutyTime ));
	p = cb.and( p, cb.notEqual( root.get( AttendanceDetail_.offDutyTime), ""));
	p = cb.and( p, root.get( AttendanceDetail_.empName).in( employeeNames ));
	p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordStatus ), 1));
	if( cycleYear == null || cycleYear.isEmpty() ){
		logger.error( new CycleYearEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get( AttendanceDetail_.cycleYear), cycleYear));
	}
	if( cycleMonth == null || cycleMonth.isEmpty() ){
		logger.error( new CycleMonthEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get( AttendanceDetail_.cycleMonth), cycleMonth));
	}
	//查询总数
	cq.select( cb.count( root ) );
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 15
Source File: NotNull.java    From specification-arg-resolver with Apache License 2.0 5 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    if (converter.convert(expectedValue, Boolean.class)) {
        return cb.isNotNull(path(root));
    } else {
        return cb.isNull(path(root));
    }
}
 
Example 16
Source File: AppInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listAllAppType() throws Exception {
	EntityManager em = this.entityManagerContainer().get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	Predicate p = cb.isNotNull( root.get(AppInfo_.appType));
	cq.select(root.get(AppInfo_.appType)).distinct(true);
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 17
Source File: ProductSpecifications.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
public Specification<T> nameNotNull() {
  	return new Specification<T>() {
	@Override
	public Predicate toPredicate(Root<T> root,
			CriteriaQuery<?> query, CriteriaBuilder cb) {
              return cb.isNotNull(root.<String>get("name"));
	}
      };
}
 
Example 18
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 根据中心工作ID,工作ID来查询已经存在的工作干系人身份
 * 
 * @param centerId
 * @param workId
 * @param employeeName
 * @return
 * @throws Exception
 */
public List<String> listUserIndentityByWorkId(String centerId, String workId, String processIdentity,
		List<String> statuses) throws Exception {
	if (centerId == null || centerId.isEmpty()) {
		logger.warn("centerId is null!");
		return null;
	}
	if (workId == null || workId.isEmpty()) {
		logger.warn("workId is null!");
		return null;
	}
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	cq.select(root.get(OkrWorkPerson_.employeeIdentity));
	Predicate p = cb.isNotNull(root.get(OkrWorkPerson_.employeeIdentity));
	if (centerId != null && !centerId.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.centerId), centerId));
	}
	if (workId != null && !workId.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.workId), workId));
	}
	if (processIdentity != null && !processIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), processIdentity));
	}
	if (statuses != null && statuses.size() > 0) {
		p = cb.and(p, root.get(OkrWorkPerson_.status).in(statuses));
	}
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 19
Source File: SimpleSpecification.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Predicate generatePredicate(Root<T> root, CriteriaBuilder criteriaBuilder, SpecificationOperator op) {
	/*
	 * 根据不同的操作符返回特定的查询
	 */
	if (SpecificationOperator.Operator.eq.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.equal(root.get(op.getKey()), op.getValue());
	} else if (SpecificationOperator.Operator.ge.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.ge(root.get(op.getKey()).as(Number.class), (Number) op.getValue());
	} else if (SpecificationOperator.Operator.le.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.le(root.get(op.getKey()).as(Number.class), (Number) op.getValue());
	} else if (SpecificationOperator.Operator.gt.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.gt(root.get(op.getKey()).as(Number.class), (Number) op.getValue());
	} else if (SpecificationOperator.Operator.lt.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.lt(root.get(op.getKey()).as(Number.class), (Number) op.getValue());
	} else if (SpecificationOperator.Operator.likeAll.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.like(root.get(op.getKey()).as(String.class), "%" + op.getValue() + "%");
	} else if (SpecificationOperator.Operator.likeL.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.like(root.get(op.getKey()).as(String.class), op.getValue() + "%");
	} else if (SpecificationOperator.Operator.likeR.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.like(root.get(op.getKey()).as(String.class), "%" + op.getValue());
	} else if (SpecificationOperator.Operator.isNull.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.isNull(root.get(op.getKey()));
	} else if (SpecificationOperator.Operator.isNotNull.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.isNotNull(root.get(op.getKey()));
	} else if (SpecificationOperator.Operator.notEqual.name().equalsIgnoreCase(op.getOper())) {
		return criteriaBuilder.notEqual(root.get(op.getKey()), op.getValue());
	}
	return null;
}
 
Example 20
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 根据用户姓名,列示有权限访问的所有具体工作Id列表
 * 
 * @param name
 * @param statuses
 *            需要显示的信息状态: 正常|已删除
 * @return
 * @throws Exception
 */
// @MethodDescribe( "根据用户姓名,列示有权限访问的所有具体工作Id列表" )
public List<String> listDistinctWorkIdsByIdentity(String userIdentity, String centerId, List<String> statuses)
		throws Exception {
	if (userIdentity == null || userIdentity.isEmpty()) {
		logger.warn("userIdentity is null!");
		return null;
	}

	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	cq.distinct(true).select(root.get(OkrWorkPerson_.workId));

	/**
	 * 获取的时候过滤条件: 1、如果当前身份是创建者或者部署者的,那么,草稿也要取,如果当前身份不是创建者或者部署者,那么草稿不要去
	 * 2、信息状态是正常的才取出来 3、观察者是自己的取出来 状态正常 and ( ( 姓名 = name and 身份 in ( 部署者,
	 * 创建者 ) ) or ( 姓名 = name and 身份 in ( 协助者,阅知者 ) and 处理状态 != 草稿 ) )
	 */
	Predicate p = cb.isNotNull(root.get(OkrWorkPerson_.workId)); // 工作ID不为空的就是具体工作的权限信息
	if (centerId != null && !centerId.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.centerId), centerId));
	}
	if (statuses != null && statuses.size() > 0) {
		p = cb.and(p, root.get(OkrWorkPerson_.status).in(statuses));
	}

	List<String> identityList_1 = new ArrayList<String>();
	List<String> identityList_2 = new ArrayList<String>();
	identityList_1.add("部署者");
	identityList_1.add("创建者");
	// ( 姓名 = name and 身份 in ( 部署者, 创建者 ) )
	Predicate p_creator_or_depoloyer = cb.equal(root.get(OkrWorkPerson_.employeeIdentity), userIdentity);
	p_creator_or_depoloyer = cb.and(p_creator_or_depoloyer,
			root.get(OkrWorkPerson_.processIdentity).in(identityList_1));

	identityList_2.add("观察者");
	identityList_2.add("协助者");
	identityList_2.add("责任者");
	identityList_2.add("阅知者");
	identityList_2.add("授权者");
	// ( 姓名 = name and 身份 in ( 责任者,协助者,阅知者 ) and 处理状态 != 草稿 )
	Predicate p_watcher = cb.equal(root.get(OkrWorkPerson_.employeeIdentity), userIdentity);
	p_watcher = cb.and(p_watcher, root.get(OkrWorkPerson_.processIdentity).in(identityList_2));
	p_watcher = cb.and(p_watcher, cb.notEqual(root.get(OkrWorkPerson_.workProcessStatus), "草稿"));

	p = cb.and(p, cb.or(p_creator_or_depoloyer, p_watcher));

	return em.createQuery(cq.where(p)).setMaxResults(1000).getResultList();
}