From 48c614a9cad1c4e1b9bdd07fca2841ab3f841e7d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 2 Apr 2025 23:15:46 +0400 Subject: [PATCH 01/33] #21 -- Add report period entity --- .../ru/ulstu/report/model/ReportPeriod.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/ru/ulstu/report/model/ReportPeriod.java diff --git a/src/main/java/ru/ulstu/report/model/ReportPeriod.java b/src/main/java/ru/ulstu/report/model/ReportPeriod.java new file mode 100644 index 0000000..44e4c94 --- /dev/null +++ b/src/main/java/ru/ulstu/report/model/ReportPeriod.java @@ -0,0 +1,33 @@ +package ru.ulstu.report.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.Temporal; +import jakarta.persistence.TemporalType; +import ru.ulstu.model.BaseEntity; + +import java.util.Date; + +@Entity +public class ReportPeriod extends BaseEntity { + @Temporal(TemporalType.DATE) + private Date startDate; + + @Temporal(TemporalType.DATE) + private Date endDate; + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } +} -- 2.34.1 From 54647813abd10be6a21a7d22a67f0e8eb098f40d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 2 Apr 2025 23:17:02 +0400 Subject: [PATCH 02/33] #21 -- Add report period repository --- .../ru/ulstu/report/repository/ReportPeriodRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java diff --git a/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java b/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java new file mode 100644 index 0000000..4c8b660 --- /dev/null +++ b/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.report.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.report.model.ReportPeriod; + +public interface ReportPeriodRepository extends JpaRepository { +} -- 2.34.1 From a8912f8d8c2e3f74ad7a7b899904af34b79074ee Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 2 Apr 2025 23:31:57 +0400 Subject: [PATCH 03/33] #21 -- Fix menu --- src/main/resources/templates/default.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index ed43437..a1240ff 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -52,6 +52,7 @@ -- 2.34.1 From 07fcbce47bf904da8652277355f7d108f8bc1330 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 2 Apr 2025 23:58:23 +0400 Subject: [PATCH 04/33] #21 -- Add save report period --- .../controller/ReportPeriodController.java | 47 ++++++++++++++++++ .../ru/ulstu/report/model/ReportPeriod.java | 3 ++ .../repository/ReportPeriodRepository.java | 3 ++ .../report/service/ReportPeriodService.java | 42 ++++++++++++++++ .../templates/admin/editReportPeriod.html | 49 +++++++++++++++++++ .../templates/admin/reportPeriodList.html | 31 ++++++++++++ src/main/resources/templates/default.html | 3 +- 7 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/report/controller/ReportPeriodController.java create mode 100644 src/main/java/ru/ulstu/report/service/ReportPeriodService.java create mode 100644 src/main/resources/templates/admin/editReportPeriod.html create mode 100644 src/main/resources/templates/admin/reportPeriodList.html diff --git a/src/main/java/ru/ulstu/report/controller/ReportPeriodController.java b/src/main/java/ru/ulstu/report/controller/ReportPeriodController.java new file mode 100644 index 0000000..9737c7b --- /dev/null +++ b/src/main/java/ru/ulstu/report/controller/ReportPeriodController.java @@ -0,0 +1,47 @@ +package ru.ulstu.report.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import ru.ulstu.report.model.ReportPeriod; +import ru.ulstu.report.service.ReportPeriodService; + +@Controller +@RequestMapping("admin") +public class ReportPeriodController { + private final ReportPeriodService reportPeriodService; + + public ReportPeriodController(ReportPeriodService reportPeriodService) { + this.reportPeriodService = reportPeriodService; + } + + @GetMapping("reportPeriodList") + public String getReportPeriods(Model model) { + model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); + return "admin/reportPeriodList"; + } + + @GetMapping("editReportPeriod/{reportPeriodId}") + public String getReportPeriods(@PathVariable(value = "reportPeriodId") Integer reportPeriodId, Model model) { + model.addAttribute("reportPeriod", + reportPeriodId == 0 + ? new ReportPeriod() + : reportPeriodService.getById(reportPeriodId)); + return "admin/editReportPeriod"; + } + + @PostMapping(value = "saveReportPeriod", params = "save") + public String saveReportPeriods(ReportPeriod reportPeriod) { + reportPeriodService.save(reportPeriod); + return "redirect: admin/reportPeriodList"; + } + + @PostMapping(value = "saveReportPeriod", params = "delete") + public String delete(ReportPeriod reportPeriod) { + reportPeriodService.save(reportPeriod); + return "redirect: admin/reportPeriodList"; + } +} diff --git a/src/main/java/ru/ulstu/report/model/ReportPeriod.java b/src/main/java/ru/ulstu/report/model/ReportPeriod.java index 44e4c94..a34161d 100644 --- a/src/main/java/ru/ulstu/report/model/ReportPeriod.java +++ b/src/main/java/ru/ulstu/report/model/ReportPeriod.java @@ -3,6 +3,7 @@ package ru.ulstu.report.model; import jakarta.persistence.Entity; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.model.BaseEntity; import java.util.Date; @@ -10,9 +11,11 @@ import java.util.Date; @Entity public class ReportPeriod extends BaseEntity { @Temporal(TemporalType.DATE) + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date startDate; @Temporal(TemporalType.DATE) + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date endDate; public Date getStartDate() { diff --git a/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java b/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java index 4c8b660..ef989e4 100644 --- a/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java +++ b/src/main/java/ru/ulstu/report/repository/ReportPeriodRepository.java @@ -3,5 +3,8 @@ package ru.ulstu.report.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.report.model.ReportPeriod; +import java.util.List; + public interface ReportPeriodRepository extends JpaRepository { + List findAllByOrderByStartDateDesc(); } diff --git a/src/main/java/ru/ulstu/report/service/ReportPeriodService.java b/src/main/java/ru/ulstu/report/service/ReportPeriodService.java new file mode 100644 index 0000000..9669a17 --- /dev/null +++ b/src/main/java/ru/ulstu/report/service/ReportPeriodService.java @@ -0,0 +1,42 @@ +package ru.ulstu.report.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.report.model.ReportPeriod; +import ru.ulstu.report.repository.ReportPeriodRepository; + +import java.util.List; + +@Service +public class ReportPeriodService { + private final ReportPeriodRepository reportPeriodRepository; + + public ReportPeriodService(ReportPeriodRepository reportPeriodRepository) { + this.reportPeriodRepository = reportPeriodRepository; + } + + public List getReportPeriods() { + return reportPeriodRepository.findAllByOrderByStartDateDesc(); + } + + public ReportPeriod save(ReportPeriod reportPeriod) { + ReportPeriod dbReportPeriod; + if (reportPeriod.getId() != null) { + dbReportPeriod = getById(reportPeriod.getId()); + dbReportPeriod.setStartDate(reportPeriod.getStartDate()); + dbReportPeriod.setEndDate(reportPeriod.getEndDate()); + } else { + dbReportPeriod = reportPeriod; + } + return reportPeriodRepository.save(dbReportPeriod); + } + + public void delete(ReportPeriod reportPeriod) { + reportPeriodRepository.delete(reportPeriod); + } + + public ReportPeriod getById(Integer reportPeriodId) { + return reportPeriodRepository + .findById(reportPeriodId) + .orElseThrow(() -> new RuntimeException("Report period not found by id")); + } +} diff --git a/src/main/resources/templates/admin/editReportPeriod.html b/src/main/resources/templates/admin/editReportPeriod.html new file mode 100644 index 0000000..d5f4916 --- /dev/null +++ b/src/main/resources/templates/admin/editReportPeriod.html @@ -0,0 +1,49 @@ + + +
+

