#21 -- Add classes for statistic
This commit is contained in:
parent
fcdd90924c
commit
36d6f44378
@ -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;
|
||||
|
@ -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<ReportValue> values = new ArrayList<>();
|
||||
|
||||
@ManyToOne
|
||||
private ReportPeriod reportPeriod;
|
||||
|
||||
@ManyToOne
|
||||
private Aspirant aspirant;
|
||||
|
||||
public List<ReportValue> 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;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package ru.ulstu.aspirant.model;
|
||||
package ru.ulstu.report.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
@ -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<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")
|
||||
List<RatingItem> getRating(@Param("reportPeriodId") Integer reportPeriodId);
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
32
src/main/java/ru/ulstu/statistic/model/RatingItem.java
Normal file
32
src/main/java/ru/ulstu/statistic/model/RatingItem.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
15
src/main/java/ru/ulstu/statistic/model/StatisticForm.java
Normal file
15
src/main/java/ru/ulstu/statistic/model/StatisticForm.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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<RatingItem> getRating(Integer reportPeriodId) {
|
||||
return reportRepository.getRating(reportPeriodId);
|
||||
}
|
||||
}
|
@ -54,6 +54,7 @@
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<a class="dropdown-item" href="/admin/reportPeriodList">Список периодов отчетности</a>
|
||||
<a class="dropdown-item" href="/listAspirantReports">Список отчетов</a>
|
||||
<a class="dropdown-item" href="/statistic/statistic">Статистика по баллам</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown" sec:authorize="hasRole('ROLE_ADMIN')">
|
||||
@ -67,7 +68,7 @@
|
||||
<a class="dropdown-item" href="/admin/reports">Отчетность аспирантов</a>
|
||||
<a class="dropdown-item" href="/admin/rules">Правила БРС</a>
|
||||
<a class="dropdown-item" href="/admin/confirmation">Подтверждение БРС</a>
|
||||
<a class="dropdown-item" href="/admin/stats">Статистика по баллам</a>
|
||||
<a class="dropdown-item" href="/statistic/statistic">Статистика по баллам</a>
|
||||
<a class="dropdown-item" href="/admin">Новости и заседания</a>
|
||||
</div>
|
||||
</li>
|
||||
|
36
src/main/resources/templates/statistic/statistic.html
Normal file
36
src/main/resources/templates/statistic/statistic.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
||||
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
layout:decorate="~{default}">
|
||||
<div class="container" layout:fragment="content">
|
||||
|
||||
<form action="/statistic/statistic" method="post" th:object="${statisticForm}">
|
||||
<div class="row">
|
||||
<div class="col col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="period">Период отчетности</label>
|
||||
<select class="form-select form-control"
|
||||
id="period" aria-label="multiple select example"
|
||||
th:field="*{reportPeriod}">
|
||||
<option th:each="p : ${reportPeriods}"
|
||||
th:value="${p.id}"
|
||||
th:text="${p.startDate + ' - ' + p.endDate}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Таблица рейтинга -->
|
||||
<table class="table table-bordered table-striped mt-3">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th scope="col">ФИО</th>
|
||||
<th scope="col">Балл</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user