잠재수요처 조회 기능 수정, 엑셀 다운로드 수정

This commit is contained in:
jyha00
2025-07-02 14:30:18 +09:00
parent f6f03a62cb
commit c50c2685c1
4 changed files with 104 additions and 86 deletions
+46 -27
View File
@@ -44,7 +44,7 @@ export default function LdrmntCoSttn() {
const [searchTxt, setSearchTxt] = useState<string>();
const ref = useRef<ReturnType>({} as ReturnType);
const [excelData, setExcelData] = useState<any[]>();
const [isExcelDownload, setIsExcelDownload] = useState(false);
const excelClick = useCallback(() => {
excelDownload(
@@ -57,14 +57,22 @@ export default function LdrmntCoSttn() {
}, []);
const excelDownloadClick = () => {
downloadExcel({
data: excelData ?? [],
fileName: "잠재수요처 관리",
sheetNameArray: ["Sheet1"],
headerRange: "A1:F1"
})
ldrmntSearch(1, "10000", "0", "");
setIsExcelDownload(true);
}
useEffect(() => {
if (isExcelDownload && excelData && excelData.length > 0) {
downloadExcel({
data: excelData,
fileName: "잠재수요처 관리",
sheetNameArray: ["Sheet1"],
headerRange: "A1:F1"
});
setIsExcelDownload(false);
}
}, [excelData, isExcelDownload]);
const [isExcelOpen, setIsExcelOpen] = useState<{
isModal: boolean;
}>({ isModal: false });
@@ -73,14 +81,21 @@ export default function LdrmntCoSttn() {
if (index !== undefined) {
setDetailModal({ isOpen: true, data: ldrmntRes[index] });
}
}
const getSelCity = (val: string | number) => {
const cityValue = String(val); // Ensure val is treated as a string
const data = getCity(cityValue, code.sggCd);
setSelectSgg(data);
setObjSearch({ city: cityValue, sgg: '' });
const cityValue = String(val);
if (cityValue === "0") {
setSelectSgg([]);
setObjSearch({ city: cityValue, sgg: "" });
} else {
const data = getCity(cityValue, code.sggCd);
setSelectSgg(data);
const firstSggVal = data.find(item => item.val === "0")?.val || (data[0]?.val ?? "");
setObjSearch({ city: cityValue, sgg: firstSggVal });
}
};
const getSgg = (val: string | number) => {
@@ -125,10 +140,9 @@ export default function LdrmntCoSttn() {
setExcelData(data)
}, [excelList])
useEffect(() => {
let cityTxt = '';
let sggTxt = '';
let cityTxt = ''
let sggTxt = ''
if (objSearch?.city.toString().length > 0) {
cityTxt = code.cityCd.find((item) => item.val === objSearch?.city)?.text ?? '';
@@ -138,21 +152,23 @@ export default function LdrmntCoSttn() {
sggTxt = code.sggCd.find((item) => item.val === objSearch?.sgg)?.text ?? '';
}
let cityNm = "";
if (cityTxt === '전체' || cityTxt === '') {
cityTxt = '0'
}
let cityNm = ""
if (sggTxt !== "0") {
cityNm = cityTxt + " " + sggTxt;
cityNm = cityTxt + " " + sggTxt
} else {
cityNm = cityTxt;
cityNm = cityTxt
}
if (cityNm) {
if (cityTxt === '') cityNm = "0";
ldrmntSearch(pageNation, cityNm, searchTxt || "");
ldrmntSearch(pageNation, '20', cityNm, searchTxt || "");
} else {
ldrmntSearch(pageNation, "", searchTxt || "");
ldrmntSearch(pageNation, '20', '0', searchTxt || "");
}
}, [pageNation, objSearch, code, searchTxt, ldrmntSearch])
}, [pageNation]);
return (
<>
@@ -175,6 +191,7 @@ export default function LdrmntCoSttn() {
label="시군구"
selectClass={""}
selectArray={selectSgg || []}
value={objSearch.sgg} // value props 추가
onSelectValue={getSgg}
/>
<SearchInput
@@ -189,7 +206,7 @@ export default function LdrmntCoSttn() {
</SearchFormLeft>
<SearchFormRight
className="w-2/12 mx-5 flex flex-col items-center justify-center space-x-2 ">
<div className="flex flex-row space-x-2">
<div className="flex flex-row space-x-2 items-center">
<Button
size={"sm"}
onClick={(e) => {
@@ -205,6 +222,10 @@ export default function LdrmntCoSttn() {
sggTxt = code.sggCd.find((item) => item.val === objSearch?.sgg)?.text ?? '';
}
if (cityTxt === '전체' || cityTxt === '') {
cityTxt = '0'
}
let cityNm = ""
if (sggTxt !== "0") {
@@ -212,10 +233,8 @@ export default function LdrmntCoSttn() {
} else {
cityNm = cityTxt
}
if (cityNm) {
if (cityTxt === '') cityNm = "0";
ldrmntSearch(pageNation, cityNm, searchTxt || "");
ldrmntSearch(pageNation, '20', cityNm, searchTxt || "");
}
}}
>
@@ -46,29 +46,17 @@ export const names: nameMap = {
}
export const excelPbnstSttnParsing = (data: any[]): string[][] => {
export const excelLdrmntParsing = (data: any[]): string[][] => {
const excelExportData: string[][] = [];
data.forEach((item) => {
excelExportData.push([
item.rvbsn,
String(item.lgbsn),
item.mdmbsn ?? "",
item.rgnNm ?? "",
String(item.sido ?? ""),
String(item.gugun ?? ""),
String(item.bscFctNm ?? ""),
String(item.efflWqltStndrdNm ?? ""),
String(item.fctCpc ?? ""),
String(item.tel ?? ""),
String(item.ruseUtztnFcltNm ?? ""),
String(item.fcltCpct ?? ""),
String(item.splyExtraCpct ?? ""),
String(item.ruseCpct ?? ""),
String(item.usageTotal ?? ""),
String(item.inUsage ?? ""),
String(item.outUsage ?? ""),
item.fctryAddr?.split(" ")[0] || "",
item.fctryAddr?.split(" ")[1] || "",
item.dmdCoNm,
item.fctryAddr,
item.fctryMngNo,
item.telno,
])
})
return excelExportData;
+40 -27
View File
@@ -2,10 +2,8 @@ import type { CommonTableProps } from "@/app/store/common/type/header";
import { deleteFectch, fetchType, getFetch, postFectch, putFectch } from "@/components/lib/api";
import { ToastFormUi } from "@/components/ui/toast/toastFromUi";
import { z } from "zod";
import { ldrmntHeadListExport, ldrmntNodeListExport, ldrmntZod } from "./headList";
import { TEST_UUID } from "../../ruseFcltMng/fcltReg/rainReg";
import { ldrmntHeadListExport, ldrmntNodeListExport, ldrmntZod } from "./headList";
// 테이블 헤드 리스트
const ldrmntHeadList = ldrmntHeadListExport;
@@ -34,7 +32,7 @@ const excelDownList: ExcelType[] = [];
type ldrmntActions = {
ldrmntRegData: (data: any[]) => void,
ldrmntInit: (con: string) => void
ldrmntSearch: (page: number, sggCd: string, coNm: string) => void;
ldrmntSearch: (page: number, sggCd: string, total: string, coNm: string) => void;
ldrmntUpdate: (ldrmntRes: customLdrmnt) => void;
ldrmntDelete: () => void;
};
@@ -61,6 +59,7 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
fetchType.WR,
`/reuseFc/request/temp/1/20/${con}`
);
set((state: ldrmntState) => {
return {
...state,
@@ -68,6 +67,7 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
...state.ldrmnt,
ldrmntRes: ldrmntRes,
isInit: false,
excelList: excelDownList,
},
}
});
@@ -101,44 +101,57 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
}
},
ldrmntSearch: async (page: number, sggCd: string, coNm: string) => {
ldrmntSearch: async (page: number, total: string, sggCd: string, coNm: string) => {
let searchUrl = "";
if (sggCd !== "") {
if (coNm !== "") {
searchUrl = `/reuseFc/request/temp/${page}/20/${sggCd}/${coNm}`;
searchUrl = `/reuseFc/request/temp/${page}/${total}/${sggCd}/${coNm}`;
} else {
searchUrl = `/reuseFc/request/temp/${page}/20/${sggCd}`;
searchUrl = `/reuseFc/request/temp/${page}/${total}/${sggCd}`;
}
}
try {
const ldrmntRes = await getFetch(
fetchType.WR,
searchUrl
);
ldrmntRes.forEach((item: customLdrmnt) => {
excelDownList.push({
ctpvCd: item.ctpvCd,
sggCd: item.sggCd,
dmdCoNm: item.dmdCoNm,
fctryAddr: item.fctryAddr,
fctryMngNo: item.fctryMngNo,
telno: item.telno,
if (Number(total) > 5000) {
let excelDownList: ExcelType[] = [];
ldrmntRes.forEach((item: customLdrmnt) => {
excelDownList.push({
ctpvCd: item.ctpvCd,
sggCd: item.sggCd,
dmdCoNm: item.dmdCoNm,
fctryAddr: item.fctryAddr,
fctryMngNo: item.fctryMngNo,
telno: item.telno,
})
})
})
set((state: ldrmntState) => {
return {
...state,
ldrmnt: {
...state.ldrmnt,
excelList: excelDownList,
set((state: ldrmntState) => {
return {
...state,
ldrmnt: {
...state.ldrmnt,
ldrmntRes: ldrmntRes,
excelList: excelDownList,
},
}
})
},
};
});
return excelDownList;
} else
set((state: ldrmntState) => {
return {
...state,
ldrmnt: {
...state.ldrmnt,
ldrmntRes: ldrmntRes,
isInit: false,
},
};
});
return ldrmntRes;
} catch (e) {
console.log(e)
}
@@ -4,9 +4,9 @@ import type { customLdrmnt } from "@/app/store/matDmd/ldrmntCoSttn";
import { names } from "@/app/store/matDmd/ldrmntCoSttn/excel";
import { filePicked, FileUpload, FormUi, Title } from "@common/business_components/ui";
import { Form, FormField } from "@common/business_components/ui/form";
import { Button } from "@common/components/ui";
import { Button, Progress } from "@common/components/ui";
import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import type { z } from "zod";
@@ -30,20 +30,20 @@ export default function CoRegExcel() {
try {
let array: { [key: string]: string | number }[] = []
let isError = false;
if (Array.isArray(res)){
if (Array.isArray(res)) {
res.some((item, index) => {
let object: { [key: string]: string | number } = {}
Object.keys(names).some((key) => {
if (item && names[key] !== undefined) {
if (key === "공장관리번호") {
item[key] = String(item[key])
} else {
object[names[key] as string] = item[key];
}
// if (key === "공장관리번호") {
// item[key] = String(item[key])
// } else {
object[names[key] as string] = item[key];
// }
}
return false;
})
if(isError === true)
if (isError === true)
return true;
array.push(object)
@@ -55,8 +55,8 @@ export default function CoRegExcel() {
return false;
})
}
if(isError === false)
ldrmntRegData(array);
if (isError === false)
ldrmntRegData(array);
} catch (e) {
console.log(e)
alert(e)
@@ -67,7 +67,6 @@ export default function CoRegExcel() {
};
}
return (
<>
<div>
@@ -87,7 +86,6 @@ export default function CoRegExcel() {
</div>
<div>
<FormField
control={form.control}
name="file"