ItEr45S17CUServizoExportacionHoras: Implemented methods to export hours of all workers or just one specific worker.
This commit is contained in:
parent
6acf3e0718
commit
91dae0adbb
4 changed files with 115 additions and 9 deletions
|
|
@ -115,4 +115,7 @@ public interface IWorkerDAO extends IGenericDAO<Worker, Long> {
|
|||
List<Worker> findByFirstNameSecondNameAndNifAnotherTransaction(
|
||||
String firstname, String surname, String nif);
|
||||
|
||||
List<Object[]> getWorkingHoursGroupedPerWorker(List<String> workerNifs,
|
||||
Date startingDate, Date endingDate);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,4 +162,51 @@ public class WorkerDAO extends GenericDAOHibernate<Worker, Long>
|
|||
return query.list();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Object[]> getWorkingHoursGroupedPerWorker(
|
||||
List<String> workerNifs, Date startingDate, Date endingDate) {
|
||||
String strQuery = "SELECT worker.nif, SUM(wrl.numHours) "
|
||||
+ "FROM Worker worker, WorkReportLine wrl "
|
||||
+ "LEFT OUTER JOIN wrl.resource resource "
|
||||
+ "WHERE resource.id = worker.id ";
|
||||
|
||||
// Set date range
|
||||
if (startingDate != null && endingDate != null) {
|
||||
strQuery += "AND wrl.date BETWEEN :startingDate AND :endingDate ";
|
||||
}
|
||||
if (startingDate != null && endingDate == null) {
|
||||
strQuery += "AND wrl.date >= :startingDate ";
|
||||
}
|
||||
if (startingDate == null && endingDate != null) {
|
||||
strQuery += "AND wrl.date <= :endingDate ";
|
||||
}
|
||||
|
||||
// Set workers
|
||||
if (workerNifs != null && !workerNifs.isEmpty()) {
|
||||
strQuery += "AND worker.nif IN (:workerNifs) ";
|
||||
}
|
||||
|
||||
// Group by
|
||||
strQuery += "GROUP BY worker.nif ";
|
||||
|
||||
// Order by
|
||||
strQuery += "ORDER BY worker.nif";
|
||||
|
||||
// Set parameters
|
||||
Query query = getSession().createQuery(strQuery);
|
||||
if (startingDate != null) {
|
||||
query.setParameter("startingDate", startingDate);
|
||||
}
|
||||
if (endingDate != null) {
|
||||
query.setParameter("endingDate", endingDate);
|
||||
}
|
||||
if (workerNifs != null && !workerNifs.isEmpty()) {
|
||||
query.setParameterList("workerNifs", workerNifs);
|
||||
}
|
||||
|
||||
// Get result
|
||||
return query.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
package org.navalplanner.ws.resources.api;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -30,7 +30,10 @@ import java.util.Date;
|
|||
*/
|
||||
public interface IResourceHoursService {
|
||||
|
||||
ResourceWorkedHoursListDTO getHoursAllWorkersBetween(Date startDate,
|
||||
Date endDate);
|
||||
ResourceWorkedHoursListDTO getHoursAllWorkersBetween(String startDate,
|
||||
String endDate);
|
||||
|
||||
ResourceWorkedHoursListDTO getHoursOfWorker(String resourceCode,
|
||||
String startDate, String endDate);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,14 +20,23 @@
|
|||
|
||||
package org.navalplanner.ws.resources.impl;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.navalplanner.business.resources.daos.IWorkerDAO;
|
||||
import org.navalplanner.ws.resources.api.IResourceHoursService;
|
||||
import org.navalplanner.ws.resources.api.ResourceWorkedHoursDTO;
|
||||
import org.navalplanner.ws.resources.api.ResourceWorkedHoursListDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -41,13 +50,57 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Service("resourceHoursServiceREST")
|
||||
public class ResourceHoursServiceREST implements IResourceHoursService {
|
||||
|
||||
public static final SimpleDateFormat SERVICE_DATE_FORMAT = new SimpleDateFormat(
|
||||
"yyyy-MM-dd");
|
||||
|
||||
@Autowired
|
||||
private IWorkerDAO workerDAO;
|
||||
|
||||
@Override
|
||||
@GET
|
||||
@Path("/{startDate}/{endDate}")
|
||||
@Transactional(readOnly = true)
|
||||
public ResourceWorkedHoursListDTO getHoursAllWorkersBetween(Date startDate,
|
||||
Date endDate) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public ResourceWorkedHoursListDTO getHoursAllWorkersBetween(
|
||||
@PathParam("startDate") String startDate,
|
||||
@PathParam("endDate") String endDate) {
|
||||
return getHoursOfWorker(null, startDate, endDate);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
@GET
|
||||
@Path("/{resourceCode}/{startDate}/{endDate}")
|
||||
@Transactional(readOnly = true)
|
||||
public ResourceWorkedHoursListDTO getHoursOfWorker(
|
||||
@PathParam("resourceCode") String resourceCode,
|
||||
@PathParam("startDate") String startDate,
|
||||
@PathParam("endDate") String endDate) {
|
||||
List<ResourceWorkedHoursDTO> result = new ArrayList<ResourceWorkedHoursDTO>();
|
||||
|
||||
Date startingDate;
|
||||
Date endingDate;
|
||||
try {
|
||||
startingDate = SERVICE_DATE_FORMAT.parse(startDate);
|
||||
endingDate = SERVICE_DATE_FORMAT.parse(endDate);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
List<String> workerNifs = null;
|
||||
if (resourceCode != null) {
|
||||
workerNifs = Arrays.asList(resourceCode);
|
||||
}
|
||||
|
||||
List<Object[]> hoursPerWorker = workerDAO
|
||||
.getWorkingHoursGroupedPerWorker(workerNifs, startingDate,
|
||||
endingDate);
|
||||
|
||||
for (Object[] pair : hoursPerWorker) {
|
||||
ResourceWorkedHoursDTO resourceWorkedHoursDTO = new ResourceWorkedHoursDTO(
|
||||
(String) pair[0], ((Long) pair[1]).intValue());
|
||||
result.add(resourceWorkedHoursDTO);
|
||||
}
|
||||
|
||||
return new ResourceWorkedHoursListDTO(result, startingDate, endingDate);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue