刘磊
23 小时以前 373c52bea19dd631687453b4d6cb711ccf55b73a
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,5 +1,6 @@
using Mapster;
using Masuit.Tools;
using SixLabors.Fonts.Tables.AdvancedTypographic;
using SqlSugar;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -85,30 +86,30 @@
        {
            if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
            {
                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                //if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                //{
                if (!task.Roadway.Contains("FR") && stock.ProcessCode != "OCVB")
                {
                    if (!task.Roadway.Contains("FR") && stock.ProcessCode != "OCVB")
                    var agingOutputDto = MapToAgingOutputDto(stock);
                    content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto);
                    if (content.Status)
                    {
                        var agingOutputDto = MapToAgingOutputDto(stock);
                        content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto);
                        var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString());
                        if (content.Status)
                        if (!result.Success && result.MessageCode == "E10001")
                        {
                            var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString());
                            if (!result.Success && result.MessageCode == "E10001")
                            {
                                await HandleOutBoundError(stock, task);
                            }
                        }
                        else
                        {
                            task.Remark = "NG";
                            ConsoleHelper.WriteErrorLine("MOM通报点芯NG");
                            return content.Error("MOM通报点芯NG");
                            await HandleOutBoundError(stock, task);
                        }
                    }
                    else
                    {
                        task.Remark = "NG";
                        ConsoleHelper.WriteErrorLine("MOM通报点芯NG");
                        return content.Error("MOM通报点芯NG");
                    }
                }
                //}
            }
            if (task.Remark == "NG")
@@ -428,8 +429,8 @@
            Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("任务完成").Error(true, err);
            content.Error(err.Message);
            task.ErrorMessage= err.Message;
            task.TaskState=(int)TaskInStatusEnum.SC_InExecuting;
            task.ErrorMessage = err.Message;
            task.TaskState = (int)TaskInStatusEnum.SC_InExecuting;
            await BaseDal.Update(task);
        }
        return content;
@@ -616,13 +617,13 @@
        }
        LogFactory.GetLog("任务完成").InfoFormat(true, "验证任务是否存在", JsonConvert.SerializeObject(task));
        if (task.TaskType == (int)TaskOutboundTypeEnum.InToOut)
        {
            return await CompleteInToOutTaskAsync(task);
        }
        // 验证库存是否存在
        var stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode);
        if (task.TaskType == (int)TaskOutboundTypeEnum.InToOut)
        {
            return await CompleteInToOutTaskAsync(task, stock);
        }
        // 根据任务类型调用相应的完成任务方法
        switch (task.TaskType)
        {
@@ -636,7 +637,7 @@
            case (int)TaskOutboundTypeEnum.OutTray:
            case (int)TaskOutboundTypeEnum.Outbound:
            case (int)TaskOutboundTypeEnum.OutNG:
                LogFactory.GetLog("任务完成").InfoFormat(true, "出库任务", "");
                return await CompleteStackTaskAsync(task, stock);
@@ -647,7 +648,6 @@
            case (int)TaskRelocationTypeEnum.Relocation:
                return await CompleteTransferTaskAsync(task, stock);
            default:
                return content.Error("任务类型不存在");
        }
@@ -674,6 +674,11 @@
            var stock = await QueryStockInfo(input.PalletCode);
            if (stock != null)
            {
                List<string> strings = new List<string>() { "GW", "CW", "FR" };
                if (stock.AreaCode.Contains(strings))
                {
                    return content.Error($"托盘【{stock.PalletCode}】存在库存不允许入库");
                }
                Dt_Task taskNew = new Dt_Task
                {
                    Grade = 1,
@@ -776,6 +781,7 @@
            // 更详细的异常处理,可以根据异常类型记录不同的错误日志等
            content.Error(err.Message);
            Console.WriteLine(err.Message);
            LogFactory.GetLog($"请求入库异常").Info(true, $"异常信息【{err.Message}】异常行【{err.StackTrace}】");
        }
        return content;
@@ -859,8 +865,8 @@
                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();
                List<string> productLineconfigOne = configOne.ConfigValue.Split(',').ToList();
                List<string> productLineconfigTwo = configTwo.ConfigValue.Split(',').ToList();
                if (productLineconfigOne.Count == 0 && productLineconfigTwo.Count() == 0)
                {
@@ -879,13 +885,13 @@
                {
                    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);
        }
@@ -904,8 +910,8 @@
    // 获取组盘信息
    private DtBoxingInfo CreateBoxingInfo(ResultTrayCellsStatus result, string palletCode)
    {
         var boxing=_boxingInfoRepository.QueryFirst(x=>x.PalletCode == palletCode);
    {
        var boxing = _boxingInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
        if (boxing == null)
        {
            return new DtBoxingInfo
@@ -924,7 +930,8 @@
                }).ToList()
            };
        }
        else {
        else
        {
            _boxingInfoRepository.DeleteData(boxing);
            return new DtBoxingInfo
            {
@@ -942,7 +949,7 @@
                }).ToList()
            };
        }
    }
    // 获取工艺申请
@@ -976,6 +983,8 @@
        WebResponseContent content = new WebResponseContent();
        try
        {
            // 记录异常信息并抛出
            LogFactory.GetLog($"{position}请求{productionLine}任务").Info(true, $"{position}-{tag}-{areaCode}-{JsonConvert.SerializeObject(areaCodes)}-{productionLine}");
            // 根据托盘类型查询库存信息
            DtStockInfo stockInfo = tag == (int)TaskOutboundTypeEnum.Outbound
                ? areaCode != "CWSC1" ? await QueryStockInfoForRealTrayAsync(areaCode, areaCodes, productionLine) : await QueryStockInfoForRealTrayCWAsync(areaCodes, productionLine)
@@ -1306,7 +1315,7 @@
            if (stockInfo.AreaCode.Contains("CH"))
            {
                // 创建并添加任务到数据库
                if(stockInfo.LocationInfo.RoadwayNo=="CHSC1"|| stockInfo.LocationInfo.RoadwayNo == "CHSC2"|| stockInfo.LocationInfo.RoadwayNo == "CHSC3")
                if (stockInfo.LocationInfo.RoadwayNo == "CHSC1" || stockInfo.LocationInfo.RoadwayNo == "CHSC2" || stockInfo.LocationInfo.RoadwayNo == "CHSC3")
                {
                    task = CreateTask(stockInfo, "1020-1", taskType);
                }
@@ -1314,7 +1323,7 @@
                {
                    task = CreateTask(stockInfo, "1049-8", taskType);
                }
            }
            else
            {
@@ -1738,21 +1747,20 @@
        // 创建历史任务实例模型
        try
        {
            Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(key[0]));
            if (task == null)
            foreach (var 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)
@@ -1886,7 +1894,6 @@
        {
            taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
        }
        taskHty.TaskState = task.TaskType > 199 ? (int)TaskInStatusEnum.InFinish : (int)TaskOutStatusEnum.OutFinish;
        return taskHty;
    }
@@ -2143,7 +2150,10 @@
            ToAddress = await GetRoadWayAsync(process);
        else
            ToAddress = process[0];
        if (string.IsNullOrEmpty(ToAddress))
        {
            return content.Error("无法获取目标地址");
        }
        // 创建新任务实例
        var task = new Dt_Task
        {