[Bug #935] query grouped by date

Group by resource, type of work hours and its date and then
the result is sort by local date.

FEA : ItEr72S04BugFixing
This commit is contained in:
Susana Montes Pedreira 2011-03-15 19:10:16 +01:00
parent 2df0d5321f
commit 05b553bcd0
2 changed files with 18 additions and 1 deletions

View file

@ -68,7 +68,7 @@ public class WorkReportLineDAO extends IntegrationEntityDAO<WorkReportLine>
+ "LEFT OUTER JOIN wrl.orderElement orderElement "
+ "WHERE orderElement = :orderElement "
+ "GROUP BY wrl.resource, wrl.typeOfWorkHours, wrl.date "
+ "ORDER BY to_char(wrl.date, 'yyyy-mm-dd') , wrl.resource, wrl.typeOfWorkHours";
+ "ORDER BY wrl.resource, wrl.typeOfWorkHours, wrl.date";
// Set parameters
Query query = getSession().createQuery(strQuery);

View file

@ -23,6 +23,8 @@ package org.navalplanner.web.orders;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@ -86,6 +88,21 @@ public class AssignedHoursToOrderElementModel implements
this.assignedDirectHours = this.assignedDirectHours
+ w.getSumHours();
}
return sortByDate(listWRL);
}
private List<WorkReportLineDTO> sortByDate(List<WorkReportLineDTO> listWRL) {
Collections.sort(listWRL, new Comparator<WorkReportLineDTO>() {
public int compare(WorkReportLineDTO arg0, WorkReportLineDTO arg1) {
if (arg0.getDate() == null) {
return -1;
}
if (arg1.getDate() == null) {
return 1;
}
return arg0.getDate().compareTo(arg1.getDate());
}
});
return listWRL;
}