dengjunjie
4 天以前 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_AGV.cs
@@ -122,21 +122,23 @@
            {
                var palletCode = saveModel.MainData["palletCode"].ToString();
                if (string.IsNullOrEmpty(palletCode)) throw new Exception("托盘号不可为空");
                var orderNo = saveModel.MainData["orderNo"].ToString();
                if (string.IsNullOrEmpty(orderNo)) throw new Exception("批号不可为空");
                //var orderNo = saveModel.MainData["orderNo"].ToString();
                //if (string.IsNullOrEmpty(orderNo)) throw new Exception("批号不可为空");
                var qty = saveModel.MainData["qty"].ToString();
                if (string.IsNullOrEmpty(qty)) throw new Exception("袋数不可为空");
                var batchNo = saveModel.MainData["batchNo"].ToString();
                if (string.IsNullOrEmpty(batchNo)) throw new Exception("柜号不可为空");
                #region æŸ¥è¯¢åº“存、入库单
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(palletCode);
                if (stockInfo != null) throw new Exception($"托盘【{palletCode}】已存在库存信息");
                stockInfo = new Dt_StockInfo();
                stockInfo.Details = new List<Dt_StockInfoDetail>();
                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(orderNo);
                if (inboundOrder == null) throw new Exception($"未找到批号为【{orderNo}】的入库单");
                Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.Where(x => x.BatchNo == batchNo).FirstOrDefault();
                if (inboundOrderDetail == null) throw new Exception($"批号【{orderNo}】的入库单未找到柜号【{batchNo}】");
                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1) throw new Exception($"批号【{orderNo}】的柜号【{batchNo}】可组盘数量不足");
                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (inventoryInfo != null) throw new Exception($"托盘【{palletCode}】已存在库存信息");
                Dt_InboundOrderDetail? inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == batchNo);
                if (inboundOrderDetail == null) throw new Exception($"未找到批号【{batchNo}】的入库单");
                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < qty.ObjToInt()) throw new Exception($"批号【{batchNo}】可组盘数量不足");
                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.Id == inboundOrderDetail.OrderId);
                if (inboundOrder == null) throw new Exception($"未找到批号为【{batchNo}】的入库单");
                Dt_Inventory_Batch inventory_Batch = _inventoryBatchRepository.QueryFirst(x => x.BatchNo == batchNo);
                if (inventory_Batch == null) throw new Exception($"未找到批号为【{batchNo}】的批次信息");
                #endregion
                #region åˆ›å»ºä»»åŠ¡
@@ -149,57 +151,48 @@
                    Creater = "System",
                    PalletCode = palletCode,
                    Roadway = "SC01",
                    OrderNo = orderNo + batchNo,
                    OrderNo = batchNo,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.AGV_InFinish.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskType = inboundOrder.OrderType == InOrderTypeEnum.Quality.ObjToInt() ? TaskTypeEnum.InQuality.ObjToInt() : TaskTypeEnum.Inbound.ObjToInt(),
                    CreateDate = DateTime.Now,
                    Dispatchertime = DateTime.Now,
                };
                #endregion
                #region æ·»åŠ åº“å­˜ä¿¡æ¯ã€å¤„ç†å…¥åº“å•
                inboundOrderDetail.ReceiptQuantity++;
                inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
                if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
                inventoryInfo = new Dt_InventoryInfo()
                {
                    inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
                }
                else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt())
                {
                    inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
                }
                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                {
                    Status = StockStatusEmun.组盘暂存.ObjToInt(),
                    OrderNo = inboundOrder.OrderNo,
                    StockId = stockInfo.Id != 0 ? stockInfo.Id : 0,
                    MaterielName = inboundOrderDetail.MaterielName,
                    MaterielCode = inboundOrderDetail.MaterielCode,
                    BatchNo = inboundOrderDetail.BatchNo,
                    StockQuantity = 1,
                    SerialNumber = "",
                    BatchNo = inventory_Batch.BatchNo,
                    MaterielCode = inventory_Batch.MaterielCode,
                    MaterielName = inventory_Batch.MaterielName,
                    PalletCode = palletCode,
                    ProductionDate = inventory_Batch.ProductionDate,
                    StockStatus = StockStatusEmun.组盘暂存.ObjToInt(),
                    ProductStatus = dt_Task.TaskType == TaskTypeEnum.InQuality.ObjToInt() ? ProductStatusEmun.待检2.ObjToInt() : ProductStatusEmun.待检1.ObjToInt(),
                    ShelfLife = inventory_Batch.ShelfLife,
                    ValidityPeriod = inventory_Batch.ValidityPeriod,
                    StockQuantity = qty.ObjToInt(),
                    BoxQuantity = (qty.ObjToInt() % 8 > 0) ? (qty.ObjToInt() / 8) + 1 : qty.ObjToInt() / 8,
                    Creater = "System"
                };
                if (stockInfo.Id == 0)
                {
                    stockInfo.PalletCode = palletCode;
                    stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
                    stockInfo.Creater = "System";
                    stockInfo.Remark = "人工组盘入库";
                }
                stockInfo.Details.Add(stockInfoDetail);
                inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
                inboundOrderDetail.ReceiptQuantity += inventoryInfo.StockQuantity;
                inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
                inventory_Batch.ProductStatus = inventoryInfo.ProductStatus;
                #endregion
                Db.Ado.BeginTran();
                _inboundService.InbounOrderService.UpdateDataWithDetail(inboundOrder);
                _stockService.StockInfoService.AddMaterielGroup(stockInfo);
                _inboundService.InbounOrderService.UpdateData(inboundOrder);
                _inboundService.InboundOrderDetailService.UpdateData(inboundOrderDetail);
                _inventoryInfoRepository.AddData(inventoryInfo);
                _inventoryBatchRepository.UpdateData(inventory_Batch);
                AddData(dt_Task);
                List<WMSTaskDTO> wMSTaskDTOs = _mapper.Map<List<WMSTaskDTO>>(new List<Dt_Task> { dt_Task });
                var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ReceiveTask, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"向WCS下发人工组盘入库任务超时");
                if (ResultData.Result == null) throw new Exception($"向WCS下发入库任务超时");
                responseContent = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
                if (responseContent == null) throw new Exception($"下发人工组盘入库任务WCS无响应");
                if (responseContent == null) throw new Exception($"下发入库任务WCS无响应");
                if (!responseContent.Status) throw new Exception(responseContent.Message);
                Db.Ado.CommitTran();
            }