Files
todo-backend/src/main/java/com/example/building/dto/CreateOrderRequest.java

132 lines
2.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.example.building.dto;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
/**
* 创建订单请求DTO
* 核心业务逻辑:
* 1. 计算订单原价(total_amount) = Σ(item.price × item.quantity)
* 2. 计算优惠金额(discount_amount) = total_amount × (100 - discount_rate) / 100
* 3. 计算实付金额(actual_amount) = total_amount - discount_amount
*/
public class CreateOrderRequest {
/**
* 客户ID
*/
private String customerId;
/**
* 订单明细
*/
@NotEmpty(message = "订单明细不能为空")
private List<OrderItemDTO> items;
/**
* 折扣率(百分比), 默认100
*/
private BigDecimal discountRate;
/**
* 备注
*/
private String remark;
/**
* 支付方式
*/
private String paymentMethod;
// Getters and Setters
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public List<OrderItemDTO> getItems() {
return items;
}
public void setItems(List<OrderItemDTO> items) {
this.items = items;
}
public BigDecimal getDiscountRate() {
return discountRate;
}
public void setDiscountRate(BigDecimal discountRate) {
this.discountRate = discountRate;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(String paymentMethod) {
this.paymentMethod = paymentMethod;
}
/**
* 订单明细项DTO
*/
public static class OrderItemDTO {
/**
* 商品ID
*/
@NotBlank(message = "商品ID不能为空")
private String productId;
/**
* 数量
*/
@NotNull(message = "数量不能为空")
private Integer quantity;
/**
* 销售单价(用户可自定义)
*/
private BigDecimal price;
// Getters and Setters
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
}
}