feat: 엑셀 원본 파일 선택 기능 및 프론트엔드/백엔드 최적화

- PTC(2023-2026.02).xlsx 최신화
- PTC/index.html: 에러 핸들링, 동적 API 베이스, 예산 계산 로직 개선 및 UI 최적화
- server/ptc_api_server.py: 4000 포트에서 프론트엔드 직접 서빙, 원본 엑셀 경로 설정 기능, DB 인덱스 추가 및 성능 최적화
- windows/: 원본 파일 선택을 위한 set_ptc_source.bat 추가 및 기존 스크립트 수정
This commit is contained in:
2026-03-24 13:21:20 +09:00
parent f88d8e53cb
commit b5e121136f
9 changed files with 748 additions and 102 deletions

View File

@@ -1,14 +1,17 @@
사용 파일
- start_ptc_share.bat : 관리자 권한으로 실행되며, WSL 서버 시작 + portproxy + 방화벽까지 자동 설정
- start_ptc_share.bat : 공유용 실행 파일. 관리자 권한으로 다시 실행되 WSL 서버 시작, IP 공유 설정, 방화벽 허용, 공유 주소 복사까지 처리합니다.
- set_ptc_source.bat : 사용할 PTC 원본 `.xlsx` 파일을 선택하고 저장한 뒤 서버를 다시 시작합니다.
- stop_ptc_share.bat : 공유 중지
- check_ptc_share.bat : 현재 공유 상태 확인
사용 순서
1. start_ptc_share.bat 실행
2. 브라우저에서 http://172.16.40.36:8000/PTC/ 확인
3. 안 되면 check_ptc_share.bat 실행
1. 원본 파일을 바꾸려면 set_ptc_source.bat 실행
2. start_ptc_share.bat 실행
3. 같은 PC에서는 `http://localhost:4000/PTC/` 확인
4. 다른 사람에게는 배치파일이 출력한 `http://내PCIP:4000/PTC/` 주소 전달
4. 안 되면 check_ptc_share.bat 실행
주의
- PC가 켜져 있어야 합니다.
- WSL이 재시작되어 IP가 바뀌면 start_ptc_share.bat 를 다시 실행하세요.
- 관리자 권한이 필요합니다.
- 이제 프론트와 API를 모두 4000 포트 하나로 제공합니다.

View File

@@ -1,20 +1,26 @@
@echo off
setlocal EnableExtensions
set "HOST_IP="
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$ip = Get-NetIPAddress -AddressFamily IPv4 ^| Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and $_.PrefixOrigin -ne 'WellKnown' } ^| Sort-Object InterfaceMetric, SkipAsSource ^| Select-Object -ExpandProperty IPAddress -First 1; if ($ip) { $ip }"`) do (
set "HOST_IP=%%i"
)
if "%HOST_IP%"=="" set "HOST_IP=localhost"
echo [Windows portproxy]
netsh interface portproxy show v4tov4
echo.
echo [WSL web]
wsl.exe bash -lc "curl -I -s http://127.0.0.1:8000/PTC/ | head -n 1"
echo.
echo [WSL api]
wsl.exe bash -lc "curl -s http://127.0.0.1:4000/api/health"
echo.
echo [WSL web]
wsl.exe bash -lc "curl -I -s http://127.0.0.1:4000/PTC/ | head -n 1"
echo.
echo [Office LAN web]
powershell -NoProfile -Command "try { (Invoke-WebRequest -Uri 'http://172.16.40.36:8000/PTC/' -UseBasicParsing -TimeoutSec 5).StatusCode } catch { $_.Exception.Message }"
powershell -NoProfile -Command "try { (Invoke-WebRequest -Uri 'http://%HOST_IP%:4000/PTC/' -UseBasicParsing -TimeoutSec 5).StatusCode } catch { $_.Exception.Message }"
echo.
echo [Office LAN api]
powershell -NoProfile -Command "try { (Invoke-WebRequest -Uri 'http://172.16.40.36:4000/api/health' -UseBasicParsing -TimeoutSec 5).Content } catch { $_.Exception.Message }"
powershell -NoProfile -Command "try { (Invoke-WebRequest -Uri 'http://%HOST_IP%:4000/api/health' -UseBasicParsing -TimeoutSec 5).Content } catch { $_.Exception.Message }"
echo.
pause

