Browse Source

提交:1.增加根据设备名称查询日志文件 2.增加接口耍界面店铺

master
fyf 2 years ago
parent
commit
294c999591
6 changed files with 176 additions and 8 deletions
  1. +13
    -0
      DataVAPI.Tools/IOT/IOTDevServer.cs
  2. +18
    -0
      DataVAPI/Controllers/DeviceController.cs
  3. +28
    -0
      DataVAPI/Controllers/LogController.cs
  4. +5
    -0
      DataVAPI/DataVAPI.csproj
  5. +7
    -8
      DataVAPI/UpAndDown/ProcessServer.cs
  6. +105
    -0
      DataVAPI/UpAndDown/Sample.cs

+ 13
- 0
DataVAPI.Tools/IOT/IOTDevServer.cs View File

@@ -276,6 +276,17 @@ namespace DataVAPI.Tool.IOT
}
client.Subscribe(new string[] { topic }, new byte[] { 0 });
}

public void SetSub(List<string> str)
{
str?.ForEach(par =>
{
if (SubTopicList.Contains(par))
{
SubTopicList.Add(par);
}
});
}
#endregion

#region 私有函数
@@ -358,6 +369,8 @@ namespace DataVAPI.Tool.IOT
SubTopicList.ForEach(par =>
{
client.Subscribe(new string[] { par }, new byte[] { 0 });
UNConnectMqtt?.Invoke($"订阅主题{par}!");

});
UNConnectMqtt?.Invoke("重新连接阿里云MQTT成功!");
}


+ 18
- 0
DataVAPI/Controllers/DeviceController.cs View File

@@ -1,6 +1,7 @@
using DataVAPI.Model;
using DataVAPI.ModelDataBus;
using DataVAPI.ServerDB.MongoDB;
using DataVAPI.UpAndDown;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
@@ -198,5 +199,22 @@ namespace DataVAPI.Controllers
return JsonMsg<string>.Error(null, st, ex.Message);
}
}
/// <summary>
/// 刷新设备
/// </summary>
[HttpGet]
public JsonMsg<string> FlushedDevice()
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
ProcessServer.Instance.LoadingShopInformation();
return JsonMsg<string>.OK("success!", st);
}
catch (Exception ex)
{
return JsonMsg<string>.Error(null, st, ex.Message);
}
}
}
}

+ 28
- 0
DataVAPI/Controllers/LogController.cs View File

@@ -2,6 +2,7 @@
using DataVAPI.ModelDataBus;
using DataVAPI.ServerDB.MongoDB;
using DataVAPI.Tool.IOT;
using DataVAPI.UpAndDown;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
@@ -256,5 +257,32 @@ namespace DataVAPI.Controllers
return JsonMsg<string>.Error(null, st, ex.Message);
}
}

/// <summary>
/// 查询设备所有文件
/// </summary>
/// <param name="DeviceName"></param>
/// <returns></returns>
[HttpGet]
public JsonMsg<object> QueryLogFile(string DeviceName)
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
if (string.IsNullOrEmpty(DeviceName))
{
return JsonMsg<object>.Error(null, st, "设备名称不能为空");
}
else
{
return JsonMsg<object>.OK(Sample.FileQueryALL(DeviceName), st);
}
}
catch (Exception ex)
{
return JsonMsg<object>.Error(null, st, ex.Message);
}
}

}
}

+ 5
- 0
DataVAPI/DataVAPI.csproj View File

@@ -13,12 +13,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AlibabaCloud.OpenApiClient" Version="0.1.3" />
<PackageReference Include="AlibabaCloud.SDK.Iot20180120" Version="3.0.5" />
<PackageReference Include="AlibabaCloud.TeaConsole" Version="0.1.0" />
<PackageReference Include="AlibabaCloud.TeaUtil" Version="0.1.13" />
<PackageReference Include="BPA.ApolloClient" Version="1.0.9" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
<PackageReference Include="Tea" Version="1.0.11" />
</ItemGroup>

<ItemGroup>


+ 7
- 8
DataVAPI/UpAndDown/ProcessServer.cs View File

@@ -61,14 +61,14 @@ namespace DataVAPI.UpAndDown
LoadingShopInformation();
//MQTT 数据接收处理
ConsoleHelper.WriteInfoLine("尝试连接阿里云.");
//设置变量
IOTDevServer.GetInstance().Set(DataBus.ProductKey, DataBus.DeviceName, DataBus.DeviceSecret);
IOTDevServer.GetInstance().SetSub(new List<string> { IOTDevServer.HeartbeatSubTopic, IOTDevServer.BroadcastTopic });

