18 changed files with 561 additions and 57 deletions
@ -0,0 +1,143 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Expressions; |
||||
|
using System.Threading.Tasks; |
||||
|
using Coravel.Invocable; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using SettleAccount.Domain.BQ; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
||||
|
using Win.Sfs.Shared.RepositoryBase; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// HBPO发运数据同步服务
|
||||
|
/// </summary>
|
||||
|
[AllowAnonymous] |
||||
|
[Route("api/settleaccount/[controller]/[action]")]
|
||||
|
public class BBACSeSyncAppService : ApplicationService, IInvocable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// WMS数据上下文
|
||||
|
/// </summary>
|
||||
|
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 同步位置标记
|
||||
|
/// </summary>
|
||||
|
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// HBPO发运数据仓储
|
||||
|
/// </summary>
|
||||
|
private readonly INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> _bbacSeDetailRepository; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 构造
|
||||
|
/// </summary>
|
||||
|
public BBACSeSyncAppService( |
||||
|
WMSBJBMPTDbContext wmsBJBMPTContext, |
||||
|
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
||||
|
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> bbacSeDetailRepository) |
||||
|
{ |
||||
|
_wmsBJBMPTContext = wmsBJBMPTContext; |
||||
|
_syncPositionFlagRepository = syncPositionFlagRepository; |
||||
|
_bbacSeDetailRepository = bbacSeDetailRepository; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
public async Task Invoke() |
||||
|
{ |
||||
|
await SyncJitRecord(); |
||||
|
//await SyncJisRecord();
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 同步JitRecord
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
private async Task SyncJitRecord() |
||||
|
{ |
||||
|
//同步表名称
|
||||
|
var syncTableName = "TM_BJBMPT_JIT_RECORD"; |
||||
|
//BBAC类型集合
|
||||
|
var EnumDeliverSubBillTypes = new List<EnumDeliverSubBillType> |
||||
|
{ |
||||
|
EnumDeliverSubBillType.保险杠BBAC, |
||||
|
EnumDeliverSubBillType.买单件保险杠BBAC, |
||||
|
EnumDeliverSubBillType.买单件小件BBAC, |
||||
|
EnumDeliverSubBillType.小件BBAC, |
||||
|
EnumDeliverSubBillType.JIT直供件BBAC |
||||
|
}; |
||||
|
|
||||
|
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) |
||||
|
{ |
||||
|
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> expression = (t) => t.UID > int.Parse(syncPositionFlag.Position); |
||||
|
var body = expression.Body; |
||||
|
predicate = Expression.Lambda<Func<TM_BJBMPT_JIT_RECORD, bool>>(Expression.And(predicate.Body, body), predicate.Parameters); |
||||
|
} |
||||
|
|
||||
|
var jitRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD.Where(predicate).OrderBy(b => b.UID).ToList(); |
||||
|
|
||||
|
var bbacSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<BBAC_SE_DETAIL>>(jitRecords); |
||||
|
if (bbacSeDetails.Any()) |
||||
|
{ |
||||
|
await _bbacSeDetailRepository.InsertManyAsync(bbacSeDetails); |
||||
|
|
||||
|
if (syncPositionFlag != null) |
||||
|
{ |
||||
|
syncPositionFlag.Position = jitRecords.Last().UID.ToString(); |
||||
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
syncPositionFlag = new SyncPositionFlag() |
||||
|
{ |
||||
|
TableName = syncTableName, |
||||
|
Position = jitRecords.Last().UID.ToString() |
||||
|
}; |
||||
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private async Task SyncJisRecord() |
||||
|
{ |
||||
|
//同步表名称
|
||||
|
var syncTableName = "TM_BJBMPT_JIS_RECORD"; |
||||
|
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => true; |
||||
|
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName); |
||||
|
if (syncPositionFlag != null) |
||||
|
{ |
||||
|
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position); |
||||
|
} |
||||
|
|
||||
|
var jisRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD.Where(predicate).OrderBy(b => b.UID).ToList(); |
||||
|
|
||||
|
var bbacSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<BBAC_SE_DETAIL>>(jisRecords); |
||||
|
if (bbacSeDetails.Any()) |
||||
|
{ |
||||
|
await _bbacSeDetailRepository.InsertManyAsync(bbacSeDetails); |
||||
|
|
||||
|
if (syncPositionFlag != null) |
||||
|
{ |
||||
|
syncPositionFlag.Position = jisRecords.Last().UID.ToString(); |
||||
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
syncPositionFlag = new SyncPositionFlag() |
||||
|
{ |
||||
|
TableName = syncTableName, |
||||
|
Position = jisRecords.Last().UID.ToString() |
||||
|
}; |
||||
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel; |
||||
|
using DocumentFormat.OpenXml.Office2010.ExcelAc; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 发运同步配置
|
||||
|
/// </summary>
|
||||
|
public class SeSyncConfig |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 同步表名称
|
||||
|
/// </summary>
|
||||
|
public string SyncTableName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 同步发运主类型
|
||||
|
/// </summary>
|
||||
|
public EnumDeliverBjBmpBillType SyncDeliverBillType { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 同步发运子类型
|
||||
|
/// </summary>
|
||||
|
public List<EnumDeliverSubBillType> SyncDeliverSubBillTypes { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
public EnumBusinessType BusinessType { get; set; } |
||||
|
} |
@ -0,0 +1,122 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Expressions; |
||||
|
using System.Threading.Tasks; |
||||
|
using Coravel.Invocable; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using SettleAccount.Domain.BQ; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
||||
|
using Win.Sfs.Shared.RepositoryBase; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 直供件BBAC发运同步
|
||||
|
/// </summary>
|
||||
|
[AllowAnonymous] |
||||
|
[Route("api/settleaccount/[controller]/[action]")]
|
||||
|
public class ZhiGongBBACSeSyncAppService : JitSeSyncAppService |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 构造
|
||||
|
/// </summary>
|
||||
|
public ZhiGongBBACSeSyncAppService( |
||||
|
WMSBJBMPTDbContext wmsBJBMPTContext, |
||||
|
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
||||
|
INormalEfCoreRepository<PUB_SE_DETAIL, Guid> pubSeDetailRepository |
||||
|
) : base(wmsBJBMPTContext, syncPositionFlagRepository, pubSeDetailRepository) |
||||
|
{ |
||||
|
base.SeSyncConfigInfo = new SeSyncConfig() |
||||
|
{ |
||||
|
SyncTableName = "ZhiGongBBACSeSync", |
||||
|
SyncDeliverBillType = EnumDeliverBjBmpBillType.JIT直供件, |
||||
|
SyncDeliverSubBillTypes = new List<EnumDeliverSubBillType> |
||||
|
{ |
||||
|
EnumDeliverSubBillType.JIT直供件BBAC |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Jit发运数据同步
|
||||
|
/// </summary>
|
||||
|
public class JitSeSyncAppService : ApplicationService, IInvocable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// WMS数据上下文
|
||||
|
/// </summary>
|
||||
|
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 同步位置标记
|
||||
|
/// </summary>
|
||||
|
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Jit发运数据仓储
|
||||
|
/// </summary>
|
||||
|
private readonly INormalEfCoreRepository<PUB_SE_DETAIL, Guid> _pubSeDetailRepository; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 构造
|
||||
|
/// </summary>
|
||||
|
public JitSeSyncAppService( |
||||
|
WMSBJBMPTDbContext wmsBJBMPTContext, |
||||
|
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
||||
|
INormalEfCoreRepository<PUB_SE_DETAIL, Guid> pubSeDetailRepository) |
||||
|
{ |
||||
|
_wmsBJBMPTContext = wmsBJBMPTContext; |
||||
|
_syncPositionFlagRepository = syncPositionFlagRepository; |
||||
|
_pubSeDetailRepository = pubSeDetailRepository; |
||||
|
} |
||||
|
|
||||
|
public SeSyncConfig SeSyncConfigInfo { get; set; } |
||||
|
|
||||
|
[HttpPost] |
||||
|
public async Task Invoke() |
||||
|
{ |
||||
|
//同步表名称
|
||||
|
var syncTableName = SeSyncConfigInfo.SyncTableName; |
||||
|
//同步发运主类型
|
||||
|
var deliverBillType = SeSyncConfigInfo.SyncDeliverBillType; |
||||
|
//同步发运子类型
|
||||
|
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes; |
||||
|
|
||||
|
Expression<Func<TM_BJBMPT_OTHER_RECORD, bool>> predicate = (t) => t.DeliverBillType == deliverBillType && (!deliverSubBillTypes.Any() || deliverSubBillTypes.Contains(t.DeliverSubBillType)); |
||||
|
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName); |
||||
|
if (syncPositionFlag != null) |
||||
|
{ |
||||
|
Expression<Func<TM_BJBMPT_OTHER_RECORD, bool>> expression = (t) => t.UID > int.Parse(syncPositionFlag.Position); |
||||
|
var body = expression.Body; |
||||
|
predicate = Expression.Lambda<Func<TM_BJBMPT_OTHER_RECORD, bool>>(Expression.And(predicate.Body, body), predicate.Parameters); |
||||
|
} |
||||
|
|
||||
|
var jitRecords = _wmsBJBMPTContext.TM_BJBMPT_OTHER_RECORD.Where(predicate).OrderBy(b => b.UID)?.ToList(); |
||||
|
|
||||
|
var pubSeDetails = ObjectMapper.Map<List<TM_BJBMPT_OTHER_RECORD>, List<PUB_SE_DETAIL>>(jitRecords); |
||||
|
if (pubSeDetails.Any()) |
||||
|
{ |
||||
|
await _pubSeDetailRepository.InsertManyAsync(pubSeDetails); |
||||
|
|
||||
|
if (syncPositionFlag != null) |
||||
|
{ |
||||
|
syncPositionFlag.Position = jitRecords.Last().UID.ToString(); |
||||
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
syncPositionFlag = new SyncPositionFlag() |
||||
|
{ |
||||
|
TableName = syncTableName, |
||||
|
Position = jitRecords.Last().UID.ToString() |
||||
|
}; |
||||
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
||||
|
} |
||||
|
} |
||||
|
await Task.CompletedTask; |
||||
|
} |
||||
|
} |
@ -0,0 +1,91 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Jit(非Jis
|
||||
|
/// </summary>
|
||||
|
public class TM_BJBMPT_OTHER_RECORD |
||||
|
{ |
||||
|
[Key] |
||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] |
||||
|
public long UID { get; set; } |
||||
|
|
||||
|
[DisplayName("发货单号")] |
||||
|
public string BillNum { get; set; } |
||||
|
|
||||
|
[DisplayName("发货时间")] |
||||
|
public DateTime? BillTime { get; set; } |
||||
|
|
||||
|
[DisplayName("零件号")] |
||||
|
public string PartCode { get; set; } |
||||
|
|
||||
|
[DisplayName("批次")] |
||||
|
public string Batch { get; set; } |
||||
|
|
||||
|
[DisplayName("发货人")] |
||||
|
public string Oper { get; set; } |
||||
|
|
||||
|
[DisplayName("DN单据号")] |
||||
|
public string DnBillNum { get; set; } |
||||
|
|
||||
|
[DisplayName("DN单据时间")] |
||||
|
public DateTime? DnBillTime { get; set; } |
||||
|
|
||||
|
[DisplayName("DN单添加人")] |
||||
|
public string DnOper { get; set; } |
||||
|
|
||||
|
[DisplayName("交付索引")] |
||||
|
public string DeliveryIndex { get; set; } |
||||
|
|
||||
|
[DisplayName("客户")] |
||||
|
public string CustId { get; set; } |
||||
|
|
||||
|
[DisplayName("发货仓库")] |
||||
|
public string DeliveryHose { get; set; } |
||||
|
|
||||
|
[DisplayName("来源库位")] |
||||
|
public string FromLocCode { get; set; } |
||||
|
|
||||
|
[DisplayName("来源仓库")] |
||||
|
public string FromHose { get; set; } |
||||
|
|
||||
|
[DisplayName("来源ERP库存")] |
||||
|
public string FromErpLocCode { get; set; } |
||||
|
|
||||
|
[DisplayName("目标库位")] |
||||
|
public string ToLocCode { get; set; } |
||||
|
|
||||
|
[DisplayName("目标仓库")] |
||||
|
public string ToHose { get; set; } |
||||
|
|
||||
|
[DisplayName("目标Erp库位")] |
||||
|
public string ToErpLocCode { get; set; } |
||||
|
|
||||
|
[DisplayName("数量")] |
||||
|
public decimal? Qty { get; set; } |
||||
|
|
||||
|
//[DisplayName("单据类型")]
|
||||
|
//public EnumBillType BillType { get; set; }
|
||||
|
|
||||
|
//[DisplayName("子单据类型")]
|
||||
|
//public EnumSubBillType SubBillType { get; set; }
|
||||
|
|
||||
|
[DisplayName("事务类型")] |
||||
|
public EnumDelTransType TransType { get; set; } |
||||
|
|
||||
|
[DisplayName("发运主类型")] |
||||
|
public EnumDeliverBjBmpBillType DeliverBillType { get; set; } |
||||
|
|
||||
|
[DisplayName("发运子类型")] |
||||
|
public EnumDeliverSubBillType DeliverSubBillType { get; set; } |
||||
|
|
||||
|
//[DisplayName("业务类型")]
|
||||
|
//public EnumProTpe ProType { get; set; }
|
||||
|
|
||||
|
[DisplayName("备注")] |
||||
|
public string Remark { get; set; } |
||||
|
} |
Loading…
Reference in new issue