javax.persistence.criteria.CriteriaBuilder.In Java Examples

The following examples show how to use javax.persistence.criteria.CriteriaBuilder.In. 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: CallAgentResourceController.java    From youkefu with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/res/agent")
  @Menu(type = "res" , subtype = "agent")
  public ModelAndView add(ModelMap map , HttpServletRequest request , @Valid String q) {
if(q==null){
	q = "" ;
}
final String search = q;
final String orgi = super.getOrgi(request);
final List<String> organList = CallCenterUtils.getExistOrgan(super.getUser(request));
map.put("owneruserList", userRes.findAll(new Specification<User>(){
	@Override
	public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query,
			CriteriaBuilder cb) {
		List<Predicate> list = new ArrayList<Predicate>();  
		In<Object> in = cb.in(root.get("organ"));
		
		list.add(cb.equal(root.get("orgi").as(String.class),orgi ));
		
		list.add(cb.or(cb.like(root.get("username").as(String.class),"%"+search+"%" ),cb.like(root.get("uname").as(String.class),"%"+search+"%" )));
		
		if(organList.size() > 0){
			
			for(String id : organList){
				in.value(id) ;
			}
		}else{
			in.value(UKDataContext.UKEFU_SYSTEM_NO_DAT) ;
		}
		list.add(in) ;
		
		Predicate[] p = new Predicate[list.size()];  
		return cb.and(list.toArray(p));   
	}}));
return request(super.createRequestPageTempletResponse("/public/agent"));
  }
 
Example #2
Source File: CallCenterUtils.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * 我的部门以及授权给我的部门 - 批次
 * @param batchRes
 * @param userRoleRes
 * @param callOutRoleRes
 * @param user
 * @return
 */
public static List<JobDetail> getBatchList(JobDetailRepository batchRes,UserRoleRepository userRoleRes , CallOutRoleRepository callOutRoleRes, final User user){
	
	//final List<String> organList = CallCenterUtils.getAuthOrgan(userRoleRes, callOutRoleRes, user);
	
	final List<String> organList = CallCenterUtils.getExistOrgan(user);
	
	List<JobDetail> batchList = batchRes.findAll(new Specification<JobDetail>(){
		@Override
		public Predicate toPredicate(Root<JobDetail> root, CriteriaQuery<?> query,
				CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();  
			In<Object> in = cb.in(root.get("organ"));
			
			list.add(cb.equal(root.get("orgi").as(String.class), user.getOrgi()));
			list.add(cb.equal(root.get("tasktype").as(String.class), UKDataContext.TaskType.BATCH.toString()));
			
			if(organList.size() > 0){
				
				for(String id : organList){
					in.value(id) ;
				}
			}else{
				in.value(UKDataContext.UKEFU_SYSTEM_NO_DAT) ;
			}
			list.add(in) ;
			
			Predicate[] p = new Predicate[list.size()];  
			return cb.and(list.toArray(p));   
		}});
	
	return batchList;
}
 
Example #3
Source File: CallCenterUtils.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * 我的部门以及授权给我的部门 - 筛选表单
 * @param filterRes
 * @param userRoleRes
 * @param callOutRoleRes
 * @param user
 * @return
 */
public static List<FormFilter> getFormFilterList(FormFilterRepository filterRes,UserRoleRepository userRoleRes , CallOutRoleRepository callOutRoleRes, final User user){
	
	//final List<String> organList = CallCenterUtils.getAuthOrgan(userRoleRes, callOutRoleRes, user);
	
	final List<String> organList = CallCenterUtils.getExistOrgan(user);
	
	List<FormFilter> formFilterList = filterRes.findAll(new Specification<FormFilter>(){
		@Override
		public Predicate toPredicate(Root<FormFilter> root, CriteriaQuery<?> query,
				CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();  
			In<Object> in = cb.in(root.get("organ"));
			
			list.add(cb.equal(root.get("orgi").as(String.class), user.getOrgi()));
			
			if(organList.size() > 0){
				
				for(String id : organList){
					in.value(id) ;
				}
			}else{
				in.value(UKDataContext.UKEFU_SYSTEM_NO_DAT) ;
			}
			list.add(in) ;
			
			Predicate[] p = new Predicate[list.size()];  
			return cb.and(list.toArray(p));   
		}});
	
	return formFilterList;
}
 
