EFCore重新生成
如题
This commit is contained in:
@@ -89,68 +89,68 @@ namespace BLW_Log.Controllers
|
||||
[HttpPost()]
|
||||
public async Task AddIOTLog()
|
||||
{
|
||||
string sssttt = "";
|
||||
try
|
||||
{
|
||||
var readResult = Request.BodyReader.ReadAsync().Result;
|
||||
Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End);
|
||||
string body = Encoding.UTF8.GetString(readResult.Buffer.FirstSpan);
|
||||
sssttt = body;
|
||||
Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(body);
|
||||
string topic = dic["topic"];
|
||||
string payload = dic["payload"];
|
||||
//string sssttt = "";
|
||||
//try
|
||||
//{
|
||||
// var readResult = Request.BodyReader.ReadAsync().Result;
|
||||
// Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End);
|
||||
// string body = Encoding.UTF8.GetString(readResult.Buffer.FirstSpan);
|
||||
// sssttt = body;
|
||||
// Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(body);
|
||||
// string topic = dic["topic"];
|
||||
// string payload = dic["payload"];
|
||||
|
||||
this._logger.Info("Topic: " + topic);
|
||||
this._logger.Info("PayLoad: " + payload);
|
||||
// this._logger.Info("Topic: " + topic);
|
||||
// this._logger.Info("PayLoad: " + payload);
|
||||
|
||||
IOTMonitorData igs = JsonConvert.DeserializeObject<IOTMonitorData>(payload);
|
||||
// IOTMonitorData igs = JsonConvert.DeserializeObject<IOTMonitorData>(payload);
|
||||
|
||||
//using (var a = new LowmachinelogContext())
|
||||
//{
|
||||
// //using (var a = new LowmachinelogContext())
|
||||
// //{
|
||||
|
||||
// IotMonitorlog iot = new IotMonitorlog();
|
||||
// iot.TriggerTime = igs.TriggerTime;
|
||||
// iot.RoomNumber = igs.RoomNumber;
|
||||
// iot.RequestId = igs.RequestId;
|
||||
// iot.Platform = igs.Platform;
|
||||
// iot.Step = igs.Step;
|
||||
// iot.CommandDescription = igs.CommandDescription;
|
||||
// iot.HotelName = igs.HotelName;
|
||||
// // IotMonitorlog iot = new IotMonitorlog();
|
||||
// // iot.TriggerTime = igs.TriggerTime;
|
||||
// // iot.RoomNumber = igs.RoomNumber;
|
||||
// // iot.RequestId = igs.RequestId;
|
||||
// // iot.Platform = igs.Platform;
|
||||
// // iot.Step = igs.Step;
|
||||
// // iot.CommandDescription = igs.CommandDescription;
|
||||
// // iot.HotelName = igs.HotelName;
|
||||
|
||||
// int abc = 0;
|
||||
// int.TryParse(igs.HotelId ?? "0", out abc);
|
||||
// iot.HotelId = abc;
|
||||
// iot.HotelCode = igs.HotelCode.ToString();
|
||||
// a.IotMonitorlogs.Add(iot);
|
||||
// a.SaveChanges();
|
||||
// a.WebapiMonitorlogs.AsNoTracking().ToArray();
|
||||
//}
|
||||
// // int abc = 0;
|
||||
// // int.TryParse(igs.HotelId ?? "0", out abc);
|
||||
// // iot.HotelId = abc;
|
||||
// // iot.HotelCode = igs.HotelCode.ToString();
|
||||
// // a.IotMonitorlogs.Add(iot);
|
||||
// // a.SaveChanges();
|
||||
// // a.WebapiMonitorlogs.AsNoTracking().ToArray();
|
||||
// //}
|
||||
|
||||
|
||||
|
||||
IotMonitorlog iot = new IotMonitorlog();
|
||||
iot.TriggerTime = igs.TriggerTime;
|
||||
iot.RoomNumber = igs.RoomNumber;
|
||||
iot.RequestId = igs.RequestId;
|
||||
iot.Platform = igs.Platform;
|
||||
iot.Step = igs.Step;
|
||||
iot.CommandDescription = igs.CommandDescription;
|
||||
iot.HotelName = igs.HotelName;
|
||||
// IotMonitorlog iot = new IotMonitorlog();
|
||||
// iot.TriggerTime = igs.TriggerTime;
|
||||
// iot.RoomNumber = igs.RoomNumber;
|
||||
// iot.RequestId = igs.RequestId;
|
||||
// iot.Platform = igs.Platform;
|
||||
// iot.Step = igs.Step;
|
||||
// iot.CommandDescription = igs.CommandDescription;
|
||||
// iot.HotelName = igs.HotelName;
|
||||
|
||||
int abc = 0;
|
||||
int.TryParse(igs.HotelId ?? "0", out abc);
|
||||
iot.HotelId = abc;
|
||||
iot.HotelCode = igs.HotelCode.ToString();
|
||||
dbContext.IotMonitorlogs.Add(iot);
|
||||
await dbContext.SaveChangesAsync();
|
||||
//dbContext.WebapiMonitorlogs.AsNoTracking().ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this._logger.Error(ex.Message);
|
||||
this._logger.Error("数据为: " + sssttt);
|
||||
this._logger.Error(ex.StackTrace);
|
||||
}
|
||||
// int abc = 0;
|
||||
// int.TryParse(igs.HotelId ?? "0", out abc);
|
||||
// iot.HotelId = abc;
|
||||
// iot.HotelCode = igs.HotelCode.ToString();
|
||||
// dbContext.IotMonitorlogs.Add(iot);
|
||||
// await dbContext.SaveChangesAsync();
|
||||
// //dbContext.WebapiMonitorlogs.AsNoTracking().ToArray();
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// this._logger.Error(ex.Message);
|
||||
// this._logger.Error("数据为: " + sssttt);
|
||||
// this._logger.Error(ex.StackTrace);
|
||||
//}
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
@@ -497,84 +497,84 @@ namespace BLW_Log.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpPost()]
|
||||
public ReturnInfo Get_IOTLog([FromForm] string QueryData)
|
||||
{
|
||||
ReturnInfo info = new ReturnInfo();
|
||||
info.isok = true;
|
||||
try
|
||||
{
|
||||
List<IotMonitorlog> lg = new List<IotMonitorlog>();
|
||||
LogQuery? q = JsonConvert.DeserializeObject<LogQuery>(QueryData);
|
||||
//[HttpPost()]
|
||||
//public ReturnInfo Get_IOTLog([FromForm] string QueryData)
|
||||
//{
|
||||
// ReturnInfo info = new ReturnInfo();
|
||||
// info.isok = true;
|
||||
// try
|
||||
// {
|
||||
// List<IotMonitorlog> lg = new List<IotMonitorlog>();
|
||||
// LogQuery? q = JsonConvert.DeserializeObject<LogQuery>(QueryData);
|
||||
|
||||
string? st = q?.Start_Time;
|
||||
string? et = q?.End_Time;
|
||||
// string? st = q?.Start_Time;
|
||||
// string? et = q?.End_Time;
|
||||
|
||||
int PageSize = q.PageSize;
|
||||
int PageIndex = q.PageIndex;
|
||||
// int PageSize = q.PageSize;
|
||||
// int PageIndex = q.PageIndex;
|
||||
|
||||
List<string> c11 = q.CommandType;
|
||||
// List<string> c11 = q.CommandType;
|
||||
|
||||
int AAA = (PageIndex - 1) * PageSize;
|
||||
DateTime sst = DateTime.Parse(st);
|
||||
DateTime eet = DateTime.Parse(et);
|
||||
if (eet < sst)
|
||||
{
|
||||
info.isok = false;
|
||||
info.message = "结束时间不能大于开始时间";
|
||||
return info;
|
||||
}
|
||||
var qqqq = q?.Data;
|
||||
// int AAA = (PageIndex - 1) * PageSize;
|
||||
// DateTime sst = DateTime.Parse(st);
|
||||
// DateTime eet = DateTime.Parse(et);
|
||||
// if (eet < sst)
|
||||
// {
|
||||
// info.isok = false;
|
||||
// info.message = "结束时间不能大于开始时间";
|
||||
// return info;
|
||||
// }
|
||||
// var qqqq = q?.Data;
|
||||
|
||||
int TotalCount = 0;
|
||||
//using (var a = new LowmachinelogContext())
|
||||
//{
|
||||
var h11 = qqqq?.Select(x => x.HotelCode).Distinct();
|
||||
var r11 = qqqq?.Select(x => x.RoomNumber).Distinct();
|
||||
// int TotalCount = 0;
|
||||
// //using (var a = new LowmachinelogContext())
|
||||
// //{
|
||||
// var h11 = qqqq?.Select(x => x.HotelCode).Distinct();
|
||||
// var r11 = qqqq?.Select(x => x.RoomNumber).Distinct();
|
||||
|
||||
string h22 = string.Join(",", h11.Select(name => $"'{name.Replace("'", "''")}'"));
|
||||
string r22 = string.Join(",", r11.Select(name => $"'{name.Replace("'", "''")}'"));
|
||||
// string h22 = string.Join(",", h11.Select(name => $"'{name.Replace("'", "''")}'"));
|
||||
// string r22 = string.Join(",", r11.Select(name => $"'{name.Replace("'", "''")}'"));
|
||||
|
||||
string sss = $"""
|
||||
SELECT * FROM iot_monitorlog a
|
||||
where a."HotelCode" in ({h22}) and a."RoomNumber" in ({r22})
|
||||
and a."TriggerTime">='{st}' and a."TriggerTime" <='{et}' order by a."ID" DESC;
|
||||
""";
|
||||
// string sss = $"""
|
||||
// SELECT * FROM iot_monitorlog a
|
||||
// where a."HotelCode" in ({h22}) and a."RoomNumber" in ({r22})
|
||||
// and a."TriggerTime">='{st}' and a."TriggerTime" <='{et}' order by a."ID" DESC;
|
||||
// """;
|
||||
|
||||
var ddd = dbContext.IotMonitorlogs.FromSqlRaw<IotMonitorlog>(sss).ToList();
|
||||
// var ddd = dbContext.IotMonitorlogs.FromSqlRaw<IotMonitorlog>(sss).ToList();
|
||||
|
||||
|
||||
|
||||
string sss111 = $"""
|
||||
SELECT count("ID") FROM iot_monitorlog a
|
||||
where a."HotelCode" in ({h22}) and a."RoomNumber" in ({r22})
|
||||
and a."TriggerTime">='{st}' and a."TriggerTime" <='{et}';
|
||||
""";
|
||||
var query_int = dbContext.Database.SqlQueryRaw<int>(sss111);
|
||||
// string sss111 = $"""
|
||||
// SELECT count("ID") FROM iot_monitorlog a
|
||||
// where a."HotelCode" in ({h22}) and a."RoomNumber" in ({r22})
|
||||
// and a."TriggerTime">='{st}' and a."TriggerTime" <='{et}';
|
||||
// """;
|
||||
// var query_int = dbContext.Database.SqlQueryRaw<int>(sss111);
|
||||
|
||||
foreach (var NNH in query_int)
|
||||
{
|
||||
int ccg = 0;
|
||||
int.TryParse(NNH.ToString(), out ccg);
|
||||
TotalCount += ccg;
|
||||
}
|
||||
lg = ddd;
|
||||
//}
|
||||
// foreach (var NNH in query_int)
|
||||
// {
|
||||
// int ccg = 0;
|
||||
// int.TryParse(NNH.ToString(), out ccg);
|
||||
// TotalCount += ccg;
|
||||
// }
|
||||
// lg = ddd;
|
||||
// //}
|
||||
|
||||
var qqa = lg.OrderBy(x => x.TriggerTime).ToList();
|
||||
DevMonitorIOTLogResult_WITH_Count c = new DevMonitorIOTLogResult_WITH_Count();
|
||||
c.TotalCount = TotalCount;
|
||||
c.devMonitorLogResults = qqa;
|
||||
// var qqa = lg.OrderBy(x => x.TriggerTime).ToList();
|
||||
// DevMonitorIOTLogResult_WITH_Count c = new DevMonitorIOTLogResult_WITH_Count();
|
||||
// c.TotalCount = TotalCount;
|
||||
// c.devMonitorLogResults = qqa;
|
||||
|
||||
info.response = c;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
info.isok = false;
|
||||
info.message = ex.Message;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
// info.response = c;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// info.isok = false;
|
||||
// info.message = ex.Message;
|
||||
// }
|
||||
// return info;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace BLW_Log.Models
|
||||
|
||||
public class DevMonitorIOTLogResult_WITH_Count
|
||||
{
|
||||
public List<DAL.PGModels.IotMonitorlog> devMonitorLogResults { get; set; }
|
||||
//public List<DAL.PGModels.IotMonitorlog> devMonitorLogResults { get; set; }
|
||||
public int TotalCount { get; set; }
|
||||
}
|
||||
public class DevMonitorWebAPILogResult_WITH_Count
|
||||
|
||||
Reference in New Issue
Block a user