From 990afb24199ef1f7a4648728ac28ed74394e459c Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期二, 31 三月 2026 12:27:50 +0800
Subject: [PATCH] 任务服务优化与接口扩展,日志与配置调整

---
 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs |  112 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 90 insertions(+), 22 deletions(-)

diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
index 7662b61..8350e38 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,4 +1,5 @@
-锘縰sing Mapster;
+锘縰sing AngleSharp.Io;
+using Mapster;
 using Masuit.Tools;
 using SixLabors.Fonts.Tables.AdvancedTypographic;
 using SqlSugar;
@@ -10,6 +11,7 @@
 using WIDESEA_DTO.WMS;
 using WIDESEA_IServices;
 using WIDESEA_IStoragIntegrationServices;
+using WIDESEA_Model.Models;
 using WIDESEAWCS_BasicInfoRepository;
 using WIDESEAWCS_QuartzJob.Models;
 
@@ -665,9 +667,13 @@
         {
             // 鏌ヨ浠诲姟
             var task = await QueryTaskByPalletCode(input.PalletCode);
-            if (task != null)
+            if (task != null && (task.TaskState == (int)TaskInStatusEnum.InNew || task.TaskState == (int)TaskOutStatusEnum.OutNew))
             {
                 return CreateAndReturnWMSTaskDTO(task);
+            }
+            if(task != null && (task.TaskState != (int)TaskInStatusEnum.InNew || task.TaskState != (int)TaskOutStatusEnum.OutNew))
+            {
+                return content.Error($"鎵樼洏{input.PalletCode}瀛樺湪浠诲姟");
             }
 
             // 鏌ヨ搴撳瓨淇℃伅锛堣繖閲屽悗缁瀹屽杽璐ㄦ鍥炲簱閫昏緫锛�
@@ -1024,6 +1030,8 @@
                 stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable;
                 await _locationRepository.UpdateDataAsync(stockInfo.LocationInfo);
             }
+            if (position == "1670")
+                LogFactory.GetLog($"OCV{position}璇锋眰{productionLine}浠诲姟").Info(true, $"杩斿洖鍙傛暟{JsonConvert.SerializeObject(taskDTO)}");
 
             // 杩斿洖鎴愬姛鍝嶅簲
             return content.OK(data: taskDTO);
@@ -1052,26 +1060,38 @@
             }
 
             //var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel");
-            var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList();
+            //var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList();
 
-            List<string>? materielCodes = outBoundMateriel.Count != 0
-                ? outBoundMateriel.Where(x => x.ProductionLine == productionLine && x.ProcessCode == area.AreaCode)
-                                  .Select(x => x.MaterielCode)
-                                  .ToList()
-                : null;
+            //List<string>? materielCodes = outBoundMateriel.Count != 0
+            //    ? outBoundMateriel.Where(x => x.ProductionLine == productionLine && x.ProcessCode == area.AreaCode)
+            //                      .Select(x => x.MaterielCode)
+            //                      .ToList()
+            //    : null;
 
-            var result = new DtStockInfo();
+            //DtStockInfo result = null;
 
-            result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+            var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
                             .Includes(x => x.LocationInfo)
-                            .Includes(x => x.StockInfoDetails)
+                            //.Includes(x => x.StockInfoDetails)
                             .Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull)
                             .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
                             .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo))
                             .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable)
-                            .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
+                            //.WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
                             .OrderBy(x => x.OutboundTime)
                             .FirstAsync();
+            //foreach (var stock in stockInfoList)
+            //{
+            //    var hasMatchingDetail = await _stockInfoRepository.Db.Queryable<DtStockInfoDetail>()
+            //        .Where(d => d.StockId == stock.Id && materielCodes.Contains(d.MaterielCode))
+            //        .AnyAsync();
+
+            //    if (hasMatchingDetail)
+            //    {
+            //        result = stock;
+            //        break;
+            //    }
+            //}
 
             if (result.IsNullOrEmpty())
                 ConsoleHelper.WriteErrorLine($"{area.AreaName}-{productionLine}鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
@@ -1119,21 +1139,43 @@
                 .Where(x => x.DeviceCode.Contains("CWSC"))
                 .ToList().Select(x => x.DeviceCode).ToList();
 
+            //var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+            //    .Where(x => areaCodes.Contains(x.AreaCode) && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢
+            //    .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
+            //    .Includes(x => x.LocationInfo)
+            //    .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo))
+            //    .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && areaId.Contains(x.LocationInfo.AreaId) && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢
+            //    .Includes(x => x.StockInfoDetails)
+            //    .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
+            //    .OrderBy(x => x.OutboundTime) // 鎺掑簭
+            //    .FirstAsync(); // 鑾峰彇绗竴涓厓绱�
+
+            DtStockInfo stockInfo = null;
             var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
                 .Where(x => areaCodes.Contains(x.AreaCode) && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢
                 .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
                 .Includes(x => x.LocationInfo)
                 .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo))
                 .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && areaId.Contains(x.LocationInfo.AreaId) && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢
