javax.persistence.criteria.CriteriaQuery Java Examples

The following examples show how to use javax.persistence.criteria.CriteriaQuery. 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: ActionListWithIdentityObject.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
private List<Wo> list(Business business, Wi wi) throws Exception {
	List<Wo> wos = new ArrayList<>();
	List<Identity> os = business.identity().pick(wi.getIdentityList());
	List<String> ids = ListTools.extractProperty(os, JpaObject.id_FIELDNAME, String.class, true, true);
	EntityManager em = business.entityManagerContainer().get(Identity.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Identity> root = cq.from(Identity.class);
	Predicate p = root.get(Identity_.id).in(ids);
	List<String> unitIds = em.createQuery(cq.select(root.get(Identity_.unit)).where(p).distinct(true))
			.getResultList();
	unitIds = ListTools.trim(unitIds, true, true);
	for (Unit o : business.unit().pick(unitIds)) {
		wos.add(this.convert(business, o, Wo.class));
	}
	return wos;
}
 
Example #2
Source File: ActionListWithUnitSubNestedLikeObject.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<String> people(Business business, Wi wi) throws Exception {
	List<Unit> os = business.unit().pick(wi.getUnitList());
	List<String> unitIds = new ArrayList<>();
	for (Unit o : os) {
		unitIds.add(o.getId());
		unitIds.addAll(business.unit().listSubNested(o.getId()));
	}
	unitIds = ListTools.trim(unitIds, true, true);
	EntityManager em = business.entityManagerContainer().get(Identity.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Identity> root = cq.from(Identity.class);
	Predicate p = root.get(Identity_.unit).in(unitIds);
	List<String> list = em.createQuery(cq.select(root.get(Identity_.person)).where(p).distinct(true))
			.getResultList();
	return list;
}
 
Example #3
Source File: JpaUserDao.java    From angular-rest-springsecurity with Apache License 2.0 6 votes vote down vote up
@Override
@Transactional(readOnly = true)
public User findByName(String name)
{
    final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder();
    final CriteriaQuery<User> criteriaQuery = builder.createQuery(this.entityClass);

    Root<User> root = criteriaQuery.from(this.entityClass);
    Path<String> namePath = root.get("name");
    criteriaQuery.where(builder.equal(namePath, name));

    TypedQuery<User> typedQuery = this.getEntityManager().createQuery(criteriaQuery);
    List<User> users = typedQuery.getResultList();

    if (users.isEmpty()) {
        return null;
    }

    return users.iterator().next();
}
 
Example #4
Source File: StatisticUnitForMonthFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据顶层组织名称,统计年月,统计顶层组织所有人员请假人次总和
 * @param topUnitNames
 * @param cycleYear
 * @param cycleMonth
 * @return
 * @throws Exception
 */
public Double sumOnSelfHolidayCountByTopUnitNamesYearAndMonth( List<String> topUnitNames, String cycleYear, String cycleMonth ) throws Exception{
	if( topUnitNames == null || topUnitNames.size() == 0 ){
		logger.error( new TopUnitNamesEmptyException() );
		return null;
	}	
	EntityManager em = this.entityManagerContainer().get( StatisticUnitForMonth.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Double> cq = cb.createQuery(Double.class);
	Root<StatisticUnitForMonth> root = cq.from( StatisticUnitForMonth.class);		
	//查询总数
	cq.select( cb.sum( root.get(StatisticUnitForMonth_.onSelfHolidayCount) ) );		
	Predicate p = root.get(StatisticUnitForMonth_.topUnitName).in( topUnitNames );
	if( cycleYear == null || cycleYear.isEmpty() ){
		logger.error( new CycleYearEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticUnitForMonth_.statisticYear), cycleYear));
	}
	if( cycleMonth == null || cycleMonth.isEmpty() ){
		logger.error( new CycleMonthEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get(StatisticUnitForMonth_.statisticMonth), cycleMonth));
	}
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #5
Source File: ApplicationView.java    From tutorials with MIT License 6 votes vote down vote up
public String[] nullCriteria() {
    final Session session = HibernateUtil.getHibernateSession();
    final CriteriaBuilder cb = session.getCriteriaBuilder();
    final CriteriaQuery<Item> cr = cb.createQuery(Item.class);
    final Root<Item> root = cr.from(Item.class);
    cr.select(root)
        .where(cb.isNull(root.get("itemDescription")));
    // cr.add(Restrictions.isNull("itemDescription"));
    Query<Item> query = session.createQuery(cr);
    final List<Item> nullItemsList = query.getResultList();
    final String nullDescItems[] = new String[nullItemsList.size()];
    for (int i = 0; i < nullItemsList.size(); i++) {
        nullDescItems[i] = nullItemsList.get(i)
            .getItemName();
    }
    session.close();
    return nullDescItems;
}
 
Example #6
Source File: OkrConfigSystemFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public String getValueWithConfigCode(String configCode) throws Exception {
	if( configCode == null || configCode.isEmpty() ){
		throw new Exception( "config code is null, can not find any system config!" );
	}
	EntityManager em = this.entityManagerContainer().get(OkrConfigSystem.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<OkrConfigSystem> root = cq.from(OkrConfigSystem.class);
	Predicate p = cb.equal( root.get( OkrConfigSystem_.configCode ), configCode );
	cq.select(root.get(OkrConfigSystem_.configValue));
	//System.out.println("SQL:" + em.createQuery(cq.where(p)).toString() );
	List<String> valueList = em.createQuery(cq.where(p)).getResultList();
	if( valueList != null && valueList.size() > 0 ){
		//System.out.println("valueList.get(0):" + valueList.get(0) );
		return valueList.get(0);
	}
	return null;
}
 
Example #7
Source File: OkrConfigSecretaryFactory.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> listAllDistinctLeaderIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrConfigSecretary.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrConfigSecretary> root = cq.from(OkrConfigSecretary.class);
	
	Predicate p = cb.isNotNull( root.get( OkrConfigSecretary_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrConfigSecretary_.leaderIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrConfigSecretary_.leaderIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrConfigSecretary_.leaderIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example #8
Source File: AttendanceDetailStatisticFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据顶层组织,打卡日期月,统计请假天数
 * @param topUnitNames
 * @param recordDate
 * @return
 * @throws Exception
 */
public Double sumOnSelfHolidayDaysByTopUnitAndDate( List<String> topUnitNames, String recordDate ) throws Exception{
	if( topUnitNames == null || topUnitNames.size() == 0 ){
		logger.error( new TopUnitNamesEmptyException() );
		return null;
	}		
	EntityManager em = this.entityManagerContainer().get( AttendanceDetail.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Double> cq = cb.createQuery(Double.class);
	Root<AttendanceDetail> root = cq.from( AttendanceDetail.class);			
	Predicate p = root.get( AttendanceDetail_.topUnitName ).in( topUnitNames );
	p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordStatus ), 1));
	if( recordDate == null || recordDate.isEmpty() ){
		logger.error( new RecordDateEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordDateString ), recordDate));
	}		
	//查询总数
	cq.select( cb.sum( root.get( AttendanceDetail_.getSelfHolidayDays ) ) );	
			
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #9
Source File: OkrWorkBaseInfoFactory.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> listAllDistinctDeployerIdentity( List<String> identities_ok, List<String> identities_error ) 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);
	
	Predicate p = cb.isNotNull( root.get( OkrWorkBaseInfo_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkBaseInfo_.deployerIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkBaseInfo_.deployerIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrWorkBaseInfo_.deployerIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example #10
Source File: TestCriteriaConstructor.java    From HibernateTips with MIT License 6 votes vote down vote up
@Test
public void selectPojo() {
	log.info("... selectPojo ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<AuthorValue> q = cb.createQuery(AuthorValue.class);
	Root<Author> root = q.from(Author.class);
	q.select(cb.construct(AuthorValue.class, root.get(Author_.firstName), root.get(Author_.lastName)));

	TypedQuery<AuthorValue> query = em.createQuery(q);
	List<AuthorValue> authors = query.getResultList();

	for (AuthorValue author : authors) {
		log.info(author.getFirstName() + " "
				+ author.getLastName());
	}

	em.getTransaction().commit();
	em.close();
}
 
Example #11
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Long getCompletedWorkCountByCenterId(String identity, List<String> status, String processIdentity)
		throws Exception {
	if (identity == null || identity.isEmpty()) {
		throw new Exception("identity is null.");
	}
	if (status == null || status.isEmpty()) {
		throw new Exception("status is null.");
	}
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	Predicate p = root.get(OkrWorkPerson_.status).in(status);
	p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.employeeIdentity), identity));
	p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.workProcessStatus), "已完成"));
	if (processIdentity != null && !processIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), processIdentity));
	}
	// 查询总数
	cq.select(cb.count(root));
	// logger.info( ">>>>getCompletedWorkCountByCenterId-SQL:" +
	// em.createQuery(cq.where(p)).toString() );
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #12
Source File: V2ListCreatePaging.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size, JsonElement jsonElement)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		EntityManager em = emc.get(Review.class);
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
		Root<Review> root = cq.from(Review.class);
		Predicate p = cb.equal(root.get(Review_.creatorPerson), effectivePerson.getDistinguishedName());
		p = cb.and(p, this.toFilterPredicate(effectivePerson, business, wi));
		List<Wo> wos = emc.fetchDescPaging(Review.class, Wo.copier, p, page, size, Review.sequence_FIELDNAME);
		result.setData(wos);
		result.setCount(emc.count(Review.class, p));
		this.relate(business, result.getData(), wi);
		return result;
	}
}
 