Редактирование отчетного периода:

+
+ +
+ + +

+ Ошибка +

+
+ +
+ + +

+ Ошибка +

+
+ + + + Отмена +
+ + +
+ diff --git a/src/main/resources/templates/admin/reportPeriodList.html b/src/main/resources/templates/admin/reportPeriodList.html new file mode 100644 index 0000000..61e6817 --- /dev/null +++ b/src/main/resources/templates/admin/reportPeriodList.html @@ -0,0 +1,31 @@ + + +
+ + + + + + + + + + + + + + + + + + + +
Дата началаДата окончания
+ + + Редактировать + +
+
+ \ No newline at end of file diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index a1240ff..7f1ae87 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -63,11 +63,12 @@ Список показателей Список научных руководителей Список аспирантов - Новости и заседания + Список периодов отчетности Отчетность аспирантов Правила БРС Подтверждение БРС Статистика по баллам + Новости и заседания 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 -- 2.34.1 From 732ffc3441019d9d0f4e67b63d0fefb52a9a186a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 11:30:19 +0400 Subject: [PATCH 08/33] #21 -- Fix displaying statistic --- .../statistic/controller/StatisticController.java | 11 ++++++++++- .../resources/templates/statistic/statistic.html | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/statistic/controller/StatisticController.java b/src/main/java/ru/ulstu/statistic/controller/StatisticController.java index 444c170..178f7d9 100644 --- a/src/main/java/ru/ulstu/statistic/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/statistic/controller/StatisticController.java @@ -5,10 +5,15 @@ 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 { @@ -25,12 +30,16 @@ 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 diff --git a/src/main/resources/templates/statistic/statistic.html b/src/main/resources/templates/statistic/statistic.html index b6dec84..d582e03 100644 --- a/src/main/resources/templates/statistic/statistic.html +++ b/src/main/resources/templates/statistic/statistic.html @@ -5,9 +5,13 @@
-
+
+
+
+
+
+
+
+ +
+
@@ -30,6 +39,10 @@ + + + +
-- 2.34.1 From 6770d1645c1872f3b4648d8235f610d65d90997b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 11:36:21 +0400 Subject: [PATCH 09/33] #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 -- 2.34.1 From c62774aebb8722c760cd8340be2a53d1f08ac5b5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 11:41:09 +0400 Subject: [PATCH 10/33] #21 -- Fix jpql --- src/main/java/ru/ulstu/report/repository/ReportRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ru/ulstu/report/repository/ReportRepository.java b/src/main/java/ru/ulstu/report/repository/ReportRepository.java index e8c5e2e..d66abf3 100644 --- a/src/main/java/ru/ulstu/report/repository/ReportRepository.java +++ b/src/main/java/ru/ulstu/report/repository/ReportRepository.java @@ -10,7 +10,6 @@ import java.util.List; public interface ReportRepository extends JpaRepository { - // @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); } -- 2.34.1 From 6e4218fe74e76c47b667d2aeab261a5774a5caaf Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 12:15:55 +0400 Subject: [PATCH 11/33] #21 -- Fix date format --- src/main/resources/templates/admin/reportPeriodList.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/admin/reportPeriodList.html b/src/main/resources/templates/admin/reportPeriodList.html index 61e6817..9f341c4 100644 --- a/src/main/resources/templates/admin/reportPeriodList.html +++ b/src/main/resources/templates/admin/reportPeriodList.html @@ -12,12 +12,13 @@ Дата начала Дата окончания + - - + + -- 2.34.1 From 3546e016e1162aba028e7b933a1662f75f9f5831 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 12:17:55 +0400 Subject: [PATCH 12/33] #21 -- Fix date format --- src/main/resources/templates/statistic/statistic.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/statistic/statistic.html b/src/main/resources/templates/statistic/statistic.html index d582e03..c315c85 100644 --- a/src/main/resources/templates/statistic/statistic.html +++ b/src/main/resources/templates/statistic/statistic.html @@ -17,7 +17,7 @@ th:field="*{reportPeriod}"> -- 2.34.1 From 0fee0ab9ce9af903cdee9166b234faa350f11936 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 14:53:21 +0400 Subject: [PATCH 13/33] #21 -- Add report list form --- .../repository/AspirantRepository.java | 2 + .../aspirant/service/AspirantService.java | 17 ++--- .../report/controller/ReportController.java | 40 ++++++++++++ .../ru/ulstu/report/model/ReportListForm.java | 13 ++++ .../report/repository/ReportRepository.java | 6 ++ .../ulstu/report/service/ReportService.java | 35 +++++++++++ src/main/java/ru/ulstu/user/UserService.java | 4 ++ src/main/resources/templates/default.html | 8 +-- .../templates/report/reportList.html | 62 +++++++++++++++++++ 9 files changed, 175 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ru/ulstu/report/controller/ReportController.java create mode 100644 src/main/java/ru/ulstu/report/model/ReportListForm.java create mode 100644 src/main/java/ru/ulstu/report/service/ReportService.java create mode 100644 src/main/resources/templates/report/reportList.html diff --git a/src/main/java/ru/ulstu/aspirant/repository/AspirantRepository.java b/src/main/java/ru/ulstu/aspirant/repository/AspirantRepository.java index 4c3f55b..d29b562 100644 --- a/src/main/java/ru/ulstu/aspirant/repository/AspirantRepository.java +++ b/src/main/java/ru/ulstu/aspirant/repository/AspirantRepository.java @@ -2,6 +2,8 @@ package ru.ulstu.aspirant.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.aspirant.model.Aspirant; +import ru.ulstu.model.User; public interface AspirantRepository extends JpaRepository { + Aspirant findByUser(User user); } diff --git a/src/main/java/ru/ulstu/aspirant/service/AspirantService.java b/src/main/java/ru/ulstu/aspirant/service/AspirantService.java index 2b6014a..7e6d5eb 100644 --- a/src/main/java/ru/ulstu/aspirant/service/AspirantService.java +++ b/src/main/java/ru/ulstu/aspirant/service/AspirantService.java @@ -6,10 +6,10 @@ import org.springframework.stereotype.Service; import ru.ulstu.admin.model.AspirantForm; import ru.ulstu.aspirant.model.Aspirant; import ru.ulstu.aspirant.repository.AspirantRepository; -import ru.ulstu.indicator.model.Course; import ru.ulstu.indicator.model.Indicator; import ru.ulstu.indicator.service.IndicatorService; -import ru.ulstu.user.UserUtils; +import ru.ulstu.model.User; +import ru.ulstu.user.UserService; import java.util.List; @@ -17,11 +17,14 @@ import java.util.List; public class AspirantService { private final AspirantRepository aspirantRepository; private final IndicatorService indicatorService; + private final UserService userService; public AspirantService(AspirantRepository aspirantRepository, - IndicatorService indicatorService) { + IndicatorService indicatorService, + UserService userService) { this.aspirantRepository = aspirantRepository; this.indicatorService = indicatorService; + this.userService = userService; } public List getAspirants() { @@ -40,14 +43,12 @@ public class AspirantService { aspirantRepository.deleteById(aspirantForm.getId()); } - public Aspirant getAspirantByUser(String currentUserLogin) { - //return aspirantRepository.getAspirantByLogin(); - //TODO: read aspirant - return aspirantRepository.findAll().stream().findAny().orElse(new Aspirant("default", Course.FIRST)); + public Aspirant getAspirantByUser(User user) { + return aspirantRepository.findByUser(user); } public List getIndicatorsByCourse() { - Aspirant aspirant = getAspirantByUser(UserUtils.getCurrentUserLogin()); + Aspirant aspirant = getAspirantByUser(userService.getCurrentUser()); return indicatorService.getIndicatorsByCourse(aspirant.getCourse()); } diff --git a/src/main/java/ru/ulstu/report/controller/ReportController.java b/src/main/java/ru/ulstu/report/controller/ReportController.java new file mode 100644 index 0000000..9a977c2 --- /dev/null +++ b/src/main/java/ru/ulstu/report/controller/ReportController.java @@ -0,0 +1,40 @@ +package ru.ulstu.report.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.model.ReportListForm; +import ru.ulstu.report.service.ReportPeriodService; +import ru.ulstu.report.service.ReportService; + +@Controller +@RequestMapping("report") +public class ReportController { + private final ReportService reportService; + private final ReportPeriodService reportPeriodService; + + public ReportController(ReportService reportService, + ReportPeriodService reportPeriodService) { + this.reportService = reportService; + this.reportPeriodService = reportPeriodService; + } + + @GetMapping("reportList") + public String getReportPeriods(Model model) { + model.addAttribute("reportListForm", new ReportListForm()); + model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); + model.addAttribute("canCreate", false); + return "report/reportList"; + } + + @PostMapping("reportList") + public String getReportPeriods(ReportListForm reportListForm, Model model) { + model.addAttribute("reportListForm", reportListForm); + model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); + model.addAttribute("reports", reportService.getReports(reportListForm.getReportPeriod())); + model.addAttribute("canCreate", reportService.canCreateReport(reportListForm.getReportPeriod())); + return "report/reportList"; + } +} diff --git a/src/main/java/ru/ulstu/report/model/ReportListForm.java b/src/main/java/ru/ulstu/report/model/ReportListForm.java new file mode 100644 index 0000000..3dcde9e --- /dev/null +++ b/src/main/java/ru/ulstu/report/model/ReportListForm.java @@ -0,0 +1,13 @@ +package ru.ulstu.report.model; + +public class ReportListForm { + private ReportPeriod reportPeriod; + + public ReportPeriod getReportPeriod() { + return reportPeriod; + } + + public void setReportPeriod(ReportPeriod reportPeriod) { + this.reportPeriod = reportPeriod; + } +} diff --git a/src/main/java/ru/ulstu/report/repository/ReportRepository.java b/src/main/java/ru/ulstu/report/repository/ReportRepository.java index d66abf3..d28615f 100644 --- a/src/main/java/ru/ulstu/report/repository/ReportRepository.java +++ b/src/main/java/ru/ulstu/report/repository/ReportRepository.java @@ -3,13 +3,19 @@ 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.aspirant.model.Aspirant; import ru.ulstu.report.model.Report; +import ru.ulstu.report.model.ReportPeriod; import ru.ulstu.statistic.model.RatingItem; import java.util.List; public interface ReportRepository extends JpaRepository { + List findAllByReportPeriod(ReportPeriod reportPeriod); + + Report findByReportPeriodAndAspirant(ReportPeriod reportPeriod, Aspirant aspirant); + @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/report/service/ReportService.java b/src/main/java/ru/ulstu/report/service/ReportService.java new file mode 100644 index 0000000..567b86c --- /dev/null +++ b/src/main/java/ru/ulstu/report/service/ReportService.java @@ -0,0 +1,35 @@ +package ru.ulstu.report.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.aspirant.model.Aspirant; +import ru.ulstu.aspirant.service.AspirantService; +import ru.ulstu.report.model.Report; +import ru.ulstu.report.model.ReportPeriod; +import ru.ulstu.report.repository.ReportRepository; +import ru.ulstu.user.UserService; + +import java.util.List; + +@Service +public class ReportService { + private final ReportRepository reportRepository; + private final UserService userService; + private final AspirantService aspirantService; + + public ReportService(ReportRepository reportRepository, + UserService userService, + AspirantService aspirantService) { + this.reportRepository = reportRepository; + this.userService = userService; + this.aspirantService = aspirantService; + } + + public List getReports(ReportPeriod reportPeriod) { + return reportRepository.findAllByReportPeriod(reportPeriod); + } + + public boolean canCreateReport(ReportPeriod reportPeriod) { + Aspirant currentAspirant = aspirantService.getAspirantByUser(userService.getCurrentUser()); + return reportRepository.findByReportPeriodAndAspirant(reportPeriod, currentAspirant) == null; + } +} diff --git a/src/main/java/ru/ulstu/user/UserService.java b/src/main/java/ru/ulstu/user/UserService.java index 9634e54..98b419a 100644 --- a/src/main/java/ru/ulstu/user/UserService.java +++ b/src/main/java/ru/ulstu/user/UserService.java @@ -94,4 +94,8 @@ public class UserService implements UserDetailsService { public void initDefaultHead() { createDefaultUser("head", UserRoleConstants.HEAD); } + + public User getCurrentUser() { + return getUserByLogin(UserUtils.getCurrentUserLogin()); + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 0d3bae7..7f93ab9 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -37,7 +37,7 @@ aria-haspopup="true" aria-expanded="false">Аспиранту @@ -65,9 +65,9 @@ Список научных руководителей Список аспирантов Список периодов отчетности - Отчетность аспирантов Правила БРС Подтверждение БРС + Список отчетов Статистика по баллам Новости и заседания diff --git a/src/main/resources/templates/report/reportList.html b/src/main/resources/templates/report/reportList.html new file mode 100644 index 0000000..39f4f43 --- /dev/null +++ b/src/main/resources/templates/report/reportList.html @@ -0,0 +1,62 @@ + + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
Период отчетаАспирантДата созданияСтатус
+ + + Редактировать + +
+
+ \ No newline at end of file -- 2.34.1 From 0ec47113d13f2e0a6cf512cf34156559bcd204b6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 15:41:29 +0400 Subject: [PATCH 14/33] #21 -- Fix report page --- .../controller/AspirantController.java | 50 ------------------- .../report/controller/ReportController.java | 42 +++++++++++++++- src/main/resources/templates/default.html | 1 - .../{aspirant => report}/editReport.html | 7 ++- 4 files changed, 44 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/ru/ulstu/aspirant/controller/AspirantController.java rename src/main/resources/templates/{aspirant => report}/editReport.html (94%) diff --git a/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java b/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java deleted file mode 100644 index 613d358..0000000 --- a/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java +++ /dev/null @@ -1,50 +0,0 @@ -package ru.ulstu.aspirant.controller; - -import org.springframework.data.domain.Page; -import org.springframework.stereotype.Controller; -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.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; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -@Controller -@RequestMapping("aspirant") -public class AspirantController { - private static final Integer DEFAULT_PAGE_SIZE = 1; - private static final Integer DEFAULT_PAGE_NUMBER = 1; - private final AspirantService aspirantService; - - public AspirantController(AspirantService aspirantService) { - this.aspirantService = aspirantService; - } - - @GetMapping("aspirantReport") - public String createReport(Model model, - @RequestParam Optional page, - @RequestParam Optional size) { - int currentPage = page.orElse(DEFAULT_PAGE_NUMBER); - int pageSize = size.orElse(DEFAULT_PAGE_SIZE); - - Page indicators = aspirantService.getIndicatorsByCourse(new OffsetablePageRequest(currentPage - 1, pageSize)); - model.addAttribute("indicators", indicators); - int totalPages = indicators.getTotalPages(); - if (totalPages > 0) { - List pageNumbers = IntStream.rangeClosed(1, totalPages) - .boxed() - .collect(Collectors.toList()); - model.addAttribute("pageNumbers", pageNumbers); - } - - model.addAttribute("report", new Report()); - return "aspirant/editReport"; - } -} diff --git a/src/main/java/ru/ulstu/report/controller/ReportController.java b/src/main/java/ru/ulstu/report/controller/ReportController.java index 9a977c2..f7837b7 100644 --- a/src/main/java/ru/ulstu/report/controller/ReportController.java +++ b/src/main/java/ru/ulstu/report/controller/ReportController.java @@ -1,22 +1,40 @@ package ru.ulstu.report.controller; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.aspirant.service.AspirantService; +import ru.ulstu.indicator.model.Indicator; +import ru.ulstu.model.OffsetablePageRequest; +import ru.ulstu.report.model.Report; import ru.ulstu.report.model.ReportListForm; import ru.ulstu.report.service.ReportPeriodService; import ru.ulstu.report.service.ReportService; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + @Controller @RequestMapping("report") public class ReportController { + private static final Integer DEFAULT_PAGE_SIZE = 1; + private static final Integer DEFAULT_PAGE_NUMBER = 1; + + private final AspirantService aspirantService; private final ReportService reportService; private final ReportPeriodService reportPeriodService; - public ReportController(ReportService reportService, + public ReportController(AspirantService aspirantService, + ReportService reportService, ReportPeriodService reportPeriodService) { + this.aspirantService = aspirantService; this.reportService = reportService; this.reportPeriodService = reportPeriodService; } @@ -37,4 +55,26 @@ public class ReportController { model.addAttribute("canCreate", reportService.canCreateReport(reportListForm.getReportPeriod())); return "report/reportList"; } + + @GetMapping("editReport/{reportId}") + public String createReport(@PathVariable("reportId") Integer reportId, + Model model, + @RequestParam Optional page, + @RequestParam Optional size) { + int currentPage = page.orElse(DEFAULT_PAGE_NUMBER); + int pageSize = size.orElse(DEFAULT_PAGE_SIZE); + + Page indicators = aspirantService.getIndicatorsByCourse(new OffsetablePageRequest(currentPage - 1, pageSize)); + model.addAttribute("indicators", indicators); + int totalPages = indicators.getTotalPages(); + if (totalPages > 0) { + List pageNumbers = IntStream.rangeClosed(1, totalPages) + .boxed() + .collect(Collectors.toList()); + model.addAttribute("pageNumbers", pageNumbers); + } + + model.addAttribute("report", new Report()); + return "report/editReport"; + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 7f93ab9..887d301 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -36,7 +36,6 @@ diff --git a/src/main/resources/templates/aspirant/editReport.html b/src/main/resources/templates/report/editReport.html similarity index 94% rename from src/main/resources/templates/aspirant/editReport.html rename to src/main/resources/templates/report/editReport.html index 045392e..84eb4cf 100644 --- a/src/main/resources/templates/aspirant/editReport.html +++ b/src/main/resources/templates/report/editReport.html @@ -1,10 +1,9 @@ -

