| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package domain
- // Elasticsearch(iotcore-stat) MQTT 报文统计相关的响应结构。
- // 服务端遵循 Elasticsearch API 规范。索引名形如 iotcore-stat-<yyyy.MM.dd>,
- // 每条文档字段:@timestamp(date)、timeStamp(long,秒)、equipNo(keyword,站点)、cmdType(int)、event(object)。
- //
- // 说明:需求中的“站点”即 equipNo(设备号)。
- /*************** 通用 ES 结构 ***************/
- // EsShardInfo 分片信息
- type EsShardInfo struct {
- Total int `json:"total"`
- Successful int `json:"successful"`
- Skipped int `json:"skipped"`
- Failed int `json:"failed"`
- }
- // EsCountResponse 对应 GET <index>/_count
- type EsCountResponse struct {
- Count int64 `json:"count"`
- Shards *EsShardInfo `json:"_shards,omitempty"`
- }
- // EsBucket terms 聚合的单个桶(key 为字符串)
- type EsBucket struct {
- Key string `json:"key"`
- DocCount int64 `json:"doc_count"`
- }
- // EsKeyedBucket terms 聚合的单个桶(key 为数值,如 cmdType)
- type EsKeyedBucket struct {
- Key int64 `json:"key"`
- DocCount int64 `json:"doc_count"`
- }
- // EsTermsAggregation 字符串 key 的 terms 聚合结果
- type EsTermsAggregation struct {
- DocCountErrorUpperBound int64 `json:"doc_count_error_upper_bound"`
- SumOtherDocCount int64 `json:"sum_other_doc_count"`
- Buckets []EsBucket `json:"buckets"`
- }
- // EsNumericTermsAggregation 数值 key 的 terms 聚合结果
- type EsNumericTermsAggregation struct {
- DocCountErrorUpperBound int64 `json:"doc_count_error_upper_bound"`
- SumOtherDocCount int64 `json:"sum_other_doc_count"`
- Buckets []EsKeyedBucket `json:"buckets"`
- }
- // EsDateBucket date_histogram 的单个桶
- type EsDateBucket struct {
- KeyAsString string `json:"key_as_string"`
- Key int64 `json:"key"` // epoch millis
- DocCount int64 `json:"doc_count"`
- }
- // EsDateHistogramAggregation date_histogram 聚合结果
- type EsDateHistogramAggregation struct {
- Buckets []EsDateBucket `json:"buckets"`
- }
- // EsCardinality cardinality 聚合结果(去重计数)
- type EsCardinality struct {
- Value int64 `json:"value"`
- }
- /*************** 看板:报文总量 ***************/
- // MessageTotal 报文总量(月/日通用)
- type MessageTotal struct {
- Period string `json:"period"` // 统计周期,如 "2026.09" 或 "2026.09.08"
- Total int64 `json:"total"` // 报文总量
- }
- /*************** 看板:站点总量(分页,按量降序) ***************/
- // SiteTotalItem 单个站点(equipNo)的报文总量
- type SiteTotalItem struct {
- EquipNo string `json:"equipNo"`
- Total int64 `json:"total"`
- }
- // SiteTotalPage 站点总量分页结果
- type SiteTotalPage struct {
- Page int `json:"page"` // 当前页,从 1 开始
- PageSize int `json:"pageSize"` // 每页条数
- SiteCount int64 `json:"siteCount"` // 站点总数(去重 equipNo 数量),用于计算总页数
- Items []SiteTotalItem `json:"items"`
- }
- /*************** 下钻:站点每日总量 ***************/
- // DailyTotal 某天的报文总量
- type DailyTotal struct {
- Date string `json:"date"` // "2026-09-08"
- Total int64 `json:"total"`
- }
- /*************** 下钻:站点每日命令类型总量(分页,按量降序) ***************/
- // CmdTypeTotalItem 单个命令类型的报文总量
- type CmdTypeTotalItem struct {
- CmdType int64 `json:"cmdType"`
- Total int64 `json:"total"`
- }
- // CmdTypeTotalPage 命令类型总量分页结果
- type CmdTypeTotalPage struct {
- Page int `json:"page"`
- PageSize int `json:"pageSize"`
- CmdTypeCount int64 `json:"cmdTypeCount"` // 命令类型总数(去重),用于计算总页数
- Items []CmdTypeTotalItem `json:"items"`
- }
- /*************** 查询:逐条原始报文 ***************/
- // MqttMessageItem 单条 MQTT 报文记录(对应 _source)
- type MqttMessageItem struct {
- Timestamp string `json:"@timestamp"` // ISO8601,如 2026-09-08T21:49:53.000Z
- TimeStamp int64 `json:"timeStamp"` // Unix 秒
- EquipNo string `json:"equipNo"`
- CmdType int64 `json:"cmdType"`
- Event map[string]any `json:"event,omitempty"`
- DocID string `json:"docId"` // ES 文档唯一标识 "_index/_id"(非 _source 字段,查询时填充)
- }
- // MessagePage 逐条报文查询的分页结果
- type MessagePage struct {
- Page int `json:"page"`
- PageSize int `json:"pageSize"`
- Total int64 `json:"total"` // 命中总数(ES track_total_hits,可能为下界)
- Items []MqttMessageItem `json:"items"`
- }
- /*************** 内部:解析 ES _search 响应用 ***************/
- // EsHitsTotal hits.total
- type EsHitsTotal struct {
- Value int64 `json:"value"`
- Relation string `json:"relation"` // "eq" | "gte"
- }
- // EsMessageHit 单条命中
- type EsMessageHit struct {
- Index string `json:"_index"`
- ID string `json:"_id"`
- Source MqttMessageItem `json:"_source"`
- }
- // EsMessageHits hits 部分
- type EsMessageHits struct {
- Total EsHitsTotal `json:"total"`
- Hits []EsMessageHit `json:"hits"`
- }
- // EsMessageSearchResponse 逐条查询 _search 的完整返回
- type EsMessageSearchResponse struct {
- Hits *EsMessageHits `json:"hits,omitempty"`
- }
|