diff --git a/src/modules/statistics/actions/index.ts b/src/modules/statistics/actions/index.ts index 50a2e4a1..470ea215 100644 --- a/src/modules/statistics/actions/index.ts +++ b/src/modules/statistics/actions/index.ts @@ -15,6 +15,18 @@ const FLIGHT_STCS_SEARCH_SUCCESS = const FLIGHT_STCS_SEARCH_FAILURE = 'statistics/flight/FLIGHT_STCS_SEARCH_FAILURE'; +// 비정상상황 통계 (비행경로이탈, 비정상고도, 충돌위험) +const ABNORMAL_STCS_REQUEST = 'statistics/flight/ABNORMAL_STCS_REQUEST'; +const ABNORMAL_STCS_SUCCESS = 'statistics/flight/ABNORMAL_STCS_SUCCESS'; +const ABNORMAL_STCS_FAILURE = 'statistics/flight/ABNORMAL_STCS_FAILURE'; + +// 비정상상황 통계 카테고리별 검색 +const ABNORMAL_STCS_SEARCH_REQUEST = 'statistics/ABNORMAL_STCS_SEARCH_REQUEST'; +const ABNORMAL_STCS_SEARCH_SUCCESS = + 'statistics/flight/ABNORMAL_STCS_SEARCH_SUCCESS'; +const ABNORMAL_STCS_SEARCH_FAILURE = + 'statistics/flight/ABNORMAL_STCS_SEARCH_FAILURE'; + // 비행 실적 통계 (비행실적, 비행계획, 비행승인) const RESULT_STCS_REQUEST = 'statistics/flight/RESULT_STCS_REQUEST'; const RESULT_STCS_SUCCESS = 'statistics/flight/RESULT_STCS_SUCCESS'; @@ -39,6 +51,18 @@ export const FLIGHT_STCS_SEARCH = createAsyncAction( FLIGHT_STCS_SEARCH_FAILURE )(); +export const ABNORMAL_STCS = createAsyncAction( + ABNORMAL_STCS_REQUEST, + ABNORMAL_STCS_SUCCESS, + ABNORMAL_STCS_FAILURE +)(); + +export const ABNORMAL_STCS_SEARCH = createAsyncAction( + ABNORMAL_STCS_SEARCH_REQUEST, + ABNORMAL_STCS_SEARCH_SUCCESS, + ABNORMAL_STCS_SEARCH_FAILURE +)(); + export const RESULT_STCS = createAsyncAction( RESULT_STCS_REQUEST, RESULT_STCS_SUCCESS, @@ -54,6 +78,8 @@ export const RESULT_STCS_SEARCH = createAsyncAction( const actions = { FLIGHT_STCS, FLIGHT_STCS_SEARCH, + ABNORMAL_STCS, + ABNORMAL_STCS_SEARCH, RESULT_STCS, RESULT_STCS_SEARCH }; diff --git a/src/modules/statistics/apis/index.ts b/src/modules/statistics/apis/index.ts index 51198792..5284ea62 100644 --- a/src/modules/statistics/apis/index.ts +++ b/src/modules/statistics/apis/index.ts @@ -21,6 +21,24 @@ export const statisticsAPI = { return await axios.get(`api/main/statistics/flight/${type}${queryString}`); }, + abnormal: async () => { + return await axios.get('/api/main/statistics/warn-static'); + }, + abnormalSearch: async (data: IStcsSearchRq) => { + const { type } = data; + const params = {}; + Object.keys(data).forEach(i => { + if (data[i] && i !== 'type') { + params[`${i}`] = data[i]; + } + }); + const queryString = qs.stringify(params, { + addQueryPrefix: true, + arrayFormat: 'repeat' + }); + + return await axios.get(`api/main/statistics/warn/${type}${queryString}`); + }, result: async () => { return await axios.get('/api/main/statistics/flight/result-static'); }, diff --git a/src/modules/statistics/models/index.ts b/src/modules/statistics/models/index.ts index 5d90bb1c..81fd2194 100644 --- a/src/modules/statistics/models/index.ts +++ b/src/modules/statistics/models/index.ts @@ -1,6 +1,8 @@ export interface IStatisticsState { flight: IStcsRs[]; flightSearch: IStcsSearchRs; + abnormal: IStcsRs[]; + abnormalSearch: IStcsSearchRs; result: IStcsRs[]; resultSearch: IStcsSearchRs; } @@ -33,6 +35,11 @@ export const initialState = { graphData: [], topData: [] }, + abnormal: [], + abnormalSearch: { + graphData: [], + topData: [] + }, result: [], resultSearch: { graphData: [], diff --git a/src/modules/statistics/reducers/index.ts b/src/modules/statistics/reducers/index.ts index 8db03e20..25c36cf6 100644 --- a/src/modules/statistics/reducers/index.ts +++ b/src/modules/statistics/reducers/index.ts @@ -14,7 +14,6 @@ export const statisticsReducer = createReducer< draft.flight = data || state.flight; }) ) - // 비행 통계 카테고리별 검색 .handleAction(Actions.FLIGHT_STCS_SEARCH.success, (state, action) => produce(state, draft => { @@ -23,6 +22,21 @@ export const statisticsReducer = createReducer< }) ) + // 비정상상황 통계 (비행경로이탈, 비정상고도, 충돌위험) + .handleAction(Actions.ABNORMAL_STCS.success, (state, action) => + produce(state, draft => { + const data = action.payload; + draft.abnormal = data || state.abnormal; + }) + ) + // 비정상상황 통계 카테고리별 검색 + .handleAction(Actions.ABNORMAL_STCS_SEARCH.success, (state, action) => + produce(state, draft => { + const data = action.payload; + draft.abnormalSearch = data || state.abnormalSearch; + }) + ) + // 비행 실적 통계 (비행실적, 비행계획, 비행승인) .handleAction(Actions.RESULT_STCS.success, (state, action) => produce(state, draft => { @@ -30,7 +44,6 @@ export const statisticsReducer = createReducer< draft.result = data || state.result; }) ) - // 비행 실적 통계 카테고리별 검색 .handleAction(Actions.RESULT_STCS_SEARCH.success, (state, action) => produce(state, draft => { diff --git a/src/modules/statistics/sagas/index.ts b/src/modules/statistics/sagas/index.ts index d03a88b1..ba428843 100644 --- a/src/modules/statistics/sagas/index.ts +++ b/src/modules/statistics/sagas/index.ts @@ -58,6 +58,60 @@ function* flightStcsSearchSaga( } } +function* abnormalStcsSaga( + action: ActionType +) { + try { + const payload = action.payload; + const res = yield call(Apis.statisticsAPI.abnormal); + const { data, errorCode } = res; + + if (errorCode) { + // 오류메시지 호출 + yield put( + MessageActions.IS_ERROR({ + errorCode: errorCode, + errorMessage: '처리중 오류가 발생하였습니다', + isHistoryBack: false, + isRefresh: false + }) + ); + + return; + } + yield put(Actions.ABNORMAL_STCS.success(data)); + } catch (error) { + yield put(Actions.ABNORMAL_STCS.failure(error)); + } +} + +function* abnormalStcsSearchSaga( + action: ActionType +) { + try { + const payload = action.payload; + const res = yield call(Apis.statisticsAPI.abnormalSearch, payload); + const { data, errorCode } = res; + + if (errorCode) { + // 오류메시지 호출 + yield put( + MessageActions.IS_ERROR({ + errorCode: errorCode, + errorMessage: '처리중 오류가 발생하였습니다', + isHistoryBack: false, + isRefresh: false + }) + ); + + return; + } + yield put(Actions.ABNORMAL_STCS_SEARCH.success(data)); + } catch (error) { + yield put(Actions.ABNORMAL_STCS_SEARCH.failure(error)); + } +} + function* resultStcsSaga( action: ActionType ) { @@ -115,6 +169,8 @@ function* resultStcsSearchSaga( export function* statisticsSaga() { yield takeEvery(Actions.FLIGHT_STCS.request, flightStcsSaga); yield takeEvery(Actions.FLIGHT_STCS_SEARCH.request, flightStcsSearchSaga); + yield takeEvery(Actions.ABNORMAL_STCS.request, abnormalStcsSaga); + yield takeEvery(Actions.ABNORMAL_STCS_SEARCH.request, abnormalStcsSearchSaga); yield takeEvery(Actions.RESULT_STCS.request, resultStcsSaga); yield takeEvery(Actions.RESULT_STCS_SEARCH.request, resultStcsSearchSaga); }