You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.3 KiB
147 lines
3.3 KiB
|
2 weeks ago
|
import { http } from "@/api/http";
|
||
|
|
import { ModuleTypeEnum, RequestHttpEnum } from "@/enums/httpEnum";
|
||
|
|
import { ProjectDetail } from "@/api/path/project";
|
||
|
|
import { getLocalStorage, httpErrorHandle } from "@/utils";
|
||
|
|
import { RequestDataSourceConfig } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||
|
|
import { StorageEnum } from "@/enums/storageEnum";
|
||
|
|
import { SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d'
|
||
|
|
import { SelectDataSourceTypeAPIObj } from "@/enums/dataSourceEnum";
|
||
|
|
|
||
|
|
/*
|
||
|
|
* 获取站点
|
||
|
|
*/
|
||
|
|
export const fetchDataSite = async (data: object) => {
|
||
|
|
try {
|
||
|
|
return await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-site`)
|
||
|
|
} catch {
|
||
|
|
httpErrorHandle()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
* 获取设备
|
||
|
|
* @param data {
|
||
|
|
* siteId // 站点
|
||
|
|
* }
|
||
|
|
*/
|
||
|
|
|
||
|
|
export const fetchDataDevice = async (data: object) => {
|
||
|
|
try {
|
||
|
|
return await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-entity`,data)
|
||
|
|
} catch {
|
||
|
|
httpErrorHandle()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
* 获取点位
|
||
|
|
* @param data {
|
||
|
|
* siteId // 站点
|
||
|
|
* entityId // 设备
|
||
|
|
* }
|
||
|
|
*/
|
||
|
|
export const fetchDataPoint = async (data: object) => {
|
||
|
|
try {
|
||
|
|
return await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-point`, data)
|
||
|
|
} catch {
|
||
|
|
httpErrorHandle()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// {
|
||
|
|
// "queryType": 2,
|
||
|
|
// "site": "53",
|
||
|
|
// "width": "1d",
|
||
|
|
// "tenantId": 169,
|
||
|
|
// "interval":"1h",
|
||
|
|
// "points":[]
|
||
|
|
// }
|
||
|
|
|
||
|
|
/*
|
||
|
|
* 收益参数
|
||
|
|
* @param params {
|
||
|
|
* queryType = 2
|
||
|
|
* siteId // 站点
|
||
|
|
* entityId // 设备
|
||
|
|
* width = 1d
|
||
|
|
* tenantId
|
||
|
|
* interval
|
||
|
|
* points = []
|
||
|
|
* }
|
||
|
|
*/
|
||
|
|
|
||
|
|
export async function test (){
|
||
|
|
// const params = {
|
||
|
|
// "queryType": 1,
|
||
|
|
// "site": 56,
|
||
|
|
// "with": 30,
|
||
|
|
// "deviceSn": 454,
|
||
|
|
// "points": [
|
||
|
|
// 4,
|
||
|
|
// 7
|
||
|
|
// ],
|
||
|
|
// "tenantId": 169
|
||
|
|
// }
|
||
|
|
|
||
|
|
const params = {
|
||
|
|
"queryType": 2,
|
||
|
|
"site": 56,
|
||
|
|
"with": "6h",
|
||
|
|
"interval": "20m",
|
||
|
|
"points": [],
|
||
|
|
"tenantId": 169
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
return await http(RequestHttpEnum.POST)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-by-iot`, params)
|
||
|
|
} catch {
|
||
|
|
httpErrorHandle()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPointParams(requestSource:RequestDataSourceConfig) {
|
||
|
|
let params:any = {
|
||
|
|
queryType: SelectDataSourceTypeAPIObj[requestSource.dataSourceType],
|
||
|
|
site: requestSource.station,
|
||
|
|
with: requestSource.recentTimeRange,
|
||
|
|
deviceSn: String(requestSource.device),
|
||
|
|
points: requestSource.points,
|
||
|
|
tenantId: getToken()
|
||
|
|
}
|
||
|
|
|
||
|
|
return params
|
||
|
|
}
|
||
|
|
|
||
|
|
function getEarningParams(requestSource:RequestDataSourceConfig){
|
||
|
|
let params: any = {
|
||
|
|
queryType: SelectDataSourceTypeAPIObj[requestSource.dataSourceType],
|
||
|
|
site:requestSource.station,
|
||
|
|
with: requestSource.recentTimeRange,
|
||
|
|
interval: '20m',
|
||
|
|
points: [],
|
||
|
|
tenantId: getToken()
|
||
|
|
}
|
||
|
|
|
||
|
|
return params
|
||
|
|
}
|
||
|
|
|
||
|
|
export const fetchDataByIot = async (requestSource:RequestDataSourceConfig) => {
|
||
|
|
let params:any = {}
|
||
|
|
if(requestSource.dataSourceType === 'point') {
|
||
|
|
params = getPointParams(requestSource)
|
||
|
|
} else if(requestSource.dataSourceType === 'earning') {
|
||
|
|
params = getEarningParams(requestSource)
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
return await http(RequestHttpEnum.POST)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-by-iot`, params)
|
||
|
|
} catch {
|
||
|
|
httpErrorHandle()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getToken() {
|
||
|
|
const info = getLocalStorage(StorageEnum.GO_SYSTEM_STORE)
|
||
|
|
return info ? info[SystemStoreEnum.TENANT_INFO]['tenantId'] : undefined
|
||
|
|
}
|