@Override
public MyPage<MonitorLogOutput> query(MonitorLogInput monitorLogInput) {
Sort sort = new Sort(Sort.Direction.DESC, "operationTime");
Pageable pageable = new PageRequest(monitorLogInput.getCurPage() - 1, monitorLogInput.getPageSize(), sort);
// 查询条件构造
Specification<MonitorLog> spec = new Specification<MonitorLog>() {
@Override
public Predicate toPredicate(Root<MonitorLog> root, javax.persistence.criteria.CriteriaQuery<?> query, CriteriaBuilder
cb) {
List<Predicate> lstPredicates = new ArrayList<Predicate>();
if (StringUtils.isNotBlank(monitorLogInput.getStartTime())) {
lstPredicates.add(cb.ge(root.get("operationTime"), DateUtils.convert2long(monitorLogInput.getStartTime(),
"yyyy-MM-dd")));
}
if (StringUtils.isNotBlank(monitorLogInput.getEndTime())) {
lstPredicates.add(cb.le(root.get("operationTime"), DateUtils.convert2long(monitorLogInput.getEndTime(), "yyyy-
MM-dd")));
}
if (StringUtils.isNotBlank(monitorLogInput.getOperator())) {
lstPredicates.add(cb.like(root.get("operator"), "%" + monitorLogInput.getOperator() + "%"));
}
if (StringUtils.isNotBlank(monitorLogInput.getOparationType())) {
lstPredicates.add(cb.equal(root.get("operationCategoryDetail"), monitorLogInput.getOparationType()));
}
Predicate[] arrayPredicates = new Predicate[lstPredicates.size()];
return cb.and(lstPredicates.toArray(arrayPredicates));
}
};
Page<MonitorLog> page = monitorLogDao.findAll(spec,pageable);
MyPage<MonitorLogOutput> myPage = new MyPage<>(monitorLogInput.getPageSize(), monitorLogInput.getCurPage());
myPage.setTotalRow(page.getTotalElements());
List<MonitorLogOutput> MonitorLogOutputList = Lists.newArrayList();
if (!ObjectUtils.isNull(page.getContent())) {
page.getContent().forEach(monitorLog -> MonitorLogOutputList.add(buildOutput(monitorLog)));
}
myPage.setList(MonitorLogOutputList);
return myPage;
}