当前位置: 首页 > news >正文

东莞企业网站推广技巧网页制作软件中文免费版

东莞企业网站推广技巧,网页制作软件中文免费版,建网站自学,课程网站建设发展趋势Elasticsearch 按时间进行聚合统计 需求#xff1a; 1、统计某一个小时#xff0c;每分钟的数据条数 2、统计某一天#xff0c;每个小数的数据条数 3、统计一周#xff0c;每天的数据条数 pom依赖 dependencygroupIdorg.springframework.boot/groupId 1、统计某一个小时每分钟的数据条数 2、统计某一天每个小数的数据条数 3、统计一周每天的数据条数 pom依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-elasticsearch/artifactId/dependency代码实现 package com.woodare.tsp.portal.facade;import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import com.woodare.tsp.common.core.context.Context; import com.woodare.tsp.portal.enums.DateType; import com.woodare.tsp.portal.helper.DateHelper; import com.woodare.tsp.portal.pojo.vo.DashboardVO; import com.woodare.tsp.portal.pojo.vo.StatisticsChartVO; import com.woodare.tsp.service.consts.ElasticsearchIndexNameConst; import com.woodare.tsp.service.domain.Product; import com.woodare.tsp.service.entity.IotDataLog; import com.woodare.tsp.service.service.DeviceOnlineStatusService; import com.woodare.tsp.service.service.DeviceService; import com.woodare.tsp.service.service.ProductService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.elasticsearch.core.ElasticsearchAggregations; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.SearchHits; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.stereotype.Service;import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.*;/*** author WANG*/ RequiredArgsConstructor Slf4j Service public class DashboardFacade {final DeviceService deviceService;final ProductService productService;final DeviceOnlineStatusService deviceOnlineStatusService;final ElasticsearchRestTemplate elasticsearchRestTemplate;Value(${device.online.time:10})private Integer deviceOnlineTime;/*** 统计** return 统计详情*/public DashboardVO statistics() {DashboardVO dashboardVO new DashboardVO();ListProduct productList productService.getListByCondition(new Product());Long totalCount deviceService.getTotalDeviceCount();// 设备最后在线时间在最近{10}分钟内算在线long time DateUtil.offsetMinute(new Date(), -deviceOnlineTime).getTime();long onlineCount 0;for (Product product : productList) {onlineCount deviceOnlineStatusService.count(product.getUid(), time);}BoolQueryBuilder queryBuilder QueryBuilders.boolQuery();String tenantId Context.getTenantId();if (StrUtil.isNotBlank(tenantId)) {queryBuilder.filter(QueryBuilders.termQuery(tenantId, tenantId));}StatisticsChartVO.DateRange dateRange this.getDateRange(DateType.DAY);queryBuilder.filter(QueryBuilders.rangeQuery(createdTime).gte(dateRange.getStart()).lte(dateRange.getEnd()));IndexCoordinates indexCoordinates IndexCoordinates.of(ElasticsearchIndexNameConst.TEMP_IOT_DATA_LOG);NativeSearchQuery query new NativeSearchQueryBuilder().withQuery(queryBuilder).build();SearchHitsIotDataLog searchHits elasticsearchRestTemplate.search(query, IotDataLog.class, indexCoordinates);long totalHits searchHits.getTotalHits();return dashboardVO.setTotalAlertCount(0L).setTotalMessageCount(totalHits).setTotalDeviceCount(totalCount).setTotalOnlineDeviceCount(onlineCount);}public StatisticsChartVO statisticsChart(DateType dateType) {StatisticsChartVO statisticsChartVO new StatisticsChartVO();StatisticsChartVO.DateRange dateRange this.getDateRange(dateType);BoolQueryBuilder queryBuilder QueryBuilders.boolQuery();String tenantId Context.getTenantId();if (StrUtil.isNotBlank(tenantId)) {queryBuilder.filter(QueryBuilders.termQuery(tenantId, tenantId));}queryBuilder.filter(QueryBuilders.rangeQuery(createdTime).gte(dateRange.getStart()).lte(dateRange.getEnd()));NativeSearchQuery query this.buildQueryByDateType(queryBuilder, dateType);SearchHitsObject searchHits elasticsearchRestTemplate.search(query, Object.class, IndexCoordinates.of(ElasticsearchIndexNameConst.TEMP_IOT_DATA_LOG));ElasticsearchAggregations elasticsearchAggregations (ElasticsearchAggregations) searchHits.getAggregations();assert elasticsearchAggregations ! null;Aggregations aggregations elasticsearchAggregations.aggregations();MapString, Long map new LinkedHashMap();for (Aggregation aggregation : aggregations) {ParsedDateHistogram dateHistogram (ParsedDateHistogram) aggregation;for (Histogram.Bucket bucket : dateHistogram.getBuckets()) {long docCount bucket.getDocCount();String date bucket.getKeyAsString();map.put(date, docCount);log.info(data: {} --- {}, date, docCount);}}ListStatisticsChartVO.DataItem dataList this.buildDataByDateType(map, dateType, dateRange);statisticsChartVO.setDataList(dataList);return statisticsChartVO;}private ListStatisticsChartVO.DataItem buildDataByDateType(MapString, Long map, DateType dateType, StatisticsChartVO.DateRange dateRange) {ListString dateList;String timeZone Context.getTimezone();ListStatisticsChartVO.DataItem list new ArrayList();if (DateType.HOUR.equals(dateType)) {dateList DateHelper.getMinuteList(dateRange.getStart(), dateRange.getEnd());} else if (DateType.DAY.equals(dateType)) {dateList DateHelper.getHourList();} else {dateList DateHelper.getDayList(dateRange.getStart(), dateRange.getEnd());}if (DateType.HOUR.equals(dateType)) {buildHourDataList(map, dateList, list);} else if (DateType.DAY.equals(dateType)) {for (String date : dateList) {// es查询出来的是日期是0时区的日期需转成当前时区的时间例如时间为14:00这是0时区的14:00转成8区则为22:00String hour date.split(StrUtil.COLON)[0];String newHour getHour(Integer.parseInt(hour), Integer.parseInt(timeZone));StatisticsChartVO.DataItem item new StatisticsChartVO.DataItem();String newDate newHour StrUtil.COLON date.split(StrUtil.COLON)[1];item.setDate(newDate);item.setValue(map.containsKey(date) ? map.remove(date) : 0L);list.add(item);}} else {for (String date : dateList) {StatisticsChartVO.DataItem item new StatisticsChartVO.DataItem();item.setDate(date);item.setValue(map.getOrDefault(date, 0L));list.add(item);}}list.sort(Comparator.comparing(StatisticsChartVO.DataItem::getDate));return list;}private void buildHourDataList(MapString, Long map, ListString dateList, ListStatisticsChartVO.DataItem list) {if (MapUtil.isEmpty(map)) {setDefaultData(dateList, list);} else {String offsetHour dateList.get(0).split(StrUtil.COLON)[0];String currUtcHour getHourInZeroTimeZone(System.currentTimeMillis());// 先去除其他数据MapString, Long stashMap new LinkedHashMap();for (Map.EntryString, Long entry : map.entrySet()) {String date entry.getKey();String currHour date.split(StrUtil.COLON)[0];if (currHour.equals(currUtcHour)) {String minute date.split(StrUtil.COLON)[1];stashMap.put(offsetHour StrUtil.COLON minute, entry.getValue());}}if (MapUtil.isEmpty(stashMap)) {setDefaultData(dateList, list);} else {for (String date : dateList) {StatisticsChartVO.DataItem item new StatisticsChartVO.DataItem();item.setDate(date);item.setValue(stashMap.getOrDefault(date, 0L));list.add(item);}}}}public String getHourInZeroTimeZone(long timestamp) {LocalDateTime dateTime LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC);int hour dateTime.getHour();return (hour 10 ? 0 : ) hour;}private void setDefaultData(ListString dateList, ListStatisticsChartVO.DataItem list) {for (String date : dateList) {StatisticsChartVO.DataItem item new StatisticsChartVO.DataItem();item.setDate(date);item.setValue(0L);list.add(item);}}private String getHour(int num1, int num2) {int num num1 num2;if (num 24) {num - 24;}if (num 0) {num 24;}if (num 10) {return 0 num;} else {return StrUtil.EMPTY num;}}private NativeSearchQuery buildQueryByDateType(BoolQueryBuilder queryBuilder, DateType dateType) {if (DateType.HOUR.equals(dateType)) {return new NativeSearchQueryBuilder().withQuery(queryBuilder).withAggregations(AggregationBuilders.dateHistogram(minute_stats).field(createdTime).calendarInterval(DateHistogramInterval.MINUTE).format(HH:mm)).build();} else if (DateType.DAY.equals(dateType)) {return new NativeSearchQueryBuilder().withQuery(queryBuilder).withAggregations(AggregationBuilders.dateHistogram(minute_stats).field(createdTime).calendarInterval(DateHistogramInterval.HOUR).format(HH:mm)).build();} else {return new NativeSearchQueryBuilder().withQuery(queryBuilder).withAggregations(AggregationBuilders.dateHistogram(logs_per_day).field(createdTime).calendarInterval(DateHistogramInterval.DAY).format(yyyy-MM-dd)).build();}}private StatisticsChartVO.DateRange getDateRange(DateType dateType) {StatisticsChartVO.DateRange dateRange new StatisticsChartVO.DateRange();if (DateType.HOUR.equals(dateType)) {dateRange.setStart(DateUtil.beginOfHour(new Date()).getTime());dateRange.setEnd(DateUtil.endOfHour(new Date()).getTime());} else if (DateType.DAY.equals(dateType)) {dateRange.setStart(DateUtil.beginOfDay(new Date()).getTime());dateRange.setEnd(DateUtil.endOfDay(new Date()).getTime());} else if (DateType.WEEK.equals(dateType)) {DateTime start DateUtil.offsetDay(new Date(), -7);DateTime end DateUtil.offsetDay(new Date(), -1);dateRange.setStart(start.getTime());dateRange.setEnd(end.getTime());}return dateRange;} } package com.woodare.tsp.portal.helper;import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.woodare.tsp.common.core.context.Context;import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.List;/*** author WANG*/ public class DateHelper {private static final int HOURS_OF_DAY 24;private static ListString getMinuteIntervals(long startTimestamp, long endTimestamp) {ListString intervals new ArrayList();DateTimeFormatter formatter DateTimeFormatter.ofPattern(HH:mm);int timezone Integer.parseInt(Context.getTimezone());LocalDateTime current LocalDateTime.ofEpochSecond(startTimestamp / 1000, 0, ZoneOffset.ofHours(timezone));LocalDateTime endTime LocalDateTime.ofEpochSecond(endTimestamp / 1000, 0, ZoneOffset.ofHours(timezone));while (!current.isAfter(endTime)) {intervals.add(current.format(formatter));current current.plusMinutes(1);}return intervals;}public static ListString getHourList() {ListString hourList new ArrayList();for (int i 0; i HOURS_OF_DAY; i) {String hour;if (i 10) {hour 0 i;} else {hour i;}hourList.add(hour :00);}return hourList;}public static ListString getMinuteList(Long start, Long end) {return getMinuteIntervals(start, end);}public static ListString getDayList(Long start, Long end) {ListString dates new ArrayList();LocalDateTime startDate LocalDateTime.ofInstant(Instant.ofEpochMilli(start), ZoneId.systemDefault());LocalDateTime endDate LocalDateTime.ofInstant(Instant.ofEpochMilli(end), ZoneId.systemDefault());while (!startDate.isAfter(endDate)) {dates.add(startDate.format(DateTimeFormatter.ofPattern(yyyy-MM-dd)));startDate startDate.plusDays(1);}return dates;}public static void main(String[] args) {Context.setTimezone(8);long start DateUtil.beginOfHour(new Date()).getTime();long end DateUtil.endOfHour(new Date()).getTime();ListString intervals getMinuteList(start, end);for (String interval : intervals) {System.out.println(interval);}System.out.println();ListString hourList getHourList();for (String interval : hourList) {System.out.println(interval);}System.out.println();DateTime startDate DateUtil.offsetDay(new Date(), -7);DateTime endDate DateUtil.offsetDay(new Date(), -1);ListString dayList getDayList(startDate.getTime(), endDate.getTime());for (String date : dayList) {System.out.println(date);}}}
http://www.pierceye.com/news/513144/

