浏览代码

更新上下线

master
fyf 2 年前
父节点
当前提交
fb0f80629f
共有 6 个文件被更改,包括 270 次插入7 次删除
  1. +32
    -2
      DataVAPI.ServerDB/MongoDB/MongodbHelper.cs
  2. +19
    -0
      DataVAPI/Controllers/DeviceController.cs
  3. +15
    -3
      DataVAPI/Controllers/DeviceStatsController.cs
  4. +164
    -2
      DataVAPI/Controllers/OrderController.cs
  5. +17
    -0
      DataVApi.Order/Dto/StoreListDto.cs
  6. +23
    -0
      DataVApi.Order/OrderProvider.cs

+ 32
- 2
DataVAPI.ServerDB/MongoDB/MongodbHelper.cs 查看文件

@@ -99,7 +99,7 @@ namespace DataVAPI.ServerDB.MongoDB
var oldValue = old.GetType().GetProperty(prop.Name).GetValue(old);
if (newValue != null)
{
if (!newValue.ToString().Equals(oldValue.ToString()))
if (oldValue==null || !newValue.ToString().Equals(oldValue.ToString()))
{
old.GetType().GetProperty(prop.Name).SetValue(old, newValue);
//if (Type == typeof(DateTime).Name)
@@ -130,6 +130,25 @@ namespace DataVAPI.ServerDB.MongoDB
return collection.Find(a => a.Id == id)?.ToList().FirstOrDefault();
}

public List<T> QueryAllNew(string clientId, string deviceId)
{
if (string.IsNullOrEmpty(clientId))
{
return collection.Find(par=>par.Id!=null)?.ToList().OrderByDescending(a => a.CreateTime).ToList();
}
else
{
if (string.IsNullOrEmpty(deviceId))
{
return collection.Find(a => a.ClientId == clientId)?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
}
else
{
return collection.Find(a => a.ClientId == clientId && a.DeviceId.Contains(deviceId))?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
}
}
}

public List<T> QueryAllTime(string clientId, string deviceId, DateTime datesta, DateTime datastop)
{
if (string.IsNullOrEmpty(clientId))
@@ -164,7 +183,7 @@ namespace DataVAPI.ServerDB.MongoDB
}
else
{
return collection.Find(a => a.ClientId == clientId && a.DeviceId == deviceId)?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
return collection.Find(a => a.ClientId == clientId && a.DeviceId.Contains(deviceId))?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
}
}
}
@@ -185,12 +204,23 @@ namespace DataVAPI.ServerDB.MongoDB
return collection.Find(a => a.ClientId == clientId && a.CreateTime >= DateTime.Now.Date)?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
}

public List<T> QueryClientIdName(string clientId,string name)
{
return collection.Find(a => a.ClientId == clientId && a.devicename==name)?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
}

public T QueryClientIdMax(string clientId)
{
List<T> clo = collection.Find(a => a.ClientId == clientId && a.CreateTime >= DateTime.Now.Date && a.State == "y")?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
return clo.Count>0?clo[0]:null;
}

public T QueryClientIdMaxName(string clientId,string name)
{
List<T> clo = collection.Find(a => a.ClientId == clientId && a.devicename==name && a.State == "y")?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();
return clo.Count > 0 ? clo[0] : null;
}

public List<T> QueryDeviceId(string clientId, string deviceId)
{
return collection.Find(a => a.DeviceId == deviceId && a.ClientId == clientId && a.CreateTime >= DateTime.Now.Date && a.State == "y")?.ToList().OrderByDescending(a => a.CreateTime)?.ToList();


+ 19
- 0
DataVAPI/Controllers/DeviceController.cs 查看文件

@@ -128,6 +128,25 @@ namespace DataVAPI.Controllers
}
}
/// <summary>
/// 根据客户端ID 设备id 模糊查询
/// </summary>
/// <param name="clientId"></param>
/// <param name="deviceId"></param>
/// <returns></returns>
[HttpGet]
public JsonMsg<List<DeviceTable>> QueryNew(string clientId, string deviceId)
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
return JsonMsg<List<DeviceTable>>.OK(mg.QueryAllNew(clientId, deviceId), st);
}
catch (Exception ex)
{
return JsonMsg<List<DeviceTable>>.Error(null, st, ex.Message);
}
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="clientId">客户端ID</param>


+ 15
- 3
DataVAPI/Controllers/DeviceStatsController.cs 查看文件

