From 47051ef8a22550145f78c0e3e3575ba48c583277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E4=B8=8B?= <484014559@qq.com> Date: Thu, 29 Aug 2024 16:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E6=8E=A5=E5=8F=A3=E9=80=9F?= =?UTF-8?q?=E7=8E=87=E4=BC=98=E5=8C=96=E6=8F=90=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkticket/CheckTicketRepository.java | 3 + .../checkticket/CheckTicketServiceImpl.java | 75 +++++++++++++++---- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketRepository.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketRepository.java index c9af61478..ab6b24cf0 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketRepository.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketRepository.java @@ -24,4 +24,7 @@ public interface CheckTicketRepository extends MongoRepository findAllByCheckticketdateBetween(String startTime, String endTime); } diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java index 82695d4a1..641f9bee2 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java @@ -10,10 +10,7 @@ import javax.annotation.Resource; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** @@ -31,27 +28,60 @@ public class CheckTicketServiceImpl implements CheckTicketService { @Override public List> findbytimetemp(String starTime, String endTime) { +// LocalDateTime startTime = LocalDateTime.now(); +// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); +// List> mapList = new ArrayList<>(); +// +// for (int i = 0; i < 24; i++) { +// Mapmap =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> mapList = new ArrayList<>(); + //临时数据载体 + HashMap countMap = new HashMap<>(); + for (int i = 0; i < 24; i++) { + countMap.put("map"+String.format("%02d", Integer.parseInt(i+"")),0); + } + //查询该时间区域的所有数据 + List 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> mapList = new ArrayList<>(); - for (int i = 0; i < 24; i++) { - Mapmap =new LinkedHashMap<>(); + Map mapName = 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); + mapName.put("date",begintime+"-"+resulttime); + mapName.put("count",countMap.get("map"+begintime.substring(0,2)).toString()); + mapList.add(mapName); } + + return mapList; } @@ -69,4 +99,17 @@ 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; + } + } \ No newline at end of file