Browse Source

비정상상황 통계 api 작성

pull/2/head
hhjk00 10 months ago
parent
commit
dfcba2bdc0
  1. 26
      src/modules/statistics/actions/index.ts
  2. 18
      src/modules/statistics/apis/index.ts
  3. 7
      src/modules/statistics/models/index.ts
  4. 17
      src/modules/statistics/reducers/index.ts
  5. 56
      src/modules/statistics/sagas/index.ts

26
src/modules/statistics/actions/index.ts

@ -15,6 +15,18 @@ const FLIGHT_STCS_SEARCH_SUCCESS =
const FLIGHT_STCS_SEARCH_FAILURE = const FLIGHT_STCS_SEARCH_FAILURE =
'statistics/flight/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_REQUEST = 'statistics/flight/RESULT_STCS_REQUEST';
const RESULT_STCS_SUCCESS = 'statistics/flight/RESULT_STCS_SUCCESS'; const RESULT_STCS_SUCCESS = 'statistics/flight/RESULT_STCS_SUCCESS';
@ -39,6 +51,18 @@ export const FLIGHT_STCS_SEARCH = createAsyncAction(
FLIGHT_STCS_SEARCH_FAILURE FLIGHT_STCS_SEARCH_FAILURE
)<IStcsSearchRq, IStcsSearchRs, AxiosError>(); )<IStcsSearchRq, IStcsSearchRs, AxiosError>();
export const ABNORMAL_STCS = createAsyncAction(
ABNORMAL_STCS_REQUEST,
ABNORMAL_STCS_SUCCESS,
ABNORMAL_STCS_FAILURE
)<null, IStcsRs[], AxiosError>();
export const ABNORMAL_STCS_SEARCH = createAsyncAction(
ABNORMAL_STCS_SEARCH_REQUEST,
ABNORMAL_STCS_SEARCH_SUCCESS,
ABNORMAL_STCS_SEARCH_FAILURE
)<IStcsSearchRq, IStcsSearchRs, AxiosError>();
export const RESULT_STCS = createAsyncAction( export const RESULT_STCS = createAsyncAction(
RESULT_STCS_REQUEST, RESULT_STCS_REQUEST,
RESULT_STCS_SUCCESS, RESULT_STCS_SUCCESS,
@ -54,6 +78,8 @@ export const RESULT_STCS_SEARCH = createAsyncAction(
const actions = { const actions = {
FLIGHT_STCS, FLIGHT_STCS,
FLIGHT_STCS_SEARCH, FLIGHT_STCS_SEARCH,
ABNORMAL_STCS,
ABNORMAL_STCS_SEARCH,
RESULT_STCS, RESULT_STCS,
RESULT_STCS_SEARCH RESULT_STCS_SEARCH
}; };

18
src/modules/statistics/apis/index.ts

@ -21,6 +21,24 @@ export const statisticsAPI = {
return await axios.get(`api/main/statistics/flight/${type}${queryString}`); 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 () => { result: async () => {
return await axios.get('/api/main/statistics/flight/result-static'); return await axios.get('/api/main/statistics/flight/result-static');
}, },

7
src/modules/statistics/models/index.ts

@ -1,6 +1,8 @@
export interface IStatisticsState { export interface IStatisticsState {
flight: IStcsRs[]; flight: IStcsRs[];
flightSearch: IStcsSearchRs; flightSearch: IStcsSearchRs;
abnormal: IStcsRs[];
abnormalSearch: IStcsSearchRs;
result: IStcsRs[]; result: IStcsRs[];
resultSearch: IStcsSearchRs; resultSearch: IStcsSearchRs;
} }
@ -33,6 +35,11 @@ export const initialState = {
graphData: [], graphData: [],
topData: [] topData: []
}, },
abnormal: [],
abnormalSearch: {
graphData: [],
topData: []
},
result: [], result: [],
resultSearch: { resultSearch: {
graphData: [], graphData: [],

17
src/modules/statistics/reducers/index.ts

@ -14,7 +14,6 @@ export const statisticsReducer = createReducer<
draft.flight = data || state.flight; draft.flight = data || state.flight;
}) })
) )
// 비행 통계 카테고리별 검색 // 비행 통계 카테고리별 검색
.handleAction(Actions.FLIGHT_STCS_SEARCH.success, (state, action) => .handleAction(Actions.FLIGHT_STCS_SEARCH.success, (state, action) =>
produce(state, draft => { 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) => .handleAction(Actions.RESULT_STCS.success, (state, action) =>
produce(state, draft => { produce(state, draft => {
@ -30,7 +44,6 @@ export const statisticsReducer = createReducer<
draft.result = data || state.result; draft.result = data || state.result;
}) })
) )
// 비행 실적 통계 카테고리별 검색 // 비행 실적 통계 카테고리별 검색
.handleAction(Actions.RESULT_STCS_SEARCH.success, (state, action) => .handleAction(Actions.RESULT_STCS_SEARCH.success, (state, action) =>
produce(state, draft => { produce(state, draft => {

56
src/modules/statistics/sagas/index.ts

@ -58,6 +58,60 @@ function* flightStcsSearchSaga(
} }
} }
function* abnormalStcsSaga(
action: ActionType<typeof Actions.ABNORMAL_STCS.request>
) {
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<typeof Actions.ABNORMAL_STCS_SEARCH.request>
) {
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( function* resultStcsSaga(
action: ActionType<typeof Actions.RESULT_STCS.request> action: ActionType<typeof Actions.RESULT_STCS.request>
) { ) {
@ -115,6 +169,8 @@ function* resultStcsSearchSaga(
export function* statisticsSaga() { export function* statisticsSaga() {
yield takeEvery(Actions.FLIGHT_STCS.request, flightStcsSaga); yield takeEvery(Actions.FLIGHT_STCS.request, flightStcsSaga);
yield takeEvery(Actions.FLIGHT_STCS_SEARCH.request, flightStcsSearchSaga); 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.request, resultStcsSaga);
yield takeEvery(Actions.RESULT_STCS_SEARCH.request, resultStcsSearchSaga); yield takeEvery(Actions.RESULT_STCS_SEARCH.request, resultStcsSearchSaga);
} }

Loading…
Cancel
Save