@@ -22,9 +22,10 @@ namespace DataVAPI.Controllers
/// 根据客户端ID查询最近上下线与告警时间
/// </summary>
/// <param name="clientId"></param>
/// <param name="name"></param>
/// <returns></returns>
[HttpGet]
public JsonMsg<object> StatsOnOff(string clientId)
public JsonMsg<object> StatsOnOff(string clientId,string name)
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
@@ -33,8 +34,19 @@ namespace DataVAPI.Controllers
string sx_time = "未知";
string xx_time = "未知";

AlarmTable alarmTable = mggj.QueryClientIdMax(clientId);
List<LogTable> log = mglog.QueryClientId(clientId);
AlarmTable alarmTable = new AlarmTable();
List<LogTable> log = new List<LogTable>();
if (!string.IsNullOrEmpty(name))
{
alarmTable = mggj.QueryClientIdMaxName(clientId,name);
log = mglog.QueryClientIdName(clientId, name);
}
else
{
alarmTable = mggj.QueryClientIdMax(clientId);
log = mglog.QueryClientId(clientId);
}

if (alarmTable != null) gj_time = alarmTable.AlarmTime;
LogTable logTable1 = log.Find(par => par.LogMessage.Contains("设备在线了"));
LogTable logTable2 = log.Find(par => par.LogMessage.Contains("设备离线了"));


+ 164
- 2
DataVAPI/Controllers/OrderController.cs 查看文件

@@ -1,7 +1,12 @@
using DataVApi.Order;
using DataVApi.Order.Dto;
using DataVApi.Order.RequestModel;
using DataVAPI.Model;
using DataVAPI.ModelDataBus;
using DataVAPI.ServerDB.MongoDB;
using Microsoft.AspNetCore.Mvc;
using NPOI.Util;
using System.Collections.Generic;

namespace DataVAPI.Controllers
{
@@ -12,6 +17,7 @@ namespace DataVAPI.Controllers
{
string st = System.Reflection.MethodBase.GetCurrentMethod().Name;
OrderProvider orderProvider = new OrderProvider();
MongoDbHelper<DeviceTable> mg = new MongoDbHelper<DeviceTable>(DataBus.connStr, DataBus.dbName);
/// <summary>
/// 全部数据
/// </summary>
@@ -35,7 +41,7 @@ namespace DataVAPI.Controllers
/// <param name="auth"></param>
/// <returns></returns>
[HttpGet]
public JsonMsg<object> GetAllOrderDataState(int? OrgId,int? DeviceId)
public JsonMsg<object> GetAllOrderDataState(int? OrgId, int? DeviceId)
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
@@ -79,7 +85,7 @@ namespace DataVAPI.Controllers
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
FullScreenBasic fullScreen=new FullScreenBasic();
FullScreenBasic fullScreen = new FullScreenBasic();
fullScreen.Count = Count;
object retdata = orderProvider.OrderLine(fullScreen);
return JsonMsg<object>.OK(retdata, st);
@@ -146,5 +152,161 @@ namespace DataVAPI.Controllers
return JsonMsg<object>.Error(null, st, ex.Message);
}
}

/// <summary>
/// 获取店铺集合
/// </summary>
/// <returns></returns>
[HttpGet]
public JsonMsg<object> StoreList()
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
object retdata = orderProvider.StoreList();
return JsonMsg<object>.OK(retdata, st);
}
catch (System.Exception ex)
{
return JsonMsg<object>.Error(null, st, ex.Message);
}
}

/// <summary>
/// 查询组织好的店铺信息
/// </summary>
/// <returns></returns>
[HttpGet]
public JsonMsg<object> StoreListIOT()
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
List<DeviceTable> _dev = mg.QueryAllTime(null, null, System.DateTime.MinValue, System.DateTime.MinValue);
Dictionary<int, List<StoreListDto>> retdata = orderProvider.StoreList();
List<object> list = new List<object>();
foreach (var item in retdata)
{
int i = 0;
string namesy = string.Empty;
string devid = string.Empty;
int ClientId = item.Key;
List<object> aly_data = new List<object>();
if (retdata.ContainsKey(ClientId))//查询店铺下面所有设备集合
{
List<DeviceTable> devices = _dev?.FindAll(par => par.ClientId == ClientId.ToString());
item.Value?.ForEach(p =>
{
#region 查询设备阿里云连接
DeviceTable dev = devices?.Find(x =>
{
List<string> retudata = new List<string>();
if (x.DeviceId != null)
{

string[] vs;
if (x.DeviceId.Contains(" ")) vs = x.DeviceId.Split(" ");
else if (x.DeviceId.Contains(",")) vs = x.DeviceId.Split(",");
else { vs = new string[1]; vs[0] = x.DeviceId; }
retudata = Arrays.AsList(vs);
}
if (retudata == null || retudata.Count <= 0 || !retudata.Contains(p.DeviceID.ToString()))
return false;
else
return true;
});
#endregion
if (i == 0) {
devid = p.DeviceID.ToString();
namesy = dev != null ? dev.devicename : "";
i++;
}
aly_data.Add( new
{
ClientId = p.ClientId,
ClientName = p.ClientName,
DeviceID = p.DeviceID,
DeviceName = p.DeviceName,
DeviceTypeKey = p.DeviceTypeKey,
AlyName = dev != null ? dev.devicename : "",
});
});
}
object _data = new
{
Name = item.Value?[0]?.ClientName,
ClientId = item.Value?[0]?.ClientId,
DeviceList= aly_data,
FirstName = namesy,
FirstDeviceID= devid
};
list.Add(_data);
}
return JsonMsg<object>.OK(list, st);
}
catch (System.Exception ex)
{
return JsonMsg<object>.Error(null, st, ex.Message);
}
}

