70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
|
|
import type { SteadyDataView } from '@/api/steady/steadyDataView/interface'
|
||
|
|
import { buildTimePeriodRange, type TimePeriodUnit } from '@/views/components/TimePeriodSearch/timePeriod'
|
||
|
|
|
||
|
|
export interface ChecksquareFormState {
|
||
|
|
timeRange: string[]
|
||
|
|
timeUnit: TimePeriodUnit
|
||
|
|
timeBaseDate: Date
|
||
|
|
}
|
||
|
|
|
||
|
|
export const defaultChecksquareFormState = (): ChecksquareFormState => {
|
||
|
|
const baseDate = new Date()
|
||
|
|
|
||
|
|
return {
|
||
|
|
timeRange: buildTimePeriodRange('day', baseDate),
|
||
|
|
timeUnit: 'day',
|
||
|
|
timeBaseDate: baseDate
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const padTimeValue = (value: number) => `${value}`.padStart(2, '0')
|
||
|
|
|
||
|
|
export const formatChecksquareTime = (date: Date) => {
|
||
|
|
return `${date.getFullYear()}-${padTimeValue(date.getMonth() + 1)}-${padTimeValue(date.getDate())} ${padTimeValue(
|
||
|
|
date.getHours()
|
||
|
|
)}:${padTimeValue(date.getMinutes())}:${padTimeValue(date.getSeconds())}`
|
||
|
|
}
|
||
|
|
|
||
|
|
export const collectChecksquareIndicatorCodes = (indicators: SteadyDataView.SteadyIndicatorNode[]) => {
|
||
|
|
return Array.from(new Set(indicators.map(item => item.indicatorCode).filter(Boolean))) as string[]
|
||
|
|
}
|
||
|
|
|
||
|
|
export const buildSteadyChecksquarePayload = (
|
||
|
|
lineId: string,
|
||
|
|
indicators: SteadyDataView.SteadyIndicatorNode[],
|
||
|
|
formState: ChecksquareFormState,
|
||
|
|
harmonicOrder?: number
|
||
|
|
): SteadyDataView.SteadyChecksquareQueryParams => {
|
||
|
|
const payload: SteadyDataView.SteadyChecksquareQueryParams = {
|
||
|
|
lineId,
|
||
|
|
indicatorCodes: collectChecksquareIndicatorCodes(indicators),
|
||
|
|
timeStart: (formState.timeRange[0] || '').replace(/\.[^.]+$/, ''),
|
||
|
|
timeEnd: (formState.timeRange[1] || '').replace(/\.[^.]+$/, '')
|
||
|
|
}
|
||
|
|
|
||
|
|
if (harmonicOrder) {
|
||
|
|
payload.harmonicOrders = [harmonicOrder]
|
||
|
|
}
|
||
|
|
|
||
|
|
return payload
|
||
|
|
}
|
||
|
|
|
||
|
|
export const validateChecksquareSelection = (params: {
|
||
|
|
lineIds: string[]
|
||
|
|
indicators: SteadyDataView.SteadyIndicatorNode[]
|
||
|
|
timeRange: string[]
|
||
|
|
}) => {
|
||
|
|
const { lineIds, indicators, timeRange } = params
|
||
|
|
|
||
|
|
if (!lineIds.length) return '请选择监测点'
|
||
|
|
if (lineIds.length > 1) return '数据校验一次只能选择一个监测点'
|
||
|
|
if (!indicators.length) return '请选择指标'
|
||
|
|
if (!timeRange[0]) return '请选择开始时间'
|
||
|
|
if (!timeRange[1]) return '请选择结束时间'
|
||
|
|
if (Date.parse(timeRange[0].replace(' ', 'T')) > Date.parse(timeRange[1].replace(' ', 'T'))) {
|
||
|
|
return '开始时间不能大于结束时间'
|
||
|
|
}
|
||
|
|
|
||
|
|
return ''
|
||
|
|
}
|