public Page<VWProcessDetails> list(Integer pageSize, Integer pageNumber, String topicCode, String sourceCode, String countyCode, String villageCode, String qStatusCode, Timestamp startTime, Timestamp endTime, String executiver) {
Specification<VWProcessDetails> specification = new Specification<VWProcessDetails>() {
@Override
public Predicate toPredicate(Root<VWProcessDetails> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
ArrayList<Predicate> predicates = new ArrayList<>();
if (!topicCode.isEmpty()) {
predicates.add(cb.equal(root.get("topicCode").as(String.class), topicCode));
}
if (!sourceCode.isEmpty()) {
predicates.add(cb.equal(root.get("sourceCode").as(String.class), sourceCode));
}
if (!countyCode.isEmpty()) {
predicates.add(cb.equal(root.get("countyCode").as(String.class), countyCode));
}
if (!villageCode.isEmpty()) {
predicates.add(cb.equal(root.get("villageCode").as(String.class), villageCode));
}
if (!qStatusCode.isEmpty()) {
predicates.add(cb.equal(root.get("qStatusCode").as(String.class), qStatusCode));
}
if (startTime != null && endTime != null) {
predicates.add(cb.between(root.get("entryTime"), startTime, endTime));
}
//or判断
ArrayList<Predicate> or = new ArrayList<>();
if (executiver != null && !executiver.isEmpty()) {
or.add(cb.equal(root.get("executiver").as(String.class), executiver));
}
if (executiver != null && !executiver.isEmpty()) {
or.add(cb.equal(root.get("entrant").as(String.class), executiver));
}
predicates.add(cb.or(or.toArray(new Predicate[or.size()])));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
Page<VWProcessDetails> page = getPage(specification, pageSize, pageNumber);
return page;
}
public List<VwBaseInfo> provinceWaterAreaByYears() {
Sort.Order order = Sort.Order.asc("year");
Sort sort = Sort.by(order);
List<VwBaseInfo> list = baseInfoDao.findByAdLevel(PROVINCEADMINDIVLEVEL, sort);
return list;
}
//另一种or判断 ArrayList<Predicate> or = new ArrayList<>(); if (!userCode.isEmpty()) { or.add(cb.equal(root.get("entrant").as(String.class), userCode)); or.add(cb.equal(root.get("executiver").as(String.class), userCode)); } ArrayList<Predicate> list = new ArrayList<>(); list.add(cb.and(predicates.toArray(new Predicate[predicates.size()]))); list.add(cb.or(or.toArray(new Predicate[or.size()]))); return cb.or(list.toArray(new Predicate[predicates.size()]));