wenminjie
2026-08-06 02c7bf03fa071325c201d29353330152d35ac71a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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, "工作台统计查询失败");
        }
        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, "待处理订单", number(row.get("pendingOrderCount")));
        addAlert(alerts, "待审核商品", number(row.get("pendingProductCount")));
        addAlert(alerts, "待处理预约", number(row.get("pendingApplicationCount")));
        result.put("alertCount", alerts.stream().mapToLong(a -> number(a.get("count"))).sum());
        result.put("alerts", alerts);
        result.put("statisticsBasis", "补贴仅统计政府承担的商品补贴和政府补贴券金额,商家自行让利不计入政府补贴");
        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);
    }
}