317 lines
9.6 KiB
TypeScript
317 lines
9.6 KiB
TypeScript
import { TEST_UUID } from "../rainReg";
|
|
import {
|
|
deleteFectch,
|
|
fetchType,
|
|
getFetch,
|
|
postFectch,
|
|
putFectch,
|
|
} from "@/components/lib/api";
|
|
import type { chHeadType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
|
import {
|
|
type customPbnst,
|
|
type fcBizType,
|
|
type pbnstInsertIndex,
|
|
type pubHasuType,
|
|
} from "./type";
|
|
import type { SelectDataType } from "@common/business_components/ui";
|
|
import {
|
|
pbnstMngUpHeadListExport,
|
|
pbnstOrgwtHeadListRxport,
|
|
pbnstMngNmExport,
|
|
pubFacHeadListExport,
|
|
pplInstlsHeadListExport,
|
|
pbnstDemandHeadListExport,
|
|
fcOrgwtsHeadListExport,
|
|
} from "./headList";
|
|
import type { TableUpperProps } from "@/app/store/common/type/header";
|
|
import toast from "react-hot-toast";
|
|
|
|
/**
|
|
* 하수재이용시설 등록 (스토어)
|
|
* 재이용시설 등록 - 하수재이용시설 등록
|
|
* 하수재이용시설 사용하는 api 및 타입 등을 관리한다.
|
|
* */
|
|
|
|
const selectLabel: SelectDataType[] = [{ text: "test", val: "1" }];
|
|
const pubFacHeadList = pubFacHeadListExport;
|
|
const pbnstMngUpHeadList = pbnstMngUpHeadListExport;
|
|
const pbnstOrgwtHeadList = pbnstOrgwtHeadListRxport;
|
|
const pbnstMngNm = pbnstMngNmExport;
|
|
const pplInstlsHeadLisat = pplInstlsHeadListExport;
|
|
const pbnstDemandHeadList = pbnstDemandHeadListExport;
|
|
const fcOrgwtsHeadList = fcOrgwtsHeadListExport;
|
|
|
|
export type pubFacState = {
|
|
pbnst: {
|
|
pubFacHeadList: TableUpperProps[];
|
|
pbnstMngUpHeadList: TableUpperProps[];
|
|
pbnstMngNm: chHeadType[];
|
|
pbnstHasuRes: pubHasuType[];
|
|
pbnstRes: customPbnst[] | null; // 배열에서 단일 객체 또는 null로 변경
|
|
pbnstResObj: customPbnst | null; // 배열에서 단일 객체 또는 null로 변경
|
|
pbnstBizCycle: SelectDataType[];
|
|
selectLabel: SelectDataType[];
|
|
pbnstOrgwtHeadList: TableUpperProps[];
|
|
pplInstlsHeadLisat: TableUpperProps[];
|
|
pbnstDemandHeadList: TableUpperProps[];
|
|
fcOrgwtsHeadList: TableUpperProps[];
|
|
pbnstMngRegData: customPbnst[];
|
|
pbnsUpdateIndex: pbnstInsertIndex;
|
|
fcOrgwtsNmList: pubHasuType[];
|
|
dmdComList: any[];
|
|
apiMessage: string;
|
|
pbnstHasuResCount: number;
|
|
};
|
|
};
|
|
type pubFacActions = {
|
|
pubHasuInit: (page: string, sggOrCity: string) => void;
|
|
pbnstRegClick: (pubHasuRes: pubHasuType) => void;
|
|
//pbnstReg: (txt: string | undefined) => void;
|
|
pbnstInsert(pbnstRes: customPbnst): Promise<void>;
|
|
fileDelete: (atflCd: string) => void;
|
|
fileDownLoad: (atflCd: string) => void;
|
|
pbnstRuseFcltUpdate: (ruseRes: customPbnst[]) => void;
|
|
pbnstRuseBizUpdate: (ruseRes: fcBizType[]) => void;
|
|
pubHasuSearch: (page: string, sggOrCity: string, searchTxt: string) => void;
|
|
getFcOrgwts: (fcltPkList: string[], size: number) => void;
|
|
};
|
|
export type pubFacType = pubFacState & pubFacActions;
|
|
|
|
export const pubFacStateExport: pubFacState = {
|
|
pbnst: {
|
|
pubFacHeadList: pubFacHeadList,
|
|
pbnstMngUpHeadList: pbnstMngUpHeadList,
|
|
pbnstMngNm: pbnstMngNm,
|
|
pbnstOrgwtHeadList: pbnstOrgwtHeadList,
|
|
pplInstlsHeadLisat: pplInstlsHeadLisat,
|
|
pbnstDemandHeadList: pbnstDemandHeadList,
|
|
fcOrgwtsHeadList: fcOrgwtsHeadList,
|
|
selectLabel: selectLabel,
|
|
pbnstResObj: null, // 초기값을 null로 변경
|
|
pbnstHasuRes: [],
|
|
pbnstRes: [], // 초기값을 null로 변경
|
|
pbnstBizCycle: [{ text: "없음", val: "1" }],
|
|
pbnstMngRegData: [],
|
|
pbnsUpdateIndex: {} as pbnstInsertIndex,
|
|
fcOrgwtsNmList: [],
|
|
dmdComList: [],
|
|
apiMessage: "",
|
|
pbnstHasuResCount: 1,
|
|
},
|
|
};
|
|
|
|
export const checkWrRegList = async () => {
|
|
const wrRegList = await getFetch("wr", `/reuseFc/pubFc`);
|
|
return wrRegList;
|
|
};
|
|
|
|
const hasuListFetch = async (
|
|
page: string,
|
|
sggOrCity: string,
|
|
searchTxt?: string
|
|
) => {
|
|
const checkWrRegListRes = await checkWrRegList();
|
|
|
|
let url = `/prcsFclt/ruseInfo/${page ? page : 1}/11/A/${sggOrCity ? sggOrCity : "11"}/0/1/SW`;
|
|
|
|
const data = checkWrRegListRes.filter((item: string) => item !== "");
|
|
if (searchTxt) {
|
|
url = url + `/${searchTxt}`;
|
|
}
|
|
const rainRes = await postFectch(url, data, fetchType.COMMON);
|
|
|
|
const hasuList = rainRes.data.map((item: any) => {
|
|
return {
|
|
...item,
|
|
fctCpc: Number(item.fctCpc) || 0,
|
|
ruse: item.ruse === false ? "N" : "Y",
|
|
};
|
|
});
|
|
|
|
return { data: hasuList, count: rainRes.count };
|
|
};
|
|
|
|
const initFetch = async (ruseFcltPk: string | undefined) => {
|
|
const pbnstRes = await getFetch("wr", `/reuseFc/pubFc/${ruseFcltPk}`);
|
|
return pbnstRes;
|
|
};
|
|
|
|
export const writeRgtrAndMdfr = (data: customPbnst[]) => {
|
|
data.forEach((pbnst) => {
|
|
pbnst.rgtr = TEST_UUID;
|
|
pbnst.mdfr = TEST_UUID;
|
|
|
|
pbnst.fcBizs = pbnst.fcBizs?.map((item) => {
|
|
item.rgtr = TEST_UUID;
|
|
item.mdfr = TEST_UUID;
|
|
item.fcOrgwts = item.fcOrgwts?.map((orgwt) => {
|
|
orgwt.mdfr = TEST_UUID;
|
|
orgwt.rgtr = TEST_UUID;
|
|
return orgwt;
|
|
});
|
|
|
|
item.fcDemands = item.fcDemands?.map((dmd) => {
|
|
dmd.mdfr = TEST_UUID;
|
|
dmd.rgtr = TEST_UUID;
|
|
return dmd;
|
|
});
|
|
return item;
|
|
});
|
|
pbnst.fcOpers = pbnst?.fcOpers?.map((oper) => {
|
|
oper.rgtr = TEST_UUID;
|
|
oper.mdfr = TEST_UUID;
|
|
return oper;
|
|
});
|
|
pbnst.fcFiles = pbnst.fcFiles?.map((file) => {
|
|
file.rgtr = TEST_UUID;
|
|
file.mdfr = TEST_UUID;
|
|
return file;
|
|
});
|
|
});
|
|
|
|
return data;
|
|
};
|
|
export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
|
return {
|
|
// 하수처리시설을 조회한다(운영실태)
|
|
pubHasuInit: async (page: string, sggOrCity: string) => {
|
|
try {
|
|
const pbnstHasuRes = await hasuListFetch(page, sggOrCity);
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstHasuRes: pbnstHasuRes.data,
|
|
pbnstHasuResCount: pbnstHasuRes.count,
|
|
},
|
|
}));
|
|
} catch (errorHasu) {
|
|
console.log(errorHasu);
|
|
}
|
|
},
|
|
// 하수처리시설을 조회한다(운영실태) (처리시설명 포함)
|
|
pubHasuSearch: async (
|
|
page: string,
|
|
sggOrCity: string,
|
|
searchTxt: string
|
|
) => {
|
|
try {
|
|
const pbnstHasuRes = await hasuListFetch(page, sggOrCity, searchTxt);
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstHasuRes: pbnstHasuRes.data,
|
|
pbnstHasuResCount: pbnstHasuRes.count,
|
|
},
|
|
}));
|
|
} catch (errorHasu) {
|
|
console.log(errorHasu);
|
|
}
|
|
},
|
|
// 하수재이용시설을 조회한다
|
|
pbnstRegClick: async (pubHasuRes: pubHasuType) => {
|
|
try {
|
|
const pbnstRes = await initFetch(pubHasuRes.bscFctCd);
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstRes: pbnstRes,
|
|
},
|
|
}));
|
|
} catch (errorHasu) {
|
|
console.log(errorHasu);
|
|
}
|
|
},
|
|
// 하수재이용시설을 등록한다.
|
|
pbnstInsert: async (pbnstRes: customPbnst) => {
|
|
try {
|
|
const response = await postFectch(`/reuseFc/pubFc`, pbnstRes);
|
|
if (response.status === 200) {
|
|
toast.success(
|
|
`${pbnstRes.ruseUtztnFcltNm} 하수재이용 시설이 등록되었습니다.`
|
|
);
|
|
}
|
|
|
|
const newPbnstRes = await initFetch(
|
|
pbnstRes.pbnstRuseFcltId.slice(0, 11)
|
|
);
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstRes: newPbnstRes,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("Error updating pbnst:", error);
|
|
}
|
|
},
|
|
// 하수재이용시설을 업데이트한다.(사업제외) 다르게하는 이유는 객체가 너무커서 분활 처리하려고
|
|
pbnstRuseFcltUpdate: async (ruseRes: customPbnst[]) => {
|
|
try {
|
|
await putFectch(`/reuseFc/pubFc`, ruseRes);
|
|
} catch (error) {
|
|
console.error("Error pbnstRuseFcltUpdate:", error);
|
|
}
|
|
},
|
|
// 하수재이용시설을 업데이트한다.(사업포함) 다르게하는 이유는 객체가 너무커서 분활 처리하려고
|
|
pbnstRuseBizUpdate: async (ruseRes: fcBizType[]) => {
|
|
try {
|
|
await putFectch(`/reuseFc/pubFcBiz`, ruseRes);
|
|
} catch (error) {
|
|
console.error("Error pbnstRuseFcltUpdate:", error);
|
|
}
|
|
},
|
|
// 파일삭제 (attach-service)
|
|
fileDelete: async (atflCd: string) => {
|
|
try {
|
|
const response = await deleteFectch(
|
|
`/attach-service/api/v1/atfl/attachments/atflCd//${atflCd}`,
|
|
undefined,
|
|
fetchType.CS
|
|
);
|
|
|
|
console.log("File deleted successfully:", response);
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("Error deleting file:", error);
|
|
}
|
|
},
|
|
// 파일다운로드 (attach-service)
|
|
fileDownLoad: async (atflCd: string) => {
|
|
try {
|
|
await getFetch(
|
|
fetchType.CS,
|
|
`/attach-service/api/v1/atflcd/download/${atflCd}`
|
|
);
|
|
} catch (error) {
|
|
console.error("Error downloading file:", error);
|
|
throw new Error(`Error downloading file: ${error}`);
|
|
}
|
|
},
|
|
//원수취수 팝업의 하수처리 시설 리스트 조회
|
|
getFcOrgwts: async (fcltPkList: string[], size: number) => {
|
|
const fcOrgwtsNmList = await postFectch(
|
|
`/prcsFclt/ruseInfo/1/${size}/A/0/0/1/SW`,
|
|
fcltPkList,
|
|
fetchType.COMMON
|
|
);
|
|
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
fcOrgwtsNmList: fcOrgwtsNmList.data ?? [],
|
|
},
|
|
}));
|
|
},
|
|
};
|
|
};
|