| | |
| | | |
| | | #region 路由方式 |
| | | List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); |
| | | |
| | | childDeviceCodes.Add("4000"); |
| | | |
| | | foreach (string childDeviceCode in childDeviceCodes) |
| | | { |
| | |
| | | MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod); |
| | | if (method != null) |
| | | { |
| | | //var strings = platform.Location.Split(',').ToList(); |
| | | int count = 1; |
| | | method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform }); |
| | | } |
| | |
| | | var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); |
| | | if (tokenInfos == null || !tokenInfos.Any()) |
| | | { |
| | | //throw new Exception(conveyorLine.DeviceName + "缓存中未找到Token缓存"); |
| | | continue; |
| | | } |
| | | var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList(); |
| | |
| | | |
| | | //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); |
| | | WriteInfo(conveyorLine.DeviceName, log); |
| | | |
| | | if (childDeviceCode == "4000") |
| | | { |
| | | conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(1601), childDeviceCode); |
| | | Thread.Sleep(100); |
| | | conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, 9999, childDeviceCode); |
| | | } |
| | | |
| | | if (task == null) |
| | | { |
| | |
| | | /// <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); |
| | |
| | | /// <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); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); |
| | | if (sendFlag) |
| | | { |
| | | conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); |
| | | content = _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationArea == "Call" && x.stationType == 12); |
| | | CommonConveyorLine_BZ? commonConveyorBZ=Storage.Devices.FirstOrDefault(x=>x.DeviceCode==station.stationPLC) as CommonConveyorLine_BZ; |
| | | if (commonConveyorBZ != null) |
| | | { |
| | | ConveyorLineTaskCommand_After readSignal = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationLocation); |
| | | if (readSignal.Reserved5 == 1) |
| | | { |
| | | var tasks = _taskRepository.QueryData(x => x.TargetAddress == childDeviceCode); |
| | | if (tasks.Count == 0) |
| | | { |
| | | commonConveyorBZ.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), station.stationLocation); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | } |
| | | } |
| | | |
| | | //conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | |
| | | bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); |
| | | if (sendFlag) |
| | | { |
| | |
| | | taskNext.ExceptionMessage = log; |
| | | content = _taskService.UpdateTaskStatusToNext(taskNext); |
| | | } |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationArea == "Call" && x.stationType == 12); |
| | | CommonConveyorLine_BZ? commonConveyorBZ = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC) as CommonConveyorLine_BZ; |
| | | if (commonConveyorBZ != null) |
| | | { |
| | | ConveyorLineTaskCommand_After readSignal = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationLocation); |
| | | if (readSignal.Reserved5 == 1) |
| | | { |
| | | var tasks = _taskRepository.QueryData(x => x.TargetAddress == childDeviceCode); |
| | | if (tasks.Count == 0) |
| | | { |
| | | commonConveyorBZ.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), station.stationLocation); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |