using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SqlSugar; using SqlSugar.Extensions; using WIDESEA_Common.StockEnum; using WIDESEA_Core; using WIDESEA_DTO.CalcOut; using WIDESEA_Model.Models; namespace WIDESEA_OutboundService { public partial class OutboundService { public WebResponseContent GetOrderInfo(string orderNo) { try { Dt_OutboundOrder outboundOrder = _outboundRepository.Db.Queryable().First(x => x.OrderNo == orderNo); return WebResponseContent.Instance.OK(data: outboundOrder); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } //public WebResponseContent QueryPickingTasks(string palletCode, string orderNo) //{ // try // { // Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First(); // var outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo); // bool isMatMixed = false; // if (stockInfo != null) // { // isMatMixed = stockInfo.Details.GroupBy(x => new // { // x.MaterielCode, // x.MaterielName, // x.BatchNo, // x.SupplyCode, // x.WarehouseCode // }).Count() > 1; // } // List outStockLockInfos = _outboundLockInfoRepository.QueryData(x => x.PalletCode == palletCode && x.OrderNo == orderNo); // return WebResponseContent.Instance.OK(data: new { outStockLockInfos, stockInfo, isMatMixed }); // } // catch (Exception ex) // { // return WebResponseContent.Instance.Error(ex.Message); // } //} public WebResponseContent QueryPickingTasks(string palletCode, string orderNo) { try { Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable() .Where(x => x.PalletCode == palletCode) .Includes(x => x.Details) .First(); List outStockLockInfos = _outboundLockInfoRepository .QueryData(x => x.PalletCode == palletCode && x.OrderNo == orderNo); bool isMatMixed = false; bool orderOver = false; decimal sumQty = 0; if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Any()) { if (outStockLockInfos.FirstOrDefault() != null) { bool includeBatchNo = !string.IsNullOrEmpty(outStockLockInfos.FirstOrDefault().BatchNo); bool includeSupplyCode = !string.IsNullOrEmpty(outStockLockInfos.FirstOrDefault().SupplyCode); var orderId = outStockLockInfos.FirstOrDefault().OrderDetailIds.Split(","); foreach (var item in orderId) { Dt_OutboundOrderDetail outboundOrderDetail = _outboundRepository.Db.Queryable().Where(x=>x.Id == item.ObjToInt()).First(); if(outboundOrderDetail == null) { return WebResponseContent.Instance.Error("该托盘的出库明细未找到"); } sumQty += (outboundOrderDetail.OrderQuantity - outboundOrderDetail.OverOutQuantity - outboundOrderDetail.MoveQty); } if(sumQty < outStockLockInfos.FirstOrDefault().AssignQuantity) { orderOver = true; } if (includeBatchNo && includeSupplyCode) { isMatMixed = stockInfo.Details.GroupBy(x => new { x.MaterielCode, x.MaterielName, x.BatchNo, x.SupplyCode, x.WarehouseCode }).Count() > 1; } else if (includeBatchNo && !includeSupplyCode) { isMatMixed = stockInfo.Details.GroupBy(x => new { x.MaterielCode, x.MaterielName, x.BatchNo, x.WarehouseCode }).Count() > 1; } else if (!includeBatchNo && includeSupplyCode) { isMatMixed = stockInfo.Details.GroupBy(x => new { x.MaterielCode, x.MaterielName, x.SupplyCode, x.WarehouseCode }).Count() > 1; } else { isMatMixed = stockInfo.Details.GroupBy(x => new { x.MaterielCode, x.MaterielName, x.WarehouseCode }).Count() > 1; } } else { isMatMixed = stockInfo.Details.GroupBy(x => new { x.MaterielCode, x.MaterielName, x.WarehouseCode }).Count() > 1; Dt_OutStockLockInfo outStockLockInfo = _outboundLockInfoRepository.QueryFirst(x=>x.PalletCode == palletCode); if (outStockLockInfo != null) { return WebResponseContent.Instance.Error($"该托盘在该单据中无拣选记录,请前往{outStockLockInfo.OrderNo}单据中进行拣货操作"); } } } return WebResponseContent.Instance.OK(data: new { outStockLockInfos, stockInfo, isMatMixed, orderOver }); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 查询已拣选列表(通过库存变动记录) /// /// 查询请求 /// 已拣选列表 public WebResponseContent QueryPickedList(string orderNo, string palletCode) { WebResponseContent content = WebResponseContent.Instance; try { // 构建查询条件 var query = _stockChangeRepository.Db .Queryable() .LeftJoin((r, o) => r.OrderNo == o.OrderNo) .Where((r, o) => r.ChangeType == (int)StockChangeTypeEnum.Outbound) .Where((r, o) => r.OrderNo == orderNo) .Where((r, o) => r.PalleCode == palletCode) .OrderBy((r, o) => r.CreateDate, OrderByType.Desc) .Select((r, o) => new PickedListItemDTO { Id = r.Id, OrderNo = r.OrderNo, TaskNum = r.TaskNum, PalletCode = r.PalleCode, MaterielCode = r.MaterielCode, MaterielName = r.MaterielName, BatchNo = r.BatchNo, OriginalBarcode = r.OriginalSerilNumber, NewBarcode = r.NewSerilNumber, ChangeQuantity = r.ChangeQuantity, BeforeQuantity = r.BeforeQuantity, AfterQuantity = r.AfterQuantity, SupplyCode = r.SupplyCode, WarehouseCode = r.WarehouseCode, Remark = r.Remark, CreateDate = r.CreateDate, OrderStatus = o.OrderStatus, FactoryArea = o.FactoryArea }); var result = query.ToList(); return WebResponseContent.Instance.OK(data: result); } catch (Exception ex) { return WebResponseContent.Instance.Error($"查询已拣选列表失败:{ex.Message}"); } } } }