huangxiaoqiang
2025-04-28 a9b86405ec73459aab599119c6a593f1f3e0c767
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,8 +1,8 @@
using Mapster;
using Masuit.Tools;
using NewLife.Log;
using SqlSugar;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEA_Cache;
using WIDESEA_Core.Const;
using WIDESEA_DTO.MOM;
@@ -136,20 +136,14 @@
                await DeleteTaskAsync(task.TaskId);
                await AddTaskHtyAsync(taskHty);
            });
            try
            {
                //using (_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
                //{
                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
                //}
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("删除缓存失败").Error(true, $"{stock.PalletCode}_删除缓存失败,异常信息:{ex.Message}");
                //using (_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
                //{
                //}
            }
            //try
            //{
            //    _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
            //}
            //catch (Exception ex)
            //{
            //    LogFactory.GetLog("删除缓存失败").Error(true, $"{stock.PalletCode}_删除缓存失败,异常信息:{ex.Message}");
            //}
            return content.OK("任务完成成功", task.Remark);
        }
@@ -160,7 +154,7 @@
        }
    }
    private AgingOutputDto MapToAgingOutputDto(DtStockInfo stock, ResponseEqptRunDto info = null)
    private AgingOutputDto MapToAgingOutputDto(DtStockInfo stock, ResponseEqptRunDto? info = null)
    {
        // TODO Value值根据MOM下发的静置时间到当前时间的分钟数
        var area = _areaInfoRepository.QueryFirst(x => x.AreaCode == stock.AreaCode);
@@ -254,7 +248,7 @@
        var isStockUpdated = await _locationRepository.UpdateDataAsync(info);
        if (!isStockUpdated)
        {
            throw new Exception("库存信息更新失败");
            throw new Exception("库位信息更新失败");
        }
    }
@@ -287,6 +281,36 @@
    }
    #endregion 出库任务完成
    #region 火警任务完成
    public async Task<WebResponseContent> CompleteOutFireAlarmTaskAsync(Dt_Task task, DtStockInfo stock)
    {
        WebResponseContent content = new WebResponseContent();
        (var loc, var tas) = UpdateStockAndTaskStatus(stock, task);
        var taskHty = task.Adapt<Dt_Task_Hty>();
        taskHty.FinishTime = DateTime.Now;
        taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.人工完成 : (int)OperateTypeEnum.自动完成;
        taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
        DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>();
        stockInfo_Hty.ModifyDate = DateTime.Now;
        // 事务处理
        await _unitOfWorkManage.UseTranAsync(async () =>
        {
            if (task.TaskType != (int)TaskOutboundTypeEnum.OutQuality)
            {
                await DeleteStockInfoAsync(stock.Id);
                await DeleteStockInfoDetailsAsync(stock.StockInfoDetails);
                await AddStockInfoHtyAsync(stockInfo_Hty);
                await UpdateLocationAsync(loc); //质检任务需要持续锁定库位
            }
            await DeleteTaskAsync(task.TaskId);
            await AddTaskHtyAsync(taskHty);
        });
        return content.OK("任务完成成功", task.Remark);
    }
    #endregion
    #region 移库任务完成
@@ -334,7 +358,7 @@
        WebResponseContent content = new WebResponseContent();
        try
        {
            if (task.TaskType == (int)TaskInboundTypeEnum.InNG || task.TaskType == (int)TaskInboundTypeEnum.InQuality)
            if (task.TaskType == (int)TaskInboundTypeEnum.InNG)
            {
                task.TaskState = (int)TaskInStatusEnum.SC_InFinish;
                // 创建历史任务实例模型
@@ -387,16 +411,6 @@
                stock.StockInfoDetails = new List<DtStockInfoDetail>() { { stock.StockInfoDetails[0] } };
                stock.LocationInfo = locationInf;
                //using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
                //{
                try
                {
                    _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock);
                }
                catch (Exception ex)
                {
                    LogFactory.GetLog("添加缓存失败").Error(true, $"{stock.PalletCode}_添加缓存失败,异常信息:{ex.Message}");
                }
                content.OK("入库任务完成成功");
            }