Example #4
Source File: CallCenterUtils.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * 我的部门以及授权给我的部门 - 活动
 * @param batchRes
 * @param userRoleRes
 * @param callOutRoleRes
 * @param user
 * @return
 */
public static List<JobDetail> getActivityList(JobDetailRepository batchRes,UserRoleRepository userRoleRes , CallOutRoleRepository callOutRoleRes,final User user){
	
	//final List<String> organList = CallCenterUtils.getAuthOrgan(userRoleRes, callOutRoleRes, user);
	
	final List<String> organList = CallCenterUtils.getExistOrgan(user);
	
	List<JobDetail> activityList = batchRes.findAll(new Specification<JobDetail>(){
		@Override
		public Predicate toPredicate(Root<JobDetail> root, CriteriaQuery<?> query,
				CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();  
			In<Object> in = cb.in(root.get("organ"));
			
			list.add(cb.equal(root.get("orgi").as(String.class), user.getOrgi()));
			list.add(cb.equal(root.get("tasktype").as(String.class), UKDataContext.TaskType.ACTIVE.toString()));
			
			if(organList.size() > 0){
				
				for(String id : organList){
					in.value(id) ;
				}
			}else{
				in.value(UKDataContext.UKEFU_SYSTEM_NO_DAT) ;
			}
			list.add(in) ;
			
			Predicate[] p = new Predicate[list.size()];  
			return cb.and(list.toArray(p));   
		}});
	
	return activityList;
}
 
Example #5
Source File: InExpression.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@Override
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
    In<Object> in = (In<Object>)this.criterion.toPredicate(root, query, builder);
    for (Object obj: this.value) {
        in.value(obj);
    }
    return in;
}
 
Example #6
Source File: Query.java    From FileUpload.Java with Apache License 2.0 5 votes vote down vote up
/**
 * 包含
 *
 * @param propertyName 属性名称
 * @param values       参数集合
 */
public Query whereIn(@NotNull final String propertyName, @NotNull final List<ParameterExpression> values) {
	In in = criteriaBuilder.in(from.get(propertyName));
	values.stream().forEach(in::value);
	this.predicates.add(in);
	return this;
}
 
Example #7
Source File: Query.java    From FileUpload.Java with Apache License 2.0 5 votes vote down vote up
/**
 * 包含
 *
 * @param propertyName 属性名称
 * @param values       参数值集合
 */
public Query whereValueIn(@NotNull final String propertyName, @NotNull final List<Object> values) {
	In in = criteriaBuilder.in(from.get(propertyName));
	values.stream()
			.map(this::makeParameter)
			.collect(Collectors.toList())
			.stream()
			.forEach(in::value);
	this.predicates.add(in);
	return this;
}
 
Example #8
Source File: Query.java    From FileUpload.Java with Apache License 2.0 5 votes vote down vote up
/**
 * 不包含
 *
 * @param propertyName 属性名称
 * @param values       参数集合
 */
public Query whereNotIn(@NotNull final String propertyName, @NotNull final List<ParameterExpression> values) {
	In in = criteriaBuilder.in(from.get(propertyName));
	values.stream().forEach(in::value);
	this.predicates.add(criteriaBuilder.not(in));
	return this;
}
 
Example #9
Source File: Query.java    From FileUpload.Java with Apache License 2.0 5 votes vote down vote up
/**
 * 不包含
 *
 * @param propertyName 属性名称
 * @param values       参数集合
 */
public Query whereValueNotIn(@NotNull final String propertyName, @NotNull final List<Object> values) {
	In in = criteriaBuilder.in(from.get(propertyName));
	values.stream()
			.map(this::makeParameter)
			.collect(Collectors.toList())
			.stream()
			.forEach(in::value);
	this.predicates.add(criteriaBuilder.not(in));
	return this;
}
 
Example #10
Source File: QueryService.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/**
 * <p>valueIn.</p>
 *
 * @param metaclassFunction a {@link java.util.function.Function} object.
 * @param values a {@link java.util.Collection} object.
 * @param <X> a X object.
 * @return a {@link org.springframework.data.jpa.domain.Specification} object.
 */
protected <X> Specification<ENTITY> valueIn(Function<Root<ENTITY>, Expression<X>> metaclassFunction,
                                            final Collection<X> values) {
    return (root, query, builder) -> {
        In<X> in = builder.in(metaclassFunction.apply(root));
        for (X value : values) {
            in = in.value(value);
        }
        return in;
    };
}
 
