готовая лаб 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); return modelMapper.map(entity, EntrysDataDto.class);
} }
private EntrysDataGroupedDto toGroupedDto(EntrysDataGrouped entity){ private EntrysDataGroupedDto toGroupedDto(EntrysDataGrouped entity) {
return modelMapper.map(entity, EntrysDataGroupedDto.class); return modelMapper.map(entity, EntrysDataGroupedDto.class);
} }
@ -53,9 +53,9 @@ public class EntrysDataController {
@GetMapping @GetMapping
public PageDto<EntrysDataDto> getAll( public PageDto<EntrysDataDto> getAll(
@RequestParam(name = "departmentId", defaultValue = "0") Long departmentId, @RequestParam(name = "departmentId", defaultValue = "0") Long departmentId,
@RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = Constants.DEFAULT_PAGE_SIZE) int size) { @RequestParam(name = "size", defaultValue = Constants.DEFAULT_PAGE_SIZE) int size) {
return PageDtoMapper.toDto(entrysDataService.getAll(departmentId, page, size), this::toDto); return PageDtoMapper.toDto(entrysDataService.getAll(departmentId, page, size), this::toDto);
} }
@ -85,8 +85,12 @@ public class EntrysDataController {
@RequestParam(name = "oldPassword") String oldPas) { @RequestParam(name = "oldPassword") String oldPas) {
return toDto(entrysDataService.updatePassword(id, newPas, oldPas)); return toDto(entrysDataService.updatePassword(id, newPas, oldPas));
} }
@GetMapping("/count") @GetMapping("/count")
public List<EntrysDataGroupedDto> getCount(){ public List<EntrysDataGroupedDto> getCount() {
return entrysDataService.getCount().stream().map(this::toGroupedDto).toList(); 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 { public class EntrysDataGroupedDto {
private Long DepartmentId; private Long DepartmentId;
private int Count; private Long Count;
public Long getDepartmentId(){ public Long getDepartmentId() {
return DepartmentId; return DepartmentId;
} }
public void setDepartmentId(Long DepartmentId){
public void setDepartmentId(Long DepartmentId) {
this.DepartmentId = DepartmentId; this.DepartmentId = DepartmentId;
} }
public int getCount(){ public Long getCount() {
return Count; return Count;
} }
public void setCount(int Count){ public void setCount(Long Count) {
this.Count = Count; this.Count = Count;
} }
} }

View File

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

View File

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

View File

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