@@ -411,6 +425,9 @@
            Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("任务完成").Error(true, err);
            content.Error(err.Message);
            task.ErrorMessage= err.Message;
            task.TaskState=(int)TaskInStatusEnum.SC_InExecuting;
            await BaseDal.Update(task);
        }
        return content;
    }
@@ -546,7 +563,7 @@
            {
                isFull = respone.SpecialParameterDuration.IsNullOrEmpty();
            }
            if (respone.ProductionLine == null || respone.ParameterInfos == null|| respone.ParameterInfos.IsNullOrEmpty())
            if (respone.ProductionLine == null || respone.ParameterInfos == null || respone.ParameterInfos.IsNullOrEmpty())
            {
                throw new Exception($"MOM数据返回错误,产线{respone.ProductionLine},ParameterInfos{respone.ParameterInfos}");
            }
@@ -616,8 +633,14 @@
            case (int)TaskOutboundTypeEnum.OutTray:
            case (int)TaskOutboundTypeEnum.Outbound:
            case (int)TaskOutboundTypeEnum.OutNG:
                LogFactory.GetLog("任务完成").InfoFormat(true, "出库任务", "");
                return await CompleteStackTaskAsync(task, stock);
            case (int)TaskOutboundTypeEnum.OutFireAlarm:
                LogFactory.GetLog("任务完成").InfoFormat(true, "火警任务", "");
                return await CompleteOutFireAlarmTaskAsync(task, stock);
            case (int)TaskRelocationTypeEnum.Relocation:
                return await CompleteTransferTaskAsync(task, stock);
