From 68c99ad6c09becc7322fd76bd6f19fef05ab0c67 Mon Sep 17 00:00:00 2001 From: ljpark Date: Thu, 21 Aug 2025 17:14:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20sample?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(with-base-layout)/ii/fileupload/page.tsx | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 apps/sn/app/(with-base-layout)/ii/fileupload/page.tsx diff --git a/apps/sn/app/(with-base-layout)/ii/fileupload/page.tsx b/apps/sn/app/(with-base-layout)/ii/fileupload/page.tsx new file mode 100644 index 000000000..e72f7f4a5 --- /dev/null +++ b/apps/sn/app/(with-base-layout)/ii/fileupload/page.tsx @@ -0,0 +1,99 @@ +'use client' + +// FileUpload.js +import React, { useState } from 'react'; +import axios from 'axios'; +const SEWERAGE_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || ""; + +function FileUpload() { + const [file, setFile] = useState(null); + const [text, setText] = useState(''); + + const handleFileChange = (e) => { + setFile(e.target.files[0]); + }; + + const handleTextChange = (e) => { + setText(e.target.value); + }; + + function getCookie(name:string) { + const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); + if (match && match[2]) { + return decodeURIComponent(match[2]); + } + return null; + } + const handleFindUser = (e) => { + const auth = getCookie("Authorization"); + if (auth) console.log("쿠키 auth : " + auth); + fetch(SEWERAGE_URL+"/v1/inftwtAnls/users/65a00f65-8460-49af-98ec-042977e56f4b", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({authToken: auth}) + }).then((data) => { + console.log(data); + }); + }; + const handleFindUserOna = (e) => { + const auth = getCookie("Authorization"); + if (auth) console.log("쿠키 auth : " + auth); + fetch("/server/user-service/api/v1/users/65a00f65-8460-49af-98ec-042977e56f4b").then((data) => { + console.log(data); + }); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + + if (!file) { + alert('파일을 선택하세요.'); + return; + } + + const jsonData = { + aplcnYm: '202507', + enoCd: 'ABC' + }; + + // JSON → Blob 으로 변환 + MIME 지정 + const jsonBlob = new Blob([JSON.stringify(jsonData)], { + type: 'application/json' + }); + + const formData = new FormData(); + formData.append('data', jsonBlob); + formData.append('inpFile', file); + + try { + const response = await axios.post('http://localhost:8883/sewerage-service/api/v1/rdiiAnls/savewithfile', formData); + + alert('업로드 성공: ' + response.data.message); + } catch (err) { + console.error(err); + alert('업로드 실패'); + } + }; + + return ( +
+
+ + +
+
+ + +
+ + + +
+ ); +} + +export default FileUpload; From 3d0dccaa356421201cd21cf30271ba4c47040974 Mon Sep 17 00:00:00 2001 From: ljpark Date: Fri, 22 Aug 2025 20:53:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EC=B9=A8=EC=9E=85=EC=88=98=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(with-base-layout)/ii/irsetting/page.tsx | 24 +++++++++++++++---- apps/sn/app/components/lib/api/index.ts | 4 +++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/sn/app/(with-base-layout)/ii/irsetting/page.tsx b/apps/sn/app/(with-base-layout)/ii/irsetting/page.tsx index 1f089fbd6..ae9b4107d 100644 --- a/apps/sn/app/(with-base-layout)/ii/irsetting/page.tsx +++ b/apps/sn/app/(with-base-layout)/ii/irsetting/page.tsx @@ -1,5 +1,5 @@ 'use client' -import { postData } from '@/components/lib/api' +import { postData , postMutiPart} from '@/components/lib/api' import FileUploadForm from '@/components/ui/fileUploadForm' import FormSection from '@/components/ui/formSection' import { DateMonthPicker, filePicked, downloadExcel } from '@common/business_components/ui' @@ -52,6 +52,11 @@ const IrSetting = () => { const [sggCd, setSggCd] = useState('0'); // 시군구 코드 상태 const [sggName, setSggName] = useState(''); // 시군구 이름 상태 const [swtrmtFcltNm, setSwtrmtFcltNm] = useState(''); // 하수처리시설명 상태 + const [file, setFile] = useState(null); + + const handleFileChange = (e) => { + setFile(e.target.files[0]); + }; const { data: userInfo } = useQuery({ queryKey: [ENDPOINT.USER_SERVICE.USERS], @@ -140,7 +145,16 @@ const IrSetting = () => { setIsLoadingResult(true); // 로딩 상태 시작 console.log("Submitting combined analysis data to backend:", analysisData); // 추후 API 엔드포인트에 맞게 URL 수정 필요 - const data = await postData('v1/inftwtAnls', analysisData); + // const data = await postData('v1/inftwtAnls', analysisData); + const jsonBlob = new Blob([JSON.stringify(analysisData)], { + type: 'application/json' + }); + const formData = new FormData(); + formData.append('data', jsonBlob); + if (file) { + formData.append('inpFile', file); + } + const data = await postMutiPart('v1/inftwtAnls/savewithfile', formData); console.log("Response from backend:", data); if (data) { setIsLoadingResult(false); // 로딩 상태 시작 @@ -318,8 +332,8 @@ const IrSetting = () => { anlsInfo: input2, // 분석정보 rgtr: tokenManager.getToken(AUTH_USER_ID) || null, // 등록자 (사용자 ID) rgtrNm: userInfo?.userName, // 등록자 (사용자 ID) - atflCd: file1?.atflCd, // 첨부파일CD (오수관망도) - atflId: file1?.atflId, // 첨부파일ID (오수관망도) + //atflCd: file1?.atflCd, // 첨부파일CD (오수관망도) + //atflId: file1?.atflId, // 첨부파일ID (오수관망도) atflInpNm: file1?.file?.name, // 오수관망도 파일명 atflHrPttnNm: file3?.file?.name, // 오수량 시간패턴 파일명 atflMpngNm: file2?.file?.name, // 수용가-맨홀 매칭결과 파일명 @@ -397,7 +411,7 @@ const IrSetting = () => { showPreview={true} accept={".inp"} fileIdx={0} /> - +
=> method: "POST", body: data, }; - const res = await fetch(`${BASE_URL}/${url}`, options); + //const res = await fetch(`${BASE_URL}/${url}`, options); + const res = await axios.post(`${BASE_URL}/${url}`, data); const resData = await res.json(); return resData; };