瀏覽代碼

修改同步逻辑

undefined
xxe 2 年之前
父節點
當前提交
f605e806df
共有 6 個檔案被更改,包括 102 行新增45 行删除
  1. +7
    -7
      HKCardOUT/Bootstrapper.cs
  2. +22
    -13
      HKCardOUT/Logic/RemoteService.cs
  3. +51
    -15
      HKCardOUT/Logic/Service/HKCore.cs
  4. +15
    -6
      HKCardOUT/QuartzUtil/Job/QuartzJob.cs
  5. +6
    -3
      HKCardOUT/ViewModels/RootViewModel.cs
  6. +1
    -1
      HKCardOUT/options.json

+ 7
- 7
HKCardOUT/Bootstrapper.cs 查看文件

@@ -73,13 +73,13 @@ namespace HKCardOUT
/// </summary>
protected override void OnLaunch()
{
//QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
//{
// JobDetail = "定时推送订单",
// Cron = DataBus.Cron,
// JobName = "订单",
// JobGroup = "订单"
//});
QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
{
JobDetail = "定时推送订单",
Cron = DataBus.Cron,
JobName = "订单",
JobGroup = "订单"
});
base.OnLaunch();
}



+ 22
- 13
HKCardOUT/Logic/RemoteService.cs 查看文件

@@ -37,21 +37,30 @@ namespace HKCardOUT.Logic
/// <param name="Money"></param>
public static bool SyncSaleLog(string CardNo, string StallId)
{
var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId;
var data = IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.ReqType = MultiType.POST;
t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson();
t.NodePath = ApiRoute.SyncSaleLog;
}).Build().RunStringFirst();
HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}");
var m = bool.Parse(data.ToModel<JObject>()["data"].ToString());
if (m)
try
{
var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId;
var data = IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.ReqType = MultiType.POST;
t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson();
t.NodePath = ApiRoute.SyncSaleLog;
}).Build().RunStringFirst();
HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}");
var m = bool.Parse(data.ToModel<JObject>()["data"].ToString());
if (m)
{
UHF_RS485_Helper.GetInstance().OpenBeep(StallId.AsInt());
return m;
}
else return false;
}
catch (Exception ex)
{
UHF_RS485_Helper.GetInstance().OpenBeep(StallId.AsInt());
return m;
HKLog.HKLogImport.WriteError(ex);
return false;
}
else return false;
}
/// <summary>
/// 获取店铺信息


+ 51
- 15
HKCardOUT/Logic/Service/HKCore.cs 查看文件

@@ -50,11 +50,23 @@ namespace HKCardOUT.Logic.Service
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
if (entity.Id != Guid.Empty)
{
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
//有网络直接同步
if (DataBus.NetWordState)
{
//先出餐后推数据
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if(res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
}
else
{
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
return true;
}
}
}
return false;
@@ -90,11 +102,23 @@ namespace HKCardOUT.Logic.Service
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
if (entity.Id != Guid.Empty)
{
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
//有网络直接同步
if (DataBus.NetWordState)
{
//先出餐后推数据
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
}
else
{
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
return true;
}
}
}
return false;
@@ -130,11 +154,23 @@ namespace HKCardOUT.Logic.Service
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
if (entity.Id != Guid.Empty)
{
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
//有网络直接同步
if (DataBus.NetWordState)
{
//先出餐后推数据
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
}
else
{
if (!DataBus.IsTest)
Main.GetInstance.Start(input.Location.AsInt());
return true;
}
}
}
return false;


+ 15
- 6
HKCardOUT/QuartzUtil/Job/QuartzJob.cs 查看文件

@@ -1,8 +1,6 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKCardOUT.Logic;
using HKCardOUT.Logic.Model;
using Quartz;
using System.Threading.Tasks;

namespace HKCardOUT.QuartzUtil.Job
@@ -14,7 +12,18 @@ namespace HKCardOUT.QuartzUtil.Job
switch (context.JobDetail.Key.Group)
{
default:
await Task.CompletedTask;
{
var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false).ToList();
if (WaitSync.Count > 0)
{
foreach (var input in WaitSync)
{
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (res)
await DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == input.Id).ExecuteCommandAsync();
}
}
}
break;
}
}


+ 6
- 3
HKCardOUT/ViewModels/RootViewModel.cs 查看文件

@@ -241,7 +241,8 @@ namespace HKCardOUT.ViewModels
Core.DeviceSaleAM(new SaleLog
{
CardNo = input.ResData.Substring(1, input.ResData.Length - 1),
Location = input.Address.AsInt().ToString()
Location = input.Address.AsInt().ToString(),
IsSync=false
});
}
if (DateTime.Now.Hour >= PM[0] && DateTime.Now.Hour < PM[1])
@@ -249,7 +250,8 @@ namespace HKCardOUT.ViewModels
Core.DeviceSalePM(new SaleLog
{
CardNo = input.ResData.Substring(1, input.ResData.Length - 1),
Location = input.Address.AsInt().ToString()
Location = input.Address.AsInt().ToString(),
IsSync = false
});
}
if (DateTime.Now.Hour >= AT[0] && DateTime.Now.Hour < AT[1])
@@ -257,7 +259,8 @@ namespace HKCardOUT.ViewModels
Core.DeviceSaleAT(new SaleLog
{
CardNo = input.ResData.Substring(1, input.ResData.Length - 1),
Location = input.Address.AsInt().ToString()
Location = input.Address.AsInt().ToString(),
IsSync = false
});
}
//Result = new ObservableCollection<SaleLog>(this.Container.Get<HKCore>().PullDaySaleLog());


+ 1
- 1
HKCardOUT/options.json 查看文件

@@ -4,7 +4,7 @@
"IsTest": true,
"COM": "COM4",
//定时任务时间表达式
"Cron": "0 0 11,15 * * ? ",
"Cron": "0 0 0/1 * * ? ",
//店铺ID
"StoreId": "a19535e8-119f-4b10-a011-6288fd3ddb37",
"ConnectionStrings": {


Loading…
取消
儲存