From d11b1f9c98e8765d3cee15abd4474b0e05a5acbc Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 01 三月 2025 10:33:56 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  184 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 137 insertions(+), 47 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 58557c4..b53fad2 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -113,7 +113,7 @@
                     x.AGVArea = agvDescription;
                 });
                 string url = AppSettings.Get("WCS");
-                if(string.IsNullOrEmpty(url))
+                if (string.IsNullOrEmpty(url))
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒癢CSApi鍦板潃,璇锋鏌ラ厤缃枃浠�");
                 }
@@ -140,12 +140,74 @@
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒癢CSAApi鍦板潃,璇锋鏌ラ厤缃枃浠�");
                 }
-                string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish", code);
+                string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish?code=" + code);
 
                 return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒");
             }
             catch (Exception ex)
             {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        public WebResponseContent AGVTasks(SaveModel saveModel)
+        {
+            try
+            {
+                var palletCode = saveModel.MainData["barcode"].ToString();
+                var stationCode = saveModel.MainData["address"].ToString();
+                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error("鏈壘鍒板簱鍖�");
+                }
+
+                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode && x.WarehouseId == warehouseId);
+                if (task != null)
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡鐢熸垚浠诲姟");
+                }
+                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && warehouse.WarehouseCode != WarehouseEnum.HA58.ToString())
+                {
+                    return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
+                }
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
+                }
+                if (stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘");
+                }
+                if (warehouseId != stockInfo.WarehouseId)
+                {
+                    return WebResponseContent.Instance.Error($"浠撳簱涓嶆纭�");
+                }
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = stationCode,
+                    Grade = 0,
+                    NextAddress ="",
+                    PalletCode = palletCode,
+                    Roadway = warehouse.Remark,//鏌ヨ瀵瑰簲绾胯竟浠撳湴鍧�宸烽亾鍙�
+                    SourceAddress = stationCode,
+                    TargetAddress = "",
+                    TaskType = TaskTypeEnum.OutAllocate.ObjToInt(),
+                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                    WarehouseId = stockInfo.WarehouseId,
+                    PalletType = stockInfo.PalletType
+                };
+                _unitOfWorkManage.BeginTran();
+                BaseDal.AddData(newTask);
+                PushTasksToWCS(new List<Dt_Task> { newTask});
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
@@ -180,7 +242,17 @@
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
                 }
-
+                #region 绌烘墭閫�搴�
+                if (task.TaskType == TaskTypeEnum.MesPalletReturn.ObjToInt())
+                {
+                    _unitOfWorkManage.BeginTran();
+                    BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
+                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                    _unitOfWorkManage.CommitTran();
+                    return WebResponseContent.Instance.OK();
+                }
+                #endregion
                 Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                 if (locationInfo == null)
                 {
@@ -198,15 +270,20 @@
 
                 stockInfo.LocationCode = locationInfo.LocationCode;
 
-                #region 绌虹鍏ュ簱
-                if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt())
+                #region 绌虹鍏ュ簱/鎷i�夊洖搴�/鐢熶骇閫�鏂�
+                if (task.TaskType == TaskTypeEnum.InEmpty.ObjToInt() || task.TaskType == TaskTypeEnum.InPick.ObjToInt() || (task.TaskType == TaskTypeEnum.ProductionReturn.ObjToInt() && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()))
                 {
                     stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                     task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                    stockInfo.Details.ForEach(x =>
+                    {
+                        x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                    });
                     _unitOfWorkManage.BeginTran();
                     BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                     _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
                     _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                    _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details);
                     _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted);
                     _unitOfWorkManage.CommitTran();
                     return WebResponseContent.Instance.OK();
@@ -214,53 +291,55 @@
                 #endregion
 
                 Dt_InboundOrder? inboundOrder = _inboundRepository.InboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