Example #13
Source File: OkrWorkPersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public Long getOvertimenessWorkCountByCenterId(String identity, List<String> status, String processIdentity)
		throws Exception {
	if (identity == null || identity.isEmpty()) {
		throw new Exception("identity is null.");
	}
	if (status == null || status.isEmpty()) {
		throw new Exception("status is null.");
	}
	EntityManager em = this.entityManagerContainer().get(OkrWorkPerson.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<OkrWorkPerson> root = cq.from(OkrWorkPerson.class);
	Predicate p = root.get(OkrWorkPerson_.status).in(status);
	p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.employeeIdentity), identity));
	p = cb.and(p, cb.isFalse(root.get(OkrWorkPerson_.isOverTime)));
	if (processIdentity != null && !processIdentity.isEmpty()) {
		p = cb.and(p, cb.equal(root.get(OkrWorkPerson_.processIdentity), processIdentity));
	}
	// 查询总数
	cq.select(cb.count(root));
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #14
Source File: ReviewFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<String> checkTaskIdsWithPermission(List<String> taskIds, String personName) throws Exception {
	if( ListTools.isEmpty( taskIds ) ) {
		throw new Exception("taskIds can not be empty!");
	}
	if( StringUtils.isEmpty( personName ) ) {
		throw new Exception("personName can not be empty!");
	}
	EntityManager em = this.entityManagerContainer().get( Review.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<Review> root = cq.from( Review.class );
	Predicate p = cb.equal( root.get( Review_.permissionObj ), personName );
	p = cb.and( p, root.get( Review_.taskId ).in( taskIds ));
	p = cb.and( p, cb.equal( root.get( Review_.deleted ), false ));
	cq.select(root.get( Review_.taskId)).where(p);
	return em.createQuery( cq ).getResultList();
}
 
Example #15
Source File: RestoreData.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T> void clean(Class<T> cls, EntityManager em) throws Exception {
	List<T> list = null;
	do {
		if (ListTools.isNotEmpty(list)) {
			em.getTransaction().begin();
			for (T t : list) {
				em.remove(t);
			}
			em.getTransaction().commit();
		}
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<T> cq = cb.createQuery(cls);
		Root<T> root = cq.from(cls);
		cq.select(root);
		list = em.createQuery(cq).setMaxResults(Config.dumpRestoreData().getBatchSize()).getResultList();
	} while (ListTools.isNotEmpty(list));
}
 
Example #16
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> listStartTimeMonthPair(Business business, EffectivePerson effectivePerson)
		throws Exception {
	EntityManager em = business.entityManagerContainer().get(TaskCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<TaskCompleted> root = cq.from(TaskCompleted.class);
	Predicate p = cb.equal(root.get(TaskCompleted_.person), effectivePerson.getDistinguishedName());
	p = cb.and(p,
			cb.or(cb.equal(root.get(TaskCompleted_.latest), true), cb.isNull(root.get(TaskCompleted_.latest))));
	cq.select(root.get(TaskCompleted_.startTimeMonth)).where(p).distinct(true);
	List<String> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> wos = new ArrayList<>();
	for (String str : os) {
		if (StringUtils.isNotEmpty(str)) {
			NameValueCountPair o = new NameValueCountPair();
			o.setValue(str);
			o.setName(str);
			wos.add(o);
		}
	}
	SortTools.desc(wos, "name");
	return wos;
}
 
Example #17
Source File: PersonFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<String> listSubDirect(String id) throws Exception {
	List<String> list = new ArrayList<>();
	if (StringUtils.isEmpty(id)) {
		return list;
	}
	Person person = this.pick(id);
	if (null == person) {
		return list;
	}
	EntityManager em = this.entityManagerContainer().get(Person.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Person> root = cq.from(Person.class);
	Predicate p = cb.equal(root.get(Person_.superior), person.getId());
	list = em.createQuery(cq.select(root.get(Person_.id)).where(p).distinct(true)).getResultList();
	return list;
}
 
Example #18
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> listActivityName(Business business, EffectivePerson effectivePerson,
		Application application) throws Exception {
	List<NameValueCountPair> wos = new ArrayList<>();
	EntityManager em = business.entityManagerContainer().get(Work.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Work> root = cq.from(Work.class);
	Predicate p = cb.equal(root.get(Work_.application), application.getId());
	p = cb.and(p, cb.equal(root.get(Work_.creatorPerson), effectivePerson.getDistinguishedName()));
	cq.select(root.get(Work_.activityName)).where(p).distinct(true);
	List<String> list = em.createQuery(cq).getResultList();
	for (String str : list) {
		NameValueCountPair o = new NameValueCountPair();
		o.setValue(str);
		o.setName(str);
		wos.add(o);
	}
	SortTools.asc(wos, "name");
	return wos;
}
 
Example #19
Source File: OkrWorkReportProcessLogFactory.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> listAllDistinctProcessorIdentity(List<String> identities_ok, List<String> identities_error) throws Exception {
	EntityManager em = this.entityManagerContainer().get(OkrWorkReportProcessLog.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<OkrWorkReportProcessLog> root = cq.from(OkrWorkReportProcessLog.class);
	Predicate p = cb.isNotNull( root.get( OkrWorkReportProcessLog_.id ) );
	if( identities_ok != null && identities_ok.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkReportProcessLog_.processorIdentity ).in( identities_ok )) );
	}
	if( identities_error != null && identities_error.size() > 0 ){
		p = cb.and( p, cb.not(root.get( OkrWorkReportProcessLog_.processorIdentity ).in( identities_error )) );
	}
	cq.distinct(true).select(root.get( OkrWorkReportProcessLog_.processorIdentity ));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example #20
Source File: SecurityFunctionDaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public SecurityFunctionEntity getSecurityFunctionByName(String securityFunctionName)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<SecurityFunctionEntity> criteria = builder.createQuery(SecurityFunctionEntity.class);

    // The criteria root is the security role function.
    Root<SecurityFunctionEntity> securityFunctionEntity = criteria.from(SecurityFunctionEntity.class);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(securityFunctionEntity.get(SecurityFunctionEntity_.code)), securityFunctionName.toUpperCase()));

    // Add the clauses for the query.
    criteria.select(securityFunctionEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    return executeSingleResultQuery(criteria,
        String.format("Found more than one security function with parameters {securityFunctionName=\"%s\"}.", securityFunctionName));
}
 
Example #21
Source File: SecurityRoleDaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public SecurityRoleEntity getSecurityRoleByName(String securityRoleName)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<SecurityRoleEntity> criteria = builder.createQuery(SecurityRoleEntity.class);

    // The criteria root is the security role.
    Root<SecurityRoleEntity> securityRoleEntity = criteria.from(SecurityRoleEntity.class);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(securityRoleEntity.get(SecurityRoleEntity_.code)), securityRoleName.toUpperCase()));

    // Add the clauses for the query.
    criteria.select(securityRoleEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    return executeSingleResultQuery(criteria,
        String.format("Found more than one security role with parameters {securityRoleName=\"%s\"}.", securityRoleName));
}
 
