batchDownloadDomain.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package domain
  2. import (
  3. "fmt"
  4. "time"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. )
  7. type BatchDownloadInfo struct {
  8. Id primitive.ObjectID `bson:"_id" json:"id"`
  9. Sn []string `bson:"sn" json:"sn"`
  10. Description string `bson:"description" json:"description"`
  11. TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"`
  12. Options BatchDownloadOptions `bson:"options" json:"options"`
  13. Progress Progress `bson:"progress" json:"progress"`
  14. FailReasons []string `bson:"failReasons" json:"failReasons"`
  15. Items []BatchDownloadItem `bson:"items" json:"items"`
  16. TotalCount int `bson:"totalCount" json:"totalCount"`
  17. DoneCount int `bson:"doneCount" json:"doneCount"`
  18. Owner *[]string `bson:"owner,omitempty" json:"owner,omitempty"`
  19. }
  20. type BatchDownloadOptions struct {
  21. PowerFlow bool `bson:"powerFlow" json:"powerFlow"` // 功率流图
  22. MqttLogs []string `bson:"mqttLogs" json:"mqttLogs"` // MQTT日志
  23. EventAlarm bool `bson:"eventAlarm" json:"eventAlarm"` // 事件和告警日志
  24. AlarmSnapshot bool `bson:"alarmSnapshot" json:"alarmSnapshot"` // 告警快照
  25. EmsLogs []string `bson:"emsLogs" json:"emsLogs"` // EMS日志
  26. FaultRecord bool `bson:"faultRecord" json:"faultRecord"` // 故障录波
  27. UpdateLog bool `bson:"updateLog" json:"updateLog"` // 升级记录
  28. Settings bool `bson:"settings" json:"settings"` // 站点设置
  29. }
  30. type BatchDownloadConfigWrite struct {
  31. Sn []string `bson:"sn" json:"sn"`
  32. Description string `bson:"description" json:"description"`
  33. TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"`
  34. Options BatchDownloadOptions `bson:"options"`
  35. Owner *[]string `bson:"owner,omitempty" json:"owner,omitempty"`
  36. }
  37. type BatchDownloadConfig struct {
  38. Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
  39. Sn []string `bson:"sn" json:"sn"`
  40. Description string `bson:"description" json:"description"`
  41. TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"`
  42. Options BatchDownloadOptions `bson:"options"`
  43. Progress Progress `bson:"progress" json:"progress"`
  44. Data map[string]BatchDownloadData `bson:"data" json:"data"` // map-key为SN
  45. FailReasons []string `bson:"failReasons" json:"failReasons"`
  46. Items []BatchDownloadItem `bson:"items" json:"items"`
  47. TotalCount int `bson:"totalCount" json:"totalCount"`
  48. DoneCount int `bson:"doneCount" json:"doneCount"`
  49. Owner *[]string `bson:"owner,omitempty" json:"owner,omitempty"`
  50. }
  51. type TaskBatchDownload struct {
  52. Id primitive.ObjectID `bson:"_id" json:"id"`
  53. Sn []string `bson:"sn" json:"sn"`
  54. TimePeriod [2]string `bson:"timePeriod" json:"timePeriod"`
  55. Options BatchDownloadOptions `bson:"options"`
  56. }
  57. // 数据说明
  58. // map的key为日期,格式为 YYYY-MM-DD
  59. // MqttLogs和EmsLogs的二级map为日志类型名称
  60. // 存储的最终数据是文件服务器(minio)的存储路径
  61. type BatchDownloadData struct {
  62. PowerFlow *map[string]string `bson:"powerFlow,omitempty" json:"powerFlow,omitempty"` // 功率流图
  63. MqttLogs *map[string]map[string]string `bson:"mqttLogs,omitempty" json:"mqttLogs,omitempty"` // MQTT日志
  64. EventAlarm *map[string]string `bson:"eventAlarm,omitempty" json:"eventAlarm,omitempty"` // 事件和告警日志
  65. AlarmSnapshot *map[string]string `bson:"alarmSnapshot,omitempty" json:"alarmSnapshot,omitempty"` // 告警快照
  66. EmsLogs *map[string]map[string]string `bson:"emsLogs,omitempty" json:"emsLogs,omitempty"` // EMS日志
  67. FaultRecord *map[string]string `bson:"faultRecord,omitempty" json:"faultRecord,omitempty"` // 故障录波 map的key为文件名
  68. UpdateLog *string `bson:"updateLog,omitempty" json:"updateLog,omitempty"` // 升级记录
  69. Settings *string `bson:"settings,omitempty" json:"settings,omitempty"` // 站点设置
  70. }
  71. // 下载任务数据 (保存于redis数据库)
  72. type BatchDownloadFileTaskInfo struct {
  73. DevType int `bson:"devType" json:"devType"` // 设备类型:-1-忽略 0-aPower-PE 1-aGate/MCA 2-aPower-MPPT 3-aHub
  74. Sn string `bson:"sn" json:"sn"`
  75. Date string `bson:"date" json:"date"`
  76. FileType string `bson:"fileType" json:"fileType"`
  77. FileSupType string `bson:"fileSubType" json:"fileSubType"`
  78. Result int `bson:"result" json:"result"` // -1-失败 0-进行中 1-成功
  79. Reason string `bson:"reason" json:"reason"` // 失败原因
  80. }
  81. type BatchDownloadUpdateLogVersionInfo struct {
  82. Name string `json:"name"` // 名称
  83. OldVer string `json:"oldVer"`
  84. NewVer string `json:"newVer"`
  85. }
  86. type BatchDownloadUpdateLogSubDevInfo struct {
  87. DevSn string `json:"devSn"`
  88. DevVerList []BatchDownloadUpdateLogVersionInfo `json:"devVerList"`
  89. }
  90. type BatchDownloadUpdateLogAHubVersionInfo struct {
  91. FileName string `json:"fileName"` // 文件名称
  92. FileOrder string `json:"fileOrder"` // 文件单号
  93. Result string `json:"result"` // 升级结果 "0"-成功
  94. ResultDesc string `json:"resultDesc"` // 升级结果说明
  95. OldVer string `json:"oldVer"`
  96. NewVer string `json:"newVer"`
  97. }
  98. // 系统升级日志信息数据
  99. type BatchDownloadSystemUpdateLogInfo struct {
  100. OrderNo string `json:"orderNo"` // 升级工单号
  101. TriggerType string `json:"triggerType"` // 触发类型 自动 or 手动
  102. GateSn string `json:"gateSn"`
  103. FileName string `json:"fileName"` // 升级包名
  104. UpdateTime string `json:"updateTime"` // 触发升级时间 - 北京时间
  105. Result string `json:"result"` // 升级结果
  106. GateVerList []BatchDownloadUpdateLogVersionInfo `json:"gateVerList"`
  107. SubDevList []BatchDownloadUpdateLogSubDevInfo `json:"subVerList"`
  108. }
  109. // aHub升级日志信息数据
  110. type BatchDownloadAHubUpdateLogInfo struct {
  111. OrderNo string `json:"orderNo"` // 升级工单号
  112. TriggerType string `json:"triggerType"` // 触发类型 自动 or 手动
  113. AHubSn string `json:"aHubSn"` // aHubSn
  114. GateSn string `json:"gateSn"`
  115. EndTime string `json:"endTime"` // 升级时间 - 北京时间
  116. Result string `json:"result"` // 升级结果
  117. DetailList []BatchDownloadUpdateLogAHubVersionInfo `json:"detailList"`
  118. }
  119. // ==================== BatchDownload 结构化结果单元 ====================
  120. // ItemStatus 单个下载工作单元的状态
  121. type ItemStatus = string
  122. const (
  123. ItemPending ItemStatus = "pending" // 待处理
  124. ItemSuccess ItemStatus = "success" // 成功
  125. ItemFailed ItemStatus = "failed" // 失败
  126. ItemSkipped ItemStatus = "skipped" // 无满足条件的数据,非错误
  127. )
  128. // item 失败发生的阶段
  129. const (
  130. StageBuild = "build" // 构建期(查可召唤列表/站点信息、入队等)
  131. StageQuery = "query" // 查询数据
  132. StageCall = "call" // 召唤
  133. StagePoll = "poll" // 轮询召唤结果
  134. StageDownload = "download" // 下载文件
  135. StageSave = "save" // 保存/写库
  136. )
  137. // BatchDownloadItem 是批量下载中的一个最小工作单元的结构化结果
  138. type BatchDownloadItem struct {
  139. Key string `bson:"key" json:"key"` // 唯一键 fileType|sn|devType|date|subType
  140. Sn string `bson:"sn" json:"sn"` // 归属 SN
  141. DevType int `bson:"devType" json:"devType"` // -1 表示不涉及设备类型
  142. FileType string `bson:"fileType" json:"fileType"`
  143. SubType string `bson:"subType" json:"subType"` // logType / indexList / ""
  144. Date string `bson:"date" json:"date"`
  145. Status ItemStatus `bson:"status" json:"status"`
  146. Stage string `bson:"stage" json:"stage"` // 失败发生的阶段
  147. Reason string `bson:"reason" json:"reason"` // 失败补充文本
  148. UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
  149. }
  150. // BuildItemKey 生成 item 唯一键。主任务构建与子任务上报必须使用同一套规则。
  151. func BuildItemKey(fileType, sn string, devType int, date, subType string) string {
  152. return fmt.Sprintf("%s|%s|%d|%s|%s", fileType, sn, devType, date, subType)
  153. }