diff --git a/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java b/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java index f87162b..613d358 100644 --- a/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java +++ b/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java @@ -6,10 +6,10 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import ru.ulstu.aspirant.model.Report; import ru.ulstu.aspirant.service.AspirantService; import ru.ulstu.indicator.model.Indicator; import ru.ulstu.model.OffsetablePageRequest; +import ru.ulstu.report.model.Report; import java.util.List; import java.util.Optional; diff --git a/src/main/java/ru/ulstu/aspirant/model/Report.java b/src/main/java/ru/ulstu/report/model/Report.java similarity index 58% rename from src/main/java/ru/ulstu/aspirant/model/Report.java rename to src/main/java/ru/ulstu/report/model/Report.java index 8bb1771..cc69be3 100644 --- a/src/main/java/ru/ulstu/aspirant/model/Report.java +++ b/src/main/java/ru/ulstu/report/model/Report.java @@ -1,9 +1,11 @@ -package ru.ulstu.aspirant.model; +package ru.ulstu.report.model; import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; +import ru.ulstu.aspirant.model.Aspirant; import ru.ulstu.model.BaseEntity; import java.util.ArrayList; @@ -18,6 +20,12 @@ public class Report extends BaseEntity { @OneToMany private List values = new ArrayList<>(); + @ManyToOne + private ReportPeriod reportPeriod; + + @ManyToOne + private Aspirant aspirant; + public List getValues() { return values; } @@ -33,4 +41,20 @@ public class Report extends BaseEntity { public void setCreateDate(Date createDate) { this.createDate = createDate; } + + public ReportPeriod getReportPeriod() { + return reportPeriod; + } + + public void setReportPeriod(ReportPeriod reportPeriod) { + this.reportPeriod = reportPeriod; + } + + public Aspirant getAspirant() { + return aspirant; + } + + public void setAspirant(Aspirant aspirant) { + this.aspirant = aspirant; + } } diff --git a/src/main/java/ru/ulstu/aspirant/model/ReportValue.java b/src/main/java/ru/ulstu/report/model/ReportValue.java similarity index 95% rename from src/main/java/ru/ulstu/aspirant/model/ReportValue.java rename to src/main/java/ru/ulstu/report/model/ReportValue.java index 37b10da..a5f6802 100644 --- a/src/main/java/ru/ulstu/aspirant/model/ReportValue.java +++ b/src/main/java/ru/ulstu/report/model/ReportValue.java @@ -1,4 +1,4 @@ -package ru.ulstu.aspirant.model; +package ru.ulstu.report.model; import jakarta.persistence.Entity; import jakarta.persistence.ManyToOne; diff --git a/src/main/java/ru/ulstu/report/repository/ReportRepository.java b/src/main/java/ru/ulstu/report/repository/ReportRepository.java new file mode 100644 index 0000000..17c3a36 --- /dev/null +++ b/src/main/java/ru/ulstu/report/repository/ReportRepository.java @@ -0,0 +1,16 @@ +package ru.ulstu.report.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import ru.ulstu.report.model.Report; +import ru.ulstu.statistic.model.RatingItem; + +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") + 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 new file mode 100644 index 0000000..444c170 --- /dev/null +++ b/src/main/java/ru/ulstu/statistic/controller/StatisticController.java @@ -0,0 +1,36 @@ +package ru.ulstu.statistic.controller; + +import org.springframework.stereotype.Controller; +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.report.service.ReportPeriodService; +import ru.ulstu.statistic.model.StatisticForm; +import ru.ulstu.statistic.service.StatisticService; + +@Controller +@RequestMapping("statistic") +public class StatisticController { + private final ReportPeriodService reportPeriodService; + private final StatisticService statisticService; + + public StatisticController(ReportPeriodService reportPeriodService, + StatisticService statisticService) { + this.reportPeriodService = reportPeriodService; + this.statisticService = statisticService; + } + + @GetMapping("statistic") + public String getStatistic(Model model) { + model.addAttribute("statisticForm", new StatisticForm()); + model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); + return "/statistic/statistic"; + } + + @PostMapping("statistic") + public String getStatistic(StatisticForm form, Model model) { + model.addAttribute("rating", statisticService.getRating(form.getReportPeriod().getId())); + return "/statistic/statistic"; + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/statistic/model/RatingItem.java b/src/main/java/ru/ulstu/statistic/model/RatingItem.java new file mode 100644 index 0000000..8765028 --- /dev/null +++ b/src/main/java/ru/ulstu/statistic/model/RatingItem.java @@ -0,0 +1,32 @@ +package ru.ulstu.statistic.model; + +import ru.ulstu.aspirant.model.Aspirant; + +public class RatingItem { + private Aspirant aspirant; + private Integer score; + + public RatingItem() { + } + + public RatingItem(Aspirant aspirant, Integer score) { + this.aspirant = aspirant; + this.score = score; + } + + public Aspirant getAspirant() { + return aspirant; + } + + public void setAspirant(Aspirant aspirant) { + this.aspirant = aspirant; + } + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } +} diff --git a/src/main/java/ru/ulstu/statistic/model/StatisticForm.java b/src/main/java/ru/ulstu/statistic/model/StatisticForm.java new file mode 100644 index 0000000..670eeae --- /dev/null +++ b/src/main/java/ru/ulstu/statistic/model/StatisticForm.java @@ -0,0 +1,15 @@ +package ru.ulstu.statistic.model; + +import ru.ulstu.report.model.ReportPeriod; + +public class StatisticForm { + private ReportPeriod reportPeriod; + + public ReportPeriod getReportPeriod() { + return reportPeriod; + } + + public void setReportPeriod(ReportPeriod reportPeriod) { + this.reportPeriod = reportPeriod; + } +} diff --git a/src/main/java/ru/ulstu/statistic/service/StatisticService.java b/src/main/java/ru/ulstu/statistic/service/StatisticService.java new file mode 100644 index 0000000..d7a4335 --- /dev/null +++ b/src/main/java/ru/ulstu/statistic/service/StatisticService.java @@ -0,0 +1,20 @@ +package ru.ulstu.statistic.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.report.repository.ReportRepository; +import ru.ulstu.statistic.model.RatingItem; + +import java.util.List; + +@Service +public class StatisticService { + private final ReportRepository reportRepository; + + public StatisticService(ReportRepository reportRepository) { + this.reportRepository = reportRepository; + } + + public List getRating(Integer reportPeriodId) { + return reportRepository.getRating(reportPeriodId); + } +} diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 7f1ae87..0d3bae7 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -54,6 +54,7 @@ diff --git a/src/main/resources/templates/statistic/statistic.html b/src/main/resources/templates/statistic/statistic.html new file mode 100644 index 0000000..b6dec84 --- /dev/null +++ b/src/main/resources/templates/statistic/statistic.html @@ -0,0 +1,36 @@ + + +
+ +
+
+
+
+ + +
+
+
+
+ + + + + + + + + + + +
ФИОБалл
+
+ \ No newline at end of file