using JiShe.ServicePro; using JiShe.ServicePro.ApacheIoTDB.Provider.Options; using JiShe.ServicePro.Consts; using JiShe.ServicePro.Core; using JiShe.ServicePro.Dto; using JiShe.ServicePro.Enums; using JiShe.ServicePro.FreeRedisProvider; using JiShe.ServicePro.FreeSqlProvider; using JiShe.ServicePro.IoTDBManagement.TableModels; using Volo.Abp; namespace JiShe.IoT { /* Inherit your application services from this class. */ public abstract class IoTAppService : ApplicationService { protected IFreeSqlProvider FreeSqlDbContext => LazyServiceProvider.LazyGetRequiredService(); protected IFreeRedisProvider RedisProvider => LazyServiceProvider.LazyGetRequiredService(); protected IoTAppService() { LocalizationResource = typeof(IoTResource); } /// /// 获取设备遥测指令信息 /// /// IoTDBOptions /// 请求原始对象 /// 设备信息 /// 明文消息体 /// /// protected DeviceTelemetryPacketTaskInfo GetDeviceTelemetryPacketTaskInfo(IoTDBOptions iotDBOptions, OpenApiRequest input, DeviceCacheInfos deviceInfo,string messageBody) { try { if (iotDBOptions == null || string.IsNullOrWhiteSpace(iotDBOptions.DataBaseName) || input == null || deviceInfo == null || string.IsNullOrWhiteSpace(messageBody)) { throw new UserFriendlyException($"设备遥测指令创建失败,参数信息异常。"); } //反序列化消息数据,得到数据实体 ReceiveCommandInfoDto commandIssueInfo = input.Message.Deserialize(); var oneNETIssueMessageEntity = new DeviceTelemetryPacketTaskInfo() { DataBaseName = iotDBOptions.DataBaseName, DeviceType = $"{commandIssueInfo.DeviceType}", DeviceAddress = commandIssueInfo.DeviceAddress, IssueRawMessage = input.Serialize(), IoTDataType = IoTDBDataTypeConst.Command, TelemetryType = (int)commandIssueInfo.TelemetryType, TelemetrySource = (int)commandIssueInfo.SourceType, IoTPlatform = (int)commandIssueInfo.IoTPlatform, IoTPlatformProductId = deviceInfo.IoTPlatformProductId, IoTPlatformDeviceOpenInfo = deviceInfo.IoTPlatformDeviceOpenInfo, IoTPlatformAccountId = deviceInfo.IoTPlatformAccountId, AccountPhoneNumber = deviceInfo.AccountPhoneNumber, IoTPlatformProductName = deviceInfo.IoTPlatformProductName, IssuePayload = messageBody, RetryCount = 0, IssueStatus = (int)DeviceCommandIssueStatusEnum.Unprocessed }; return oneNETIssueMessageEntity; } catch (Exception) { throw; } } } }