From 6770d1645c1872f3b4648d8235f610d65d90997b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 11:36:21 +0400 Subject: [PATCH] #21 -- Fix jpql --- .../ru/ulstu/report/repository/ReportRepository.java | 4 ++-- .../ulstu/statistic/controller/StatisticController.java | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/ulstu/report/repository/ReportRepository.java b/src/main/java/ru/ulstu/report/repository/ReportRepository.java index 17c3a36..e8c5e2e 100644 --- a/src/main/java/ru/ulstu/report/repository/ReportRepository.java +++ b/src/main/java/ru/ulstu/report/repository/ReportRepository.java @@ -10,7 +10,7 @@ import java.util.List; public interface ReportRepository extends JpaRepository { - //(SELECT sum(rv.indicatorValue) FROM ReportValue rv WHERE rv MEMBER OF r.values) - @Query("SELECT new ru.ulstu.statistic.model.RatingItem(r.aspirant, 10) FROM Report r JOIN r.reportPeriod rp WHERE rp.id = :reportPeriodId") + // + @Query("SELECT new ru.ulstu.statistic.model.RatingItem(r.aspirant, (SELECT cast(sum(rv.indicatorValue) AS Integer) FROM ReportValue rv WHERE rv MEMBER OF r.values)) FROM Report r JOIN r.reportPeriod rp WHERE rp.id = :reportPeriodId") List getRating(@Param("reportPeriodId") Integer reportPeriodId); } diff --git a/src/main/java/ru/ulstu/statistic/controller/StatisticController.java b/src/main/java/ru/ulstu/statistic/controller/StatisticController.java index 178f7d9..77259e7 100644 --- a/src/main/java/ru/ulstu/statistic/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/statistic/controller/StatisticController.java @@ -5,15 +5,10 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import ru.ulstu.aspirant.model.Aspirant; -import ru.ulstu.indicator.model.Course; import ru.ulstu.report.service.ReportPeriodService; -import ru.ulstu.statistic.model.RatingItem; import ru.ulstu.statistic.model.StatisticForm; import ru.ulstu.statistic.service.StatisticService; -import java.util.List; - @Controller @RequestMapping("statistic") public class StatisticController { @@ -30,16 +25,14 @@ public class StatisticController { public String getStatistic(Model model) { model.addAttribute("statisticForm", new StatisticForm()); model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); - model.addAttribute("rating", List.of(new RatingItem(new Aspirant("Иванов", Course.FIRST), 20))); return "/statistic/statistic"; } @PostMapping("statistic") public String getStatistic(StatisticForm form, Model model) { - //model.addAttribute("rating", statisticService.getRating(form.getReportPeriod().getId())); + model.addAttribute("rating", statisticService.getRating(form.getReportPeriod().getId())); model.addAttribute("statisticForm", form); model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); - model.addAttribute("rating", List.of(new RatingItem(new Aspirant("Иванов", Course.FIRST), 20))); return "/statistic/statistic"; } } \ No newline at end of file