reports-service правки IMDG, т.к. Hazelcast <4.0.0 не умеет Instant сравнивать через SQL!
This commit is contained in:
parent
e794177155
commit
220239de6e
14 changed files with 176 additions and 10 deletions
|
|
@ -58,6 +58,11 @@ public abstract class ReportDataCollector<T extends AbstractReport> {
|
|||
|
||||
protected String toString(LocalDate date) {
|
||||
if (date == null) return null;
|
||||
return DATE_TIME_FORMATTER.format(date);
|
||||
return DATE_FORMATTER.format(date);
|
||||
}
|
||||
|
||||
protected String formatToIMDGInstant(LocalDate date) {
|
||||
LocalDateTime ldt = date.atStartOfDay();
|
||||
return DATE_TIME_FORMATTER.format(ldt);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@ import ru.spcex.platform.enumeration.ClearingStatus;
|
|||
import ru.spcex.platform.enumeration.Market;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -52,6 +56,22 @@ public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1
|
|||
return listingImdg.getSingleObjectByFieldValues(qParam);
|
||||
}
|
||||
|
||||
Collection<LiabilitiesClaimsAssets> searchLiabilitiesClaimsAssets(LocalDate startDate, LocalDate endDate, Long allowClearingStatusId) {
|
||||
// String ql = String.format("'%s' <= refundDate and refundDate <= '%s' and clearingStatus=%s",
|
||||
// formatToIMDGInstant(startDate), formatToIMDGInstant(endDate), allowClearingStatusId);
|
||||
// Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql);
|
||||
//todo refactoring IMDG API, TimeUtil
|
||||
ImdgPredicateBuilder pb = liabilitiesClaimsAssetsImdg.predicateBuilder();
|
||||
Instant dateTimeLo = startDate.atStartOfDay(TimeUtil.zone).toInstant();
|
||||
Instant dateTimeHi = endDate.plusDays(1).atStartOfDay(TimeUtil.zone).minusSeconds(1).toInstant();
|
||||
|
||||
ImdgPredicate p=pb.and(pb.and(pb.greatEqual("refundDate", dateTimeLo),
|
||||
pb.lessEqual("refundDate", dateTimeHi)),
|
||||
pb.equals("clearingStatus", allowClearingStatusId));
|
||||
Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsByPredicate(p);
|
||||
return liabilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReportBR_0420315_P1 collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
|
||||
validateDateRange(startDate, endDate);
|
||||
|
|
@ -63,9 +83,7 @@ public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1
|
|||
|
||||
final Long allowClearingStatusId = MapUtil.getDictionaryIdByCode(clearingStatusDictionaryImdg, ALLOW_CLEARING_STATUS); // "OK"
|
||||
|
||||
String ql = String.format("'%s' <= refundDate and refundDate <= '%s' and clearingStatus=%s",
|
||||
startDate, endDate, allowClearingStatusId);
|
||||
Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql);
|
||||
Collection<LiabilitiesClaimsAssets> liabilities = searchLiabilitiesClaimsAssets(startDate, endDate, allowClearingStatusId);
|
||||
|
||||
Map<Long, List<LiabilitiesClaimsAssets>> indexByCompany = MapUtil.indexList(liabilities, LiabilitiesClaimsAssets::getCompanyId);
|
||||
company_for:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class Bt17_1_P2_collector extends ReportDataCollector<ReportBR_0420315_P2
|
|||
@Override
|
||||
public ReportBR_0420315_P2 collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
|
||||
validateDateRange(startDate, endDate);
|
||||
String ql = String.format("'%s' <= refundDate and refundDate <= '%s'", startDate, endDate);
|
||||
String ql = String.format("'%s' <= refundDate and refundDate <= '%s'", formatToIMDGInstant(startDate), formatToIMDGInstant(endDate));
|
||||
Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql);
|
||||
|
||||
long contractorQty;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class Bt17_2_collector extends ReportDataCollector<ReportBR_0420317> {
|
|||
public ReportBR_0420317 collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
|
||||
validateDateRange(startDate, endDate);
|
||||
|
||||
String ql = String.format("'%s' <= updated and updated <= '%s' and service='MKR'", startDate, endDate);
|
||||
String ql = String.format("'%s' <= updated and updated <= '%s' and service='MKR'", formatToIMDGInstant(startDate), formatToIMDGInstant(endDate));
|
||||
// todo обговорить про updatedAt updated, todo enum MKR
|
||||
Collection<Relation> relations = relationImdg.getCollectionObjectsBySQL(ql);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class Bt17_5_P1_collector extends ReportDataCollector<ReportBR_0420312_P1
|
|||
// todo обговорить про updatedAt updated, todo enum MKR
|
||||
|
||||
String ql = String.format("'%s' <= refundDate and refundDate <= '%s'",
|
||||
startDate, endDate);
|
||||
formatToIMDGInstant(startDate), formatToIMDGInstant(endDate));
|
||||
Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql);
|
||||
Map<Long, List<LiabilitiesClaimsAssets>> indexByCompany = MapUtil.indexList(liabilities, LiabilitiesClaimsAssets::getCompanyId);
|
||||
for (Map.Entry<Long, List<LiabilitiesClaimsAssets>> companyEntry : indexByCompany.entrySet()) {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class Repbr0420314_P1_bt_17_4_collector extends ReportDataCollector<Repor
|
|||
final Long allowClearingStatusId = MapUtil.getDictionaryIdByCode(clearingStatusDictionaryImdg, ALLOW_CLEARING_STATUS); // "OK"
|
||||
|
||||
String ql = String.format("'%s' <= refundDate and refundDate <= '%s' and clearingStatus=%s",
|
||||
startDate, endDate, allowClearingStatusId);
|
||||
formatToIMDGInstant(startDate), formatToIMDGInstant(endDate), allowClearingStatusId);
|
||||
Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql);
|
||||
|
||||
for (LiabilitiesClaimsAssets liability: liabilities) {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class Repbr0420314_P2_bt_17_4_collector extends ReportDataCollector<Repor
|
|||
);
|
||||
|
||||
String ql = String.format("'%s' <= created and created <= '%s'",
|
||||
startDate, endDate);
|
||||
formatToIMDGInstant(startDate), formatToIMDGInstant(endDate));
|
||||
Collection<PaymentInstruction> paymentInstructionsAll = paymentInstructionImdg.getCollectionObjectsBySQL(ql);
|
||||
|
||||
Map<Long, List<PaymentInstruction>> companyIdPyPaymtInstruction =
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ reports-service.kafka-consumer.buffer-memory=33554432
|
|||
#reports-service.kafka-producer.linger-ms=1
|
||||
#reports-service.kafka-producer.buffer-memory=33554432
|
||||
|
||||
reports-service.hazelcast.cluster-members=127.0.0.1:5701,10.200.200.181:5701
|
||||
reports-service.hazelcast.cluster-members=127.0.0.1:5701
|
||||
#,10.200.200.181:5701
|
||||
reports-service.hazelcast.login=dev
|
||||
reports-service.hazelcast.password=dev-pass
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.predicate.ImdgPredicateBuilderHazelcast;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.predicate.ImdgPredicateHazelcast;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -181,4 +185,26 @@ public class ImdgHazelcast<T extends SpcexObjectBase> implements Imdg<T> {
|
|||
public void setMapName(String mapName) {
|
||||
this.mapName = mapName;
|
||||
}
|
||||
|
||||
|
||||
// Predicate API
|
||||
@Override
|
||||
public Collection<T> getCollectionObjectsByPredicate(ImdgPredicate predicateImdg) {
|
||||
Predicate hazelcastPredicate = ((ImdgPredicateHazelcast) predicateImdg).getRawPredicate();
|
||||
Set<Long> ids = map.keySet(hazelcastPredicate);
|
||||
Iterator<Long> idIterator = ids.iterator();
|
||||
Collection<T> searchResult = new ArrayList<>();
|
||||
while (idIterator.hasNext()) {
|
||||
T element = map.get(idIterator.next());
|
||||
if (element != null) {
|
||||
searchResult.add(element);
|
||||
}
|
||||
}
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicateBuilder predicateBuilder() {
|
||||
return new ImdgPredicateBuilderHazelcast(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
package ru.spcex.platform.imdg.iml.hazelcast.adapter.predicate;
|
||||
|
||||
import com.hazelcast.query.Predicates;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
|
||||
public class ImdgPredicateBuilderHazelcast implements ImdgPredicateBuilder {
|
||||
protected final ImdgHazelcast imdg;
|
||||
|
||||
public ImdgPredicateBuilderHazelcast(ImdgHazelcast imdg) {
|
||||
this.imdg = imdg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate equals(String key, Object value) {
|
||||
Comparable cmpValue = (Comparable) value;
|
||||
return new ImdgPredicateHazelcast(this, Predicates.equal(key, cmpValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate greatEqual(String key, Comparable cmpValue) {
|
||||
return new ImdgPredicateHazelcast(this, Predicates.greaterEqual(key, cmpValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate lessEqual(String key, Comparable cmpValue) {
|
||||
return new ImdgPredicateHazelcast(this, Predicates.lessEqual(key, cmpValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate greater(String key, Comparable cmpValue) {
|
||||
return new ImdgPredicateHazelcast(this, Predicates.greaterThan(key, cmpValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate less(String key, Comparable cmpValue) {
|
||||
return new ImdgPredicateHazelcast(this, Predicates.lessThan(key, cmpValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate not(ImdgPredicate param) {
|
||||
ImdgPredicateHazelcast paramMy = (ImdgPredicateHazelcast) param;
|
||||
assert this == paramMy.builder;
|
||||
return new ImdgPredicateHazelcast(this, Predicates.not(paramMy.hazelcastPredicate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate and(ImdgPredicate paramA, ImdgPredicate paramB) {
|
||||
ImdgPredicateHazelcast paramAMy = (ImdgPredicateHazelcast) paramA;
|
||||
assert this == paramAMy.builder;
|
||||
ImdgPredicateHazelcast paramBMy = (ImdgPredicateHazelcast) paramB;
|
||||
assert this == paramBMy.builder;
|
||||
return new ImdgPredicateHazelcast(this, Predicates.and(paramAMy.hazelcastPredicate, paramBMy.hazelcastPredicate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate or(ImdgPredicate paramA, ImdgPredicate paramB) {
|
||||
ImdgPredicateHazelcast paramAMy = (ImdgPredicateHazelcast) paramA;
|
||||
assert this == paramAMy.builder;
|
||||
ImdgPredicateHazelcast paramBMy = (ImdgPredicateHazelcast) paramB;
|
||||
assert this == paramBMy.builder;
|
||||
return new ImdgPredicateHazelcast(this, Predicates.or(paramAMy.hazelcastPredicate, paramBMy.hazelcastPredicate));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package ru.spcex.platform.imdg.iml.hazelcast.adapter.predicate;
|
||||
|
||||
import com.hazelcast.query.Predicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
|
||||
public class ImdgPredicateHazelcast implements ImdgPredicate {
|
||||
protected final ImdgPredicateBuilderHazelcast builder;
|
||||
protected final Predicate hazelcastPredicate;
|
||||
|
||||
protected ImdgPredicateHazelcast(ImdgPredicateBuilderHazelcast builder, Predicate hazelcastPredicate) {
|
||||
assert hazelcastPredicate != null;
|
||||
this.builder = builder;
|
||||
this.hazelcastPredicate = hazelcastPredicate;
|
||||
}
|
||||
|
||||
public Predicate getRawPredicate() {
|
||||
return hazelcastPredicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ImdgPredicateHazelcast{" + hazelcastPredicate + '}';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package ru.spcex.platform.imdg.api;
|
||||
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
|
@ -65,4 +67,13 @@ public interface Imdg<T extends SpcexObjectBase> {
|
|||
default Integer size() {
|
||||
throw new UnsupportedOperationException("not implemented size");
|
||||
}
|
||||
|
||||
// Predicate API
|
||||
default Collection<T> getCollectionObjectsByPredicate(ImdgPredicate predicate) {
|
||||
throw new UnsupportedOperationException("not implemented getCollectionObjectsByPredicate");
|
||||
}
|
||||
|
||||
default ImdgPredicateBuilder predicateBuilder() {
|
||||
throw new UnsupportedOperationException("not implemented predicateBuilder API");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
package ru.spcex.platform.imdg.api.predicate;
|
||||
|
||||
public interface ImdgPredicate {
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package ru.spcex.platform.imdg.api.predicate;
|
||||
|
||||
public interface ImdgPredicateBuilder {
|
||||
ImdgPredicate equals(String key, Object value);
|
||||
ImdgPredicate greatEqual(String key, Comparable value);
|
||||
ImdgPredicate lessEqual(String key, Comparable value);
|
||||
ImdgPredicate greater(String key, Comparable value);
|
||||
ImdgPredicate less(String key, Comparable value);
|
||||
|
||||
ImdgPredicate not(ImdgPredicate param);
|
||||
ImdgPredicate and(ImdgPredicate paramA, ImdgPredicate paramB);
|
||||
ImdgPredicate or(ImdgPredicate paramA, ImdgPredicate paramB);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue