package com.talentcard.server.service;
|
|
import com.talentcard.server.common.BusinessException;
|
import com.talentcard.server.common.ErrorCode;
|
import com.talentcard.server.mapper.AdminWorkbenchStatisticsMapper;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class AdminWorkbenchStatisticsService {
|
private final AdminWorkbenchStatisticsMapper mapper;
|
|
public AdminWorkbenchStatisticsService(AdminWorkbenchStatisticsMapper mapper) {
|
this.mapper = mapper;
|
}
|
|
@Transactional(readOnly = true)
|
public Map<String, Object> summary() {
|
Map<String, Object> row = mapper.selectSummary();
|
if (row == null) {
|
throw new BusinessException(ErrorCode.INTERNAL_ERROR, "\u5de5\u4f5c\u53f0\u7edf\u8ba1\u67e5\u8be2\u5931\u8d25");
|
}
|
long subsidyCents = number(row.get("subsidyAmountCents"));
|
long monthlyVerification = number(row.get("monthlyVerificationCount"));
|
long talentCount = number(row.get("talentCount"));
|
Map<String, Object> result = new LinkedHashMap<>();
|
result.put("totalSubsidyAmountCents", subsidyCents);
|
result.put("totalSubsidyAmount", money(subsidyCents));
|
result.put("cumulativeSubsidyTotal", money(subsidyCents));
|
result.put("monthlyVerificationCount", monthlyVerification);
|
result.put("monthlyVerificationOrders", monthlyVerification);
|
result.put("talentCount", talentCount);
|
result.put("cardholderTotal", talentCount);
|
result.put("budgetConfigured", false);
|
result.put("budgetUsageRate", BigDecimal.ZERO.setScale(2));
|
result.put("budgetUsageRateText", "0.00%");
|
|
List<Map<String, Object>> alerts = new ArrayList<>();
|
addAlert(alerts, "\u5f85\u5904\u7406\u8ba2\u5355", number(row.get("pendingOrderCount")));
|
addAlert(alerts, "\u5f85\u5ba1\u6838\u5546\u54c1", number(row.get("pendingProductCount")));
|
addAlert(alerts, "\u5f85\u5904\u7406\u9884\u7ea6", number(row.get("pendingApplicationCount")));
|
result.put("alertCount", alerts.stream().mapToLong(a -> number(a.get("count"))).sum());
|
result.put("alerts", alerts);
|
result.put("statisticsBasis", "\u8865\u8d34\u4ec5\u7edf\u8ba1\u653f\u5e9c\u627f\u62c5\u7684\u5546\u54c1\u8865\u8d34\u548c\u653f\u5e9c\u8865\u8d34\u5238\u91d1\u989d\uff0c\u5546\u5bb6\u81ea\u884c\u8ba9\u5229\u4e0d\u8ba1\u5165\u653f\u5e9c\u8865\u8d34");
|
return result;
|
}
|
|
private void addAlert(List<Map<String, Object>> alerts, String type, long count) {
|
if (count <= 0) return;
|
Map<String, Object> alert = new LinkedHashMap<>();
|
alert.put("type", type);
|
alert.put("count", count);
|
alerts.add(alert);
|
}
|
|
private long number(Object value) {
|
return value instanceof Number n ? n.longValue() : 0L;
|
}
|
|
private BigDecimal money(long cents) {
|
return BigDecimal.valueOf(cents, 2).setScale(2, RoundingMode.HALF_UP);
|
}
|
}
|