|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq.Dynamic.Core; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Coravel.Invocable; |
|
|
@ -48,117 +49,46 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService |
|
|
|
_hbpoSeDetailRepository = hbpoSeDetailRepository; |
|
|
|
} |
|
|
|
|
|
|
|
//private readonly IRepository<TM_BJBMPT_JIT_RECORD> _TMBJBMPTJITRECORDRepository;
|
|
|
|
|
|
|
|
//public HBPOSeSyncAppService(IRepository<TM_BJBMPT_JIT_RECORD> TMBJBMPTJITRECORDRepository)
|
|
|
|
//{
|
|
|
|
// _TMBJBMPTJITRECORDRepository = TMBJBMPTJITRECORDRepository;
|
|
|
|
//}
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task Invoke() |
|
|
|
{ |
|
|
|
await SyncJitRecord(); |
|
|
|
//await SyncJisRecord();
|
|
|
|
//if (!dbContext.GetService<IRelationalDatabaseCreator>().Exists() && dbContext.Database.EnsureCreated())
|
|
|
|
//{
|
|
|
|
// this._balanceRepository.AsNoTracking().ForEachAsync(o =>
|
|
|
|
// {
|
|
|
|
// dbContext.Set<VmiBalance>().Add(o);
|
|
|
|
// });
|
|
|
|
// dbContext.SaveChanges();
|
|
|
|
// var snapshot = new VmiSnapshot { Name = date, Path = connectionString };
|
|
|
|
// this._snapshotRepository.InsertAsync(snapshot).Wait();
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//using (var context = new HouseDbContext(optionsBuilder.Options))
|
|
|
|
//{
|
|
|
|
// var one = context.Notices.FirstOrDefault(n => n.Id == notice.Id);
|
|
|
|
// // 当然你也可以直接初始化其他的Service
|
|
|
|
// var nService = new NoticeService(context, null);
|
|
|
|
// var one = nService.FindOne(notice.Id);
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var TM_BJBMPT_JIT_RECORDs = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD
|
|
|
|
// .Where(b => b.UID > 3)
|
|
|
|
// .OrderBy(b => b.BillTime)
|
|
|
|
// .ToList();
|
|
|
|
//foreach (var TM_BJBMPT_JIT_RECORD in TM_BJBMPT_JIT_RECORDs)
|
|
|
|
//{
|
|
|
|
// Console.WriteLine($"{TM_BJBMPT_JIT_RECORD.UID}");
|
|
|
|
//}
|
|
|
|
|
|
|
|
//using (var db = new WMSBJBMPTDbContext())
|
|
|
|
//{
|
|
|
|
// var blogs = db.TM_BJBMPT_JIT_RECORD
|
|
|
|
// .Where(b => b.UID > 3)
|
|
|
|
// .OrderBy(b => b.BillTime)
|
|
|
|
// .ToList();
|
|
|
|
|
|
|
|
// foreach (var blog in blogs)
|
|
|
|
// {
|
|
|
|
// Console.WriteLine($"{blog.UID}");
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
Console.WriteLine($"{GetType().FullName}执行了"); |
|
|
|
await SyncJitRecordAsync(); |
|
|
|
await SyncJisRecordAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 同步JitRecord
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SyncJitRecord() |
|
|
|
private async Task SyncJitRecordAsync() |
|
|
|
{ |
|
|
|
//同步表名称
|
|
|
|
var syncTableName = "TM_BJBMPT_JIT_RECORD"; |
|
|
|
var syncTableName = "JisHBPOSeSync_Jit"; |
|
|
|
//HBPO类型集合
|
|
|
|
var EnumDeliverSubBillTypes = new List<EnumDeliverSubBillType> |
|
|
|
{ |
|
|
|
EnumDeliverSubBillType.保险杠HBPO, |
|
|
|
EnumDeliverSubBillType.买单件保险杠HBPO, |
|
|
|
EnumDeliverSubBillType.买单件小件HBPO, |
|
|
|
EnumDeliverSubBillType.小件HBPO, |
|
|
|
EnumDeliverSubBillType.JIT直供件HBPO |
|
|
|
EnumDeliverSubBillType.小件HBPO |
|
|
|
}; |
|
|
|
|
|
|
|
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
|
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName); |
|
|
|
if (syncPositionFlag != null) |
|
|
|
{ |
|
|
|
//var inv = Expression.Invoke(t=>t.UID > int.Parse(syncPositionFlag.Position), predicate.Parameters);
|
|
|
|
//return Expression.Lambda<Func<T, bool>>(Expression.And(exp.Body, inv), exp.Parameters);
|
|
|
|
|
|
|
|
//predicate.And(t => t.UID > int.Parse(syncPositionFlag.Position));
|
|
|
|
|
|
|
|
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> expression = (t) => t.UID > int.Parse(syncPositionFlag.Position); |
|
|
|
var body = expression.Body; |
|
|
|
|
|
|
|
//var inv = Expression.Invoke(condition, exp.Parameters);
|
|
|
|
predicate = Expression.Lambda<Func<TM_BJBMPT_JIT_RECORD, bool>>(Expression.And(predicate.Body, body), predicate.Parameters); |
|
|
|
|
|
|
|
//Expression.Lambda<Func<T, bool>>(Expression.Equal(member, constant), parameter);
|
|
|
|
//var expression = predicate.And(t => t.UID > int.Parse(syncPositionFlag.Position));
|
|
|
|
|
|
|
|
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
|
} |
|
|
|
|
|
|
|
Console.WriteLine($"表达式:{predicate}"); |
|
|
|
|
|
|
|
var jitRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD |
|
|
|
.Where(predicate) |
|
|
|
.OrderBy(b => b.UID) |
|
|
|
.ToList(); |
|
|
|
//WMS发运数据
|
|
|
|
var wmsRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD.Where(predicate).OrderBy(b => b.UID).ToList(); |
|
|
|
|
|
|
|
var hbpoSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<HBPO_SE_DETAIL>>(jitRecords); |
|
|
|
var hbpoSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<HBPO_SE_DETAIL>>(wmsRecords); |
|
|
|
if (hbpoSeDetails.Any()) |
|
|
|
{ |
|
|
|
await _hbpoSeDetailRepository.InsertManyAsync(hbpoSeDetails); |
|
|
|
|
|
|
|
if (syncPositionFlag != null) |
|
|
|
{ |
|
|
|
syncPositionFlag.Position = jitRecords.Last().UID.ToString(); |
|
|
|
syncPositionFlag.Position = wmsRecords.Last().UID.ToString(); |
|
|
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
|
|
|
} |
|
|
|
else |
|
|
@ -166,37 +96,46 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService |
|
|
|
syncPositionFlag = new SyncPositionFlag() |
|
|
|
{ |
|
|
|
TableName = syncTableName, |
|
|
|
Position = jitRecords.Last().UID.ToString() |
|
|
|
Position = wmsRecords.Last().UID.ToString() |
|
|
|
}; |
|
|
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SyncJisRecord() |
|
|
|
/// <summary>
|
|
|
|
/// 同步JisRecord
|
|
|
|
/// </summary>
|
|
|
|
private async Task SyncJisRecordAsync() |
|
|
|
{ |
|
|
|
//同步表名称
|
|
|
|
var syncTableName = "TM_BJBMPT_JIS_RECORD"; |
|
|
|
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => true; |
|
|
|
var syncTableName = "JisHBPOSeSync_Jis"; |
|
|
|
//BBAC类型集合
|
|
|
|
var EnumDeliverSubBillTypes = new List<EnumDeliverSubBillType> |
|
|
|
{ |
|
|
|
EnumDeliverSubBillType.保险杠BBAC, |
|
|
|
EnumDeliverSubBillType.买单件保险杠BBAC, |
|
|
|
EnumDeliverSubBillType.买单件小件BBAC, |
|
|
|
EnumDeliverSubBillType.小件BBAC |
|
|
|
}; |
|
|
|
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
|
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName); |
|
|
|
if (syncPositionFlag != null) |
|
|
|
{ |
|
|
|
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position); |
|
|
|
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
|
} |
|
|
|
|
|
|
|
var jisRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD |
|
|
|
.Where(predicate) |
|
|
|
.OrderBy(b => b.UID) |
|
|
|
.ToList(); |
|
|
|
//WMS发运数据
|
|
|
|
var wmsRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD.Where(predicate).OrderBy(b => b.UID).ToList(); |
|
|
|
|
|
|
|
var hbpoSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<HBPO_SE_DETAIL>>(jisRecords); |
|
|
|
var hbpoSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<HBPO_SE_DETAIL>>(wmsRecords); |
|
|
|
if (hbpoSeDetails.Any()) |
|
|
|
{ |
|
|
|
await _hbpoSeDetailRepository.InsertManyAsync(hbpoSeDetails); |
|
|
|
|
|
|
|
if (syncPositionFlag != null) |
|
|
|
{ |
|
|
|
syncPositionFlag.Position = jisRecords.Last().UID.ToString(); |
|
|
|
syncPositionFlag.Position = wmsRecords.Last().UID.ToString(); |
|
|
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
|
|
|
} |
|
|
|
else |
|
|
@ -204,7 +143,7 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService |
|
|
|
syncPositionFlag = new SyncPositionFlag() |
|
|
|
{ |
|
|
|
TableName = syncTableName, |
|
|
|
Position = jisRecords.Last().UID.ToString() |
|
|
|
Position = wmsRecords.Last().UID.ToString() |
|
|
|
}; |
|
|
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
|
|
|
} |
|
|
|