View File

@@ -0,0 +1,42 @@
@echo off
setlocal EnableExtensions
set "CONFIG_PATH=/home/hyein/project/server/ptc_source_path.txt"
set "SELECTED_FILE="
set "WSL_SOURCE_PATH="
for /f "usebackq delims=" %%i in (`powershell -NoProfile -STA -Command "Add-Type -AssemblyName System.Windows.Forms; $dialog = New-Object System.Windows.Forms.OpenFileDialog; $dialog.Filter = 'Excel Files (*.xlsx)|*.xlsx'; $dialog.Title = 'PTC 원본 엑셀 파일 선택'; $dialog.InitialDirectory = [Environment]::GetFolderPath('Desktop'); if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { $dialog.FileName }"`) do (
set "SELECTED_FILE=%%i"
)
if "%SELECTED_FILE%"=="" (
echo 파일 선택이 취소되었습니다.
pause
exit /b 1
)
echo 선택한 파일:
echo %SELECTED_FILE%
for /f "usebackq delims=" %%i in (`wsl.exe wslpath -a "%SELECTED_FILE%"`) do (
set "WSL_SOURCE_PATH=%%i"
)
if "%WSL_SOURCE_PATH%"=="" (
echo WSL 경로 변환에 실패했습니다.
pause
exit /b 1
)
wsl.exe bash -lc "printf '%s\n' \"%WSL_SOURCE_PATH%\" > %CONFIG_PATH%"
if errorlevel 1 (
echo 원본 파일 설정 저장에 실패했습니다.
pause
exit /b 1
)
echo 설정 저장 완료
echo 다음 실행부터 이 파일을 사용합니다.
echo.
echo 바로 서버를 다시 시작합니다...
call "%~dp0start_ptc_share.bat"

View File

