xieb
2023-09-13 3667807a7b7418efc090ee3fa6a6b734bc3080bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import request, { IWorkspaceResponse, IListWorkspaceResponse } from '/@/api/http/request'
import { DeviceValue, DOMAIN } from '/@/types/device'
import { DeviceLogUploadStatusEnum } from '/@/types/device-log'
import { ELocalStorageKey } from '/@/types'
import { CURRENT_CONFIG } from '/@/api/http/config'
 
const MNG_API_PREFIX = '/manage/api/v1'
 
const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || ''
 
export interface GetDeviceUploadLogListParams {
  device_sn: string,
  page: number,
  page_size: number,
  begin_time?: number, // 开始时间
  end_time?: number, // 结束时间
  status?: DeviceLogUploadStatusEnum, // 日志上传状态
  logs_information?: string // 搜索内容
}
 
export interface BriefDeviceInfo {
  sn: string,
  device_model: DeviceValue,
  device_callsign: string
}
 
export interface DeviceLogProgressInfo{
  device_sn: string,
  device_model_domain: DOMAIN,
  progress: number, // 进度
  result: number, // 上传结果
  upload_rate: number, // 上传速率
  status: DeviceLogUploadStatusEnum // 上传状态
}
 
export interface DeviceLogItem {
  boot_index: number, // 日志id
  start_time: number, // 日志开始时间
  end_time: number, // 日志结束时间
  size: number // 日志大小
}
 
export interface DeviceLogFileInfo {
  device_sn: string,
  module: DOMAIN,
  result: number,
  object_key: string,
  file_id: string,
  list: DeviceLogItem[]
}
 
export interface DeviceLogFileListInfo {
  files: DeviceLogFileInfo[]
}
 
export interface GetDeviceUploadLogListRsp {
  logs_id: string, // 记录id
  happen_time: string, // 发生时间
  user_name: string, // 用户
  logs_information: string, // 异常描述
  create_time: string, // 上传时间
  status:DeviceLogUploadStatusEnum, // 日志上传状态
  device_topo:{ // 设备topo
    hosts: BriefDeviceInfo[],
    parents: BriefDeviceInfo[]
  },
  logs_progress: DeviceLogProgressInfo[], // 日志上传进度
  device_logs: DeviceLogFileListInfo // 设备日志
}
 
/**
 * 获取设备上传日志列表信息
 * @param params
 * @returns
 */
export async function getDeviceUploadLogList (params: GetDeviceUploadLogListParams): Promise<IListWorkspaceResponse<GetDeviceUploadLogListRsp>> {
  const resp = await request.get(`${MNG_API_PREFIX}/workspaces/${workspaceId}/devices/${params.device_sn}/logs-uploaded`, {
    params: params
  })
  return resp.data
}
 
export interface GetDeviceLogListParams{
  device_sn: string,
  domain: DOMAIN[]
}
 
/**
 * 获取设备日志列表信息
 * @param params
 * @returns
 */
export async function getDeviceLogList (params: GetDeviceLogListParams): Promise<IWorkspaceResponse<DeviceLogFileListInfo>> {
  const domain = params.domain ? params.domain : []
  const resp = await request.get(`${MNG_API_PREFIX}/workspaces/${workspaceId}/devices/${params.device_sn}/logs`, {
    params: {
      domain_list: domain.join(',')
    }
  })
  return resp.data
}
 
export interface UploadDeviceLogBody {
  device_sn: string
  happen_time: string // 发生时间
  logs_information: string // 异常描述
  files:{
    list: DeviceLogItem[],
    device_sn: string,
    module: DOMAIN
  }[]
}
 
/**
 * 上传设备日志
 * @param body
 * @returns
 */
export async function postDeviceUpgrade (body: UploadDeviceLogBody): Promise<IWorkspaceResponse<{}>> {
  const resp = await request.post(`${MNG_API_PREFIX}/workspaces/${workspaceId}/devices/${body.device_sn}/logs`, body)
  return resp.data
}
 
export type DeviceLogUploadAction = 'cancel'
 
export interface CancelDeviceLogUploadBody {
  device_sn: string
  status: DeviceLogUploadAction
  module_list: DOMAIN[]
}
 
// 取消上传
export async function cancelDeviceLogUpload (body: CancelDeviceLogUploadBody): Promise<IWorkspaceResponse<{}>> {
  const url = `${MNG_API_PREFIX}/workspaces/${workspaceId}/devices/${body.device_sn}/logs`
  const result = await request.delete(url, {
    data: body
  })
  return result.data
}
 
export interface DeleteDeviceLogUploadBody {
  device_sn: string
  logs_id: string
}
 
// 取消上传
export async function deleteDeviceLogUpload (body: DeleteDeviceLogUploadBody): Promise<IWorkspaceResponse<{}>> {
  const url = `${MNG_API_PREFIX}/workspaces/${workspaceId}/devices/${body.device_sn}/logs/${body.logs_id}`
  const result = await request.delete(url, {
    data: body
  })
  return result.data
}
 
export interface GetUploadDeviceLogUrlParams{
  logs_id: string,
  file_id: string,
}
 
// export interface GetUploadDeviceLogRsp{
//   url: string
// }
 
/**
 * 获取设备上传日志url
 * @param params
 * @returns
 */
export async function getUploadDeviceLogUrl (params: GetUploadDeviceLogUrlParams): Promise<IWorkspaceResponse<string>> {
  const resp = await request.get(`${MNG_API_PREFIX}/workspaces/${workspaceId}/logs/${params.logs_id}/url/${params.file_id}`)
  return resp.data
}