Browse Source

同步数据

Lishi
xxe 2 years ago
parent
commit
45afd65d06
3 changed files with 48 additions and 11 deletions
  1. +18
    -0
      HKCardOUT/DTO/FailDto.cs
  2. +4
    -4
      HKCardOUT/Logic/RemoteService.cs
  3. +26
    -7
      HKCardOUT/QuartzUtil/Job/QuartzJob.cs

+ 18
- 0
HKCardOUT/DTO/FailDto.cs View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DTO
{
public class FailDto
{
/// <summary>
///
/// </summary>
public string cardNum { get; set; }
/// <summary>
/// 当前卡没有绑定会员
/// </summary>
public string msg { get; set; }
}
}

+ 4
- 4
HKCardOUT/Logic/RemoteService.cs View File

@@ -86,7 +86,7 @@ namespace HKCardOUT.Logic
/// 批量同步同步消费记录
/// </summary>
/// <returns></returns>
public static bool SyncSaleLogList(List<SaleDto> dto)
public static List<FailDto> SyncSaleLogList(List<SaleDto> dto)
{
try
{
@@ -94,7 +94,7 @@ namespace HKCardOUT.Logic
{
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;
if (check) return null ;
var data = IHttpMultiClient.HttpMulti.AddHeader(t =>
{
t.HeaderKey = "TenantId";
@@ -106,13 +106,13 @@ namespace HKCardOUT.Logic
t.NodePath = ApiRoute.SyncSaleLogList;
}).Build().RunStringFirst();
HKLog.HKLogImport.WriteInfo($"批量同步同步消费记录调用:{data}");
return bool.Parse(data.ToModel<JObject>()["data"].ToString());
return data.ToModel<JObject>()["data"].ToString().ToModel<JObject>()["failList"].ToJson().ToModel<List<FailDto>>();
}
}
catch (Exception ex)
{
HKLog.HKLogImport.WriteError(ex);
return false;
return null;
}




+ 26
- 7
HKCardOUT/QuartzUtil/Job/QuartzJob.cs View File

@@ -21,7 +21,7 @@ namespace HKCardOUT.QuartzUtil.Job
{
default:
{
var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false&&t.State==true).ToList();
var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false && t.State == true).ToList();
List<SaleDto> dto = new List<SaleDto>();
if (WaitSync.Count > 0)
{
@@ -46,14 +46,33 @@ namespace HKCardOUT.QuartzUtil.Job
lock (obj)
{
db.BeginTran();
foreach (var item in dto)
var result = RemoteService.SyncSaleLogList(dto);
if (result != null && result.Count > 0)
{
var res = RemoteService.SyncSaleLogList(new List<SaleDto> { item });
if (res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id==item.Id).ExecuteCommand();
else
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.State==false).Where(t => t.Id == item.Id).ExecuteCommand();
var cardNum = result.Select(t => t.cardNum).ToList();
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.State == false).Where(t => cardNum.Contains(t.Id.ToString())).ExecuteCommand();

dto.RemoveAll(t => cardNum.Contains(t.CardNum));

var Sid = dto.Select(t => t.Id).ToList();

DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => Sid.Contains(t.Id)).ExecuteCommand();
}
else
{
var Sid = dto.Select(t => t.Id).ToList();

DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => Sid.Contains(t.Id)).ExecuteCommand();

}
//foreach (var item in dto)
//{
// var res = (new List<SaleDto> { item });
// if (res)
// DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == item.Id).ExecuteCommand();
// else
// DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.State == false).Where(t => t.Id == item.Id).ExecuteCommand();
//}
db.CommitTran();
}
}


Loading…
Cancel
Save