zxl
2026-03-25 8819762ad58f77e606431fca4072c19e542e6055
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.tievd.jyz.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tievd.jyz.entity.DepartLabel;
import com.tievd.jyz.mapper.DepartLabelMapper;
import com.tievd.jyz.service.IDepartLabelService;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class DepartLabelServiceImpl extends ServiceImpl<DepartLabelMapper, DepartLabel> implements IDepartLabelService {
 
    @Override
    public List<Map<String, Object>> queryDepartLabelList(String labelName, String parentCode, String parentId) {
        return baseMapper.queryDepartLabelList(labelName, parentCode, parentId);
    }
 
    @Override
    public List<String> queryAllLabelNames(String parentCode, String parentId) {
        return baseMapper.queryAllLabelNames(parentCode, parentId);
    }
 
    @Override
    public List<Map<String, Object>> queryOrgOilCount(String orgCode, String startTime, String endTime) {
        List<Map<String, Object>> oilCountList = baseMapper.queryOrgOilCount(orgCode, startTime, endTime);
        
        System.out.println("=== queryOrgOilCount 开始 ===");
        System.out.println("orgCode: " + orgCode);
        System.out.println("startTime: " + startTime);
        System.out.println("endTime: " + endTime);
        System.out.println("oilCountList size: " + (oilCountList != null ? oilCountList.size() : 0));
        
        if (oilCountList == null || oilCountList.isEmpty()) {
            return new ArrayList<>();
        }
        
        Map<String, String> orgCodeToIdMap = new HashMap<>();
        Map<String, String> idToParentIdMap = new HashMap<>();
        Map<String, Integer> idOilCountMap = new HashMap<>();
        Map<String, Integer> idCarCountMap = new HashMap<>();
        Map<String, Integer> idStationCountMap = new HashMap<>();
        Map<String, Integer> idOilVolumeMap = new HashMap<>();
        
        for (Map<String, Object> item : oilCountList) {
            String orgCodeStr = (String) item.get("org_code");
            String departId = (String) item.get("depart_id");
            
            Object oilCountObj = item.get("oilCount");
            Integer oilCount = null;
            if (oilCountObj instanceof Integer) {
                oilCount = (Integer) oilCountObj;
            } else if (oilCountObj instanceof Number) {
                oilCount = ((Number) oilCountObj).intValue();
            } else if (oilCountObj instanceof String) {
                oilCount = Integer.parseInt((String) oilCountObj);
            }
            
            Object carCountObj = item.get("carCount");
            Integer carCount = null;
            if (carCountObj instanceof Integer) {
                carCount = (Integer) carCountObj;
            } else if (carCountObj instanceof Number) {
                carCount = ((Number) carCountObj).intValue();
            } else if (carCountObj instanceof String) {
                carCount = Integer.parseInt((String) carCountObj);
            }
            
            Object stationCountObj = item.get("stationCount");
            Integer stationCount = null;
            if (stationCountObj instanceof Integer) {
                stationCount = (Integer) stationCountObj;
            } else if (stationCountObj instanceof Number) {
                stationCount = ((Number) stationCountObj).intValue();
            } else if (stationCountObj instanceof String) {
                stationCount = Integer.parseInt((String) stationCountObj);
            }
            
            Object oilVolumeObj = item.get("oilVolume");
            Integer oilVolume = null;
            if (oilVolumeObj instanceof Integer) {
                oilVolume = (Integer) oilVolumeObj;
            } else if (oilVolumeObj instanceof Number) {
                oilVolume = ((Number) oilVolumeObj).intValue();
            } else if (oilVolumeObj instanceof String) {
                oilVolume = Integer.parseInt((String) oilVolumeObj);
            }
            
            if (departId != null) {
                orgCodeToIdMap.put(orgCodeStr, departId);
                if (oilCount != null) {
                    idOilCountMap.put(departId, oilCount);
                }
                if (carCount != null) {
                    idCarCountMap.put(departId, carCount);
                }
                if (stationCount != null) {
                    idStationCountMap.put(departId, stationCount);
                }
                if (oilVolume != null) {
                    idOilVolumeMap.put(departId, oilVolume);
                }
            }
        }
        
        List<Map<String, Object>> departList = baseMapper.queryDepartLabelList(null, orgCode, null);
        System.out.println("departList size: " + (departList != null ? departList.size() : 0));
        
        for (Map<String, Object> depart : departList) {
            String departId = (String) depart.get("id");
            Object parentIdObj = depart.get("parent_id");
            System.out.println("departId: " + departId + ", parentId: " + parentIdObj);
            if (parentIdObj != null) {
                String parentIdStr = parentIdObj.toString();
                if (parentIdStr != null && !parentIdStr.isEmpty()) {
                    String[] parentIds = parentIdStr.split(",");
                    for (String pid : parentIds) {
                        if (!pid.trim().isEmpty()) {
                            idToParentIdMap.put(departId, pid.trim());
                            System.out.println("  -> 父子关系: " + departId + " -> " + pid.trim());
                        }
                    }
                }
            }
        }
        
        System.out.println("idToParentIdMap size: " + idToParentIdMap.size());
        System.out.println("idOilCountMap: " + idOilCountMap);
        System.out.println("idCarCountMap: " + idCarCountMap);
        System.out.println("idStationCountMap: " + idStationCountMap);
        System.out.println("idOilVolumeMap: " + idOilVolumeMap);
        
        Map<String, Integer> finalOilCountMap = new HashMap<>(idOilCountMap);
        Map<String, Integer> finalCarCountMap = new HashMap<>(idCarCountMap);
        Map<String, Integer> finalStationCountMap = new HashMap<>(idStationCountMap);
        Map<String, Integer> finalOilVolumeMap = new HashMap<>(idOilVolumeMap);
        
        for (Map.Entry<String, String> entry : idToParentIdMap.entrySet()) {
            String childId = entry.getKey();
            String parentIdStr = entry.getValue();
            if (parentIdStr != null && !parentIdStr.isEmpty()) {
                Integer childOilCount = idOilCountMap.get(childId);
                if (childOilCount != null) {
                    finalOilCountMap.merge(parentIdStr, childOilCount, Integer::sum);
                    System.out.println("累加加油数: 父节点 " + parentIdStr + " += 子节点 " + childId + " 的 " + childOilCount);
                }
                Integer childCarCount = idCarCountMap.get(childId);
                if (childCarCount != null) {
                    finalCarCountMap.merge(parentIdStr, childCarCount, Integer::sum);
                    System.out.println("累加车流量: 父节点 " + parentIdStr + " += 子节点 " + childId + " 的 " + childCarCount);
                }
                Integer childStationCount = idStationCountMap.get(childId);
                if (childStationCount != null) {
                    finalStationCountMap.merge(parentIdStr, childStationCount, Integer::sum);
                    System.out.println("累加进站数: 父节点 " + parentIdStr + " += 子节点 " + childId + " 的 " + childStationCount);
                }
                Integer childOilVolume = idOilVolumeMap.get(childId);
                if (childOilVolume != null) {
                    finalOilVolumeMap.merge(parentIdStr, childOilVolume, Integer::sum);
                    System.out.println("累加油品销量: 父节点 " + parentIdStr + " += 子节点 " + childId + " 的 " + childOilVolume);
                }
            }
        }
        
        System.out.println("finalOilCountMap: " + finalOilCountMap);
        System.out.println("finalCarCountMap: " + finalCarCountMap);
        System.out.println("finalStationCountMap: " + finalStationCountMap);
        System.out.println("finalOilVolumeMap: " + finalOilVolumeMap);
        
        for (Map<String, Object> item : oilCountList) {
            String departId = (String) item.get("depart_id");
            Integer finalOilCount = finalOilCountMap.get(departId);
            if (finalOilCount != null) {
                item.put("oilCount", finalOilCount);
                System.out.println("更新 " + item.get("depart_name") + " 的加油数: " + finalOilCount);
            }
            Integer finalCarCount = finalCarCountMap.get(departId);
            if (finalCarCount != null) {
                item.put("carCount", finalCarCount);
                System.out.println("更新 " + item.get("depart_name") + " 的车流量: " + finalCarCount);
            }
            Integer finalStationCount = finalStationCountMap.get(departId);
            if (finalStationCount != null) {
                item.put("stationCount", finalStationCount);
                System.out.println("更新 " + item.get("depart_name") + " 的进站数: " + finalStationCount);
            }
            Integer finalOilVolume = finalOilVolumeMap.get(departId);
            if (finalOilVolume != null) {
                item.put("oilVolume", finalOilVolume);
                System.out.println("更新 " + item.get("depart_name") + " 的油品销量: " + finalOilVolume);
            }
        }
        
        System.out.println("=== queryOrgOilCount 结束 ===");
        return oilCountList;
    }
}