@@ -630,244 +653,6 @@
    #endregion 任务完成
    #region 请求任务入库
    #region
    /// <summary>
    /// 请求任务巷道
    /// </summary>
    /// <param name="input">请求模型</param>
    /// <returns>包含任务信息的响应内容</returns>
    public async Task<WebResponseContent> RequestTaskAsync2(RequestTaskDto input)
    {
        // 创建一个WebResponseContent对象
        WebResponseContent content = new WebResponseContent();
        try
        {
            // 调用BaseDal.QueryFirstAsync方法,查询任务
            var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode);
            if (task != null)
            {
                //if (task.TaskState == (int)TaskInStatusEnum.InNew)
                {
                    // 创建WMS任务
                    WMSTaskDTO taskDTO = new WMSTaskDTO()
                    {
                        TaskNum = task.TaskNum.Value,
                        Grade = 1,
                        PalletCode = task.PalletCode,
                        RoadWay = task.Roadway,
                        SourceAddress = task.SourceAddress,
                        TargetAddress = task.Roadway,
                        TaskState = task.TaskState.Value,
                        Id = 0,
                        TaskType = task.TaskType,
                    };
                    return content.OK(data: taskDTO);
                }
            }
            var stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == input.PalletCode && x.IsFull);
            if (stock != null)
            {
                // TODO质检回库
            }
            var area = await _areaInfoRepository.QueryFirstAsync(x => x.Spare1.Contains(input.Position));
            if (area == null)
                return content.Error("改点位不在区域列表中存在");
            // 创建一个TrayCellsStatusDto对象,并赋值
            TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
            {
                Software = area.Spare3,
                TrayBarcode = input.PalletCode,
                EquipmentCode = area.Spare2,
                SceneType = area.Spare4,
            };
            // 调用GetTrayCellStatusAsync方法,获取整盘电芯
            content = await GetTrayCellStatusAsync(trayCells);
            // 如果状态为false,则返回content
            if (!content.Status) return content;
            // 添加组盘信息
            // 将content.Data转换为ResultTrayCellsStatus对象
            var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString());
            if (!result.Success)
                return content.Error(result.MOMMessage);
            // 获取异常电芯
            List<SerialNoDto>? serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
            if (serialNosError.Count > 0)
            {
                // TODO 创建任务送至NG排出口
                var efg = _stationManagerRepository.QueryData(x => x.stationType == 1 && x.stationChildCode == input.Position && x.stationArea == area.AreaCode).ToList();
                //List<string> NGStation = input.Position == "1088" ? new List<string>() { "1020" } : new List<string>() { "JZSC01" };
                if (efg.Count <= 0)
                {
                    throw new Exception("未找到NG入库站台配置");
                }
                List<string> NGStation = efg.Select(x => x.stationNGLocation).ToList();
                if (NGStation.Count <= 0)
                {
                    NGStation = efg.Select(x => x.stationNGChildCode).ToList();
                }
                content = await CreateNewTask(input, result.ProductionLine, result.ProcessCode, NGStation, 2);
                return content.Error("存在异常电芯");
            }
            if (result.SerialNos.Count <= 0)
            {
                // Todo 空托盘入库逻辑
                content = await RequestTrayInTaskAsync(input);
                return content;
            }
            var boxing = CreateBoxingInfo(result, input.PalletCode);
            //Console.WriteLine(boxing.ToJsonString());
            if (boxing == null) return content.Error("组盘失败");
            if (result.ProcessCode == "OCVB")
            {
                //TODO 判断需不需要去包装,不需要就去常温三
                var stationManagers = _stationManagerRepository.QueryData(x => x.stationPLC == "1018" && x.stationArea == "Cache");
                var station = stationManagers.Select(x => x.stationChildCode).ToList();
                // 获取WCSip地址
                var configz = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wcsBasez = configz.Where(x => x.ConfigKey == SysConfigConst.WCSIPAddress).FirstOrDefault()?.ConfigValue;
                var address = configz.Where(x => x.ConfigKey == SysConfigConst.GetStation).FirstOrDefault()?.ConfigValue;
                if (wcsBasez == null || address == null)
                {
                    throw new InvalidOperationException("WCS IP 未配置");
                }
                var wcsIpAddrss = wcsBasez + address;
                var abc = HttpHelper.PostAsync(wcsIpAddrss, station.ToJsonString()).Result;
                content = JsonConvert.DeserializeObject<WebResponseContent>(abc);
                if (content.Data.ObjToInt() > 0)
                {
                    // TODO 送至包装
                    List<string> strings = stationManagers.Where(x => x.stationType == 0).Select(x => x.Roadway).ToList();
                    content = await CreateNewTask(input, result.ProductionLine, result.ProcessCode, strings, 3);
                    return content;
                }
                else
                {
                    var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker");
                    var strings = config.ConfigValue.Split(',').ToList();
                    // TODO 入库
                    content = await CreateNewTask(input, result.ProductionLine, result.ProcessCode, strings);
                    if (content.Status)
                        await _boxingInfoRepository.AddDataNavAsync(boxing);
                }
            }
            else
            {
                // TODO 获取本地料框属性与整盘电芯属性获取的值进行对比,如果一致则继续,否则返回错误信息
                //var productions = await _productionRepository.QueryDataAsync(x => result.TrayBarcodePropertys.Select(x => x.TrayBarcodeProperty).ToList().Contains(x.TrayBarcodeProperty));
                //if (productions.Count <= 0)
                //    return content.Error("料框属性不存在");
                // 调用CreateBoxingInfo方法,创建组盘信息
                //var boxing = CreateBoxingInfo(result, input.PalletCode);
                ////Console.WriteLine(boxing.ToJsonString());
                //if (boxing == null) return content.Error("组盘失败");
                // 调用GetProcessApplyAsync方法,获取工艺路线
                ProcessApplyDto process = await GetProcessApplyAsync(result);
                // 如果process为null,则返回content
                if (process == null) return content;
                // 并赋值上位软件名称和设备编码
                process.Software = area.Spare3;
                process.EquipmentCode = area.Spare2;
                // 调用GetProcessApplyAsync方法,获取工艺申请
                // 调用_processApplyService.GetProcessApplyAsync方法,获取工艺申请
                content = await _processApplyService.GetProcessApplyAsync(process);
                // 如果状态为false,则返回null
                if (!content.Status) return content.Error("工艺申请失败");
                var resultProcessApply = JsonConvert.DeserializeObject<ResultProcessApply>(content.Data.ToString());
                if (!resultProcessApply.Success) return content.Error("工艺申请失败");
                var number = resultProcessApply.ProcessInfo.Where(x => x.ProcessCode == boxing.ProcessCode).FirstOrDefault().Number.ToInt32();
                foreach (var item in resultProcessApply.ProcessInfo)
                {
                    if (item.Number.ToInt32() == number + 1)
                    {
                        boxing.NextProcessCode = item.ProcessCode;
                    }
                }
                Console.WriteLine();
                Console.WriteLine($"当前工序:{boxing.ProcessCode}");
                Console.WriteLine($"下一工序:{boxing.NextProcessCode}");
                Console.WriteLine(area.AreaCode + "-----------------------");
                Console.WriteLine(input.Position + "-----------------------");
                var areaIn = string.Empty;
                switch (boxing.NextProcessCode)
                {
                    case "CH01":
                        areaIn = "CH001";
                        break;
                    case "JZ01":
                        areaIn = "JZ001";
                        break;
                    case "GW01":
                        areaIn = "GWSC1";
                        break;
                    case "CW01":
                        areaIn = "CWSC1";
                        break;
                    case "CW02":
                        areaIn = "CWSC2";
                        break;
                    default:
                        break;
                }
                var stationManagers = _stationManagerRepository.QueryData(x => x.stationType == 1 && x.stationChildCode == input.Position && x.stationArea.Contains(areaIn)).FirstOrDefault();
                if (stationManagers == null)
                {
                    throw new Exception("未找到入库站台配置");
                }
                List<string> strings = stationManagers.Roadway.Split(',').ToList();
                Console.WriteLine(strings.ToJsonString() + "b-----------------------");
                //// 调用CreateNewTask方法,创建新任务
                content = await CreateNewTask(input, result.ProductionLine, result.ProcessCode, strings);
                if (content.Status)
                {
                    var isBox = await _boxingInfoRepository.AddDataNavAsync(boxing);
                }
                //}
            }
        }
        catch (Exception err)
        {
            // 如果发生异常,则调用content.Error方法,记录错误信息,并输出错误信息
            content.Error(err.Message);
            Console.WriteLine(err.Message);
        }
        // 返回content
        return content;
    }
    #endregion 请求任务入库
    public async Task<WebResponseContent> RequestTaskAsync(RequestTaskDto input)
    {
@@ -1064,7 +849,39 @@
                if (stationManagers == null)
                    throw new Exception("未找到空托盘入库站台和入库站台配置");
            }
            List<string> strings = stationManagers.Roadway.Split(',').ToList();
            List<string> strings;
            if (input.Position == "1016-3")
            {
                var configOne = _configService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStacker, SysConfigConst.CHInboundEmptyProductLineOne);
                var configTwo = _configService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStacker, SysConfigConst.CHInboundEmptyProductLineTwo);
                List<string>  productLineconfigOne = configOne.ConfigValue.Split(',').ToList();
                List<string>  productLineconfigTwo = configTwo.ConfigValue.Split(',').ToList();
                if (productLineconfigOne.Count == 0 && productLineconfigTwo.Count() == 0)
                {
                    ConsoleHelper.WriteErrorLine($"未找到配置文件产线配置");
                    return content.Error("未找到配置文件产线配置");
                }
                if (productLineconfigOne.Contains(result.ProductionLine))
                {
                    strings = configOne.Remark.Split(',').ToList();
                }
                else if (productLineconfigTwo.Contains(result.ProductionLine))
                {
                    strings = configTwo.Remark.Split(',').ToList();
                }
                else
                {
                    ConsoleHelper.WriteErrorLine($"未找到{result.ProductionLine}对应配置巷道");
                    return content.Error($"未找到{result.ProductionLine}对应配置巷道");
                }
            }
            else
            {
                strings = stationManagers.Roadway.Split(',').ToList();
            }
            return await CreateNewTask(input, result.ProductionLine, result.ProcessCode, strings, 1);
        }
