@echo off

REM 根据输入参数，选择执行对应方法，不输入则执行使用说明
if "%1"=="port" goto port
if "%1"=="base" goto base
if "%1"=="modules" goto modules
if "%1"=="backend" goto backend
if "%1"=="frontend" goto frontend
if "%1"=="stop" goto stop
if "%1"=="rm" goto rm
goto usage

REM 使用说明，用来提示输入参数
:usage
echo Usage: deploy.bat [port^|base^|modules^|backend^|stop^|rm]
exit /b 1

REM 开启所需端口
:port
netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80
netsh advfirewall firewall add rule name="Open Port 8080" dir=in action=allow protocol=TCP localport=8080
netsh advfirewall firewall add rule name="Open Port 8848" dir=in action=allow protocol=TCP localport=8848
netsh advfirewall firewall add rule name="Open Port 9848" dir=in action=allow protocol=TCP localport=9848
netsh advfirewall firewall add rule name="Open Port 9849" dir=in action=allow protocol=TCP localport=9849
netsh advfirewall firewall add rule name="Open Port 6379" dir=in action=allow protocol=TCP localport=6379
netsh advfirewall firewall add rule name="Open Port 3306" dir=in action=allow protocol=TCP localport=3306
netsh advfirewall firewall add rule name="Open Port 9100" dir=in action=allow protocol=TCP localport=9100
netsh advfirewall firewall add rule name="Open Port 9200" dir=in action=allow protocol=TCP localport=9200
netsh advfirewall firewall add rule name="Open Port 9201" dir=in action=allow protocol=TCP localport=9201
netsh advfirewall firewall add rule name="Open Port 9202" dir=in action=allow protocol=TCP localport=9202
netsh advfirewall firewall add rule name="Open Port 9203" dir=in action=allow protocol=TCP localport=9203
netsh advfirewall firewall add rule name="Open Port 9300-9399" dir=in action=allow protocol=TCP localport=9300-9399
net stop mpssvc
net start mpssvc
exit /b 0

REM 启动基础环境（必须）
:base
docker-compose up -d wfc-mysql wfc-redis wfc-nacos
exit /b 0

REM 启动程序模块（必须）
:modules
docker-compose up -d wfc-nginx wfc-gateway wfc-auth wfc-modules-system wfc-modules-user wfc-modules-payment
exit /b 0

REM 启动程序模块（后端）
:backend
docker-compose up -d wfc-gateway wfc-auth wfc-modules-system wfc-modules-user wfc-modules-payment wfc-modules-job wfc-modules-file wfc-modules-gen 
exit /b 0

REM 启动程序模块（前端）
:frontend
docker-compose up -d wfc-nginx
exit /b 0

REM 关闭所有环境/模块
:stop
docker-compose stop
exit /b 0

REM 删除所有环境/模块
:rm
docker-compose rm
exit /b 0


