perf: 优化财务数据的采集和显示
This commit is contained in:
@@ -1,17 +1,6 @@
|
||||
package com.lanyuanxiaoyao.leopard.strategy;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.BalanceSheet;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.CashFlow;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Income;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QBalanceSheet;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QCashFlow;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QIncome;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.BalanceSheetRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.CashFlowRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.DailyRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.IncomeRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.StockRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -30,12 +19,6 @@ public class StrategyApplication {
|
||||
private StockRepository stockRepository;
|
||||
@Resource
|
||||
private DailyRepository dailyRepository;
|
||||
@Resource
|
||||
private BalanceSheetRepository balanceSheetRepository;
|
||||
@Resource
|
||||
private IncomeRepository incomeRepository;
|
||||
@Resource
|
||||
private CashFlowRepository cashFlowRepository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(StrategyApplication.class, args);
|
||||
@@ -44,85 +27,5 @@ public class StrategyApplication {
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void test() {
|
||||
var code = "600132.SH";
|
||||
for (int year = 2019; year <= 2019; year++) {
|
||||
var balance = balanceSheetRepository.findOne(
|
||||
QBalanceSheet.balanceSheet.stock.code.eq(code)
|
||||
.and(QBalanceSheet.balanceSheet.year.eq(year))
|
||||
).orElseThrow();
|
||||
var income = incomeRepository.findOne(
|
||||
QIncome.income.stock.code.eq(code)
|
||||
.and(QIncome.income.year.eq(year))
|
||||
).orElseThrow();
|
||||
var cashflow = cashFlowRepository.findOne(
|
||||
QCashFlow.cashFlow.stock.code.eq(code)
|
||||
.and(QCashFlow.cashFlow.year.eq(year))
|
||||
).orElseThrow();
|
||||
log.info("{} {}", year, calculateFinanceIndicator(balance, income, cashflow));
|
||||
}
|
||||
}
|
||||
|
||||
private FinanceIndicator calculateFinanceIndicator(BalanceSheet balance, Income income, CashFlow cashflow) {
|
||||
return new FinanceIndicator(
|
||||
safeDiv(balance.getTotalLiabilities(), balance.getTotalAssets()),
|
||||
safeDiv(balance.getTotalAssets(), balance.getTotalNonCurrentAssets()),
|
||||
safeDiv(balance.getTotalCurrentAssets(), balance.getTotalCurrentLiabilities()),
|
||||
safeDiv(safeMinus(balance.getTotalCurrentAssets(), balance.getInventories()), balance.getTotalCurrentLiabilities()),
|
||||
safeDiv(income.getOperatingRevenue(), balance.getNotesAndAccountsReceivable()),
|
||||
safeDiv(360.0, safeDiv(income.getOperatingRevenue(), balance.getNotesAndAccountsReceivable())),
|
||||
safeDiv(income.getTotalOperatingCost(), balance.getInventories()),
|
||||
safeDiv(360.0, safeDiv(income.getTotalOperatingCost(), balance.getInventories())),
|
||||
safeDiv(income.getOperatingRevenue(), balance.getTotalAssets()),
|
||||
safeDiv(income.getNetProfitIncludingMinorityInterest(), balance.getTotalShareholdersEquityExcludingMinorityInterest())
|
||||
);
|
||||
}
|
||||
|
||||
private Double safePlus(Double a, Double b) {
|
||||
if (ObjectUtil.isNull(a) || ObjectUtil.isNull(b)) {
|
||||
return null;
|
||||
}
|
||||
return a + b;
|
||||
}
|
||||
|
||||
private Double safeMinus(Double a, Double b) {
|
||||
if (ObjectUtil.isNull(a) || ObjectUtil.isNull(b)) {
|
||||
return null;
|
||||
}
|
||||
return a - b;
|
||||
}
|
||||
|
||||
private Double safeDiv(Double a, Double b) {
|
||||
if (ObjectUtil.isNull(a) || ObjectUtil.isNull(b) || b == 0) {
|
||||
return null;
|
||||
}
|
||||
return NumberUtil.div(a, b, 4);
|
||||
}
|
||||
|
||||
public record FinanceIndicator(
|
||||
Double debtToAssetRatio,
|
||||
Double longTermFundsToRealEstateRatio,
|
||||
Double currentRatio,
|
||||
Double quickRatio,
|
||||
Double accountsReceivableTurnoverRate,
|
||||
Double averageCashCollectionDays,
|
||||
Double inventoryTurnoverRate,
|
||||
Double averageSalesDays,
|
||||
Double totalAssetTurnover,
|
||||
Double roe
|
||||
) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "负债占资产比率=" + debtToAssetRatio +
|
||||
", 长期资金占固定资产比率=" + longTermFundsToRealEstateRatio +
|
||||
", 流动比率=" + currentRatio +
|
||||
", 速动比率=" + quickRatio +
|
||||
", 应收账款周转率=" + accountsReceivableTurnoverRate +
|
||||
", 平均现金回收天数=" + averageCashCollectionDays +
|
||||
", 库存周转率=" + inventoryTurnoverRate +
|
||||
", 平均销货天数=" + averageSalesDays +
|
||||
", 总资产周转率=" + totalAssetTurnover +
|
||||
", 股东权益报酬率(ROE)=" + roe +
|
||||
';';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user