etreschenkov 2023-10-18 13:37:43 +03:00
parent 41ce70416c
commit 657a3e79eb
12 changed files with 66 additions and 41 deletions

View file

@ -16,6 +16,7 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import static ru.spcex.clearing.imdg.base.ObjectBaseMapStore.MAX_IN_CLAUSE_SIZE;
@ -75,20 +76,21 @@ public abstract class AbstractSliceMapLoader<T extends WithId> implements Autoco
@Override
public Iterable<Long> loadAllKeys() {
//fixme понять какое поле подходит большинству таблиц. created_at???
//fixme пока выгружаются все ключи безотносительно даты
// return Collections.emptyList();
// Instant yesterdayInstant = Instant.now().minus(0, ChronoUnit.DAYS);
// Instant halfYearAgo = yesterdayInstant.minus(365, ChronoUnit.DAYS);
// List<Long> ids = jdbcTemplate.query("select id from " + getTableName() + " where CAST(tradingday as DATE) <= ? and CAST(tradingday as DATE) >= ? ",
// new Object[]{FIREBIRD_INSTANT_FORMATTER.format(yesterdayInstant), FIREBIRD_INSTANT_FORMATTER.format(halfYearAgo)},
log.debug("loading all keys from {}...", getTableName());
List<Long> ids = jdbcTemplate.query("select id from " + getTableName(),
(resultSet, i) -> resultSet.getObject("id", Long.class));
LocalDate yesterdayInstant = LocalDate.now().minus(0, ChronoUnit.DAYS);
// Instant yesterdayInstant = Instant.now().minus(0, ChronoUnit.DAYS);
LocalDate fewDaysAgo = yesterdayInstant.minus(2, ChronoUnit.DAYS);
String fieldOfDay = fieldOfDay();
List<Long> ids = jdbcTemplate.query("select id from " + getTableName() + " where " + fieldOfDay + " <= ? " +
"and " + fieldOfDay + " >= ? ",
(resultSet, i) -> resultSet.getLong("id"),
yesterdayInstant, fewDaysAgo);
log.debug("loading all keys from {} done; size={}", getTableName(), ids.size());
return ids;
}
protected abstract String fieldOfDay();
protected LocalDate getLocalDateFromSqlDate(ResultSet rs, String column) throws SQLException {
Date date = rs.getDate(column);
return date != null ? date.toLocalDate() : null;

View file

@ -19,7 +19,12 @@ public class SearchAdmittedLiabilitiesRegisterMapStore extends AbstractSliceMapL
protected String getTableName() {
return "admitted_liabilities_register";
}
//
@Override
protected String fieldOfDay() {
return "clearing_date";
}
@Override
public Collection<SearchProxyAdmittedLiabilitiesRegister> load(Collection<Long> keys) {

View file

@ -19,7 +19,11 @@ public class SearchCoveredLiabilitiesRegisterMapStore extends AbstractSliceMapLo
protected String getTableName() {
return "covered_liabilities_register";
}
//
@Override
protected String fieldOfDay() {
return "clearing_date";
}
@Override
public Collection<SearchProxyCoveredLiabilitiesRegister> load(Collection<Long> keys) {

View file

@ -20,6 +20,10 @@ public class SearchDepoPaymentInstructionRegisterMapStore extends AbstractSliceM
return "depo_payment_instruction_register";
}
@Override
protected String fieldOfDay() {
return "CREATED_AT";
}
@Override
public Collection<SearchProxyDepoPaymentInstructionRegister> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);
@ -34,7 +38,7 @@ public class SearchDepoPaymentInstructionRegisterMapStore extends AbstractSliceM
@Override
public String getMapName() {
return IMDGDistributedNames.Map_SearchMoneyPaymentInstructionRegister;
return IMDGDistributedNames.Map_SearchDepoPaymentInstructionRegister;
}
@Override

View file

@ -20,6 +20,10 @@ public class SearchExcludeLiabilitiesRegisterMapStore extends AbstractSliceMapLo
return "exclude_liabilities_register";
}
@Override
protected String fieldOfDay() {
return "CREATED_AT";
}
@Override
public Collection<SearchProxyExcludeLiabilitiesRegister> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);
@ -34,7 +38,7 @@ public class SearchExcludeLiabilitiesRegisterMapStore extends AbstractSliceMapLo
@Override
public String getMapName() {
return IMDGDistributedNames.Map_SearchMoneyPaymentInstructionRegister;
return IMDGDistributedNames.Map_SearchExcludeLiabilitiesRegister;
}
@Override

View file

