| | |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | |
| | | /// <summary> |
| | | /// 组盘 |
| | | /// </summary> |
| | | public async Task<bool> GroupPallet(StockDTO stock) |
| | | public async Task<WebResponseContent> GroupPalletAsync(StockDTO stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | var now = DateTime.Now; |
| | | var details = stock.Details.Select(item => new Dt_StockInfoDetail |
| | | { |
| | |
| | | }).ToList(); |
| | | |
| | | var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo); |
| | | var result = false; |
| | | if (existingStock != null) |
| | | { |
| | | details.ForEach(d => d.StockId = existingStock.Id); |
| | | return await StockInfoDetailService.Repository.AddDataAsync(details) > 0; |
| | | result = await StockInfoDetailService.Repository.AddDataAsync(details) > 0; |
| | | if (result) return content.OK("组盘成功"); |
| | | return content.Error("组盘失败"); |
| | | } |
| | | |
| | | var entity = new Dt_StockInfo |
| | |
| | | Details = details |
| | | }; |
| | | |
| | | return StockInfoService.Repository.AddData(entity, x => x.Details); |
| | | result = StockInfoService.Repository.AddData(entity, x => x.Details); |
| | | if (result) return content.OK("组盘成功"); |
| | | return content.Error("组盘失败"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 换盘 |
| | | /// </summary> |
| | | public async Task<bool> ChangePallet(StockDTO stock) |
| | | public async Task<WebResponseContent> ChangePalletAsync(StockDTO stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (stock == null || |
| | | string.IsNullOrWhiteSpace(stock.TargetPalletNo) || |
| | | string.IsNullOrWhiteSpace(stock.SourcePalletNo) || |
| | | string.Equals(stock.SourcePalletNo, stock.TargetPalletNo, StringComparison.OrdinalIgnoreCase)) |
| | | { |
| | | return false; |
| | | return content.Error("源托盘号与目标托盘号相同"); |
| | | } |
| | | |
| | | var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo); |
| | | if (sourceStock == null) return false; |
| | | if (sourceStock == null) return content.Error("源托盘不存在"); |
| | | |
| | | var targetStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo); |
| | | if (targetStock == null) |
| | |
| | | }; |
| | | |
| | | var newId = StockInfoService.Repository.AddData(newStock); |
| | | if (newId <= 0) return false; |
| | | if (newId <= 0) return content.Error("换盘失败"); |
| | | |
| | | targetStock = newStock; |
| | | targetStock.Id = newId; |
| | | } |
| | | |
| | | var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList(); |
| | | if (!serialNumbers.Any()) return false; |
| | | if (!serialNumbers.Any()) return content.Error("未找到有效的序列号"); |
| | | |
| | | var detailEntities = StockInfoDetailService.Repository.QueryData( |
| | | d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber)); |
| | | if (!detailEntities.Any()) return false; |
| | | if (!detailEntities.Any()) return content.Error("未找到有效的库存明细"); |
| | | |
| | | if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "换盘")) <= 0) |
| | | return false; |
| | | return content.Error("换盘历史记录保存失败"); |
| | | |
| | | if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock, targetStock }, "换盘")) <= 0) |
| | | return false; |
| | | return content.Error("换盘历史记录保存失败"); |
| | | |
| | | detailEntities.ForEach(d => d.StockId = targetStock.Id); |
| | | return await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities); |
| | | var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities); |
| | | if (!result) return content.Error("换盘失败"); |
| | | return content.OK("换盘成功"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 拆盘 |
| | | /// </summary> |
| | | public async Task<bool> SplitPallet(StockDTO stock) |
| | | public async Task<WebResponseContent> SplitPalletAsync(StockDTO stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo)) |
| | | return false; |
| | | return content.Error("源托盘号不能为空"); |
| | | |
| | | var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo); |
| | | if (sourceStock == null) return false; |
| | | if (sourceStock == null) return content.Error("源托盘不存在"); |
| | | |
| | | 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)); |
| | | if (!detailEntities.Any()) return false; |
| | | if (!detailEntities.Any()) return content.Error("未找到有效的库存明细"); |
| | | |
| | | if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "拆盘")) <= 0) |
| | | return false; |
| | | return content.Error("拆盘历史记录保存失败"); |
| | | |
| | | if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "拆盘")) <= 0) |
| | | return false; |
| | | return content.Error("拆盘历史记录保存失败"); |
| | | |
| | | return await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities); |
| | | var result = await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities); |
| | | if (!result) return content.Error("拆盘失败"); |
| | | return content.OK("拆盘成功"); |
| | | } |
| | | |
| | | public async Task<bool> UpdateStockInfo(StockInfoDTO stock) |
| | | /// <summary> |
| | | /// 堆垛机换盘后更新库存信息(清空库位信息) |
| | | /// </summary> |
| | | /// <param name="stock"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> UpdateStockInfoAsync(StockInfoDTO stock) |
| | | { |
| | | if (stock == null) return false; |
| | | 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 false; |
| | | if (existingStock == null) return content.Error("托盘信息不存在"); |
| | | |
| | | existingStock.LocationCode = ""; |
| | | existingStock.LocationId = 0; |
| | | |
| | | return await StockInfoService.Repository.UpdateDataAsync(existingStock); |
| | | 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) |
| | | { |