Example #22
Source File: AttendanceDetailStatisticFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据员工,打卡日期月,统计请假天数
 * @param unitNames
 * @param recordDate
 * @return
 * @throws Exception
 */
public Double sumOnSelfHolidayDaysByUnitAndDate( List<String> unitNames, String recordDate ) throws Exception{
	if( unitNames == null || unitNames.size() == 0 ){
		logger.error( new UnitNamesEmptyException() );
		return null;
	}		
	EntityManager em = this.entityManagerContainer().get( AttendanceDetail.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Double> cq = cb.createQuery(Double.class);
	Root<AttendanceDetail> root = cq.from( AttendanceDetail.class);			
	Predicate p = root.get( AttendanceDetail_.unitName ).in( unitNames );
	p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordStatus ), 1));
	if( recordDate == null || recordDate.isEmpty() ){
		logger.error( new RecordDateEmptyException() );
	}else{
		p = cb.and( p, cb.equal( root.get( AttendanceDetail_.recordDateString ), recordDate));
	}		
	//查询总数
	cq.select( cb.sum( root.get( AttendanceDetail_.getSelfHolidayDays ) ) );	
			
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example #23
Source File: FileInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 列示指定文档的所有云文件图片信息ID列表
 * @param doucmentId 指定的文档ID
 * @return
 * @throws Exception 
 */