@ -20,6 +20,11 @@ public class SearchExecutionDepositMapStore extends AbstractSliceMapLoader<Searc
return "execution_deposit";
}
@Override
protected String fieldOfDay() {
return "trading_date";
}
@Override
public Collection<SearchProxyExecutionDeposit> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);

View file

@ -20,6 +20,11 @@ public class SearchExecutionFondMapStore extends AbstractSliceMapLoader<SearchPr
return "execution_fond";
}
@Override
protected String fieldOfDay() {
return "trading_date";
}
@Override
public Collection<SearchProxyExecutionFond> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);

View file

@ -20,6 +20,11 @@ public class SearchExecutionRegisterMapStore extends AbstractSliceMapLoader<Sear
return "execution_fond";
}
@Override
protected String fieldOfDay() {
return "trading_date";
}
@Override
public Collection<SearchProxyExecutionRegister> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);
@ -34,7 +39,7 @@ public class SearchExecutionRegisterMapStore extends AbstractSliceMapLoader<Sear
@Override
public String getMapName() {
return IMDGDistributedNames.Map_SearchExecutionFond;
return IMDGDistributedNames.Map_SearchExecutionRegister;
}
@Override

View file

@ -20,6 +20,11 @@ public class SearchLiabilitiesRegisterMapStore extends AbstractSliceMapLoader<Se
return "liabilities_register";
}
@Override
protected String fieldOfDay() {
return "CREATED_AT";
}
@Override
public Collection<SearchProxyLiabilitiesRegister> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);
@ -34,7 +39,7 @@ public class SearchLiabilitiesRegisterMapStore extends AbstractSliceMapLoader<Se
@Override
public String getMapName() {
return IMDGDistributedNames.Map_SearchMoneyPaymentInstructionRegister;
return IMDGDistributedNames.Map_SearchLiabilitiesRegister;
}
@Override

View file

@ -19,30 +19,11 @@ public class SearchMoneyBalanceRegisterMapStore extends AbstractSliceMapLoader<S
protected String getTableName() {
return "money_balance_register";
}
//
// @Override
// public Iterable<Long> loadAllKeys() {
// //пример loadAllKeys
// log.debug("loading all keys from {}...", getTableName());
// LocalDate upperInstant = LocalDate.now().plus(1, ChronoUnit.DAYS);
// LocalDate halfYearAgo = upperInstant.minus(365, ChronoUnit.DAYS);
// List<Long> ids = jdbcTemplate.query("select id from " + getTableName() + " where CAST(created_at as DATE) <= ? and CAST(created_at as DATE) >= ? ",
// new Object[]{upperInstant, halfYearAgo},
// (resultSet, i) -> resultSet.getObject("id", Long.class));
// log.debug("loading all keys from {} done; size={}", getTableName(), ids.size());
// return ids;
// //LocalDate today = LocalDate.now();
// // log.debug("loadAllKeys from {} on {} {} today", getTableName(), dateField, canBeGreat ? ">=" : "=");
// // List<Long> keys;
// // try {
// // keys = jdbcTemplate.query("select id from " + getTableName() + " where " + dateField + (canBeGreat ? " >= ?" : " = ?"),
// // (resultSet, i) -> resultSet.getLong("id"),
// // new Object[]{today});
// // } catch (Throwable e) {
// // log.error("At load keys from {} (by field {}): {}", getTableName(), dateField, ExceptionUtils.getStackTrace(e));
// // throw e;
// // }
// }
@Override
protected String fieldOfDay() {
return "CREATED_AT";
}
@Override
public Collection<SearchProxyMoneyBalanceRegister> load(Collection<Long> keys) {

View file

@ -20,6 +20,11 @@ public class SearchMoneyPaymentInstructionRegisterMapStore extends AbstractSlice
return "money_payment_instruction_register";
}
@Override
protected String fieldOfDay() {
return "clearing_date";
}
@Override
public Collection<SearchProxyMoneyPaymentInstructionRegister> load(Collection<Long> keys) {
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);

View file

@ -2,9 +2,9 @@ imdg.hist.hazelcast.listenPort=5702
imdg.hist.hazelcast.login=dev-hist
imdg.hist.hazelcast.password=dev-pass-hist
imdg.hist.hazelcast.cluster-members[0]=127.0.0.1
imdg.hist.database.login=clearing
imdg.hist.database.login=cls_dev
imdg.hist.database.password=Aa111111
imdg.hist.database.url=jdbc:postgresql://10.200.200.133:5432/clearing?currentSchema=clearing_prod
imdg.hist.database.url=jdbc:postgresql://10.200.200.133:5432/clearing?currentSchema=clearing_dev
#imdg.database.url=jdbc:postgresql://10.200.200.133:5432/postgres?currentSchema=clearing_tester
#debug tester mode: