huangxiaoqiang
2025-06-05 87ce8f1a70dfbf819e6804a26ab8e845a134856c
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -2,6 +2,7 @@
using Masuit.Tools;
using SqlSugar;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEA_Cache;
using WIDESEA_Core.Const;
using WIDESEA_DTO.MOM;
@@ -31,6 +32,7 @@
    private readonly IAgingInOrOutInputService _agingInOrOutInputService; //静置\陈化
    private readonly IDt_StationManagerRepository _stationManagerRepository;
    private readonly ISys_ConfigService _configService;
    private readonly IDt_ChangeoversRepository _dt_ChangeoversRepository;
    private readonly ISimpleCacheService _simpleCacheService;
    public Dt_TaskService(IDt_TaskRepository BaseDal,
@@ -50,7 +52,8 @@
                                IStockInfoDetailRepository stockInfoDetailRepository,
                                IDt_StationManagerRepository stationManagerRepository,
                                ISys_ConfigService configService,
                                ISimpleCacheService simpleCacheService) : base(BaseDal)
                                ISimpleCacheService simpleCacheService,
                                IDt_ChangeoversRepository dt_ChangeoversRepository) : base(BaseDal)
    {
        _unitOfWorkManage = unitOfWorkManage;
        _stockInfoRepository = stockInfoRepository;
@@ -68,6 +71,7 @@
        _stationManagerRepository = stationManagerRepository;
        _configService = configService;
        _simpleCacheService = simpleCacheService;
        _dt_ChangeoversRepository = dt_ChangeoversRepository;
    }
    #region 外部接口方法
@@ -135,14 +139,14 @@
                await DeleteTaskAsync(task.TaskId);
                await AddTaskHtyAsync(taskHty);
            });
            try
            {
                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("删除缓存失败").Error(true, $"{stock.PalletCode}_删除缓存失败,异常信息:{ex.Message}");
            }
            //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);
        }
@@ -247,7 +251,7 @@
        var isStockUpdated = await _locationRepository.UpdateDataAsync(info);
        if (!isStockUpdated)
        {
            throw new Exception("库存信息更新失败");
            throw new Exception("库位信息更新失败");
        }
    }
@@ -280,6 +284,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 移库任务完成
@@ -327,7 +361,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;
                // 创建历史任务实例模型
@@ -380,16 +414,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("入库任务完成成功");
            }
@@ -404,6 +428,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;
    }
@@ -609,8 +636,15 @@
            case (int)TaskOutboundTypeEnum.OutTray:
            case (int)TaskOutboundTypeEnum.Outbound:
            case (int)TaskOutboundTypeEnum.OutNG:
            case (int)TaskOutboundTypeEnum.OutQuality:
                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);
@@ -724,12 +758,13 @@
            else
            {
                // 处理异常电芯情况
                var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
                if (serialNosError.Count > 0)
                {
                    return await HandleErrorCells(input, area, serialNosError);
                }
                #region 电芯分结果异常不需要我们处理
                //var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
                //if (serialNosError.Count > 0)
                //{
                //    return await HandleErrorCells(input, area, serialNosError);
                //}
                #endregion
                var boxing = CreateBoxingInfo(result, input.PalletCode);
                if (boxing == null) return content.Error("组盘失败");
@@ -819,7 +854,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);
        }
@@ -839,21 +906,44 @@
    // 获取组盘信息
    private DtBoxingInfo CreateBoxingInfo(ResultTrayCellsStatus result, string palletCode)
    {
        return new DtBoxingInfo
        var boxing=_boxingInfoRepository.QueryFirst(x=>x.PalletCode== palletCode);
        if (boxing == null)
        {
            PalletCode = palletCode,
            IsFull = true,
            ProcessCode = result.ProcessCode,
            ProductionLine = result.ProductionLine,
            BoxingInfoDetails = result.SerialNos.Select(serialNoObj => new DtBoxingInfoDetail
            return new DtBoxingInfo
            {
                SerialNumber = serialNoObj.SerialNo,
                OrderNo = serialNoObj.PositionNo.ToString(),
                Status = serialNoObj.SerialNoStatus,
                MaterielCode = result.BindCode,
                Remark = result.TrayBarcodePropertys.ToJsonString(),
            }).ToList()
        };
                PalletCode = palletCode,
                IsFull = true,
                ProcessCode = result.ProcessCode,
                ProductionLine = result.ProductionLine,
                BoxingInfoDetails = result.SerialNos.Select(serialNoObj => new DtBoxingInfoDetail
                {
                    SerialNumber = serialNoObj.SerialNo,
                    OrderNo = serialNoObj.PositionNo.ToString(),
                    Status = serialNoObj.SerialNoStatus,
                    MaterielCode = result.BindCode,
                    Remark = result.TrayBarcodePropertys.ToJsonString(),
                }).ToList()
            };
        }
        else
        {
            _boxingInfoRepository.DeleteData(boxing);
            return new DtBoxingInfo
            {
                PalletCode = palletCode,
                IsFull = true,
                ProcessCode = result.ProcessCode,
                ProductionLine = result.ProductionLine,
                BoxingInfoDetails = result.SerialNos.Select(serialNoObj => new DtBoxingInfoDetail
                {
                    SerialNumber = serialNoObj.SerialNo,
                    OrderNo = serialNoObj.PositionNo.ToString(),
                    Status = serialNoObj.SerialNoStatus,
                    MaterielCode = result.BindCode,
                    Remark = result.TrayBarcodePropertys.ToJsonString(),
                }).ToList()
            };
        }
    }
    // 获取工艺申请
@@ -951,35 +1041,30 @@
                return null;
            }
            var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel");
            //var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel");
            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;
            IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
            List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
            var result = new DtStockInfo();
            if (areaCode == "CH001")
            {
                LogFactory.GetLog("CH001").Info(true, JsonConvert.SerializeObject(stockInfoList[0], Formatting.Indented));
            }
            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($"{areaCode}-{productionLine}查询实盘库存信息失败:未找到符合条件的数据");
            if (result.IsNullOrEmpty())
                ConsoleHelper.WriteErrorLine($"{area.AreaName}-{productionLine}查询实盘库存信息失败:未找到符合条件的数据");
            return result;
        }
@@ -1011,7 +1096,8 @@
            //    materielCodes = outBoundMateriel.Where(x => x.ProductionLine == productionLine && x.ProcessCode == areaCodes[0]).Select(x => x.MaterielCode).ToList();
            //}
            var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel");
            //var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel");
            var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList();
            List<string>? materielCodes = outBoundMateriel.Count != 0
                ? outBoundMateriel.Where(x => x.ProductionLine == productionLine && x.ProcessCode == areaCodes[0])
                                  .Select(x => x.MaterielCode)
@@ -1022,27 +1108,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;
        }
@@ -1073,21 +1152,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;
        }
@@ -1231,7 +1308,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
            {
@@ -1655,21 +1740,23 @@
        // 创建历史任务实例模型
        try
        {
            Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(key[0]));
            if (task == null)
            foreach (object item in key)
            {
                return content.Error("未找到任务信息!");
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(key));
                if (task == null)
                {
                    return content.Error("未找到任务信息!");
                }
                var taskHtyNG = CreateHistoricalTask(task, true);
                // 执行数据库事务
                // 添加历史任务
                var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0;
                // 删除任务数据
                var isTaskDelete = BaseDal.Delete(task.TaskId);
            }
            var taskHtyNG = CreateHistoricalTask(task, true);
            // 执行数据库事务
            // 添加历史任务
            var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0;
            // 删除任务数据
            var isTaskDelete = BaseDal.Delete(task.TaskId);
            return content.OK("删除成功!");
        }
        catch (Exception ex)
@@ -1860,32 +1947,32 @@
            }
            #region 更新库存信息(暂时不需要)
            //if (stock.IsFull)
            //{
            //    // 查询符合条件的库存信息
            //    var stocks = _stockInfoRepository.QueryData(x => x.AreaCode == stock.AreaCode && x.ProductionLine == stock.ProductionLine && x.SpecialParameterDuration != stock.SpecialParameterDuration);
            if (stock.IsFull)
            {
                // 查询符合条件的库存信息
                var stocks = _stockInfoRepository.QueryData(x => x.AreaCode == stock.AreaCode && x.ProductionLine == stock.ProductionLine && x.SpecialParameterDuration != stock.SpecialParameterDuration);
            //    // 查询任务信息
            //    var tasks = BaseDal.QueryData(x => x.PalletCode != stock.PalletCode && x.ProductionLine == stock.ProductionLine).Select(x => x.PalletCode).ToList();
                // 查询任务信息
                var tasks = BaseDal.QueryData(x => x.PalletCode != stock.PalletCode && x.ProductionLine == stock.ProductionLine).Select(x => x.PalletCode).ToList();
            //    if (stocks != null && stocks.Count > 0)
            //    {
            //        // 过滤出需要更新的库存信息
            //        var stocksToUpdate = stocks.Where(item => !tasks.Contains(item.PalletCode)).ToList();
            //        foreach (var item in stocksToUpdate)
            //        {
            //            // 更新库存信息的特定参数
            //            item.SpecialParameterDuration = stock.SpecialParameterDuration;
            //            item.ParameterInfos = stock.ParameterInfos;
            //            item.OutboundTime = Convert.ToDateTime(item.LinedProcessFeedbackTime == null ? item.CreateDate : item.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(stock.SpecialParameterDuration));
            //        }
            //        if (stocksToUpdate.Count > 0)
            //        {
            //            // 异步更新库存信息
            //            var isUpdates = await _stockInfoRepository.UpdateDataAsync(stocksToUpdate);
            //        }
            //    }
            //}
                if (stocks != null && stocks.Count > 0)
                {
                    // 过滤出需要更新的库存信息
                    var stocksToUpdate = stocks.Where(item => !tasks.Contains(item.PalletCode)).ToList();
                    foreach (var item in stocksToUpdate)
                    {
                        // 更新库存信息的特定参数
                        item.SpecialParameterDuration = stock.SpecialParameterDuration;
                        item.ParameterInfos = stock.ParameterInfos;
                        item.OutboundTime = Convert.ToDateTime(item.LinedProcessFeedbackTime == null ? item.CreateDate : item.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(stock.SpecialParameterDuration));
                    }
                    if (stocksToUpdate.Count > 0)
                    {
                        // 异步更新库存信息
                        var isUpdates = await _stockInfoRepository.UpdateDataAsync(stocksToUpdate);
                    }
                }
            }
            #endregion
            // 添加历史任务