Compare commits

..

14 Commits

Author SHA1 Message Date
Agent
3dd3e106dc fix: 修复分类管理缺少description字段问题
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-04 07:19:55 +00:00
Agent
1427538598 fix: 编辑订单时恢复旧库存并扣减新库存
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 12:25:39 +00:00
Agent
8f01832b65 fix: 创建商品时自动创建库存记录(初始为0)
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 07:35:52 +00:00
Agent
379df40aee fix: 修复updateOrderStatus方法中取消订单恢复库存逻辑
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 04:27:57 +00:00
Agent
a0aa1432ab feat: 订单创建时扣减库存,确认完成时不再扣减,取消时恢复库存
Some checks failed
continuous-integration/drone/push Build is failing
2026-04-03 04:19:20 +00:00
Agent
4da4b1f922 fix: 添加V14迁移为order_items表增加length,width,area字段
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 03:22:01 +00:00
Agent
c12912f1c5 fix: 订单列表增加异常捕获,防止查询明细失败导致整体失败
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 03:11:07 +00:00
Agent
5e7cdc1bc4 fix: 修复订单列表查询时可能出现的空指针问题
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 02:59:37 +00:00
Agent
4f39d3ec45 fix: 补充import java.util.List
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 16:42:34 +00:00
Agent
4ac409020a feat: 订单列表接口返回明细items,不需要单独查询
Some checks failed
continuous-integration/drone/push Build is failing
2026-04-01 16:39:45 +00:00
Agent
84324774da fix: V13迁移改为PostgreSQL语法
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:42:12 +00:00
Agent
c74a46b110 feat: 商品表增加长度、宽度、面积字段
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:37:22 +00:00
Agent
ed0138c777 feat: 新增获取所有商品接口(包括下架)用于商品管理
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:18:41 +00:00
Agent
0a62e19d51 feat: 订单明细增加长度、宽度、面积字段 2026-04-01 14:01:55 +00:00
12 changed files with 166 additions and 8 deletions

View File

@@ -79,6 +79,18 @@ public class ProductController {
return Result.success(productService.getProducts(categoryId, keyword, page, pageSize));
}
/**
* 获取所有商品(包括下架的,用于管理)
*/
@GetMapping("/all")
public Result<Page<Product>> getAllProducts(
@RequestParam(required = false) String categoryId,
@RequestParam(required = false) String keyword,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "20") Integer pageSize) {
return Result.success(productService.getAllProducts(categoryId, keyword, page, pageSize));
}
/**
* 获取商品详情
*/

View File

@@ -70,5 +70,20 @@ public class CreateOrderRequest {
* 销售单价(用户可自定义)
*/
private BigDecimal price;
/**
* 长度(cm)
*/
private BigDecimal length;
/**
* 宽度(cm)
*/
private BigDecimal width;
/**
* 面积(m²)
*/
private BigDecimal area;
}
}

View File

