Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.02 KB | None | 0 0
  1.     public boolean isNeedToCreateNewPreventiveCategoryForAdmCase(@NonNull Case admCase) {
  2.         if (isNull(admCase.getCitizen())) {
  3.             return false;
  4.         }
  5.  
  6.         Citizen citizen = citizenService.getById(admCase.getCitizen().getCitizenId());
  7.  
  8.         // Есть отметка об освобождении из мест лишения свободы.
  9.         if (isNotEmpty(citizen.getConvictions())) {
  10.             Date currentDate = new Date();
  11.             if (citizen.getConvictions().stream()
  12.                     .anyMatch(conviction -> (!isNull(conviction.getReleaseDate()) && conviction.getReleaseDate().compareTo(currentDate) <= 0)
  13.                             || (!isNull(conviction.getConditionalReleaseEndDate()) && conviction.getConditionalReleaseEndDate().compareTo(currentDate) <= 0))) {
  14.                 return true;
  15.             }
  16.         }
  17.  
  18.         if (!isNull(admCase.getKoap()) && hasActiveAdmPunishmentResolutionType(admCase)) {
  19.  
  20.             // Назначено наказаное по по ст. 6.1.1.
  21.             if (Objects.equals(admCase.getKoap().getArticleNumber(), KOAP_611_ARTICLE_NUMBER)) {
  22.                 return true;
  23.             }
  24.  
  25.             List<Case> citizenCases = caseRepository.getCasesByCitizenId(citizen.getCitizenId());
  26.             Date currentCommitDate = admCase.getCommitDate();
  27.             List<Case> citizenCasesOverThePastYear = citizenCases.stream()
  28.                     .filter(c -> !Objects.equals(c.getCaseId(), admCase.getCaseId()))
  29.                     .filter(c -> {
  30.                         int yearsBetween = Years.yearsBetween(new DateTime(c.getCommitDate().getTime()), new DateTime(currentCommitDate.getTime())).getYears();
  31.                         return yearsBetween < 1;
  32.                     })
  33.                     .collect(Collectors.toList());
  34.  
  35.             UupPrevention prevention = uupPreventionService.findByCitizenId(citizen.getCitizenId());
  36.             boolean isAlcoholic = !isNull(prevention)
  37.                     && uupPreventionService.hasActiveMonitoringWithCategory(uupPreventionService.findByCitizenId(citizen.getCitizenId()), UUP_PREVENTIVE_CATEGORY_ALCOHOLISM_ON_ACCOUNT);
  38.             if (isAlcoholic) {
  39.                 boolean hasAnyAnotherCase = citizenCasesOverThePastYear.stream()
  40.                         .anyMatch(c -> !isNull(c.getKoap()) && hasActiveAdmPunishmentResolutionType(c));
  41.                 boolean hasAnIntoxicationMark = citizenCasesOverThePastYear.stream()
  42.                         .map(Case::getProtocols)
  43.                         .flatMap(Collection::stream)
  44.                         .anyMatch(protocol -> protocol.getDrunk() || !isNull(protocol.getIntoxicatedDrugType()));
  45.                 if ((hasAnyAnotherCase && hasAnIntoxicationMark)
  46.                         || (Objects.equals(admCase.getKoap().getArticleNumber(), KOAP_20_20_ARTICLE_NUMBER)
  47.                         && Objects.equals(admCase.getKoap().getArticlePart(), KOAP_20_20_PART_ONE_NUMBER))) {
  48.                     return true;
  49.                 }
  50.             }
  51.  
  52.             boolean isAddict = !isNull(prevention)
  53.                     && uupPreventionService.hasActiveMonitoringWithCategory(uupPreventionService.findByCitizenId(citizen.getCitizenId()), UUP_PREVENTIVE_CATEGORY_NARCOMANIA_ON_ACCOUNT);
  54.             if (isAddict) {
  55.                 List<String> koapNumbers = new ArrayList<>(Arrays.asList(KOAP_6_8_ARTICLE_NUMBER, KOAP_6_9_ARTICLE_NUMBER, KOAP_6_9_1_ARTICLE_NUMBER));
  56.                 List<String> koapParts = new ArrayList<>(Arrays.asList(KOAP_20_20_PART_TWO_NUMBER, KOAP_20_20_PART_THREE_NUMBER));
  57.                 boolean hasAppropriateAnotherCase = citizenCasesOverThePastYear.stream()
  58.                         .anyMatch(c -> !isNull(c.getKoap()) && hasActiveAdmPunishmentResolutionType(c)
  59.                                 && (koapNumbers.contains(c.getKoap().getArticleNumber())
  60.                                 || (Objects.equals(c.getKoap().getArticleNumber(), KOAP_20_20_ARTICLE_NUMBER) && koapParts.contains(c.getKoap().getArticlePart()))));
  61.                 if (hasAppropriateAnotherCase && (koapNumbers.contains(admCase.getKoap().getArticleNumber())
  62.                         || (Objects.equals(admCase.getKoap().getArticleNumber(), KOAP_20_20_ARTICLE_NUMBER) && koapParts.contains(admCase.getKoap().getArticlePart())))) {
  63.                     return true;
  64.                 }
  65.             }
  66.  
  67.             if (!isNull(admCase.getMassevent()) && !isNull(admCase.getMassevent().getPurpose())
  68.                     && (isPoliticalMasseventPurpose(admCase.getMassevent().getPurpose().getReferenceId())
  69.                     || isSportMasseventPurpose(admCase.getMassevent().getPurpose().getReferenceId()))) {
  70.                 return true;
  71.             }
  72.         }
  73.  
  74.         uupPotentialPreventionService.deleteByAdmCaseIfExists(admCase.getCaseId());
  75.         return false;
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement