From d9c99e0480b4910cdb134778dd5c314b35ec4cf2 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 29 九月 2025 10:05:23 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  159 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 102 insertions(+), 57 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 29caa7a..d2faf8e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -267,7 +267,7 @@
                     return webResponse.Error($"鎵瑰彿銆恵batchNo}銆戝凡璐ㄦ鍏ュ簱");
                 List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoRepository.QueryData(x => x.BatchNo == batchNo && x.StockStatus == StockStatusEmun.宸插叆搴�.ObjToInt()).OrderByDescending(x => x.InDate).Take(qty).ToList();
                 if (_InventoryInfos.Count < 1) return webResponse.Error($"鏈壘鍒版壒鍙枫�恵batchNo}銆戠殑搴撳瓨");
-                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == _InventoryInfos.First().LocationCode);
+                List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x => _InventoryInfos.Select(x => x.LocationCode).ToList().Contains(x.LocationCode));
                 List<Dt_Task> tasks = new List<Dt_Task>();
                 List<Dt_OutStockLockInfo> OutStockLockInfos = new List<Dt_OutStockLockInfo>();
                 #region 鐢熸垚璐ㄦ鍑哄簱鍗�
@@ -289,6 +289,7 @@
                 #endregion
                 foreach (var item in _InventoryInfos)
                 {
+                    var locationInfo = locationInfos.First(x => x.LocationCode == item.LocationCode);
                     orderDetail.MaterielCode = item.MaterielCode;
                     orderDetail.MaterielName = item.MaterielName;
                     orderDetail.OrderQuantity += item.StockQuantity;
@@ -301,10 +302,10 @@
                         Grade = 0,
                         PalletCode = item.PalletCode,
                         SourceIsPickPlace = item.SerialNumber == locationInfo.MaxQty,
-                        NextAddress = "1005",
+                        NextAddress = "1008",
                         Roadway = "SC01",
                         SourceAddress = item.LocationCode,
-                        TargetAddress = "1005",
+                        TargetAddress = "1008",
                         TaskState = OutTaskStatusEnum.OutNew.ObjToInt(),
                         TaskType = TaskTypeEnum.OutQuality.ObjToInt(),
                         TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
@@ -331,7 +332,7 @@
                     OutStockLockInfos.Add(outStockLockInfo);
                     #endregion
                 }
-
+                bool CreateQCIn = AppSettings.app(nameof(CreateQCIn)).ObjToBool();
                 #region 鐢熸垚璐ㄦ鍏ュ簱鍗�
                 Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail()
                 {
@@ -364,7 +365,7 @@
                 BaseDal.AddData(tasks);
                 _outboundService.OutboundOrderService.Repository.Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
                 _outboundService.OutboundStockLockInfoService.Repository.AddData(OutStockLockInfos);
-                _inboundService.InbounOrderService.Repository.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
+                if (CreateQCIn) _inboundService.InbounOrderService.Repository.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                 _inventoryInfoRepository.UpdateData(_InventoryInfos);
                 _inventoryBatchRepository.UpdateData(inventory_Batch);
                 #region 涓嬪彂浠诲姟缁橶CS
@@ -394,15 +395,15 @@
                 if (inventoryInfo == null) throw new Exception("鏈壘鍒版墭鐩樹俊鎭�");
                 if (inventoryInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && inventoryInfo.StockStatus != StockStatusEmun.鍏ュ簱纭.ObjToInt() && inventoryInfo.StockStatus != StockStatusEmun.鍏ュ簱涓�.ObjToInt())
                     throw new Exception($"鎵樼洏闈炲叆搴撲腑,涓嶅彲淇敼鏁伴噺");
-                Dt_InboundOrderDetail orderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
+                //Dt_InboundOrderDetail orderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                 var StockQty = inventoryInfo.StockQuantity;
                 inventoryInfo.StockQuantity = qty;
                 inventoryInfo.BoxQuantity = qty % 8 > 0 ? qty / 8 + 1 : qty / 8;
-                if (orderDetail != null)
-                {
-                    orderDetail.ReceiptQuantity -= StockQty - qty;
-                    _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
-                }
+                //if (orderDetail != null)
+                //{
+                //    orderDetail.ReceiptQuantity -= StockQty - qty;
+                //    _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
+                //}
                 _inventoryInfoRepository.UpdateData(inventoryInfo);
                 return webResponseContent.OK();
             }