//@MethodDescribe("列示指定文档的所有云文件图片信息ID列表")
public List<String> listCloudPictureByDocument(String documentId) throws Exception {
	if( StringUtils.isEmpty(documentId) ){
		throw new Exception("内容管理listByDocument方法不接受document为空的查询操作!");
	}		
	EntityManager em = this.entityManagerContainer().get( FileInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class );
	Root<FileInfo> root = cq.from( FileInfo.class );		
	Predicate p = cb.equal(root.get( FileInfo_.documentId ), documentId);
	p = cb.and( p, cb.equal(root.get( FileInfo_.fileExtType ), "PICTURE") );
	p = cb.and( p, cb.equal(root.get( FileInfo_.fileType ), "CLOUD") );
	cq.select(root.get(FileInfo_.id));
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example #24
Source File: UserNamespaceAuthorizationDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getUserIdsWithWriteOrWriteDescriptiveContentPermissionsByNamespace(NamespaceEntity namespaceEntity)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);

    // The criteria root is the user namespace authorization.
    Root<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntityRoot = criteria.from(UserNamespaceAuthorizationEntity.class);

    // Get the user id column.
    Path<String> userIdColumn = userNamespaceAuthorizationEntityRoot.get(UserNamespaceAuthorizationEntity_.userId);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(userNamespaceAuthorizationEntityRoot.get(UserNamespaceAuthorizationEntity_.namespace), namespaceEntity));
    predicates.add(builder.or(builder.isTrue(userNamespaceAuthorizationEntityRoot.get(UserNamespaceAuthorizationEntity_.writePermission)),
        builder.isTrue(userNamespaceAuthorizationEntityRoot.get(UserNamespaceAuthorizationEntity_.writeDescriptiveContentPermission))));

    // Order by user id.
    Order orderBy = builder.asc(userNamespaceAuthorizationEntityRoot.get(UserNamespaceAuthorizationEntity_.userId));

    // Add all clauses to the query.
    criteria.select(userIdColumn).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);

    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}
 
