Overview
The Supplier Service (jea-proveedor) manages supplier master data including company information, contact details, and supplier lifecycle. It provides supplier information to the Purchase service for procurement operations. Database: PostgreSQL (proveedor-db)
Port: Dynamic (configured via Eureka)
Core Entities
Proveedor
Supplier master data. Location:jea-proveedor/src/main/java/com/example/jeaproveedor/entity/Proveedor.java:6
Fields:
id(Long) - Primary keyruc(String) - Tax identification number (RUC)nombre(String) - Supplier company nametelefono(String) - Phone numberdireccion(String) - Addresscorreo(String) - Email addressestado(Boolean) - Active status (default: true)
proveedor
Lifecycle Hooks:
@PrePersist- Setsestadoto true on creation
Key Components
Controllers
ProveedorController
Location:jea-proveedor/src/main/java/com/example/jeaproveedor/Controller/ProveedorController.java:14
Endpoints:
GET /proveedor- List all suppliersGET /proveedor/{id}- Get supplier by IDPOST /proveedor- Create new supplierPUT /proveedor/{id}- Update supplierDELETE /proveedor/{id}- Delete supplierPUT /proveedor/desactivar/{id}- Deactivate supplierPUT /proveedor/activar/{id}- Activate supplierGET /proveedor/buscar?ruc={ruc}- Search by RUC
- RUC-based supplier lookup
- Activation/deactivation endpoints
- Full CRUD operations
- Standard REST conventions
Services
ProveedorService
Location:jea-proveedor/src/main/java/com/example/jeaproveedor/service/ProveedorService.java
Implementation: ProveedorServiceImpl.java
Key Methods:
listarTodos()- List all suppliersobtenerPorId()- Find by IDcrear()- Create new supplieractualizar()- Update supplier informationeliminar()- Delete supplierdesactivar()- Deactivate supplier (soft delete)activar()- Reactivate supplierbuscarPorRuc()- Find by RUC (tax ID)
Repositories
ProveedorRepository
Location:jea-proveedor/src/main/java/com/example/jeaproveedor/Repository/ProveedorRepository.java
Extends JpaRepository<Proveedor, Long>
Provides custom query methods:
findByRuc()- Lookup supplier by RUCfindByEstado()- Filter by active status
Dependencies
Spring Boot Version: 3.1.3 Spring Cloud Version: 2022.0.2 Key Dependencies:spring-boot-starter-data-jpa- JPA/Hibernatespring-boot-starter-web- REST APIspring-boot-starter-validation- Bean validationspring-cloud-starter-netflix-eureka-client:4.0.3- Service discoveryspring-cloud-starter-config:4.0.4- Centralized configurationspringdoc-openapi-starter-webmvc-ui:2.0.2- OpenAPI/Swagger UIpostgresql- PostgreSQL driverlombok- Code generation
Configuration
Config File:config-data/jea-proveedor-service.yml
Key Settings:
Database Schema
Main Tables:proveedor- Supplier master data- Primary key:
id - Recommended unique constraint:
ruc - Index on
rucfor fast lookups
- Primary key:
Key Features
- Supplier master data management
- RUC-based supplier identification
- Active/inactive status tracking
- Soft delete via activation/deactivation
- RUC-based supplier search
- PostgreSQL database (same as Customer service)
- OpenAPI/Swagger documentation
- Eureka service discovery integration
- Centralized configuration via Config Server
Integration Points
Consumed by:
- Purchase Service - Fetches supplier data for purchase transactions via
ProveedorFeign
APIs Exposed:
- Supplier CRUD operations
- Supplier lookup by ID
- Supplier search by RUC
- Supplier activation/deactivation
- Supplier listing
Usage Pattern
The Purchase service references suppliers by ID:Validation Rules
RUC (Tax ID)
- Unique identifier for suppliers
- Should be unique across all suppliers
- Used for legal and tax identification
- Format varies by country (Peru: 11 digits)
Supplier Status
estado = true- Active supplier, can be used in purchasesestado = false- Inactive supplier (soft deleted)- Deactivation is preferred over deletion for audit trail
Status Management
Activation/Deactivation
The service provides explicit endpoints for status management:- Clear intent vs generic update
- Audit-friendly operations
- Prevents accidental deletions
- Maintains referential integrity in purchases
- Deactivate: Supplier no longer in business, poor performance, contract ended
- Activate: Re-engaging with previous supplier, resolving issues
Comparison: Customer vs Supplier
Both services share similar architecture with key differences:| Aspect | Customer (Cliente) | Supplier (Proveedor) |
|---|---|---|
| Identifier | DNI (personal ID) | RUC (tax ID) |
| Database | PostgreSQL | PostgreSQL |
| Status Field | activo (Boolean) | estado (Boolean) |
| Status Endpoints | Managed via update | Explicit activate/deactivate |
| Unique, required | Not unique constraint | |
| Used By | Sales, Orders | Purchases |
Data Privacy Considerations
Business Information
The Supplier service stores business-related data:- Tax identification (RUC)
- Company information
- Contact details
- Implement access control at API Gateway level
- Log access for audit trails
- Maintain data accuracy for tax/legal compliance
- Support data export for reporting
Database Choice: PostgreSQL
Why PostgreSQL?
- Data Integrity - ACID compliance for supplier master data
- Consistency - Same database as Customer service for similar data types
- Reliability - Critical business relationships require stable storage
- Future Features - Support for complex supplier hierarchies, JSON fields
Benefits for Supplier Management
- Strong foreign key constraints
- Better support for complex queries (if needed for reporting)
- Robust transaction handling
- Reliable for critical business data
Supplier Lifecycle
1. Registration
- Create new supplier with basic information
estadoautomatically set totrue- RUC should be unique
2. Active Operations
- Supplier used in purchase transactions
- Information updated as needed via
PUT /proveedor/{id}
3. Deactivation
- Set
estado = false - Supplier cannot be used in new purchases
- Historical purchases remain intact
4. Reactivation (if needed)
- Set
estado = true - Supplier available for new purchases again
5. Permanent Deletion (rare)
- Physical deletion from database
- Only if no purchase history exists
- Generally discouraged in favor of deactivation
Best Practices
Supplier Validation
-
RUC Validation
- Validate RUC format before saving
- Check for duplicates
- Verify with tax authority API (if available)
-
Contact Information
- Ensure at least one contact method (phone or email)
- Validate email format
- Store multiple contacts if needed (future enhancement)
-
Address Validation
- Complete address for legal documents
- Support multiple addresses (future: billing, warehouse)
Status Management
-
Use Deactivation Over Deletion
- Maintains audit trail
- Preserves purchase history
- Allows reactivation
-
Status Filtering
- Default to showing active suppliers only
- Provide option to view all/inactive
- Warn users when selecting inactive supplier
Future Enhancements
Potential additions:- Supplier categories/classifications
- Supplier ratings and reviews
- Payment terms (net 30, net 60, etc.)
- Credit limits for purchases
- Multiple contacts per supplier
- Supplier documents (contracts, certificates)
- Product catalogs per supplier
- Supplier performance metrics
- Supplier onboarding workflow
- Integration with procurement systems