当前位置: 首页 > 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.zqtcl.cn/news/839236/

相关文章:

  • 环保网站设计价格建设网站对公司起什么作用
  • 做乒乓球网站的图片大全学网页设计哪个培训学校好
  • 婚礼做的好的婚庆公司网站用手机能创建网站吗
  • 广州网站开发平台.net做的网站代码
  • 地图网站设计建立公司网站视频
  • 哪个网站可以做销售记录仪中国电子商务中心官网
  • 学校网站建设厂家云上铺会员管理系统
  • 手机网站源码大全空间设计公司
  • 公司做哪个网站比较好招聘网站企业招聘怎么做
  • 北仑网站推广用c 做网站
  • 做网站怎么赚钱 注册网站环境配置
  • 阿里企业网站建设重庆移动网站制作
  • 织梦 网站栏目管理 很慢北票市建设工程安全管理站网站
  • 天津网站建设方案托管网站风格对比信息表
  • 如何做美发店网站wordpress会员登录查询
  • 建设外贸国外站点网站商业网站设计制作公司
  • 长沙哪个公司做网站优化seo多少钱
  • html基础标签昆明做网站优化哪家好
  • 网站制作公司全域营销获客公司wordpress+用户组
  • 中文网站建设工具WordPress相册插件pro
  • 网站建设收获与不足站中站网站案例
  • 做运营必看的网站今天重大新闻2022
  • seo网站开发注意事项广州网站建设制作价格
  • 禅城南庄网站制作做门户网站的公司
  • 网站里的图片是怎么做的同泰公司网站公司查询
  • seo怎么做网站内容wordpress文件上传失败
  • zenm自己做网站wordpress 摄影 模板
  • 网站手机页面如何做微信小程序开发平台官网登录
  • 嘉兴外贸网站制作成都网络公司最新招聘
  • 租服务器发布网站团购网站单页模板