This commit is contained in:
@@ -6,6 +6,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@@ -26,4 +28,7 @@ public class ComplaintStatisticResponse {
|
||||
|
||||
@JsonProperty("total_cancelled")
|
||||
private Long totalCancelled;
|
||||
|
||||
@JsonProperty("complaints")
|
||||
private Map<String, Object> complaints;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.soune.nocopy.dto.BaseRequest;
|
||||
import ru.soune.nocopy.dto.BaseResponse;
|
||||
import ru.soune.nocopy.dto.MessageCode;
|
||||
import ru.soune.nocopy.dto.complaint.ComplaintRequest;
|
||||
import ru.soune.nocopy.dto.statistic.ComplaintStatisticResponse;
|
||||
import ru.soune.nocopy.service.statistic.ComplaintStatisticService;
|
||||
|
||||
@@ -16,9 +18,12 @@ public class StatisticComplaintHandler implements RequestHandler {
|
||||
|
||||
private final ComplaintStatisticService complaintStatisticService;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
ComplaintStatisticResponse complaintStatisticResponse = complaintStatisticService.complaintStatistic();
|
||||
ComplaintRequest complaintRequest = objectMapper.convertValue(request.getMessageBody(), ComplaintRequest.class);
|
||||
ComplaintStatisticResponse complaintStatisticResponse = complaintStatisticService.complaintStatistic(complaintRequest);
|
||||
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package ru.soune.nocopy.service.statistic;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.dto.complaint.ComplaintRequest;
|
||||
import ru.soune.nocopy.dto.statistic.ComplaintStatisticResponse;
|
||||
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
||||
import ru.soune.nocopy.repository.ComplaintEntityRepository;
|
||||
import ru.soune.nocopy.service.complaint.ComplaintEntityService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -12,14 +20,36 @@ public class ComplaintStatisticService {
|
||||
|
||||
private final ComplaintEntityRepository complaintEntityRepository;
|
||||
|
||||
public ComplaintStatisticResponse complaintStatistic() {
|
||||
private final ComplaintEntityService complaintService;
|
||||
|
||||
public ComplaintStatisticResponse complaintStatistic(ComplaintRequest complaintRequest) {
|
||||
return ComplaintStatisticResponse.builder()
|
||||
.totalComplaints(complaintEntityRepository.getTotalComplaintsCount())
|
||||
.totalCancelled(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.CANCELLED))
|
||||
.totalCreated(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.CREATED))
|
||||
.totalCompleted(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.COMPLETED))
|
||||
.totalInWork(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.IN_WORK))
|
||||
.complaints(handleGetAll(complaintRequest))
|
||||
.build();
|
||||
}
|
||||
|
||||
private Map<String, Object> handleGetAll(ComplaintRequest req) {
|
||||
Pageable pageable = PageRequest.of(
|
||||
req.getPage() != null ? req.getPage() : 0,
|
||||
req.getSize() != null ? req.getSize() : 5,
|
||||
Sort.by(Sort.Direction.fromString(
|
||||
req.getSortDirection() != null ? req.getSortDirection() : "desc"),
|
||||
req.getSortBy() != null ? req.getSortBy() : "updatedAt"));
|
||||
|
||||
var page = complaintService.getAllComplaints(pageable);
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("content", page.getContent());
|
||||
data.put("page", page.getNumber() + 1);
|
||||
data.put("size", page.getSize());
|
||||
data.put("totalElements", page.getTotalElements());
|
||||
data.put("totalPages", page.getTotalPages());
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user