@@ -36,6 +36,11 @@ public class Category {
*/
private String icon;
/**
* 描述
*/
private String description;
/**
* 状态: 1启用 0禁用
*/

View File

@@ -5,6 +5,7 @@ import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* 订单实体类
@@ -109,4 +110,10 @@ public class Order {
*/
@TableField("deleted")
private Integer deleted;
/**
* 订单明细(不存数据库仅用于API返回)
*/
@TableField(exist = false)
private List<OrderItem> items;
}

View File

@@ -86,6 +86,21 @@ public class OrderItem {
*/
private BigDecimal subtotal;
/**
* 长度(cm)
*/
private BigDecimal length;
/**
* 宽度(cm)
*/
private BigDecimal width;
/**
* 面积(m²)
*/
private BigDecimal area;
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createdAt;
}

View File

@@ -43,6 +43,21 @@ public class Product {
*/
private BigDecimal price;
/**
* 长度(mm)
*/
private BigDecimal length;
/**
* 宽度(mm)
*/
private BigDecimal width;
/**
* 面积(m²)
*/
private BigDecimal area;
/**
* 成本价
*/

View File

@@ -37,6 +37,11 @@ public interface ProductService {
*/
Page<Product> getProducts(String categoryId, String keyword, Integer page, Integer pageSize);
/**
* 获取所有商品(包括下架的)
*/
Page<Product> getAllProducts(String categoryId, String keyword, Integer page, Integer pageSize);
/**
* 获取商品详情
*/

View File

@@ -113,11 +113,14 @@ public class OrderServiceImpl implements OrderService {
item.setDescription(product.getDescription());
item.setPrice(price);
item.setQuantity(itemDTO.getQuantity());
item.setLength(itemDTO.getLength());
item.setWidth(itemDTO.getWidth());
item.setArea(itemDTO.getArea());
item.setSubtotal(subtotal);
orderItems.add(item);
// 4. 暂时不扣减库存,等确认完成时再扣减
// decreaseStock(product.getProductId(), itemDTO.getQuantity(), order.getOrderId(), operatorId);
// 4. 创建订单时立即扣减库存
decreaseStock(product.getProductId(), itemDTO.getQuantity(), order.getOrderId(), operatorId);
}
// 设置订单原价
@@ -188,7 +191,27 @@ public class OrderServiceImpl implements OrderService {
wrapper.le(Order::getCreatedAt, endDate);
}
wrapper.orderByDesc(Order::getCreatedAt);
return orderMapper.selectPage(pageParam, wrapper);
Page<Order> result = orderMapper.selectPage(pageParam, wrapper);
// 查询每个订单的明细
if (result.getRecords() != null && !result.getRecords().isEmpty()) {
for (Order order : result.getRecords()) {
try {
if (order.getOrderId() != null) {
List<OrderItem> items = orderItemMapper.selectList(
new LambdaQueryWrapper<OrderItem>().eq(OrderItem::getOrderId, order.getOrderId()));
order.setItems(items);
} else {
order.setItems(new ArrayList<>());
}
} catch (Exception e) {
// 查询明细失败时设置空列表
order.setItems(new ArrayList<>());
}
}
}
return result;
}
/**
@@ -230,7 +253,13 @@ public class OrderServiceImpl implements OrderService {
throw new RuntimeException("订单状态不允许取消");
}
// 未完成订单没有扣减库存,不需要恢复
// 取消订单需要恢复库存(因为创建时已扣减库存)
List<OrderItem> items = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
.eq(OrderItem::getOrderId, orderId));
for (OrderItem item : items) {
increaseStock(item.getProductId(), item.getQuantity(), orderId, operatorId);
}
// 更新订单状态
order.setStatus(2); // 已取消
orderMapper.updateById(order);
@@ -279,14 +308,18 @@ public class OrderServiceImpl implements OrderService {
}
if (status == 1) {
// 确认完成:扣减库存
// 确认完成:订单在创建时已扣减库存,此处不再扣减
// 只需更新状态为已完成
}
// 取消订单需要恢复库存(因为创建时已扣减)
if (status == 2) {
// 取消订单需要恢复库存(因为创建时已扣减)
List<OrderItem> items = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
.eq(OrderItem::getOrderId, orderId));
for (OrderItem item : items) {
decreaseStock(item.getProductId(), item.getQuantity(), orderId, operatorId);
increaseStock(item.getProductId(), item.getQuantity(), orderId, operatorId);
}
}
// 取消不需要恢复库存(因为创建时没扣减)
order.setStatus(status);
orderMapper.updateById(order);
@@ -333,10 +366,17 @@ public class OrderServiceImpl implements OrderService {
// 重新计算金额
BigDecimal totalAmount = BigDecimal.ZERO;
// 删除旧的订单明细前,先恢复库存
List<OrderItem> oldItems = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
.eq(OrderItem::getOrderId, orderId));
for (OrderItem oldItem : oldItems) {
increaseStock(oldItem.getProductId(), oldItem.getQuantity(), orderId, operatorId);
}
// 删除旧的订单明细
orderItemMapper.delete(new LambdaQueryWrapper<OrderItem>().eq(OrderItem::getOrderId, orderId));
// 重新创建订单明细
// 重新创建订单明细,并扣减库存
List<OrderItem> orderItems = new ArrayList<>();
for (CreateOrderRequest.OrderItemDTO itemDTO : request.getItems()) {
Product product = productMapper.selectById(itemDTO.getProductId());
@@ -364,9 +404,14 @@ public class OrderServiceImpl implements OrderService {
item.setDescription(product.getDescription());
item.setPrice(price);
item.setQuantity(itemDTO.getQuantity());
item.setLength(itemDTO.getLength());
item.setWidth(itemDTO.getWidth());
item.setArea(itemDTO.getArea());
item.setSubtotal(subtotal);
orderItems.add(item);
orderItemMapper.insert(item);
// 扣减库存
decreaseStock(product.getProductId(), itemDTO.getQuantity(), orderId, operatorId);
}
order.setTotalAmount(totalAmount);

View File

@@ -99,6 +99,20 @@ public class ProductServiceImpl implements ProductService {
return productMapper.selectPage(pageParam, wrapper);
}
@Override
public Page<Product> getAllProducts(String categoryId, String keyword, Integer page, Integer pageSize) {
Page<Product> pageParam = new Page<>(page, pageSize);
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.hasText(categoryId)) {
wrapper.eq(Product::getCategoryId, categoryId);
}
if (StringUtils.hasText(keyword)) {
wrapper.like(Product::getName, keyword);
}
wrapper.orderByDesc(Product::getCreatedAt);
return productMapper.selectPage(pageParam, wrapper);
}
/**
* 获取商品详情
*/
@@ -119,6 +133,15 @@ public class ProductServiceImpl implements ProductService {
product.setProductId(UUID.randomUUID().toString());
product.setStatus(1);
productMapper.insert(product);
// 创建商品时自动创建库存记录
Stock stock = new Stock();
stock.setStockId(UUID.randomUUID().toString());
stock.setProductId(product.getProductId());
stock.setQuantity(0);
stock.setLockedQuantity(0);
stockMapper.insert(stock);
return product;
}

View File

@@ -0,0 +1,7 @@
-- 添加商品长度、宽度、面积字段
ALTER TABLE products ADD COLUMN length DECIMAL(10,2);
COMMENT ON COLUMN products.length IS '长度(mm)';
ALTER TABLE products ADD COLUMN width DECIMAL(10,2);
COMMENT ON COLUMN products.width IS '宽度(mm)';
ALTER TABLE products ADD COLUMN area DECIMAL(10,4);
COMMENT ON COLUMN products.area IS '面积(m²)';

View File

@@ -0,0 +1,7 @@
-- 添加订单明细长度、宽度、面积字段
ALTER TABLE order_items ADD COLUMN length DECIMAL(10,2);
COMMENT ON COLUMN order_items.length IS '长度(mm)';
ALTER TABLE order_items ADD COLUMN width DECIMAL(10,2);
COMMENT ON COLUMN order_items.width IS '宽度(mm)';
ALTER TABLE order_items ADD COLUMN area DECIMAL(10,4);
COMMENT ON COLUMN order_items.area IS '面积(m²)';

View File

@@ -0,0 +1,2 @@
-- 添加分类描述字段
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description TEXT;