项目初始化

This commit is contained in:
2026-03-23 17:38:35 +08:00
parent 876b3800b4
commit 6011e29abf
12 changed files with 1554 additions and 1108 deletions

View File

@@ -0,0 +1,124 @@
package com.jeesite.modules.apps.Module;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class ChartDataItem implements Serializable {
/**
* 项目编号
*/
private String itemCode;
/**
* 序号
*/
private Long soring;
/**
* X轴名称
*/
private String axisName;
/**
* 指标01
*/
private String value01;
/**
* 指标02
*/
private String value02;
/**
* 指标03
*/
private String value03;
/**
* 指标04
*/
private String value04;
/**
* 指标05
*/
private String value05;
/**
* 指标06
*/
private String value06;
/**
* 指标07
*/
private String value07;
/**
* 指标08
*/
private String value08;
/**
* 指标09
*/
private String value09;
/**
* 指标10
*/
private String value10;
/**
* 指标11
*/
private String value11;
/**
* 指标12
*/
private String value12;
/**
* 指标13
*/
private String value13;
/**
* 指标14
*/
private String value14;
/**
* 指标15
*/
private String value15;
/**
* 业务主键编号
*/
private String bizKey;
/**
* 指标求和
*/
private BigDecimal indexSum;
/**
* 指标平均
*/
private BigDecimal indexAvg;
/**
* 指标最大
*/
private BigDecimal indexMax;
/**
* 指标最小
*/
private BigDecimal indexMin;
}

View File

