|
|
@@ -9,11 +9,12 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -96,7 +97,7 @@ public class ZhjqPassengerFlowServiceImpl implements IZhjqPassengerFlowService {
|
|
|
@Override
|
|
|
public Map<String, Object> selectAllStatistics(JSONObject jsonObject) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- if (ObjectUtils.isNotEmpty(jsonObject.get("groupId"))) {
|
|
|
+ if (ObjectUtils.isNotEmpty(jsonObject.get("groupId"))) {
|
|
|
ZhjqPassengerFlowVO vo = zhjqPassengerFlowMapper.selectAllStatisticsByGroupId(jsonObject);
|
|
|
map.put("data", vo);
|
|
|
} else {
|
|
|
@@ -123,4 +124,44 @@ public class ZhjqPassengerFlowServiceImpl implements IZhjqPassengerFlowService {
|
|
|
public List<ZhjqPassengerFlow> selectGroupName() {
|
|
|
return zhjqPassengerFlowMapper.selectGroupName();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> selectAppStatistics(String groupId) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<Map<String, Object>> maps = zhjqPassengerFlowMapper.selectAppStatistics(groupId);
|
|
|
+ List<String> last7DaysIncludingToday = getLast7DaysFormatted();
|
|
|
+ List<Object> inNumList = new ArrayList<>();
|
|
|
+ List<Object> dateList = new ArrayList<>();
|
|
|
+ for (String day : last7DaysIncludingToday) {
|
|
|
+ boolean found = false;
|
|
|
+ for (Map<String, Object> record : maps) {
|
|
|
+ String insertTime = String.valueOf(record.get("insertTime"));
|
|
|
+ if (day.equals(insertTime)) {
|
|
|
+ inNumList.add(record.get("noRepeatInNum"));
|
|
|
+ dateList.add(day);
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found) {
|
|
|
+ inNumList.add(0);
|
|
|
+ dateList.add(day);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int totalFlow = maps.stream()
|
|
|
+ .map(m -> Integer.parseInt(String.valueOf(m.getOrDefault("noRepeatInNum", 0))))
|
|
|
+ .reduce(0, Integer::sum);
|
|
|
+ map.put("totalFlow", totalFlow);
|
|
|
+ map.put("date", dateList);
|
|
|
+ map.put("datasource", inNumList);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<String> getLast7DaysFormatted() {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ return IntStream.rangeClosed(0, 6)
|
|
|
+ .mapToObj(i -> today.minusDays(6 - i).format(formatter))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|