@@ -411,7 +412,38 @@
                 return webResponseContent.Error(ex.Message);
             }
         }
-
+        public override WebResponseContent UpdateData(SaveModel saveModel)
+        {
+            WebResponseContent webResponseContent = new WebResponseContent();
+            try
+            {
+                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.TaskId == saveModel.MainData["taskId"].ObjToInt());
+                string newBarcode = saveModel.MainData["palletCode"].ToString();
+                if (TaskEnumHelper.GetTaskTypeGroup(dt_Task.TaskType) != TaskTypeGroup.InboundGroup)
+                    throw new Exception($"鍙彲淇敼鍏ュ簱浠诲姟,濡傞渶淇敼鍏朵粬浠诲姟绫诲瀷璇疯仈绯荤鐞嗗憳锛�");
+                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == newBarcode);
+                if (inventoryInfo != null) throw new Exception($"鎵樼洏鍙枫�恵newBarcode}銆戝凡瀛樺湪搴撳瓨淇℃伅锛�");
+                inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == dt_Task.PalletCode);
+                if (inventoryInfo == null) throw new Exception($"鎵樼洏鍙枫�恵dt_Task.PalletCode}銆戞湭鎵惧埌搴撳瓨淇℃伅锛�");
+                inventoryInfo.PalletCode = newBarcode;
+                dt_Task.PalletCode = newBarcode;
+                Db.Ado.BeginTran();
+                WMSTaskDTO wMSTaskDTOs = _mapper.Map<WMSTaskDTO>(dt_Task);
+                var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ModifyBarcode, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>());
+                if (ResultData.Result == null) throw new Exception($"WCS鍝嶅簲瓒呮椂");
+                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
+                if (content == null) throw new Exception($"WCS鏃犲搷搴�");
+                if (!content.Status) throw new Exception(content.Message);
+                BaseDal.UpdateData(dt_Task);
+                _inventoryInfoRepository.UpdateData(inventoryInfo);
+                Db.Ado.CommitTran();
+                return webResponseContent.OK();
+            }
+            catch (Exception ex)
+            {
+                return webResponseContent.Error(ex.Message);
+            }
+        }
         public WebResponseContent ModifyBarcode(string barcode, string newBarcode)
         {
             WebResponseContent webResponseContent = new WebResponseContent();
@@ -460,23 +492,36 @@
             {
                 Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == WMStask.TaskNum && x.TaskType == WMStask.TaskType);
                 if (task == null) return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
-                Dt_StockInfo? _StockInfo = _stockService.StockInfoService.GetStockByPalletCode(task.PalletCode);
-                if (_StockInfo != null)
+                Dt_InventoryInfo? inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                if (inventoryInfo != null)
                 {
-                    Dt_StockInfoDetail? detail = _StockInfo.Details.FirstOrDefault();
-                    if (detail != null)
+                    Dt_InboundOrderDetail? inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
+                    if (inboundOrderDetail != null)
                     {
-                        Dt_InboundOrder dt_InboundOrder = _inboundService.InbounOrderService.GetInboundOrder(detail.OrderNo);
-                        Dt_InboundOrderDetail? inboundOrderDetail = dt_InboundOrder.Details.FirstOrDefault(x => x.BatchNo == detail.BatchNo);
-                        if (inboundOrderDetail != null)
-                        {
-                            inboundOrderDetail.ReceiptQuantity--;
-                            _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
-                        }
-                        _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(_StockInfo.Details, OperateType.AGV鍒犻櫎);
+                        inboundOrderDetail.ReceiptQuantity--;
+                        _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                     }
-                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(_StockInfo, OperateType.AGV鍒犻櫎);
+                    _inventoryInfoRepository.DeleteAndMoveIntoHty(inventoryInfo, OperateType.AGV鍒犻櫎);
                 }
+                #region MyRegion
+                //Dt_StockInfo? _StockInfo = _stockService.StockInfoService.GetStockByPalletCode(task.PalletCode);
+                //if (_StockInfo != null)
+                //{
+                //    Dt_StockInfoDetail? detail = _StockInfo.Details.FirstOrDefault();
+                //    if (detail != null)
+                //    {
+                //        Dt_InboundOrder dt_InboundOrder = _inboundService.InbounOrderService.GetInboundOrder(detail.OrderNo);
+                //        Dt_InboundOrderDetail? inboundOrderDetail = dt_InboundOrder.Details.FirstOrDefault(x => x.BatchNo == detail.BatchNo);
+                //        if (inboundOrderDetail != null)
+                //        {
+                //            inboundOrderDetail.ReceiptQuantity--;
+                //            _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
+                //        }
+                //        _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(_StockInfo.Details, OperateType.AGV鍒犻櫎);
+                //    }
+                //    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(_StockInfo, OperateType.AGV鍒犻櫎);
+                //}
+                #endregion
                 BaseDal.DeleteAndMoveIntoHty(task, /*App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 :*/ OperateType.AGV鍒犻櫎);
             }
             catch (Exception ex)
