김장현
7 months ago
7 changed files with 329 additions and 26 deletions
@ -0,0 +1,41 @@
|
||||
import { createSlice } from '@reduxjs/toolkit'; |
||||
import { initMainDash } from './dashboardState'; |
||||
import { |
||||
getStcsAreaList, |
||||
getStcsDayList, |
||||
getAllDashboardData, |
||||
getDronOperationList |
||||
} from './dashboardThunk'; |
||||
import { |
||||
IStcsDayListRs, |
||||
IStcsAreaListRs, |
||||
IDashBoardDataRs, |
||||
IDronOperationListRs |
||||
} from './dashboardState'; |
||||
|
||||
const dashboardSlice = createSlice({ |
||||
name: 'dashboardSlice', |
||||
initialState: initMainDash, |
||||
reducers: {}, |
||||
extraReducers: builder => { |
||||
builder |
||||
.addCase(getStcsDayList.fulfilled, (state, action) => { |
||||
const data = action.payload as IStcsDayListRs[]; |
||||
state.stcsDayListRs = data; |
||||
}) |
||||
.addCase(getStcsAreaList.fulfilled, (state, action) => { |
||||
const data = action.payload as IStcsAreaListRs[]; |
||||
state.stcsAreaListRs = data; |
||||
}) |
||||
.addCase(getAllDashboardData.fulfilled, (state, action) => { |
||||
const data = action.payload as IDashBoardDataRs; |
||||
state.dashboardDataRs = { ...data }; |
||||
}) |
||||
.addCase(getDronOperationList.fulfilled, (state, action) => { |
||||
const data = action.payload as IDronOperationListRs[]; |
||||
state.dronOperationListRs = data; |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
export const dashboardReducer = dashboardSlice.reducer; |
@ -0,0 +1,100 @@
|
||||
export const initMainDash: MainDashState = { |
||||
stcsDayListRs: [], |
||||
stcsAreaListRs: [], |
||||
dashboardDataRs: { |
||||
dailyFlightWarn: [], |
||||
dailyFlightCount: [], |
||||
dailyFlightPlan: [], |
||||
dronSituation: [] |
||||
}, |
||||
dronOperationListRs: [] |
||||
}; |
||||
|
||||
export enum EDateType { |
||||
yesterday = '전일', |
||||
today = '금일', |
||||
tomorrow = '명일' |
||||
} |
||||
|
||||
export enum EDronStatus { |
||||
inFlight = '비행 중', |
||||
flightComplete = '비행 완료', |
||||
flightWaiting = '비행 대기 중 ' |
||||
} |
||||
|
||||
export interface MainDashState { |
||||
stcsDayListRs: IStcsDayListRs[]; |
||||
stcsAreaListRs: IStcsAreaListRs[]; |
||||
dashboardDataRs: IDashBoardDataRs; |
||||
dronOperationListRs: IDronOperationListRs[]; |
||||
} |
||||
|
||||
export interface IDronOperationListRs { |
||||
groupNm: string; |
||||
memberName: string; |
||||
idntfNum: string; |
||||
cntrlStDt: string; |
||||
cntrlEndDt: string; |
||||
totalFlightTime: string; |
||||
status: string; |
||||
} |
||||
|
||||
export interface IDronSituationRs { |
||||
typeCd: string; |
||||
count: number; |
||||
} |
||||
|
||||
export interface IDailyFlightPlanRs { |
||||
dateType: string; |
||||
plan: number; |
||||
aprvn: number; |
||||
count: number; |
||||
note: number; |
||||
} |
||||
export interface IDailyFlightWarnRs { |
||||
dateType: string; |
||||
plan: number; |
||||
altitude: number; |
||||
crash: number; |
||||
count: number; |
||||
note: number; |
||||
} |
||||
|
||||
export interface IDailyFlightCountRs { |
||||
dateType: string; |
||||
flightPlan: number; |
||||
completeFlight: number; |
||||
notFlight: number; |
||||
note: number; |
||||
} |
||||
|
||||
export interface IStcsDayListRs { |
||||
typeCd: string; |
||||
count: number; |
||||
} |
||||
|
||||
export interface IStcsAreaListRs { |
||||
typeCd: string; |
||||
count: number; |
||||
} |
||||
|
||||
export interface GroupListData { |
||||
groupNm: string; |
||||
groupId: string; |
||||
joinDt: Date; |
||||
createDt: Date; |
||||
} |
||||
|
||||
export interface DronListData { |
||||
arcrftModelNm: string; |
||||
prdctNum: string; |
||||
createDt: Date; |
||||
groupNm: string; |
||||
} |
||||
|
||||
export interface IDashBoardDataRs { |
||||
dailyFlightWarn: IDailyFlightWarnRs[]; |
||||
dailyFlightCount: IDailyFlightCountRs[]; |
||||
dailyFlightPlan: IDailyFlightPlanRs[]; |
||||
dronSituation: IDronSituationRs[]; |
||||
} |
@ -0,0 +1,162 @@
|
||||
import { createAsyncThunk } from '@reduxjs/toolkit'; |
||||
import qs from 'qs'; |
||||
import axios from '../../../modules/utils/customAxiosUtil'; |
||||
import { isError } from '../comn/message/messageSlice'; |
||||
import { ERROR_MESSAGE } from '@src/configs/constants'; |
||||
import { |
||||
EDronStatus, |
||||
IStcsDayListRs, |
||||
IStcsAreaListRs, |
||||
IDashBoardDataRs, |
||||
IDronSituationRs, |
||||
IDronOperationListRs |
||||
} from './dashboardState'; |
||||
|
||||
// 일 별 비행횟수 통계 날짜 리스트
|
||||
export const getStcsDayList = createAsyncThunk( |
||||
'dashboard/getStcsDayList', |
||||
async (rq: string, thunkAPI) => { |
||||
try { |
||||
const queryString = qs.stringify(rq, { |
||||
addQueryPrefix: true, |
||||
arrayFormat: 'repeat' |
||||
}); |
||||
|
||||
const { data, errorCode }: { data: IStcsDayListRs[]; errorCode: string } = |
||||
await axios.get(`api/main/dash/stcs/day${queryString}`); |
||||
|
||||
if (errorCode) { |
||||
throw new Error(errorCode); |
||||
} |
||||
|
||||
return data; |
||||
} catch (error) { |
||||
thunkAPI.dispatch( |
||||
isError({ |
||||
errorCode: ERROR_MESSAGE, |
||||
errorMessage: '처리중 오류가 발생하였습니다', |
||||
isHistoryBack: false, |
||||
isRefresh: false |
||||
}) |
||||
); |
||||
} |
||||
} |
||||
); |
||||
|
||||
// top5 지역 별 비행횟수 통계 리스트
|
||||
export const getStcsAreaList = createAsyncThunk( |
||||
'dashboard/getStcsAreaList', |
||||
async (rq: string, thunkAPI) => { |
||||
try { |
||||
const queryString = qs.stringify(rq, { |
||||
addQueryPrefix: true, |
||||
arrayFormat: 'repeat' |
||||
}); |
||||
|
||||
const { |
||||
data, |
||||
errorCode |
||||
}: { data: IStcsAreaListRs[]; errorCode: string } = await axios.get( |
||||
`api/main/dash/stcs/area${queryString}` |
||||
); |
||||
|
||||
if (errorCode) { |
||||
throw new Error(errorCode); |
||||
} |
||||
|
||||
return data; |
||||
} catch (error) { |
||||
thunkAPI.dispatch( |
||||
isError({ |
||||
errorCode: ERROR_MESSAGE, |
||||
errorMessage: '처리중 오류가 발생하였습니다', |
||||
isHistoryBack: false, |
||||
isRefresh: false |
||||
}) |
||||
); |
||||
} |
||||
} |
||||
); |
||||
|
||||
// 일일 비행계획 현황, 일일 비행건수 현황, 일일 비정상상황 현황 Promise.all 처리
|
||||
export const getAllDashboardData = createAsyncThunk( |
||||
'dashboard/getAllDashboardData', |
||||
async (_, thunkAPI) => { |
||||
try { |
||||
const allDashboardApi = [ |
||||
'api/main/dash/current/flight-warn', |
||||
'api/main/dash/current/flight-plan', |
||||
'api/main/dash/stcs/dailyflight', |
||||
'api/main/dash/stcs/dron-flight' |
||||
]; |
||||
|
||||
const promise = allDashboardApi.map(api => axios.get(api)); |
||||
|
||||
const res = await Promise.all(promise); |
||||
|
||||
let errorCode = res.filter(i => i.hasOwnProperty('errorCode')); |
||||
if (errorCode.length > 0) { |
||||
throw new Error(); |
||||
} |
||||
|
||||
let dronSituationArr: IDronSituationRs[] = []; |
||||
|
||||
if (res[3].data) { |
||||
Object.keys(res[3].data).forEach(i => { |
||||
dronSituationArr.push({ |
||||
typeCd: EDronStatus[`${i}`], |
||||
count: Number(res[3].data[i]) |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
const data: IDashBoardDataRs = { |
||||
dailyFlightWarn: res[0].data.slice(0, res[0].data.length - 1), |
||||
dailyFlightPlan: res[1].data, |
||||
dailyFlightCount: res[2].data, |
||||
dronSituation: dronSituationArr |
||||
}; |
||||
|
||||
return data; |
||||
} catch (error) { |
||||
thunkAPI.dispatch( |
||||
isError({ |
||||
errorCode: ERROR_MESSAGE, |
||||
errorMessage: '처리중 오류가 발생하였습니다', |
||||
isHistoryBack: false, |
||||
isRefresh: false |
||||
}) |
||||
); |
||||
} |
||||
} |
||||
); |
||||
|
||||
// 드론 별 비행운항 목록 리스트
|
||||
export const getDronOperationList = createAsyncThunk( |
||||
'dashboard/getDronOperationList', |
||||
async (rq: string, thunkAPI) => { |
||||
try { |
||||
const { |
||||
data, |
||||
errorCode |
||||
}: { data: IDronOperationListRs[]; errorCode: string } = await axios.get( |
||||
`api/main/dash/dron-flight/list?serviceType=${rq}` |
||||
); |
||||
|
||||
if (errorCode) { |
||||
throw new Error(errorCode); |
||||
} |
||||
|
||||
return data; |
||||
} catch (error) { |
||||
thunkAPI.dispatch( |
||||
isError({ |
||||
errorCode: ERROR_MESSAGE, |
||||
errorMessage: '처리중 오류가 발생하였습니다', |
||||
isHistoryBack: false, |
||||
isRefresh: false |
||||
}) |
||||
); |
||||
} |
||||
} |
||||
); |
Loading…
Reference in new issue