-                List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
-                List<ERPInboundDetailModel> detailModels = new List<ERPInboundDetailModel>();
-                if (stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+                Dt_InboundOrderDetail? inboundOrderDetail = null;
+                Dt_ReturnOrder? returnOrder = null;
+                //鏍囧噯鍏ュ簱娴佺▼鏌ユ壘鍏ュ簱鍗曟嵁
+                if (inboundOrder != null && stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
                 {
-                    if (inboundOrder == null)
-                    {
-                        return WebResponseContent.Instance.Error($"瀵瑰簲鍏ュ簱鍗曚笉瀛樺湪");
-                    }
+                    //鏌ヨ鍘熷畬鎴愮殑鍏ュ簱鏄庣粏鏁伴噺
+                    int overCount = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
+                    inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.RowNo == stockInfo.Details.FirstOrDefault()?.InboundOrderRowNo);
                     foreach (var item in stockInfo.Details)
                     {
-                        Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.RowNo == item.InboundOrderRowNo);
                         if (inboundOrderDetail == null)
                         {
                             continue;
                         }
-                        ERPInboundDetailModel detailModel = new ERPInboundDetailModel()
-                        {
-                            ExpiryDate = item.EffectiveDate ?? "",
-                            LocationCode = warehouse.WarehouseCode,
-                            MaterialsCode = item.MaterielCode,
-                            MfgDate = item.ProductionDate ?? "",
-                            QtyCustoms = "0",
-                            Quantity = item.StockQuantity.ToString(),
-                            Rack = stockInfo.LocationCode,
-                            ReceiptCode = inboundOrder.UpperOrderNo,
-                            ReceiptSerNo = item.InboundOrderRowNo.ToString()
-                        };
-                        inboundOrderDetail.OverInQuantity += detailModel.Quantity.ObjToInt();
+                        inboundOrderDetail.OverInQuantity += item.StockQuantity;
                         if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
                         {
                             inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                            overCount += 1;
                         }
-                        inboundOrderDetails.Add(inboundOrderDetail);
-                        detailModels.Add(detailModel);
+                        else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                        {
+                            inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+                        }
                     }
-
-                    //鍏ュ簱鏄庣粏鏂板瀹屾垚鏁伴噺
-                    int newCount = inboundOrderDetails.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
-                    //鍏ュ簱鏄庣粏鍘熷畬鎴愭暟閲�
-                    int oldCount = inboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
-                    if (inboundOrder.Details.Count == (newCount + oldCount))
+                    if (inboundOrder.Details.Count == overCount)
                     {
                         inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                        //鍒ゆ柇鏄惁涓洪��鏂欏叆搴撳崟
+                        if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
+                        {
+                            returnOrder = _inboundRepository.ReturnOrderRepository.Db.Queryable<Dt_ReturnOrder>().Where(x => x.OrderNo == inboundOrder.UpperOrderNo).Includes(x => x.Details).First();
+                            returnOrder.ReturnOrderStatus = ReturnOrderStatusEnum.Returned.ObjToInt();
+                            foreach (var item in inboundOrder.Details)
+                            {
+                                Dt_ReturnOrderDetail returnOrderDetail = returnOrder.Details?.FirstOrDefault(x => x.MCode == item.MaterielCode);
+                                if (returnOrderDetail != null)
+                                {
+                                    returnOrderDetail.OverReturnQty = item.OverInQuantity;
+                                    returnOrderDetail.OrderDetailStatus = ReturnOrderStatusEnum.Returned.ObjToInt();
+                                }
+                            }
+                        }
                     }
-                    
+                    else if (inboundOrder.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                    }
                 }
-
                 if ((stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt() || stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt()) && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString())
                 {
                     foreach (var model in stockInfo.Details)
@@ -268,7 +347,6 @@
                         TestSynStock(new TestToolSynInfo() { ToolCode = model.BatchNo, MaterialName = model.MaterielName, Life = int.TryParse(model.Remark, out int val) ? val : 1000 });
                     }
                 }
-
                 //娴嬭瘯鏋跺叆搴撳簱瀛樼姸鎬�
                 if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt())
                 {
@@ -277,14 +355,13 @@
                 else
                 {
                     stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-
                 }
                 stockInfo.Details.ForEach(x =>
                 {
                     x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                 });
                 //鏇存柊浠诲姟鐘舵��
-                task.TaskStatus = (int)TaskStatusEnum.Finish;
+                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                 _unitOfWorkManage.BeginTran();
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                 _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
@@ -294,13 +371,26 @@
                 _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, stockInfo.Details.Sum(x => x.StockQuantity), stockInfo.Details.Sum(x => x.StockQuantity), StockChangeTypeEnum.Inbound, taskNum);
                 if (inboundOrder != null)
                 {
-                    _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetails);
                     _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+                    _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetail);
