diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPOSeSyncAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPOSeSyncAppService.cs index 298d8f4b..6ca8f350 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPOSeSyncAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPOSeSyncAppService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Coravel.Invocable; using Microsoft.AspNetCore.Authorization; @@ -8,6 +9,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using SettleAccount.Domain.BQ; using Volo.Abp.Application.Services; +using Win.Sfs.SettleAccount.Entities.BQ.Syncs; using Win.Sfs.SettleAccount.Entities.BQ.Vmi; using Win.Sfs.SettleAccount.Entities.Prices; using Win.Sfs.SettleAccount.EntityFrameworkCore; @@ -27,6 +29,11 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService /// private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; + /// + /// 同步位置标记 + /// + private readonly INormalEfCoreRepository _syncPositionFlagRepository; + /// /// HBPO发运数据仓储 /// @@ -37,9 +44,11 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService /// public HBPOSeSyncAppService( WMSBJBMPTDbContext wmsBJBMPTContext, + INormalEfCoreRepository syncPositionFlagRepository, INormalEfCoreRepository hbpoSeDetailRepository) { _wmsBJBMPTContext = wmsBJBMPTContext; + _syncPositionFlagRepository = syncPositionFlagRepository; _hbpoSeDetailRepository = hbpoSeDetailRepository; } @@ -53,16 +62,8 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService [HttpPost] public async Task Invoke() { - //using var dbContext = new WMSBJBMPTDbContext(); - var TM_BJBMPT_JIT_RECORDs = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD - .Where(b => b.UID > 3) - .OrderBy(b => b.BillTime) - .ToList(); - - var hbpoSeDetails = ObjectMapper.Map, List>(TM_BJBMPT_JIT_RECORDs); - - _hbpoSeDetailRepository.InsertManyAsync(hbpoSeDetails); - + //await SyncJitRecord(); + //await SyncJisRecord(); //if (!dbContext.GetService().Exists() && dbContext.Database.EnsureCreated()) //{ // this._balanceRepository.AsNoTracking().ForEachAsync(o => @@ -109,4 +110,83 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable //IJobService Console.WriteLine($"{this.GetType().FullName}执行了"); } + /// + /// 同步JitRecord + /// + /// + private async Task SyncJitRecord() + { + //同步表名称 + var syncTableName = "TM_BJBMPT_JIT_RECORD"; + Expression> predicate = (t) => true; + var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName); + if (syncPositionFlag != null) + { + predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position); + } + + var jitRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD + .Where(predicate) + .OrderBy(b => b.UID) + .ToList(); + + var hbpoSeDetails = ObjectMapper.Map, List>(jitRecords); + if (hbpoSeDetails.Any()) + { + await _hbpoSeDetailRepository.InsertManyAsync(hbpoSeDetails); + + 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> 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 hbpoSeDetails = ObjectMapper.Map, List>(jisRecords); + if (hbpoSeDetails.Any()) + { + await _hbpoSeDetailRepository.InsertManyAsync(hbpoSeDetails); + + 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); + } + } + } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index 1f0c5b54..b2d1fba8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -58,7 +58,7 @@ using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using SettleAccount.Domain.BQ; using System.ComponentModel.DataAnnotations; using System.Reflection; -using Win.Sfs.SettleAccount.Entities.BQ; +using Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount { @@ -1029,15 +1029,26 @@ namespace Win.Sfs.SettleAccount private void CreateMapSeSync() { CreateMap() - .ForMember(x => x.SeqNumber, y => y.MapFrom(d => d.JISNum)) - .ForMember(x => x.AssemblyCode, y => y.MapFrom(d => d.RealPartCode)) - .ForMember(x => x.InjectionCode, y => y.MapFrom(d => d.DeliverCode)) - .ForMember(x => x.BeginDate, y => y.MapFrom(d => d.BillTime)) - .ForMember(x => x.ShippingDate, y => y.MapFrom(d => d.BillTime)) - .ForMember(x => x.WmsBillNum, y => y.MapFrom(d => d.BillNum)) - .ForMember(x => x.LU, y => y.MapFrom(d => d.PartCode)) - .ForMember(x => x.PN, y => y.MapFrom(d => d.VinCode)) - .ForMember(x => x.Qty, y => y.MapFrom(d => d.Qty)); + .ForMember(x => x.SeqNumber, y => y.MapFrom(d => d.JISNum)) + .ForMember(x => x.AssemblyCode, y => y.MapFrom(d => d.RealPartCode)) + .ForMember(x => x.InjectionCode, y => y.MapFrom(d => d.DeliverCode)) + .ForMember(x => x.BeginDate, y => y.MapFrom(d => d.BillTime)) + .ForMember(x => x.ShippingDate, y => y.MapFrom(d => d.BillTime)) + .ForMember(x => x.WmsBillNum, y => y.MapFrom(d => d.BillNum)) + .ForMember(x => x.LU, y => y.MapFrom(d => d.PartCode)) + .ForMember(x => x.PN, y => y.MapFrom(d => d.VinCode)) + .ForMember(x => x.Qty, y => y.MapFrom(d => d.Qty)); + + CreateMap() + .ForMember(x => x.SeqNumber, y => y.MapFrom(d => d.JISNum)) + .ForMember(x => x.AssemblyCode, y => y.MapFrom(d => d.RealPartCode)) + .ForMember(x => x.InjectionCode, y => y.MapFrom(d => d.DeliverCode)) + .ForMember(x => x.BeginDate, y => y.MapFrom(d => d.BillTime)) + .ForMember(x => x.ShippingDate, y => y.MapFrom(d => d.BillTime)) + .ForMember(x => x.WmsBillNum, y => y.MapFrom(d => d.BillNum)) + .ForMember(x => x.LU, y => y.MapFrom(d => d.PartCode)) + .ForMember(x => x.PN, y => y.MapFrom(d => d.VinCode)) + .ForMember(x => x.Qty, y => y.MapFrom(d => d.Qty)); } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/SyncPositionFlag.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/SyncPositionFlag.cs index c918bed8..f5d869f4 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/SyncPositionFlag.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/SyncPositionFlag.cs @@ -20,4 +20,9 @@ public class SyncPositionFlag : AuditedAggregateRoot /// [Display(Name = "位置")] public string Position { get; set; } + + /// + /// 构造 + /// + public SyncPositionFlag() { } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs new file mode 100644 index 00000000..c3cbcabc --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs @@ -0,0 +1,104 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; + +public class TM_BJBMPT_JIS_RECORD +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int UID { get; set; } + + [DisplayName("JIS单据编号")] + public string JISNum { get; set; } + + [DisplayName("发货时间")] + public DateTime? BillTime { get; set; } + + [DisplayName("发货人")] + public string Oper { get; set; } + + [DisplayName("JIS排序单号")] + public string OrderNum { get; set; } + + [DisplayName("订单序号")] + public string Seq { get; set; } + + [DisplayName("JIS实际生产码")] + public string RealCode { get; set; } + + [DisplayName("订单生产码")] + public string VinCode { get; set; } + + [DisplayName("JIS生产码类型")] + public string CodeType { get; set; } + + [DisplayName("订单零件号")] + public string PartCode { get; set; } + + [DisplayName("数量")] + public decimal? Qty { get; set; } + + [DisplayName("发货单号")] + public string BillNum { get; set; } + + public string MESConfigCode { get; set; } + + [DisplayName("来源库位")] + public string FromLoc { get; set; } + + [DisplayName("目标库位")] + public string ToLoc { get; set; } + + public string RealPartCode { get; set; } + + public string Batch { get; set; } + + [DisplayName("参照订单生产码")] + public string RefVinCode { get; set; } + + //[DisplayName("单据类型")] + //public EnumBillType BillType { get; set; } + + //[DisplayName("子单据类型")] + //public EnumSubBillType SubBillType { get; set; } + + [DisplayName("单据性质")] + public string BillCharacter { get; set; } + + public int? TransType { get; set; } + + public int? DeliverBillType { get; set; } + + public int? DeliverSubBillType { get; set; } + + [DisplayName("发货关联单号")] + public string RefBillNum { get; set; } + + [DisplayName("Erp目标库位")] + public string ErpToLoc { get; set; } + + [DisplayName("原生产码")] + public string OrigiCode { get; set; } + + [DisplayName("备注")] + public string Remark { get; set; } + + [DisplayName("塑件唯一码")] + public string UniqueCode { get; set; } + + [DisplayName("PJS顺序号")] + public string PjsNum { get; set; } + + [DisplayName("虚拟小总成")] + public string MatchNumber { get; set; } + + //[DisplayName("业务类型")] + //public EnumProTpe ProType { get; set; } + + public string DeliverCode { get; set; } + + public string Position { get; set; } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/TM_BJBMPT_JIT_RECORD.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs similarity index 98% rename from code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/TM_BJBMPT_JIT_RECORD.cs rename to code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs index c7a13008..4c9fd6fb 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/TM_BJBMPT_JIT_RECORD.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs @@ -3,7 +3,8 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace Win.Sfs.SettleAccount.Entities.BQ; +namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; + public class TM_BJBMPT_JIT_RECORD { [Key] diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/WMSBJBMPTDbContext.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/WMSBJBMPTDbContext.cs index 007f55c7..bbd0ae9a 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/WMSBJBMPTDbContext.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/WMSBJBMPTDbContext.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore; using Volo.Abp.Data; -using Win.Sfs.SettleAccount.Entities.BQ; +using Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount.EntityFrameworkCore; @@ -8,6 +8,7 @@ namespace Win.Sfs.SettleAccount.EntityFrameworkCore; public class WMSBJBMPTDbContext : DbContext { public DbSet TM_BJBMPT_JIT_RECORD { get; set; } + public DbSet TM_BJBMPT_JIS_RECORD { get; set; } public WMSBJBMPTDbContext() {