|
|
@ -1,10 +1,14 @@ |
|
|
|
package com.zc.business.service.impl; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateField; |
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
@ -1886,4 +1890,27 @@ public class DcTrafficSurveyDataServiceImpl implements IDcTrafficSurveyDataServi |
|
|
|
public DcDevice selectDeviceByIotId(String iotDeviceId){ |
|
|
|
return dcTrafficSurveyDataMapper.selectDeviceByIotId(iotDeviceId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<DcTrafficSurveyData> getTrafficSurveyDataList(DcTrafficSurveyData dcTrafficSurveyData) throws ParseException { |
|
|
|
Date startTime = DateUtil.beginOfHour(dcTrafficSurveyData.getStartTime()); |
|
|
|
Date endTime = DateUtil.endOfHour(dcTrafficSurveyData.getEndTime()); |
|
|
|
List<DateTime> dateRangeList = DateUtil.rangeToList(startTime, endTime, DateField.HOUR_OF_DAY, 1); |
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
List<String> timeList = new ArrayList<>(); |
|
|
|
for (DateTime dateTime : dateRangeList) { |
|
|
|
timeList.add(df.format(dateTime)); |
|
|
|
} |
|
|
|
List<DcTrafficSurveyData> list = dcTrafficSurveyDataMapper.getTrafficSurveyDataList(dcTrafficSurveyData); |
|
|
|
Map<String, List<DcTrafficSurveyData>> collect = list.stream().collect(Collectors.groupingBy(item -> df.format(item.getTimestamp()))); |
|
|
|
for (String time : timeList) { |
|
|
|
if (!collect.containsKey(time)){ |
|
|
|
DcTrafficSurveyData trafficSurveyData = new DcTrafficSurveyData(0); |
|
|
|
trafficSurveyData.setTimestamp(df.parse(time)); |
|
|
|
list.add(trafficSurveyData); |
|
|
|
} |
|
|
|
} |
|
|
|
list = list.stream().sorted(Comparator.comparing(DcTrafficSurveyData::getTimestamp)).collect(Collectors.toList()); |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|