from ${start}
to ${end}
diff --git a/WebContent/WEB-INF/views/guides/guidesStatistics.jsp b/WebContent/WEB-INF/views/guides/guidesStatistics.jsp
new file mode 100644
index 0000000..0bc9c47
--- /dev/null
+++ b/WebContent/WEB-INF/views/guides/guidesStatistics.jsp
@@ -0,0 +1,33 @@
+<%@ page session="false" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
+
+
+
+
+
+
+
+
+
+
+
Find statistics in time slot:
+
+
+
+
+
+
+
+
+
diff --git a/WebContent/WEB-INF/views/guides/guidesStatisticsResults.jsp b/WebContent/WEB-INF/views/guides/guidesStatisticsResults.jsp
new file mode 100644
index 0000000..77eb4ca
--- /dev/null
+++ b/WebContent/WEB-INF/views/guides/guidesStatisticsResults.jsp
@@ -0,0 +1,60 @@
+<%@ page session="false" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Guides' statistics
+
+
+
+
+
+ Guide | Total tours | Total tours' duration |
+
+
+
+ ${current.firstName} ${current.lastName} |
+ ${current.totalExcursions} |
+ ${current.excursionsTotalDuration} |
+
+
+
+
+
+ not found!
+ Try one more time
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/softserve/museum/dao/impl/GuideDAOimpl.java b/src/com/softserve/museum/dao/impl/GuideDAOimpl.java
index 5a14dfa..088b122 100644
--- a/src/com/softserve/museum/dao/impl/GuideDAOimpl.java
+++ b/src/com/softserve/museum/dao/impl/GuideDAOimpl.java
@@ -75,7 +75,7 @@ public List
findByTime(LocalDateTime start, LocalDateTime end) {
public List getGuidesStatisticByPeriod(LocalDateTime start, LocalDateTime end) {
StringBuilder query = new StringBuilder(
"SELECT XS.guide.firstName AS firstName, XS.guide.lastName AS lastName, COUNT(id) AS totalExcursions, "
- + "SUM(XS.details.durationsec) AS excursionsTotalDuration " + "FROM Excursion AS XS "
+ + "SUM(XS.details.durationSec) AS excursionsTotalDuration " + "FROM Excursion AS XS "
+ "WHERE (XS.start >= :startDate AND XS.end <= :endDate) GROUP BY XS.guide");
System.out.println(query.toString());
Query result = sessionFactory.getCurrentSession().createQuery(query.toString());
diff --git a/src/com/softserve/museum/service/GuideService.java b/src/com/softserve/museum/service/GuideService.java
index 249f230..e021342 100644
--- a/src/com/softserve/museum/service/GuideService.java
+++ b/src/com/softserve/museum/service/GuideService.java
@@ -68,6 +68,8 @@ public interface GuideService {
public abstract List findByTime(String start, String end);
public abstract List getGuidesStatisticByPeriod(LocalDateTime start, LocalDateTime end);
+
+ public abstract List getGuidesStatisticByPeriod(String start, String end);
/* @SuppressWarnings("rawtypes")
public abstract List getCountGuidesByPeriod(LocalDateTime start, LocalDateTime end);
diff --git a/src/com/softserve/museum/service/impl/GuideServiceImpl.java b/src/com/softserve/museum/service/impl/GuideServiceImpl.java
index a77dc91..f93e7b7 100644
--- a/src/com/softserve/museum/service/impl/GuideServiceImpl.java
+++ b/src/com/softserve/museum/service/impl/GuideServiceImpl.java
@@ -15,9 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import com.softserve.museum.dao.generic.ExcursionDAO;
import com.softserve.museum.dao.generic.GuideDAO;
-import com.softserve.museum.domain.Excursion;
import com.softserve.museum.domain.Guide;
import com.softserve.museum.domain.GuideStatisticDTO;
import com.softserve.museum.domain.Position;
@@ -38,9 +36,6 @@ public class GuideServiceImpl implements GuideService {
@Autowired
private GuideDAO guides;
- @Autowired
- private ExcursionDAO excursions;
-
/**
* Finds all guides.
* @return list of all guides
@@ -58,14 +53,7 @@ public List listGuides() {
*/
@Override
public List findByTime(LocalDateTime start, LocalDateTime end) {
- List eList = excursions.findInPeriod(start, end);
- List gList = guides.getAll();
-
- for (Excursion e: eList) {
- gList.remove(e.getGuide());
- }
-
- return gList;
+ return guides.findByTime(start, end);
}
@@ -95,6 +83,21 @@ public List findByTime(String start, String end) {
public List getGuidesStatisticByPeriod(LocalDateTime start, LocalDateTime end) {
return guides.getGuidesStatisticByPeriod(start, end);
}
+
+ /**
+ * Return statistic about all guides excursions in given time slot.
+ * @param start start of time slot
+ * @param end end of time slot
+ * @return list of proxy object GuideStatisticDTO
+ */
+ @Override
+ public List getGuidesStatisticByPeriod(String start, String end) {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
+ LocalDateTime startTime = LocalDateTime.parse(start, formatter);
+ LocalDateTime endTime = LocalDateTime.parse(end, formatter);
+
+ return guides.getGuidesStatisticByPeriod(startTime, endTime);
+ }
@SuppressWarnings("rawtypes")
@Override
diff --git a/src/com/softserve/museum/web/controller/GuidesController.java b/src/com/softserve/museum/web/controller/GuidesController.java
index 5501ec4..dc93024 100644
--- a/src/com/softserve/museum/web/controller/GuidesController.java
+++ b/src/com/softserve/museum/web/controller/GuidesController.java
@@ -74,7 +74,7 @@ public ModelAndView findAvailable(
@RequestParam(name="end") String end) {
ModelAndView model = new ModelAndView("guides/guidesAvailableResults");
- // trim milliseconds and delimiters
+ // trim seconds, milliseconds and delimiters
start = start.replace('T', ' ').substring(0, (start.length() - 7));
end = end.replace('T', ' ').substring(0, (end.length() - 7));
model.addObject("start", start);
@@ -115,6 +115,30 @@ public ModelAndView showGuideByPosition(@PathVariable("position") String positio
model.addObject("position", position);
model.addObject("guides", guideService.findByPosition(position));
return model;
- }
+ }
+
+ @GetMapping("/statistics")
+ public ModelAndView showStatisticsFindForm() {
+ ModelAndView model = new ModelAndView("guides/guidesStatistics");
+ model.addObject("start", LocalDateTime.now());
+ model.addObject("end", LocalDateTime.now().plusHours(2));
+ return model;
+ }
+
+ @PostMapping("/statistics")
+ public ModelAndView showStatisticsResults(
+ @RequestParam(name="start") String start,
+ @RequestParam(name="end") String end) {
+
+ ModelAndView model = new ModelAndView("guides/guidesStatisticsResults");
+ // trim seconds, milliseconds and delimiters
+ start = start.replace('T', ' ').substring(0, (start.length() - 7));
+ end = end.replace('T', ' ').substring(0, (end.length() - 7));
+ model.addObject("start", start);
+ model.addObject("end", end);
+ model.addObject("statistics", guideService.getGuidesStatisticByPeriod(start, end));
+
+ return model;
+ }
}