zxl
2026-03-25 74e332504d98caaf8fab951d7d24be762b169f49
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
package com.tievd.jyz.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tievd.jyz.constants.SystemConstant;
import com.tievd.jyz.entity.OilRecord;
import com.tievd.jyz.entity.OilStatis;
import com.tievd.jyz.entity.TrafficFlow;
import com.tievd.jyz.entity.vo.DataStatisReqVo;
import com.tievd.jyz.entity.vo.OilVolumeVo;
import com.tievd.jyz.entity.vo.StatDataTableVo;
import com.tievd.jyz.mapper.OilRecordMapper;
import com.tievd.jyz.mapper.OilStaticMapper;
import com.tievd.jyz.mapper.TrafficFlowMapper;
import com.tievd.jyz.service.IOilRecordService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
 
/**
 * OilRecord
 * @author      cube
 * @since       2023-02-27
 * @version     V2.0.0
 */
@Service
@Log4j2
public class OilRecordServiceImpl extends ServiceImpl<OilRecordMapper, OilRecord> implements IOilRecordService {
    
    @Autowired
    OilRecordMapper oilRecordMapper;
    
    @Autowired
    TrafficFlowMapper trafficFlowMapper;
    
    @Autowired
    OilStaticMapper oilStaticMapper;
    
    @Override
    public Map statisOilPosition(String licenseNum, String orgCode) {
        Map res = new HashMap();
        List<Map> positionList = oilRecordMapper.statisOilPosition(licenseNum, orgCode);
        List<Integer> countList = new ArrayList<>();
        try {
            //加油位多边形统计数据
            Object max = positionList.stream().max(Comparator.comparingInt(m -> Integer.valueOf(m.get("count").toString()))).get().get("count");
            for (Map map : positionList) {
                countList.add(Integer.valueOf(map.get("count").toString()));
                map.put("max", max);
            }
        } catch (Exception e) {
            log.error("加油位统计失败", e);
        }
        res.put("count", countList);
        res.put("oilPosition", positionList);
        return res;
    }
    
    @Override
    public Map statisByMonth(String licenseNum, String orgCode) {
        Map res = new HashMap();
        try {
            List<Map> monthCountList = oilRecordMapper.statisByMonth(licenseNum, orgCode);
            res = convertToStatisList(monthCountList);
        } catch (Exception e) {
            log.error("车辆月统计失败", e);
        }
        return res;
    }
    
    private Map convertToStatisList(List<? extends Map> dataList) {
        Set keys = dataList.get(0).keySet();
        Map res = new HashMap();
        for (Object key : keys) {
            List convertList = new ArrayList();
            for (Map map : dataList) {
                convertList.add(map.get(key));
            }
            res.put(key, convertList);
        }
        return res;
    }
    
    @Override
    public Map statisByHour(String licenseNum, String orgCode) {
        Map res = new HashMap();
        try {
            List<Map> hourCountList = oilRecordMapper.statisByHour(licenseNum, orgCode);
            res = convertToStatisList(hourCountList);
        } catch (Exception e) {
            log.error("车辆时统计失败", e);
        }
        return res;
    }
    
    @Override
    public Map statisByStayTime(String licenseNum, String orgCode) {
        Map res = new HashMap();
        try {
            List<Map> stayCountList = oilRecordMapper.statisByStayTime(licenseNum, orgCode);
            res = convertToStatisList(stayCountList);
        } catch (Exception e) {
            log.error("车辆停留时长统计失败", e);
        }
        return res;
    }
    
    /**
     * 加油量分页
     */
    @Override
    public IPage<Map> getStatisOilVolume(IPage page, String orgCode, String dateMonth) {
        return oilRecordMapper.getStatisOilVolume(page, orgCode, dateMonth);
    }
    
    @Override
    public Map getOilVolumeTotal(String orgCode, String dateMonth) {
        return oilRecordMapper.getOilVolumeTotal(orgCode, dateMonth);
    }
    