Example #11
Source File: QueryService.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/**
 * <p>valueNotIn.</p>
 *
 * @param metaclassFunction a {@link java.util.function.Function} object.
 * @param values a {@link java.util.Collection} object.
 * @param <X> a X object.
 * @return a {@link org.springframework.data.jpa.domain.Specification} object.
 */
protected <X> Specification<ENTITY> valueNotIn(Function<Root<ENTITY>, Expression<X>> metaclassFunction,
                                               final Collection<X> values) {
    return (root, query, builder) -> {
        In<X> in = builder.in(metaclassFunction.apply(root));
        for (X value : values) {
            in = in.value(value);
        }
        return builder.not(in);
    };
}
 
Example #12
Source File: AbstractGenericDAOImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public final List<T> findListByPropertyInList(final SingularAttribute<T, ? extends Object> property, final Object[] values) {
	final CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(getPersistentClass());
	final Root<T> root = criteriaQuery.from(getPersistentClass());
	criteriaQuery.select(root);
	final In<Object> in = criteriaBuilder.in((Path<Object>) root.get(property));
	for (final Object object : values) {
		in.value(object);
	}
	criteriaQuery.where(in);
	final TypedQuery<T> typedQuery = getEntityManager().createQuery(criteriaQuery);
	addCacheHints(typedQuery, "findListByPropertyInList");
	return typedQuery.getResultList();
}
 
Example #13
Source File: EmployeeSearchServiceImpl.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public List<DeptEmployee> filterbyTitleUsingCriteriaBuilder(List<String> titles) {
    CriteriaQuery<DeptEmployee> criteriaQuery = createCriteriaQuery(DeptEmployee.class);
    Root<DeptEmployee> root = criteriaQuery.from(DeptEmployee.class);
    In<String> inClause = criteriaBuilder.in(root.get("title"));
    for (String title : titles) {
        inClause.value(title);
    }
    criteriaQuery.select(root)
        .where(inClause);
    TypedQuery<DeptEmployee> query = entityManager.createQuery(criteriaQuery);
    return query.getResultList();
}
 
Example #14
Source File: CallCenterUtils.java    From youkefu with Apache License 2.0 4 votes vote down vote up
/**
 * 查询条件,下拉信息返回
 * @param map
 * @param user
 * @param ownerdept
 * @param actid
 */
public static void getAllCallOutList(ModelMap map, final User user,String ownerdept, String actid){
	JobDetailRepository batchRes = UKDataContext.getContext().getBean(JobDetailRepository.class) ;
	UserRoleRepository userRoleRes = UKDataContext.getContext().getBean(UserRoleRepository.class) ;
	CallOutRoleRepository callOutRoleRes = UKDataContext.getContext().getBean(CallOutRoleRepository.class) ;
	FormFilterRepository filterRes = UKDataContext.getContext().getBean(FormFilterRepository.class) ;
	OrganRepository organRes = UKDataContext.getContext().getBean(OrganRepository.class) ;
	SaleStatusRepository saleStatusRes = UKDataContext.getContext().getBean(SaleStatusRepository.class);
	
	List<JobDetail> activityList = CallCenterUtils.getActivityList(batchRes,userRoleRes, callOutRoleRes,user);
	final List<String> actidList = new ArrayList<String>();
	for(JobDetail act :activityList){
		actidList.add(act.getDicid());
	}
	List<SaleStatus> salestatusList = saleStatusRes.findAll(new Specification<SaleStatus>(){
		@Override
		public Predicate toPredicate(Root<SaleStatus> root, CriteriaQuery<?> query,
				CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();  
			In<Object> in = cb.in(root.get("activityid"));

			list.add(cb.equal(root.get("orgi").as(String.class), user.getOrgi()));

			if(actidList.size() > 0){
				for(String id : actidList){
					in.value(id) ;
				}
			}else{
				in.value(UKDataContext.UKEFU_SYSTEM_NO_DAT) ;
			}	
			list.add(in) ;

			Predicate[] p = new Predicate[list.size()];  
			return cb.and(list.toArray(p));   
		}});
	map.put("salestatusList", salestatusList);
	map.put("batchList", CallCenterUtils.getBatchList(batchRes, userRoleRes, callOutRoleRes,user));
	map.put("activityList", CallCenterUtils.getActivityList(batchRes,userRoleRes, callOutRoleRes,user));
	map.put("formFilterList", CallCenterUtils.getFormFilterList(filterRes,userRoleRes, callOutRoleRes,user));
	if(StringUtils.isBlank(ownerdept)){
		
		map.addAttribute("owneruserList",UKDataContext.getContext().getBean(UserRepository.class).findByOrganAndDatastatusAndOrgi(UKDataContext.UKEFU_SYSTEM_NO_DAT, false, user.getOrgi()));
	}else{
		map.addAttribute("owneruserList",UKDataContext.getContext().getBean(UserRepository.class).findByOrganAndDatastatusAndOrgi(ownerdept, false, user.getOrgi()));
		
	}
	map.addAttribute("skillList", organRes.findAll(CallCenterUtils.getAuthOrgan(userRoleRes, callOutRoleRes, user)));
	map.put("taskList",UKDataContext.getContext().getBean(CallOutTaskRepository.class).findByActidAndOrgi(actid, user.getOrgi()));
	map.put("allUserList",UKDataContext.getContext().getBean(UserRepository.class).findByOrgiAndDatastatus(user.getOrgi(), false));
	//JobDetail act = batchRes.findByIdAndOrgi(actid, user.getOrgi());
	//if(act != null){
	//	map.put("salestatusList",UKDataContext.getContext().getBean(SaleStatusRepository.class).findByOrgiAndActivityid(user.getOrgi(), act.getDicid()));
	//}
	//机器人
	map.addAttribute("aiList",UKDataContext.getContext().getBean(ExtentionRepository.class).findByExtypeAndOrgi(UKDataContext.ExtentionType.IVR.toString() , user.getOrgi()));
	//队列
	map.addAttribute("forcastQueueList",UKDataContext.getContext().getBean(CallCenterSkillRepository.class).findByOrgi(user.getOrgi()));
	map.addAttribute("statusList",UKeFuDic.getInstance().getDic("com.dic.callout.activity"));
}
 
Example #15
Source File: ApplicationServiceImpl.java    From MultimediaDesktop with Apache License 2.0 4 votes vote down vote up
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public PageDto<ApplicationDto> findBy(final String userId,
		final String name, final Date startDate, final Date endDate,
		final ApplicationType typeGroup, final List<UserRole> roles,
		final Boolean auditingStatu, PageSize pageSize, SortDto sortDto) {
	if (pageSize == null) {
		pageSize = new PageSize();
	}

	Page<Application> applications = applicationRepository.findAll(
			new Specification<Application>() {

				@Override
				public Predicate toPredicate(Root<Application> root,
						CriteriaQuery<?> query, CriteriaBuilder cb) {

					List<Predicate> pres = new ArrayList<Predicate>();

					if (!StringUtils.isBlank(userId)) {
						pres.add(cb.equal(root.get("addUser")
								.as(User.class), new User(userId)));
					}

					if (!StringUtils.isBlank(name)) {
						pres.add(cb.like(root.get("name").as(String.class),
								name));
					}

					// 没办法。Mysql不支持bit查询
					pres.add(cb.equal(
							root.get("auditingStatu").as(Integer.class),
							auditingStatu ? 1 : 0));

					if (startDate != null) {
						pres.add(cb.greaterThanOrEqualTo(root
								.get("addDate").as(Date.class), startDate));
					}

					if (endDate != null) {
						pres.add(cb.lessThanOrEqualTo(root.get("addDate")
								.as(Date.class), endDate));
					}

					if (typeGroup != null) {
						pres.add(cb.equal(
								root.get("typeGroup").as(
										ApplicationType.class), typeGroup));
					}

					if (roles != null && !roles.isEmpty()) {
						In<UserRole> in = cb.in(root.get("role").as(
								UserRole.class));
						for (UserRole role : roles) {
							in.value(role);
						}
						pres.add(in);
					}

					Predicate[] p = new Predicate[pres.size()];
					return cb.and(pres.toArray(p));
				}
			}, new PageRequest(pageSize.getPage() - 1, pageSize.getLimit(),
					SortUtils.covertSortDto(sortDto)));

	return applicationCovert.covertToDto(applications);
}