xxyy
2025-03-10 457b75b642a1fdaa7158e5b047cabc5d7ae16333
修复和优化 Dt_TaskService.cs 中的任务请求逻辑

- 移除不必要的 using 语句,清理代码。
- 修改 MapToAgingOutputDto 方法以支持可空参数。
- 优化条件判断,提升代码可读性。
- 删除冗余的请求任务入库方法,简化逻辑。
- 添加异常处理,确保系统稳定性。
- 更新 .gitignore 文件以排除不必要的文件。
已删除1个文件
已修改3个文件
250 ■■■■■ 文件已修改
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs 247 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -1687,3 +1687,4 @@
/Code Management/.vs/Code Management/CopilotIndices/17.13.433.20974/SemanticSymbols.db
/Code Management/.vs/Code Management/CopilotIndices/17.13.433.20974/SemanticSymbols.db-shm
/Code Management/.vs/Code Management/CopilotIndices/17.13.433.20974/SemanticSymbols.db-wal
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77
Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77
Binary files differ
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,6 +1,5 @@
using Mapster;
using Masuit.Tools;
using NewLife.Log;
using SqlSugar;
using System.Text.RegularExpressions;
using WIDESEA_Cache;
@@ -160,7 +159,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);
@@ -546,7 +545,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}");
            }
@@ -630,244 +629,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)
    {
@@ -1115,7 +876,7 @@
        };
    }
    #endregion 外部接口方法
    #endregion 请求任务入库
    #region 请求出库(实盘&空盘)
@@ -1848,7 +1609,7 @@
        }
    }
    #endregion 静置异常口入库
    #endregion 外部接口方法
    #endregion 外部接口方法
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -1,8 +1,6 @@
using Masuit.Tools;
using SqlSugar;
using WIDESEA_Common.CustomModels;
//using WIDESEA_Common.CustomModels;
using WIDESEA_Core.Const;
using WIDESEA_DTO.MOM;
using WIDESEA_DTO.WMS;