@@ -1,3 +1,3 @@ | |||
{ | |||
"APIurl": "http://124.222.238.75:6002" | |||
"APIurl": "http://111.9.47.105:21527/datav" | |||
} |
@@ -1,4 +1,5 @@ | |||
using DataVAPI.ProcessServices.AppConfig; | |||
using DataVAPI.Model; | |||
using DataVAPI.ProcessServices.AppConfig; | |||
using DataVAPI.Tool; | |||
using DataVAPI.Tool.API请求; | |||
using DataVAPI.Tool.IOT; | |||
@@ -58,14 +59,12 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One | |||
public void Initialize() | |||
{ | |||
APIurl = AppConfigurtaionServices.Configuration.GetSection("APIurl").Value; | |||
//DataVstatus = new Dictionary<string,ReceiveModel>(); | |||
devModel = new ScreenMonitorModel(); | |||
devModel.operatingDeviceStatus = new OperatingDeviceStatus(); devModel.operatingDeviceStatus.data = new List<DevStatus>();//现场设备于状态 | |||
devModel.infoMessage = new InfoMessage(); devModel.infoMessage.data = new List<DeviceBase>();//通知消息 | |||
devModel.TotalSales = "0"; | |||
//加载店铺信息 | |||
LoadingShopInformation(); | |||
LoadingSqlite(); | |||
//MQTT 数据接收处理 | |||
ConsoleHelper.WriteInfoLine("尝试连接阿里云."); | |||
IOTDevServer.GetInstance().SetUrl(APIurl); | |||
@@ -99,22 +98,6 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One | |||
ConsoleHelper.WriteSuccessLine("订阅主题: " + subscribe); | |||
} | |||
/// <summary> | |||
/// 记载本地数据 | |||
/// </summary> | |||
public void LoadingSqlite() | |||
{ | |||
//ConsoleHelper.WriteSuccessLine("加载缓存集合..."); | |||
//SqlContext<DataVModel>.Base.Database.EnsureCreated(); | |||
//SqlContext<DataVModel>.Base.GetLists()?.ForEach(par => | |||
//{ | |||
// DataVstatus[par.Id] = BPA.Message.IOT.Tools.JsonToObjectTools<ReceiveModel>(par.json); | |||
// UpdateData(DataVstatus[par.Id],false); | |||
//}); | |||
//ConsoleHelper.WriteSuccessLine($"加载完成,总共设备数.{DataVstatus.Count}台..."); | |||
} | |||
/// <summary> | |||
/// 加载店铺信息 | |||
/// </summary> | |||
@@ -128,7 +111,7 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One | |||
if (string.IsNullOrEmpty(clientId)) url = $"{APIurl}/api/Device/Query"; | |||
string json = HttpRequestHelper.HttpGetRequest(url); | |||
JsonMsg<List<DeviceTable>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<DeviceTable>>>(json); | |||
jsonMsg?.obj?.ForEach(par => | |||
jsonMsg?.obj?.data?.ForEach(par => | |||
{ | |||
if (par.ClientId != "0") | |||
@@ -151,7 +134,7 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One | |||
} | |||
} | |||
}); | |||
ConsoleHelper.WriteSuccessLine($"加载设备数[ {jsonMsg?.obj?.FindAll(o => o.ClientId != "0")?.Count()} ]台..."); | |||
ConsoleHelper.WriteSuccessLine($"加载设备数[ {jsonMsg?.obj?.data?.FindAll(o => o.ClientId != "0")?.Count()} ]台..."); | |||
} | |||
catch (Exception ex) | |||
{ | |||
@@ -193,7 +176,7 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One | |||
{ | |||
devicename = receiveModel.deviceContext.deviceName, | |||
ClientId = dev.clientId, | |||
LogTime = DateTime.Now, | |||
LogTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | |||
LogType = "1", | |||
LogMessage = $"设备{receiveModel.status.value}了!", | |||
LogVla = "上下线" | |||
@@ -55,8 +55,7 @@ namespace DataVAPI.ServerDB.MongoDB | |||
public T Insert(T entity) | |||
{ | |||
var flag = ObjectId.GenerateNewId(); | |||
entity.GetType().GetProperty("Id").SetValue(entity, flag); | |||
entity.Id = ObjectId.GenerateNewId().ToString(); | |||
entity.State = "y"; | |||
entity.CreateTime = DateTime.Now;//.ToString("yyyy-MM-dd HH:mm:ss"); | |||
entity.UpdateTime = DateTime.Now;//.ToString("yyyy-MM-dd HH:mm:ss"); | |||
@@ -87,7 +86,7 @@ namespace DataVAPI.ServerDB.MongoDB | |||
public void UpdateID(T entity) | |||
{ | |||
var old = collection.Find(e => e.IdStr.Equals(entity.IdStr))?.ToList().FirstOrDefault(); | |||
var old = collection.Find(e => e.Id.Equals(entity.Id))?.ToList().FirstOrDefault(); | |||
foreach (var prop in entity.GetType().GetProperties()) | |||
{ | |||
@@ -116,7 +115,7 @@ namespace DataVAPI.ServerDB.MongoDB | |||
old.State = "y"; | |||
old.UpdateTime = DateTime.Now;//.ToString("yyyy-MM-dd HH:mm:ss"); | |||
var filter = Builders<T>.Filter.Eq("IdStr", entity.IdStr); | |||
var filter = Builders<T>.Filter.Eq("IdStr", entity.Id); | |||
ReplaceOneResult result = collection.ReplaceOneAsync(filter, old).Result; | |||
} | |||
@@ -128,7 +127,7 @@ namespace DataVAPI.ServerDB.MongoDB | |||
public T QueryOne(string id) | |||
{ | |||
return collection.Find(a => a.IdStr == id)?.ToList().FirstOrDefault(); | |||
return collection.Find(a => a.Id == id)?.ToList().FirstOrDefault(); | |||
} | |||
public List<T> QueryAllTime(string clientId, string deviceId, DateTime datesta, DateTime datastop) | |||
@@ -223,23 +222,8 @@ namespace DataVAPI.ServerDB.MongoDB | |||
/// <summary> | |||
/// ID | |||
/// </summary> | |||
private ObjectId _ID; | |||
public ObjectId Id | |||
{ | |||
get | |||
{ | |||
return _ID; | |||
} | |||
set | |||
{ | |||
_ID = value; | |||
IdStr = _ID.ToString(); | |||
} | |||
} | |||
/// <summary> | |||
/// 唯一ID | |||
/// </summary> | |||
public string IdStr { get; set; } | |||
[BsonRepresentation(BsonType.ObjectId)] | |||
public string Id { get; set; } | |||
/// <summary> | |||
/// 客户端 ID | |||
/// </summary> | |||
@@ -24,180 +24,180 @@ namespace DataVAPI.Tool.API请求 | |||
public int totalCount { get; set; } | |||
} | |||
public class JsonMsg<T> where T : class | |||
{ | |||
/// <summary> | |||
/// 状态码 | |||
/// </summary> | |||
public int code { get; set; } | |||
/// <summary> | |||
/// 消息 | |||
/// </summary> | |||
public string msg { get; set; } | |||
/// <summary> | |||
/// 描述 | |||
/// </summary> | |||
public string ms { get; set; } | |||
/// <summary> | |||
/// 内容 | |||
/// </summary> | |||
public T obj { get; set; } | |||
/// <summary> | |||
/// 图标 | |||
/// </summary> | |||
public int icon { get; set; } | |||
public static JsonMsg<T> OK(T obj, string msg = "接口名称", string mso = "调用接口成功") | |||
{ | |||
string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用成功,描述:" + mso + obj}"; | |||
ConsoleColor currentForeColor = Console.ForegroundColor; | |||
Console.ForegroundColor = ConsoleColor.Green; | |||
Console.WriteLine(str); | |||
Console.ForegroundColor = currentForeColor; | |||
return new JsonMsg<T>() { code = 1, ms = mso, msg = "成功", obj = obj, icon = 1 }; | |||
} | |||
public static JsonMsg<T> Error(T obj, string msg = "接口名称", string mso = "调用接口成功失败") | |||
{ | |||
string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用失败,描述:" + mso + obj}"; | |||
ConsoleColor currentForeColor = Console.ForegroundColor; | |||
Console.ForegroundColor = ConsoleColor.Red; | |||
Console.WriteLine(str); | |||
Console.ForegroundColor = currentForeColor; | |||
return new JsonMsg<T>() { code = 0, ms = mso, msg = "失败", obj = obj, icon = 1 }; | |||
} | |||
} | |||
public class DeviceTable : BaseEntity | |||
{ | |||
/// <summary> | |||
/// 阿里云设备key | |||
/// </summary> | |||
public string productkey { get; set; } | |||
/// <summary> | |||
/// 阿里云设备secret | |||
/// </summary> | |||
public string devicesecret { get; set; } | |||
/// <summary> | |||
/// 客户端类型 | |||
/// </summary> | |||
public string devtype { get; set; } | |||
/// <summary> | |||
/// 经度 | |||
/// </summary> | |||
public string jd { get; set; } | |||
/// <summary> | |||
/// 维度 | |||
/// </summary> | |||
public string wd { get; set; } | |||
/// <summary> | |||
/// 备注 | |||
/// </summary> | |||
public string remark { get; set; } | |||
} | |||
/// <summary> | |||
/// 告警消息表 | |||
/// </summary> | |||
public class AlarmTable : BaseEntity | |||
{ | |||
/// <summary> | |||
/// 告警时间 | |||
/// </summary> | |||
public DateTime AlarmTime { get; set; } | |||
/// <summary> | |||
/// 告警类型:1 轻微 2:一般 3 严重 | |||
/// </summary> | |||
public string AlarmType { get; set; } | |||
/// <summary> | |||
/// 告警消息 | |||
/// </summary> | |||
public string AlarmMessage { get; set; } | |||
/// <summary> | |||
/// 告警值 | |||
/// </summary> | |||
public string AlarmVla { get; set; } | |||
/// <summary> | |||
/// IP 地址 | |||
/// </summary> | |||
public string IP { get; set; } | |||
public AlarmTable() | |||
{ | |||
IP = Tools.GetLocalIp(); | |||
} | |||
} | |||
/// <summary> | |||
/// 日志表 | |||
/// </summary> | |||
public class LogTable : BaseEntity | |||
{ | |||
/// <summary> | |||
/// 日志时间 | |||
/// </summary> | |||
public DateTime LogTime { get; set; } | |||
/// <summary> | |||
/// 日志类型:1 轻微 2:一般 3 严重 | |||
/// </summary> | |||
public string LogType { get; set; } | |||
/// <summary> | |||
/// 日志消息 | |||
/// </summary> | |||
public string LogMessage { get; set; } | |||
/// <summary> | |||
/// 日志值 | |||
/// </summary> | |||
public string LogVla { get; set; } | |||
/// <summary> | |||
/// IP 地址 | |||
/// </summary> | |||
public string IP { get; set; } | |||
public LogTable() | |||
{ | |||
IP = Tools.GetLocalIp(); | |||
} | |||
} | |||
/// <summary> | |||
/// MongoDB基类 | |||
/// </summary> | |||
public abstract class BaseEntity | |||
{ | |||
/// <summary> | |||
/// ID | |||
/// </summary> | |||
public string IdStr { get; set; } | |||
/// <summary> | |||
/// 客户端 ID | |||
/// </summary> | |||
public string ClientId { get; set; } | |||
/// <summary> | |||
/// 设备 ID | |||
/// </summary> | |||
public string DeviceId { get; set; } | |||
/// <summary> | |||
/// 状态 | |||
/// </summary> | |||
public string State { get; set; } | |||
/// <summary> | |||
/// 创建时间 | |||
/// </summary> | |||
public DateTime CreateTime { get; set; } | |||
/// <summary> | |||
/// 修改时间 | |||
/// </summary> | |||
public DateTime UpdateTime { get; set; } | |||
/// <summary> | |||
/// 阿里云设备名称 | |||
/// </summary> | |||
public string devicename { get; set; } | |||
} | |||
//public class JsonMsg<T> where T : class | |||
//{ | |||
// /// <summary> | |||
// /// 状态码 | |||
// /// </summary> | |||
// public int code { get; set; } | |||
// /// <summary> | |||
// /// 消息 | |||
// /// </summary> | |||
// public string msg { get; set; } | |||
// /// <summary> | |||
// /// 描述 | |||
// /// </summary> | |||
// public string ms { get; set; } | |||
// /// <summary> | |||
// /// 内容 | |||
// /// </summary> | |||
// public T obj { get; set; } | |||
// /// <summary> | |||
// /// 图标 | |||
// /// </summary> | |||
// public int icon { get; set; } | |||
// public static JsonMsg<T> OK(T obj, string msg = "接口名称", string mso = "调用接口成功") | |||
// { | |||
// string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用成功,描述:" + mso + obj}"; | |||
// ConsoleColor currentForeColor = Console.ForegroundColor; | |||
// Console.ForegroundColor = ConsoleColor.Green; | |||
// Console.WriteLine(str); | |||
// Console.ForegroundColor = currentForeColor; | |||
// return new JsonMsg<T>() { code = 1, ms = mso, msg = "成功", obj = obj, icon = 1 }; | |||
// } | |||
// public static JsonMsg<T> Error(T obj, string msg = "接口名称", string mso = "调用接口成功失败") | |||
// { | |||
// string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用失败,描述:" + mso + obj}"; | |||
// ConsoleColor currentForeColor = Console.ForegroundColor; | |||
// Console.ForegroundColor = ConsoleColor.Red; | |||
// Console.WriteLine(str); | |||
// Console.ForegroundColor = currentForeColor; | |||
// return new JsonMsg<T>() { code = 0, ms = mso, msg = "失败", obj = obj, icon = 1 }; | |||
// } | |||
//} | |||
//public class DeviceTable : BaseEntity | |||
//{ | |||
// /// <summary> | |||
// /// 阿里云设备key | |||
// /// </summary> | |||
// public string productkey { get; set; } | |||
// /// <summary> | |||
// /// 阿里云设备secret | |||
// /// </summary> | |||
// public string devicesecret { get; set; } | |||
// /// <summary> | |||
// /// 客户端类型 | |||
// /// </summary> | |||
// public string devtype { get; set; } | |||
// /// <summary> | |||
// /// 经度 | |||
// /// </summary> | |||
// public string jd { get; set; } | |||
// /// <summary> | |||
// /// 维度 | |||
// /// </summary> | |||
// public string wd { get; set; } | |||
// /// <summary> | |||
// /// 备注 | |||
// /// </summary> | |||
// public string remark { get; set; } | |||
//} | |||
///// <summary> | |||
///// 告警消息表 | |||
///// </summary> | |||
//public class AlarmTable : BaseEntity | |||
//{ | |||
// /// <summary> | |||
// /// 告警时间 | |||
// /// </summary> | |||
// public DateTime AlarmTime { get; set; } | |||
// /// <summary> | |||
// /// 告警类型:1 轻微 2:一般 3 严重 | |||
// /// </summary> | |||
// public string AlarmType { get; set; } | |||
// /// <summary> | |||
// /// 告警消息 | |||
// /// </summary> | |||
// public string AlarmMessage { get; set; } | |||
// /// <summary> | |||
// /// 告警值 | |||
// /// </summary> | |||
// public string AlarmVla { get; set; } | |||
// /// <summary> | |||
// /// IP 地址 | |||
// /// </summary> | |||
// public string IP { get; set; } | |||
// public AlarmTable() | |||
// { | |||
// IP = Tools.GetLocalIp(); | |||
// } | |||
//} | |||
///// <summary> | |||
///// 日志表 | |||
///// </summary> | |||
//public class LogTable : BaseEntity | |||
//{ | |||
// /// <summary> | |||
// /// 日志时间 | |||
// /// </summary> | |||
// public DateTime LogTime { get; set; } | |||
// /// <summary> | |||
// /// 日志类型:1 轻微 2:一般 3 严重 | |||
// /// </summary> | |||
// public string LogType { get; set; } | |||
// /// <summary> | |||
// /// 日志消息 | |||
// /// </summary> | |||
// public string LogMessage { get; set; } | |||
// /// <summary> | |||
// /// 日志值 | |||
// /// </summary> | |||
// public string LogVla { get; set; } | |||
// /// <summary> | |||
// /// IP 地址 | |||
// /// </summary> | |||
// public string IP { get; set; } | |||
// public LogTable() | |||
// { | |||
// IP = Tools.GetLocalIp(); | |||
// } | |||
//} | |||
///// <summary> | |||
///// MongoDB基类 | |||
///// </summary> | |||
//public abstract class BaseEntity | |||
//{ | |||
// /// <summary> | |||
// /// ID | |||
// /// </summary> | |||
// public string IdStr { get; set; } | |||
// /// <summary> | |||
// /// 客户端 ID | |||
// /// </summary> | |||
// public string ClientId { get; set; } | |||
// /// <summary> | |||
// /// 设备 ID | |||
// /// </summary> | |||
// public string DeviceId { get; set; } | |||
// /// <summary> | |||
// /// 状态 | |||
// /// </summary> | |||
// public string State { get; set; } | |||
// /// <summary> | |||
// /// 创建时间 | |||
// /// </summary> | |||
// public DateTime CreateTime { get; set; } | |||
// /// <summary> | |||
// /// 修改时间 | |||
// /// </summary> | |||
// public DateTime UpdateTime { get; set; } | |||
// /// <summary> | |||
// /// 阿里云设备名称 | |||
// /// </summary> | |||
// public string devicename { get; set; } | |||
//} | |||
} |
@@ -9,4 +9,8 @@ | |||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\DataVAPI.Model\DataVAPI.Model.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,5 @@ | |||
| |||
using DataVAPI.Model; | |||
using DataVAPI.Tool.API请求; | |||
using Newtonsoft.Json; | |||
using System; | |||
@@ -153,9 +154,9 @@ namespace DataVAPI.Tool.IOT | |||
//http://localhost:9092/api/Device/Query?chid=2 | |||
string json = HttpRequestHelper.HttpGetRequest($"{APIurl}/api/Device/Query?clientId={ClientId}"); | |||
JsonMsg<List<DeviceTable>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<DeviceTable>>>(json); | |||
if (jsonMsg.obj != null) | |||
if (jsonMsg.obj != null && jsonMsg.obj.data!=null) | |||
{ | |||
device = jsonMsg.obj.FirstOrDefault(); | |||
device = jsonMsg.obj.data.FirstOrDefault(); | |||
if (device == null) return false; | |||
Set(device.productkey, device.devicename, device.devicesecret); | |||
@@ -32,7 +32,6 @@ namespace DataVAPI.Controllers | |||
if (largeScreen != null) | |||
{ | |||
largeScreenTable.IdStr = largeScreen.IdStr; | |||
largeScreenTable.Id = largeScreen.Id; | |||
mg.UpdateID(largeScreenTable); | |||
} | |||
@@ -18,6 +18,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\DataVAPI.Model\DataVAPI.Model.csproj" /> | |||
<ProjectReference Include="..\DataVAPI.Tools\DataVAPI.Tool.csproj" /> | |||
</ItemGroup> | |||
@@ -1,4 +1,5 @@ | |||
using AduSkin.Controls.Metro; | |||
using DataVAPI.Model; | |||
using DataVAPI.Tool.API请求; | |||
using DataVAPI.Tool.IOT; | |||
using DataVIOT.Help.Model; | |||
@@ -41,7 +42,7 @@ namespace IOT.Help | |||
else MessageBox.Show("增加失败"); | |||
break; | |||
case "Update": | |||
if (string.IsNullOrEmpty(MainViewModel.Instance.device.IdStr)) { | |||
if (string.IsNullOrEmpty(MainViewModel.Instance.device.Id)) { | |||
MessageBox.Show("请先“查询”或者“双击右侧表格行”,修改之后在点击“修改”"); | |||
return; | |||
} | |||
@@ -51,7 +52,7 @@ namespace IOT.Help | |||
break; | |||
case "Delete": | |||
if (string.IsNullOrEmpty(MainViewModel.Instance.device.IdStr)) | |||
if (string.IsNullOrEmpty(MainViewModel.Instance.device.Id)) | |||
{ | |||
MessageBox.Show("请先“查询”或者“双击右侧表格行”,修改之后在点击“删除”"); | |||
return; | |||
@@ -1,4 +1,5 @@ | |||
using DataVAPI.Tool.API请求; | |||
using DataVAPI.Model; | |||
using DataVAPI.Tool.API请求; | |||
using DataVAPI.Tool.IOT; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using System; | |||
@@ -100,7 +101,7 @@ namespace DataVIOT.Help.ViewModel | |||
if (!string.IsNullOrEmpty(clientId)) url = ApiURL + "/api/Device/Query?clientId=" + clientId; | |||
string json = HttpRequestHelper.HttpGetRequest(url); | |||
JsonMsg<List<DeviceTable>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<DeviceTable>>>(json); | |||
return jsonMsg.obj; | |||
return jsonMsg.obj.data; | |||
} | |||
catch (Exception ex) | |||
{ | |||
@@ -173,7 +174,7 @@ namespace DataVIOT.Help.ViewModel | |||
{ | |||
try | |||
{ | |||
string url = ApiURL + "/api/Device/DeleteDate?id=" + device.IdStr; | |||
string url = ApiURL + "/api/Device/DeleteDate?id=" + device.Id; | |||
string json = HttpRequestHelper.HttpGetRequest(url); | |||
Refresh(); | |||
return true; | |||