大屏页面初始化

This commit is contained in:
2026-03-03 09:37:37 +08:00
parent 2528968f70
commit 42b9bead15

View File

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Controller;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.List; import java.util.List;
import java.util.Objects;
@Controller @Controller
public class erpJobs { public class erpJobs {
@@ -25,65 +26,75 @@ public class erpJobs {
@Resource @Resource
private ErpTransactionFlowService flowService; private ErpTransactionFlowService flowService;
@Scheduled(cron = "0 0 2 * * ?") @Scheduled(cron = "10 30 2 * * ?")
public void updateErpIndex() { public void updateErpIndex() {
final BigDecimal BUDGET_AMOUNT = new BigDecimal("3000"); try {
QueryWrapper<ErpTransactionFlow> query = new QueryWrapper<>(); final BigDecimal BUDGET_AMOUNT = new BigDecimal("3000");
query.eq("year_date", DateUtils.getCurrentYear()) QueryWrapper<ErpTransactionFlow> query = new QueryWrapper<>();
.eq("month_date", DateUtils.getCurrentMonth()); query.eq("year_date", DateUtils.getCurrentYear())
List<ErpTransactionFlow> flowList = flowService.list(query); .eq("month_date", DateUtils.getCurrentMonth());
BigDecimal incomeAmount = flowList.stream() List<ErpTransactionFlow> flowList = flowService.list(query);
.filter(flow -> flow.getTransactionType().equals("2")) BigDecimal incomeAmount = flowList.stream()
.map(ErpTransactionFlow::getAmount) .filter(flow -> flow.getTransactionType().equals("2"))
.filter(amount -> amount != null) .map(ErpTransactionFlow::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add); .filter(Objects::nonNull)
BigDecimal expenseAmount = flowList.stream() .reduce(BigDecimal.ZERO, BigDecimal::add);
.filter(flow -> flow.getTransactionType().equals("1")) BigDecimal expenseAmount = flowList.stream()
.map(ErpTransactionFlow::getAmount) .filter(flow -> flow.getTransactionType().equals("1"))
.filter(amount -> amount != null) .map(ErpTransactionFlow::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add); .filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
//净利润
BigDecimal netProfit = incomeAmount.subtract(expenseAmount);
//利润率
BigDecimal profitRate = incomeAmount.equals(BigDecimal.ZERO)
? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)
: netProfit.divide(incomeAmount, 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"))
.setScale(2, RoundingMode.HALF_UP);
//占比
BigDecimal expenseIncomeRatio = incomeAmount.equals(BigDecimal.ZERO)
? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)
: expenseAmount.divide(incomeAmount, 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"))
.setScale(2, RoundingMode.HALF_UP);
//净利润 boolean isOverBudget = expenseAmount.compareTo(BUDGET_AMOUNT) > 0;
BigDecimal netProfit = incomeAmount.subtract(expenseAmount); String budgetStatusName = isOverBudget ? "超出" : "正常";
//利润率 BigDecimal overBudgetAmount = isOverBudget ? expenseAmount.subtract(BUDGET_AMOUNT) : BigDecimal.ZERO;
BigDecimal profitRate = netProfit.divide(incomeAmount, 4, RoundingMode.HALF_UP) String[] indexList = {
.multiply(new BigDecimal("100")) "ERP_001",
.setScale(2, RoundingMode.HALF_UP); "ERP_002",
//占比 "ERP_003",
BigDecimal expenseIncomeRatio = expenseAmount.divide(incomeAmount, 4, RoundingMode.HALF_UP) "ERP_004",
.multiply(new BigDecimal("100")) "ERP_006",
.setScale(2, RoundingMode.HALF_UP); };
boolean isOverBudget = expenseAmount.compareTo(BUDGET_AMOUNT) > 0; for (String index : indexList) {
String budgetStatusName = isOverBudget ? "超出" : "正常"; QueryWrapper<IndexInfo> queryWrapper = new QueryWrapper<>();
BigDecimal overBudgetAmount = isOverBudget ? expenseAmount.subtract(BUDGET_AMOUNT) : BigDecimal.ZERO; queryWrapper.eq("module_code", index);
String[] indexList = { IndexInfo indexInfo = infoService.getOne(queryWrapper);
"ERP_001", if (index.equals("ERP_001")) {
"ERP_002", indexInfo.setValue(incomeAmount);
"ERP_003", }
"ERP_004", if (index.equals("ERP_002")) {
"ERP_006", indexInfo.setValue(expenseAmount);
}; }
for (String index : indexList) { if (index.equals("ERP_003")) {
QueryWrapper<IndexInfo> queryWrapper = new QueryWrapper<>(); indexInfo.setValue(profitRate);
queryWrapper.eq("module_code", index); }
IndexInfo indexInfo = infoService.getOne(queryWrapper); if (index.equals("ERP_004")) {
if (index.equals("ERP_001")) { indexInfo.setValue(expenseIncomeRatio);
indexInfo.setValue(incomeAmount); }
if (index.equals("ERP_006")) {
indexInfo.setModule(budgetStatusName);
indexInfo.setValue(overBudgetAmount);
}
infoService.update(indexInfo, queryWrapper);
} }
if (index.equals("ERP_002")) { } catch (Exception e) {
indexInfo.setValue(expenseAmount); System.out.println(e.getMessage());
}
if (index.equals("ERP_003")) {
indexInfo.setValue(profitRate);
}
if (index.equals("ERP_004")) {
indexInfo.setValue(expenseIncomeRatio);
}
if (index.equals("ERP_006")) {
indexInfo.setModule(budgetStatusName);
indexInfo.setValue(overBudgetAmount);
}
infoService.update(indexInfo, queryWrapper);
} }
} }
} }