相关文章:

  • 北京家居网站建设如何制作软件手机软件
  • 北京网站建设策划解决方案长沙建设工程造价网站
  • 北京网站设计公司价格阿里云wordpress插件
  • 网站建设自助建站企业萧山人才网手机版
  • 长沙建站挺找有为太极wordpress 需要zend
  • 通信管理局 网站备案天猫网站设计教程
  • 营销型网站制作成都打造品牌的三点策略
  • 做查工资的网站如何下载网页在线视频
  • 北沙滩网站建设公司主页怎么填
  • 手机asp网站网站设计方案
  • 长春市网站开发广东一站式网站建设推荐
  • 企业网站推广策略商会联盟网站建设方案
  • 清丰网站建设百度推广建设网站是不是合发
  • 邢台12345网站哪个公司的装饰设计公司
  • 嘉兴网嘉兴网站建设手机网站管理软件
  • 网站主色调简介怎么说本地常州微信网站建设
  • 电子商务网站数据库建设怎样推广一个网站
  • illustrator 学习网站wordpress外链产品
  • 电脑端网站一般做多宽最好网页游戏制作成本
  • 怎样做好手机网站建设wordpress开启xml rpc
  • 泉州企业网站建设公司做外贸要建什么网站
  • 找人做网站价格永城网站设计公司
  • 如何让网站做网页适配深圳市门户网站建设多少钱
  • 中金超钒 网站建设淘客推广方法
  • 网站建设的基本流程域名备案需要哪些资料
  • 怎么查找网站死链怎么自己做微信推送新闻
  • 做网站的人能看到浏览的人的信息吗怎么刷网站权重
  • 有了域名搭建网站详细步骤服务外包有哪些
  • 外贸网站样式传扬互动网站建设公司
  • 企业网站建设需要哪些资料信息免费推广工具