    /**
     * 加油量详情
     */
    @Override
    public IPage<OilVolumeVo> descOilVolumeList(IPage page, Map map) {
        return oilRecordMapper.descOilVolumeList(page, map);
    }
    
    @Override
    public StatDataTableVo statisTotal(DataStatisReqVo param) {
        return oilRecordMapper.statisTotal(param);
    }
    
    @Override
    public List<Map> statisOrgTopTraffic(DataStatisReqVo param) {
        return oilRecordMapper.statisOrgTopTraffic(param);
    }
    
    @Override
    public List<Map> statisOrgTopOil(DataStatisReqVo param) {
        return oilRecordMapper.statisOrgTopOil(param);
    }
    
    @Override
    public List<Map> statisOrgTopVolume(DataStatisReqVo param) {
        return oilRecordMapper.statisOrgTopVolume(param);
    }
 
    @Override
    public List<Map> statisOilFreqCompare(DataStatisReqVo param) {
        return oilRecordMapper.statisOilFreqCompare(param);
    }
    
    @Override
    public JSONObject statFan(DataStatisReqVo param) {
        JSONObject res;
        List<StatDataTableVo> dataList = new ArrayList<>();
        Function<StatDataTableVo, ?> xfunc = null;
        Function<StatDataTableVo, ?> barfunc = null;
        switch(param.getType()) {
            case 1 :
                dataList = oilRecordMapper.statFanByModel(param);
                xfunc = StatDataTableVo::getModelName;
                barfunc = StatDataTableVo::getOilCount;
                break;
            case 2 :
                dataList = oilRecordMapper.statFanByPosition(param);
                xfunc = StatDataTableVo::getOilPosition;
                barfunc = StatDataTableVo::getOilCount;
                break;
            case 3 :
                dataList = oilRecordMapper.statFanByModel(param);
                xfunc = StatDataTableVo::getModelName;
                barfunc = StatDataTableVo::getOilVolume;
                break;
            case 4 :
                dataList = oilRecordMapper.statFanByPosition(param);
                xfunc = StatDataTableVo::getOilPosition;
                barfunc = StatDataTableVo::getOilVolume;
                break;
            case 5 :
                dataList = oilRecordMapper.statFanByOilType(param);
                xfunc = StatDataTableVo::getOilType;
                barfunc = StatDataTableVo::getOilVolume;
                break;
            case 6 :
                dataList = oilRecordMapper.statFanByOilType(param);
                xfunc = StatDataTableVo::getOilType;
                barfunc = StatDataTableVo::getTotalAmount;
                break;
        }
        res = dataTransLists(dataList, xfunc, barfunc, null, "", "");
        return res;
    }
    
    
    @Override
    public JSONObject statBar(DataStatisReqVo param) {
        JSONObject res;
        List<StatDataTableVo> dataList;
        Function<StatDataTableVo, ?> xfunc;
        Function<StatDataTableVo, ?> barfunc;
        Function<StatDataTableVo, ?> linefunc;
        String barName = "";
        String lineName = "";
        if (param.getType() == 1) {
            dataList = oilRecordMapper.statBarByModel(param);
            xfunc = StatDataTableVo::getModelName;
            barfunc = StatDataTableVo::getOilCount;
            linefunc = StatDataTableVo::getCarCount;
            barName = "加油数";
            lineName = "车流量";
        } else if (param.getType() == 2) {
            dataList = oilRecordMapper.statFanByPosition(param);
            xfunc = StatDataTableVo::getOilPosition;
            barfunc = StatDataTableVo::getOilCount;
            linefunc = StatDataTableVo::getOilVolume;
            barName = "加油数";
            lineName = "油品销量";
        } else if (param.getType() == 3) {
            dataList = oilRecordMapper.statFanByOilType(param);
            xfunc = StatDataTableVo::getOilType;
            barfunc = StatDataTableVo::getOilVolume;
            linefunc = StatDataTableVo::getTotalAmount;
            barName = "油品销量";
            lineName = "销售金额";
        } else {
            dataList = oilRecordMapper.statFanByOilType(param);
            xfunc = StatDataTableVo::getOilType;
            barfunc = StatDataTableVo::getTotalAmount;
            linefunc = StatDataTableVo::getOilVolume;
            barName = "销售金额";
            lineName = "油品销量";
        }
        res = dataTransLists(dataList, xfunc, barfunc, linefunc, barName, lineName);
        return res;
    }
    
