|
|
@@ -5,10 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.haha.entity.DeviceInventory;
|
|
|
import com.haha.entity.InventoryLog;
|
|
|
import com.haha.entity.Order;
|
|
|
+import com.haha.entity.Product;
|
|
|
import com.haha.entity.RefundItem;
|
|
|
import com.haha.service.DeviceInventoryService;
|
|
|
import com.haha.service.InventoryLogService;
|
|
|
import com.haha.service.OrderInventoryService;
|
|
|
+import com.haha.service.ProductService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -30,6 +32,9 @@ public class OrderInventoryServiceImpl implements OrderInventoryService {
|
|
|
@Autowired
|
|
|
private InventoryLogService inventoryLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
@@ -63,8 +68,16 @@ public class OrderInventoryServiceImpl implements OrderInventoryService {
|
|
|
Integer quantity = extractQuantity(item);
|
|
|
String productCode = extractProductCode(item);
|
|
|
|
|
|
+ // AI识别返回的items只有code没有productId,需要通过code反查本地商品库
|
|
|
+ if (productId == null && productCode != null) {
|
|
|
+ Product product = productService.getProductByCode(productCode);
|
|
|
+ if (product != null) {
|
|
|
+ productId = product.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (productId == null) {
|
|
|
- log.warn("商品ID为空,跳过扣减: orderNo={}, item={}", orderNo, item);
|
|
|
+ log.warn("无法确定商品ID,跳过扣减: orderNo={}, productCode={}", orderNo, productCode);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -147,6 +160,15 @@ public class OrderInventoryServiceImpl implements OrderInventoryService {
|
|
|
for (Map<String, Object> item : itemsList) {
|
|
|
Long productId = extractProductId(item);
|
|
|
Integer quantity = extractQuantity(item);
|
|
|
+ String productCode = extractProductCode(item);
|
|
|
+
|
|
|
+ // AI识别返回的items只有code没有productId,需要通过code反查本地商品库
|
|
|
+ if (productId == null && productCode != null) {
|
|
|
+ Product product = productService.getProductByCode(productCode);
|
|
|
+ if (product != null) {
|
|
|
+ productId = product.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if (productId != null) {
|
|
|
DeviceInventory inventory = deviceInventoryService.getByDeviceAndProduct(deviceId, productId);
|