核心利润获现率
代码块`import lombok.Data;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
-
核心利润获现率计算程序
-
计算公式: 经营活动流量净额/(营业收入-营业总成本-财务费用+其他收益)
*/
public class CoreProfitCashRateCalculator {/**
-
公司收入对象类
/
@Data
public static class CompanyIncome {
/* 公司名称 /
private String companyName;
/* 报告时间 (格式: 20250930) /
private String reportTime;
/* 营业收入 /
private Double operatingIncome;
/* 营业总成本 /
private Double totalOperatingCost;
/* 财务费用 /
private Double financialExpense;
/* 其他收益 /
private Double otherIncome;
/* 经营活动流量净额 /
private Double netOperatingCashFlow;
/* 核心利润获现率 /
private Double coreProfitCashRate;
/* 是否大于1.2 */
private Boolean isGreaterThan1Point2;public CompanyIncome(String companyName, String reportTime, Double operatingIncome,
Double totalOperatingCost, Double financialExpense,
Double otherIncome, Double netOperatingCashFlow) {
this.companyName = companyName;
this.reportTime = reportTime;
this.operatingIncome = operatingIncome;
this.totalOperatingCost = totalOperatingCost;
this.financialExpense = financialExpense;
this.otherIncome = otherIncome;
this.netOperatingCashFlow = netOperatingCashFlow;
}@Override
public String toString() {
return "公司名称: " + companyName +
", 报告时间: " + reportTime +
", 营业收入: " + operatingIncome +
", 营业总成本: " + totalOperatingCost +
", 财务费用: " + financialExpense +
", 其他收益: " + otherIncome +
“, 经营活动流量净额: " + netOperatingCashFlow +
“, 核心利润获现率: " + (coreProfitCashRate != null ? String.format(”%.4f”, coreProfitCashRate) : “N/A”) +
", 是否大于1.2: " + (isGreaterThan1Point2 != null ? isGreaterThan1Point2 : “N/A”);
}
}
/**
-
计算核心利润获现率
-
公式: 经营活动流量净额/(营业收入-营业总成本-财务费用+其他收益)
-
@param companyIncomeList 公司收入对象列表
-
@return 计算结果列表,按公司名称和报告时间升序排序
*/
public static List calculateCoreProfitCashRate(List companyIncomeList) {
if (companyIncomeList == null || companyIncomeList.isEmpty()) {
return new ArrayList<>();
}// 遍历列表,计算核心利润获现率
for (CompanyIncome companyIncome : companyIncomeList) {
// 计算分母: 营业收入-营业总成本-财务费用+其他收益
double denominator = companyIncome.getOperatingIncome() - companyIncome.getTotalOperatingCost()
- companyIncome.getFinancialExpense() + companyIncome.getOtherIncome();// 防止分母为0if (Math.abs(denominator) < 0.000001) {companyIncome.setCoreProfitCashRate(null);companyIncome.setIsGreaterThan1Point2(false);continue;}// 计算核心利润获现率double coreProfitCashRate = companyIncome.getNetOperatingCashFlow() / denominator;companyIncome.setCoreProfitCashRate(coreProfitCashRate);// 判断是否大于1.2companyIncome.setIsGreaterThan1Point2(coreProfitCashRate > 1.2);
}
// 按公司名称和报告时间升序排序
companyIncomeList.sort(Comparator
.comparing(CompanyIncome::getCompanyName)
.thenComparing(CompanyIncome::getReportTime));return companyIncomeList;
}
/**
-
打印核心利润获现率结果
-
@param companyIncomeList 计算结果列表
*/
public static void printCoreProfitCashRateResults(List companyIncomeList) {
if (companyIncomeList == null || companyIncomeList.isEmpty()) {
System.out.println(“没有数据可供打印”);
return;
}System.out.println(“核心利润获现率计算结果:”);
System.out.println(“==================================================”);String currentCompany = null;
for (CompanyIncome companyIncome : companyIncomeList) {
// 如果是新公司,打印公司名称
if (currentCompany == null || !currentCompany.equals(companyIncome.getCompanyName())) {
currentCompany = companyIncome.getCompanyName();
System.out.println("\n公司: " + currentCompany);
}// 打印详细信息System.out.println(" 报告时间: " + companyIncome.getReportTime() +", 核心利润获现率: " + (companyIncome.getCoreProfitCashRate() != null ?String.format("%.4f", companyIncome.getCoreProfitCashRate()) : "无法计算") +", 是否大于1.2: " + companyIncome.getIsGreaterThan1Point2());
}
System.out.println(“==================================================”);
}
/**
-
主方法,用于演示核心利润获现率计算功能
-
@param args 命令行参数
*/
public static void main(String[] args) {
// 创建测试数据
List companyIncomeList = new ArrayList<>();// 添加测试数据
companyIncomeList.add(new CompanyIncome(“比亚迪”, “20240631”, 3011.0, 2879.0, 0.69, 48.24, 141.8));
companyIncomeList.add(new CompanyIncome(“比亚迪”, “20240931”, 5023.0, 4780.0, 10.27, 90.52, 526.7));
companyIncomeList.add(new CompanyIncome(“比亚迪”, “20241231”, 7771.0, 7379.0, 12.16, 140.5, 1335.0));
companyIncomeList.add(new CompanyIncome(“比亚迪”, “20250331”, 1704.0, 1629.0, -19.08, 32.98, 85.81));
companyIncomeList.add(new CompanyIncome(“比亚迪”, “20250631”, 3713.0, 3596.0, -32.47, 66.22, 318.3));// 计算核心利润获现率
List results = calculateCoreProfitCashRate(companyIncomeList);// 打印结果
printCoreProfitCashRateResults(results);// 打印完整信息
System.out.println(“\n完整数据信息:”);
for (CompanyIncome result : results) {
System.out.println(result);
}
}
}
-
`