@@ -1,70 +1,77 @@
@echo off
setlocal EnableExtensions EnableDelayedExpansion
setlocal EnableExtensions
set "PROJECT_DIR=/home/hyein/project"
set "WEB_PORT=8000"
set "API_PORT=4000"
set "LOCAL_URL=http://localhost:4000/PTC/"
set "SHARE_URL="
set "LAN_IP="
set "CURRENT_SOURCE="
net session >nul 2>&1
if not "%errorlevel%"=="0" (
echo 관리자 권한으로 다시 실행합니다...
echo 관리자 권한으로 다시 실행해 공유 설정까지 적용합니다...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
for /f "usebackq delims=" %%i in (`wsl.exe bash -lc "if [ -f /home/hyein/project/server/ptc_source_path.txt ]; then cat /home/hyein/project/server/ptc_source_path.txt; else echo /home/hyein/project/PTC(2023-2026.02).xlsx; fi"`) do (
set "CURRENT_SOURCE=%%i"
)
echo PTC 서버 시작 중...
echo 원본 파일: %CURRENT_SOURCE%
wsl.exe bash -lc "pkill -f '/home/hyein/project/server/ptc_api_server.py' >/dev/null 2>&1 || true; nohup python3 /home/hyein/project/server/ptc_api_server.py >/tmp/ptc_api.log 2>&1 & sleep 3"
if errorlevel 1 (
echo WSL에서 서버 시작 명령 실행에 실패했습니다.
echo WSL이 실행 가능한지 확인해 주세요.
pause
exit /b 1
)
echo 로컬 서버 상태 확인 중...
wsl.exe bash -lc "curl -fsS http://127.0.0.1:4000/api/health >/tmp/ptc_api_health.json && curl -fsSI http://127.0.0.1:4000/PTC/ >/tmp/ptc_web_health.txt"
if errorlevel 1 (
echo 로컬 서버 확인에 실패했습니다.
echo 아래 로그를 확인해 주세요.
wsl.exe bash -lc "tail -n 80 /tmp/ptc_api.log"
pause
exit /b 1
)
echo 브라우저를 엽니다...
start "" "%LOCAL_URL%"
echo.
echo 로컬 실행 완료
echo 메인 화면: %LOCAL_URL%
echo.
echo 사내망 공유용 Windows IP 확인 중...
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$ip = Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and $_.PrefixOrigin -ne 'WellKnown' } | Select-Object -ExpandProperty IPAddress -First 1; if ($ip) { $ip }"`) do (
set "LAN_IP=%%i"
)
echo WSL IP 확인 중...
for /f "usebackq delims=" %%i in (`wsl.exe bash -lc "hostname -I | cut -d' ' -f1"`) do (
for /f "usebackq delims=" %%i in (`wsl.exe bash -lc "hostname -I | awk '{print $1}'"`) do (
set "WSL_IP=%%i"
)
if "%WSL_IP%"=="" (
echo WSL IP를 확인하지 못했습니다.
pause
exit /b 1
)
if "%LAN_IP%"=="" goto :share_done
if "%WSL_IP%"=="" goto :share_done
echo WSL IP: %WSL_IP%
echo 기존 서버 정리 및 재실행 중...
wsl.exe bash -lc "pkill -f 'python3 -m http.server 8000' >/dev/null 2>&1 || true; pkill -f '/home/hyein/project/server/ptc_api_server.py' >/dev/null 2>&1 || true; nohup python3 -m http.server 8000 --directory /home/hyein/project >/tmp/ptc_web.log 2>&1 & nohup python3 /home/hyein/project/server/ptc_api_server.py >/tmp/ptc_api.log 2>&1 & sleep 2"
echo 포트포워딩 갱신 중...
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=%WEB_PORT% >nul 2>&1
echo 사내망 공유 설정 중...
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=%API_PORT% >nul 2>&1
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=%WEB_PORT% connectaddress=%WSL_IP% connectport=%WEB_PORT%
if errorlevel 1 (
echo 8000 포트포워딩 설정에 실패했습니다.
pause
exit /b 1
)
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=%API_PORT% connectaddress=%WSL_IP% connectport=%API_PORT%
if errorlevel 1 (
echo 4000 포트포워딩 설정에 실패했습니다.
pause
exit /b 1
)
echo 방화벽 규칙 적용 중...
netsh advfirewall firewall delete rule name="PTC 8000" >nul 2>&1
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=%API_PORT% connectaddress=%WSL_IP% connectport=%API_PORT% >nul 2>&1
netsh advfirewall firewall delete rule name="PTC 4000" >nul 2>&1
netsh advfirewall firewall add rule name="PTC 8000" dir=in action=allow protocol=TCP localport=%WEB_PORT% >nul
netsh advfirewall firewall add rule name="PTC 4000" dir=in action=allow protocol=TCP localport=%API_PORT% >nul
netsh advfirewall firewall add rule name="PTC 4000" dir=in action=allow protocol=TCP localport=%API_PORT% >nul 2>&1
echo 서버 상태 확인 중...
wsl.exe bash -lc "curl -s http://127.0.0.1:4000/api/health >/tmp/ptc_api_health.json && curl -I -s http://127.0.0.1:8000/PTC/ >/tmp/ptc_web_health.txt"
if errorlevel 1 (
echo WSL 내부 서버 확인에 실패했습니다.
echo /tmp/ptc_api.log 와 /tmp/ptc_web.log 를 확인해 주세요.
pause
exit /b 1
:share_done
if not "%LAN_IP%"=="" (
set "SHARE_URL=http://%LAN_IP%:%API_PORT%/PTC/"
echo 사내망 접속 주소: %SHARE_URL%
echo %SHARE_URL%| clip
echo 공유 주소를 클립보드에 복사했습니다.
)
echo.
echo 공유 준비 완료
echo 메인 화면: http://172.16.40.36:%WEB_PORT%/PTC/
echo API 안내 : http://172.16.40.36:%API_PORT%/
echo.
echo 참고: WSL이 재시작되어 IP가 바뀌면 이 파일을 다시 실행하세요.
pause