Compare commits
No commits in common. "ffc330485f5ee6b44f3e2cabf8c0c5b739ed2298" and "90d30810ed17fe0a037bd45804ff72e7f6788f74" have entirely different histories.
ffc330485f
...
90d30810ed
@ -24,7 +24,4 @@ public interface CheckTicketRepository extends MongoRepository<CheckTicket,Strin
|
||||
|
||||
// @Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1} , 'checktickettime':{'$gte': ?2, '$lt': ?3}}")
|
||||
Long countByCheckticketdateBetweenAndChecktickettimeBetween(String startTime, String endTime,String beingTime, String resultTime);
|
||||
|
||||
@Query(value = "{'checkticketdate':{'$gte': ?0, '$lt': ?1}}", fields = "{ 'checktickettime': 1 }")
|
||||
List<CheckTicket> findAllByCheckticketdateBetween(String startTime, String endTime);
|
||||
}
|
||||
|
@ -10,7 +10,10 @@ import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@ -28,59 +31,26 @@ public class CheckTicketServiceImpl implements CheckTicketService {
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> findbytimetemp(String starTime, String endTime) {
|
||||
// LocalDateTime startTime = LocalDateTime.now();
|
||||
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
// List<Map<String, String>> mapList = new ArrayList<>();
|
||||
//
|
||||
// for (int i = 0; i < 24; i++) {
|
||||
// Map<String,String>map =new LinkedHashMap<>();
|
||||
// LocalDateTime hourStartTime = startTime.withHour(i).withMinute(0).withSecond(0).withNano(0);
|
||||
// LocalDateTime hourEndTime = hourStartTime.plusHours(1);
|
||||
// String begintime = formatter.format(hourStartTime);
|
||||
// String resulttime = formatter.format(hourEndTime);
|
||||
// Long checkTickets;
|
||||
// if (starTime != null && endTime != null && starTime.equals(endTime)){
|
||||
// checkTickets = checkTicketRepository.countByCheckticketdateAndChecktickettimeBetween(starTime,begintime,resulttime);
|
||||
// }else {
|
||||
// checkTickets = checkTicketRepository.countByCheckticketdateBetweenAndChecktickettimeBetween(starTime,endTime,begintime,resulttime);
|
||||
// }
|
||||
// map.put("date",begintime+"-"+resulttime);
|
||||
// map.put("count", String.valueOf(checkTickets));
|
||||
// mapList.add(map);
|
||||
// }
|
||||
|
||||
//最终数据源
|
||||
List<Map<String, String>> mapList = new ArrayList<>();
|
||||
//临时数据载体
|
||||
HashMap<String, Integer> countMap = new HashMap<>();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
countMap.put("map"+String.format("%02d", Integer.parseInt(i+"")),0);
|
||||
}
|
||||
//查询该时间区域的所有数据
|
||||
List<CheckTicket> allByCheckticketdateBetween = checkTicketRepository.findAllByCheckticketdateBetween(starTime, this.publicMethod(endTime));
|
||||
//分析数据
|
||||
for (CheckTicket checkTicket : allByCheckticketdateBetween) {
|
||||
String checktickettime = checkTicket.getChecktickettime();
|
||||
String result = checktickettime.substring(0, 2);
|
||||
Integer numberCount = countMap.get("map" + result);
|
||||
countMap.put("map" + result, numberCount+1);
|
||||
}
|
||||
|
||||
//构造数据结构
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
List<Map<String, String>> mapList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 24; i++) {
|
||||
Map<String,String> mapName = new LinkedHashMap<>();
|
||||
Map<String,String>map =new LinkedHashMap<>();
|
||||
LocalDateTime hourStartTime = startTime.withHour(i).withMinute(0).withSecond(0).withNano(0);
|
||||
LocalDateTime hourEndTime = hourStartTime.plusHours(1);
|
||||
String begintime = formatter.format(hourStartTime);
|
||||
String resulttime = formatter.format(hourEndTime);
|
||||
mapName.put("date",begintime+"-"+resulttime);
|
||||
mapName.put("count",countMap.get("map"+begintime.substring(0,2)).toString());
|
||||
mapList.add(mapName);
|
||||
Long checkTickets;
|
||||
if (starTime != null && endTime != null && starTime.equals(endTime)){
|
||||
checkTickets = checkTicketRepository.countByCheckticketdateAndChecktickettimeBetween(starTime,begintime,resulttime);
|
||||
}else {
|
||||
checkTickets = checkTicketRepository.countByCheckticketdateBetweenAndChecktickettimeBetween(starTime,endTime,begintime,resulttime);
|
||||
}
|
||||
map.put("date",begintime+"-"+resulttime);
|
||||
map.put("count", String.valueOf(checkTickets));
|
||||
mapList.add(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return mapList;
|
||||
}
|
||||
@ -99,17 +69,4 @@ public class CheckTicketServiceImpl implements CheckTicketService {
|
||||
return checkTicketRepository.countByCheckticketdateBetween(starTime,formattedNextDay).size();
|
||||
}
|
||||
|
||||
public String publicMethod(String endTime){
|
||||
// 创建 DateTimeFormatter 实例以解析指定日期的格式
|
||||
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
// 解析指定日期字符串为 LocalDate 对象
|
||||
LocalDate specifiedDate = LocalDate.parse(endTime, inputFormatter);
|
||||
// 获取指定日期的下一天
|
||||
LocalDate nextDay = specifiedDate.plusDays(1);
|
||||
// 格式化指定日期和下一天
|
||||
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
String formattedNextDay = nextDay.format(outputFormatter);
|
||||
return formattedNextDay;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user