public Page<XMGLFileTemplateDTO> findXMGLFileTemplateByConditions(XMGLFileTemplateDTO xmglFileTemplateDTO, Pageable pageable) throws MyException { Page<XMGLFileTemplate> XMGLFileTemplateLists = this.xmglFileTemplateRepository.findAll(new Specification<XMGLFileTemplate>() { @Override public Predicate toPredicate(Root<XMGLFileTemplate> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { List<Predicate> predicateList = new ArrayList<Predicate>(); //文档名称 if(StringUtils.isNotBlank(xmglFileTemplateDTO.getFileName())){ predicateList.add(criteriaBuilder.like(root.get("fileName"),"%"+xmglFileTemplateDTO.getFileName()+"%")); } //上传人员 if(StringUtils.isNotBlank(xmglFileTemplateDTO.getUploadUserName())){ predicateList.add(criteriaBuilder.like(root.get("rsglSysUser").get("name"),"%"+xmglFileTemplateDTO.getUploadUserName()+"%")); } //重要性 if(null != xmglFileTemplateDTO.getImportantLevel()){ predicateList.add(criteriaBuilder.equal(root.get("importantLevel"),xmglFileTemplateDTO.getImportantLevel())); } //交易时间 if (null != xmglFileTemplateDTO.getUploadBeginTime() && null != xmglFileTemplateDTO.getUploadEndTime()) { predicateList.add(criteriaBuilder.and(criteriaBuilder.greaterThanOrEqualTo(root.get("uploadTime"), DateUtils.parseDateTime(xmglFileTemplateDTO.getUploadBeginTime() + " 00:00:00")), criteriaBuilder.lessThanOrEqualTo(root.get("uploadTime"), DateUtils.parseDateTime(xmglFileTemplateDTO.getUploadEndTime() + " 23:59:59")))); } else if (null != xmglFileTemplateDTO.getUploadBeginTime()) { predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("uploadTime"),DateUtils.parseDateTime(xmglFileTemplateDTO.getUploadBeginTime() + " 00:00:00"))); } else if (null != xmglFileTemplateDTO.getUploadEndTime()) { predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("uploadTime"),DateUtils.parseDateTime(xmglFileTemplateDTO.getUploadEndTime() + " 23:59:59"))); } criteriaQuery.where(predicateList.toArray(new Predicate[0])); //更新时间倒序排序 criteriaQuery.orderBy(criteriaBuilder.desc(root.get("uploadTime"))); return null; } }, pageable); List<XMGLFileTemplateDTO> xmglFileTemplateDTOs = new ArrayList<XMGLFileTemplateDTO>(); for (XMGLFileTemplate xmglFileTemplate : XMGLFileTemplateLists.getContent()) {//把分页对象转换为list对象 因为 XMGLFileTemplateDTO dto = new XMGLFileTemplateDTO(); BeanUtils.copyProperties(xmglFileTemplate, dto);//把接受前台参数的DTO和doman层的进行匹配拷贝 dto.setUploadUserName(xmglFileTemplate.getRsglSysUser().getName()); xmglFileTemplateDTOs.add(dto);//加入list集合 } return new CustomPageImpl<XMGLFileTemplateDTO>(xmglFileTemplateDTOs, pageable,XMGLFileTemplateLists.getTotalElements()); }
services层,使用对象分页查询
时间: 2024-10-21 02:42:09