if (IOTDevServer.GetInstance().CreateLinks(DataBus.ProductKey, DataBus.DeviceName, DataBus.DeviceSecret))
{
//属性状态变xin
//Subscribe(IOTDevServer.TargetStatusSubTopic);

//订阅上下线
Subscribe(IOTDevServer.HeartbeatSubTopic);

//订阅主播消息
Subscribe(IOTDevServer.BroadcastTopic);
ConsoleHelper.WriteSuccessLine($"阿里云【Transit】连接成功");
@@ -104,18 +104,17 @@ namespace DataVAPI.UpAndDown

if (IOTDevServer.GetInstance().CreateLinks(DataBus.ProductKey, DataBus.DeviceName, DataBus.DeviceSecret))
{
ConsoleHelper.WriteSuccessLine($"阿里云【Transit】连接成功");
ConsoleHelper.WriteSuccessLine($"阿里云【Transit】重新连接成功");
//订阅上下线
Subscribe(IOTDevServer.HeartbeatSubTopic);

//订阅主播消息
Subscribe(IOTDevServer.BroadcastTopic);
}
else
{
ConsoleHelper.WriteSuccessLine($"阿里云【Transit】连接失败");
ConsoleHelper.WriteSuccessLine($"阿里云【Transit】重新连接失败");
}
Thread.Sleep(10000);
Thread.Sleep(360000);
}

}


+ 105
- 0
DataVAPI/UpAndDown/Sample.cs View File

@@ -0,0 +1,105 @@
using DataVAPI.ModelDataBus;
using DataVAPI.Tool.IOT;
using System.Collections.Generic;
using Tea;
using static AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileResponseBody;

namespace DataVAPI.UpAndDown
{
public class Sample
{

/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.SDK.Iot20180120.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 您的AccessKey ID
AccessKeyId = accessKeyId,
// 您的AccessKey Secret
AccessKeySecret = accessKeySecret,
};
// 访问的域名
config.Endpoint = "iot.cn-shanghai.aliyuncs.com";
return new AlibabaCloud.SDK.Iot20180120.Client(config);
}

public static List<QueryDeviceFileResponseBodyData> FileQueryALL(string DeviceName)
{
List<QueryDeviceFileResponseBodyData> retdata=new List<QueryDeviceFileResponseBodyData>();
AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi");
AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListRequest queryDeviceFileListRequest = new AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListRequest
{
IotInstanceId = "iot-06z00g9pf3kwtxp",
ProductKey = DataBus.ProductKey,
DeviceName = DeviceName,
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListResponse resp = client.QueryDeviceFileListWithOptions(queryDeviceFileListRequest, runtime);
//AlibabaCloud.TeaConsole.Client.Log();
//;
AlibabaCloudRes cloudRes= Tools.JsonToObjectTools<AlibabaCloudRes>(AlibabaCloud.TeaUtil.Common.ToJSONString(resp.ToMap()));
cloudRes?.body?.Data?.FileSummary?.ForEach(fileSummary =>
{
QueryDeviceFileResponseBodyData _data= FileQuery(DeviceName,fileSummary.FileId);
if (_data != null)
{
retdata.Add(_data);
}
});
return retdata;
}

public static QueryDeviceFileResponseBodyData FileQuery(string DeviceName,string FileId)
{
AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi");
AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileRequest queryDeviceFileRequest = new AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileRequest
{
IotInstanceId = "iot-06z00g9pf3kwtxp",
DeviceName = DeviceName,
ProductKey = DataBus.ProductKey,
FileId = FileId,
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
// 复制代码运行请自行打印 API 的返回值
QueryDeviceFileResponseBodyData queryDeviceFile= client.QueryDeviceFileWithOptions(queryDeviceFileRequest, runtime).Body.Data;
return queryDeviceFile;
}

}

public class AlibabaCloudRes
{
public object headers { get; set; }
public StrRes body { get; set; }
}
public class StrRes
{
public string code { get; set; }
public string CurrentPage { get; set; }
public ResData Data { get; set; }
public string ErrorMessage { get; set; }
public int PageCount { get; set; }
public int PageSize { get; set; }
public string RequestId { get; set; }
public bool Success { get; set; }
public int Total { get; set; }
}
public class ResData
{
public List<summary> FileSummary { get; set; }
}
public class summary
{
public string UtcCreatedOn { get; set; }
public string Size { get; set; }
public string FileId { get; set; }
public string Name { get; set; }
}
}

Loading…
Cancel
Save