From 0c522e2faf3ceea478414f95d2a7bb068408773a Mon Sep 17 00:00:00 2001 From: backdev-1 Date: Thu, 21 May 2026 13:15:11 +0700 Subject: [PATCH] dev check violation for lawcase,complaint --- src/main/java/ru/soune/nocopy/dto/MessageCode.java | 1 + .../ru/soune/nocopy/handler/ComplaintEntityHandler.java | 6 ++++++ .../java/ru/soune/nocopy/handler/LawCaseHandler.java | 7 +++++++ .../java/ru/soune/nocopy/handler/ViolationHandler.java | 3 +-- .../soune/nocopy/service/violation/ViolationService.java | 9 +++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/soune/nocopy/dto/MessageCode.java b/src/main/java/ru/soune/nocopy/dto/MessageCode.java index b16c839..6a74be6 100644 --- a/src/main/java/ru/soune/nocopy/dto/MessageCode.java +++ b/src/main/java/ru/soune/nocopy/dto/MessageCode.java @@ -18,6 +18,7 @@ public enum MessageCode { FILE_NOT_EXIST(2, "File not exist on disk"), FILE_DELETE(2, "File was deleted"), USER_NOT_HAD_PERMISSION(2, "User not have permission for file"), + NOT_OWNER_FILE_STATUS_VIOLATION(2, "Violation in not owner file status"), USER_NOT_VERIFIED(2, "User not verified"), LAW_CASE_NOT_FOUND(4, "Law case not found"), PERMISSION_NOT_FOUND(2, "Permission not found"), diff --git a/src/main/java/ru/soune/nocopy/handler/ComplaintEntityHandler.java b/src/main/java/ru/soune/nocopy/handler/ComplaintEntityHandler.java index 09f2b01..da189cd 100644 --- a/src/main/java/ru/soune/nocopy/handler/ComplaintEntityHandler.java +++ b/src/main/java/ru/soune/nocopy/handler/ComplaintEntityHandler.java @@ -23,6 +23,7 @@ import ru.soune.nocopy.repository.ViolationRepository; import ru.soune.nocopy.service.complaint.ComplaintEntityService; import ru.soune.nocopy.service.register.AuthService; import ru.soune.nocopy.service.user.UserService; +import ru.soune.nocopy.service.violation.ViolationStatus; import java.util.*; @@ -99,6 +100,11 @@ public class ComplaintEntityHandler implements RequestHandler { MessageCode.USER_NOT_HAD_PERMISSION.getDescription()); } + if (violation.getStatus().equals(ViolationStatus.NOT_OWNER_FILE.name())) { + return errorResponse(msgId, MessageCode.USER_NOT_HAD_PERMISSION.getCode(), + MessageCode.USER_NOT_HAD_PERMISSION.getDescription()); + } + if (complaintEntityRepository.existsByViolationId(violationId)) { return errorResponse(msgId, MessageCode.COMPLAINT_ALREADY_EXIST.getCode(), MessageCode.COMPLAINT_ALREADY_EXIST.getDescription()); diff --git a/src/main/java/ru/soune/nocopy/handler/LawCaseHandler.java b/src/main/java/ru/soune/nocopy/handler/LawCaseHandler.java index 33fbfee..0b4e3f9 100644 --- a/src/main/java/ru/soune/nocopy/handler/LawCaseHandler.java +++ b/src/main/java/ru/soune/nocopy/handler/LawCaseHandler.java @@ -28,6 +28,7 @@ import ru.soune.nocopy.service.register.AuthService; import ru.soune.nocopy.service.tariff.TariffConstants; import ru.soune.nocopy.service.tariff.TariffInfoService; import ru.soune.nocopy.service.violation.ViolationService; +import ru.soune.nocopy.service.violation.ViolationStatus; import java.io.IOException; import java.util.*; @@ -163,12 +164,18 @@ public class LawCaseHandler implements RequestHandler { private BaseResponse createLawCase(Long userId, LawCaseRequest lawCaseRequest, BaseRequest request) { validateRequiredParameters(lawCaseRequest, request, userId); Long violationId = lawCaseRequest.getViolationId(); + Violation violation = violationService.getById(violationId); if (lawCaseService.lawCaseExistByViolationId(violationId)) { return new BaseResponse(request.getMsgId(), MessageCode.LAW_CASE_ALREADY_EXIST.getCode(), MessageCode.LAW_CASE_ALREADY_EXIST.getDescription(), "Law case was already exists"); } + if (violation != null && violation.getStatus().equals(ViolationStatus.NOT_OWNER_FILE.name())) { + return new BaseResponse(request.getMsgId(), MessageCode.USER_NOT_HAD_PERMISSION.getCode(), + MessageCode.USER_NOT_HAD_PERMISSION.getDescription(), "Wrong status"); + } + try { tariffInfoService.writeOffTokens(userId, TariffConstants.LEGAL_COST, OperationType.CREATE_LEGAL_CASE); } catch (TariffNotFoundException e) { diff --git a/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java b/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java index 19c845b..08ab9a4 100644 --- a/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java +++ b/src/main/java/ru/soune/nocopy/handler/ViolationHandler.java @@ -159,8 +159,7 @@ public class ViolationHandler implements RequestHandler { violationRequest.getStatus(), violationRequest.getPage(), violationRequest.getSize(), - violationRequest.getSortDirection() - ); + violationRequest.getSortDirection()); ViolationResponse.ViolationDto firstShowViolation = null; List content = violationPage.getContent(); diff --git a/src/main/java/ru/soune/nocopy/service/violation/ViolationService.java b/src/main/java/ru/soune/nocopy/service/violation/ViolationService.java index 501f9dc..df44636 100644 --- a/src/main/java/ru/soune/nocopy/service/violation/ViolationService.java +++ b/src/main/java/ru/soune/nocopy/service/violation/ViolationService.java @@ -90,9 +90,18 @@ public class ViolationService { cb.between(root.get("createdDate"), startDate, endDate)); } + List allStatuses = Arrays.asList( + "NEW", "SHOWED", "LEGAL_IN_WORK", + "COMPLAINT_IN_WORK", "COMPLAINT_AND_LEGAL_IN_WORK", + "AUTHORIZED_USE" + ); + if (status != null && !status.isEmpty()) { spec = spec.and((root, query, cb) -> cb.equal(root.get("status"), status)); + } else { + spec = spec.and((root, query, cb) -> + root.get("status").in(allStatuses)); } Sort sort = Sort.by("ASC".equalsIgnoreCase(sortDirection) ?