-                .Includes(x => x.StockInfoDetails)
-                .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
                 .OrderBy(x => x.OutboundTime) // 鎺掑簭
-                .FirstAsync(); // 鑾峰彇绗竴涓厓绱�
+                .ToListAsync();
 
-            if (result.IsNullOrEmpty())
+            foreach (var stock in result)
+            {
+                var hasMatchingDetail = await _stockInfoRepository.Db.Queryable<DtStockInfoDetail>()
+                    .Where(d => d.StockId == stock.Id && materielCodes.Contains(d.MaterielCode))
+                    .AnyAsync();
+
+                if (hasMatchingDetail)
+                {
+                    stockInfo = stock;
+                    break;
+                }
+            }
+            if (stockInfo.IsNullOrEmpty())
                 ConsoleHelper.WriteErrorLine($"{JsonConvert.SerializeObject(areaCodes)}-{productionLine}鏌ヨ甯告俯瀹炵洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
 
-            return result;
+            return stockInfo;
         }
         catch (Exception ex)
         {
@@ -1162,21 +1204,36 @@
                 .Where(x => stackers.Contains(x.DeviceCode))
                 .ToList().Select(x => x.DeviceCode).ToList();
 
+            DtStockInfo stockInfo = null;
+
             var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
                 .Where(x => x.ProductionLine == station.productLine)
                 .Where(x => x.AreaCode == areaCode && x.IsFull == false)
-                .Includes(x => x.StockInfoDetails)
-                .Where(x => x.StockInfoDetails.Any(y => y.MaterielCode == "绌烘墭鐩�"))
+                //.Includes(x => x.StockInfoDetails)
+                //.Where(x => x.StockInfoDetails.Any(y => y.MaterielCode == "绌烘墭鐩�"))
                 .Includes(x => x.LocationInfo)
                 .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo))
                 .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢
                 .OrderBy(x => x.CreateDate) // 鎺掑簭
-                .FirstAsync(); // 杞崲涓哄垪琛�
+                .ToListAsync();
+
+            foreach (var stock in result)
+            {
+                var hasMatchingDetail = await _stockInfoRepository.Db.Queryable<DtStockInfoDetail>()
+                    .Where(d => d.StockId == stock.Id && d.MaterielCode == "绌烘墭鐩�")
+                    .AnyAsync();
+
+                if (hasMatchingDetail)
+                {
+                    stockInfo = stock;
+                    break;
+                }
+            }
 
             if (result.IsNullOrEmpty())
                 ConsoleHelper.WriteErrorLine($"{area}-{station.productLine}鏌ヨ绌虹洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
 
-            return result;
+            return stockInfo;
         }
         catch (Exception ex)
         {
@@ -1540,6 +1597,13 @@
                 ConsoleHelper.WriteErrorLine(content.ToJsonString());
                 var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString());
                 if (result == null || !result.Success) return content.Error(result?.MOMMessage ?? "Deserialization error");
+
+                List<string> strings = station.productLine.Split(",").ToList();
+                if (!result.ProductionLine.Contains(strings))
+                {
+                    ConsoleHelper.WriteErrorLine($"鎵樼洏鍙枫�恵palletCode}銆戣姹備骇绾裤�恵result.ProductionLine}銆戜笉鍏佽鍏ャ�恵station.Roadway}銆�");
+                    return content.Error($"鎵樼洏鍙枫�恵palletCode}銆戣姹備骇绾裤�恵result.ProductionLine}銆戜笉鍏佽鍏ャ�恵station.Roadway}銆�");
+                }
 
                 if (result.SerialNos.Count > 0)
                 {
@@ -2271,7 +2335,7 @@
              .Where(x => x.DeviceStatus == 1.ToString() && process.Contains(x.DeviceCode))
              .Select(x => x.DeviceCode).ToListAsync();
 
-        var minGroup = _locationRepository.QueryData(x => deviceCode.Contains(x.RoadwayNo) && x.LocationStatus == (int)LocationEnum.Free)
+        var minGroup = _locationRepository.QueryData(x => deviceCode.Contains(x.RoadwayNo) && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
              .GroupBy(x => x.RoadwayNo)
              .OrderByDescending(g => g.Count()) // 鏍规嵁姣忎釜缁勭殑鍏冪礌鏁伴噺鎺掑簭
              .ToList(); // 鍙栧嚭鏁伴噺鏈�澶氱殑缁�
@@ -2280,6 +2344,10 @@
         foreach (var item in minGroup)
         {
             var number = BaseDal.QueryData(x => x.TargetAddress == item.Key).Count();
+            if (item.Count() - number <= 0)
+            {
+                continue;
+            }
             result.Add(item.Key, item.Count() - number);
         }
 

--
Gitblit v1.9.3