江陵项目客流统计 时间的计算

2023-10-09 13:40

本文主要是介绍江陵项目客流统计 时间的计算,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

 1 @Override
 2     public Map<String,List<Map.Entry<String,RmpPassengerDto>>> getPassengerByDateAndPlace(RmpPassengerReportConditionDto conditionDto) {
 3         LogUtils.logInfo("进入客流报表服务层!");
 4         String regionId = conditionDto.getRegion_id();
 5         LogUtils.logInfo("区域ID"+regionId);
 6         Integer regionType = conditionDto.getRegion_type();
 7         LogUtils.logInfo("区域类型"+regionType);
 8         String startDate = conditionDto.getStartDate();
 9         LogUtils.logInfo("开始时间"+startDate);
10         String endDate = conditionDto.getEndDate();
11         LogUtils.logInfo("结束时间"+endDate);
12         String dateType = conditionDto.getDateType();
13         //江铃门店类型
14         Integer storeType = conditionDto.getStoreType();
15         //获得图表显示的日期
16         List<String> timeXList;
17 
18 
19         //对日期进行处理 年 20XX-01-01 00:00:00~20XX-12-31 23:59:59
20         //月 20XX-XX-01
21         LogUtils.logInfo("开始处理时间信息。");
22         Map<String,Date> startAndTime = vssCarRecordService.valiteDate(startDate,endDate,dateType);
23         LogUtils.logInfo("时间信息处理完成。");
24         Date startTime = startAndTime.get("startTime");
25         Date endTime = startAndTime.get("endTime");
26         LogUtils.logInfo("开始时间:"+startTime);
27         LogUtils.logInfo("结束时间:"+endTime);
28         Collection<Date> dateList = getDateList(startTime,endTime,dateType);
29          timeXList = convertDateToStringSimple(dateList, true,dateType);
30 
31        Map<String,RmpPassengerDto> resultMap = new TreeMap<>(new Comparator<String>() {
32            @Override
33            public int compare(String o1, String o2) {
34                return o1.compareTo(o2);
35            }
36        });
37         for (String timeX: timeXList
38              ) {
39             resultMap.put(timeX,null);
40         }
41 
42          Timestamp startTimes = new Timestamp(startTime.getTime());
43         Timestamp endTimes = new Timestamp(endTime.getTime());
44 
45         List<Integer> regionIds = new ArrayList<>();
46         if(regionId!=null && regionType != null) {
47             //通过region中path查询出所有的子门店
48             LogUtils.logInfo("查询区域信息。");
49             regionIds = rmpPassengerUtilDao.getRegionIDsByParentNodes(regionId,-1);
50         }
51         Map<String,List<Map.Entry<String,RmpPassengerDto>>> brandDateMap = rmpPassengerDao.queryDataByDateAndPlaceDevideBrand(startTimes, endTimes, dateType, regionIds,resultMap,storeType);
52         return brandDateMap;
53     }
 /*** 给定日期类型(年月周天)和日期计算出开始和结束的时间** @param startDate* @param endDate* @param dateType* @return*/public Map<String, Date> valiteDate(String startDate, String endDate, String dateType) {Calendar c = Calendar.getInstance();SimpleDateFormat sdf;Date startTime = new Date();Date endTime = new Date();int year;int month;switch (dateType) {case RmpReportConstant.LEVEL_YEAR:sdf = new SimpleDateFormat("yyyy");try {startTime = sdf.parse(startDate);c.setTime(startTime);year = c.get(Calendar.YEAR);c.set(year, 0, 01, 00, 00, 00);startTime = c.getTime();c.set(year, 11, 31, 23, 59, 59);endTime = c.getTime();} catch (ParseException e) {e.printStackTrace();}break;case RmpReportConstant.LEVEL_MONTH:sdf = new SimpleDateFormat("yyyy-MM");try {startTime = sdf.parse(startDate);c.setTime(startTime);year = c.get(Calendar.YEAR);month = c.get(Calendar.MONTH);int dayMonthEnd = c.getActualMaximum(Calendar.DAY_OF_MONTH);c.set(year, month, 01, 00, 00, 00);startTime = c.getTime();c.set(year, month, dayMonthEnd, 23, 59, 59);endTime = c.getTime();} catch (ParseException e) {e.printStackTrace();}break;case RmpReportConstant.LEVEL_WEEK:String startDates = RmpDateTimeUtil.getFirstDayOfWeek(startDate);String endDates = RmpDateTimeUtil.getLastDayOfWeek(startDate);sdf = new SimpleDateFormat("yyyy-MM-dd");try {startTime = sdf.parse(startDates);endTime = sdf.parse(endDates);} catch (ParseException e) {e.printStackTrace();}break;case RmpReportConstant.LEVEL_DAY:sdf = new SimpleDateFormat("yyyy-MM-dd");try {Date dayDate = sdf.parse(startDate);c.setTime(dayDate);c.set(Calendar.HOUR, 0);c.set(Calendar.MINUTE, 0);c.set(Calendar.SECOND, 0);c.set(Calendar.MILLISECOND, 0);startTime = c.getTime();c.set(Calendar.HOUR, 23);c.set(Calendar.MINUTE, 59);c.set(Calendar.SECOND, 59);c.set(Calendar.MILLISECOND, 999);endTime = c.getTime();} catch (ParseException e) {e.printStackTrace();}break;case RmpReportConstant.LEVEL_CUSTOM:sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");try {startTime = sdf.parse(startDate + " 00:00:00");endTime = sdf.parse(endDate + " 23:59:59");} catch (ParseException e) {e.printStackTrace();}break;default:break;}Map<String, Date> resultMap = new TreeMap<>();resultMap.put("startTime", startTime);resultMap.put("endTime", endTime);return resultMap;}
/*** 获取当前时间所属周的第一天* @author yuchuanjun 2016年12月14日 下午7:41:17* @param date* @return*/public static String getFirstDayOfWeek(String date) {try{SimpleDateFormat format = new SimpleDateFormat(DATA_FORMAT_yyyy_MM_dd);Calendar cal = Calendar.getInstance();cal.setTime(format.parse(date));int day = cal.get(Calendar.DAY_OF_WEEK);// 当周第一天是星期天 Calendar周日是每周的第一天if (day == 1) {day = 7;} else {day--;}// 周一cal.add(Calendar.DAY_OF_MONTH, -(day - 1));return format.format(cal.getTime());}catch(Exception e){e.printStackTrace();}return null;}/*** 获取当前时间所属周的最后一天* @author yuchuanjun 2016年12月14日 下午7:45:34* @param date* @return*/public static String getLastDayOfWeek(String date) {try{SimpleDateFormat format = new SimpleDateFormat(DATA_FORMAT_yyyy_MM_dd);Calendar cal = Calendar.getInstance();cal.setTime(format.parse(date));int day = cal.get(Calendar.DAY_OF_WEEK);// 当周第一天是星期天 Calendar周日是每周的第一天if (day == 1) {day = 7;} else {day--;}// 周日cal.add(Calendar.DAY_OF_MONTH, 7 - day);return format.format(cal.getTime());}catch(Exception e){e.printStackTrace();}return null;}
View Code
 protected Collection<Date> getDateList( Date startDate,Date endDate,String dateType) {Collection<Date> dateSet = new ArrayList<Date>();if(endDate!=null){Calendar calendar = Calendar.getInstance();while(startDate.compareTo(endDate) <= 0) {calendar.setTime(startDate);dateSet.add(startDate);if("day".equals(dateType)){addCalendarDay(calendar);}else if("year".equals(dateType)){addCalendarYear(calendar);}else {addCalendar(calendar);}startDate = calendar.getTime();}}else{dateSet.add(startDate);}return dateSet;}
    protected List<String> convertDateToStringSimple(Collection<Date> dateList, boolean isConvertToday,String dateType) {List<String> dateStrList = new ArrayList<String>();if(!RmpUtils.isEmpty(dateList)){for(Date date : dateList){if("day".equals(dateType)){dateStrList.add(convertDateToStringSimpleDay(date, isConvertToday));}else if("year".equals(dateType)){dateStrList.add(convertDateToStringSimpleYear(date, isConvertToday));}else{dateStrList.add(convertDateToStringSimple(date, isConvertToday));}}}return dateStrList;}protected String convertDateToStringSimple(Date date, boolean isConvertToday) {return RmpDateTimeUtil.dateToString(date, RmpDateTimeUtil.DATA_FORMAT_yyyy_MM_dd);}protected String convertDateToStringSimpleDay(Date date, boolean isConvertToday) {return RmpDateTimeUtil.dateToString(date, RmpDateTimeUtil.DATE_FORMAT_HH);}protected String convertDateToStringSimpleYear(Date date, boolean isConvertToday) {return RmpDateTimeUtil.dateToString(date, RmpDateTimeUtil.DATE_FORMAT_yyyy_MM);}
SELECTstore.brand_name,z. DATE,SUM (z.in_count) passenger_in_count,SUM (z.out_count) passenger_out_count
FROM(SELECTx.region_id,x. DATE,SUM (x. IN) AS in_count,SUM (x. OUT) AS out_countFROM(SELECTto_char(v. TIME, 'yyyy-MM') DATE,v.region_id,SUM (v.passenger_in_count) AS IN,SUM (v.passenger_out_count) AS OUTFROMvss_passenger_hour_view vLEFT JOIN s_region s ON v.region_id = s.region_idWHEREs.region_level = 0AND v.datetime BETWEEN ?AND ?AND v.region_id IN (6, 7, 4)GROUP BYv. TIME,v.region_id) xGROUP BYx.region_id,DATE) z
LEFT JOIN (SELECTrs.unit_id,rb.brand_nameFROMrmp_brand rbRIGHT JOIN rmp_store rs ON rb. ID = rs.brand_id
) store ON z.region_id = store.unit_id
GROUP BYstore.brand_name,z. DATE

 

switch (timeType) {
case RmpReportConstant.LEVEL_YEAR:
queryDateType = "yyyy-MM";
break;
case RmpReportConstant.LEVEL_MONTH:
queryDateType = "yyyy-MM-dd";
break;
case RmpReportConstant.LEVEL_WEEK:
queryDateType = "yyyy-MM-dd";
break;
case RmpReportConstant.LEVEL_CUSTOM:
queryDateType = "yyyy-MM-dd";
break;
case RmpReportConstant.LEVEL_DAY:
queryDateType = "hh24";
break;
default:
break;
}

转载于:https://www.cnblogs.com/xjatj/p/9637304.html

这篇关于江陵项目客流统计 时间的计算的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/173238

相关文章

MyBatis Plus实现时间字段自动填充的完整方案

《MyBatisPlus实现时间字段自动填充的完整方案》在日常开发中,我们经常需要记录数据的创建时间和更新时间,传统的做法是在每次插入或更新操作时手动设置这些时间字段,这种方式不仅繁琐,还容易遗漏,... 目录前言解决目标技术栈实现步骤1. 实体类注解配置2. 创建元数据处理器3. 服务层代码优化填充机制详

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

Python实现精确小数计算的完全指南

《Python实现精确小数计算的完全指南》在金融计算、科学实验和工程领域,浮点数精度问题一直是开发者面临的重大挑战,本文将深入解析Python精确小数计算技术体系,感兴趣的小伙伴可以了解一下... 目录引言:小数精度问题的核心挑战一、浮点数精度问题分析1.1 浮点数精度陷阱1.2 浮点数误差来源二、基础解决

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

C# LiteDB处理时间序列数据的高性能解决方案

《C#LiteDB处理时间序列数据的高性能解决方案》LiteDB作为.NET生态下的轻量级嵌入式NoSQL数据库,一直是时间序列处理的优选方案,本文将为大家大家简单介绍一下LiteDB处理时间序列数... 目录为什么选择LiteDB处理时间序列数据第一章:LiteDB时间序列数据模型设计1.1 核心设计原则

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Python文本相似度计算的方法大全

《Python文本相似度计算的方法大全》文本相似度是指两个文本在内容、结构或语义上的相近程度,通常用0到1之间的数值表示,0表示完全不同,1表示完全相同,本文将深入解析多种文本相似度计算方法,帮助您选... 目录前言什么是文本相似度?1. Levenshtein 距离(编辑距离)核心公式实现示例2. Jac

MySQL按时间维度对亿级数据表进行平滑分表

《MySQL按时间维度对亿级数据表进行平滑分表》本文将以一个真实的4亿数据表分表案例为基础,详细介绍如何在不影响线上业务的情况下,完成按时间维度分表的完整过程,感兴趣的小伙伴可以了解一下... 目录引言一、为什么我们需要分表1.1 单表数据量过大的问题1.2 分表方案选型二、分表前的准备工作2.1 数据评估

Springboot项目构建时各种依赖详细介绍与依赖关系说明详解

《Springboot项目构建时各种依赖详细介绍与依赖关系说明详解》SpringBoot通过spring-boot-dependencies统一依赖版本管理,spring-boot-starter-w... 目录一、spring-boot-dependencies1.简介2. 内容概览3.核心内容结构4.