From abd1d32e14d649fd1b65c2df0a44de6ffdd30aab Mon Sep 17 00:00:00 2001 From: Agent Date: Tue, 31 Mar 2026 16:27:04 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A2=E5=8D=95=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81=E5=86=97=E4=BD=99=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=AE=8C=E6=95=B4=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/building/entity/OrderItem.java | 30 +++++++++++++++++++ .../service/impl/OrderServiceImpl.java | 12 ++++++++ .../V10__add_order_item_product_fields.sql | 7 +++++ 3 files changed, 49 insertions(+) create mode 100644 src/main/resources/db/migration/V10__add_order_item_product_fields.sql 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