From 67348f250a1b7970059698002949a5e0a5f3c52f Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 14 八月 2025 08:51:04 +0800
Subject: [PATCH] 上传最新代码

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs |  207 ++++++++++++++++++++++-----------------------------
 1 files changed, 90 insertions(+), 117 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
index 3a26c86..8728bfe 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
@@ -1,4 +1,5 @@
 锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using SqlSugar;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -22,123 +23,6 @@
 {
     public partial class TaskService
     {
-        /// <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, newTask.PalletCode, newTask.TaskNum.ToString());
-                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>
         /// 浠呯敵璇蜂换鍔★紝璁¦CS鏍规嵁璺敱纭畾涓嬩竴鍦板潃
         /// </summary>
@@ -234,6 +118,95 @@
             }
         }
         /// <summary>
+        /// 鍘熸枡鐢宠鍏ュ簱
+        /// </summary>
+        /// <param name="stationCode">璧峰绔欑偣</param>
+        /// <param name="palletCode">鎵樼洏</param>
+        /// <returns></returns>
+        public WebResponseContent RequestYLWMSTaskSimple(string stationCode, string palletCode)
+        {
+            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())
+            {
+                return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
+            }
+            string rowWay = AssignYLRoadwayNo(stockInfo.PalletCode);
+            Dt_Task newTask = new Dt_Task()
+            {
+                CurrentAddress = stationCode,
+                Grade = 0,
+                NextAddress = "",
+                PalletCode = palletCode,
+                Roadway = rowWay,
+                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();
+            }
+            _unitOfWorkManage.BeginTran();
+            int taskId = BaseDal.AddData(newTask);
+            newTask.TaskId = taskId;
+            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+            _unitOfWorkManage.CommitTran();
+            PushTasksToWCS(new List<Dt_Task> { newTask });
+            WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
+            return WebResponseContent.Instance.OK(data: wMSTaskDTO);
+        }
+        public string AssignYLRoadwayNo(string palletCode)
+        {
+            try
+            {
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == stockInfo.WarehouseId);
+
+                if (warehouse == null)
+                {
+                    throw new Exception($"鏈壘鍒板贩閬撳搴斾粨搴撲俊鎭�");
+                }
+
+                string roadwayNo = "";
+                if (stockInfo.MaterielWide < 2200 && stockInfo.MaterielThickness > 800)
+                {
+                    List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("SC01_YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                    roadwayNo = locationCounts.OrderBy(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
+                }
+                else if (stockInfo.MaterielWide>2200 && stockInfo.MaterielThickness>800)
+                {
+                    List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && !x.RoadwayNo.Contains("SC01_YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                    roadwayNo = locationCounts.OrderBy(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
+                }
+                return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                throw new Exception(ex.Message);
+            }
+        }
+        /// <summary>
         /// 鍏ュ簱浠诲姟鐢宠鍒嗛厤璐т綅
         /// </summary>
         /// <param name="taskNum">浠诲姟鍙�</param>

--
Gitblit v1.9.3