Merge branch 'master' of http://101.43.112.107:3000/root/ludu-cloud into xinwei

This commit is contained in:
XinWei 2024-08-28 09:44:44 +08:00
commit bfa7d6f59b
8 changed files with 142 additions and 134 deletions

View File

@ -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<Map<String, String>> findbytimetemp(@PathVariable("day") String day) {
return checkTicketService.findbytimetemp(day);
public List<Map<String, String>> findbytimetemp(String starTime, String endTime) {
String replace = starTime.replace("-", "");
String replace1 = endTime.replace("-", "");
return checkTicketService.findbytimetemp(replace,replace1);
}
}

View File

@ -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<Map<String, String>> thisyearNum(@PathVariable("startTime") String startTime) {
return saleDataService.findCheckticketcountBytime(startTime);
public List<Map<String, String>> 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<Map<String, String>> 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<Map<String, String>> lastyearNum(String starTime, String endTime) {
String replace = starTime.replace("-", "");
String replace1 = endTime.replace("-", "");
return saleDataService.findCheckticketcountBytime(replace, replace1);
}
@GetMapping("/gender")
@Operation(summary = "获得所有数据的男女数量")
public List<Map<String, String>> 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<Map<String, String>> 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<Map<String, String>> lastyearfindByregion() {
return saleDataService.findByregion(saleDataService.findEventsLastYear());
public List<Map<String, String>> 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<Map<String, String>> thisyearfindByregion() {
return saleDataService.findByregion(saleDataService.findEventsThisYear());
public List<Map<String, String>> 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<Map<String, String>> 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<Map<String, String>> 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());
}

View File

@ -14,10 +14,14 @@ public interface CheckTicketRepository extends MongoRepository<CheckTicket,Strin
@Query("{'name': {'$regex': '?0', '$options': 'i'}}")
Page<CheckTicket> findByName(String q, PageRequest pageable);
int countByCheckticketdate(String day);
@Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1}}")
List<CheckTicket> countByCheckticketdateBetween(String starTime, String endTime);
@Query("{'checktickettime':{'$gte': ?0, '$lt': ?1},'checkticketdate':{'$dt': ?2}}")
List<CheckTicket> findByTimestampBetweenAndCheckticketdate(String startTime, String endTime,String day);
List<CheckTicket>findByCheckticketdateAndChecktickettimeBetween(String day,String startTime, String endTime);
List<CheckTicket> findByCheckticketdateAndChecktickettimeBetween(String day,String startTime, String endTime);
@Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1} , 'checktickettime':{'$gte': ?2, '$lt': ?3}}")
List<CheckTicket> findByCheckticketdateBetweenAndChecktickettimeBetween(String startTime, String endTime,String beingTime, String resultTime);
}

View File

@ -18,6 +18,9 @@ public interface SaleDataRepository extends MongoRepository<SaleData,String> {
Page<SaleData> findByName(String q, PageRequest pageable);*/
int countBySddate(String day);
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'sddate': 1 }")
List<String> 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<SaleData,String> {
List<SaleDataItemTypeVo> findAllByItemtypenameTime(String starTime, String endTime);
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
List<String> findAllByTransactiontypenoTime(String starTime, String endTime);
List<SaleData> findAllByTransactiontypenoTime(String starTime, String endTime);
}

View File

@ -14,15 +14,15 @@ public interface CheckTicketService {
/**
* 获取日期当天各个时段的检票人数
* @param day
* @param starTime
* @return java.util.List<java.util.Map<java.lang.String,java.lang.String>>
*/
public List<Map<String, String>> findbytimetemp(String day);
public List<Map<String, String>> findbytimetemp(String starTime, String endTime);
/**
* 获得日期当天的检票人数
* @param day 日期
* @param starTime 日期
* @return long 检票人数
*/
public long checkTicketTotal(String day);
public long checkTicketTotal(String starTime, String endTime);
}

View File

@ -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<Map<String, String>> findbytimetemp(String day) {
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<>();
@ -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<CheckTicket> checkTickets = checkTicketRepository.findByCheckticketdateAndChecktickettimeBetween(day,begintime,endtime);
map.put("date",begintime+"-"+endtime);
String resulttime = formatter.format(hourEndTime);
List<CheckTicket> 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();
}
}

View File

@ -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<java.util.Map>
*/
public List<Map<String,String>> findCheckticketcountBytime(String startTime);
public List<Map<String,String>> findCheckticketcountBytime(String starTime, String endTime);
/**
* 查询男女人数
@ -44,11 +44,13 @@ public interface SaleDataService {
* @return
*/
public List<SaleData> findEventsLastYear();
public List<SaleData> findEventsLastYear(String starTime, String endTime);
/**
* 查询今年1月1日到12月31日的全部数据
* @return
*/
public List<SaleData> findEventsThisYear();
public List<SaleData> findEventsThisYear(String starTime, String endTime);
/**
* 查询各个省份和人数

View File

@ -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<Map<String,String>> findCheckticketcountBytime(String startTime) {
public long countBySddate(String starTime, String endTime) {
return saleDataRepository.countBySddateToTime(starTime, this.publicMethod(endTime)).size();
}
@Override
public List<Map<String,String>> 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<String,String>>map = new ArrayList<>();
while (!calendar.getTime().after(date1)){
while (!calendar.getTime().after(date2)){
Map<String,String>map1= 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<Map<String, String>> 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<String, String>> map = new ArrayList<>();
Map<String,String>map1=new HashMap<>();
Map<String,String>map2=new HashMap<>();
@ -92,19 +98,7 @@ public class SaleDataServiceImpl implements SaleDataService {
@Override
public List<Map<String, String>> 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<String,String>>map=new ArrayList<>();
Map<String,String>map1=new LinkedHashMap<>();
Map<String,String>map2=new LinkedHashMap<>();
@ -145,6 +139,16 @@ public class SaleDataServiceImpl implements SaleDataService {
return saleDataRepository.findBySddateBetween(start, end);
}
@Override
public List<SaleData> 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<SaleData> 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<SaleData> 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<Map<String, String>> findByregion(List<SaleData> list) {
@ -198,24 +212,12 @@ public class SaleDataServiceImpl implements SaleDataService {
@Override
public List<Map<String, String>> findBySaleMethod(String starTime, String endTime) {
List<String> 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<SaleData> saleDataList = saleDataRepository.findAllByTransactiontypenoTime(starTime, this.publicMethod(endTime));
int[] saleMethodCounts = new int[5];
Map<String,String>map=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<Map<String, String>> findByDoItemType(String starTime, String endTime) {
List<SaleDataItemTypeVo> 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<SaleDataItemTypeVo> list = saleDataRepository.findAllByItemtypenameTime(starTime, this.publicMethod(endTime));
Map<String, Long> countMap = list.stream()
.collect(Collectors.groupingBy(SaleDataItemTypeVo::getItemtypename, Collectors.counting()));
List<Map<String, String>> 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);
}