    /**
     * 加油相关图表
     * @param param
     * @return
     */
    @Override
    public JSONObject statTrend(DataStatisReqVo param) {
        DataStatisReqVo.StatUnit timeUnit = param.getTimeUnit();
        DataStatisReqVo.TrendType trendType = param.getTrendType();
    
        //时间区间
        LocalDateTime timeLimit = LocalDateTime.now()
                .minus(timeUnit.value(), ChronoUnit.valueOf(timeUnit.name()))
                .with(timeUnit.initField(), 1);
        LocalDateTime timeLimitRight = LocalDateTime.now().with(timeUnit.initField(), 1);
        log.info("打印时间开始: {}, 打印时间结束: {}", timeLimit.toString(), timeLimitRight.toString());
        LambdaQueryWrapper wrapper = new LambdaQueryWrapper<OilRecord>()
                .ge(OilRecord::getStartTime, timeLimit.toString())
                .le(OilRecord::getStartTime, timeLimitRight.toString())
                .likeRight(OilRecord::getOrgCode, param.getOrgCode());
        List<OilRecord> records = this.list(wrapper);
        
        
        //x轴
        Map<String, StatDataTableVo> statVoMap = new HashMap<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeUnit.statFormat());
        for (int i = 0; i < timeUnit.value(); i++) {
            LocalDateTime time = timeLimit.plus(i, ChronoUnit.valueOf(timeUnit.name()));
            String key = time.format(formatter);
            String preKey = time.minus(1, ChronoUnit.valueOf(timeUnit.name())).format(formatter);
            StatDataTableVo statVo = new StatDataTableVo().setStatTime(time);
            if (statVo.getPreStatVo() == null) statVo.setPreStatVo(statVoMap.getOrDefault(preKey, new StatDataTableVo()));
            statVoMap.put(key, statVo);
        }
        for (OilRecord record : records) {
            String key = formatter.format(record.getStartTime().toLocalDateTime());
            if (!statVoMap.containsKey(key)) {
                continue;
            }
            StatDataTableVo statVo = statVoMap.get(key);
            statVo.addAppearCount(1);
            if (record.getBehavior().intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) statVo.addOilCount(1);
            if (record.getBehavior().intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) statVo.addOilVolume(record.getOilVolume());
            if (record.getBehavior().intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) statVo.addTotalAmount(record.getTotalAmount());
            statVo.addSumSpand(record.getSpandTime());
        }
        
        //车流量
        switch(trendType) {
            case TRAFFIC:
                wrapper = new LambdaQueryWrapper<TrafficFlow>()
                        .select(TrafficFlow::getCarCount, TrafficFlow::getCaptureTime, TrafficFlow::getOrgCode)
                        .ge(TrafficFlow::getCaptureTime, timeLimit.toString())
                        .le(TrafficFlow::getCaptureTime, timeLimitRight.toString())
                        .likeRight(TrafficFlow::getOrgCode, param.getOrgCode());
                List<TrafficFlow> trafficList = trafficFlowMapper.selectList(wrapper);
                for (TrafficFlow traffic : trafficList) {
                    String key = formatter.format(traffic.getCaptureTime().toLocalDateTime());
                    if (!statVoMap.containsKey(key)) continue;
                    StatDataTableVo statVo = statVoMap.get(key);
                    statVo.addCarCount(traffic.getCarCount());
                }
                break;
        }
    
