Сданая 5 лаба

This commit is contained in:
DyCTaTOR 2024-06-07 18:26:55 +04:00
parent 8f8d048296
commit 233d338cb0
7 changed files with 1247 additions and 2 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ package com.example.demo.entrysData.api;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken; import org.modelmapper.TypeToken;
@ -21,6 +22,7 @@ import com.example.demo.core.configuration.Constants;
import com.example.demo.department.api.DepartmentDto; import com.example.demo.department.api.DepartmentDto;
import com.example.demo.department.service.DepartmentService; import com.example.demo.department.service.DepartmentService;
import com.example.demo.entrysData.model.EntrysDataEntity; import com.example.demo.entrysData.model.EntrysDataEntity;
import com.example.demo.entrysData.model.EntrysDataGrouped;
import com.example.demo.entrysData.model.EntrysDataGroupedDepartment; import com.example.demo.entrysData.model.EntrysDataGroupedDepartment;
import com.example.demo.entrysData.service.EntrysDataService; import com.example.demo.entrysData.service.EntrysDataService;
@ -33,7 +35,7 @@ public class EntrysDataController {
private static final String USERS_VIEW = "users"; private static final String USERS_VIEW = "users";
private static final String USERS_EDIT_VIEW = "user-edit"; private static final String USERS_EDIT_VIEW = "user-edit";
private static final String DEPARTMENTS_ATTRIBUTE = "departments"; private static final String DEPARTMENTS_ATTRIBUTE = "departments";
private static final String DEPARTMENT_ITEM_ATTRIBUTE = "departmentItem"; private static final String STATISTIC_VIEW = "statistic";
private static final String USERS_ATTRIBUTE = "users"; private static final String USERS_ATTRIBUTE = "users";
private static final String PAGE_ATTRIBUTE = "page"; private static final String PAGE_ATTRIBUTE = "page";
private final EntrysDataService entrysDataService; private final EntrysDataService entrysDataService;
@ -55,6 +57,10 @@ public class EntrysDataController {
return modelMapper.map(entity, EntrysDataGroupedDepartmentDto.class); return modelMapper.map(entity, EntrysDataGroupedDepartmentDto.class);
} }
private EntrysDataGroupedDto toDto(EntrysDataGrouped entity){
return modelMapper.map(entity, EntrysDataGroupedDto.class);
}
private EntrysDataEntity toEntity(EntrysDataDto dto) { private EntrysDataEntity toEntity(EntrysDataDto dto) {
final EntrysDataEntity entity = modelMapper.map(dto, EntrysDataEntity.class); final EntrysDataEntity entity = modelMapper.map(dto, EntrysDataEntity.class);
entity.setDepartment(departmentService.get(dto.getDepartmentId())); entity.setDepartment(departmentService.get(dto.getDepartmentId()));
@ -81,6 +87,14 @@ public class EntrysDataController {
return USERS_VIEW; return USERS_VIEW;
} }
@GetMapping("/statistic/")
public String statistic(Model model){
List<EntrysDataGrouped> list = entrysDataService.getCount();
List<EntrysDataGroupedDto> list2 = list.stream().map(this::toDto).collect(Collectors.toList());
model.addAttribute("statisctics", list2);
return STATISTIC_VIEW;
}
@GetMapping("/edit/") @GetMapping("/edit/")
public String create(Model model, public String create(Model model,
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page) { @RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page) {

View File

@ -1,6 +1,7 @@
package com.example.demo.entrysData.api; package com.example.demo.entrysData.api;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
public class EntrysDataDto { public class EntrysDataDto {
@ -8,6 +9,8 @@ public class EntrysDataDto {
@NotBlank @NotBlank
@Size(min = 3, max = 20) @Size(min = 3, max = 20)
private String login; private String login;
@NotNull
private Long departmentId;
private String role; private String role;
public Long getId() { public Long getId() {
@ -18,6 +21,14 @@ public class EntrysDataDto {
this.id = id; this.id = id;
} }
public Long getDepartmentId(){
return departmentId;
}
public void setDepartmentId(Long departmentId){
this.departmentId = departmentId;
}
public String getLogin() { public String getLogin() {
return login; return login;
} }

View File

@ -100,7 +100,8 @@ public class EntrysDataService implements UserDetailsService{
@Transactional @Transactional
public List<EntrysDataGrouped> getCount() { public List<EntrysDataGrouped> getCount() {
return repository.getCountEntrysInDepartment(); List<EntrysDataGrouped> list = repository.getCountEntrysInDepartment();
return list;
} }
@Transactional @Transactional

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Статистика пользователей</title>
</head>
<body>
<main layout:fragment="content">
<table class="table">
<caption></caption>
<thead>
<tr>
<th scope="col" class="w-50">Кафедра</th>
<th scope="col" class="w-25">Количество пользователей</th>
</tr>
</thead>
<tbody>
<tr th:each="statisctic : ${statisctics}">
<th scope="row" th:text="${statisctic.departmentName}"></th>
<th scope="row" th:text="${statisctic.count}"></th>
</tr>
</tbody>
</table>
</main>
</body>
</html>

View File

@ -15,6 +15,11 @@
<div> <div>
<a href="/users/edit/" class="btn btn-danger">Добавить пользователя</a> <a href="/users/edit/" class="btn btn-danger">Добавить пользователя</a>
</div> </div>
<div class="d-flex justify-content-right">
<a href="/admin/users/statistic/" class="btn btn-link">
<i class="fa fa-file-earmark-bar-graph">Статистика</i>
</a>
</div>
<th:block th:switch="${items.size()}"> <th:block th:switch="${items.size()}">
<h2 th:case="0">Данные отсутствуют</h2> <h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*"> <th:block th:case="*">