You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/ServiceProjectSyncWin/Program.cs

103 lines
3.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Furion;
using Furion.DatabaseAccessor;
using Microsoft.Extensions.DependencyInjection;
using ServiceProjectSyncWin;
using SqlSugar;
Serve.RunGeneric(additional: services =>
{
services.AddRemoteRequest();
services.AddSqlsugarSetup(App.Configuration);
}, true, true);
Console.WriteLine("开始准备同步历史服务状态数据");
Console.ReadKey();
public class SyncHisRecord
{
SqlSugar.ISqlSugarClient _db;
public SyncHisRecord(ISqlSugarClient db)
{
_db = db;
}
public void SyncServiceProjectRecord()
{
/*
//_db.Queryable<Order>()
var tenantInfo = _sysTenantRepository.AsQueryable().Filter(null, true).First(a => a.Id == tenantId);
/*
1、按批次读取服务状态数据。去掉没有完成时间的、并且订舱数据是已删除的记录
2、写入历史记录表。
3、单票生成触发报文并推送状态。
4、更新历史记录标记同步状态
maxId = _serviceStatusBookingSyncHisInfoRepository.AsQueryable().Max(a => a.ORG_STATUS_ID);
_logger.LogInformation("批次={no} 获取最后同步服务状态的ID={maxId}", batchNo, maxId);
int takeNum = 1000;
while (true)
{
var takeList = _bookingGoodsStatusRepository.AsQueryable().Filter(null, true)
.InnerJoin<BookingGoodsStatusConfig>((gs, cfg) => gs.ConfigId == cfg.Id)
.InnerJoin<BookingOrder>((gs, cfg, bk) => gs.bookingId == bk.Id)
.Where((gs, cfg, bk) =>
gs.FinishTime.HasValue && gs.TenantId == tenantId
&& !bk.IsDeleted && gs.FinishUserId != 142307070910551
&& (maxId == 0 || gs.Id > maxId))
.OrderBy((gs, cfg, bk) => gs.Id)
.Select((gs, cfg, bk) => new { GS = gs, CFG = cfg, BK = bk })
.Take(takeNum).ToList();
totalSyncNum += takeList.Count;
_logger.LogInformation("批次={no} 同步待处理任务 totalSyncNum={totalSyncNum}", batchNo, totalSyncNum);
//没有记录跳出循环
if (takeList.Count == 0)
break;
maxId = takeList.Max(a => a.GS.Id);
_logger.LogInformation("批次={no} 获取最后同步服务状态的 maxId={maxId}", batchNo, maxId);
//写入记录表
takeList.ForEach(async record => {
var entity = new ServiceStatusBookingSyncHisInfo
{
PK_ID = IDGen.NextID().ToString(),
ORG_STATUS_ID = record.GS.Id,
BOOKING_ID = record.BK.Id,
FINISH_TIME = record.GS.FinishTime.Value,
FINISH_USER_ID = record.GS.FinishUserId.Value,
FINISH_USER_NAME = record.GS.FinishUser,
MBL_NO = record.BK.MBLNO,
SORT_NO = record.CFG.Sort,
STATUS_SKU_CODE = record.CFG.SystemCode,
STATUS_SKU_NAME = record.CFG.StatusName,
STATUS_REMARK = record.GS.Remark,
STATUS_VAL = record.GS.ExtData,
TENANT_ID = record.GS.TenantId.Value,
TENANT_NAME = tenantInfo.Name,
VESSEL = record.BK.VESSEL,
VOYNO = record.BK.VOYNO,
};
await _serviceStatusBookingSyncHisInfoRepository.InsertAsync(entity);
succSyncNum++;
});
Thread.Sleep(500);
}
*/
}
}