From b35e72bcf8011cf6e30182b0800e2f6e1a18e149 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 28 五月 2025 15:40:06 +0800
Subject: [PATCH] 更新代码

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs |  536 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 524 insertions(+), 12 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
index 8ffe4b3..a225003 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
@@ -4,14 +4,17 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.Helper;
+using WIDESEA_DTO;
 using WIDESEA_DTO.Task;
 using WIDESEA_Model.Models;
 
@@ -22,8 +25,7 @@
         /// <summary>
         /// 鐢宠鍏ュ簱浠诲姟(PDA浣跨敤锛屼粎鎵樼洏缁戝畾鍏ュ簱绔欏彴锛屼笉鍒嗛厤璐т綅)
         /// </summary>
-        /// <param name="palletCode">鎵樼洏鍙�</param>
-        /// <param name="stationCode">绔欏彴鍙�</param>
+        /// <param name="saveModel"></param>
         /// <returns></returns>
         public WebResponseContent RequestInboundTask(SaveModel saveModel)
         {
@@ -37,23 +39,24 @@
                 {
                     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)
+                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && warehouse.WarehouseCode != WarehouseEnum.HA60.ToString())
                 {
                     return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
                 }
 
-                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+                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() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt())
+                if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt())
                 {
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
                 }
@@ -87,14 +90,52 @@
                         WarehouseId = stockInfo.WarehouseId,
                         PalletType = stockInfo.PalletType
                     };
-
+                    //鑾峰彇鏄惁瀛樺湪鍏ュ簱鍗�
+                    Dt_InboundOrder? inboundOrder =  null;
+                    if (stockInfo!=null && stockInfo.Details.Count>0)
+                    {
+                        string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
+                        inboundOrder =_inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt());
+                        if (inboundOrder!=null)
+                        {
+                            newTask.OrderNo = inboundOrder.InboundOrderNo;
+                        }
+                    }
+                    
+                    if (inboundOrder != null)
+                    {
+                        if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
+                        {
+                            newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
+                            newTask.OrderNo = inboundOrder.InboundOrderNo;
+                        }
+                        else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
+                        {
+                            newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
+                            newTask.OrderNo = inboundOrder.InboundOrderNo;
+                        }
+                    }
                     if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
                     {
                         stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt();
                     }
+                    else if (stockInfo.StockStatus == StockStatusEmun.鎷i�夊畬鎴�.ObjToInt())
+                    {
+                        stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+                        newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
+                    }
                     else
                     {
                         stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+                    }
+
+                    if (warehouse.WarehouseCode==WarehouseEnum.HA57.ToString())
+                    {
+                        Dt_Task dt_TaskMesReturn = BaseDal.QueryFirst(x=>x.TaskType==TaskTypeEnum.MesMatReturn.ObjToInt() && x.TaskStatus!=TaskStatusEnum.SC_Executing.ObjToInt());
+                        if (dt_TaskMesReturn!=null)
+                        {
+                            return WebResponseContent.Instance.Error($"閫�鏂欎换鍔℃鎵ц");
+                        }
                     }
                     _unitOfWorkManage.BeginTran();
                     int taskId = BaseDal.AddData(newTask);
@@ -111,9 +152,13 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
         /// <summary>
         /// 鍏ョ┖绠�
         /// </summary>
+        /// <param name="barcode"></param>
+        /// <param name="address"></param>
+        /// <param name="WarehouseId"></param>
         /// <returns></returns>
         public WebResponseContent InEmpty(string barcode, string address, int WarehouseId)
         {
@@ -164,7 +209,7 @@
                 _stockRepository.StockInfoRepository.AddData(stockInfo);
                 _unitOfWorkManage.CommitTran();
                 PushTasksToWCS(new List<Dt_Task> { newTask });
-                PutFinish(address);
+                PutFinish(address, newTask.PalletCode, newTask.TaskNum.ToString());
                 return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -173,6 +218,15 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="qty"></param>
+        /// <param name="address"></param>
+        /// <param name="WarehouseId"></param>
+        /// <param name="barcode"></param>
+        /// <returns></returns>
         public WebResponseContent OutEmpty(int qty, string address, int WarehouseId, string barcode)
         {
             try
@@ -216,6 +270,14 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="stationCode"></param>
+        /// <param name="roadwayNo"></param>
+        /// <param name="palletCode"></param>
+        /// <returns></returns>
         public WebResponseContent DeviceRequestInboundTask(string stationCode, string roadwayNo, string palletCode)
         {
             try
@@ -223,20 +285,21 @@
                 Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                 if (task != null)
                 {
+                    PushTasksToWCS(new List<Dt_Task> { task });
                     return WebResponseContent.Instance.OK($"璇ユ墭鐩樺凡鐢熸垚浠诲姟", _mapper.Map<WMSTaskDTO>(task));
                 }
 
-                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
+                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && stationCode != "8005")//杈呮枡浠撲笉闄愬埗鍏ュ簱浠诲姟
                 {
                     return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
                 }
 
-                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+                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() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt())
+                if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES閫�搴�.ObjToInt())
                 {
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
                 }
@@ -266,14 +329,42 @@
                     PalletType = stockInfo.PalletType
                 };
 
+                //鑾峰彇鏄惁瀛樺湪鍏ュ簱鍗�
+                Dt_InboundOrder? inboundOrder = null;
+                if (stockInfo != null && stockInfo.Details.Count > 0)
+                {
+                    string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
+                    inboundOrder = _inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt());
+                }
+
+                if (inboundOrder != null)
+                {
+                    if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
+                    {
+                        newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
+                    }
+                    else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
+                    {
+                        newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
+                    }
+                }
                 if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
                 {
                     stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt();
+                }
+                else if (stockInfo.StockStatus == StockStatusEmun.MES閫�搴�.ObjToInt())
+                {
+                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
+                }
+                else if (stockInfo.StockStatus == StockStatusEmun.鎷i�夊畬鎴�.ObjToInt())
+                {
+                    newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                 }
                 else
                 {
                     stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
                 }
+                
                 LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                 _unitOfWorkManage.BeginTran();
                 _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
@@ -285,7 +376,188 @@
                 WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
 
                 PushTasksToWCS(new List<Dt_Task> { newTask });
-                if (newTask.WarehouseId == 5) PutFinish(stationCode);
+                if (newTask.WarehouseId == 5) PutFinish(stationCode.ToString(),newTask.PalletCode, newTask.TaskNum.ToString());
+                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 浠呯敵璇蜂换鍔★紝璁¦CS鏍规嵁璺敱纭畾涓嬩竴鍦板潃
+        /// </summary>
+        /// <param name="stationCode"></param>
+        /// <param name="palletCode"></param>
+        /// <returns></returns>
+        public WebResponseContent DeviceRequestInboundTaskSimple(string stationCode, string palletCode)
+        {
+            try
+            {
+                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
+                if (task != null)
+                {
+                    PushTasksToWCS(new List<Dt_Task> { task });
+                    return WebResponseContent.Instance.OK($"璇ユ墭鐩樺凡鐢熸垚浠诲姟", _mapper.Map<WMSTaskDTO>(task));
+                }
+
+                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
+                {
+                    return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
+                }
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
+                }
+                if (stockInfo.StockStatus != StockStatusEmun.閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
+                }
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+                }
+
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = stationCode,
+                    Grade = 0,
+                    NextAddress = "",
+                    PalletCode = palletCode,
+                    Roadway = "",
+                    SourceAddress = stationCode,
+                    TargetAddress = "",
+                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
+                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                    WarehouseId = stockInfo.WarehouseId,
+                    PalletType = stockInfo.PalletType
+                };
+
+
+                if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
+                {
+                    stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt();
+                }
+                else if (stockInfo.StockStatus == StockStatusEmun.MES閫�搴�.ObjToInt())
+                {
+                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
+                }
+                else if (stockInfo.StockStatus == StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt())
+                {
+                    //todo 灏忔墭鐩樻殏鏃舵湭鍚敤
+                    if (stockInfo.PalletType == PalletTypeEnum.MediumPallet.ObjToInt())
+                    {
+                        newTask.TaskType = TaskTypeEnum.MesPalletLargeReturn.ObjToInt();
+                    }
+                    else
+                    {
+                        newTask.TaskType = TaskTypeEnum.MesPalletSmallReturn.ObjToInt();
+                    }
+                }
+                else
+                {
+                    stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+                }
+
+                _unitOfWorkManage.BeginTran();
+                int taskId = BaseDal.AddData(newTask);
+                newTask.TaskId = taskId;
+                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                _unitOfWorkManage.CommitTran();
+                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
+
+                PushTasksToWCS(new List<Dt_Task> { newTask });
+                if (newTask.WarehouseId == 5) PutFinish(stationCode, newTask.PalletCode, newTask.TaskNum.ToString());
+                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="stationCode"></param>
+        /// <param name="palletCode"></param>
+        /// <param name="staions"></param>
+        /// <param name="heightType"></param>
+        /// <returns></returns>
+        public WebResponseContent DeviceRequestInboundTaskByRoadways(string stationCode, string palletCode, List<string> staions, int heightType)
+        {
+            try
+            {
+                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
+                if (task != null)
+                {
+                    PushTasksToWCS(new List<Dt_Task> { task });
+                    return WebResponseContent.Instance.OK($"璇ユ墭鐩樺凡鐢熸垚浠诲姟", _mapper.Map<WMSTaskDTO>(task));
+                }
+
+                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
+                {
+                    return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
+                }
+
+                string roadwayNo = AssignRoadwayNo(staions, palletCode, heightType);
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
+                }
+                if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES閫�搴�.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
+                }
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+                }
+
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = stationCode,
+                    Grade = 0,
+                    NextAddress = "",
+                    PalletCode = palletCode,
+                    Roadway = roadwayNo,
+                    SourceAddress = stationCode,
+                    TargetAddress = roadwayNo,
+                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
+                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                    WarehouseId = stockInfo.WarehouseId,
+                    PalletType = stockInfo.PalletType
+                };
+
+                if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
+                {
+                    stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt();
+                }
+                else if (stockInfo.StockStatus == StockStatusEmun.MES閫�搴�.ObjToInt())
+                {
+                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
+                }
+                else
+                {
+                    stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+                }
+
+                _unitOfWorkManage.BeginTran();
+                int taskId = BaseDal.AddData(newTask);
+                newTask.TaskId = taskId;
+                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                _unitOfWorkManage.CommitTran();
+                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
+
+                PushTasksToWCS(new List<Dt_Task> { newTask });
+                //if (newTask.WarehouseId == 5) PutFinish(stationCode);
                 return WebResponseContent.Instance.OK(data: wMSTaskDTO);
             }
             catch (Exception ex)