@@ -1115,7 +932,7 @@
        };
    }
    #endregion 外部接口方法
    #endregion 请求任务入库
    #region 请求出库(实盘&空盘)
@@ -1203,34 +1020,27 @@
                                  .ToList()
                : null;
            IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
            List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
            var result = new DtStockInfo();
            //if (stockInfoList.IsNullOrEmpty())
            //{
            //    stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
            //        .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock).IncludesAllFirstLayer().ToListAsync();
            //}
            result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
                            .Includes(x => x.LocationInfo)
                            .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)))
                            .OrderBy(x => x.OutboundTime)
                            .FirstAsync();
            result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull)
                              .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
                              .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable)
                              .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo))
                              .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
                              .OrderBy(x => x.OutboundTime)
            .FirstOrDefault();
            if (result != null)
                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
            else
                ConsoleHelper.WriteErrorLine("QueryStockInfoForRealTrayAsync查询实盘库存信息失败:未找到符合条件的数据");
            if (result.IsNullOrEmpty())
                ConsoleHelper.WriteErrorLine($"{area.AreaName}-{productionLine}查询实盘库存信息失败:未找到符合条件的数据");
            return result;
        }
        catch (Exception ex)
        {
            ConsoleHelper.WriteErrorLine("QueryStockInfoForRealTrayAsync查询实盘库存信息失败:" + ex.Message + "\r\n" + ex.StackTrace);
            ConsoleHelper.WriteErrorLine("查询实盘库存信息失败:" + ex.Message + "\r\n" + ex.StackTrace);
            return null;
        }
    }
