готовая лаб 3

This commit is contained in:
DyCTaTOR 2024-04-21 21:12:49 +04:00
parent 7094911275
commit c26da9cafc
7 changed files with 3104 additions and 18 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,7 @@ public class EntrysDataController {
return modelMapper.map(entity, EntrysDataDto.class);
}
private EntrysDataGroupedDto toGroupedDto(EntrysDataGrouped entity){
private EntrysDataGroupedDto toGroupedDto(EntrysDataGrouped entity) {
return modelMapper.map(entity, EntrysDataGroupedDto.class);
}
@ -53,9 +53,9 @@ public class EntrysDataController {
@GetMapping
public PageDto<EntrysDataDto> getAll(
@RequestParam(name = "departmentId", defaultValue = "0") Long departmentId,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = Constants.DEFAULT_PAGE_SIZE) int size) {
@RequestParam(name = "departmentId", defaultValue = "0") Long departmentId,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = Constants.DEFAULT_PAGE_SIZE) int size) {
return PageDtoMapper.toDto(entrysDataService.getAll(departmentId, page, size), this::toDto);
}
@ -85,8 +85,12 @@ public class EntrysDataController {
@RequestParam(name = "oldPassword") String oldPas) {
return toDto(entrysDataService.updatePassword(id, newPas, oldPas));
}
@GetMapping("/count")
public List<EntrysDataGroupedDto> getCount(){
return entrysDataService.getCount().stream().map(this::toGroupedDto).toList();
public List<EntrysDataGroupedDto> getCount() {
var val1 = entrysDataService.getCount().stream();
var val2 = val1.map(this::toGroupedDto).toList();
List<EntrysDataGroupedDto> list = val2;
return list;
}
}

View File

@ -3,20 +3,21 @@ package com.example.demo.entrysData.api;
public class EntrysDataGroupedDto {
private Long DepartmentId;
private int Count;
private Long Count;
public Long getDepartmentId(){
public Long getDepartmentId() {
return DepartmentId;
}
public void setDepartmentId(Long DepartmentId){
public void setDepartmentId(Long DepartmentId) {
this.DepartmentId = DepartmentId;
}
public int getCount(){
public Long getCount() {
return Count;
}
public void setCount(int Count){
public void setCount(Long Count) {
this.Count = Count;
}
}

View File

@ -3,5 +3,5 @@ package com.example.demo.entrysData.model;
public interface EntrysDataGrouped {
Long getDepartmentId();
int getCount();
Long getCount();
}

View File

@ -22,9 +22,8 @@ public interface EntrysDataRepository extends CrudRepository<EntrysDataEntity, L
Page<EntrysDataEntity> findAll(Pageable pageable);
@Query("SELECT department_id, COUNT(id) AS count_id" +
"FROM entrys_data" +
"GROUP BY department_id" +
"ORDER BY count_id DESC")
@Query("SELECT e.department.id AS departmentId, COUNT(e.id) AS count " +
"FROM EntrysDataEntity e " +
"GROUP BY departmentId ORDER BY count DESC")
List<EntrysDataGrouped> getCountEntrysInDepartment();
}

View File

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