dev add statistic files protected
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-04-15 18:28:42 +07:00
parent 2d80b40b27
commit be62dd458a
8 changed files with 137 additions and 1 deletions
@@ -42,7 +42,8 @@ public class HandlerConfig {
StatisticUserFilesHandler statisticUserHandler,
StatisticTariffInfoFileHandler statisticTariffInfoFileHandler,
StatisticUserDynamicHandler statisticUserDynamicHandler,
StatisticProtectedFilesHandler statisticProtectedFilesHandler
StatisticProtectedFilesHandler statisticProtectedFilesHandler,
StatisticViolationHandler statisticViolationHandler
) {
Map<Integer, RequestHandler> map = new HashMap<>();
@@ -77,6 +78,7 @@ public class HandlerConfig {
map.put(30020, statisticTariffInfoFileHandler);
map.put(30021, statisticUserDynamicHandler);
map.put(30022, statisticProtectedFilesHandler);
map.put(30023, statisticViolationHandler);
return map;
}
@@ -0,0 +1,7 @@
package ru.soune.nocopy.dto.statistic;
import lombok.Data;
@Data
public class ViolationStatisticRequest {
}
@@ -0,0 +1,32 @@
package ru.soune.nocopy.dto.statistic;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ViolationStatisticResponse {
@JsonProperty("total_violations")
private Long totalViolations;
@JsonProperty("total_complaints")
private Long totalComplaints;
@JsonProperty("total_law_cases")
private Long totalLawCases;
@JsonProperty("complaints_without_case")
private Long complaintsWithoutCase;
@JsonProperty("violations_with_complaint")
private Long violationsWithComplaint;
@JsonProperty("violations_without_complaint")
private Long violationsWithoutComplaint;
}
@@ -0,0 +1,34 @@
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.statistic.ViolationStatisticResponse;
import ru.soune.nocopy.service.statistic.ViolationStatisticService;
@Component
@RequiredArgsConstructor
@Slf4j
public class StatisticViolationHandler implements RequestHandler {
private final ObjectMapper objectMapper;
private final ViolationStatisticService statisticService;
@Override
public BaseResponse handle(BaseRequest request) throws Exception {
log.debug("Handling violation statistic request, msgId: {}", request.getMsgId());
ViolationStatisticResponse statistics = statisticService.getViolationStatistics();
return new BaseResponse(
request.getMsgId(),
MessageCode.SUCCESS.getCode(),
MessageCode.SUCCESS.getDescription(),
statistics
);
}
}
@@ -25,4 +25,16 @@ public interface ComplaintEntityRepository extends JpaRepository<ComplaintEntity
@Transactional
@Query("UPDATE ComplaintEntity c SET c.status = :status WHERE c.id = :id")
int updateStatus(Long id, ComplaintStatus status);
@Query("SELECT COUNT(c.id) FROM ComplaintEntity c")
Long getTotalComplaintsCount();
@Query("""
SELECT COUNT(c.id)
FROM ComplaintEntity c
WHERE NOT EXISTS (
SELECT 1 FROM LawCase lc WHERE lc.violationId = c.violation.id
)
""")
Long getComplaintsWithoutLawCaseCount();
}
@@ -39,4 +39,7 @@ public interface LawCaseRepository extends JpaRepository<LawCase, Long> {
@Param("priority") LawCasePriority priority,
@Param("violationId") Long violationId,
Pageable pageable);
@Query("SELECT COUNT(lc.id) FROM LawCase lc")
Long getTotalLawCasesCount();
}
@@ -74,4 +74,10 @@ public interface ViolationRepository extends JpaRepository<Violation, Long> {
List<Violation> findByFileEntityInAndStatusAndCreatedDateBetween(List<FileEntity> files, String status,
LocalDateTime startDate, LocalDateTime endDate,
Sort sort);
@Query("SELECT COUNT(v.id) FROM Violation v")
Long getTotalViolationsCount();
@Query("SELECT COUNT(DISTINCT c.violation.id) FROM ComplaintEntity c WHERE c.violation IS NOT NULL")
Long getViolationsWithComplaintCount();
}
@@ -0,0 +1,40 @@
package ru.soune.nocopy.service.statistic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.soune.nocopy.dto.statistic.ViolationStatisticResponse;
import ru.soune.nocopy.repository.ComplaintEntityRepository;
import ru.soune.nocopy.repository.LawCaseRepository;
import ru.soune.nocopy.repository.ViolationRepository;
@Service
@RequiredArgsConstructor
@Slf4j
public class ViolationStatisticService {
private final ViolationRepository violationRepository;
private final ComplaintEntityRepository complaintRepository;
private final LawCaseRepository lawCaseRepository;
public ViolationStatisticResponse getViolationStatistics() {
Long totalViolations = violationRepository.getTotalViolationsCount();
Long totalComplaints = complaintRepository.getTotalComplaintsCount();
Long totalLawCases = lawCaseRepository.getTotalLawCasesCount();
Long complaintsWithoutCase = complaintRepository.getComplaintsWithoutLawCaseCount();
Long violationsWithComplaint = violationRepository.getViolationsWithComplaintCount();
Long violationsWithoutComplaint = totalViolations - violationsWithComplaint;
return ViolationStatisticResponse.builder()
.totalViolations(totalViolations != null ? totalViolations : 0L)
.totalComplaints(totalComplaints != null ? totalComplaints : 0L)
.totalLawCases(totalLawCases != null ? totalLawCases : 0L)
.complaintsWithoutCase(complaintsWithoutCase != null ? complaintsWithoutCase : 0L)
.violationsWithComplaint(violationsWithComplaint != null ? violationsWithComplaint : 0L)
.violationsWithoutComplaint(violationsWithoutComplaint)
.build();
}
}