@echo off
chcp 65001
setlocal enabledelayedexpansion

REM 定义要复制的模块名
set MODULE_LIST=admin common framework generator quartz system

REM 目标目录
set "TARGET_DIR=%cd%\jar"

REM 检查并创建 jar 目录
if not exist "%TARGET_DIR%" (
    echo [INFO] jar目录不存在，正在创建...
    mkdir "%TARGET_DIR%"
)

REM 遍历模块列表
for %%i in (%MODULE_LIST%) do (
    set "MODULE=%%i"
    set "FOUND=0"

    REM 遍历匹配的所有 jar 文件
    for %%j in (..\!MODULE!\target\!MODULE!*.jar) do (
        if exist "%%j" (
            set "SOURCE_FILE=%%j"
            set "FILENAME=%%~nxj"
            set "FOUND=1"
            
            echo [INFO] 复制 !SOURCE_FILE! 到 %TARGET_DIR%\!FILENAME! ...
            copy /Y "!SOURCE_FILE!" "%TARGET_DIR%\!FILENAME!" >nul
            echo [SUCCESS] 复制 !FILENAME! 完成。
        )
    )

    if "!FOUND!"=="0" (
        echo [WARNING] 未找到模块 !MODULE! 的jar文件，跳过...
    )
)

endlocal
if "%ERROR_FOUND%"=="1" (
    pause
)