@@ -681,43 +726,43 @@
             {
                 Db.Ado.BeginTran();
                 Dt_OutStockLockInfo? outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum && x.PalletCode == task.PalletCode);
-                Dt_OutboundOrder? outboundOrder = null;
-                Dt_OutboundOrderDetail? outboundOrderDetail = null;
+                //Dt_OutboundOrder? outboundOrder = null;
+                //Dt_OutboundOrderDetail? outboundOrderDetail = null;
                 int overCount = 0;
                 if (outStockLockInfo != null)
                 {
-                    outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfo.OrderDetailId);
-                    if (outboundOrderDetail != null)
-                    {
-                        outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
-                        if (outboundOrder != null)
-                        {
-                            outboundOrderDetail.OverOutQuantity++;
-                            overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
-                            if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity)
-                            {
-                                var outboundOrderdetail = outboundOrder.Details.First(x => x.Id == outboundOrderDetail.Id);
-                                outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
-                                outboundOrderdetail.OverOutQuantity = outboundOrderDetail.OverOutQuantity;
-                                outboundOrderdetail.OrderDetailStatus = outboundOrderDetail.OrderDetailStatus;
-                                overCount++;
-                            }
-                        }
-                    }
+                    //outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfo.OrderDetailId);
+                    //if (outboundOrderDetail != null)
+                    //{
+                    //    outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
+                    //    if (outboundOrder != null)
+                    //    {
+                    //        outboundOrderDetail.OverOutQuantity += outStockLockInfo.AssignQuantity;
+                    //        overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+                    //        if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity)
+                    //        {
+                    //            var outboundOrderdetail = outboundOrder.Details.First(x => x.Id == outboundOrderDetail.Id);
+                    //            outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    //            outboundOrderdetail.OverOutQuantity = outboundOrderDetail.OverOutQuantity;
+                    //            outboundOrderdetail.OrderDetailStatus = outboundOrderDetail.OrderDetailStatus;
+                    //            overCount++;
+                    //        }
+                    //    }
+                    //}
                     outStockLockInfo.Status = OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
                 }
-                if (outboundOrder != null && outboundOrder.Details.Count == overCount)
-                {
-                    outboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
-                    _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(outboundOrder.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                    outboundOrder.Details = null;
-                    _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                }
-                else
-                {
-                    if (outboundOrderDetail != null)
-                        _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetail);
-                }
+                //if (outboundOrder != null && outboundOrder.Details.Count == overCount)
+                //{
+                //    outboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                //    _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(outboundOrder.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                //    outboundOrder.Details = null;
+                //    _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                //}
+                //else
+                //{
+                //    if (outboundOrderDetail != null)
+                //        _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetail);
+                //}
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
                 if (outStockLockInfo != null) _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo);
                 Db.Ado.CommitTran();

--
Gitblit v1.9.3