```
@Transactional(readOnly =true)
public PagereferPage(PageParam searchData) {
CustomerQueryDTO dto = searchData.getDto();
ErpCustomKna1 entity =new ErpCustomKna1();
if (dto !=null) {
if (StringUtils.isNotEmpty(dto.getKunnr())) {
entity.setKunnr(dto.getKunnr());
}
if (StringUtils.isNotEmpty(dto.getName1())) {
searchData.getSearchMap().put("name1", new SearchFilter("LIKE", dto.getName1()));
}
if (StringUtils.isNotEmpty(dto.getStceg())) {
entity.setStceg(dto.getStceg());
}
if (StringUtils.isNotEmpty(dto.getKtokd())) {
entity.setKtokd(dto.getKtokd());
}
}
List params =new ArrayList<>();
if (dto !=null && StringUtils.isNotEmpty(dto.getBukrs())) {
params.add(new ParamOperateValue(ErpCustomKnb1_.BUKRS, JpaUtils.EQ_REG, dto.getBukrs()));
}
Pageable pageRequest = Pageutil.getPageRequest(searchData);
ErpCustomKna1 filter = Pageutil.buildEntity(entity, searchData);
filter.notExists(ErpCustomKna1_.KUNNR, ErpCustomKnb1.class, ErpCustomKnb1_.KUNNR, params);
Specification spec =jpaUtils.buildWhereClause(filter, false);
List result;
List strings = Arrays.asList("D000", "D001", "D002", "D003", "D004", "D005", "D008", "D009");
// specification 是一个匿名内部类
Specification specification =new Specification() {
/**
*
* @param root 查询类型,根据实体类匹配类型
* @param query 查询条件
* @param cb 构建条件,有in,and,or,like等用法。
* @return
*/
@Override
public PredicatetoPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) {
List predicates =new ArrayList<>();
if (dto !=null) {
// IN的用法,可直接传list和数组。 list中数据类型,要与实体类中类型匹配,不然需要进行类型转换。
if (StringUtils.isEmpty(dto.getKtokd())) {
//查询标准化账户组,排查此公司是否在标准化,如是则条件需要在标准化账户组参照,不是则在非标准化账户组参照
List controlRangeList = queryDictControlRange("COMPANY_R3_STANDARD");
List companyCodes = controlRangeList.parallelStream().filter(item -> StringUtils.isNotEmpty(item.getLookupCode()))
.map(LookupDTO::getLookupCode).collect(Collectors.toList());
if (companyCodes.contains(dto.getBukrs())) {
predicates.add(cb.in(root.get("ktokd")).value(strings));
}else {
predicates.add(cb.not(cb.in(root.get("ktokd")).value(strings)));
}
}else {
predicates.add(cb.equal(root.get("ktokd").as(String.class), dto.getKtokd()));
}
}
return query.where(predicates.toArray(new Predicate[0])).getRestriction();
}
};
Specification allSp = spec.and(specification);
Page all =erpCustomKna1Repository.findAll(allSp, pageRequest);
result =erpCustomKna1Mapper.toDto(all.getContent());
return new PageImpl<>(result, all.getPageable(), all.getTotalElements());
}
```