wanshenmean
2026-02-28 c3de7bb2097aa347a1f92c2f640d18753aff633a
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -1,4 +1,8 @@
using WIDESEA_Common.StockEnum;
using Autofac.Core;
using System.Net;
using System.Threading.Channels;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
@@ -15,6 +19,8 @@
        public IStockInfoDetail_HtyService StockInfoDetail_HtyService { get; }
        public IStockInfo_HtyService StockInfo_HtyService { get; }
        public StockSerivce(
            IStockInfoDetailService stockInfoDetailService,
            IStockInfoService stockInfoService,
@@ -30,7 +36,7 @@
        /// <summary>
        /// 组盘
        /// </summary>
        public async Task<bool> GroupPallet(StockDTO stock)
        public async Task<bool> GroupPalletAsync(StockDTO stock)
        {
            var now = DateTime.Now;
            var details = stock.Details.Select(item => new Dt_StockInfoDetail
@@ -70,7 +76,7 @@
        /// <summary>
        /// 换盘
        /// </summary>
        public async Task<bool> ChangePallet(StockDTO stock)
        public async Task<bool> ChangePalletAsync(StockDTO stock)
        {
            if (stock == null ||
                string.IsNullOrWhiteSpace(stock.TargetPalletNo) ||
@@ -121,7 +127,7 @@
        /// <summary>
        /// 拆盘
        /// </summary>
        public async Task<bool> SplitPallet(StockDTO stock)
        public async Task<bool> SplitPalletAsync(StockDTO stock)
        {
            if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
                return false;
@@ -130,7 +136,13 @@
            if (sourceStock == null) return false;
            var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
            if (!serialNumbers.Any()) return false;
            if (!serialNumbers.Any())
            {
                serialNumbers = sourceStock.Details
                                            .Where(x => stock.Details.Any(d => d.Channel == x.InboundOrderRowNo))
                                            .Select(x => x.SerialNumber)
                                            .ToList();
            }
            var detailEntities = StockInfoDetailService.Repository.QueryData(
                d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
@@ -143,6 +155,27 @@
                return false;
            return await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities);
        }
        /// <summary>
        /// 堆垛机换盘后更新库存信息(清空库位信息)
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> UpdateStockInfoAsync(StockInfoDTO stock)
        {
            WebResponseContent content = new WebResponseContent();
            if (string.IsNullOrWhiteSpace(stock.PalletCode)) return content.Error("托盘号不能为空");
            var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.PalletCode);
            if (existingStock == null) return content.Error("托盘信息不存在");
            existingStock.LocationCode = "";
            existingStock.LocationId = 0;
            var result = await StockInfoService.Repository.UpdateDataAsync(existingStock);
            if (!result) return content.Error("更新库存信息失败");
            return content.OK("更新库存信息成功");
        }
        private static List<Dt_StockInfoDetail_Hty> CreateDetailHistory(IEnumerable<Dt_StockInfoDetail> details, string operateType)
@@ -194,5 +227,6 @@
                ModifyDate = s.ModifyDate
            }).ToList();
        }
    }
}