#21 -- Fix jpql

This commit is contained in:
Anton Romanov 2025-04-03 11:36:21 +04:00
parent 732ffc3441
commit 6770d1645c
2 changed files with 3 additions and 10 deletions

View File

@ -10,7 +10,7 @@ import java.util.List;
public interface ReportRepository extends JpaRepository<Report, Integer> {
//(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<RatingItem> getRating(@Param("reportPeriodId") Integer reportPeriodId);
}

View File

@ -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";
}
}