123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import { Query } from '@/api/webApi'
- import { Ref } from 'vue'
- import { CommonData, CommonValue } from '~/common'
- export function useFlightState(
- name: string,
- tableData: Ref<CommonData[]>,
- finishedCount: Ref<number>
- ) {
- const warningRules = ref<CommonData[]>([])
- const getWarningRules = async () => {
- try {
- const {
- code,
- returnData: { listValues },
- message,
- } = await Query<CommonData>({
- id: DATACONTENT_ID.warningRules,
- dataContent: [],
- })
- if (Number(code) !== 0) {
- throw new Error(message || '失败')
- }
- warningRules.value = listValues
- } catch (error) {
- console.error(error)
- }
- }
- watch(tableData, data => {
- finishedCount.value = 0
- const now = Date.now()
- data.forEach(row => {
- if (
- name.includes('DepartureAirport') &&
- typeof row['planDepartureTime'] === 'string' &&
- row['planDepartureTime']
- ) {
- const departureTime = new Date(
- row.planDepartureTime.replace('T', ' ')
- ).getTime()
- // 判断已起飞
- if (now >= departureTime) {
- row.hasTakenOff = 'Y'
- if (
- name.includes('International') &&
- row['enterPark'] &&
- row['receiveSure1']
- ) {
- finishedCount.value++
- }
- if (!name.includes('International') && row['receiveSure']) {
- finishedCount.value++
- }
- } else {
- row.hasTakenOff = 'N'
- // 未起飞的匹配预警报警策略
- row.warningState = getWarningState(row)
- }
- }
- if (
- name.includes('International') &&
- !(['CA', 'ZH', 'CZ', 'O3', '5X', 'FX', 'DO'] as CommonValue[]).includes(
- row.IATACode
- )
- ) {
- row.groundService = 'Y'
- }
- if (name === 'ArrivalAirport') {
- if (
- (['ZH', 'CA', 'KY', 'SC'] as CommonValue[]).includes(row.IATACode)
- ) {
- row.groundServiceSZ = 'Y'
- } else {
- row.groundService = 'Y'
- }
- }
- if (
- name.includes('ArrivalAirport') &&
- typeof row.planLandingTime === 'string'
- ) {
- const landingTime = new Date(
- row.planLandingTime.replace('T', ' ')
- ).getTime()
- // 判断已降落
- if (now >= landingTime) {
- row.hasLanded = 'Y'
- if (row['unLoad'] && row['tally']) {
- finishedCount.value++
- }
- } else {
- row.hasLanded = 'N'
- }
- }
- })
- })
- const getWarningState = (flightData: CommonData) => {
- let warningState = ''
- if (
- typeof flightData.planDepartureTime !== 'string' ||
- typeof flightData.loadPlaneTime !== 'string'
- ) {
- return warningState
- }
- const now = Date.now()
- const departureTime = new Date(
- flightData.planDepartureTime.replace('T', ' ')
- ).getTime()
- const loadTime = new Date(
- flightData.loadPlaneTime.replace('T', ' ')
- ).getTime()
- const duration = departureTime - loadTime
- warningRules.value.some(
- ({
- startDate,
- endDate,
- IATACode,
- flightNO,
- warningDuration,
- alarmDuration,
- }) => {
- let startTime = 0,
- endTime = 0
- if (typeof startDate === 'string') {
- startTime = new Date(startDate.replace('T', ' ')).getTime()
- }
- if (typeof endDate === 'string') {
- endTime = new Date(endDate.replace('T', ' ')).getTime()
- }
- // 排除不在生效期内或是航司、航班号不匹配的策略
- if ((startTime && startTime > now) || (endTime && endTime < now)) {
- return false
- }
- if (IATACode && IATACode !== flightData.IATACode) {
- return false
- }
- if (flightNO && flightNO !== flightData.flightNO) {
- return false
- }
- if (typeof alarmDuration === 'number' && duration < alarmDuration) {
- warningState = 'alarm'
- return true
- }
- if (typeof warningDuration === 'number' && duration < warningDuration) {
- warningState = 'warning'
- return true
- }
- return false
- }
- )
- return warningState
- }
- return {
- warningRules,
- getWarningRules,
- }
- }
|