354 lines
9.7 KiB
TypeScript
354 lines
9.7 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";
|
|
|
|
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: {
|
|
isInit: boolean;
|
|
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>;
|
|
appendRuseFclt(array: customPbnst[]): 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: {
|
|
isInit: false,
|
|
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
|
|
},
|
|
};
|
|
|
|
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,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} 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,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} 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,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} 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 pbnstHasuRes = await hasuListFetch('1', '0');
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstHasuRes: pbnstHasuRes.data,
|
|
pbnstHasuResCount:pbnstHasuRes.count,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} 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);
|
|
}
|
|
} ,
|
|
getBizCycle: async (pbnstObj: customPbnst) => {
|
|
const pbnstBizCycle = pbnstObj.fcBizs.map((item) => {
|
|
return {
|
|
text: `${item.cycl}차`,
|
|
val: item.cycl,
|
|
};
|
|
});
|
|
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstBizCycle: pbnstBizCycle,
|
|
pbnstResObj: pbnstObj,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
},
|
|
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,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("Error deleting file:", error);
|
|
}
|
|
},
|
|
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}`);
|
|
|
|
}
|
|
},
|
|
|
|
appendRuseFclt: async (array: customPbnst[]) => {
|
|
try {
|
|
return set((state: pubFacState) => ({
|
|
...state,
|
|
pbnst: {
|
|
...state.pbnst,
|
|
pbnstRes: array,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
},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??[]
|
|
},
|
|
}));
|
|
}
|
|
|
|
};
|
|
};
|