/// <summary>
/// 根据客户端ID查询设备信息
/// </summary>
/// <returns></returns>
[HttpGet]
public JsonMsg<List<object>> StoreListClientId(int ClientId)
{
st = System.Reflection.MethodBase.GetCurrentMethod().Name;
try
{
List<DeviceTable> _dev = mg.QueryAllTime(null, null, System.DateTime.MinValue, System.DateTime.MinValue);
Dictionary<int, List<StoreListDto>> retdata = orderProvider.StoreList();

List<object> list = new List<object>();
if (retdata.ContainsKey(ClientId))
{
List<DeviceTable> devices= _dev?.FindAll(par => par.ClientId == ClientId.ToString());
List<StoreListDto> listdto = retdata[ClientId];
listdto?.ForEach(p =>
{
DeviceTable dev= devices?.Find(x =>
{
List<string> retudata = new List<string>();
if (x.DeviceId != null)
{
string[] vs;
if (x.DeviceId.Contains(" ")) vs = x.DeviceId.Split(" ");
else if (x.DeviceId.Contains(",")) vs = x.DeviceId.Split(",");
else { vs = new string[1];vs[0]= x.DeviceId ; }
retudata =Arrays.AsList(vs);
}
if (retudata == null || retudata.Count <= 0 || !retudata.Contains(p.DeviceID.ToString()))
return false;
else
return true;
});
object obj = new
{
ClientId= p.ClientId,
ClientName= p.ClientName,
DeviceID= p.DeviceID,
DeviceName= p.DeviceName,
DeviceTypeKey = p.DeviceTypeKey,
AlyName= dev!=null?dev.devicename: "",
};
list.Add(obj);
});
}
return JsonMsg<List<object>>.OK(list, st);
}
catch (System.Exception ex)
{
return JsonMsg<List<object>>.Error(null, st, ex.Message);
}
}
}
}

+ 17
- 0
DataVApi.Order/Dto/StoreListDto.cs 查看文件

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataVApi.Order.Dto
{
public class StoreListDto
{
public int ClientId { get; set; }
public string ClientName { get; set; }
public int DeviceID { get; set; }
public string DeviceName { get; set; }
public string DeviceTypeKey { get; set; }
}
}

+ 23
- 0
DataVApi.Order/OrderProvider.cs 查看文件

@@ -208,5 +208,28 @@ WHERE
B_Day = ((Day + L_Day) == 0) ? 0 : (((Day - L_Day) * 100) / (Day + L_Day))
};
}
/// <summary>
/// 获取店铺集合
/// </summary>
/// <returns></returns>
public Dictionary<int, List<StoreListDto>> StoreList()
{
var db = DbContext();

StringBuilder sb = new StringBuilder();
sb.Append(@"SELECT a.AutoKey as ClientId,a.Name as ClientName, b.AutoKey as DeviceID,b.DeviceName,b.DeviceTypeKey FROM BPA_Organize as a JOIN BPA_DeviceInfo as b ON a.Id= b.OrgId");

var sql = sb.ToString();
var data = db.SqlQueryable<StoreListDto>(sql).ToList();
Dictionary<int, List<StoreListDto>> dic = new Dictionary<int, List<StoreListDto>>();

IEnumerable<IGrouping<int, StoreListDto>> re = data.GroupBy(s => s.ClientId);
foreach (IGrouping<int, StoreListDto> item in re)
{
dic[item.Key] = item?.ToList();
}
return dic;
}

}
}

正在加载...
取消
保存