feat: 迭代

This commit is contained in:
2026-05-14 19:12:26 +08:00
parent da1e8b3c7d
commit 6a7ec5fca7
229 changed files with 7669 additions and 3236 deletions
+290
View File
@@ -0,0 +1,290 @@
#!/bin/bash
# 后端模块重构脚本
# 批量复制和修改文件
set -e
BASE_DIR="d:/project/company/rent/apps/server/src/modules"
echo "🚀 开始后端模块重构..."
# ============================================
# 用户端模块迁移
# ============================================
echo ""
echo "📦 迁移用户端模块..."
# 1. user/profile (从 user/user-user.controller.ts)
echo " - 迁移 user/profile..."
cp "$BASE_DIR/user/user.service.ts" "$BASE_DIR/user/profile/"
cp "$BASE_DIR/user/user-user.controller.ts" "$BASE_DIR/user/profile/profile.controller.ts"
cp -r "$BASE_DIR/user/dto" "$BASE_DIR/user/profile/"
# 修改 profile.controller.ts 的路由前缀
sed -i "s/@Controller('user')/@Controller('api\/user\/profile')/g" "$BASE_DIR/user/profile/profile.controller.ts"
sed -i "s/UserUserController/ProfileController/g" "$BASE_DIR/user/profile/profile.controller.ts"
sed -i "s/UserService/ProfileService/g" "$BASE_DIR/user/profile/profile.controller.ts"
# 重命名 service
mv "$BASE_DIR/user/profile/user.service.ts" "$BASE_DIR/user/profile/profile.service.ts"
sed -i "s/export class UserService/export class ProfileService/g" "$BASE_DIR/user/profile/profile.service.ts"
# 2. user/guest
echo " - 迁移 user/guest..."
cp "$BASE_DIR/guest/guest.service.ts" "$BASE_DIR/user/guest/"
cp "$BASE_DIR/guest/guest.controller.ts" "$BASE_DIR/user/guest/"
cp -r "$BASE_DIR/guest/dto" "$BASE_DIR/user/guest/"
sed -i "s/@Controller('user\/guests')/@Controller('api\/user\/guests')/g" "$BASE_DIR/user/guest/guest.controller.ts"
# 3. user/order
echo " - 迁移 user/order..."
cp "$BASE_DIR/order/order-user.controller.ts" "$BASE_DIR/user/order/order.controller.ts"
sed -i "s/@Controller('orders')/@Controller('api\/user\/orders')/g" "$BASE_DIR/user/order/order.controller.ts"
sed -i "s/OrderUserController/OrderController/g" "$BASE_DIR/user/order/order.controller.ts"
# 4. user/review
echo " - 迁移 user/review..."
cp "$BASE_DIR/review/review-user.controller.ts" "$BASE_DIR/user/review/review.controller.ts"
sed -i "s/@Controller('reviews')/@Controller('api\/user\/reviews')/g" "$BASE_DIR/user/review/review.controller.ts"
sed -i "s/ReviewUserController/ReviewController/g" "$BASE_DIR/user/review/review.controller.ts"
# 5. user/coupon
echo " - 迁移 user/coupon..."
cp "$BASE_DIR/coupon/coupon-user.controller.ts" "$BASE_DIR/user/coupon/coupon.controller.ts"
sed -i "s/@Controller('user\/coupons')/@Controller('api\/user\/coupons')/g" "$BASE_DIR/user/coupon/coupon.controller.ts"
sed -i "s/CouponUserController/CouponController/g" "$BASE_DIR/user/coupon/coupon.controller.ts"
# 6. user/finance
echo " - 迁移 user/finance..."
cp "$BASE_DIR/finance/finance-user.controller.ts" "$BASE_DIR/user/finance/finance.controller.ts"
cp "$BASE_DIR/finance/withdrawal-user.controller.ts" "$BASE_DIR/user/finance/withdrawal.controller.ts"
sed -i "s/@Controller('user\/finance')/@Controller('api\/user\/finance')/g" "$BASE_DIR/user/finance/finance.controller.ts"
sed -i "s/@Controller('user\/finance\/withdrawals')/@Controller('api\/user\/finance\/withdrawals')/g" "$BASE_DIR/user/finance/withdrawal.controller.ts"
sed -i "s/FinanceUserController/FinanceController/g" "$BASE_DIR/user/finance/finance.controller.ts"
sed -i "s/WithdrawalUserController/WithdrawalController/g" "$BASE_DIR/user/finance/withdrawal.controller.ts"
# 7. user/activity
echo " - 迁移 user/activity..."
cp "$BASE_DIR/activity/activity-user.controller.ts" "$BASE_DIR/user/activity/activity.controller.ts"
sed -i "s/@Controller('user\/activity\/invite')/@Controller('api\/user\/activity\/invite')/g" "$BASE_DIR/user/activity/activity.controller.ts"
sed -i "s/ActivityUserController/ActivityController/g" "$BASE_DIR/user/activity/activity.controller.ts"
# ============================================
# 商家端模块迁移
# ============================================
echo ""
echo "📦 迁移商家端模块..."
# 1. merchant/auth
echo " - 迁移 merchant/auth..."
cp "$BASE_DIR/seller-auth/seller-auth.service.ts" "$BASE_DIR/merchant/auth/auth.service.ts"
cp "$BASE_DIR/seller-auth/seller-auth.controller.ts" "$BASE_DIR/merchant/auth/auth.controller.ts"
cp "$BASE_DIR/seller-auth/seller-auth.module.ts" "$BASE_DIR/merchant/auth/auth.module.ts"
cp -r "$BASE_DIR/seller-auth/dto" "$BASE_DIR/merchant/auth/"
sed -i "s/@Controller('seller\/auth')/@Controller('api\/merchant\/auth')/g" "$BASE_DIR/merchant/auth/auth.controller.ts"
sed -i "s/SellerAuthController/AuthController/g" "$BASE_DIR/merchant/auth/auth.controller.ts"
sed -i "s/SellerAuthService/AuthService/g" "$BASE_DIR/merchant/auth/auth.controller.ts"
sed -i "s/SellerAuthService/AuthService/g" "$BASE_DIR/merchant/auth/auth.service.ts"
sed -i "s/SellerAuthModule/MerchantAuthModule/g" "$BASE_DIR/merchant/auth/auth.module.ts"
# 2. merchant/profile
echo " - 迁移 merchant/profile..."
cp "$BASE_DIR/merchant/merchant-seller.controller.ts" "$BASE_DIR/merchant/profile/profile.controller.ts"
sed -i "s/@Controller('seller\/merchant')/@Controller('api\/merchant\/profile')/g" "$BASE_DIR/merchant/profile/profile.controller.ts"
sed -i "s/MerchantSellerController/ProfileController/g" "$BASE_DIR/merchant/profile/profile.controller.ts"
# 3. merchant/statistics
echo " - 迁移 merchant/statistics..."
cp "$BASE_DIR/merchant/statistics-seller.controller.ts" "$BASE_DIR/merchant/statistics/statistics.controller.ts"
sed -i "s/@Controller('seller\/statistics')/@Controller('api\/merchant\/statistics')/g" "$BASE_DIR/merchant/statistics/statistics.controller.ts"
sed -i "s/StatisticsSellerController/StatisticsController/g" "$BASE_DIR/merchant/statistics/statistics.controller.ts"
# 4. merchant/room
echo " - 迁移 merchant/room..."
cp "$BASE_DIR/room/room-seller.controller.ts" "$BASE_DIR/merchant/room/room.controller.ts"
sed -i "s/@Controller('seller\/rooms')/@Controller('api\/merchant\/rooms')/g" "$BASE_DIR/merchant/room/room.controller.ts"
sed -i "s/RoomSellerController/RoomController/g" "$BASE_DIR/merchant/room/room.controller.ts"
# 5. merchant/room-calendar
echo " - 迁移 merchant/room-calendar..."
cp "$BASE_DIR/room-calendar/room-calendar.controller.ts" "$BASE_DIR/merchant/room-calendar/"
cp "$BASE_DIR/room-calendar/room-calendar.service.ts" "$BASE_DIR/merchant/room-calendar/"
cp "$BASE_DIR/room-calendar/room-calendar.module.ts" "$BASE_DIR/merchant/room-calendar/"
cp -r "$BASE_DIR/room-calendar/dto" "$BASE_DIR/merchant/room-calendar/"
sed -i "s/@Controller('seller\/room-calendar')/@Controller('api\/merchant\/room-calendar')/g" "$BASE_DIR/merchant/room-calendar/room-calendar.controller.ts"
# 6. merchant/order
echo " - 迁移 merchant/order..."
cp "$BASE_DIR/order/order-seller.controller.ts" "$BASE_DIR/merchant/order/order.controller.ts"
sed -i "s/@Controller('seller\/orders')/@Controller('api\/merchant\/orders')/g" "$BASE_DIR/merchant/order/order.controller.ts"
sed -i "s/OrderSellerController/OrderController/g" "$BASE_DIR/merchant/order/order.controller.ts"
# 7. merchant/review
echo " - 迁移 merchant/review..."
cp "$BASE_DIR/review/review-seller.controller.ts" "$BASE_DIR/merchant/review/review.controller.ts"
sed -i "s/@Controller('seller\/reviews')/@Controller('api\/merchant\/reviews')/g" "$BASE_DIR/merchant/review/review.controller.ts"
sed -i "s/ReviewSellerController/ReviewController/g" "$BASE_DIR/merchant/review/review.controller.ts"
# 8. merchant/finance
echo " - 迁移 merchant/finance..."
cp "$BASE_DIR/finance/transaction-seller.controller.ts" "$BASE_DIR/merchant/finance/transaction.controller.ts"
cp "$BASE_DIR/finance/withdrawal-merchant.controller.ts" "$BASE_DIR/merchant/finance/withdrawal.controller.ts"
cp "$BASE_DIR/finance/settlement-merchant.controller.ts" "$BASE_DIR/merchant/finance/settlement.controller.ts"
sed -i "s/@Controller('merchant\/finance\/transactions')/@Controller('api\/merchant\/finance\/transactions')/g" "$BASE_DIR/merchant/finance/transaction.controller.ts"
sed -i "s/@Controller('merchant\/finance\/withdrawals')/@Controller('api\/merchant\/finance\/withdrawals')/g" "$BASE_DIR/merchant/finance/withdrawal.controller.ts"
sed -i "s/@Controller('merchant\/finance\/settlements')/@Controller('api\/merchant\/finance\/settlements')/g" "$BASE_DIR/merchant/finance/settlement.controller.ts"
# ============================================
# 管理端模块迁移
# ============================================
echo ""
echo "📦 迁移管理端模块..."
# 1. admin/auth
echo " - 迁移 admin/auth..."
cp "$BASE_DIR/admin-auth/admin-auth.service.ts" "$BASE_DIR/admin/auth/auth.service.ts"
cp "$BASE_DIR/admin-auth/admin-auth.controller.ts" "$BASE_DIR/admin/auth/auth.controller.ts"
cp "$BASE_DIR/admin-auth/admin-auth.module.ts" "$BASE_DIR/admin/auth/auth.module.ts"
cp -r "$BASE_DIR/admin-auth/dto" "$BASE_DIR/admin/auth/"
sed -i "s/@Controller('admin\/auth')/@Controller('api\/admin\/auth')/g" "$BASE_DIR/admin/auth/auth.controller.ts"
sed -i "s/AdminAuthController/AuthController/g" "$BASE_DIR/admin/auth/auth.controller.ts"
sed -i "s/AdminAuthService/AuthService/g" "$BASE_DIR/admin/auth/auth.controller.ts"
sed -i "s/AdminAuthService/AuthService/g" "$BASE_DIR/admin/auth/auth.service.ts"
sed -i "s/AdminAuthModule/AdminAuthModule/g" "$BASE_DIR/admin/auth/auth.module.ts"
# 2. admin/user
echo " - 迁移 admin/user..."
cp "$BASE_DIR/user/user-admin.controller.ts" "$BASE_DIR/admin/user/user.controller.ts"
sed -i "s/@Controller('admin\/users')/@Controller('api\/admin\/users')/g" "$BASE_DIR/admin/user/user.controller.ts"
sed -i "s/UserAdminController/UserController/g" "$BASE_DIR/admin/user/user.controller.ts"
# 3. admin/merchant
echo " - 迁移 admin/merchant..."
cp "$BASE_DIR/merchant/merchant-admin.controller.ts" "$BASE_DIR/admin/merchant/merchant.controller.ts"
sed -i "s/@Controller('admin\/merchants')/@Controller('api\/admin\/merchants')/g" "$BASE_DIR/admin/merchant/merchant.controller.ts"
sed -i "s/MerchantAdminController/MerchantController/g" "$BASE_DIR/admin/merchant/merchant.controller.ts"
# 4. admin/room
echo " - 迁移 admin/room..."
cp "$BASE_DIR/room/room-admin.controller.ts" "$BASE_DIR/admin/room/room.controller.ts"
sed -i "s/@Controller('admin\/rooms')/@Controller('api\/admin\/rooms')/g" "$BASE_DIR/admin/room/room.controller.ts"
sed -i "s/RoomAdminController/RoomController/g" "$BASE_DIR/admin/room/room.controller.ts"
# 5. admin/order
echo " - 迁移 admin/order..."
cp "$BASE_DIR/order/order-admin.controller.ts" "$BASE_DIR/admin/order/order.controller.ts"
sed -i "s/@Controller('admin\/orders')/@Controller('api\/admin\/orders')/g" "$BASE_DIR/admin/order/order.controller.ts"
sed -i "s/OrderAdminController/OrderController/g" "$BASE_DIR/admin/order/order.controller.ts"
# 6. admin/review
echo " - 迁移 admin/review..."
cp "$BASE_DIR/review/review-admin.controller.ts" "$BASE_DIR/admin/review/review.controller.ts"
sed -i "s/@Controller('admin\/reviews')/@Controller('api\/admin\/reviews')/g" "$BASE_DIR/admin/review/review.controller.ts"
sed -i "s/ReviewAdminController/ReviewController/g" "$BASE_DIR/admin/review/review.controller.ts"
# 7. admin/coupon
echo " - 迁移 admin/coupon..."
cp "$BASE_DIR/coupon/coupon-admin.controller.ts" "$BASE_DIR/admin/coupon/coupon.controller.ts"
sed -i "s/@Controller('admin\/coupons')/@Controller('api\/admin\/coupons')/g" "$BASE_DIR/admin/coupon/coupon.controller.ts"
sed -i "s/CouponAdminController/CouponController/g" "$BASE_DIR/admin/coupon/coupon.controller.ts"
# 8. admin/activity
echo " - 迁移 admin/activity..."
cp "$BASE_DIR/activity/activity-admin.controller.ts" "$BASE_DIR/admin/activity/activity.controller.ts"
sed -i "s/@Controller('admin\/activity')/@Controller('api\/admin\/activity')/g" "$BASE_DIR/admin/activity/activity.controller.ts"
sed -i "s/ActivityAdminController/ActivityController/g" "$BASE_DIR/admin/activity/activity.controller.ts"
# 9. admin/config
echo " - 迁移 admin/config..."
cp "$BASE_DIR/config/config.controller.ts" "$BASE_DIR/admin/config/"
cp "$BASE_DIR/config/config.service.ts" "$BASE_DIR/admin/config/"
cp "$BASE_DIR/config/config.module.ts" "$BASE_DIR/admin/config/"
cp -r "$BASE_DIR/config/dto" "$BASE_DIR/admin/config/"
sed -i "s/@Controller('admin\/config')/@Controller('api\/admin\/config')/g" "$BASE_DIR/admin/config/config.controller.ts"
# 10. admin/finance
echo " - 迁移 admin/finance..."
cp "$BASE_DIR/finance/account-admin.controller.ts" "$BASE_DIR/admin/finance/account.controller.ts"
cp "$BASE_DIR/finance/transaction-admin.controller.ts" "$BASE_DIR/admin/finance/transaction.controller.ts"
cp "$BASE_DIR/finance/withdrawal-admin.controller.ts" "$BASE_DIR/admin/finance/withdrawal.controller.ts"
cp "$BASE_DIR/finance/settlement-admin.controller.ts" "$BASE_DIR/admin/finance/settlement.controller.ts"
cp "$BASE_DIR/finance/reconciliation-admin.controller.ts" "$BASE_DIR/admin/finance/reconciliation.controller.ts"
cp "$BASE_DIR/finance/report-admin.controller.ts" "$BASE_DIR/admin/finance/report.controller.ts"
sed -i "s/@Controller('admin\/finance\/accounts')/@Controller('api\/admin\/finance\/accounts')/g" "$BASE_DIR/admin/finance/account.controller.ts"
sed -i "s/@Controller('admin\/finance\/transactions')/@Controller('api\/admin\/finance\/transactions')/g" "$BASE_DIR/admin/finance/transaction.controller.ts"
sed -i "s/@Controller('admin\/finance\/withdrawals')/@Controller('api\/admin\/finance\/withdrawals')/g" "$BASE_DIR/admin/finance/withdrawal.controller.ts"
sed -i "s/@Controller('admin\/finance\/settlements')/@Controller('api\/admin\/finance\/settlements')/g" "$BASE_DIR/admin/finance/settlement.controller.ts"
sed -i "s/@Controller('admin\/finance\/reconciliations')/@Controller('api\/admin\/finance\/reconciliations')/g" "$BASE_DIR/admin/finance/reconciliation.controller.ts"
sed -i "s/@Controller('admin\/finance\/reports')/@Controller('api\/admin\/finance\/reports')/g" "$BASE_DIR/admin/finance/report.controller.ts"
# ============================================
# 公共模块迁移
# ============================================
echo ""
echo "📦 迁移公共模块..."
# 1. shared/room
echo " - 迁移 shared/room..."
cp "$BASE_DIR/room/room-public.controller.ts" "$BASE_DIR/shared/room/room.controller.ts"
sed -i "s/@Controller('rooms')/@Controller('api\/public\/rooms')/g" "$BASE_DIR/shared/room/room.controller.ts"
sed -i "s/RoomPublicController/RoomController/g" "$BASE_DIR/shared/room/room.controller.ts"
# 2. shared/merchant
echo " - 迁移 shared/merchant..."
cp "$BASE_DIR/merchant/merchant-public.controller.ts" "$BASE_DIR/shared/merchant/merchant.controller.ts"
sed -i "s/@Controller('merchants')/@Controller('api\/public\/merchants')/g" "$BASE_DIR/shared/merchant/merchant.controller.ts"
sed -i "s/MerchantPublicController/MerchantController/g" "$BASE_DIR/shared/merchant/merchant.controller.ts"
# 3. shared/activity
echo " - 迁移 shared/activity..."
cp "$BASE_DIR/activity/activity-public.controller.ts" "$BASE_DIR/shared/activity/activity.controller.ts"
sed -i "s/@Controller('activity')/@Controller('api\/public\/activity')/g" "$BASE_DIR/shared/activity/activity.controller.ts"
sed -i "s/ActivityPublicController/ActivityController/g" "$BASE_DIR/shared/activity/activity.controller.ts"
# 4. shared/upload
echo " - 迁移 shared/upload..."
cp "$BASE_DIR/upload/upload.controller.ts" "$BASE_DIR/shared/upload/"
cp "$BASE_DIR/upload/upload.service.ts" "$BASE_DIR/shared/upload/"
cp "$BASE_DIR/upload/upload.module.ts" "$BASE_DIR/shared/upload/"
# 修改 upload controller 的多个路由前缀
sed -i "s/@Controller('upload')/@Controller('api\/user\/upload')/g" "$BASE_DIR/shared/upload/upload.controller.ts"
sed -i "s/@Controller('seller\/upload')/@Controller('api\/merchant\/upload')/g" "$BASE_DIR/shared/upload/upload.controller.ts"
sed -i "s/@Controller('admin\/upload')/@Controller('api\/admin\/upload')/g" "$BASE_DIR/shared/upload/upload.controller.ts"
echo ""
echo "✅ 文件复制和修改完成!"
echo ""
echo "⚠️ 接下来需要:"
echo "1. 创建各端的总模块文件(user.module.ts, merchant.module.ts等)"
echo "2. 更新 app.module.ts"
echo "3. 创建官网模块"
echo "4. 更新前端 API 路径"
+204
View File
@@ -0,0 +1,204 @@
const fs = require('fs');
const path = require('path');
const serverModulesPath = path.join(__dirname, '../apps/server/src/modules');
// 模块迁移映射
const migrations = {
user: [
{ from: 'auth/auth.controller.ts', to: 'user/auth/auth.controller.ts', oldPrefix: 'auth', newPrefix: 'api/user/auth' },
{ from: 'auth/auth.service.ts', to: 'user/auth/auth.service.ts' },
{ from: 'auth/auth.module.ts', to: 'user/auth/auth.module.ts' },
{ from: 'auth/dto', to: 'user/auth/dto', isDir: true },
{ from: 'user/user-user.controller.ts', to: 'user/profile/profile.controller.ts', oldPrefix: 'user', newPrefix: 'api/user/profile' },
{ from: 'user/user.service.ts', to: 'user/profile/profile.service.ts' },
{ from: 'guest/guest.controller.ts', to: 'user/guest/guest.controller.ts', oldPrefix: 'user/guests', newPrefix: 'api/user/guests' },
{ from: 'guest/guest.service.ts', to: 'user/guest/guest.service.ts' },
{ from: 'guest/guest.module.ts', to: 'user/guest/guest.module.ts' },
{ from: 'guest/dto', to: 'user/guest/dto', isDir: true },
{ from: 'order/order-user.controller.ts', to: 'user/order/order.controller.ts', oldPrefix: 'orders', newPrefix: 'api/user/orders' },
{ from: 'review/review-user.controller.ts', to: 'user/review/review.controller.ts', oldPrefix: 'reviews', newPrefix: 'api/user/reviews' },
{ from: 'coupon/coupon-user.controller.ts', to: 'user/coupon/coupon.controller.ts', oldPrefix: 'user/coupons', newPrefix: 'api/user/coupons' },
{ from: 'finance/finance-user.controller.ts', to: 'user/finance/finance.controller.ts', oldPrefix: 'user/finance', newPrefix: 'api/user/finance' },
{ from: 'finance/withdrawal-user.controller.ts', to: 'user/finance/withdrawal.controller.ts', oldPrefix: 'user/finance/withdrawals', newPrefix: 'api/user/finance/withdrawals' },
{ from: 'activity/activity-user.controller.ts', to: 'user/activity/activity.controller.ts', oldPrefix: 'user/activity/invite', newPrefix: 'api/user/activity/invite' },
],
merchant: [
{ from: 'seller-auth/seller-auth.controller.ts', to: 'merchant/auth/auth.controller.ts', oldPrefix: 'seller/auth', newPrefix: 'api/merchant/auth' },
{ from: 'seller-auth/seller-auth.service.ts', to: 'merchant/auth/auth.service.ts' },
{ from: 'seller-auth/seller-auth.module.ts', to: 'merchant/auth/auth.module.ts' },
{ from: 'seller-auth/dto', to: 'merchant/auth/dto', isDir: true },
{ from: 'merchant/merchant-seller.controller.ts', to: 'merchant/profile/profile.controller.ts', oldPrefix: 'seller/merchant', newPrefix: 'api/merchant/profile' },
{ from: 'merchant/statistics-seller.controller.ts', to: 'merchant/statistics/statistics.controller.ts', oldPrefix: 'seller/statistics', newPrefix: 'api/merchant/statistics' },
{ from: 'room/room-seller.controller.ts', to: 'merchant/room/room.controller.ts', oldPrefix: 'seller/rooms', newPrefix: 'api/merchant/rooms' },
{ from: 'room-calendar/room-calendar.controller.ts', to: 'merchant/room-calendar/room-calendar.controller.ts', oldPrefix: 'seller/room-calendar', newPrefix: 'api/merchant/room-calendar' },
{ from: 'room-calendar/room-calendar.service.ts', to: 'merchant/room-calendar/room-calendar.service.ts' },
{ from: 'room-calendar/room-calendar.module.ts', to: 'merchant/room-calendar/room-calendar.module.ts' },
{ from: 'room-calendar/dto', to: 'merchant/room-calendar/dto', isDir: true },
{ from: 'order/order-seller.controller.ts', to: 'merchant/order/order.controller.ts', oldPrefix: 'seller/orders', newPrefix: 'api/merchant/orders' },
{ from: 'review/review-seller.controller.ts', to: 'merchant/review/review.controller.ts', oldPrefix: 'seller/reviews', newPrefix: 'api/merchant/reviews' },
{ from: 'finance/transaction-seller.controller.ts', to: 'merchant/finance/transaction.controller.ts', oldPrefix: 'merchant/finance/transactions', newPrefix: 'api/merchant/finance/transactions' },
{ from: 'finance/withdrawal-merchant.controller.ts', to: 'merchant/finance/withdrawal.controller.ts', oldPrefix: 'merchant/finance/withdrawals', newPrefix: 'api/merchant/finance/withdrawals' },
{ from: 'finance/settlement-merchant.controller.ts', to: 'merchant/finance/settlement.controller.ts', oldPrefix: 'merchant/finance/settlements', newPrefix: 'api/merchant/finance/settlements' },
],
admin: [
{ from: 'admin-auth/admin-auth.controller.ts', to: 'admin/auth/auth.controller.ts', oldPrefix: 'admin/auth', newPrefix: 'api/admin/auth' },
{ from: 'admin-auth/admin-auth.service.ts', to: 'admin/auth/auth.service.ts' },
{ from: 'admin-auth/admin-auth.module.ts', to: 'admin/auth/auth.module.ts' },
{ from: 'admin-auth/dto', to: 'admin/auth/dto', isDir: true },
{ from: 'user/user-admin.controller.ts', to: 'admin/user/user.controller.ts', oldPrefix: 'admin/users', newPrefix: 'api/admin/users' },
{ from: 'merchant/merchant-admin.controller.ts', to: 'admin/merchant/merchant.controller.ts', oldPrefix: 'admin/merchants', newPrefix: 'api/admin/merchants' },
{ from: 'room/room-admin.controller.ts', to: 'admin/room/room.controller.ts', oldPrefix: 'admin/rooms', newPrefix: 'api/admin/rooms' },
{ from: 'order/order-admin.controller.ts', to: 'admin/order/order.controller.ts', oldPrefix: 'admin/orders', newPrefix: 'api/admin/orders' },
{ from: 'review/review-admin.controller.ts', to: 'admin/review/review.controller.ts', oldPrefix: 'admin/reviews', newPrefix: 'api/admin/reviews' },
{ from: 'coupon/coupon-admin.controller.ts', to: 'admin/coupon/coupon.controller.ts', oldPrefix: 'admin/coupons', newPrefix: 'api/admin/coupons' },
{ from: 'activity/activity-admin.controller.ts', to: 'admin/activity/activity.controller.ts', oldPrefix: 'admin/activity', newPrefix: 'api/admin/activity' },
{ from: 'config/config.controller.ts', to: 'admin/config/config.controller.ts', oldPrefix: 'admin/config', newPrefix: 'api/admin/config' },
{ from: 'config/config.service.ts', to: 'admin/config/config.service.ts' },
{ from: 'config/config.module.ts', to: 'admin/config/config.module.ts' },
{ from: 'config/dto', to: 'admin/config/dto', isDir: true },
{ from: 'finance/account-admin.controller.ts', to: 'admin/finance/account.controller.ts', oldPrefix: 'admin/finance/accounts', newPrefix: 'api/admin/finance/accounts' },
{ from: 'finance/transaction-admin.controller.ts', to: 'admin/finance/transaction.controller.ts', oldPrefix: 'admin/finance/transactions', newPrefix: 'api/admin/finance/transactions' },
{ from: 'finance/withdrawal-admin.controller.ts', to: 'admin/finance/withdrawal.controller.ts', oldPrefix: 'admin/finance/withdrawals', newPrefix: 'api/admin/finance/withdrawals' },
{ from: 'finance/settlement-admin.controller.ts', to: 'admin/finance/settlement.controller.ts', oldPrefix: 'admin/finance/settlements', newPrefix: 'api/admin/finance/settlements' },
{ from: 'finance/reconciliation-admin.controller.ts', to: 'admin/finance/reconciliation.controller.ts', oldPrefix: 'admin/finance/reconciliations', newPrefix: 'api/admin/finance/reconciliations' },
{ from: 'finance/report-admin.controller.ts', to: 'admin/finance/report.controller.ts', oldPrefix: 'admin/finance/reports', newPrefix: 'api/admin/finance/reports' },
],
shared: [
{ from: 'room/room-public.controller.ts', to: 'shared/room/room.controller.ts', oldPrefix: 'rooms', newPrefix: 'api/public/rooms' },
{ from: 'merchant/merchant-public.controller.ts', to: 'shared/merchant/merchant.controller.ts', oldPrefix: 'merchants', newPrefix: 'api/public/merchants' },
{ from: 'activity/activity-public.controller.ts', to: 'shared/activity/activity.controller.ts', oldPrefix: 'activity', newPrefix: 'api/public/activity' },
{ from: 'upload/upload.controller.ts', to: 'shared/upload/upload.controller.ts',
replacements: [
{ old: "@Controller('upload')", new: "@Controller('api/user/upload')" },
{ old: "@Controller('seller/upload')", new: "@Controller('api/merchant/upload')" },
{ old: "@Controller('admin/upload')", new: "@Controller('api/admin/upload')" },
]
},
{ from: 'upload/upload.service.ts', to: 'shared/upload/upload.service.ts' },
{ from: 'upload/upload.module.ts', to: 'shared/upload/upload.module.ts' },
],
};
// 复制并修改文件
function copyAndModifyFile(fromPath, toPath, modifications) {
const fullFromPath = path.join(serverModulesPath, fromPath);
const fullToPath = path.join(serverModulesPath, toPath);
if (!fs.existsSync(fullFromPath)) {
console.log(`⚠️ 源文件不存在: ${fromPath}`);
return;
}
// 确保目标目录存在
const toDir = path.dirname(fullToPath);
if (!fs.existsSync(toDir)) {
fs.mkdirSync(toDir, { recursive: true });
}
// 读取文件内容
let content = fs.readFileSync(fullFromPath, 'utf8');
// 应用修改
if (modifications) {
if (modifications.oldPrefix && modifications.newPrefix) {
// 替换 @Controller 装饰器中的路由前缀
content = content.replace(
new RegExp(`@Controller\\(['"]${modifications.oldPrefix.replace(/\//g, '\\/')}['"]\\)`, 'g'),
`@Controller('${modifications.newPrefix}')`
);
}
if (modifications.replacements) {
modifications.replacements.forEach(({ old, new: newStr }) => {
content = content.replace(new RegExp(old.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), newStr);
});
}
}
// 写入新文件
fs.writeFileSync(fullToPath, content, 'utf8');
console.log(`✅ 已复制: ${fromPath} -> ${toPath}`);
}
// 复制目录
function copyDirectory(fromPath, toPath) {
const fullFromPath = path.join(serverModulesPath, fromPath);
const fullToPath = path.join(serverModulesPath, toPath);
if (!fs.existsSync(fullFromPath)) {
console.log(`⚠️ 源目录不存在: ${fromPath}`);
return;
}
if (!fs.existsSync(fullToPath)) {
fs.mkdirSync(fullToPath, { recursive: true });
}
const files = fs.readdirSync(fullFromPath);
files.forEach(file => {
const fromFile = path.join(fullFromPath, file);
const toFile = path.join(fullToPath, file);
if (fs.statSync(fromFile).isDirectory()) {
copyDirectory(path.join(fromPath, file), path.join(toPath, file));
} else {
fs.copyFileSync(fromFile, toFile);
}
});
console.log(`✅ 已复制目录: ${fromPath} -> ${toPath}`);
}
// 执行迁移
console.log('🚀 开始模块重构...\n');
Object.entries(migrations).forEach(([category, items]) => {
console.log(`\n📦 处理 ${category} 模块:`);
items.forEach(item => {
if (item.isDir) {
copyDirectory(item.from, item.to);
} else {
copyAndModifyFile(item.from, item.to, {
oldPrefix: item.oldPrefix,
newPrefix: item.newPrefix,
replacements: item.replacements
});
}
});
});
console.log('\n✨ 模块重构完成!');
console.log('\n⚠️ 注意:');
console.log('1. 需要手动创建各端的总模块文件(user.module.ts, merchant.module.ts, admin.module.ts等)');
console.log('2. 需要更新 app.module.ts 注册新模块');
console.log('3. 需要更新前端 API 调用路径');
console.log('4. Service 和 Module 文件可能需要手动调整导入路径');