64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { changeStatusMapData } from "@/app/common/comFunction";
|
|
import { fetchType, getFetch } from "@/components/ui/api";
|
|
import type {
|
|
DmStatusDataType,
|
|
DmStatusChartType,
|
|
} from "./type";
|
|
|
|
export type DmStatusActions = {
|
|
getDmStatusData(year: string): void;
|
|
};
|
|
|
|
export type DmStatusType = {
|
|
dmStatus: {
|
|
statusData: DmStatusDataType[];
|
|
facilityTotals: string[];
|
|
chartData: DmStatusChartType[];
|
|
};
|
|
};
|
|
|
|
export const dmStatusState: DmStatusType = {
|
|
dmStatus: {
|
|
statusData: [],
|
|
facilityTotals: [],
|
|
chartData: [],
|
|
},
|
|
};
|
|
export type DmStatusStore = DmStatusType & DmStatusActions;
|
|
|
|
export const DmStatusReducer = (set: any): DmStatusActions => {
|
|
return {
|
|
getDmStatusData: async (year: string) => {
|
|
const data = await getFetch(fetchType.WR, "/daemin/" + year);
|
|
let isData:DmStatusDataType[] =[]
|
|
if(data.data&&data.data.length>0){
|
|
isData=data.data
|
|
}else{
|
|
fetch(`data/wrStatusData.json`).then((res) => res.json()).then((json) => isData=json)//만약 백엔드에서 못가져올경우 방어책
|
|
}
|
|
|
|
const orgin: DmStatusDataType[] = isData;
|
|
const chartData = changeStatusMapData(orgin);
|
|
const facilityTotals = [
|
|
"하수재이용시설" + "(총" + orgin[0]?.sewage.split("(")[0] + "개소)",
|
|
"빗물재이용시설" + "(총" + orgin[0]?.rainwater.split("(")[0] + "개소)",
|
|
"중수도재이용시설" +
|
|
"(총" +
|
|
orgin[0]?.reclaimed.split("(")[0] +
|
|
"개소)",
|
|
"온배수재이용시설" + "(총" + orgin[0]?.thermal.split("(")[0] + "개소)",
|
|
];
|
|
|
|
set((state: DmStatusType) => ({
|
|
...state,
|
|
dmStatus: {
|
|
...state.dmStatus,
|
|
statusData: data.data,
|
|
chartData: chartData,
|
|
facilityTotals: facilityTotals,
|
|
},
|
|
}));
|
|
},
|
|
};
|
|
};
|