Created
April 28, 2018 04:13
-
-
Save HViktorTsoi/305f2f8304b8772c6bdb65475cf400ca to your computer and use it in GitHub Desktop.
Spring JPA中, 对于数据库中存在的JSON字段, 并且该字段对应Java对象,Specification分页查询方式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Page<UltrasonicImage> getAllUltrasonicImageByStatus(String status, Integer page, Integer num, User user) { | |
if (page == null || page < 1) | |
page = 1; | |
if (num == null || num < 0) | |
num = 10; | |
Sort sort = new Sort(Sort.Direction.DESC, "createTime"); | |
Pageable pageable = new PageRequest(page - 1, num, sort); | |
Page<UltrasonicImage> ultrasonicImages = ultrasonicImageRepository.findAll((root, query, cb) -> { | |
List<Predicate> predicates = new ArrayList<>(); | |
// 限制必须为该用户 | |
if (user != null) { | |
// 三表联查 找到医生对应的所有患者的所有超声图像 | |
predicates.add(cb.equal( | |
root.join("diagnosis") | |
.join("patient") | |
.get("doctor") | |
, user | |
)); | |
} | |
// 如果存在状态查询关键字 | |
if (status != null && !status.trim().equals("")) { | |
AIDiagnosticStatus allFinishedStatus = new AIDiagnosticStatus( | |
DiagnoseProcessingStatusType.FINISHED, | |
DiagnoseProcessingStatusType.FINISHED, | |
DiagnoseProcessingStatusType.WAITING | |
); | |
// 判断需要查询的处理状态 | |
if (status.equals("ANALYSING")) { | |
// 正在分析状态 即不是全完成 | |
predicates.add(cb.notEqual( | |
root.get("aiDiagnosticStatus"), | |
allFinishedStatus | |
)); | |
} else if (status.equals("FINISHED")) { | |
// 完成状态 即全部完成 | |
predicates.add(cb.equal( | |
root.get("aiDiagnosticStatus"), | |
allFinishedStatus | |
)); | |
} | |
// TODO 医生诊断结果完成后判断AI是否误诊 | |
} | |
return predicates.isEmpty() ? cb.conjunction() : cb.and(predicates.toArray(new Predicate[predicates.size()])); | |
}, pageable); | |
return ultrasonicImages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment