diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/checkticket/CheckTicketApi.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/checkticket/CheckTicketApi.java index e27863bed..bd7d6865f 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/checkticket/CheckTicketApi.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/checkticket/CheckTicketApi.java @@ -20,15 +20,19 @@ import java.util.Map; public class CheckTicketApi { @Resource private CheckTicketService checkTicketService; - @GetMapping("/{day}") + @GetMapping() @Operation(summary = "获得日期当天的检票人数") - public Long checkTicketTotal(@PathVariable("day") String day) { - return checkTicketService.checkTicketTotal(day); + public Long checkTicketTotal(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return checkTicketService.checkTicketTotal(replace,replace1); } - @GetMapping("/qushi/{day}") + @GetMapping("/qushi") @Operation(summary = "获取日期当天各个时段的检票人数") - public List> findbytimetemp(@PathVariable("day") String day) { - return checkTicketService.findbytimetemp(day); + public List> findbytimetemp(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return checkTicketService.findbytimetemp(replace,replace1); } } diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/saledata/SaleDataApi.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/saledata/SaleDataApi.java index fd1970086..1c1a0da7b 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/saledata/SaleDataApi.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/saledata/SaleDataApi.java @@ -27,89 +27,76 @@ public class SaleDataApi { @Resource private SaleDataService saleDataService; - @GetMapping("/{day}") + @GetMapping() @Operation(summary = "获得输入日期的当天总售票数") - public Long checkTicketTotal(@PathVariable("day") String day) { - return saleDataService.countBySddate(day); + public Long checkTicketTotal(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.countBySddate(replace, replace1); } - @GetMapping("/thisyear/{startTime}") + @GetMapping("/thisyear") @Operation(summary = "获得今年日期往前十天内的数据") - public List> thisyearNum(@PathVariable("startTime") String startTime) { - return saleDataService.findCheckticketcountBytime(startTime); + public List> thisyearNum(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findCheckticketcountBytime(replace, replace1); } - @GetMapping("/lastyear/{startTime}") + @GetMapping("/lastyear") @Operation(summary = "获得去年日期往前推十天的数据") - public List> lastyearNum(@PathVariable("startTime") String startTime) { - String resultStr = startTime.replaceAll("-", ""); - // 正则表达式匹配 yyyyMMdd 格式 - Pattern pattern = Pattern.compile("^\\d{8}$"); - Matcher matcher = pattern.matcher(resultStr); - if (matcher.matches()){ - return saleDataService.findCheckticketcountBytime(resultStr); - } - return null; + public List> lastyearNum(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findCheckticketcountBytime(replace, replace1); } @GetMapping("/gender") @Operation(summary = "获得所有数据的男女数量") public List> findByGender(String starTime, String endTime) { - if (starTime != null && endTime != null){ - String replace = starTime.replace("-", ""); - String replace1 = endTime.replace("-", ""); - return saleDataService.findByGender(replace, replace1); - }else{ - return saleDataService.findByGender(starTime, endTime); - } + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findByGender(replace, replace1); } @GetMapping("/age") @Operation(summary = "获得所有数据的年龄分段和数量") public List> findByage(String starTime, String endTime) { - if (starTime != null && endTime != null){ - String replace = starTime.replace("-", ""); - String replace1 = endTime.replace("-", ""); - return saleDataService.findByAge(replace, replace1); - }else{ - return saleDataService.findByAge(starTime, endTime); - } + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findByAge(replace, replace1); } @GetMapping("/lastyear/region") @Operation(summary = "查询去年各个省份的人数") - public List> lastyearfindByregion() { - return saleDataService.findByregion(saleDataService.findEventsLastYear()); + public List> lastyearfindByregion(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findByregion(saleDataService.findEventsLastYear(replace, replace1)); } @GetMapping("/thisyear/region") @Operation(summary = "查询今年各个省份的人数") - public List> thisyearfindByregion() { - return saleDataService.findByregion(saleDataService.findEventsThisYear()); + public List> thisyearfindByregion(String starTime, String endTime) { + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findByregion(saleDataService.findEventsThisYear(replace, replace1)); } @GetMapping("/salemethod") @Operation(summary = "查询各个销售渠道的购票人数") public List> findBysaleMethod(String starTime, String endTime) { - if (starTime != null && endTime != null){ - String replace = starTime.replace("-", ""); - String replace1 = endTime.replace("-", ""); - return saleDataService.findBySaleMethod(replace, replace1); - }else{ - return saleDataService.findBySaleMethod(starTime, endTime); - } + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findBySaleMethod(replace, replace1); } @GetMapping("/itemType") @Operation(summary = "查询各个产品类型的购票人数") public List> findByItemType(String starTime, String endTime) { - if (starTime != null && endTime != null){ - String replace = starTime.replace("-", ""); - String replace1 = endTime.replace("-", ""); - return saleDataService.findByDoItemType(replace, replace1); - }else{ - return saleDataService.findByDoItemType(starTime, endTime); - } + String replace = starTime.replace("-", ""); + String replace1 = endTime.replace("-", ""); + return saleDataService.findByDoItemType(replace, replace1); } @GetMapping("/wuyi/{x}") @@ -140,6 +127,8 @@ public class SaleDataApi { @GetMapping("/thisyear/nianjun") @Operation(summary = "查询今年年度售票平均金额") public BigDecimal findmoneythisyear() { +// String replace = starTime.replace("-", ""); +// String replace1 = endTime.replace("-", ""); return saleDataService.findyearJun(saleDataService.findEventsThisYear()); } 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 5cc6effca..08b94120d 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 @@ -14,10 +14,14 @@ public interface CheckTicketRepository extends MongoRepository findByName(String q, PageRequest pageable); - int countByCheckticketdate(String day); + @Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1}}") + List countByCheckticketdateBetween(String starTime, String endTime); @Query("{'checktickettime':{'$gte': ?0, '$lt': ?1},'checkticketdate':{'$dt': ?2}}") List findByTimestampBetweenAndCheckticketdate(String startTime, String endTime,String day); - ListfindByCheckticketdateAndChecktickettimeBetween(String day,String startTime, String endTime); + List findByCheckticketdateAndChecktickettimeBetween(String day,String startTime, String endTime); + + @Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1} , 'checktickettime':{'$gte': ?2, '$lt': ?3}}") + List findByCheckticketdateBetweenAndChecktickettimeBetween(String startTime, String endTime,String beingTime, String resultTime); } diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataRepository.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataRepository.java index d333177f0..fdbb93904 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataRepository.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataRepository.java @@ -18,6 +18,9 @@ public interface SaleDataRepository extends MongoRepository { Page findByName(String q, PageRequest pageable);*/ int countBySddate(String day); + @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'sddate': 1 }") + List countBySddateToTime(String starTime, String endTime); + // @Query("{ 'sddate' : { $gte: ?0, $lte: ?1 } }") @Query(value = "{ 'sddate': { $gte: ?0, $lte: ?1 } }", fields = "{ 'certificateno': 1, 'amount': 1}") @@ -59,6 +62,6 @@ public interface SaleDataRepository extends MongoRepository { List findAllByItemtypenameTime(String starTime, String endTime); @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }") - List findAllByTransactiontypenoTime(String starTime, String endTime); + List findAllByTransactiontypenoTime(String starTime, String endTime); } diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketService.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketService.java index 6964e6423..de6bbb056 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketService.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketService.java @@ -14,15 +14,15 @@ public interface CheckTicketService { /** * 获取日期当天各个时段的检票人数 - * @param day + * @param starTime * @return java.util.List> */ - public List> findbytimetemp(String day); + public List> findbytimetemp(String starTime, String endTime); /** * 获得日期当天的检票人数 - * @param day 日期 + * @param starTime 日期 * @return long 检票人数 */ - public long checkTicketTotal(String day); + public long checkTicketTotal(String starTime, String endTime); } \ No newline at end of file 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 18aee1159..19697e226 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 @@ -2,12 +2,14 @@ package cn.iocoder.yudao.module.datacenter.service.checkticket; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO; import cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket.CheckTicketRepository; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -31,7 +33,7 @@ public class CheckTicketServiceImpl implements CheckTicketService { @Override - public List> findbytimetemp(String day) { + public List> findbytimetemp(String starTime, String endTime) { LocalDateTime startTime = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); List> mapList = new ArrayList<>(); @@ -41,9 +43,14 @@ public class CheckTicketServiceImpl implements CheckTicketService { LocalDateTime hourStartTime = startTime.withHour(i).withMinute(0).withSecond(0).withNano(0); LocalDateTime hourEndTime = hourStartTime.plusHours(1); String begintime = formatter.format(hourStartTime); - String endtime = formatter.format(hourEndTime); - List checkTickets = checkTicketRepository.findByCheckticketdateAndChecktickettimeBetween(day,begintime,endtime); - map.put("date",begintime+"-"+endtime); + String resulttime = formatter.format(hourEndTime); + List checkTickets; + if (starTime != null && endTime != null && starTime.equals(endTime)){ + checkTickets = checkTicketRepository.findByCheckticketdateAndChecktickettimeBetween(starTime,begintime,resulttime); + }else { + checkTickets = checkTicketRepository.findByCheckticketdateBetweenAndChecktickettimeBetween(starTime,endTime,begintime,resulttime); + } + map.put("date",begintime+"-"+resulttime); map.put("count", String.valueOf(checkTickets.stream().count())); mapList.add(map); } @@ -52,8 +59,17 @@ public class CheckTicketServiceImpl implements CheckTicketService { } @Override - public long checkTicketTotal(String day) { - return checkTicketRepository.countByCheckticketdate(day); + public long checkTicketTotal(String starTime, 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 checkTicketRepository.countByCheckticketdateBetween(starTime,formattedNextDay).size(); } } \ No newline at end of file diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataService.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataService.java index ef7e074f8..3bd51e375 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataService.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataService.java @@ -18,14 +18,14 @@ public interface SaleDataService { * @param day 日期 * @return 当天总售票数 */ - public long countBySddate(String day); + public long countBySddate(String starTime, String endTime); /** * 日期往前十天内的数据 - * @param startTime 起始日期 + * @param starTime 起始日期 * @return java.util.List */ - public List> findCheckticketcountBytime(String startTime); + public List> findCheckticketcountBytime(String starTime, String endTime); /** * 查询男女人数 @@ -44,11 +44,13 @@ public interface SaleDataService { * @return */ public List findEventsLastYear(); + public List findEventsLastYear(String starTime, String endTime); /** * 查询今年1月1日到12月31日的全部数据 * @return */ public List findEventsThisYear(); + public List findEventsThisYear(String starTime, String endTime); /** * 查询各个省份和人数 diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java index 83ede1009..2c3796e55 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java @@ -33,30 +33,48 @@ public class SaleDataServiceImpl implements SaleDataService { @Autowired private SaleDataRepository saleDataRepository; - @Override - public long countBySddate(String day) { - return saleDataRepository.countBySddate(day); + + 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; } @Override - public List> findCheckticketcountBytime(String startTime) { + public long countBySddate(String starTime, String endTime) { + return saleDataRepository.countBySddateToTime(starTime, this.publicMethod(endTime)).size(); + } + + @Override + public List> findCheckticketcountBytime(String starTime, String endTime) { SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); + Calendar calendar2 = Calendar.getInstance(); Date date1= null; + Date date2= null; try { - date1 = inputFormat.parse(startTime); + date1 = inputFormat.parse(starTime); + date2 = inputFormat.parse(endTime); } catch (ParseException e) { throw new RuntimeException(e); } calendar.setTime(date1); - calendar.add(Calendar.DAY_OF_YEAR, -9); + calendar2.setTime(date2); +// calendar.add(Calendar.DAY_OF_YEAR, -9); List>map = new ArrayList<>(); - while (!calendar.getTime().after(date1)){ + while (!calendar.getTime().after(date2)){ Mapmap1= new HashMap<>(); String date = inputFormat.format(calendar.getTime()); map1.put("date",outputFormat.format(calendar.getTime())); - map1.put("count", String.valueOf(this.countBySddate(date))); + map1.put("count", String.valueOf(saleDataRepository.countBySddate(date))); map.add(map1); calendar.add(Calendar.DAY_OF_YEAR, 1); } @@ -65,19 +83,7 @@ public class SaleDataServiceImpl implements SaleDataService { @Override public List> findByGender(String starTime, String endTime) { - AggregationVO allByCertificateno; - if (starTime == null || endTime == null){ - // 获取当前日期 - LocalDate currentDate = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - String formattedDate = currentDate.format(formatter); - // 将当前日期加一天 - LocalDate nextDay = currentDate.plusDays(1); - String nextDayFormatter = nextDay.format(formatter); - allByCertificateno = saleDataRepository.findAllByCertificatenoSDTime(formattedDate, nextDayFormatter); - }else { - allByCertificateno = saleDataRepository.findAllByCertificatenoSDTime(starTime, endTime); - } + AggregationVO allByCertificateno = saleDataRepository.findAllByCertificatenoSDTime(starTime, this.publicMethod(endTime)); List> map = new ArrayList<>(); Mapmap1=new HashMap<>(); Mapmap2=new HashMap<>(); @@ -92,19 +98,7 @@ public class SaleDataServiceImpl implements SaleDataService { @Override public List> findByAge(String starTime, String endTime) { - AgeVo byAge; - if (starTime == null || endTime == null){ - // 获取当前日期 - LocalDate currentDate = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - String formattedDate = currentDate.format(formatter); - // 将当前日期加一天 - LocalDate nextDay = currentDate.plusDays(1); - String nextDayFormatter = nextDay.format(formatter); - byAge = saleDataRepository.findByAge(formattedDate,nextDayFormatter); - }else { - byAge = saleDataRepository.findByAge(starTime,endTime); - } + AgeVo byAge = saleDataRepository.findByAge(starTime,this.publicMethod(endTime)); List>map=new ArrayList<>(); Mapmap1=new LinkedHashMap<>(); Mapmap2=new LinkedHashMap<>(); @@ -145,6 +139,16 @@ public class SaleDataServiceImpl implements SaleDataService { return saleDataRepository.findBySddateBetween(start, end); } @Override + public List findEventsLastYear(String starTime, String endTime) { +// DateTimeFormatter date = DateTimeFormatter.ofPattern("yyyyMMdd"); +// LocalDate lastYear = LocalDate.now().minusYears(1); +// LocalDate startOfYear = lastYear.withDayOfYear(1); +// LocalDate endOfYear = lastYear.withDayOfYear(lastYear.lengthOfYear()); +// String start = date.format(startOfYear); +// String end = date.format(endOfYear); + return saleDataRepository.findBySddateBetween(starTime, endTime); + } + @Override public List findEventsThisYear() { DateTimeFormatter date = DateTimeFormatter.ofPattern("yyyyMMdd"); LocalDate thisYear = LocalDate.now().minusYears(0); @@ -154,6 +158,16 @@ public class SaleDataServiceImpl implements SaleDataService { String end = date.format(endOfYear); return saleDataRepository.findBySddateBetween(start,end); } + @Override + public List findEventsThisYear(String starTime, String endTime) { +// DateTimeFormatter date = DateTimeFormatter.ofPattern("yyyyMMdd"); +// LocalDate thisYear = LocalDate.now().minusYears(0); +// LocalDate startOfYear = thisYear.withDayOfYear(1); +// LocalDate endOfYear = thisYear.withDayOfYear(thisYear.lengthOfYear()); +// String start = date.format(startOfYear); +// String end = date.format(endOfYear); + return saleDataRepository.findBySddateBetween(starTime,endTime); + } @Override public List> findByregion(List list) { @@ -198,24 +212,12 @@ public class SaleDataServiceImpl implements SaleDataService { @Override public List> findBySaleMethod(String starTime, String endTime) { - List saleDataList; - if (starTime == null || endTime == null){ - // 获取当前日期 - LocalDate currentDate = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - String formattedDate = currentDate.format(formatter); - // 将当前日期加一天 - LocalDate nextDay = currentDate.plusDays(1); - String nextDayFormatter = nextDay.format(formatter); - saleDataList = saleDataRepository.findAllByTransactiontypenoTime(formattedDate, nextDayFormatter); - }else { - saleDataList = saleDataRepository.findAllByTransactiontypenoTime(starTime, endTime); - } + List saleDataList = saleDataRepository.findAllByTransactiontypenoTime(starTime, this.publicMethod(endTime)); int[] saleMethodCounts = new int[5]; Mapmap=new LinkedHashMap<>(); - for (String saleData : saleDataList) { -// String transactiontypeno = saleData.getTransactiontypeno(); - switch (saleData){ + for (SaleData saleData : saleDataList) { + String transactiontypeno = saleData.getTransactiontypeno(); + switch (transactiontypeno){ case "SD01": saleMethodCounts[0]++; break; @@ -252,19 +254,7 @@ public class SaleDataServiceImpl implements SaleDataService { @Override public List> findByDoItemType(String starTime, String endTime) { - List list; - if (starTime == null || endTime == null){ - // 获取当前日期 - LocalDate currentDate = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - String formattedDate = currentDate.format(formatter); - // 将当前日期加一天 - LocalDate nextDay = currentDate.plusDays(1); - String nextDayFormatter = nextDay.format(formatter); - list = saleDataRepository.findAllByItemtypenameTime(formattedDate, nextDayFormatter); - }else { - list = saleDataRepository.findAllByItemtypenameTime(starTime, endTime); - } + List list = saleDataRepository.findAllByItemtypenameTime(starTime, this.publicMethod(endTime)); Map countMap = list.stream() .collect(Collectors.groupingBy(SaleDataItemTypeVo::getItemtypename, Collectors.counting())); List> mapArrayList = new ArrayList<>(); @@ -419,7 +409,7 @@ public class SaleDataServiceImpl implements SaleDataService { int count = 0; while (!calendar.getTime().after(date1)){ String date = inputFormat.format(calendar.getTime()); - long i = this.countBySddate(date); + long i = saleDataRepository.countBySddate(date); count+=i; calendar.add(Calendar.DAY_OF_YEAR, 1); }