        Function<StatDataTableVo,?> xFunc = t -> t.getStatTime().format(formatter);
        Function barFunc = trendType.getBarFunc();
        Function lineFunc = trendType.getLineFunc();
        String barName = trendType.getBarName();
        String lineName = trendType.getLineName();
        List<StatDataTableVo> dataList = new ArrayList<>(statVoMap.values());
        dataList.sort((t1, t2) -> t1.getStatTime().compareTo(t2.getStatTime()));
        JSONObject res = dataTransLists(dataList, xFunc, barFunc, lineFunc, barName, lineName);
        return res;
    }
    
    /**
     * 客户图表
     * @param param
     * @return
     */
    @Override
    public JSONObject statTrendClient(DataStatisReqVo param) {
        DataStatisReqVo.StatUnit timeUnit = param.getTimeUnit();
        DataStatisReqVo.TrendType trendType = param.getTrendType();
    
        //时间区间
        LocalDateTime timeLimit = LocalDateTime.now()
                .minus(timeUnit.value(), ChronoUnit.valueOf(timeUnit.name()))
                .with(timeUnit.initField(), 1);
        LocalDateTime timeLimitRight = LocalDateTime.now().with(timeUnit.initField(), 1);
        
        //x轴
        Map<String, Integer> timeValMap = new TreeMap<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeUnit.statFormat());
        for (int i = 0; i < timeUnit.value(); i++) {
            LocalDateTime time = timeLimit.plus(i, ChronoUnit.valueOf(timeUnit.name()));
            String key = time.format(formatter);
            timeValMap.put(key, 0);
        }
    
        LambdaQueryWrapper wrapper = new LambdaQueryWrapper<OilStatis>()
                .ge(OilStatis::getUpdateTimeSelf, timeLimit.toString())
                .le(OilStatis::getUpdateTimeSelf, timeLimitRight.toString())
                .likeRight(OilStatis::getOrgCode, param.getOrgCode());
        List<OilStatis> oilStatis = oilStaticMapper.selectList(wrapper);
        List barDatas = new ArrayList();
        List lineDatas = new ArrayList();
        switch(trendType) {
            case CLIENT:
                Map<String, Map<String, Integer>> dataMap = new HashMap<>();
                for (OilStatis stat : oilStatis) {
                    dataMap.putIfAbsent(stat.getClientName(), new TreeMap<String, Integer>(){{putAll(timeValMap);}});
                    Map<String, Integer> client = dataMap.get(stat.getClientName());
                    String key = formatter.format(stat.getUpdateTimeSelf().toLocalDateTime());
                    if (!client.containsKey(key)) continue;
                    client.put(key, client.get(key) + 1);
                }
                barDatas = dataMap.entrySet().stream().map(e -> {
                    JSONObject barData = new JSONObject();
                    barData.put("name", e.getKey());
                    barData.put("value", e.getValue().values());
                    return barData;
                }).collect(Collectors.toList());
                break;
            case LOSE_CLIENT:
                Map<String, Integer> sumMap = new HashMap<String, Integer>(){{putAll(timeValMap);}};
                for (OilStatis stat : oilStatis) {
                    String key = formatter.format(stat.getUpdateTimeSelf().toLocalDateTime());
                    if (!timeValMap.containsKey(key)) continue;
                    sumMap.put(key, sumMap.get(key) + 1);
                    if (stat.getClientId() == SystemConstant.LOSE_CLIENT_ID) {
                        timeValMap.put(key, timeValMap.get(key) + 1);
                    }
                }
                lineDatas = timeValMap.entrySet().stream().map(e ->
                    sumMap.get(e.getKey()) == 0 ? 0 : e.getValue() * 100 / sumMap.get(e.getKey())
                ).collect(Collectors.toList());
                break;
        }
        
    
        List<String> xDatas = new ArrayList<>(timeValMap.keySet());
        JSONObject res = new JSONObject();
        res.put("xData", xDatas);
        res.put("barData", barDatas);
        res.put("lineData", lineDatas);
        return res;
    }
 
    @Override
    public List<Map<String, Object>> statTrendDetail(DataStatisReqVo param) {
        if (param.getTrendType() == null || param.getTimeUnit() == null || param.getStatTime() == null) {
            return new ArrayList<>();
        }
        DataStatisReqVo.TrendType trendType = param.getTrendType();
        DataStatisReqVo.StatUnit timeUnit = param.getTimeUnit();
        LocalDateTime[] timeRange = getTrendTimeRange(timeUnit);
        LocalDateTime timeLimit = timeRange[0];
        LocalDateTime timeLimitRight = timeRange[1];
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeUnit.statFormat());
        String statTime = param.getStatTime();
        List<Map<String, Object>> detailList = new ArrayList<>();
 
        if (trendType == DataStatisReqVo.TrendType.TRAFFIC) {
            LambdaQueryWrapper<TrafficFlow> wrapper = new LambdaQueryWrapper<TrafficFlow>()
                    .ge(TrafficFlow::getCaptureTime, timeLimit.toString())
                    .le(TrafficFlow::getCaptureTime, timeLimitRight.toString())
                    .likeRight(TrafficFlow::getOrgCode, param.getOrgCode())
                    .orderByDesc(TrafficFlow::getCaptureTime);
            List<TrafficFlow> list = trafficFlowMapper.selectList(wrapper);
            for (TrafficFlow trafficFlow : list) {
                if (!matchStatTime(trafficFlow.getCaptureTime().toLocalDateTime(), formatter, statTime)) {
                    continue;
                }
                Map<String, Object> row = new LinkedHashMap<>();
                row.put("id", trafficFlow.getId());
                row.put("captureTime", trafficFlow.getCaptureTime());
                row.put("carCount", trafficFlow.getCarCount());
                row.put("modelCode", trafficFlow.getModelCode());
                row.put("cameraCode", trafficFlow.getCameraCode());
                detailList.add(row);
            }
            return detailList;
        }
 
        if (trendType == DataStatisReqVo.TrendType.CLIENT || trendType == DataStatisReqVo.TrendType.LOSE_CLIENT) {
            LambdaQueryWrapper<OilStatis> wrapper = new LambdaQueryWrapper<OilStatis>()
                    .ge(OilStatis::getUpdateTimeSelf, timeLimit.toString())
                    .le(OilStatis::getUpdateTimeSelf, timeLimitRight.toString())
                    .likeRight(OilStatis::getOrgCode, param.getOrgCode())
                    .orderByDesc(OilStatis::getUpdateTimeSelf);
            List<OilStatis> list = oilStaticMapper.selectList(wrapper);
            for (OilStatis oilStatis : list) {
                if (!matchStatTime(oilStatis.getUpdateTimeSelf().toLocalDateTime(), formatter, statTime)) {
                    continue;
                }
                if (trendType == DataStatisReqVo.TrendType.CLIENT
                        && param.getSeriesName() != null
                        && !param.getSeriesName().equals(oilStatis.getClientName())) {
                    continue;
                }
                if (trendType == DataStatisReqVo.TrendType.LOSE_CLIENT
                        && (oilStatis.getClientId() == null || oilStatis.getClientId() != SystemConstant.LOSE_CLIENT_ID)) {
                    continue;
                }
                Map<String, Object> row = new LinkedHashMap<>();
                row.put("id", oilStatis.getId());
                row.put("updateTimeSelf", oilStatis.getUpdateTimeSelf());
                row.put("licenseNum", oilStatis.getLicenseNum());
                row.put("clientName", oilStatis.getClientName());
                row.put("oilCount", oilStatis.getOilCount());
                row.put("oilSum", oilStatis.getOilSum());
                detailList.add(row);
            }
            return detailList;
        }
 
        LambdaQueryWrapper<OilRecord> wrapper = new LambdaQueryWrapper<OilRecord>()
                .ge(OilRecord::getStartTime, timeLimit.toString())
                .le(OilRecord::getStartTime, timeLimitRight.toString())
                .likeRight(OilRecord::getOrgCode, param.getOrgCode())
                .orderByDesc(OilRecord::getStartTime);
        List<OilRecord> records = this.list(wrapper);
        for (OilRecord oilRecord : records) {
            if (!matchStatTime(oilRecord.getStartTime().toLocalDateTime(), formatter, statTime)) {
                continue;
            }
            if (trendType == DataStatisReqVo.TrendType.OIL
                    && (oilRecord.getBehavior() == null || oilRecord.getBehavior().intValue() != SystemConstant.BEHAVIOR_TYPE_OIL)) {
                continue;
            }
            if (trendType == DataStatisReqVo.TrendType.OIL_vOLUME
                    && (oilRecord.getBehavior() == null || oilRecord.getBehavior().intValue() != SystemConstant.BEHAVIOR_TYPE_OIL)) {
                continue;
            }
            if (trendType == DataStatisReqVo.TrendType.SALES_AMOUNT
                    && (oilRecord.getBehavior() == null || oilRecord.getBehavior().intValue() != SystemConstant.BEHAVIOR_TYPE_OIL)) {
                continue;
            }
            Map<String, Object> row = new LinkedHashMap<>();
            row.put("id", oilRecord.getId());
            row.put("startTime", oilRecord.getStartTime());
            row.put("licenseNum", oilRecord.getLicenseNum());
            row.put("behavior", oilRecord.getBehavior());
            row.put("behaviorText", behaviorText(oilRecord.getBehavior()));
            row.put("oilPosition", oilRecord.getOilPosition());
            row.put("oilVolume", oilRecord.getOilVolume());
            row.put("totalAmount", oilRecord.getTotalAmount());
            row.put("spandTime", oilRecord.getSpandTime());
            detailList.add(row);
        }
        return detailList;
    }
 
    private LocalDateTime[] getTrendTimeRange(DataStatisReqVo.StatUnit timeUnit) {
        LocalDateTime timeLimit = LocalDateTime.now()
                .minus(timeUnit.value(), ChronoUnit.valueOf(timeUnit.name()))
                .with(timeUnit.initField(), 1);
        LocalDateTime timeLimitRight = LocalDateTime.now().with(timeUnit.initField(), 1);
        return new LocalDateTime[]{timeLimit, timeLimitRight};
    }
 
    private boolean matchStatTime(LocalDateTime time, DateTimeFormatter formatter, String statTime) {
        return formatter.format(time).equals(statTime);
    }
 
    private String behaviorText(Byte behavior) {
        if (behavior == null) {
            return "";
        }
        if (behavior.intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) {
            return "加油";
        }
        if (behavior.intValue() == SystemConstant.BEHAVIOR_TYPE_TMP) {
            return "停靠";
        }
        return behavior.toString();
    }
    
    private <E> JSONObject  dataTransLists(
            List<E> dataList,
            Function<E, ?> xDataMapper,
            Function<E, ?> barDataMapper,
            Function<E, ?> lineDataMapper,
            String barName,
            String lineName) {
        List xDatas = new ArrayList();
        List<Object> barDatas = new ArrayList<>();
        List lineDatas = new ArrayList<>();
        double sum = 0;
        for (E statVo : dataList) {
            Object xData = "";
            Object barData = 0;
            Object lineData = 0;
            try {
                xData = xDataMapper.apply(statVo);
                Object barValue = barDataMapper.apply(statVo);
                if (barValue instanceof java.math.BigDecimal) {
                    barData = ((java.math.BigDecimal) barValue).doubleValue();
                } else {
                    barData = Integer.valueOf(barValue.toString());
                }
                if (lineDataMapper != null) lineData = lineDataMapper.apply(statVo);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("统计出现异常", e);
            }
    
            xDatas.add(xData);
            barDatas.add(barData);
            lineDatas.add(lineData);
            if (barData instanceof Number) {
                sum += ((Number) barData).doubleValue();
            }
        }
        if (lineDataMapper == null) {
            double finalSum = sum;
            lineDatas = barDatas.stream().map(n -> {
                if (n instanceof Number) {
                    return ((Number) n).doubleValue() * 100 / finalSum;
                }
                return 0;
            }).collect(Collectors.toList());
        }
        JSONObject res = new JSONObject();
        res.put("xData", xDatas);
        res.put("barData", barDatas);
        res.put("lineData", lineDatas);
        res.put("barName", barName);
        res.put("lineName", lineName);
        return res;
    }
    
}