完善业务系统对接
This commit is contained in:
parent
d1c02f023f
commit
376ce4a0a5
@ -17,7 +17,7 @@ namespace JiShe.IoT.BusinessSystemAggregation.Dto
|
||||
/// 设备来源类型,只接收 预付费业务系统推送、能耗业务系统推送
|
||||
/// </summary>
|
||||
public DeviceSourceTypeEnum DeviceSourceType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 物联网平台类型
|
||||
/// </summary>
|
||||
@ -33,4 +33,23 @@ namespace JiShe.IoT.BusinessSystemAggregation.Dto
|
||||
/// </summary>
|
||||
public List<string> DeviceAddresses { get; set; }
|
||||
}
|
||||
|
||||
public class SubDeviceInfoInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备地址
|
||||
/// </summary>
|
||||
public string DeviceAddresses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子设备地址
|
||||
/// </summary>
|
||||
public string SubDeviceAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子设备索引
|
||||
/// </summary>
|
||||
public int SubDeviceIndex { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
using JiShe.ServicePro.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.BusinessSystemAggregation.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 单个查询设备信息输入
|
||||
/// </summary>
|
||||
public class QueryDeviceDataInfoInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备类型
|
||||
/// </summary>
|
||||
public DeviceTypeEnum DeviceType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
public string IoTDataType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间,最终需要转换为纳秒级时间戳
|
||||
/// </summary>
|
||||
public DateTime BeginTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间,最终需要转换为纳秒级时间戳
|
||||
/// </summary>
|
||||
public DateTime EndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网关或者直连设备地址
|
||||
/// </summary>
|
||||
public string DeviceAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子设备地址
|
||||
/// </summary>
|
||||
public string SubDeviceAddress { get; set; }
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,13 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult<List<IoTDBDynamicObject>>> BatchQueryDeviceDataInfoAsync(OpenApiRequest input);
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统查询单个设备数据,Msg 字段为 QueryDeviceDataInfoInput 实体
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult<List<IoTDBDynamicObject>>> QueryDeviceDataInfoAsync(OpenApiRequest input);
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量新增设备数据,Msg 字段为 BatchCreateDeviceInfoInput 实体
|
||||
/// </summary>
|
||||
|
||||
@ -213,6 +213,91 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统查询单个设备数据,Msg 字段为 QueryDeviceDataInfoInput 实体
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult<List<IoTDBDynamicObject>>> QueryDeviceDataInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var handleResult = HandleOpenApiRequest<QueryDeviceDataInfoInput>(input, serverOptions);
|
||||
if (handleResult.Success == false)
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, handleResult.Message, handleResult.LocationCode);
|
||||
}
|
||||
var messageBody = handleResult.Data;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(messageBody.DeviceAddress))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, "设备地址不能为空", -103);
|
||||
}
|
||||
|
||||
// Lua脚本
|
||||
string luaScript = @"
|
||||
local hashKey = KEYS[1]
|
||||
local fieldKeys = ARGV
|
||||
return redis.call('HMGET', hashKey, unpack(fieldKeys))";
|
||||
|
||||
//执行脚本
|
||||
var result = await FreeRedisProvider.Instance.EvalAsync
|
||||
(
|
||||
luaScript,
|
||||
new[] { RedisConst.CacheAllDeviceInfoHashKey },
|
||||
new List<string>() { messageBody.DeviceAddress }.ToArray()
|
||||
);
|
||||
|
||||
List<DeviceCacheInfos> deviceCacheInfos = new List<DeviceCacheInfos>();
|
||||
|
||||
// 处理返回结果
|
||||
if (result is object[] values)
|
||||
{
|
||||
foreach (var value in values)
|
||||
{
|
||||
var tempFocusInfo = ServiceProJsonSerializer.Deserialize<DeviceCacheInfos>(value as string);
|
||||
deviceCacheInfos.Add(tempFocusInfo);
|
||||
}
|
||||
}
|
||||
|
||||
List<IoTDBDynamicObject> queryResult = new List<IoTDBDynamicObject>();
|
||||
var deviceCacheInfo = deviceCacheInfos.FirstOrDefault(x => x.DeviceAddress == messageBody.DeviceAddress);
|
||||
|
||||
if (deviceCacheInfo == null)
|
||||
{
|
||||
_logger.LogError($"{nameof(BatchQueryDeviceDataInfoAsync)} 业务系统单个查询设备数据,设备地址:{messageBody.DeviceAddress}未找到设备地址缓存信息,消息体为:{input.Serialize()}");
|
||||
}
|
||||
|
||||
var pageResult = await treeModelService.OpenRequestDeviceDataInfoPageAsync(new DeviceTreeModelDataInfoInput()
|
||||
{
|
||||
DeviceAddress = messageBody.DeviceAddress,
|
||||
DeviceType = messageBody.DeviceType,
|
||||
IoTDataType = messageBody.IoTDataType,
|
||||
IsNeedPaging = false,
|
||||
StartCreationTime = messageBody.BeginTime,
|
||||
EndCreationTime = messageBody.EndTime,
|
||||
SubDeviceAddress = messageBody.SubDeviceAddress,
|
||||
});
|
||||
|
||||
//todo 根据业务系统时间间隔要求进行过滤
|
||||
if (pageResult.Items != null && pageResult.Items.Count > 0)
|
||||
{
|
||||
queryResult.AddRange(pageResult.Items);
|
||||
}
|
||||
|
||||
return HttpDataResultExtensions.Success(queryResult, "查询成功");
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, $"查询设备数据失败,发送异常:{ex.Message}", -106);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量新增设备数据,Msg 字段为 BatchCreateDeviceInfoInput 实体
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user