项目初始化
This commit is contained in:
@@ -261,6 +261,63 @@ public class ErpScreenController {
|
||||
return chartDataItems;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "getErpYearChart")
|
||||
@ResponseBody
|
||||
public List<ChartDataItem> getErpYearChart(ErpTransactionFlow erpTransactionFlow) {
|
||||
List<ChartDataItem> chartDataItems = new ArrayList<>();
|
||||
List<ErpTransactionFlow> flowList = erpTransactionFlowService.findList(erpTransactionFlow);
|
||||
Map<String, Map<String, Object>> yearMap = flowList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
ErpTransactionFlow::getYearDate, // 这里改成年
|
||||
Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||
BigDecimal sumValue01 = list.stream()
|
||||
.filter(flow -> flow.getFlowType().equals("2"))
|
||||
.map(ErpTransactionFlow::getAmount)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal sumValue02 = list.stream()
|
||||
.filter(flow -> flow.getFlowType().equals("1"))
|
||||
.map(ErpTransactionFlow::getAmount)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal sumValue04 = BigDecimalUtils.subtract(sumValue01, sumValue02);
|
||||
BigDecimal sumValue03 = BigDecimalUtils.percent(sumValue04, sumValue01);
|
||||
return Map.of(
|
||||
"sumValue01", sumValue01,
|
||||
"sumValue02", sumValue02,
|
||||
"sumValue03", sumValue03,
|
||||
"sumValue04", sumValue04
|
||||
);
|
||||
})
|
||||
));
|
||||
List<String> sortedYears = new ArrayList<>(yearMap.keySet());
|
||||
Collections.sort(sortedYears);
|
||||
for (int i = 0; i < sortedYears.size(); i++) {
|
||||
String currentYear = sortedYears.get(i);
|
||||
Map<String, Object> current = yearMap.get(currentYear);
|
||||
BigDecimal income = (BigDecimal) current.get("sumValue01");
|
||||
BigDecimal expend = (BigDecimal) current.get("sumValue02");
|
||||
BigDecimal profitRate = (BigDecimal) current.get("sumValue03");
|
||||
BigDecimal profit = (BigDecimal) current.get("sumValue04");
|
||||
BigDecimal lastIncome = BigDecimal.ZERO;
|
||||
BigDecimal lastExpend = BigDecimal.ZERO;
|
||||
if (i > 0) {
|
||||
String lastYear = sortedYears.get(i - 1);
|
||||
Map<String, Object> lastData = yearMap.get(lastYear);
|
||||
lastIncome = (BigDecimal) lastData.get("sumValue01");
|
||||
lastExpend = (BigDecimal) lastData.get("sumValue02");
|
||||
}
|
||||
ChartDataItem item = new ChartDataItem();
|
||||
item.setAxisName(currentYear); // 年份作为X轴
|
||||
item.setValue01(income.toString()); // 本年收入
|
||||
item.setValue02(expend.toString()); // 本年支出
|
||||
item.setValue03(profitRate.toString()); // 利润率
|
||||
item.setValue04(profit.toString()); // 净利润
|
||||
item.setValue05(lastIncome.toString()); // 上年收入
|
||||
item.setValue06(lastExpend.toString()); // 上年支出
|
||||
chartDataItems.add(item);
|
||||
}
|
||||
return chartDataItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* 季度收支
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user