package domain import ( "fmt" "time" "go.mongodb.org/mongo-driver/bson/primitive" ) type BatchDownloadInfo struct { Id primitive.ObjectID `bson:"_id" json:"id"` Sn []string `bson:"sn" json:"sn"` Description string `bson:"description" json:"description"` TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"` Options BatchDownloadOptions `bson:"options" json:"options"` Progress Progress `bson:"progress" json:"progress"` FailReasons []string `bson:"failReasons" json:"failReasons"` Items []BatchDownloadItem `bson:"items" json:"items"` TotalCount int `bson:"totalCount" json:"totalCount"` DoneCount int `bson:"doneCount" json:"doneCount"` Owner *[]string `bson:"owner,omitempty" json:"owner,omitempty"` } type BatchDownloadOptions struct { PowerFlow bool `bson:"powerFlow" json:"powerFlow"` // 功率流图 MqttLogs []string `bson:"mqttLogs" json:"mqttLogs"` // MQTT日志 EventAlarm bool `bson:"eventAlarm" json:"eventAlarm"` // 事件和告警日志 AlarmSnapshot bool `bson:"alarmSnapshot" json:"alarmSnapshot"` // 告警快照 EmsLogs []string `bson:"emsLogs" json:"emsLogs"` // EMS日志 FaultRecord bool `bson:"faultRecord" json:"faultRecord"` // 故障录波 UpdateLog bool `bson:"updateLog" json:"updateLog"` // 升级记录 Settings bool `bson:"settings" json:"settings"` // 站点设置 } type BatchDownloadConfigWrite struct { Sn []string `bson:"sn" json:"sn"` Description string `bson:"description" json:"description"` TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"` Options BatchDownloadOptions `bson:"options"` Owner *[]string `bson:"owner,omitempty" json:"owner,omitempty"` } type BatchDownloadConfig struct { Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` Sn []string `bson:"sn" json:"sn"` Description string `bson:"description" json:"description"` TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"` Options BatchDownloadOptions `bson:"options"` Progress Progress `bson:"progress" json:"progress"` Data map[string]BatchDownloadData `bson:"data" json:"data"` // map-key为SN FailReasons []string `bson:"failReasons" json:"failReasons"` Items []BatchDownloadItem `bson:"items" json:"items"` TotalCount int `bson:"totalCount" json:"totalCount"` DoneCount int `bson:"doneCount" json:"doneCount"` Owner *[]string `bson:"owner,omitempty" json:"owner,omitempty"` } type TaskBatchDownload struct { Id primitive.ObjectID `bson:"_id" json:"id"` Sn []string `bson:"sn" json:"sn"` TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"` Options BatchDownloadOptions `bson:"options"` } // 数据说明 // map的key为日期,格式为 YYYY-MM-DD // MqttLogs和EmsLogs的二级map为日志类型名称 // 存储的最终数据是文件服务器(minio)的存储路径 type BatchDownloadData struct { PowerFlow *map[string]string `bson:"powerFlow,omitempty" json:"powerFlow,omitempty"` // 功率流图 MqttLogs *map[string]map[string]string `bson:"mqttLogs,omitempty" json:"mqttLogs,omitempty"` // MQTT日志 EventAlarm *map[string]string `bson:"eventAlarm,omitempty" json:"eventAlarm,omitempty"` // 事件和告警日志 AlarmSnapshot *map[string]string `bson:"alarmSnapshot,omitempty" json:"alarmSnapshot,omitempty"` // 告警快照 EmsLogs *map[string]map[string]string `bson:"emsLogs,omitempty" json:"emsLogs,omitempty"` // EMS日志 FaultRecord *map[string]string `bson:"faultRecord,omitempty" json:"faultRecord,omitempty"` // 故障录波 map的key为文件名 UpdateLog *string `bson:"updateLog,omitempty" json:"updateLog,omitempty"` // 升级记录 Settings *string `bson:"settings,omitempty" json:"settings,omitempty"` // 站点设置 } // 下载任务数据 (保存于redis数据库) type BatchDownloadFileTaskInfo struct { DevType int `bson:"devType" json:"devType"` // 设备类型:-1-忽略 0-aPower-PE 1-aGate/MCA 2-aPower-MPPT 3-aHub Sn string `bson:"sn" json:"sn"` Date string `bson:"date" json:"date"` FileType string `bson:"fileType" json:"fileType"` FileSupType string `bson:"fileSubType" json:"fileSubType"` Result int `bson:"result" json:"result"` // -1-失败 0-进行中 1-成功 Reason string `bson:"reason" json:"reason"` // 失败原因 } type BatchDownloadUpdateLogVersionInfo struct { Name string `json:"name"` // 名称 OldVer string `json:"oldVer"` NewVer string `json:"newVer"` } type BatchDownloadUpdateLogSubDevInfo struct { DevSn string `json:"devSn"` DevVerList []BatchDownloadUpdateLogVersionInfo `json:"devVerList"` } type BatchDownloadUpdateLogAHubVersionInfo struct { FileName string `json:"fileName"` // 文件名称 FileOrder string `json:"fileOrder"` // 文件单号 Result string `json:"result"` // 升级结果 "0"-成功 ResultDesc string `json:"resultDesc"` // 升级结果说明 OldVer string `json:"oldVer"` NewVer string `json:"newVer"` } // 系统升级日志信息数据 type BatchDownloadSystemUpdateLogInfo struct { OrderNo string `json:"orderNo"` // 升级工单号 TriggerType string `json:"triggerType"` // 触发类型 自动 or 手动 GateSn string `json:"gateSn"` FileName string `json:"fileName"` // 升级包名 UpdateTime string `json:"updateTime"` // 触发升级时间 - 北京时间 Result string `json:"result"` // 升级结果 GateVerList []BatchDownloadUpdateLogVersionInfo `json:"gateVerList"` SubDevList []BatchDownloadUpdateLogSubDevInfo `json:"subVerList"` } // aHub升级日志信息数据 type BatchDownloadAHubUpdateLogInfo struct { OrderNo string `json:"orderNo"` // 升级工单号 TriggerType string `json:"triggerType"` // 触发类型 自动 or 手动 AHubSn string `json:"aHubSn"` // aHubSn GateSn string `json:"gateSn"` EndTime string `json:"endTime"` // 升级时间 - 北京时间 Result string `json:"result"` // 升级结果 DetailList []BatchDownloadUpdateLogAHubVersionInfo `json:"detailList"` } // ==================== BatchDownload 结构化结果单元 ==================== // ItemStatus 单个下载工作单元的状态 type ItemStatus = string const ( ItemPending ItemStatus = "pending" // 待处理 ItemSuccess ItemStatus = "success" // 成功 ItemFailed ItemStatus = "failed" // 失败 ItemSkipped ItemStatus = "skipped" // 无满足条件的数据,非错误 ) // item 失败发生的阶段 const ( StageBuild = "build" // 构建期(查可召唤列表/站点信息、入队等) StageQuery = "query" // 查询数据 StageCall = "call" // 召唤 StagePoll = "poll" // 轮询召唤结果 StageDownload = "download" // 下载文件 StageSave = "save" // 保存/写库 ) // BatchDownloadItem 是批量下载中的一个最小工作单元的结构化结果 type BatchDownloadItem struct { Key string `bson:"key" json:"key"` // 唯一键 fileType|sn|devType|date|subType Sn string `bson:"sn" json:"sn"` // 归属 SN DevType int `bson:"devType" json:"devType"` // -1 表示不涉及设备类型 FileType string `bson:"fileType" json:"fileType"` SubType string `bson:"subType" json:"subType"` // logType / indexList / "" Date string `bson:"date" json:"date"` Status ItemStatus `bson:"status" json:"status"` Stage string `bson:"stage" json:"stage"` // 失败发生的阶段 Reason string `bson:"reason" json:"reason"` // 失败补充文本 UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` } // BuildItemKey 生成 item 唯一键。主任务构建与子任务上报必须使用同一套规则。 func BuildItemKey(fileType, sn string, devType int, date, subType string) string { return fmt.Sprintf("%s|%s|%d|%s|%s", fileType, sn, devType, date, subType) }