This commit is contained in:
@@ -6,6 +6,8 @@ import lombok.Builder;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -26,4 +28,7 @@ public class ComplaintStatisticResponse {
|
|||||||
|
|
||||||
@JsonProperty("total_cancelled")
|
@JsonProperty("total_cancelled")
|
||||||
private Long totalCancelled;
|
private Long totalCancelled;
|
||||||
|
|
||||||
|
@JsonProperty("complaints")
|
||||||
|
private Map<String, Object> complaints;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package ru.soune.nocopy.handler;
|
package ru.soune.nocopy.handler;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import ru.soune.nocopy.dto.BaseRequest;
|
import ru.soune.nocopy.dto.BaseRequest;
|
||||||
import ru.soune.nocopy.dto.BaseResponse;
|
import ru.soune.nocopy.dto.BaseResponse;
|
||||||
import ru.soune.nocopy.dto.MessageCode;
|
import ru.soune.nocopy.dto.MessageCode;
|
||||||
|
import ru.soune.nocopy.dto.complaint.ComplaintRequest;
|
||||||
import ru.soune.nocopy.dto.statistic.ComplaintStatisticResponse;
|
import ru.soune.nocopy.dto.statistic.ComplaintStatisticResponse;
|
||||||
import ru.soune.nocopy.service.statistic.ComplaintStatisticService;
|
import ru.soune.nocopy.service.statistic.ComplaintStatisticService;
|
||||||
|
|
||||||
@@ -16,9 +18,12 @@ public class StatisticComplaintHandler implements RequestHandler {
|
|||||||
|
|
||||||
private final ComplaintStatisticService complaintStatisticService;
|
private final ComplaintStatisticService complaintStatisticService;
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
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(
|
return new BaseResponse(
|
||||||
request.getMsgId(),
|
request.getMsgId(),
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package ru.soune.nocopy.service.statistic;
|
package ru.soune.nocopy.service.statistic;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
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 org.springframework.stereotype.Service;
|
||||||
|
import ru.soune.nocopy.dto.complaint.ComplaintRequest;
|
||||||
import ru.soune.nocopy.dto.statistic.ComplaintStatisticResponse;
|
import ru.soune.nocopy.dto.statistic.ComplaintStatisticResponse;
|
||||||
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
import ru.soune.nocopy.entity.complaint.ComplaintStatus;
|
||||||
import ru.soune.nocopy.repository.ComplaintEntityRepository;
|
import ru.soune.nocopy.repository.ComplaintEntityRepository;
|
||||||
|
import ru.soune.nocopy.service.complaint.ComplaintEntityService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -12,14 +20,36 @@ public class ComplaintStatisticService {
|
|||||||
|
|
||||||
private final ComplaintEntityRepository complaintEntityRepository;
|
private final ComplaintEntityRepository complaintEntityRepository;
|
||||||
|
|
||||||
public ComplaintStatisticResponse complaintStatistic() {
|
private final ComplaintEntityService complaintService;
|
||||||
|
|
||||||
|
public ComplaintStatisticResponse complaintStatistic(ComplaintRequest complaintRequest) {
|
||||||
return ComplaintStatisticResponse.builder()
|
return ComplaintStatisticResponse.builder()
|
||||||
.totalComplaints(complaintEntityRepository.getTotalComplaintsCount())
|
.totalComplaints(complaintEntityRepository.getTotalComplaintsCount())
|
||||||
.totalCancelled(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.CANCELLED))
|
.totalCancelled(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.CANCELLED))
|
||||||
.totalCreated(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.CREATED))
|
.totalCreated(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.CREATED))
|
||||||
.totalCompleted(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.COMPLETED))
|
.totalCompleted(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.COMPLETED))
|
||||||
.totalInWork(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.IN_WORK))
|
.totalInWork(complaintEntityRepository.getTotalComplaintsCountByStatus(ComplaintStatus.IN_WORK))
|
||||||
|
.complaints(handleGetAll(complaintRequest))
|
||||||
.build();
|
.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