Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
@@ -146,4 +146,4 @@ app.MapHubs(); app.MapControllers(); app.Run(); app.Run(); Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/appsettings.json
@@ -1,5 +1,5 @@ { "urls": "http://*:9291", //web服务端口,如果用IIS部署,把这个去掉 "urls": "http://*:9290", //web服务端口,如果用IIS部署,把这个去掉 "Logging": { "LogLevel": { "Default": "Information", @@ -12,7 +12,7 @@ "MainDB": "DB_WIDESEA", //当前项目的主库,所对应的连接字符串的Enabled必须为true //连接字符串 //"ConnectionString": "Data Source=.\\LIULEI;Initial Catalog=WIDESEA_WCSDBB2F;User ID=sa;Password=123456;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", "ConnectionString": "Data Source=.;Initial Catalog=WIDESEA_WCSDB;User ID=sa;Password=P@ssw0rd;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", "ConnectionString": "Data Source=.;Initial Catalog=WIDESEA_WCSDB;User ID=sa;Password=123456;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", //跨域 "Cors": { "PolicyName": "CorsIpAccess", //策略名称 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs
@@ -448,7 +448,7 @@ { if (task.TaskType == (int)TaskOutboundTypeEnum.InToOut && taskDTO.RoadWay.Contains("CW")) { var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == taskDTO.RoadWay); var stationinfo = _stationManagerRepository.QueryFirst(x => (x.stationPLC == "1017" ||x.stationPLC=="1024")&& x.stationType == 10 && x.Roadway == taskDTO.RoadWay); task.TaskState = (int)TaskOutStatusEnum.OutNew; task.CurrentAddress = taskDTO.SourceAddress; task.NextAddress = stationinfo.stationChildCode; Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs
@@ -320,20 +320,36 @@ /// <param name="command">读取的请求信息</param> /// <param name="childDeviceCode">子设备编号</param> /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param> /// <summary> /// 触发输送线出库请求处理 /// </summary> /// <param name="conveyorLine">输送线实例(CommonConveyorLine_CW类型),包含输送线设备基础信息和操作方法</param> /// <param name="command">输送线任务指令对象(后续版本),暂未直接使用,预留指令上下文</param> /// <param name="childDeviceCode">子设备编码,用于定位输送线的具体子设备</param> public void RequestOutbound(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { // 根据主输送线设备编码和子设备编码,查询对应的输送线任务 var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); // 若查询到有效任务,则执行后续指令发送和状态更新逻辑 if (task != null) { // 将数据库查询到的任务对象映射为指令对象(适配指令发送的数据结构) ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); //conveyorLine.SendCommand(taskCommand, childDeviceCode); // 发送任务指令到指定输送线子设备,并获取发送结果(原注释掉的conveyorLine.SendCommand已替换为封装后的方法) bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); // 若指令发送成功,执行状态更新操作 if (sendFlag) { // 更新输送线子设备的响应状态为1(1代表指令已响应/处理成功,对应数据库字段ConveyorLineDBName_After.ResponState) conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); // 将任务状态更新到下一个阶段(通用任务状态流转) _taskService.UpdateTaskStatusToNext(task); // 特殊处理:若任务类型为出托盘(OutTray),额外再执行一次任务状态更新(适配出托盘任务的特殊状态流转逻辑) if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) { _taskService.UpdateTaskStatusToNext(task); @@ -348,63 +364,103 @@ /// <param name="conveyorLine">输送线实例对象</param> /// <param name="command">读取的请求信息</param> /// <param name="childDeviceCode">子设备编号</param> /// <summary> /// 处理输送线下一地址请求(核心逻辑:查询执行中任务→获取MOM配置→调用MOM接口校验→根据校验结果/任务状态发送指令并更新任务) /// </summary> /// <param name="conveyorLine">输送线实例(CommonConveyorLine_CW类型),包含输送线设备基础信息和操作方法</param> /// <param name="command">输送线任务指令对象(后续版本),携带任务编号、条码、子设备编码等关键指令参数</param> /// <param name="childDeviceCode">子设备编码,用于定位输送线的具体子设备</param> public void RequestOutNextAddress(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { // 1. 查询指定条件下正在执行的输送线任务(任务编号+子设备编码+输送线条码) Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); // 仅当查询到有效执行中任务时,执行后续逻辑 if (task != null) { // 2. 获取系统配置中「IP地址」分类下的配置项(用于拼接MOM接口地址) var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); // 提取MOM基础IP配置值 var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue; // 提取托盘格口状态接口的IP路径配置值 var ipAddress = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.TrayCellsStatus)?.ConfigValue; // 校验MOM IP配置完整性,缺失则抛出异常终止流程 if (wmsBase == null || ipAddress == null) { throw new InvalidOperationException("MOM IP 未配置"); } // 3. 查询当前输送线设备+子设备对应的工位配置信息(关联PLC编码、子编码与MOM设备编码) Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); // 4. 构建托盘格口状态校验的请求DTO(适配MOM接口入参格式) TrayCellsStatusDto trayCells = new TrayCellsStatusDto() { Software = "WMS", TrayBarcode = command.ConveyorLineBarcode, EquipmentCode = stationManager.stationEquipMOM, SessionId = Guid.NewGuid().ToString(), EmployeeNo = "MITest", SceneType = "1", RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") Software = "WMS", // 调用方系统标识(固定为WMS) TrayBarcode = command.ConveyorLineBarcode, // 输送线条码(托盘条码) EquipmentCode = stationManager.stationEquipMOM, // MOM系统对应的设备编码 SessionId = Guid.NewGuid().ToString(), // 唯一会话ID(防止重复请求) EmployeeNo = "MITest", // 操作员工编号(测试固定值) SceneType = "1", // 场景类型(1代表入站校验场景) RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") // UTC格式请求时间 }; // 拼接完整的MOM接口地址(基础IP + 接口路径) var MOMIpAddress = wmsBase + ipAddress; // 5. 调用MOM接口(POST异步请求,同步等待结果) var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result; // 记录接口调用日志(请求参数、返回参数),便于问题排查 WriteInfo("入站校验", $"【{childDeviceCode}】入站校验请求参数【{trayCells.Serialize()}】"); WriteInfo("入站校验", ""); WriteInfo("入站校验", $"【{childDeviceCode}】入站校验返回参数【{result}】"); // 6. 解析MOM接口返回结果为实体对象 ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result); // 7. 分支1:接口校验成功 或 任务备注非NG(正常流程) if (result1.Success || task.Remark != "NG") { // 更新任务的位置信息(任务编号+当前地址),返回更新后的任务对象 Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); if (newTask != null) { // 将更新后的任务对象映射为输送线指令对象(适配指令发送结构) ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); //conveyorLine.SendCommand(taskCommand, childDeviceCode); // 发送指令到输送线子设备,获取发送结果(封装后的SendCommand方法) bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); // 指令发送成功则更新设备响应状态和任务数据 if (sendFlag) { // 更新输送线子设备响应状态为1(代表指令处理成功) conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); // 持久化更新后的任务数据到数据库 _taskService.UpdateData(newTask); } } } // 8. 分支2:接口校验失败 且 任务备注为NG(异常流程,发送NG地址指令) else { // 将原任务对象映射为输送线指令对象 ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); // 设置指令的目标地址为工位配置中的NG子编码(导向异常处理工位) taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); //conveyorLine.SendCommand(taskCommand, childDeviceCode); // 发送NG地址指令到输送线子设备,获取发送结果 bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); // 指令发送成功则更新设备响应状态和任务状态 if (sendFlag) { // 更新输送线子设备响应状态为1 conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); // 将任务状态流转到下一个阶段(适配NG任务的状态逻辑) _taskService.UpdateTaskStatusToNext(task); } } Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -173,13 +173,13 @@ if (commonStackerCrane.DeviceCode.Contains("CW") && task.TaskType==(int)TaskOutboundTypeEnum.InToOut) { var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode); var stationinfo = _stationManagerRepository.QueryFirst(x => (x.stationPLC == "1017"||x.stationPLC=="1024") && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode); IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationinfo.stationPLC); if (device != null) { CommonConveyorLine_CW conveyorLine = (CommonConveyorLine_CW)device; conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(1815), stationinfo.stationChildCode); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(4000), stationinfo.stationChildCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, 1000, stationinfo.stationChildCode); } @@ -334,24 +334,11 @@ else { IDevice? device = null; if (task.Roadway.Contains("GWSC3")) if (task.Roadway.Contains("GW")) { device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "2025"); if (device != null) { CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device; if (conveyorLine.IsOccupied(task.TargetAddress))//出库站台未被占用 { return task; } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.TargetAddress}】对应的通讯对象,无法判断出库站台是否被占用"); } } else if (task.Roadway.Contains("GW")) { device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1015"); string targetDeviceCode = task.Roadway == "GWSC3" ? "2025" : "1015"; device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == targetDeviceCode); if (device != null) { CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device; Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob_NewCW/CommonStackerCrane_NewCWJob.cs
@@ -173,13 +173,13 @@ if (commonStackerCrane.DeviceCode.Contains("CW") && task.TaskType==(int)TaskOutboundTypeEnum.InToOut) { var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode); var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1024" && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode); IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationinfo.stationPLC); if (device != null) { CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)device; conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(1815), stationinfo.stationChildCode); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(4000), stationinfo.stationChildCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, 1000, stationinfo.stationChildCode); } Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
@@ -1,4 +1,6 @@ using AngleSharp.Dom; using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Excel; using Mapster; using Masuit.Tools; using SqlSugar; @@ -10,6 +12,8 @@ using WIDESEA_Cache; using WIDESEA_Common; using WIDESEA_Core; using WIDESEA_IStorageBasicService; using WIDESEA_Model.Models.BasicModel; namespace WIDESEA_StorageBasicService; @@ -18,10 +22,12 @@ private readonly ISimpleCacheService _simpleCacheService; private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository; public StockInfoService(IStockInfoRepository BaseDal, ISimpleCacheService simpleCacheService, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository) : base(BaseDal) private readonly IStockInfoDetailRepository _IStockInfoDetailRepository; public StockInfoService(IStockInfoRepository BaseDal, ISimpleCacheService simpleCacheService, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, IStockInfoDetailRepository stockInfoDetailService) : base(BaseDal) { _simpleCacheService = simpleCacheService; _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; _IStockInfoDetailRepository = stockInfoDetailService; } /// <summary> @@ -151,6 +157,71 @@ .ToDictionary(x => x.Key, x => x.Count()); return result; } public override WebResponseContent Export(PageDataOptions options) { WebResponseContent content = new WebResponseContent(); try { // 1. 构建主表查询条件和排序 string wheres = ValidatePageOptions(options); Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties); // 2. 查询主表数据 List<DtStockInfo> mainList = BaseDal.QueryData(wheres, orderbyDic); if (!mainList.Any()) { return WebResponseContent.Instance.OK("无数据可导出"); } // 3. 批量查询子表数据(通过主表Id关联) var mainIds = mainList.Select(m => m.Id).Distinct().ToList(); List<DtStockInfoDetail> detailList = _IStockInfoDetailRepository.Db .Queryable<DtStockInfoDetail>() .Where(d => mainIds.Contains(d.StockId)) .ToList(); // 4. 关联主表和子表数据(只取子表第一条) var exportData = new List<PalletWithDetailExportModel>(); foreach (var main in mainList) { // 只取当前主表数据关联的子表第一条(可通过OrderBy指定排序,确保取到想要的第一条) var firstDetail = detailList .Where(d => d.StockId == main.Id) .OrderBy(d => d.Id) // 可选:按子表Id排序,确保结果稳定(可替换为其他字段) .FirstOrDefault(); var exportModel = new PalletWithDetailExportModel { Id = main.Id, PalletCode = main.PalletCode, LocationCode = main.LocationCode, IsFull = main.IsFull, Remark = main.Remark, Creater = main.Creater, CreateDate = main.CreateDate, OutboundTime = (DateTime)main.OutboundTime, // 有子表数据则取第一条的物料编码,无则为空 MaterielCode = firstDetail?.MaterielCode ?? "" }; exportData.Add(exportModel); } // 5. 导出数据(逻辑不变) string savePath = AppDomain.CurrentDomain.BaseDirectory + "ExcelExport"; IExporter exporter = new ExcelExporter(); byte[] data = exporter.ExportAsByteArray(exportData).Result; string fileName = "托盘及物料编码数据.xlsx"; FileHelper.WriteFile(savePath, fileName, data); content = WebResponseContent.Instance.OK(data: Path.Combine(savePath, fileName)); } catch (Exception ex) { content = WebResponseContent.Instance.Error(ex.Message); } return content; } //public override WebResponseContent UpdateData(DtStockInfo entity) //{