add history mapstores

This commit is contained in:
etreschenkov 2023-10-13 16:57:56 +03:00
parent 86a76a4488
commit 1d36a64dd5
2 changed files with 31 additions and 32 deletions

View file

@ -76,15 +76,17 @@ public abstract class AbstractSliceMapLoader<T extends WithId> implements Autoco
@Override @Override
public Iterable<Long> loadAllKeys() { public Iterable<Long> loadAllKeys() {
//fixme понять какое поле подходит большинству таблиц. created_at??? //fixme понять какое поле подходит большинству таблиц. created_at???
return Collections.emptyList(); //fixme пока выгружаются все ключи безотносительно даты
// log.debug("loading all keys from {}...", getTableName()); // return Collections.emptyList();
// Instant yesterdayInstant = Instant.now().minus(0, ChronoUnit.DAYS); // Instant yesterdayInstant = Instant.now().minus(0, ChronoUnit.DAYS);
// Instant halfYearAgo = yesterdayInstant.minus(365, 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) >= ? ", // 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)}, // new Object[]{FIREBIRD_INSTANT_FORMATTER.format(yesterdayInstant), FIREBIRD_INSTANT_FORMATTER.format(halfYearAgo)},
// (resultSet, i) -> resultSet.getObject("id", Long.class)); log.debug("loading all keys from {}...", getTableName());
// log.debug("loading all keys from {} done; size={}", getTableName(), ids.size()); List<Long> ids = jdbcTemplate.query("select id from " + getTableName(),
// return ids; (resultSet, i) -> resultSet.getObject("id", Long.class));
log.debug("loading all keys from {} done; size={}", getTableName(), ids.size());
return ids;
} }
protected LocalDate getLocalDateFromSqlDate(ResultSet rs, String column) throws SQLException { protected LocalDate getLocalDateFromSqlDate(ResultSet rs, String column) throws SQLException {

View file

@ -5,11 +5,8 @@ import org.springframework.stereotype.Component;
import ru.spcex.clearing.historyimdg.index.SearchProxyMoneyBalanceRegister; import ru.spcex.clearing.historyimdg.index.SearchProxyMoneyBalanceRegister;
import ru.spcex.clearing.imdg.IMDGDistributedNames; import ru.spcex.clearing.imdg.IMDGDistributedNames;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
@Component @Component
@ -22,30 +19,30 @@ public class SearchMoneyBalanceRegisterMapStore extends AbstractSliceMapLoader<S
protected String getTableName() { protected String getTableName() {
return "money_balance_register"; return "money_balance_register";
} }
//
@Override // @Override
public Iterable<Long> loadAllKeys() { // public Iterable<Long> loadAllKeys() {
//пример loadAllKeys // //пример loadAllKeys
log.debug("loading all keys from {}...", getTableName()); // log.debug("loading all keys from {}...", getTableName());
LocalDate upperInstant = LocalDate.now().plus(1, ChronoUnit.DAYS); // LocalDate upperInstant = LocalDate.now().plus(1, ChronoUnit.DAYS);
LocalDate halfYearAgo = upperInstant.minus(365, 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) >= ? ", // 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}, // new Object[]{upperInstant, halfYearAgo},
(resultSet, i) -> resultSet.getObject("id", Long.class)); // (resultSet, i) -> resultSet.getObject("id", Long.class));
log.debug("loading all keys from {} done; size={}", getTableName(), ids.size()); // log.debug("loading all keys from {} done; size={}", getTableName(), ids.size());
return ids; // return ids;
//LocalDate today = LocalDate.now(); // //LocalDate today = LocalDate.now();
// log.debug("loadAllKeys from {} on {} {} today", getTableName(), dateField, canBeGreat ? ">=" : "="); // // log.debug("loadAllKeys from {} on {} {} today", getTableName(), dateField, canBeGreat ? ">=" : "=");
// List<Long> keys; // // List<Long> keys;
// try { // // try {
// keys = jdbcTemplate.query("select id from " + getTableName() + " where " + dateField + (canBeGreat ? " >= ?" : " = ?"), // // keys = jdbcTemplate.query("select id from " + getTableName() + " where " + dateField + (canBeGreat ? " >= ?" : " = ?"),
// (resultSet, i) -> resultSet.getLong("id"), // // (resultSet, i) -> resultSet.getLong("id"),
// new Object[]{today}); // // new Object[]{today});
// } catch (Throwable e) { // // } catch (Throwable e) {
// log.error("At load keys from {} (by field {}): {}", getTableName(), dateField, ExceptionUtils.getStackTrace(e)); // // log.error("At load keys from {} (by field {}): {}", getTableName(), dateField, ExceptionUtils.getStackTrace(e));
// throw e; // // throw e;
// } // // }
} // }
@Override @Override
public Collection<SearchProxyMoneyBalanceRegister> load(Collection<Long> keys) { public Collection<SearchProxyMoneyBalanceRegister> load(Collection<Long> keys) {