Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean isNeedToCreateNewPreventiveCategoryForAdmCase(@NonNull Case admCase) {
- if (isNull(admCase.getCitizen())) {
- return false;
- }
- Citizen citizen = citizenService.getById(admCase.getCitizen().getCitizenId());
- // Есть отметка об освобождении из мест лишения свободы.
- if (isNotEmpty(citizen.getConvictions())) {
- Date currentDate = new Date();
- if (citizen.getConvictions().stream()
- .anyMatch(conviction -> (!isNull(conviction.getReleaseDate()) && conviction.getReleaseDate().compareTo(currentDate) <= 0)
- || (!isNull(conviction.getConditionalReleaseEndDate()) && conviction.getConditionalReleaseEndDate().compareTo(currentDate) <= 0))) {
- return true;
- }
- }
- if (!isNull(admCase.getKoap()) && hasActiveAdmPunishmentResolutionType(admCase)) {
- // Назначено наказаное по по ст. 6.1.1.
- if (Objects.equals(admCase.getKoap().getArticleNumber(), KOAP_611_ARTICLE_NUMBER)) {
- return true;
- }
- List<Case> citizenCases = caseRepository.getCasesByCitizenId(citizen.getCitizenId());
- Date currentCommitDate = admCase.getCommitDate();
- List<Case> citizenCasesOverThePastYear = citizenCases.stream()
- .filter(c -> !Objects.equals(c.getCaseId(), admCase.getCaseId()))
- .filter(c -> {
- int yearsBetween = Years.yearsBetween(new DateTime(c.getCommitDate().getTime()), new DateTime(currentCommitDate.getTime())).getYears();
- return yearsBetween < 1;
- })
- .collect(Collectors.toList());
- UupPrevention prevention = uupPreventionService.findByCitizenId(citizen.getCitizenId());
- boolean isAlcoholic = !isNull(prevention)
- && uupPreventionService.hasActiveMonitoringWithCategory(uupPreventionService.findByCitizenId(citizen.getCitizenId()), UUP_PREVENTIVE_CATEGORY_ALCOHOLISM_ON_ACCOUNT);
- if (isAlcoholic) {
- boolean hasAnyAnotherCase = citizenCasesOverThePastYear.stream()
- .anyMatch(c -> !isNull(c.getKoap()) && hasActiveAdmPunishmentResolutionType(c));
- boolean hasAnIntoxicationMark = citizenCasesOverThePastYear.stream()
- .map(Case::getProtocols)
- .flatMap(Collection::stream)
- .anyMatch(protocol -> protocol.getDrunk() || !isNull(protocol.getIntoxicatedDrugType()));
- if ((hasAnyAnotherCase && hasAnIntoxicationMark)
- || (Objects.equals(admCase.getKoap().getArticleNumber(), KOAP_20_20_ARTICLE_NUMBER)
- && Objects.equals(admCase.getKoap().getArticlePart(), KOAP_20_20_PART_ONE_NUMBER))) {
- return true;
- }
- }
- boolean isAddict = !isNull(prevention)
- && uupPreventionService.hasActiveMonitoringWithCategory(uupPreventionService.findByCitizenId(citizen.getCitizenId()), UUP_PREVENTIVE_CATEGORY_NARCOMANIA_ON_ACCOUNT);
- if (isAddict) {
- List<String> koapNumbers = new ArrayList<>(Arrays.asList(KOAP_6_8_ARTICLE_NUMBER, KOAP_6_9_ARTICLE_NUMBER, KOAP_6_9_1_ARTICLE_NUMBER));
- List<String> koapParts = new ArrayList<>(Arrays.asList(KOAP_20_20_PART_TWO_NUMBER, KOAP_20_20_PART_THREE_NUMBER));
- boolean hasAppropriateAnotherCase = citizenCasesOverThePastYear.stream()
- .anyMatch(c -> !isNull(c.getKoap()) && hasActiveAdmPunishmentResolutionType(c)
- && (koapNumbers.contains(c.getKoap().getArticleNumber())
- || (Objects.equals(c.getKoap().getArticleNumber(), KOAP_20_20_ARTICLE_NUMBER) && koapParts.contains(c.getKoap().getArticlePart()))));
- if (hasAppropriateAnotherCase && (koapNumbers.contains(admCase.getKoap().getArticleNumber())
- || (Objects.equals(admCase.getKoap().getArticleNumber(), KOAP_20_20_ARTICLE_NUMBER) && koapParts.contains(admCase.getKoap().getArticlePart())))) {
- return true;
- }
- }
- if (!isNull(admCase.getMassevent()) && !isNull(admCase.getMassevent().getPurpose())
- && (isPoliticalMasseventPurpose(admCase.getMassevent().getPurpose().getReferenceId())
- || isSportMasseventPurpose(admCase.getMassevent().getPurpose().getReferenceId()))) {
- return true;
- }
- }
- uupPotentialPreventionService.deleteByAdmCaseIfExists(admCase.getCaseId());
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement