- Thêm đồng bộ thủ công
- Báo trạng thái khi resend - Báo rõ hơn từng loại cảm biến CDM, Sensor
This commit is contained in:
+55
-2
@@ -1,4 +1,5 @@
|
||||
using DE70_CMDv2;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SafeBagDE70.API;
|
||||
using SafeBagDE70.Model;
|
||||
@@ -37,6 +38,7 @@ namespace SafeBagDE70
|
||||
public static string BaseURL = "";
|
||||
public static int TenantId = 0;
|
||||
public static bool IsInternetOk = false;
|
||||
static Task? resendTask = null;
|
||||
public static DeviceStatus? _DeviceStatus = null;
|
||||
public static DeviceStatus? DeviceStatus
|
||||
{
|
||||
@@ -259,6 +261,58 @@ namespace SafeBagDE70
|
||||
}
|
||||
return str.Trim(',');
|
||||
}
|
||||
public static void ResendData()
|
||||
{
|
||||
if (!AppData.IsInTransaction && AppData.IsInternetOk)
|
||||
{
|
||||
|
||||
if (resendTask == null || resendTask.IsCompleted)
|
||||
{
|
||||
resendTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = new CDMDbContext())
|
||||
{
|
||||
var startTime = DateTime.Now.Date.AddDays(-2).Date;
|
||||
var unsentHist = context.Histories
|
||||
.Where(x => x.DepositTime >= startTime)
|
||||
.Where(x => ((x.IsSent == null || x.IsSent == false)))
|
||||
.ToList();
|
||||
foreach (var item in unsentHist)
|
||||
{
|
||||
var data2Send = JsonConvert.DeserializeObject<CountingData2Send>(item.Data);
|
||||
var bResult = await APIModels.SendCountingData(data2Send);
|
||||
if (bResult)
|
||||
{
|
||||
item.IsSent = true;
|
||||
context.Update(item);
|
||||
context.SaveChanges();
|
||||
Log.Information("Resend: " + item.Data + " successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Resend: " + item.Data + " failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Resend failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information("Previous resend are running");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information($"Resend could not start Is In Transaction: {AppData.IsInTransaction} IsInternetOk: {AppData.IsInTransaction}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public class CustomerAccount
|
||||
@@ -499,12 +553,11 @@ namespace SafeBagDE70
|
||||
public enum SensorStatusCode
|
||||
{
|
||||
NORMAL = 0,
|
||||
ERROR = 1
|
||||
ERROR = 4
|
||||
}
|
||||
public enum CDMStatusCode
|
||||
{
|
||||
NORMAL = 0,
|
||||
DISCONNECT_SERIALPORT=1,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user