diff --git a/DataVAPI.ProcessServices/appsettings.json b/DataVAPI.ProcessServices/appsettings.json index f2dd67f..bbf9fc2 100644 --- a/DataVAPI.ProcessServices/appsettings.json +++ b/DataVAPI.ProcessServices/appsettings.json @@ -1,3 +1,3 @@ { - "APIurl": "http://124.222.238.75:6002" + "APIurl": "http://111.9.47.105:21527/datav" } diff --git a/DataVAPI.ProcessServices/阿里云处理流程One/ALY_ProcessServer.cs b/DataVAPI.ProcessServices/阿里云处理流程One/ALY_ProcessServer.cs index f7c33ca..c182390 100644 --- a/DataVAPI.ProcessServices/阿里云处理流程One/ALY_ProcessServer.cs +++ b/DataVAPI.ProcessServices/阿里云处理流程One/ALY_ProcessServer.cs @@ -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(); devModel = new ScreenMonitorModel(); devModel.operatingDeviceStatus = new OperatingDeviceStatus(); devModel.operatingDeviceStatus.data = new List();//现场设备于状态 devModel.infoMessage = new InfoMessage(); devModel.infoMessage.data = new List();//通知消息 devModel.TotalSales = "0"; //加载店铺信息 LoadingShopInformation(); - LoadingSqlite(); //MQTT 数据接收处理 ConsoleHelper.WriteInfoLine("尝试连接阿里云."); IOTDevServer.GetInstance().SetUrl(APIurl); @@ -99,22 +98,6 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One ConsoleHelper.WriteSuccessLine("订阅主题: " + subscribe); } - - /// - /// 记载本地数据 - /// - public void LoadingSqlite() - { - //ConsoleHelper.WriteSuccessLine("加载缓存集合..."); - //SqlContext.Base.Database.EnsureCreated(); - //SqlContext.Base.GetLists()?.ForEach(par => - //{ - // DataVstatus[par.Id] = BPA.Message.IOT.Tools.JsonToObjectTools(par.json); - // UpdateData(DataVstatus[par.Id],false); - //}); - //ConsoleHelper.WriteSuccessLine($"加载完成,总共设备数.{DataVstatus.Count}台..."); - } - /// /// 加载店铺信息 /// @@ -128,7 +111,7 @@ namespace DataVAPI.ProcessServices.阿里云处理流程One if (string.IsNullOrEmpty(clientId)) url = $"{APIurl}/api/Device/Query"; string json = HttpRequestHelper.HttpGetRequest(url); JsonMsg> jsonMsg = Tools.JsonToObjectTools>>(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 = "上下线" diff --git a/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs b/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs index 1436f6b..20f4e55 100644 --- a/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs +++ b/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs @@ -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.Filter.Eq("IdStr", entity.IdStr); + var filter = Builders.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 QueryAllTime(string clientId, string deviceId, DateTime datesta, DateTime datastop) @@ -223,23 +222,8 @@ namespace DataVAPI.ServerDB.MongoDB /// /// ID /// - private ObjectId _ID; - public ObjectId Id - { - get - { - return _ID; - } - set - { - _ID = value; - IdStr = _ID.ToString(); - } - } - /// - /// 唯一ID - /// - public string IdStr { get; set; } + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } /// /// 客户端 ID /// diff --git a/DataVAPI.Tools/API请求/HttpResponseStatusBase.cs b/DataVAPI.Tools/API请求/HttpResponseStatusBase.cs index f5944fc..1db2694 100644 --- a/DataVAPI.Tools/API请求/HttpResponseStatusBase.cs +++ b/DataVAPI.Tools/API请求/HttpResponseStatusBase.cs @@ -24,180 +24,180 @@ namespace DataVAPI.Tool.API请求 public int totalCount { get; set; } } - public class JsonMsg where T : class - { - /// - /// 状态码 - /// - public int code { get; set; } - - /// - /// 消息 - /// - public string msg { get; set; } - - /// - /// 描述 - /// - public string ms { get; set; } - - /// - /// 内容 - /// - public T obj { get; set; } - - /// - /// 图标 - /// - public int icon { get; set; } - - - public static JsonMsg 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() { code = 1, ms = mso, msg = "成功", obj = obj, icon = 1 }; - } - - public static JsonMsg 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() { code = 0, ms = mso, msg = "失败", obj = obj, icon = 1 }; - } - } - - public class DeviceTable : BaseEntity - { - /// - /// 阿里云设备key - /// - public string productkey { get; set; } - /// - /// 阿里云设备secret - /// - public string devicesecret { get; set; } - /// - /// 客户端类型 - /// - public string devtype { get; set; } - /// - /// 经度 - /// - public string jd { get; set; } - /// - /// 维度 - /// - public string wd { get; set; } - /// - /// 备注 - /// - public string remark { get; set; } - - } - - /// - /// 告警消息表 - /// - public class AlarmTable : BaseEntity - { - /// - /// 告警时间 - /// - public DateTime AlarmTime { get; set; } - /// - /// 告警类型:1 轻微 2:一般 3 严重 - /// - public string AlarmType { get; set; } - /// - /// 告警消息 - /// - public string AlarmMessage { get; set; } - /// - /// 告警值 - /// - public string AlarmVla { get; set; } - /// - /// IP 地址 - /// - public string IP { get; set; } - - public AlarmTable() - { - IP = Tools.GetLocalIp(); - } - } - - /// - /// 日志表 - /// - public class LogTable : BaseEntity - { - /// - /// 日志时间 - /// - public DateTime LogTime { get; set; } - /// - /// 日志类型:1 轻微 2:一般 3 严重 - /// - public string LogType { get; set; } - /// - /// 日志消息 - /// - public string LogMessage { get; set; } - /// - /// 日志值 - /// - public string LogVla { get; set; } - /// - /// IP 地址 - /// - public string IP { get; set; } - - public LogTable() - { - IP = Tools.GetLocalIp(); - } - } - - /// - /// MongoDB基类 - /// - public abstract class BaseEntity - { - /// - /// ID - /// - public string IdStr { get; set; } - /// - /// 客户端 ID - /// - public string ClientId { get; set; } - /// - /// 设备 ID - /// - public string DeviceId { get; set; } - /// - /// 状态 - /// - public string State { get; set; } - /// - /// 创建时间 - /// - public DateTime CreateTime { get; set; } - /// - /// 修改时间 - /// - public DateTime UpdateTime { get; set; } - /// - /// 阿里云设备名称 - /// - public string devicename { get; set; } - } + //public class JsonMsg where T : class + //{ + // /// + // /// 状态码 + // /// + // public int code { get; set; } + + // /// + // /// 消息 + // /// + // public string msg { get; set; } + + // /// + // /// 描述 + // /// + // public string ms { get; set; } + + // /// + // /// 内容 + // /// + // public T obj { get; set; } + + // /// + // /// 图标 + // /// + // public int icon { get; set; } + + + // public static JsonMsg 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() { code = 1, ms = mso, msg = "成功", obj = obj, icon = 1 }; + // } + + // public static JsonMsg 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() { code = 0, ms = mso, msg = "失败", obj = obj, icon = 1 }; + // } + //} + + //public class DeviceTable : BaseEntity + //{ + // /// + // /// 阿里云设备key + // /// + // public string productkey { get; set; } + // /// + // /// 阿里云设备secret + // /// + // public string devicesecret { get; set; } + // /// + // /// 客户端类型 + // /// + // public string devtype { get; set; } + // /// + // /// 经度 + // /// + // public string jd { get; set; } + // /// + // /// 维度 + // /// + // public string wd { get; set; } + // /// + // /// 备注 + // /// + // public string remark { get; set; } + + //} + + ///// + ///// 告警消息表 + ///// + //public class AlarmTable : BaseEntity + //{ + // /// + // /// 告警时间 + // /// + // public DateTime AlarmTime { get; set; } + // /// + // /// 告警类型:1 轻微 2:一般 3 严重 + // /// + // public string AlarmType { get; set; } + // /// + // /// 告警消息 + // /// + // public string AlarmMessage { get; set; } + // /// + // /// 告警值 + // /// + // public string AlarmVla { get; set; } + // /// + // /// IP 地址 + // /// + // public string IP { get; set; } + + // public AlarmTable() + // { + // IP = Tools.GetLocalIp(); + // } + //} + + ///// + ///// 日志表 + ///// + //public class LogTable : BaseEntity + //{ + // /// + // /// 日志时间 + // /// + // public DateTime LogTime { get; set; } + // /// + // /// 日志类型:1 轻微 2:一般 3 严重 + // /// + // public string LogType { get; set; } + // /// + // /// 日志消息 + // /// + // public string LogMessage { get; set; } + // /// + // /// 日志值 + // /// + // public string LogVla { get; set; } + // /// + // /// IP 地址 + // /// + // public string IP { get; set; } + + // public LogTable() + // { + // IP = Tools.GetLocalIp(); + // } + //} + + ///// + ///// MongoDB基类 + ///// + //public abstract class BaseEntity + //{ + // /// + // /// ID + // /// + // public string IdStr { get; set; } + // /// + // /// 客户端 ID + // /// + // public string ClientId { get; set; } + // /// + // /// 设备 ID + // /// + // public string DeviceId { get; set; } + // /// + // /// 状态 + // /// + // public string State { get; set; } + // /// + // /// 创建时间 + // /// + // public DateTime CreateTime { get; set; } + // /// + // /// 修改时间 + // /// + // public DateTime UpdateTime { get; set; } + // /// + // /// 阿里云设备名称 + // /// + // public string devicename { get; set; } + //} } diff --git a/DataVAPI.Tools/DataVAPI.Tool.csproj b/DataVAPI.Tools/DataVAPI.Tool.csproj index 70bfbd3..6164ce4 100644 --- a/DataVAPI.Tools/DataVAPI.Tool.csproj +++ b/DataVAPI.Tools/DataVAPI.Tool.csproj @@ -9,4 +9,8 @@ + + + + diff --git a/DataVAPI.Tools/IOT/IOTDevServer.cs b/DataVAPI.Tools/IOT/IOTDevServer.cs index 9018c7f..17b85e0 100644 --- a/DataVAPI.Tools/IOT/IOTDevServer.cs +++ b/DataVAPI.Tools/IOT/IOTDevServer.cs @@ -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> jsonMsg = Tools.JsonToObjectTools>>(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); diff --git a/DataVAPI/Controllers/ScreenController.cs b/DataVAPI/Controllers/ScreenController.cs index beaa9b8..86e9cb1 100644 --- a/DataVAPI/Controllers/ScreenController.cs +++ b/DataVAPI/Controllers/ScreenController.cs @@ -32,7 +32,6 @@ namespace DataVAPI.Controllers if (largeScreen != null) { - largeScreenTable.IdStr = largeScreen.IdStr; largeScreenTable.Id = largeScreen.Id; mg.UpdateID(largeScreenTable); } diff --git a/IOT.Help/DataVIOT.Help.csproj b/IOT.Help/DataVIOT.Help.csproj index 4cb88ea..f25dd62 100644 --- a/IOT.Help/DataVIOT.Help.csproj +++ b/IOT.Help/DataVIOT.Help.csproj @@ -18,6 +18,7 @@ + diff --git a/IOT.Help/MainWindow.xaml.cs b/IOT.Help/MainWindow.xaml.cs index eab4514..6830868 100644 --- a/IOT.Help/MainWindow.xaml.cs +++ b/IOT.Help/MainWindow.xaml.cs @@ -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; diff --git a/IOT.Help/ViewModel/MainViewModel.cs b/IOT.Help/ViewModel/MainViewModel.cs index 78c6c01..c7f0bba 100644 --- a/IOT.Help/ViewModel/MainViewModel.cs +++ b/IOT.Help/ViewModel/MainViewModel.cs @@ -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> jsonMsg = Tools.JsonToObjectTools>>(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;