@@ -65,24 +65,24 @@ namespace HKCardOUT | |||||
var configer = (new ConfigurationBuilder()).AddJsonFile("options.pro.json").Build(); | var configer = (new ConfigurationBuilder()).AddJsonFile("options.pro.json").Build(); | ||||
#endif | #endif | ||||
DataBus.ConnectionString = configer.GetConnectionString("Sqlite"); | DataBus.ConnectionString = configer.GetConnectionString("Sqlite"); | ||||
DataBus.SaasRoute = configer["SaasRoute"]; | |||||
HKLib.Configer.MqAddress = configer["MQ"]; | HKLib.Configer.MqAddress = configer["MQ"]; | ||||
DataBus.Cron = configer["Cron"]; | DataBus.Cron = configer["Cron"]; | ||||
DataBus.SaasRoute = configer["SaasRoute"]; | |||||
DataBus.StoreId = configer["StoreId"]; | DataBus.StoreId = configer["StoreId"]; | ||||
DataBus.COM = configer["COM"]; | DataBus.COM = configer["COM"]; | ||||
DataBus.TenantId = configer["TenantId"]; | DataBus.TenantId = configer["TenantId"]; | ||||
DataBus.StartDevice = configer["StartDevice"].AsBool(); | DataBus.StartDevice = configer["StartDevice"].AsBool(); | ||||
DataBus.Cancel = configer["Cancel"].AsBool(); | DataBus.Cancel = configer["Cancel"].AsBool(); | ||||
DataBus.Count = configer["Count"].AsInt(); | DataBus.Count = configer["Count"].AsInt(); | ||||
HKLib.Configer.SaasRoute = DataBus.SaasRoute; | |||||
RemoteService.PullShopInfo(); | |||||
//初始化表 | //初始化表 | ||||
DbContext.InitTable(); | DbContext.InitTable(); | ||||
ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push); | ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push); | ||||
ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push); | ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push); | ||||
HKLib.Configer.SaasRoute = DataBus.SaasRoute; | |||||
//服务器拉取数据 | //服务器拉取数据 | ||||
RemoteService.SyncTime(); | RemoteService.SyncTime(); | ||||
RemoteService.GetCardStuatas(); | RemoteService.GetCardStuatas(); | ||||
RemoteService.PullShopInfo(); | |||||
base.Configure(); | base.Configure(); | ||||
} | } | ||||
@@ -0,0 +1,15 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace DTO | |||||
{ | |||||
public class SaleDto | |||||
{ | |||||
public int Type { get; set; } = -1; | |||||
public string GateId { get; set; } | |||||
public string CardNum { get; set; } | |||||
public Guid Id { get; set; } | |||||
public DateTime CreateAt { get; set; } | |||||
} | |||||
} |
@@ -50,6 +50,10 @@ namespace HKCardOUT.Helper | |||||
/// </summary> | /// </summary> | ||||
public static string SyncSaleLog = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrecharge"; | public static string SyncSaleLog = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrecharge"; | ||||
/// <summary> | /// <summary> | ||||
/// 批量消费记录 | |||||
/// </summary> | |||||
public static string SyncSaleLogList = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrechargelist"; | |||||
/// <summary> | |||||
/// 获取店铺信息 | /// 获取店铺信息 | ||||
/// </summary> | /// </summary> | ||||
public static string PullShopInfo = DataBus.SaasRoute + $"api/StoreHelper/GeBasisGateList?StoreId={DataBus.StoreId}"; | public static string PullShopInfo = DataBus.SaasRoute + $"api/StoreHelper/GeBasisGateList?StoreId={DataBus.StoreId}"; | ||||
@@ -1,4 +1,5 @@ | |||||
using HKCardOUT.Helper; | |||||
using DTO; | |||||
using HKCardOUT.Helper; | |||||
using HKCardOUT.Logic.Model; | using HKCardOUT.Logic.Model; | ||||
using HKCardOUT.Logic.Service; | using HKCardOUT.Logic.Service; | ||||
using HKLib.Dto; | using HKLib.Dto; | ||||
@@ -21,6 +22,7 @@ namespace HKCardOUT.Logic | |||||
{ | { | ||||
public class RemoteService | public class RemoteService | ||||
{ | { | ||||
private static readonly object locker = new(); | |||||
/// <summary> | /// <summary> | ||||
/// 获取所有卡状态和卡号 | /// 获取所有卡状态和卡号 | ||||
/// </summary> | /// </summary> | ||||
@@ -82,6 +84,41 @@ namespace HKCardOUT.Logic | |||||
return false; | return false; | ||||
} | } | ||||
} | |||||
/// <summary> | |||||
/// 批量同步同步消费记录 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public static bool SyncSaleLogList(List<SaleDto> dto) | |||||
{ | |||||
try | |||||
{ | |||||
lock (locker) | |||||
{ | |||||
var Ids = dto.Select(t => t.Id).ToList(); | |||||
var check = DbContext.Context.Queryable<SaleLog>().Where(t => Ids.Contains(t.Id)).Any(t => t.IsSync); | |||||
if (check) return false; | |||||
var data = IHttpMultiClient.HttpMulti.AddHeader(t => | |||||
{ | |||||
t.HeaderKey = "TenantId"; | |||||
t.HeaderValue = DataBus.TenantId; | |||||
}).AddNode(t => | |||||
{ | |||||
t.ReqType = MultiType.POST; | |||||
t.JsonParam = dto.ToJson(); | |||||
t.NodePath = ApiRoute.SyncSaleLogList; | |||||
}).Build().RunStringFirst(); | |||||
HKLog.HKLogImport.WriteInfo($"批量同步同步消费记录调用:{data}"); | |||||
return bool.Parse(data.ToModel<JObject>()["data"].ToString()); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
HKLog.HKLogImport.WriteError(ex); | |||||
return false; | |||||
} | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// 获取店铺信息 | /// 获取店铺信息 | ||||
@@ -1,8 +1,14 @@ | |||||
using HKCardOUT.Logic; | |||||
using DTO; | |||||
using HKCardOUT.Helper; | |||||
using HKCardOUT.Logic; | |||||
using HKCardOUT.Logic.Model; | using HKCardOUT.Logic.Model; | ||||
using Quartz; | using Quartz; | ||||
using S7.Net.Types; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using XExten.Advance.LinqFramework; | |||||
namespace HKCardOUT.QuartzUtil.Job | namespace HKCardOUT.QuartzUtil.Job | ||||
{ | { | ||||
@@ -14,18 +20,42 @@ namespace HKCardOUT.QuartzUtil.Job | |||||
{ | { | ||||
default: | default: | ||||
{ | { | ||||
var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false).ToList(); | var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false).ToList(); | ||||
List<SaleDto> dto = new List<SaleDto>(); | |||||
if (WaitSync.Count > 0) | if (WaitSync.Count > 0) | ||||
{ | { | ||||
HKLog.HKLogImport.WriteInfo($"订单推送执行,推送数量{WaitSync.Count},推送的卡号:【{string.Join(",", WaitSync.Select(t => t.CardNo))}】"); | HKLog.HKLogImport.WriteInfo($"订单推送执行,推送数量{WaitSync.Count},推送的卡号:【{string.Join(",", WaitSync.Select(t => t.CardNo))}】"); | ||||
foreach (var input in WaitSync) | foreach (var input in WaitSync) | ||||
{ | { | ||||
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); | |||||
var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == input.Location.AsInt())?.GateId; | |||||
dto.Add(new SaleDto | |||||
{ | |||||
CardNum = input.CardNo, | |||||
GateId = GateId, | |||||
Id= input.Id, | |||||
CreateAt=input.CreateTime | |||||
}); | |||||
} | |||||
var db = DbContext.Context; | |||||
try | |||||
{ | |||||
db.BeginTran(); | |||||
var res = RemoteService.SyncSaleLogList(dto); | |||||
if (res) | if (res) | ||||
await DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == input.Id).ExecuteCommandAsync(); | |||||
{ | |||||
var ids = WaitSync.Select(t => t.Id).ToList(); | |||||
await DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => ids.Contains(t.Id)).ExecuteCommandAsync(); | |||||
db.CommitTran(); | |||||
} | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
db.RollbackTran(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||