-
@@ -97,14 +96,14 @@ onclick="return confirm('Удалить запись?')"> Удалить - Отмена + Отмена
-- 2.34.1 From 7d40a52f19f26b59203138528021c0212c19daba Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 16:09:34 +0400 Subject: [PATCH 15/33] #21 -- Fix report indicator description --- .../ru/ulstu/report/controller/ReportController.java | 11 +++++++---- src/main/resources/templates/report/editReport.html | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/report/controller/ReportController.java b/src/main/java/ru/ulstu/report/controller/ReportController.java index f7837b7..78eee25 100644 --- a/src/main/java/ru/ulstu/report/controller/ReportController.java +++ b/src/main/java/ru/ulstu/report/controller/ReportController.java @@ -13,6 +13,7 @@ import ru.ulstu.indicator.model.Indicator; import ru.ulstu.model.OffsetablePageRequest; import ru.ulstu.report.model.Report; import ru.ulstu.report.model.ReportListForm; +import ru.ulstu.report.model.ReportPeriod; import ru.ulstu.report.service.ReportPeriodService; import ru.ulstu.report.service.ReportService; @@ -42,17 +43,19 @@ public class ReportController { @GetMapping("reportList") public String getReportPeriods(Model model) { model.addAttribute("reportListForm", new ReportListForm()); - model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); - model.addAttribute("canCreate", false); + List periods = reportPeriodService.getReportPeriods(); + model.addAttribute("reportPeriods", periods); + model.addAttribute("canCreate", !periods.isEmpty() && reportService.canCreateReport(periods.getFirst())); return "report/reportList"; } @PostMapping("reportList") public String getReportPeriods(ReportListForm reportListForm, Model model) { model.addAttribute("reportListForm", reportListForm); - model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods()); model.addAttribute("reports", reportService.getReports(reportListForm.getReportPeriod())); - model.addAttribute("canCreate", reportService.canCreateReport(reportListForm.getReportPeriod())); + List periods = reportPeriodService.getReportPeriods(); + model.addAttribute("reportPeriods", periods); + model.addAttribute("canCreate", !periods.isEmpty() && reportService.canCreateReport(periods.getFirst())); return "report/reportList"; } diff --git a/src/main/resources/templates/report/editReport.html b/src/main/resources/templates/report/editReport.html index 84eb4cf..ba87a9a 100644 --- a/src/main/resources/templates/report/editReport.html +++ b/src/main/resources/templates/report/editReport.html @@ -2,14 +2,16 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml" layout:decorate="~{default}">
-

+

- +

+

+

-- 2.34.1 From 3d699960911e41fbb2dc6e4c1aa2e3dc1695aef2 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 3 Apr 2025 22:47:16 +0400 Subject: [PATCH 17/33] #21 -- Fix file upload form --- .../templates/report/editReport.html | 80 ++----------------- 1 file changed, 5 insertions(+), 75 deletions(-) diff --git a/src/main/resources/templates/report/editReport.html b/src/main/resources/templates/report/editReport.html index 8c84be8..616fa56 100644 --- a/src/main/resources/templates/report/editReport.html +++ b/src/main/resources/templates/report/editReport.html @@ -12,84 +12,14 @@

-
- -
-
- - -
-
+
+ + + +
- - - -