Browse Source

fix: 补货操作回写actualQuantity/beforeStock/afterStock到订单明细

- 补货操作时查询补货前库存,成功后回写实际数量、补货前/后库存
- completeOrder不再覆盖补货操作已写入的actualQuantity
- 订单详情页展示计划/实际双数量
- operation页totalReplenishCount使用用户实际输入

Co-Authored-By: Claude <noreply@anthropic.com>
skyline 14 giờ trước cách đây
mục cha
commit
e6e8e903d6

+ 0 - 3
haha-admin-mp/src/pages/replenish/operation.vue

@@ -137,9 +137,6 @@ const isInOrder = (item: any) => {
 const orderItemsData = ref<any[]>([]);
 
 const totalReplenishCount = computed(() => {
-  if (orderItemsData.value.length > 0) {
-    return orderItemsData.value.reduce((s, oi) => s + (oi.plannedQuantity || 0), 0);
-  }
   return replenishItems.value.reduce((s, i) => s + (i.quantity || 0), 0);
 });
 

+ 5 - 1
haha-admin-mp/src/pages/replenish/order-detail.vue

@@ -79,7 +79,10 @@
               <text class="product-name">{{ item.productName || '未知商品' }}</text>
               <text class="product-shelf" v-if="item.shelfNum">层 {{ item.shelfNum }} · {{ item.position || '' }}</text>
             </view>
-            <text class="product-qty">{{ item.plannedQuantity || item.quantity || 0 }}</text>
+            <text class="product-qty">
+              <text>{{ item.plannedQuantity || item.quantity || 0 }}</text>
+              <text class="qty-actual" v-if="item.actualQuantity != null"> / {{ item.actualQuantity }}</text>
+            </text>
           </view>
         </view>
 
@@ -236,6 +239,7 @@ onMounted(async () => {
   .product-shelf { font-size: 20rpx; color: $text-color-muted; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
 }
 .product-qty { font-size: 30rpx; font-weight: 700; color: $text-color-primary; margin-left: 16rpx; flex-shrink: 0; min-width: 40rpx; text-align: right; }
+.qty-actual { font-size: 24rpx; font-weight: 500; color: $text-color-muted; }
 
 // ====== Bottom ======
 .bottom-spacer { height: 120rpx; }

+ 20 - 0
haha-admin/src/main/java/com/haha/admin/controller/ReplenisherOperationController.java

@@ -15,6 +15,7 @@ import com.haha.entity.Replenisher;
 import com.haha.entity.ReplenishmentOrder;
 import com.haha.entity.ReplenishmentOrderItem;
 import com.haha.entity.dto.ReplenishDTO;
+import com.haha.mapper.ReplenishmentOrderItemMapper;
 import com.haha.service.DeviceInventoryService;
 import com.haha.service.DeviceService;
 import com.haha.service.InventoryLogService;
@@ -46,6 +47,7 @@ public class ReplenisherOperationController {
     private final DeviceService deviceService;
     private final ReplenishmentOrderService replenishmentOrderService;
     private final InventoryLogService inventoryLogService;
+    private final ReplenishmentOrderItemMapper orderItemMapper;
 
     /**
      * 获取当前补货员信息
@@ -315,6 +317,10 @@ public class ReplenisherOperationController {
 
         for (ReplenishDTO.ReplenishItem item : dto.getItems()) {
             try {
+                // 补货前获取当前库存
+                DeviceInventory beforeInv = deviceInventoryService.getByDeviceAndProduct(dto.getDeviceId(), item.getProductId());
+                int beforeStock = beforeInv != null ? beforeInv.getStock() : 0;
+
                 DeviceInventory inventory = deviceInventoryService.increaseStock(
                         dto.getDeviceId(),
                         item.getProductId(),
@@ -328,6 +334,20 @@ public class ReplenisherOperationController {
                         null
                 );
 
+                // 回写订单明细:实际补货数量、补货前/后库存
+                if (dto.getOrderId() != null) {
+                    ReplenishmentOrderItem orderItem = orderItemMapper.selectOne(
+                            new LambdaQueryWrapper<ReplenishmentOrderItem>()
+                                    .eq(ReplenishmentOrderItem::getOrderId, dto.getOrderId())
+                                    .eq(ReplenishmentOrderItem::getProductCode, item.getProductCode()));
+                    if (orderItem != null) {
+                        orderItem.setActualQuantity(item.getQuantity());
+                        orderItem.setBeforeStock(beforeStock);
+                        orderItem.setAfterStock(inventory.getStock());
+                        orderItemMapper.updateById(orderItem);
+                    }
+                }
+
                 successCount++;
                 Map<String, Object> itemResult = new HashMap<>();
                 itemResult.put("productId", item.getProductId());

+ 3 - 1
haha-service/src/main/java/com/haha/service/impl/ReplenishmentOrderServiceImpl.java

@@ -498,7 +498,9 @@ public class ReplenishmentOrderServiceImpl extends ServiceImpl<ReplenishmentOrde
 
             item.setBeforeStock(beforeStock);
             item.setAfterStock(afterStock);
-            item.setActualQuantity(item.getPlannedQuantity());
+            if (item.getActualQuantity() == null) {
+                item.setActualQuantity(item.getPlannedQuantity());
+            }
             orderItemMapper.updateById(item);
 
             log.info("更新设备库存: deviceId={}, productCode={}, {} -> {}",