#120 use loading from kias

pull/221/head
T-Midnight 5 years ago
parent c21739bfc6
commit 5f214620bf

@ -27,4 +27,26 @@ public class GrantScheduler {
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished"); log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
} }
@Scheduled(cron = "0 0 8 1 * ?", zone = "Europe/Samara")
public void loadGrantsFromKias() {
log.debug("GrantScheduler.loadGrantsFromKias started");
//
// Метод для сохранения загруженных грантов
//
// List<GrantDto> grants = IndexKiasTest.getNewGrantsDto();
// grants.forEach(grantDto -> {
// try {
// if (grantService.saveFromKias(grantDto)) {
// log.debug("GrantScheduler.loadGrantsFromKias new grant was loaded");
// } else {
// log.debug("GrantScheduler.loadGrantsFromKias grant wasn't loaded, cause it's already exists");
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// });
log.debug("GrantScheduler.loadGrantsFromKias finished");
}
} }

@ -189,16 +189,31 @@ public class GrantService extends BaseService {
if (errors.hasErrors()) { if (errors.hasErrors()) {
return false; return false;
} }
if (isEmpty(grantDto.getId())) { if (isEmpty(grantDto.getId())) {
create(grantDto); create(grantDto);
} else { } else {
update(grantDto); update(grantDto);
} }
return true; return true;
} }
public boolean saveFromKias(GrantDto grantDto) throws IOException {
grantDto.setName(grantDto.getTitle());
String title = checkUniqueName(grantDto, grantDto.getId()); //проверка уникальности имени
if (title != null) {
Grant grantFromDB = grantRepository.findByTitle(title); //грант с таким же названием из бд
if (checkSameDeadline(grantDto, grantFromDB.getId())) { //если дедайны тоже совпадают
return false;
} else { //иначе грант уже был в системе, но в другом году, поэтому надо создать
create(grantDto);
return true;
}
} else { //иначе такого гранта ещё нет, поэтому надо создать
create(grantDto);
return true;
}
}
private void checkEmptyLeader(GrantDto grantDto, Errors errors) { private void checkEmptyLeader(GrantDto grantDto, Errors errors) {
if (grantDto.getLeaderId().equals(-1)) { if (grantDto.getLeaderId().equals(-1)) {
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя"); errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
@ -211,6 +226,14 @@ public class GrantService extends BaseService {
} }
} }
private boolean checkSameDeadline(GrantDto grantDto, Integer id) {
Date date = grantDto.getDeadlines().get(0).getDate(); //дата с сайта киас
if (deadlineService.findByGrantIdAndDate(id, date).compareTo(date) == 0) { //если есть такая строка с датой
return true;
}
return false;
}
public List<User> getGrantAuthors(GrantDto grantDto) { public List<User> getGrantAuthors(GrantDto grantDto) {
List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree()); List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
if (grantDto.isWasLeader()) { if (grantDto.isWasLeader()) {

Loading…
Cancel
Save