@@ -0,0 +1,168 @@
package com.jeesite.modules.apps.web;
import com.jeesite.modules.apps.Module.ChartDataItem;
import com.jeesite.modules.erp.entity.ErpTransactionFlow;
import com.jeesite.modules.erp.service.ErpTransactionFlowService;
import com.jeesite.modules.utils.BigDecimalUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value = "${adminPath}/erp/screen")
public class ErpScreenController {
private final ErpTransactionFlowService erpTransactionFlowService;
public ErpScreenController(ErpTransactionFlowService erpTransactionFlowService) {
this.erpTransactionFlowService = erpTransactionFlowService;
}
/**
* 账号收支
*/
@RequestMapping(value = "getErpAccountChart")
@ResponseBody
public List<ChartDataItem> getErpAccountChart(ErpTransactionFlow erpTransactionFlow) {
List<ChartDataItem> chartDataItems = new ArrayList<>();
List<ErpTransactionFlow> flowList = erpTransactionFlowService.findList(erpTransactionFlow);
Map<String, Map<String, Object>> accountMap = flowList.stream()
.collect(Collectors.groupingBy(
ErpTransactionFlow::getAccountName,
Collectors.collectingAndThen(Collectors.toList(), list -> {
String accountId = list.stream()
.findFirst()
.map(ErpTransactionFlow::getAccountId)
.orElse("");
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 sumValue03 = BigDecimalUtils.subtract(sumValue01, sumValue02);
return Map.of(
"accountId", accountId,
"sumValue01", sumValue01,
"sumValue02", sumValue02,
"sumValue03", sumValue03
);
})
));
for (Map.Entry<String, Map<String, Object>> entry : accountMap.entrySet()) {
String accountName = entry.getKey();
Map<String, Object> map = entry.getValue();
ChartDataItem item = new ChartDataItem();
item.setItemCode("CHART");
item.setAxisName(accountName);
item.setValue01(map.get("sumValue01").toString());
item.setValue02(map.get("sumValue02").toString());
item.setValue03(map.get("sumValue03").toString());
item.setBizKey(map.get("accountId").toString());
chartDataItems.add(item);
}
return chartDataItems;
}
/**
* 月份收支
*/
@RequestMapping(value = "getErpMonthChart")
@ResponseBody
public List<ChartDataItem> getErpMonthChart(ErpTransactionFlow erpTransactionFlow) {
List<ChartDataItem> chartDataItems = new ArrayList<>();
List<ErpTransactionFlow> flowList = erpTransactionFlowService.findList(erpTransactionFlow);
Map<String, Map<String, Object>> accountMap = flowList.stream()
.collect(Collectors.groupingBy(
ErpTransactionFlow::getMonthDate,
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
);
})
));
for (Map.Entry<String, Map<String, Object>> entry : accountMap.entrySet()) {
String monthDate = entry.getKey();
Map<String, Object> map = entry.getValue();
ChartDataItem item = new ChartDataItem();
item.setAxisName(monthDate);
item.setValue01(map.get("sumValue01").toString());
item.setValue02(map.get("sumValue02").toString());
item.setValue03(map.get("sumValue03").toString());
item.setValue04(map.get("sumValue04").toString());
chartDataItems.add(item);
}
return chartDataItems;
}
/**
* 分类收支
*/
@RequestMapping(value = "getCategoryChart")
@ResponseBody
public List<ChartDataItem> getCategoryChart(ErpTransactionFlow erpTransactionFlow) {
List<ChartDataItem> chartDataItems = new ArrayList<>();
List<ErpTransactionFlow> flowList = erpTransactionFlowService.findList(erpTransactionFlow);
BigDecimal totalAmount = flowList.stream()
.map(ErpTransactionFlow::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Map<String, Map<String, Object>> accountMap = flowList.stream()
.collect(Collectors.groupingBy(
ErpTransactionFlow::getCategoryName,
Collectors.collectingAndThen(Collectors.toList(), list -> {
BigDecimal sumValue01 = list.stream()
.map(ErpTransactionFlow::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal sumValue02 = BigDecimalUtils.percent(sumValue01, totalAmount);
return Map.of(
"sumValue01", sumValue01,
"sumValue02", sumValue02
);
})
));
List<Map.Entry<String, Map<String, Object>>> sortedList = new ArrayList<>(accountMap.entrySet());
sortedList.sort((e1, e2) -> {
BigDecimal v1 = (BigDecimal) e1.getValue().get("sumValue02");
BigDecimal v2 = (BigDecimal) e2.getValue().get("sumValue02");
return v2.compareTo(v1);
});
long soring = 1;
for (Map.Entry<String, Map<String, Object>> entry : sortedList) {
String categoryName = entry.getKey();
Map<String, Object> map = entry.getValue();
ChartDataItem item = new ChartDataItem();
item.setSoring(soring++);
item.setAxisName(categoryName);
item.setValue01(map.get("sumValue01").toString());
item.setValue02(map.get("sumValue02").toString());
chartDataItems.add(item);
}
return chartDataItems;
}
}

View File

@@ -42,8 +42,8 @@ import java.io.Serial;
@Column(name = "remark", attrName = "remark", label = "交易备注", isQuery = false),
@Column(name = "update_time", attrName = "updateTime", label = "更新时间", isQuery = false, isUpdateForce = true),
@Column(name = "business_id", attrName = "businessId", label = "业务标识"),
@Column(name = "year_date", attrName = "yearDate", label = "业务标识"),
@Column(name = "month_date", attrName = "monthDate", label = "业务标识"),
@Column(name = "year_date", attrName = "yearDate", label = "年份"),
@Column(name = "month_date", attrName = "monthDate", label = "月份"),
}, joinTable = {
@JoinTable(type = Type.LEFT_JOIN, entity = ErpAccount.class, alias = "b",
on = "a.account_id = b.account_id", attrName = "this",

View File

@@ -48,6 +48,22 @@ public class BigDecimalUtils {
return num1.divide(num2, SCALE, ROUND_MODE);
}
/**
* 百分比
*/
public static BigDecimal percent(BigDecimal num1, BigDecimal num2) {
num1 = defaultIfNull(num1);
num2 = defaultIfNull(num2);
if (num2.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO;
}
// 先除 → 再 ×100 → 保留2位
return num1.divide(num2, 4, ROUND_MODE)
.multiply(new BigDecimal("100"))
.setScale(SCALE, ROUND_MODE);
}
private static BigDecimal defaultIfNull(BigDecimal num) {
return num == null ? BigDecimal.ZERO : num;
}