수용가 상수사용량 upload
This commit is contained in:
@@ -9,7 +9,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
import { excelToFlowRateData, excelToMatchingResultData, excelToTimePatternData } from '@/components/lib/utils'
|
||||
import { excelToFlowRateData, excelToMatchingResultData, excelToTimePatternData, excelToRcptrInfoData } from '@/components/lib/utils'
|
||||
import BaseLayout from '../BaseLayout'
|
||||
import { validateMultipleFiles, FILE_EXTENSIONS, type FileValidationConfig } from '../../fileValidation';
|
||||
import { validateBasicSelectionsWithAlert } from '../../selectionValidation';
|
||||
@@ -172,12 +172,14 @@ const IrSetting = () => {
|
||||
const file1 = uploadedFilesData[0]; // 오수관망도
|
||||
const file2 = uploadedFilesData[1]; // 수용가-맨홀 매칭결과
|
||||
const file3 = uploadedFilesData[2]; // 오수량 시간패턴
|
||||
const file4 = uploadedFilesData[3]; // 유량자료
|
||||
const file4 = uploadedFilesData[3]; // 유량자료
|
||||
const file5 = uploadedFilesData[4]; // 수용가 상수사용량
|
||||
|
||||
console.log("오수관망도 정보:", file1?.file);
|
||||
console.log("수용가-맨홀 매칭결과 정보:", file2);
|
||||
console.log("오수량 시간패턴 정보:", file3);
|
||||
console.log("유량자료 정보:", file4);
|
||||
console.log("수용가 상수사용량 정보:", file5);
|
||||
|
||||
// 모든 필수 파일이 선택되었는지 확인 (UploadedFileInfo 객체와 그 안의 file 객체 모두 확인)
|
||||
// 유량자료는 선택값
|
||||
@@ -214,6 +216,14 @@ const IrSetting = () => {
|
||||
fileDescription: '유량자료'
|
||||
});
|
||||
}
|
||||
// 수용가 상수사용량 파일이 있는 경우 검증 목록에 추가
|
||||
if (file5?.file) {
|
||||
validationConfigs.push({
|
||||
file: file5.file,
|
||||
allowedExtensions: FILE_EXTENSIONS.EXCEL,
|
||||
fileDescription: '수용가 상수사용량'
|
||||
});
|
||||
}
|
||||
|
||||
// 파일 확장자 검증 실행
|
||||
const validationResult = validateMultipleFiles(validationConfigs);
|
||||
@@ -242,18 +252,22 @@ const IrSetting = () => {
|
||||
type MatchingResult = { anlsSn: number; mhlMngNo: string; rcptrNo: string; };
|
||||
type TimePattern = { hrId: number; rt?: number | null | undefined; };
|
||||
type FlowRate = { pplMngNo: string; mtrngDt: string; oilq?: number | null | undefined; };
|
||||
type rcptrInfo = { rcptrNo: string; useYm: string; usqty?: number | null | undefined; };
|
||||
|
||||
const filePickers: {
|
||||
file: UploadedFileInfo;
|
||||
parser: (excelData: any) => MatchingResult[] | TimePattern[] | FlowRate[];
|
||||
parser: (excelData: any) => MatchingResult[] | TimePattern[] | FlowRate[] | rcptrInfo[];
|
||||
}[] = [
|
||||
{ file: file2, parser: excelToMatchingResultData },
|
||||
{ file: file3, parser: excelToTimePatternData }
|
||||
];
|
||||
|
||||
if (file4?.file) {
|
||||
if (file4?.file) { // 유량자료 파일이 있는 경우
|
||||
filePickers.push({ file: file4, parser: excelToFlowRateData });
|
||||
}
|
||||
if (file5?.file) { // 수용가 상수사용량 파일이 있는 경우
|
||||
filePickers.push({ file: file5, parser: excelToRcptrInfoData });
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedResults = await Promise.all(
|
||||
@@ -290,6 +304,9 @@ const IrSetting = () => {
|
||||
const flowRateData = file4?.file
|
||||
? parsedResults.find(r => r && r.fileName === file4.file?.name)?.parsedData
|
||||
: null;
|
||||
const rcptrInfoData = file5?.file
|
||||
? parsedResults.find(r => r && r.fileName === file5.file?.name)?.parsedData
|
||||
: null;
|
||||
|
||||
// 새로운 JSON 데이터 생성
|
||||
const combinedAnalysisData = {
|
||||
@@ -310,6 +327,7 @@ const IrSetting = () => {
|
||||
tbSnRcptrMhlMpng: matchingResultData, // 수용가-맨홀 매칭결과
|
||||
tbSnHrPttn: timePatternData, // 오수량 시간패턴
|
||||
tbSnOilqData: flowRateData, // 유량자료 (없을 수 있음)
|
||||
tbSnRcptrInfo: rcptrInfoData, // 수용가 상수사용량 (없을 수 있음)
|
||||
};
|
||||
|
||||
console.log("통합 분석 데이터 (JSON):", combinedAnalysisData);
|
||||
@@ -326,7 +344,7 @@ const IrSetting = () => {
|
||||
}
|
||||
// const handleAnalysisClick = () => {
|
||||
// }
|
||||
|
||||
const rcptrInfoShow = false;
|
||||
return (
|
||||
<>
|
||||
<LoadingOverlay isLoading={isLoadingResult} />
|
||||
@@ -390,6 +408,15 @@ const IrSetting = () => {
|
||||
startYear={1900} // 시작 연도 설정
|
||||
/>
|
||||
</FormSection>
|
||||
{rcptrInfoShow && <FormSection name='rcptrInfo' form={form} titleNm='▷ 수용가 상수사용량'>
|
||||
<FileUploadForm
|
||||
key={`file-upload-4-${formResetKey}`} // 폼 초기화를 위한 key
|
||||
onFileSelect={(file, cd, id) => handleFileSelection(4, file, cd, id)}
|
||||
showButton={false}
|
||||
showPreview={true}
|
||||
accept={".xls, .xlsx, .xlsm, .xltx"}
|
||||
fileIdx={4} />
|
||||
</FormSection>}
|
||||
<FormSection name='rtkSource' form={form} titleNm='▷ 오수전환율'>
|
||||
<Input
|
||||
value={input1}
|
||||
|
||||
@@ -157,6 +157,25 @@ export const excelToFlowRateData = (excelData: any) => {
|
||||
return flowRateData;
|
||||
};
|
||||
|
||||
// 수용가 물사용량
|
||||
export const rcptrInfoZod = z.object({
|
||||
rcptrNo: z.string(), // 수용가번호
|
||||
useYm: z.string(), // 사용연월
|
||||
usqty: z.number().nullish(), // 사용량(㎥)
|
||||
});
|
||||
export type rcptrInfoZodType = z.infer<typeof rcptrInfoZod>;
|
||||
export const excelToRcptrInfoData = (excelData: any) => {
|
||||
const flowRateData: rcptrInfoZodType[] = excelData.map((item: any) => {
|
||||
|
||||
return {
|
||||
rcptrNo: String(item["수용가번호"]),
|
||||
useYm: String(item["사용연월"]),
|
||||
usqty: Number(item["사용량(㎥)"]),
|
||||
};
|
||||
}).filter((el: any) => el !== undefined);
|
||||
return flowRateData;
|
||||
};
|
||||
|
||||
|
||||
// 강우자료 (수정 필요)
|
||||
export const rainZod = z.object({
|
||||
|
||||
Reference in New Issue
Block a user