wanshenmean
昨天 c9a1df9c19a64844d05d120ff171f523d77e7823
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -247,6 +247,14 @@
                    var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
                    if (!result) return content.Error("换盘失败");
                    // 检查源托盘是否还有剩余库存明细,若无则删除源托盘库存头
                    var remainingSourceDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id);
                    if (!remainingSourceDetails.Any())
                    {
                        if (await StockInfoService.Repository.Db.Deleteable<Dt_StockInfo>().Where(s => s.Id == sourceStock.Id).ExecuteCommandAsync() <= 0)
                            return content.Error("删除源托盘库存失败");
                    }
                    return content.OK("换盘成功");
                });
            }
@@ -314,6 +322,19 @@
                    if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "拆盘")) <= 0)
                        return content.Error("拆盘历史记录保存失败");
                    // 删除已拆出的库存明细
                    var detailIds = detailEntities.Select(d => d.Id).ToList();
                    if (await StockInfoDetailService.Repository.Db.Deleteable<Dt_StockInfoDetail>().In(detailIds).ExecuteCommandAsync() <= 0)
                        return content.Error("删除库存明细失败");
                    // 检查源托盘是否还有剩余库存明细,若无则删除源托盘库存头
                    var remainingSourceDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id);
                    if (!remainingSourceDetails.Any())
                    {
                        if (await StockInfoService.Repository.Db.Deleteable<Dt_StockInfo>().Where(s => s.Id == sourceStock.Id).ExecuteCommandAsync() <= 0)
                            return content.Error("删除源托盘库存失败");
                    }
                    return content.OK("拆盘成功");
                });
@@ -563,6 +584,26 @@
        }
        /// <summary>
        /// 根据托盘号查询库存明细数量
        /// </summary>
        /// <param name="palletCode">托盘号</param>
        /// <returns>库存明细数量</returns>
        public async Task<WebResponseContent> GetStockDetailCountByPalletCodeAsync(string palletCode)
        {
            WebResponseContent content = new WebResponseContent();
            if (string.IsNullOrWhiteSpace(palletCode))
                return content.Error("托盘号不能为空");
            var stockInfo = StockInfoService.Repository.QueryFirst(s => s.PalletCode == palletCode);
            if (stockInfo == null)
                return content.Error("托盘不存在");
            var count = await StockInfoDetailService.Repository.Db.Queryable<Dt_StockInfoDetail>()
                .CountAsync(d => d.StockId == stockInfo.Id);
            return content.OK("查询成功", new { PalletCode = palletCode, DetailCount = count });
        }
        /// <summary>
        /// 根据设备名称和托盘号解析MES设备配置
        /// </summary>
        /// <param name="deviceName">设备名称</param>