@@ -1267,27 +1077,20 @@
                .Where(x => x.DeviceStatus == "1")
                .Where(x => x.DeviceCode.Contains("CWSC"))
                .ToList().Select(x => x.DeviceCode).ToList();
            //var deviceCode = devices.Select(x => x.DeviceCode).ToList();
            IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
            List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
            var result = stockInfoList.Where(x => areaCodes.Contains(x.AreaCode) && x.OutboundTime < DateTime.Now && x.IsFull == true) // 过滤条件
            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)
                .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && areaId.Contains(x.LocationInfo.AreaId) && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件
                .Includes(x => x.LocationInfo)
                .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo))
                .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
                .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) // 排序
                .FirstOrDefault(); // 获取第一个元素
                .FirstAsync(); // 获取第一个元素
            if (result != null)
            {
                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
            }
            else
            {
                ConsoleHelper.WriteErrorLine("QueryStockInfoForRealTrayCWAsync查询常温实盘库存信息失败:未找到符合条件的数据");
            }
            if (result.IsNullOrEmpty())
                ConsoleHelper.WriteErrorLine($"{JsonConvert.SerializeObject(areaCodes)}-{productionLine}查询常温实盘库存信息失败:未找到符合条件的数据");
            return result;
        }
@@ -1318,21 +1121,19 @@
                .Where(x => stackers.Contains(x.DeviceCode))
                .ToList().Select(x => x.DeviceCode).ToList();
            IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
            List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
            var result = stockInfoList.Where(x => x.ProductionLine == station.productLine)
            var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
                .Where(x => x.ProductionLine == station.productLine)
                .Where(x => x.AreaCode == areaCode && x.IsFull == false)
                .Where(x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => y.MaterielCode == "空托盘"))
                .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件
                .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) // 排序
                .FirstOrDefault(); // 转换为列表
                .FirstAsync(); // 转换为列表
            if (result != null)
                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
            else
                ConsoleHelper.WriteErrorLine("QueryStockInfoForEmptyTrayAsync查询空盘库存信息失败:未找到符合条件的数据");
            if (result.IsNullOrEmpty())
                ConsoleHelper.WriteErrorLine($"{area}-{station.productLine}查询空盘库存信息失败:未找到符合条件的数据");
            return result;
        }
@@ -1476,7 +1277,15 @@
            if (stockInfo.AreaCode.Contains("CH"))
            {
                // 创建并添加任务到数据库
                task = CreateTask(stockInfo, "1020-1", taskType);
                if(stockInfo.LocationInfo.RoadwayNo=="CHSC1"|| stockInfo.LocationInfo.RoadwayNo == "CHSC2"|| stockInfo.LocationInfo.RoadwayNo == "CHSC3")
                {
                    task = CreateTask(stockInfo, "1020-1", taskType);
                }
                else
                {
                    task = CreateTask(stockInfo, "1049-1", taskType);
                }
            }
            else
            {
@@ -1848,7 +1657,7 @@
        }
    }
    #endregion 静置异常口入库
    #endregion 外部接口方法
    #endregion 外部接口方法