diff --git a/src/main/java/com/example/building/entity/OrderItem.java b/src/main/java/com/example/building/entity/OrderItem.java index 317c015..fd8214a 100644 --- a/src/main/java/com/example/building/entity/OrderItem.java +++ b/src/main/java/com/example/building/entity/OrderItem.java @@ -26,6 +26,11 @@ public class OrderItem { */ private String productId; + /** + * 分类ID(冗余) + */ + private String categoryId; + /** * 商品名称(冗余) */ @@ -41,11 +46,36 @@ public class OrderItem { */ private String unit; + /** + * 成本价(冗余) + */ + private BigDecimal costPrice; + /** * 销售单价(当时标价) */ private BigDecimal price; + /** + * 商品图片URL(冗余) + */ + private String imageUrl; + + /** + * 商品条码(冗余) + */ + private String barcode; + + /** + * 库存预警阈值(冗余) + */ + private Integer stockAlert; + + /** + * 商品描述(冗余) + */ + private String description; + /** * 数量 */ diff --git a/src/main/java/com/example/building/service/impl/OrderServiceImpl.java b/src/main/java/com/example/building/service/impl/OrderServiceImpl.java index 4adb6c4..3508fd1 100644 --- a/src/main/java/com/example/building/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/example/building/service/impl/OrderServiceImpl.java @@ -102,9 +102,15 @@ public class OrderServiceImpl implements OrderService { item.setItemId(UUID.randomUUID().toString()); item.setOrderId(order.getOrderId()); item.setProductId(product.getProductId()); + item.setCategoryId(product.getCategoryId()); item.setProductName(product.getName()); item.setProductSpec(product.getSpec()); item.setUnit(product.getUnit()); + item.setCostPrice(product.getCostPrice()); + item.setImageUrl(product.getImageUrl()); + item.setBarcode(product.getBarcode()); + item.setStockAlert(product.getStockAlert()); + item.setDescription(product.getDescription()); item.setPrice(price); item.setQuantity(itemDTO.getQuantity()); item.setSubtotal(subtotal); @@ -347,9 +353,15 @@ public class OrderServiceImpl implements OrderService { item.setItemId(UUID.randomUUID().toString()); item.setOrderId(orderId); item.setProductId(product.getProductId()); + item.setCategoryId(product.getCategoryId()); item.setProductName(product.getName()); item.setProductSpec(product.getSpec()); item.setUnit(product.getUnit()); + item.setCostPrice(product.getCostPrice()); + item.setImageUrl(product.getImageUrl()); + item.setBarcode(product.getBarcode()); + item.setStockAlert(product.getStockAlert()); + item.setDescription(product.getDescription()); item.setPrice(price); item.setQuantity(itemDTO.getQuantity()); item.setSubtotal(subtotal); diff --git a/src/main/resources/db/migration/V10__add_order_item_product_fields.sql b/src/main/resources/db/migration/V10__add_order_item_product_fields.sql new file mode 100644 index 0000000..cf45bef --- /dev/null +++ b/src/main/resources/db/migration/V10__add_order_item_product_fields.sql @@ -0,0 +1,7 @@ +-- 订单明细表增加商品冗余字段 +ALTER TABLE order_items ADD COLUMN IF NOT EXISTS category_id VARCHAR(36); +ALTER TABLE order_items ADD COLUMN IF NOT EXISTS cost_price DECIMAL(10,2); +ALTER TABLE order_items ADD COLUMN IF NOT EXISTS image_url VARCHAR(500); +ALTER TABLE order_items ADD COLUMN IF NOT EXISTS barcode VARCHAR(50); +ALTER TABLE order_items ADD COLUMN IF NOT EXISTS stock_alert INTEGER; +ALTER TABLE order_items ADD COLUMN IF NOT EXISTS description TEXT; \ No newline at end of file