Browse Source

[redux-tookit] 비행 통계 작업

master
박상현 7 months ago
parent
commit
a2225a823a
  1. 80
      src/_redux/features/statistics/statisticsThunk.ts
  2. 5
      src/_redux/rootReducer.ts
  3. 11
      src/containers/statistics/AbnormalSituationContainer.js
  4. 12
      src/containers/statistics/FlightContainer.js
  5. 11
      src/containers/statistics/FlightResultContainer.js
  6. 5
      src/redux/reducers/rootReducer.ts

80
src/_redux/features/statistics/statisticsThunk.ts

@ -1,12 +1,20 @@
import axios from '../../../modules/utils/customAxiosUtil';
import qs from 'qs';
import { IStcsRq, IStcsSearchRq } from './statisticsState';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { isError, isMessage } from '../comn/message/messageSlice';
import {
ERROR_MESSAGE,
DUPLATE_MESSAGE,
SAVE_MESSAGE,
DELETE_MESSAGE
} from '@src/configs/constants';
// 비행 통계(총 비행시간, 총 비행 건수,총 비행거리)
export const getFlightStatistics = createAsyncThunk(
'statistics/getFlightStatistics',
async (rq: IStcsRq, thunkAPI) => {
const { rejectWithValue } = thunkAPI;
try {
const { serviceType } = rq;
const res = await axios.get(
@ -16,14 +24,24 @@ export const getFlightStatistics = createAsyncThunk(
);
return res.data;
} catch (error) {
console.error(error);
thunkAPI.dispatch(
isError({
errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false,
isRefresh: false
})
);
return rejectWithValue(error);
}
}
);
// 비행통계(비행시간, 비행 시간 top5)
export const getFlightSearch = createAsyncThunk(
'statistics/getFlightSearch',
async (rq: IStcsSearchRq, thunkAPI) => {
const { rejectWithValue } = thunkAPI;
try {
const { type } = rq;
const params = {};
@ -41,14 +59,24 @@ export const getFlightSearch = createAsyncThunk(
);
return res.data;
} catch (error) {
console.error(error);
thunkAPI.dispatch(
isError({
errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false,
isRefresh: false
})
);
return rejectWithValue(error);
}
}
);
// 비정상 상황 통계(비행경로이탈, 비정상고도, 충돌위험)
export const getAbnormalStatistics = createAsyncThunk(
'statistics/getAbnormalStatistics',
async (rq: IStcsRq, thunkAPI) => {
const { rejectWithValue } = thunkAPI;
try {
const { serviceType } = rq;
const res = await axios.get(
@ -58,14 +86,24 @@ export const getAbnormalStatistics = createAsyncThunk(
);
return res.data;
} catch (error) {
console.error(error);
thunkAPI.dispatch(
isError({
errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false,
isRefresh: false
})
);
return rejectWithValue(error);
}
}
);
// 비정상상황 통계(비행시간, 비행시간 top5)
export const getAbnormalSearch = createAsyncThunk(
'statistics/getAbnormalSearch',
async (rq: IStcsSearchRq, thunkAPI) => {
const { rejectWithValue } = thunkAPI;
try {
const { type } = rq;
const params = {};
@ -83,14 +121,24 @@ export const getAbnormalSearch = createAsyncThunk(
);
return res.data;
} catch (error) {
console.error(error);
thunkAPI.dispatch(
isError({
errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false,
isRefresh: false
})
);
return rejectWithValue(error);
}
}
);
// 비행 실적 통계(비행실적,비행계획,비행승인)
export const getResultStatistics = createAsyncThunk(
'statistics/getResultStatistics',
async (rq: IStcsRq, thunkAPI) => {
const { rejectWithValue } = thunkAPI;
try {
const { serviceType } = rq;
const res = await axios.get(
@ -100,14 +148,24 @@ export const getResultStatistics = createAsyncThunk(
);
return res.data;
} catch (error) {
console.error(error);
thunkAPI.dispatch(
isError({
errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false,
isRefresh: false
})
);
return rejectWithValue(error);
}
}
);
//비행 실적 통계(비행 실적 통계, 비행 실적 TOP5)
export const getResultSearch = createAsyncThunk(
'statistics/getResultSearch',
async (rq: IStcsSearchRq, thunkAPI) => {
const { rejectWithValue } = thunkAPI;
try {
const { type } = rq;
const params = {};
@ -125,7 +183,15 @@ export const getResultSearch = createAsyncThunk(
);
return res.data;
} catch (error) {
console.error(error);
thunkAPI.dispatch(
isError({
errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false,
isRefresh: false
})
);
return rejectWithValue(error);
}
}
);

5
src/_redux/rootReducer.ts

@ -9,7 +9,7 @@ import { faqReducer } from './features/customerService/faq/faqSlice';
import { groupReducer2 } from './features/basis/group/groupSlice';
import { simulationReducer } from './features/analysis/simulation/simulationSlice';
import { registerReducer } from './features/account/register/registerSlice';
import { statisticsReducer } from './features/statistics/statisticsSlice';
const rootReducer = (state: any, action: any) => {
const combineReducer = combineReducers({
layout: layoutReducer,
@ -21,7 +21,8 @@ const rootReducer = (state: any, action: any) => {
faq: faqReducer,
group: groupReducer2,
simulation: simulationReducer,
register: registerReducer
register: registerReducer,
statistics: statisticsReducer
});
return combineReducer(state, action);

11
src/containers/statistics/AbnormalSituationContainer.js

@ -1,7 +1,10 @@
import { CustomMainLayout } from '../../components/layout/CustomMainLayout';
import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import * as StcsActions from '../../modules/statistics/actions';
import { useDispatch, useSelector } from '@src/redux/storeConfig/store';
import {
getAbnormalSearch,
getAbnormalStatistics
} from '@src/_redux/features/statistics/statisticsThunk';
import StatisticsSearch from '../../components/statistics/StatisticsSearch';
import StatisticsTotal from '../../components/statistics/StatisticsTotal';
@ -53,7 +56,7 @@ export default function AbnormalSituationContainer() {
const params =
user?.authId === 'SUPER' ? { serviceType: searchType.serviceType } : {};
dispatch(StcsActions.ABNORMAL_STCS.request(params));
dispatch(getAbnormalStatistics(params));
}, [searchType.serviceType, user]);
// 사용자가 SUPER 권한일 경우 serviceType 파라미터 추가 - 하단 그래프 데이터
@ -71,7 +74,7 @@ export default function AbnormalSituationContainer() {
? { cate: category, date, type: dateType, serviceType }
: { cate: category, date, type: dateType };
dispatch(StcsActions.ABNORMAL_STCS_SEARCH.request(params));
dispatch(getAbnormalSearch(params));
}, [searchType, user]);
// 해당 월에 맞는 요일 표출

12
src/containers/statistics/FlightContainer.js

@ -1,10 +1,12 @@
import { CustomMainLayout } from '../../components/layout/CustomMainLayout';
import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import * as StcsActions from '../../modules/statistics/actions';
import { useDispatch, useSelector } from '@src/redux/storeConfig/store';
import StatisticsTotal from '../../components/statistics/StatisticsTotal';
import StatisticsSearch from '../../components/statistics/StatisticsSearch';
import {
getFlightStatistics,
getFlightSearch
} from '@src/_redux/features/statistics/statisticsThunk';
export default function FlightContainer() {
const dispatch = useDispatch();
@ -50,7 +52,7 @@ export default function FlightContainer() {
const params =
user?.authId === 'SUPER' ? { serviceType: searchType.serviceType } : {};
dispatch(StcsActions.FLIGHT_STCS.request(params));
dispatch(getFlightStatistics(params));
}, [searchType.serviceType, user]);
// 사용자가 SUPER 권한일 경우 serviceType 파라미터 추가 - 하단 그래프 데이터
@ -68,7 +70,7 @@ export default function FlightContainer() {
? { cate: category, date, type: dateType, serviceType }
: { cate: category, date, type: dateType };
dispatch(StcsActions.FLIGHT_STCS_SEARCH.request(params));
dispatch(getFlightSearch(params));
}, [searchType, user]);
// 해당 월에 맞는 요일 표출

11
src/containers/statistics/FlightResultContainer.js

@ -1,7 +1,10 @@
import { CustomMainLayout } from '../../components/layout/CustomMainLayout';
import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import * as StcsActions from '../../modules/statistics/actions';
import { useDispatch, useSelector } from '@src/redux/storeConfig/store';
import {
getResultSearch,
getResultStatistics
} from '@src/_redux/features/statistics/statisticsThunk';
import StatisticsTotal from '../../components/statistics/StatisticsTotal';
import StatisticsSearch from '../../components/statistics/StatisticsSearch';
@ -49,7 +52,7 @@ export default function ResultContainer() {
const params =
user?.authId === 'SUPER' ? { serviceType: searchType.serviceType } : {};
dispatch(StcsActions.RESULT_STCS.request(params));
dispatch(getResultStatistics(params));
}, [searchType.serviceType, user]);
// 사용자가 SUPER 권한일 경우 serviceType 파라미터 추가 - 하단 그래프 데이터
@ -67,7 +70,7 @@ export default function ResultContainer() {
? { cate: category, date, type: dateType, serviceType }
: { cate: category, date, type: dateType };
dispatch(StcsActions.RESULT_STCS_SEARCH.request(params));
dispatch(getResultSearch(params));
}, [searchType, user]);
// 해당 월에 맞는 요일 표출

5
src/redux/reducers/rootReducer.ts

@ -36,7 +36,8 @@ import { qnaSaga, qnaReducer } from '../../modules/cstmrService/inquiry';
// import { laancSaga, laancReducer } from '../../modules/laanc';
import { menuReducer } from '../../modules/menu';
import { statisticsSaga, statisticsReducer } from '../../modules/statistics';
// import { statisticsSaga, statisticsReducer } from '../../modules/statistics';
import { statisticsReducer } from '@src/_redux/features/statistics/statisticsSlice';
import { droneReducer } from '../../_redux/features/basis/drone/droneSlice';
import { laancReducer } from '../../_redux/features/laanc/laancSlice';
import { layoutReducer } from '../../_redux/features/layout/layoutSlice';
@ -60,7 +61,7 @@ export function* saga() {
// yield all([fork(laancSaga)]);
yield all([fork(qnaSaga)]);
yield all([fork(statisticsSaga)]);
// yield all([fork(statisticsSaga)]);
}
const rootReducer = combineReducers({

Loading…
Cancel
Save