Overview
The Orders Service (jea-pedidos) manages customer orders with fulfillment tracking, delivery scheduling, and order status management. It serves as a pre-sales process before converting orders to actual sales. Database: MySQL (pedido-ms)
Port: Dynamic (configured via Eureka)
Core Entities
Pedido
Customer order header. Location:jea-pedidos/src/main/java/com/example/jeapedidos/entity/Pedido.java:13
Fields:
id(Integer) - Primary keycodigo(String) - Unique order codeserie(String) - Unique order seriesdescripcion(String) - Order descriptionestado(String) - Order status (default: “PENDIENTE”)clienteId(Long) - Customer ID referencecliente(Cliente) - Customer data (transient, from Cliente service)detalle(List<PedidoDetalle>) - Order line itemsfechaPedido(LocalDateTime) - Order creation timestamp (auto-set)fechaEntrega(LocalDate) - Delivery date (auto-set to 1 week after order)baseImponible(Double) - Taxable base amountigv(Double) - Tax amount (IGV)total(Double) - Total amountformapagoId(Long) - Payment method ID referenceformaPago(FormaPago) - Payment method data (transient)
pedido
Default Values:
fechaPedido: Current timestampfechaEntrega: Order date + 1 weekestado: “PENDIENTE”
- One-to-many with
PedidoDetalleviapedido_id - References
Cliente(external service) - References
FormaPago(external service)
PedidoDetalle
Order line item. Location:jea-pedidos/src/main/java/com/example/jeapedidos/entity/PedidoDetalle.java
Fields:
id(Long) - Primary keycantidad(Integer) - Quantity orderedprecioUnitario(Double) - Unit pricebaseImponible(Double) - Line taxable baseigv(Double) - Line tax amount (18%)total(Double) - Line totalproductoId(Long) - Product ID referenceproducto(Producto) - Product data (transient)
pedido_detalle
Relationships:
- Many-to-one with
Pedidoviapedido_id - References
Producto(from Catalog service)
Key Components
Controllers
PedidoController
Location:jea-pedidos/src/main/java/com/example/jeapedidos/controller/PedidoController.java:13
Endpoints:
POST /pedido- Create new orderGET /pedido- List all ordersGET /pedido/{id}- Get order by IDPUT /pedido/{id}- Update orderDELETE /pedido/{id}- Delete order
Services
PedidoService
Location:jea-pedidos/src/main/java/com/example/jeapedidos/service/PedidoService.java
Implementation: PedidoServiceImpl.java
Key Methods:
createPedido()- Create order with validationgetAllPedidos()- List all orders with customer/payment datagetPedidoById()- Get order with full detailsupdatePedido()- Update order detailsdeletePedido()- Delete order
Repositories
PedidoRepository
Location:jea-pedidos/src/main/java/com/example/jeapedidos/repository/PedidoRepository.java
Extends JpaRepository<Pedido, Integer>
Provides data access for order management.
Feign Clients
ProductoFeign
Location:jea-pedidos/src/main/java/com/example/jeapedidos/feing/ProductoFeign.java
Integrates with Catalog service for product data.
ClienteFeign
Location:jea-pedidos/src/main/java/com/example/jeapedidos/feing/ClienteFeign.java
Integrates with Customer service for customer data.
FormaPagoFeign
Location:jea-pedidos/src/main/java/com/example/jeapedidos/feing/FormaPagoFeign.java
Integrates with Payment service for payment method data.
CategoriaFeign
Location:jea-pedidos/src/main/java/com/example/jeapedidos/feing/CategoriaFeign.java
Integrates with Catalog service for category data.
Configuration
OpenAPIConfig
Location:jea-pedidos/src/main/java/com/example/jeapedidos/config/OpenAPIConfig.java
Swagger/OpenAPI documentation configuration.
DTOs
Transient DTOs (from other services)
Producto- Product data from Catalog serviceCliente- Customer data from Customer serviceFormaPago- Payment method from Payment serviceCategoria- Category data from Catalog service
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 configurationspring-cloud-starter-openfeign- Feign client for microservice communicationspring-cloud-starter-circuitbreaker-resilience4j- Circuit breaker patternspringdoc-openapi-starter-webmvc-ui:2.0.2- OpenAPI/Swagger UImysql-connector-j- MySQL driverlombok- Code generation
Configuration
Config File:config-data/jea-pedido-service.yml
Key Settings:
Database Schema
Main Tables:pedido- Order header- Primary key:
id - Unique constraints:
codigo,serie - Foreign keys:
cliente_id,formapago_id(references external services)
- Primary key:
pedido_detalle- Order line items- Primary key:
id - Foreign keys:
pedido_id→pedido.id,producto_id(external)
- Primary key:
Business Logic
Order Status Management
Orders track their lifecycle through theestado field:
- PENDIENTE - Default state for new orders
- Can be updated to other statuses (e.g., EN_PROCESO, ENTREGADO, CANCELADO)
Delivery Date Calculation
When an order is created:fechaPedido: Set to current timestampfechaEntrega: Automatically set to 1 week after order date- Both dates can be manually updated
Tax Calculation
Same as Sales and Purchase services:- Base Imponible: Sum of line item bases
- IGV (Tax): 18% of base imponible
- Total: Base imponible + IGV
Order vs Sale Distinction
- Orders (Pedidos): Pre-sales commitments, can be modified/cancelled
- Sales (Ventas): Completed transactions with invoice numbers
- Orders may be converted to sales after fulfillment
Key Features
- Customer order management with CRUD operations
- Order status tracking (PENDIENTE, etc.)
- Automatic delivery date calculation (1 week default)
- Multi-line item support
- Integration with Customer, Product, and Payment services
- Tax calculation (IGV at 18%)
- Unique order codes and series
- Circuit breaker for fault tolerance
- OpenAPI/Swagger documentation
- Eureka service discovery integration
Integration Points
Consumes:
- Catalog Service (
ProductoFeign,CategoriaFeign) - Product data and availability - Customer Service (
ClienteFeign) - Customer information - Payment Service (
FormaPagoFeign) - Payment method details
APIs Exposed:
- Order CRUD operations
- Order listing and retrieval
- Order status updates
Order Lifecycle
- Order Creation - Customer places order with PENDIENTE status
- Order Processing - Status updated as order is prepared
- Order Fulfillment - Delivery scheduled (fechaEntrega)
- Conversion to Sale - Order may be converted to Venta (Sale) upon completion
- Inventory Impact - No immediate inventory changes (reserved on conversion)
Differences from Sales Service
| Feature | Orders (Pedidos) | Sales (Ventas) |
|---|---|---|
| Purpose | Pre-sales, quotations | Completed transactions |
| Document Type | Order code/serie | Invoice serie/numero |
| Status | Tracked (PENDIENTE, etc.) | Not tracked |
| Delivery Date | Scheduled (fechaEntrega) | Not applicable |
| Inventory | No immediate impact | Reduces inventory |
| Modification | Can be updated/cancelled | Generally immutable |