У меня есть пять классов, которые проверяют входные нулевые и бизнес-проверки. Ниже приведен один из них, и мы перегруппировали некоторые дублирующие коды с помощью функции biConsumer, чего раньше никогда не делали. Но мы не совсем уверены, что, если многопоточность возникает одновременно, как работает функция biConsumer? Потому что это класс с состоянием прямо сейчас.
@Component
public class AgencyPersonValidation implements IPersonValidation {
private ValidationDefinitionService validationDefinitionService;
@Autowired
public AgencyPersonValidation(ValidationDefinitionService validationDefinitionService) {
this.validationDefinitionService = validationDefinitionService;
}
private final BiConsumer<PersonRequest, MapBindingResult> checkNullObjectsConsumer = (personRequest, result) -> {
validationDefinitionService.checkNullPersonnelInformation(personRequest, result);
validationDefinitionService.checkNullPersonnelOrganizationInformation(personRequest, result);
validationDefinitionService.checkPersonnelContactInformation(personRequest, result);
validationDefinitionService.checkPersonnelSalesInformation(personRequest, result);
};
private final BiConsumer<PersonRequest, MapBindingResult> checkNullFieldsConsumer = (personRequest, result) -> {
validationDefinitionService.checkNullPersonType(personRequest, result);
validationDefinitionService.checkNullRequestSystem(personRequest, result);
validationDefinitionService.checkNullCreateDate(personRequest, result);
validationDefinitionService.checkNullUpdateDate(personRequest, result);
validationDefinitionService.checkNullUpdateUserId(personRequest, result);
validationDefinitionService.checkNullCreateUserId(personRequest, result);
validationDefinitionService.checkNullName(personRequest, result);
validationDefinitionService.checkNullSurname(personRequest, result);
validationDefinitionService.checkNullMaidenName(personRequest, result);
validationDefinitionService.checkNullEmail(personRequest, result);
validationDefinitionService.checkNullBusinessLineId(personRequest, result);
validationDefinitionService.checkNullDepartmentId(personRequest, result);
validationDefinitionService.checkNullUnitRegionId(personRequest, result);
validationDefinitionService.checkNullPositionId(personRequest, result);
validationDefinitionService.checkNullTitleId(personRequest, result);
validationDefinitionService.checkNullAgencyId(personRequest, result);
validationDefinitionService.checkNullAgencyRegistrationNo(personRequest, result);
validationDefinitionService.checkNullSuperriorPersonnelId(personRequest, result);
validationDefinitionService.checkNullIdentityNumber(personRequest, result);
validationDefinitionService.checkDigitIdentityNumber(personRequest, result);
validationDefinitionService.checkNullGender(personRequest, result);
validationDefinitionService.checkNullMaritialStatus(personRequest, result);
validationDefinitionService.checkNullBirthCountryId(personRequest, result);
validationDefinitionService.checkNullBirthCityId(personRequest, result);
validationDefinitionService.checkNullBirthDate(personRequest, result);
validationDefinitionService.checkNullFatherName(personRequest, result);
validationDefinitionService.checkNullEmploymentStatus(personRequest, result);
validationDefinitionService.checkNullEmploymentStartDate(personRequest, result);
validationDefinitionService.checkNullEmploymentEndDate(personRequest, result);
validationDefinitionService.checkNullChangeStartDate(personRequest, result);
validationDefinitionService.checkNullIsTechnicalPerson(personRequest, result);
};
private final BiConsumer<PersonRequest, MapBindingResult> checkBusinessControlsConsumer = (personRequest, result) -> {
validationDefinitionService.checkTechnicalPersonnelNoIsEmpty(personRequest, result);
validationDefinitionService.checkTechnicalExamIsEmpty(personRequest, result);
validationDefinitionService.checkTechnicalPersonnelIsEmpty(personRequest, result);
validationDefinitionService.checkOldEmployeeIdIsEmpty(personRequest, result);
validationDefinitionService.checkYoungEntrepreneurGroupIdIsEmpty(personRequest, result);
validationDefinitionService.checkAgencyPersonnel(personRequest, result);
validationDefinitionService.checkSateliteIsConnectedToRegionForAgency(personRequest, result);
validationDefinitionService.checkAgencyIsConnectedToRegion(personRequest, result);
validationDefinitionService.checkAgencyTitle(personRequest, result);
};
private final BiConsumer<PersonRequest, MapBindingResult> checkDbRecordsConsumer = (personRequest, result) -> {
validationDefinitionService.checkDepartmentIdIsExist(personRequest, result);
validationDefinitionService.checkBusinessLineIdIsExist(personRequest, result);
validationDefinitionService.checkUnitRegionIdIsExist(personRequest, result);
validationDefinitionService.checkCreateUserIdExists(personRequest, result);
validationDefinitionService.checkUpdateUserIdExists(personRequest, result);
validationDefinitionService.checkPersonnelPositionIsExistsWithId(personRequest, result);
validationDefinitionService.checkPersonnelTitleIsExistsWithId(personRequest, result);
validationDefinitionService.checkDepartmentCodeIsExistsInUnitRegion(personRequest, result);
validationDefinitionService.checkSuperiorTrainingStatusIdIsExist(personRequest, result);
validationDefinitionService.checkImposedProcessTypeIsExist(personRequest, result);
validationDefinitionService.checkYoungEntrepreneurGroupIdDigitNo(personRequest, result);
};
private final BiConsumer<PersonRequest, MapBindingResult> checkBusinessControlsForUpdateConsumer = (personRequest, result) -> {
validationDefinitionService.checkPersonIsSuitableForUpdate(personRequest, result);
validationDefinitionService.checkQuitedPersonHasATeam(personRequest, result);
validationDefinitionService.checkPersonDepartmentChanges(personRequest, result);
validationDefinitionService.checkAlreadyExistsSateliteBranch(personRequest, result);
};
@Override
public void doCreateValidation(PersonRequest personRequest, MapBindingResult result) {
checkNullObjectsConsumer.accept(personRequest, result);
checkNullFieldsConsumer
.andThen((per, res) -> validationDefinitionService.checkNullEmployeeIdPrefix(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullEmployeeId(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullUsername(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullNationalityId(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullAccessIdList(per, res)).accept(personRequest,result);
checkDbRecordsConsumer
.andThen((per, res) -> validationDefinitionService.checkEmployeeIdExists(per, res))
.andThen((per, res) -> validationDefinitionService.checkUsernameIsExist(per, res))
.andThen((per, res) -> validationDefinitionService.checkSuperiorJobIdIsExist(per, res))
.andThen((per, res) -> validationDefinitionService.checkExemptionTrainingStatusIdExist(per, res))
.andThen((per, res) -> validationDefinitionService.checkTrainingsAreExist(per, res)).accept(personRequest,result);
checkBusinessControlsConsumer
.andThen((per, res) -> validationDefinitionService.checkPersonTypeCreate(per, res)).accept(personRequest,result);
}
@Override
public void doUpdateValidation(PersonRequest personRequest, MapBindingResult result) {
checkNullObjectsConsumer.accept(personRequest, result);
checkNullFieldsConsumer
.andThen((per, res) -> validationDefinitionService.checkNullEmployeeIdPrefix(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullEmployeeId(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullUsername(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullNationalityId(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullAccessIdList(per, res)).accept(personRequest,result);
checkDbRecordsConsumer
.andThen((per, res) -> validationDefinitionService.isPersonnelNotExist(per, res))
.andThen((per, res) -> validationDefinitionService.checkPersonnelUserNotExists(per, res)).accept(personRequest,result);
checkBusinessControlsConsumer.accept(personRequest, result);
checkBusinessControlsForUpdateConsumer.accept(personRequest, result);
}
@Override
public void doSmCreateValidation(PersonRequest personRequest, MapBindingResult result) {
checkNullObjectsConsumer.accept(personRequest, result);
checkNullFieldsConsumer
.andThen((per, res) -> validationDefinitionService.checkNullProcessStatus(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullRequestId(per, res)).accept(personRequest,result);
checkDbRecordsConsumer
.andThen((per, res) -> validationDefinitionService.checkEmployeeIdExists(per, res)).accept(personRequest,result);
checkBusinessControlsConsumer
.andThen((per, res) -> validationDefinitionService.checkPersonTypeCreate(per, res)).accept(personRequest,result);
}
@Override
public void doSmUpdateValidation(PersonRequest personRequest, MapBindingResult result) {
checkNullObjectsConsumer.accept(personRequest, result);
checkNullFieldsConsumer
.andThen((per, res) -> validationDefinitionService.checkNullSMRecordId(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullEmployeeId(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullProcessStatus(per, res))
.andThen((per, res) -> validationDefinitionService.checkNullRequestId(per, res)).accept(personRequest,result);
checkDbRecordsConsumer
.andThen((per, res) -> validationDefinitionService.checkSMRecordIdIsExist(per, res))
.andThen((per, res) -> validationDefinitionService.isPersonnelNotExist(per, res))
.andThen((per, res) -> validationDefinitionService.checkPersonnelUserNotExists(per, res)).accept(personRequest,result);
checkBusinessControlsConsumer.accept(personRequest, result);
checkBusinessControlsForUpdateConsumer.accept(personRequest, result);
}
}
ValidationDefinitionService, который автоматически подключается к agencyPersonValidation, также является одноэлементным классом, но не с состоянием. Неужели у нас есть проблемы с многопоточностью из этого кода? Или функции biConsumer просто выполняют свою работу только для каждого потока?
Заранее спасибо.