From d8db1698c125618c1b5f62b009204ddc5d4eed5a Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 19 三月 2025 20:34:08 +0800
Subject: [PATCH] 成品代码更新....

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs |  512 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 471 insertions(+), 41 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 4bb32e3..cf866ab 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"
@@ -1,14 +1,19 @@
-锘縰sing System;
+锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 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.Task;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_TaskInfoService
@@ -18,8 +23,7 @@
         /// <summary>
         /// 鐢宠鍏ュ簱浠诲姟(PDA浣跨敤锛屼粎鎵樼洏缁戝畾鍏ュ簱绔欏彴锛屼笉鍒嗛厤璐т綅)
         /// </summary>
-        /// <param name="palletCode">鎵樼洏鍙�</param>
-        /// <param name="stationCode">绔欏彴鍙�</param>
+        /// <param name="saveModel"></param>
         /// <returns></returns>
         public WebResponseContent RequestInboundTask(SaveModel saveModel)
         {
@@ -28,23 +32,29 @@
                 var palletCode = saveModel.MainData["barcode"].ToString();
                 var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
                 var stationCode = saveModel.MainData["startPoint"].ToString();
+                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)
+                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())
+                if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt())
                 {
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
                 }
@@ -56,37 +66,74 @@
                 {
                     return WebResponseContent.Instance.Error($"浠撳簱涓嶆纭�");
                 }
-
-                Dt_Task newTask = new Dt_Task()
+                if (warehouse.WarehouseCode == WarehouseEnum.HA60.ToString())
                 {
-                    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();
+                    Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseId);
+                    if (locationInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒板綋鍓嶅簱鍖鸿揣浣嶄俊鎭�");
+                    return DeviceRequestInboundTask(stationCode, locationInfo.RoadwayNo, palletCode);
                 }
                 else
                 {
-                    stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+                    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
+                    };
+                    //鑾峰彇鏄惁瀛樺湪鍏ュ簱鍗�
+                    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();
+                    }
+                    _unitOfWorkManage.BeginTran();
+                    int taskId = BaseDal.AddData(newTask);
+                    newTask.TaskId = taskId;
+                    _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                    _unitOfWorkManage.CommitTran();
+                    PushTasksToWCS(new List<Dt_Task> { newTask });
+                    return WebResponseContent.Instance.OK(data: newTask);
                 }
-                _unitOfWorkManage.BeginTran();
-                int taskId = BaseDal.AddData(newTask);
-                newTask.TaskId = taskId;
-                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
-                _unitOfWorkManage.CommitTran();
-                PushTasksToWCS(new List<Dt_Task> { newTask });
-                return WebResponseContent.Instance.OK(data: newTask);
             }
             catch (Exception ex)
             {
@@ -95,6 +142,131 @@
             }
         }
 
+        /// <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)
+        {
+            try
+            {
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板簱鍖�");
+                }
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode && x.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt());
+                if (stockInfo != null) throw new Exception($"鎵樼洏鍙峰凡瀛樺湪");
+                stockInfo = new Dt_StockInfo()
+                {
+                    PalletCode = barcode,
+                    StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(),
+                    WarehouseId = WarehouseId,
+                    PalletType = PalletTypeEnum.Empty.ObjToInt(),
+                    Details = new List<Dt_StockInfoDetail>()
+                };
+                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == WarehouseId);
+                if (locationInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒板綋鍓嶅簱鍖鸿揣浣嶄俊鎭�");
+                locationInfo = _basicService.LocationInfoService.AssignLocation(locationInfo.RoadwayNo, ((PalletTypeEnum)stockInfo.PalletType).ObjToInt(), stockInfo.WarehouseId);
+                if (locationInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
+                }
+
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = address,
+                    Grade = 0,
+                    NextAddress = locationInfo.LocationCode,
+                    PalletCode = barcode,
+                    Roadway = locationInfo.RoadwayNo,
+                    SourceAddress = address,
+                    TargetAddress = locationInfo.LocationCode,
+                    TaskType = TaskTypeEnum.InEmpty.ObjToInt(),
+                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                    WarehouseId = stockInfo.WarehouseId,
+                    PalletType = stockInfo.PalletType
+                };
+                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
+                _unitOfWorkManage.BeginTran();
+                int taskId = BaseDal.AddData(newTask);
+                newTask.TaskId = taskId;
+                _basicRepository.LocationInfoRepository.UpdateData(locationInfo);
+                _stockRepository.StockInfoRepository.AddData(stockInfo);
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(new List<Dt_Task> { newTask });
+                PutFinish(address);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                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
+            {
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板簱鍖�");
+                }
+                List<Dt_StockInfo> stockInfos = null;
+                if (string.IsNullOrEmpty(barcode))
+                {
+                    stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(), qty, nameof(Dt_StockInfo.CreateDate));
+                }
+                else
+                {
+                    stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.PalletCode == barcode);
+                    if (stockInfos.Count == 0) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}鏈壘鍒扮┖绠便�恵barcode}銆�");
+                }
+
+                if (stockInfos.Count < qty) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}绌虹搴撳瓨涓嶈冻,搴撳瓨鏁般�恵stockInfos.Count}銆�");
+                List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutEmpty);
+                stockInfos.ForEach(x =>
+                {
+                    x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                });
+                tasks.ForEach(x =>
+                {
+                    x.TargetAddress = address;
+                    x.NextAddress = address;
+                });
+                _unitOfWorkManage.BeginTran();
+                BaseDal.AddData(tasks);
+                _stockRepository.StockInfoRepository.UpdateData(stockInfos);
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                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
@@ -102,20 +274,21 @@
                 Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                 if (task != null)
                 {
-                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡鐢熸垚浠诲姟");
+                    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())
+                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‘,涓嶅彲鐢宠鍏ュ簱");
                 }
@@ -124,7 +297,7 @@
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
                 }
 
-                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, (PalletTypeEnum)stockInfo.PalletType, stockInfo.WarehouseId);
+                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, stockInfo.PalletType, stockInfo.WarehouseId);
                 if (locationInfo == null)
                 {
                     return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
@@ -145,21 +318,230 @@
                     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);
+                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, newTask.PalletType, LocationStatusEnum.Lock, newTask.WarehouseId);
+                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)
+            {
+                _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.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt() && 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 鏆傛椂鏈惎鐢�
+                    return WebResponseContent.Instance.Error($"绌烘墭鏈惎鐢�");
+                    //newTask.TaskType = TaskTypeEnum.MesPalletReturn.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 });
-                return WebResponseContent.Instance.OK(data: newTask);
+                if (newTask.WarehouseId == 5) PutFinish(stationCode);
+                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)
             {
@@ -189,7 +571,7 @@
                     return WebResponseContent.Instance.OK(data: task.TargetAddress);
                 }
 
-                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, (PalletTypeEnum)task.PalletType, task.WarehouseId);
+                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId);
                 if (locationInfo == null)
                 {
                     return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
@@ -202,8 +584,56 @@
                 LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
 
                 _unitOfWorkManage.BeginTran();
-                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundAssignLocation);
-                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
+                _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($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
+                }
+
+                task.Roadway = roadwayNo;
+                task.TargetAddress = locationInfo.LocationCode;
+                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);

--
Gitblit v1.9.3