+                }
+                if (returnOrder != null)
+                {
+                    _inboundRepository.ReturnOrderRepository.UpdateData(returnOrder);
+                    _inboundRepository.ReturnOrderDetailRepository.UpdateData(returnOrder.Details);
                 }
                 _unitOfWorkManage.CommitTran();
-                if (stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+                //瀛樺湪鍏ュ簱鍗曞苟鐘舵�佷负瀹屾垚鐘舵�佹帹閫佽嚦ERP
+                if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType != InOrderTypeEnum.Allocat.ObjToInt())
                 {
-                    _inboundOrderService.FeedbackInboundOrder(stockInfo, inboundOrder, detailModels);
+                    if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
+                    {
+                        _inboundOrderService.FeedbackReturnOrder(inboundOrder, returnOrder);
+                    }
+                    else
+                    {
+                        _inboundOrderService.FeedbackInboundOrder(inboundOrder);
+                    }
                 }
                 return WebResponseContent.Instance.OK();
             }
@@ -342,7 +432,7 @@
                 List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
                 List<Dt_MesOutboundOrder> mesOutboundOrders = new List<Dt_MesOutboundOrder>();
 
-                if ((outStockLockInfos == null || outStockLockInfos.Count == 0) && warehouse.WarehouseCode != WarehouseEnum.HA64.ToString() && task.TaskType != TaskTypeEnum.OutEmpty.ObjToInt())
+                if ((outStockLockInfos == null || outStockLockInfos.Count == 0) && warehouse.WarehouseCode != WarehouseEnum.HA64.ToString() && (task.TaskType != TaskTypeEnum.OutEmpty.ObjToInt()))
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撹鎯呬俊鎭�");
                 }
@@ -368,7 +458,7 @@
                             Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == item.OrderDetailId);
                             if (outboundOrderDetail != null)
                             {
-                                outboundOrderDetail.OverOutQuantity = item.AssignQuantity;
+                                outboundOrderDetail.OverOutQuantity += item.AssignQuantity;
                                 if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity)
                                 {
                                     outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
@@ -383,13 +473,13 @@
                 task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                 _unitOfWorkManage.BeginTran();
 
-                if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt())
+                if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.OutAllocate.ObjToInt() || task.TaskType == TaskTypeEnum.MesHandPickOutbound.ObjToInt() || task.TaskType == TaskTypeEnum.MesHandOutbound.ObjToInt())
                 {
+                    //澶勭悊鍑哄簱璇︽儏
                     if (outboundOrderDetails.Count > 0)
                     {
                         _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
                     }
-
                     stockInfo.LocationCode = "";
                     stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
                     _stockService.StockInfoService.Repository.UpdateData(stockInfo);
@@ -422,7 +512,7 @@
                 }
                 if (task.TaskType == TaskTypeEnum.MesOutbound.ObjToInt())
                 {
-                    MesMaterialLotaAceptModel model = GetMesMaterialLotaAceptModel(stockInfo, stockInfo.Details.FirstOrDefault(), mesOutboundOrders.FirstOrDefault().TaskNo, warehouse.WarehouseCode, mesOutboundOrders.FirstOrDefault().OrderQuantity);
+                    MesMaterialLotaAceptModel model = GetMesMaterialLotaAceptModel(stockInfo, stockInfo.Details.FirstOrDefault(), mesOutboundOrders.FirstOrDefault().TaskNo, warehouse.WarehouseCode, stockInfo.Details.Where(x => x.MaterielCode == mesOutboundOrders.FirstOrDefault().MaterialCode).Sum(x => x.StockQuantity));
                     UploadMesMaterialLotaAcept(model);
                 }
                 return WebResponseContent.Instance.OK();

--
Gitblit v1.9.3