
services:
  # MySQL
  mysql:
    image: mysql:8.0
    container_name: hzhub-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-hzhub123}
      MYSQL_DATABASE: hzhub
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - hzhub-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-hzhub123}"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Redis
  redis:
    image: redis:7-alpine
    container_name: hzhub-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - hzhub-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Weaviate (向量数据库)
  weaviate:
    image: semitechnologies/weaviate:1.25.0
    container_name: hzhub-weaviate
    ports:
      - "28080:8080"
    environment:
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'none'
      ENABLE_MODULES: ''
      CLUSTER_HOSTNAME: 'node1'
    volumes:
      - weaviate_data:/var/lib/weaviate
    networks:
      - hzhub-network

  # MinIO (对象存储)
  minio:
    image: minio/minio:latest
    container_name: hzhub-minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: hzhub
      MINIO_ROOT_PASSWORD: hzhub123456
    command: server /data --console-address ":9001"
    volumes:
      - minio_data:/data
    networks:
      - hzhub-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  # hzhub-gateway (API网关)
  hzhub-gateway:
    build:
      context: ../hzhub-gateway
      dockerfile: Dockerfile
    container_name: hzhub-gateway
    ports:
      - "8080:8080"
    environment:
      SPRING_PROFILES_ACTIVE: prod
      REDIS_HOST: hzhub-redis
      REDIS_PORT: 6379
      AI_HOST: hzhub-ai
      AI_PORT: 6039
      SYSTEM_HOST: hzhub-system
      SYSTEM_PORT: 8083
      ERP_HOST: hzhub-erp
      ERP_PORT: 8082
      JWT_SECRET: ${JWT_SECRET:-abcdefghijklmnopqrstuvwxyz}
    depends_on:
      redis:
        condition: service_healthy
    networks:
      - hzhub-network

  # hzhub-system (系统管理服务)
  hzhub-system:
    build:
      context: ../hzhub-system
      dockerfile: Dockerfile
    container_name: hzhub-system
    ports:
      - "8083:8083"
    environment:
      SPRING_PROFILES_ACTIVE: prod
      DB_HOST: hzhub-mysql
      DB_PORT: 3306
      DB_NAME: hzhub
      DB_USERNAME: root
      DB_PASSWORD: hzhub123
      REDIS_HOST: hzhub-redis
      REDIS_PORT: 6379
      JWT_SECRET: ${JWT_SECRET:-abcdefghijklmnopqrstuvwxyz}
      ADMIN_URL: http://hzhub-monitor-admin:9090/admin
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - hzhub-network

  # hzhub-ai (AI服务)
  hzhub-ai:
    build:
      context: ../hzhub-ai
      dockerfile: Dockerfile
    container_name: hzhub-ai
    ports:
      - "6039:6039"
    environment:
      SPRING_PROFILES_ACTIVE: dev
      SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_URL: jdbc:mysql://hzhub-mysql:3306/hzhub?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
      SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_USERNAME: root
      SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_PASSWORD: hzhub123
      SPRING_DATA_REDIS_HOST: hzhub-redis
      SPRING_DATA_REDIS_PORT: 6379
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - hzhub-network

  # n8n (工作流)
  n8n:
    image: n8nio/n8n:latest
    container_name: hzhub-n8n
    environment:
      N8N_BASIC_AUTH_ACTIVE: "true"
      N8N_BASIC_AUTH_USER: ${N8N_USER:-admin}
      N8N_BASIC_AUTH_PASSWORD: ${N8N_PASSWORD:-hzhub123}
    ports:
      - "5678:5678"
    volumes:
      - n8n_data:/home/node/.n8n
    networks:
      - hzhub-network

  # hzhub-admin (前端管理后台)
  hzhub-admin:
    build:
      context: ../hzhub-admin
      dockerfile: Dockerfile
    container_name: hzhub-admin
    ports:
      - "5666:5666"
    environment:
      - NGINX_PORT=5666
      - UPSTREAM_URL=http://hzhub-gateway:8080
    depends_on:
      - hzhub-gateway
    networks:
      - hzhub-network

  # hzhub-portal-employee (员工门户)
  hzhub-portal-employee:
    build:
      context: ../hzhub-portal-employee
      dockerfile: Dockerfile
    container_name: hzhub-portal-employee
    ports:
      - "5137:5137"
    environment:
      UPSTREAM_URL: http://hzhub-gateway:8080
    depends_on:
      - hzhub-gateway
    networks:
      - hzhub-network

  # hzhub-erp (ERP服务)
  hzhub-erp:
    build:
      context: ../hzhub-erp
      dockerfile: Dockerfile
    container_name: hzhub-erp
    ports:
      - "8082:8082"
    environment:
      SPRING_PROFILES_ACTIVE: dev
      ERP_DB_HOST: ${ERP_DB_HOST:-192.168.x.x}
      ERP_DB_PORT: ${ERP_DB_PORT:-1433}
      ERP_DB_NAME: ${ERP_DB_NAME:-ERP}
      ERP_DB_USERNAME: ${ERP_DB_USERNAME:-sa}
      ERP_DB_PASSWORD: ${ERP_DB_PASSWORD:-}
      ERP_JWT_SECRET: ${ERP_JWT_SECRET:-abcdefghijklmnopqrstuvwxyz}
    networks:
      - hzhub-network

  # hzhub-portal-dealer (经销商门户)
  hzhub-portal-dealer:
    build:
      context: ../hzhub-portal-dealer
      dockerfile: Dockerfile
    container_name: hzhub-portal-dealer
    ports:
      - "5138:5138"
    environment:
      UPSTREAM_URL: http://hzhub-gateway:8080
    depends_on:
      - hzhub-gateway
    networks:
      - hzhub-network

volumes:
  mysql_data:
  redis_data:
  weaviate_data:
  minio_data:
  n8n_data:

networks:
  hzhub-network:
    driver: bridge