@@ -315,8 +587,64 @@
                 {
                     return WebResponseContent.Instance.OK(data: task.TargetAddress);
                 }
-
+                
                 Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId);
+                if (locationInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
+                }
+
+                task.Roadway = roadwayNo;
+                task.TargetAddress = locationInfo.LocationCode;
+                if (task.Roadway.Contains("AGV"))
+                {
+                    task.TaskStatus = TaskStatusEnum.AGV_Execute.ObjToInt();
+                }
+                else
+                {
+                    task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
+                }
+                
+
+                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
+
+                _unitOfWorkManage.BeginTran();
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
+                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
+                BaseDal.UpdateData(task);
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK(data: locationInfo.LocationCode);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <param name="roadwayNo"></param>
+        /// <param name="heightType"></param>
+        /// <returns></returns>
+        public WebResponseContent AssignInboundTaskLocationByHeight(int taskNum, string roadwayNo, int heightType)
+        {
+            try
+            {
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鍏ュ簱浠诲姟");
+                }
+
+                if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null)
+                {
+                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
+                }
+
+                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, heightType: heightType);
                 if (locationInfo == null)
                 {
                     return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
@@ -341,5 +669,189 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+        public readonly string[] OutStartPonits = { "5230", "5237", "5244" };
+        /// <summary>
+        /// 鎴愬搧浣欐枡閫�搴撳叆浠�
+        /// </summary>
+        /// <param name="barCode"></param>
+        /// <param name="startPoint"></param>
+        /// <returns></returns>
+        public WebResponseContent BackProductTask(string barCode, string startPoint)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                string palletCode = @"^C\d{5}$";  // 姝e垯琛ㄨ揪寮�
+                bool isValid = Regex.IsMatch(barCode, palletCode);
+                if (!isValid)
+                {
+                    return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}");
+                }
+                if (!OutStartPonits.Contains(startPoint))
+                {
+                    return content.Error($"璧风偣閿欒{startPoint}");
+                }
+                //鍒ゆ柇褰撳墠鐐逛綅鏄惁閲嶅
+                Dt_Task taskOldPoint = BaseDal.QueryFirst(x=>x.SourceAddress==startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt()||x.TaskStatus==TaskStatusEnum.Line_Execute.ObjToInt()|| x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt() || x.TaskStatus == TaskStatusEnum.AGV_Takeing.ObjToInt()));
+                if (taskOldPoint != null)
+                {
+                    return content.Error($"绔欑偣{startPoint}宸插瓨鍦ㄤ换鍔�");
+                }
+                Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode);
+                if (taskOld != null)
+                {
+                    return content.Error($"鑳舵{barCode}浠诲姟宸插瓨鍦�");
+                }
+                //鑾峰彇鑳舵浣欐枡
+                Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x=>x.PalletCode== barCode).Includes(x=>x.proStockInfoDetails).First();
+                if (proStockInfo==null)
+                {
+                    return content.Error($"鏈壘鍒皗barCode}鑳舵淇℃伅");
+                }
+                if (proStockInfo.proStockInfoDetails==null || proStockInfo.proStockInfoDetails.Count<=0)
+                {
+                    return content.Error($"{barCode}鑳舵淇℃伅涓虹┖");
+                }
+                if (proStockInfo.StockStatus!=StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+                {
+                    return content.Error($"{barCode}鑳舵淇℃伅鐘舵�佸紓甯�");
+                }
+                //鑾峰彇鎴愬搧骞冲簱
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
+                if (proStockInfo.WarehouseId != warehouse.WarehouseId && proStockInfo.LocationCode!= "鎴愬搧鍖呰鎷h揣鍖�")
+                {
+                    return content.Error($"{barCode}鑳舵淇℃伅涓嶅湪鎷h揣鍖�");
+                }
+                //鑾峰彇褰撳墠鐨勫簱瀛樺睘鎬�
+                Dt_Warehouse? warePoint = null;
+                switch (proStockInfo.ProStockAttribute)
+                {
+                    case (int)ProStockAttributeEnum.鎴愬搧:
+                        warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
+                        break;
+                    case (int)ProStockAttributeEnum.灏炬暟:
+                        warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA72.ToString());
+                        break;
+                    case (int)ProStockAttributeEnum.鐮斿彂:
+                        warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA73.ToString());
+                        break;
+                    default:
+                        throw new Exception($"鏈壘鍒皗barCode}鑳舵淇℃伅搴撳瓨灞炴��");
+                }
+                Dt_Warehouse warehouseLocation = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
+                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseLocation.WarehouseId);
+                if (locationInfo == null)
+                {
+                    return content.Error($"鏈壘鍒皗warehouse.WarehouseCode}璐т綅淇℃伅");
+                }
+                proStockInfo.StockStatus = StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt();
+                proStockInfo.proStockInfoDetails.ForEach(x =>
+                {
+                    x.ProOutDetailStatus = StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt();
+                });
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = startPoint,
+                    Grade = 0,
+                    NextAddress = "",
+                    PalletCode = proStockInfo.PalletCode,
+                    Roadway = locationInfo.RoadwayNo,
+                    SourceAddress = startPoint,
+                    TargetAddress = "",
+                    TaskType = TaskTypeEnum.InProductBack.ObjToInt(),
+                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                    WarehouseId = warePoint.WarehouseId,
+                    PalletType = proStockInfo.PalletType
+                };
+                _unitOfWorkManage.BeginTran();
+                int taskId = BaseDal.AddData(newTask);
+                newTask.TaskId = taskId;
+                _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
+                _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails);
+                _unitOfWorkManage.CommitTran();
+                //鎺ㄩ�佷换鍔�
+                PushTasksToWCS(new List<Dt_Task> { newTask });
+                content.OK("鍙戦�佹垚鍔�");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 绌烘鍥炲簱
+        /// </summary>
+        public WebResponseContent EmptyBackTask(string barCode, string startPoint)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                string palletCode = @"^C\d{5}$";  // 姝e垯琛ㄨ揪寮�
+                bool isValid = Regex.IsMatch(barCode, palletCode);
+                if (!isValid)
+                {
+                    return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}");
+                }
+                if (!OutStartPonits.Contains(startPoint))
+                {
+                    return content.Error($"璧风偣閿欒{startPoint}");
+                }
+                //鍒ゆ柇褰撳墠鐐逛綅鏄惁閲嶅
+                Dt_Task taskOldPoint = BaseDal.QueryFirst(x => x.SourceAddress == startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Execute.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt()));
+                //if (taskOldPoint != null)
+                //{
+                //    return content.Error($"绔欑偣{startPoint}宸插瓨鍦ㄤ换鍔�");
+                //}
+                Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode);
+                if (taskOld != null)
+                {
+                    return content.Error($"鑳舵{barCode}浠诲姟宸插瓨鍦�");
+                }
+                //if (_stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode) != null)
+                //{
+                //    return content.Error($"鑳舵{barCode}搴撳瓨淇℃伅宸插瓨鍦�");
+                //}
+                //todo:涓存椂瑙g粦
+                Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode);
+                if (_stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode) != null)
+                {
+                    proStockInfo.PalletCode = proStockInfo.PalletCode + ":" + DateTime.Now.ToString("MM/dd");
+                }
+                //鑾峰彇鎴愬搧骞冲簱
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = startPoint,
+                    Grade = 0,
+                    NextAddress = "",
+                    PalletCode = barCode,
+                    Roadway = "CL01_CP",
+                    SourceAddress = startPoint,
+                    TargetAddress = "",
+                    TaskType = TaskTypeEnum.EmptyProductBack.ObjToInt(),
+                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                    WarehouseId = warehouse.WarehouseId,
+                    PalletType = 1
+                };
+                _unitOfWorkManage.BeginTran();
+                int taskId = BaseDal.AddData(newTask);
+                if (proStockInfo!=null)
+                {
+                    _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
+                }
+                newTask.TaskId = taskId;
+                _unitOfWorkManage.CommitTran();
+                //鎺ㄩ�佷换鍔�
+                PushTasksToWCS(new List<Dt_Task> { newTask });
+                content.OK("鍙戦�佹垚鍔�");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
     }
 }

--
Gitblit v1.9.3