use of hse.holuhoev.datasource.util.DataSourceResult in project hse-cws by holuhoev.
the class StudentWorkloadDatasource method getStudentSumWorkload.
public DataSourceResult getStudentSumWorkload(final Integer groupId, final Integer studentId, final Integer facultyId, final Integer instituteId, final Course course, final String studentFio, final EducationType educationType, final LocalDate fromDate, final LocalDate toDate, final Integer top, final Integer skip, final Boolean fetchTotal, final String orderBy) {
QStudent qStudent = QStudent.student;
QStudentWorkload qStudentWorkload = QStudentWorkload.studentWorkload;
BooleanBuilder studentBuilder = new BooleanBuilder();
BooleanBuilder workloadBuilder = new BooleanBuilder();
if (groupId != null) {
studentBuilder.and(qStudent.groupID.eq(groupId));
}
if (studentId != null) {
studentBuilder.and(qStudent.Id.eq(studentId));
}
if (facultyId != null) {
studentBuilder.and(qStudent.facultyID.eq(facultyId));
}
if (instituteId != null) {
studentBuilder.and(qStudent.instituteID.eq(instituteId));
}
if (course != null) {
studentBuilder.and(qStudent.course.eq(course));
}
if (studentFio != null && !studentFio.isEmpty()) {
studentBuilder.and(qStudent.fio.containsIgnoreCase(studentFio));
}
if (educationType != null) {
studentBuilder.and(qStudent.educationType.eq(educationType));
}
if (fromDate != null) {
workloadBuilder.and(qStudentWorkload.date.after(fromDate).or(qStudentWorkload.date.eq(fromDate)));
}
if (toDate != null) {
workloadBuilder.and(qStudentWorkload.date.before(toDate).or(qStudentWorkload.date.before(toDate)));
}
Iterable<Student> students;
if (top != null) {
String orderByString = isNullOrEmpty(orderBy) ? "fio" : orderBy;
Pageable limit = PageRequest.of(skip, top, Sort.Direction.ASC, orderByString);
students = studentRepository.findAll(studentBuilder, limit);
} else {
students = studentRepository.findAll(studentBuilder);
}
Stream<Student> studentStream = StreamSupport.stream(students.spliterator(), false);
List<StudentSumWorkload> result = studentStream.map(student -> {
BooleanBuilder builder = new BooleanBuilder();
builder.and(workloadBuilder).and(qStudentWorkload.studentId.eq(student.getId()));
// Если запросили тот период, по которому нет инфы, то запрашивать из руза и добавлять в загруженность
// Еще надо смотреть, что есть такой date == toDate, если нет, то искать макисмальный, а остальное запросить
Integer workload = StreamSupport.stream(studentWorkloadRepository.findAll(builder).spliterator(), false).mapToInt(StudentWorkload::getWorkload).sum();
return new StudentSumWorkload(student.getFio(), workload, student.getId());
}).collect(Collectors.toList());
Map<String, Object> hints = new HashMap<>();
hints.put("paging", true);
if (fetchTotal != null && fetchTotal) {
Long count = studentRepository.count(studentBuilder);
hints.put("total", count);
}
return DataSourceResult.create(result, hints);
}
use of hse.holuhoev.datasource.util.DataSourceResult in project hse-cws by holuhoev.
the class LecturerWorkloadDatasource method getLecturerSumWorkload.
public DataSourceResult getLecturerSumWorkload(final Integer chairId, final String fio, final LocalDate fromDate, final LocalDate toDate, final Integer top, final Integer skip, final Boolean fetchTotal) {
QLecturer qLecturer = QLecturer.lecturer;
QLecturerWorkload qLecturerWorkload = QLecturerWorkload.lecturerWorkload;
BooleanBuilder lecturerBuilder = new BooleanBuilder();
BooleanBuilder workloadBuilder = new BooleanBuilder();
if (chairId != null) {
lecturerBuilder.and(qLecturer.chairId.eq(chairId));
}
if (fio != null && !fio.isEmpty()) {
lecturerBuilder.and(qLecturer.fio.containsIgnoreCase(fio));
}
if (fromDate != null) {
workloadBuilder.and(qLecturerWorkload.date.after(fromDate));
}
if (toDate != null) {
workloadBuilder.and(qLecturerWorkload.date.before(toDate));
}
Iterable<Lecturer> lecturers;
if (top != null) {
String orderByString = "fio";
Pageable limit = PageRequest.of(skip, top, Sort.Direction.ASC, orderByString);
lecturers = lecturerRepository.findAll(lecturerBuilder, limit);
} else {
lecturers = lecturerRepository.findAll(lecturerBuilder);
}
List<LecturerSumWorkload> result = StreamSupport.stream(lecturers.spliterator(), false).map(lecturer -> {
BooleanBuilder builder = new BooleanBuilder();
builder.and(workloadBuilder).and(qLecturerWorkload.lecturerId.eq(lecturer.getId()));
Integer workload = StreamSupport.stream(lecturerWorkloadRepository.findAll(builder).spliterator(), false).mapToInt(LecturerWorkload::getWorkload).sum();
return new LecturerSumWorkload(lecturer.getFio(), workload, lecturer.getId());
}).collect(Collectors.toList());
Map<String, Object> hints = new HashMap<>();
hints.put("paging", true);
if (fetchTotal != null && fetchTotal) {
Long count = lecturerWorkloadRepository.count(lecturerBuilder);
hints.put("total", count);
}
return DataSourceResult.create(result, hints);
}
Aggregations