reports-service http://jira.mfd.msk:8088/browse/CLS-25 понял про вложенность

This commit is contained in:
AKurakin 2022-12-26 17:04:58 +03:00
parent 3f0fe1d901
commit 47df118474

View file

@ -23,7 +23,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1, List<ReportBR_0420315_P1>> { public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1, ReportBR_0420315_P1> {
protected static final List<String> ALLOW_CLEARING_MEMBER_CATEGORY = Arrays.asList(ClearingCategory.I.getKey(), ClearingCategory.V.getKey()); protected static final List<String> ALLOW_CLEARING_MEMBER_CATEGORY = Arrays.asList(ClearingCategory.I.getKey(), ClearingCategory.V.getKey());
protected static final String ALLOW_CLEARING_STATUS = ClearingStatus.OK.getKey(); protected static final String ALLOW_CLEARING_STATUS = ClearingStatus.OK.getKey();
@ -55,11 +55,15 @@ public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1
} }
@Override @Override
public List<ReportBR_0420315_P1> collectReportWithPeriod(LocalDate startDate, LocalDate endDate) { public ReportBR_0420315_P1 collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
if (startDate.isAfter(endDate)) { if (startDate.isAfter(endDate)) {
throw new IllegalArgumentException("startDate(" + startDate + ") > endDate(" + endDate + ")"); throw new IllegalArgumentException("startDate(" + startDate + ") > endDate(" + endDate + ")");
} }
List<ReportBR_0420315_P1> result = new ArrayList<>(); ReportBR_0420315_P1 reportBR_0420315_p1 = new ReportBR_0420315_P1(startDate, endDate,
"BR",
"I,V", // cmc.getClearingMemberCategory()
ALLOW_CLEARING_STATUS //clearingStatus.getCode() "OK"
);
ClearingStatusDictionary allowClearingStatus = clearingStatusDictionaryImdg.getSingleObjectByFieldValues(Map.of("code", ALLOW_CLEARING_STATUS)); ClearingStatusDictionary allowClearingStatus = clearingStatusDictionaryImdg.getSingleObjectByFieldValues(Map.of("code", ALLOW_CLEARING_STATUS));
if (allowClearingStatus == null) { if (allowClearingStatus == null) {
@ -72,33 +76,35 @@ public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1
Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql); Collection<LiabilitiesClaimsAssets> liabilities = liabilitiesClaimsAssetsImdg.getCollectionObjectsBySQL(ql);
Map<Long, List<LiabilitiesClaimsAssets>> indexByCompany = MapUtil.indexList(liabilities, LiabilitiesClaimsAssets::getCompanyId); Map<Long, List<LiabilitiesClaimsAssets>> indexByCompany = MapUtil.indexList(liabilities, LiabilitiesClaimsAssets::getCompanyId);
for (Map.Entry<Long, List<LiabilitiesClaimsAssets>> companyEntry : indexByCompany.entrySet()) {
for (LiabilitiesClaimsAssets liability : liabilities) { final Long companyId = companyEntry.getKey();
final Long companyId = liability.getCompanyId(); List<LiabilitiesClaimsAssets> liabilitiesOfCompany = companyEntry.getValue();
Company company = companyImdg.getSingleObjectByID(companyId); Company company = companyImdg.getSingleObjectByID(companyId);
if (company != null) { if (company != null) {
ClearingMemberCategory cmc = clearingMemberCategoryImdg.getSingleObjectByFieldValues(Map.of("companyId", companyId)); ClearingMemberCategory cmc = clearingMemberCategoryImdg.getSingleObjectByFieldValues(Map.of("companyId", companyId));
String checkCategory = cmc == null ? null : cmc.getClearingMemberCategory(); String checkCategory = cmc == null ? null : cmc.getClearingMemberCategory();
if (!ALLOW_CLEARING_MEMBER_CATEGORY.contains(checkCategory)) { if (!ALLOW_CLEARING_MEMBER_CATEGORY.contains(checkCategory)) {
// фильтруются <> I, V // фильтруются <> I, V
log.trace("Filtered ClearingMemberCategory[{}].ClearingMemberCategory={}", log.trace("Filtered company[{}] ClearingMemberCategory[{}].ClearingMemberCategory={}",
cmc == null ? null : cmc.getId(), checkCategory); companyId, cmc == null ? null : cmc.getId(), checkCategory);
continue; continue;
} }
ReportBR_0420315_P1 reportBR_0420315_p1 = new ReportBR_0420315_P1(startDate, endDate,
"BR",
cmc.getClearingMemberCategory(),
ALLOW_CLEARING_STATUS //clearingStatus.getCode() "OK"
);
Listing listing = findListing(Market.mkrs, liability.getSecurityId()); HashSet<String> onMarket = new HashSet<>();
List<LiabilitiesClaimsAssets> allContract = indexByCompany.get(companyId);
long contractorQty; long contractorQty;
double liabilitiesAmount = 0; double liabilitiesAmount = 0;
{ {
HashSet<String> collectedToSumm = new HashSet<>(); // чтобы дважды не посчитать 1 и тот же контракт HashSet<String> collectedToSumm = new HashSet<>(); // чтобы дважды не посчитать 1 и тот же контракт
for (LiabilitiesClaimsAssets lContract : allContract) { HashSet<Long> onMarketSecurity=new HashSet<>();
for (LiabilitiesClaimsAssets lContract : liabilitiesOfCompany) {
if (!onMarketSecurity.contains(lContract.getSecurityId())) {
Listing listing = findListing(Market.mkrs, lContract.getSecurityId());
if (listing!= null) {
onMarket.add(listing.getMarket());
}
onMarketSecurity.add(lContract.getSecurityId());
}
if (lContract.getPrice() != null && StringUtils.isNotEmpty(lContract.getContract()) if (lContract.getPrice() != null && StringUtils.isNotEmpty(lContract.getContract())
&& !collectedToSumm.contains(lContract.getContract())) { && !collectedToSumm.contains(lContract.getContract())) {
collectedToSumm.add(lContract.getContract()); collectedToSumm.add(lContract.getContract());
@ -107,18 +113,20 @@ public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1
} }
contractorQty = collectedToSumm.size(); contractorQty = collectedToSumm.size();
} }
String onMarketString = StringUtils.join(onMarket, ",");
if (onMarket.size() != 1) { // Сейчас по коду ожидается один listing.market="MKRS" но потом могут быть несколько
log.warn("Market for companyId[{}]: {}", companyId, onMarketString);
}
ReportBR_0420315_P1.Info_0420315_P1 info_0420315_p1 = new ReportBR_0420315_P1.Info_0420315_P1(company.getId().toString(), ReportBR_0420315_P1.Info_0420315_P1 info_0420315_p1 = new ReportBR_0420315_P1.Info_0420315_P1(company.getId().toString(),
company.getFullName(), company.getFullName(),
listing == null ? null : listing.getMarket(), onMarketString,
String.valueOf(contractorQty), String.valueOf(contractorQty),
String.valueOf(liabilitiesAmount)); String.valueOf(liabilitiesAmount));
reportBR_0420315_p1.getRows().add(info_0420315_p1); reportBR_0420315_p1.getRows().add(info_0420315_p1);
result.add(reportBR_0420315_p1);
} }
} }
return result; return reportBR_0420315_p1;
} }