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