Example #25
Source File: DocumentElementDAOImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAvaibleDocumentStatus() {
	final CriteriaQuery<String> criteria = getCriteriaBuilder()
			.createQuery(String.class);
	final Root<DocumentElement> root = criteria.from(DocumentElement.class);
	criteria.select(root.get(DocumentElement_.id));
	criteria.where(getCriteriaBuilder().isNotNull(
			root.get(DocumentElement_.documentStatusUrlXml)));
	return getEntityManager().createQuery(criteria).getResultList();
}
 
Example #26
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listFutureWithRoom(String roomId, boolean allowOnly) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), new Date());
	p = cb.and(p, cb.equal(root.get(Meeting_.room), roomId));
	p = cb.and(p, cb.equal(root.get(Meeting_.manualCompleted), false));
	if (allowOnly) {
		p = cb.and(p, cb.equal(root.get(Meeting_.confirmStatus), ConfirmStatus.allow));
	}
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example #27
Source File: CalendarFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 列示全部的日历账户配置信息列表
 * @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();
}
 
Example #28
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWithPersonWaitConfirm(String person) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.completedTime), new Date());
	p = cb.and(p, cb.equal(root.get(Meeting_.confirmStatus), ConfirmStatus.wait));
	p = cb.and(p,
			cb.or(cb.equal(root.get(Meeting_.applicant), person), cb.equal(root.get(Meeting_.auditor), person),
					cb.isMember(person, root.get(Meeting_.invitePersonList))));
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example #29
Source File: BBSPermissionInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<BBSPermissionInfo> listByPermissionCodes( List<String> permissionCodes ) throws Exception {
	if( permissionCodes == null || permissionCodes.size() == 0 ){
		return new ArrayList<BBSPermissionInfo>();
	}
	EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSPermissionInfo> cq = cb.createQuery(BBSPermissionInfo.class);
	Root<BBSPermissionInfo> root = cq.from(BBSPermissionInfo.class);
	Predicate p = root.get(BBSPermissionInfo_.permissionCode).in( permissionCodes );
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example #30
Source File: TimerExpiredWorkUnitStubs.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private Collection<String> listUnitFromWorkCompleted(Business business, DateRange dateRange) throws Exception {
	EntityManagerContainer emc = business.entityManagerContainer();
	EntityManager em = emc.get(WorkCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<WorkCompleted> root = cq.from(WorkCompleted.class);
	Predicate p = cb.between(root.get(WorkCompleted_.expireTime), dateRange.getStart(), dateRange.getEnd());
	p = cb.and(p, cb.equal(root.get(WorkCompleted_.expired), true));
	cq.select(root.get(WorkCompleted_.creatorUnit)).distinct(true).where(p);
	List<String> list = em.createQuery(cq).getResultList();
	return list;
}