From 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 09 七月 2025 22:55:27 +0800
Subject: [PATCH] 增加质检出入库逻辑

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_AGV.cs |   81 ++++++++++++++++++----------------------
 1 files changed, 37 insertions(+), 44 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_AGV.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_AGV.cs"
index def2e67..d1ca057 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_AGV.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/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($"鍚慦CS涓嬪彂浜哄伐缁勭洏鍏ュ簱浠诲姟瓒呮椂");
+                if (ResultData.Result == null) throw new Exception($"鍚慦CS涓嬪彂鍏ュ簱浠诲姟瓒呮椂");
                 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();
             }

--
Gitblit v1.9.3