Export Service
The Export Service enables the Platon platform to generate and deliver resources in various formats (CSV, Excel, Word) to users.
It processes user requests, prepares resources, ensures fast access via caching, and logs operations to a central system.
Overview
The Export Service provides the following capabilities:
- Generate and export resources (CSV, Excel, Word)
- Apply user-provided parameters during resource generation
- Retrieve and process necessary parameters from the database
- Temporarily store resources in the file system and deliver them to users
- Manage caching for fast resource access
- Log errors and operations to the central system via NATS
Database Interactions
The Export Service performs the following database operations:
- Retrieve: Fetch export configurations from the database
- Params SQL Execution: Obtain necessary parameters during resource generation
- Transactional Handling: Ensure safe execution of parameter retrieval and resource creation
All operations are linked to the user session.
Architecture Components
- ExportResourceService: Main service that manages resource preparation, caching, and delivery to users
- ExportHandler: Handles resource generation logic based on format (CSV, Excel, Word)
- CacheOperation: Stores, updates, and clears cached resources
- DataBase: Executes SQL queries and retrieves parameters
- ThreadPoolTaskScheduler: Schedules periodic resource and cache updates
- RestSessionContext: Manages user session and request parameters
- ExportUtils: Determines and provides the appropriate ExportHandler
- Logging Service: Sends errors and successful operations to the central system (NATS)
- FileService: Downloads and handles Word and Excel template files
Resource Management Capabilities
- Generate resources in CSV, Excel, and Word formats and deliver them to users
- Merge user-provided parameters and request body data into the resource
- Temporarily store resources in the file system and automatically clean old files
- Use caching to reduce server load and improve response speed
- Log errors and successful operations to the central monitoring system
Cache and Performance
- Export resources are stored in cache
- Ensures fast access and reduces server load
- Cached resources are updated at specified intervals
- Old or unused resources are automatically removed
- Using cache reduces SQL queries and file generation overhead
Access Control
- User permissions control access to resources
- Roles and permissions determine access to specific export resources
- Admin users have access to all resources
Logging and Monitoring
- User requests and export operations are logged
- Errors and successful operations are sent to the central system via NATS
- Resource preparation and delivery are monitored
Temporary Files Management
- Temporary files are stored in the file system (
media/temp/) - Old files are automatically deleted daily at 12:00 AM
- Files are given unique MD5 hash-based names
- Generated files are delivered to the user from the file system
Handlers
CSV Handler
- Generates CSV files
- Adds UTF-8 BOM
- Inserts checksum into random rows
- Includes user data and request body in the file
Excel Handler
- Uses Excel template files with JXLS
- Inserts SQL parameters and request body into the template
- Adds checksum to protect certain rows
- Delivers the generated Excel file to the user
Word Handler
- Uses Word template files with Aspose Words
- Flattens nested maps and lists
- Replaces template placeholders with request body and SQL parameters
- Delivers the generated Word file to the user
Conclusion
The Export Service allows the Platon platform to deliver resources in multiple formats while ensuring fast performance.
It supports CSV, Excel, and Word formats, merges SQL parameters and user data, efficiently manages caching and temporary files, and logs errors and successful operations to the central system.