diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs index 687a26d4..9e1a71f6 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs @@ -20,6 +20,7 @@ using Win.Sfs.SettleAccount.Entities.BQ.Syncs; using Win.Sfs.SettleAccount.Entities.BQ.Vmi; using Win.Sfs.Shared.RepositoryBase; using Win.Sfs.SettleAccount.Entities.TaskJobs; +using Volo.Abp.Uow; namespace Win.Sfs.SettleAccount.Entities.BQ { @@ -43,24 +44,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { _service = service; } - + public override async Task ApprovalPassed(List p_list) { var detailist = _detailRepository.Where(p => p_list.Contains(p.BillNum)).ToList(); - - List customConditionList = new List(); - customConditionList.Add(new CustomCondition() { Name = "BillNumList", Value =string.Join(",",p_list) }); customConditionList.Add(new CustomCondition() { Name = "Type", Value = EnumBusinessType.JisBBAC.ToString() }); - + customConditionList.Add(new CustomCondition() { Name = "IsOut", Value ="out"}); var _taskid = await _service.ExportEnqueueAsync("BBAC待扣减任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) => { }); return _taskid; - - - } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs index f655d93c..d6058d13 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs @@ -8,123 +8,62 @@ using System.Threading.Tasks; using EFCore.BulkExtensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Nito.AsyncEx; +using NPOI.SS.Formula.Functions; using SettleAccount.Bases; using SettleAccount.Domain.BQ; using TaskJob.EventArgs; using TaskJob.Interfaces; +using Volo.Abp.Application.Services; using Volo.Abp.DependencyInjection; +using Volo.Abp.Uow; using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Vmi; using Win.Sfs.SettleAccount.Entities.CodeSettings; using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; -public class PendingDeductionService : ITransientDependency, IExportJob +public class PendingDeductionService : ApplicationService, ITransientDependency, IExportJob { - protected readonly VmiAppService _vimservice; - protected readonly INormalEfCoreRepository _bbacSecRepository; - protected readonly INormalEfCoreRepository _hbpoSecRepository; - protected readonly INormalEfCoreRepository _pubSecRepository; - protected readonly INormalEfCoreRepository _bbacRepository; - protected readonly INormalEfCoreRepository _hbpoRepository; - protected readonly INormalEfCoreRepository _pubRepository; - protected readonly INormalEfCoreRepository _codesetRepository; - protected readonly INormalEfCoreRepository _vmiRepository; + + protected readonly SettleAccountDbContext _dbcontext; public PendingDeductionService( - INormalEfCoreRepository bbacSecRepository, - INormalEfCoreRepository hbpoSecRepository, - INormalEfCoreRepository pubSecRepository, - INormalEfCoreRepository bbacRepository, - INormalEfCoreRepository hbpoRepository, - INormalEfCoreRepository pubRepository, - INormalEfCoreRepository codesetRepository, - INormalEfCoreRepository vmiRepository, - VmiAppService vimservice + SettleAccountDbContext dbcontext + + ) { - _hbpoRepository = hbpoRepository; - _bbacRepository= bbacRepository; - _pubRepository= pubRepository; - _bbacSecRepository = bbacSecRepository; - _hbpoSecRepository= hbpoSecRepository; - _pubSecRepository= pubSecRepository; - _vimservice =vimservice; - _codesetRepository = codesetRepository; - _vmiRepository = vmiRepository; + _dbcontext = dbcontext; + } public string ExportFile(Guid id, List exportName, List property) { + var billList = property.Where(p => p.Name == "BillNumList").FirstOrDefault().Value; var type = property.Where(p => p.Name == "Type").FirstOrDefault().Value; + var isout = property.Where(p => p.Name == "IsOut").FirstOrDefault().Value; var list = billList.Split(","); - var projectList = _codesetRepository.Where(p => p.Project == "库位"); + var projectList = _dbcontext.Set().Where(p => p.Project == "库位"); if (type == "JisBBAC") { - var jisdetail = _bbacRepository.Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisBBAC);//jis - Sync(jisdetail.ToList()); - var mdetail = _bbacRepository.Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianBBAC);//买单件 - Sync(mdetail.ToList()); + var jisdetail = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisBBAC);//jis + Sync(jisdetail.ToList(),isout=="out"?true:false); + var mdetail = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianBBAC);//买单件 + Sync(mdetail.ToList(), isout == "out" ? true : false); } else if (type == "JisHBPO") { - var detailist = _hbpoRepository.Where(p => list.Contains(p.BillNum) && p.BusinessType== EnumBusinessType.JisHBPO).ToList(); - Sync(detailist); - var mdetail = _bbacRepository.Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianHBPO);//买单件 - Sync(mdetail.ToList()); + var detailist = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType== EnumBusinessType.JisHBPO).ToList(); + Sync(detailist, isout == "out" ? true : false); + var mdetail = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianHBPO);//买单件 + Sync(mdetail.ToList(),isout == "out" ? true : false); } else { - var detailist = _hbpoRepository.Where(p => list.Contains(p.BillNum)).ToList(); - Sync(detailist); - - ////switch (type) - ////{ - //// case "ZhiGongJianBBAC": - //// if (detailist != null && detailist.Count > 0) - //// { - - //// } - //// break; - //// case "ZhiGongJianHBPO": - //// if (detailist != null && detailist.Count > 0) - //// { - - //// } - //// break; - //// case "MaiDanJianBBAC": - //// if (detailist != null && detailist.Count > 0) - //// { - - //// } - //// break; - //// case "MaiDanJianHBPO": - //// if (detailist != null && detailist.Count > 0) - //// { - - //// } - //// break; - //// case "BeiJian": - //// if (detailist != null && detailist.Count > 0) - //// { - - //// } - //// break; - //// case "YinDuJian": - //// if (detailist != null && detailist.Count > 0) - //// { - - //// } - //// break; - ////} - //if (detailist != null && detailist.Count > 0) - //{ - // foreach (var itm in detailist) - // { - - // } - //} + var detailist = _dbcontext.Set().Where(p => list.Contains(p.BillNum)).ToList(); + Sync(detailist, isout == "out" ? true : false); + } return id.ToString(); } @@ -144,42 +83,91 @@ public class PendingDeductionService : ITransientDependency, IExportJob return pageCount; } - public void Sync(List p_ls) where T : PD_BASE,new() + public void Sync(List p_ls,bool flag=true) where T : PD_BASE,new() { - var query = from itm in p_ls - select new + select new VmiLog() { + BillTime = DateTime.Now, ChangedTime = DateTime.Now, Qty = itm.Qty, - DeliverTime = itm.CreationTime, + RealPartCode=itm.RELU, + + RealCode=itm.RELU, + LogType = Entities.BQ.Vmi.VmiLogType.Type200, - ChangedQty = itm.Qty, + ChangedQty =(flag==true)? -itm.Qty:itm.Qty, ChangedType = VmiType.Out, //SubBillType = EnumDeliverSubBillType.小件BBAC, //BillType = EnumDeliverBjBmpBillType.JIS件, - PartCode = itm.LU, + CustPartCode = itm.LU, SettlementVinCode = itm.PN, - PartCode2 = itm.LU, - CustomerPartCode = string.IsNullOrEmpty(itm.Extend4) ? string.Empty : itm.Extend4, + VinCode = itm.PN, OrderNum = itm.GroupNum, - ErpToLoc = itm.Extend2, + ErpToLoc = string.IsNullOrEmpty(itm.Extend2)?string.Empty:itm.Extend2, }; var ls = query.ToList(); - if (ls != null && ls.Count > 0) + + + + + var _first= p_ls.FirstOrDefault(); + + + + + + using (var transaction =_dbcontext.Database.BeginTransaction()) { - var count = CalculatePageCount(ls.Count, 2000); - for (int pagenumber = 0; pagenumber < count; pagenumber++) + + try + { + // 执行批量数据操作 + if (ls != null && ls.Count > 0) + { + var count = CalculatePageCount(ls.Count, 2000); + for (int pagenumber = 0; pagenumber < count; pagenumber++) + { + ls = GetPagedData(ls, pagenumber, 2000); + foreach (var item in ls) + { + item.SetId(GuidGenerator.Create()); + } + + _dbcontext.BulkInsert(ls); + Task.Delay(500); + } + } + + // 提交事务 + transaction.Commit(); + } + catch (Exception) { - ls = GetPagedData(ls, pagenumber, 2000); - _vmiRepository.DbContext.BulkInsert(ls); - - Task.Delay(500); + // 回滚事务 + transaction.Rollback(); + throw; } } + + + + + + + + + + + + + + ; + + } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs index 71094267..2e394214 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs @@ -102,22 +102,6 @@ namespace Win.Sfs.SettleAccount }; return accesor; }); - //context.Services.AddTransient(implementationFactory => - //{ - // Func accesor = key => - // { - // if (key.Equals(typeof(PendingDeductionService).FullName)) - // { - // return implementationFactory.GetService(); - // } - // else - // { - // throw new ArgumentException($"Not Support key:{key}"); - // } - - // }; - // return accesor; - //}); } private static void ConfigureJson(ServiceConfigurationContext context) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs index 1262de80..56f1d471 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs @@ -407,10 +407,6 @@ namespace SettleAccount.Bases protected SA_CAN_BASE() { } public SA_CAN_BASE(Guid id) : base(id) { Id = id; } - - - - /// /// 期间 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SE_EDI.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SE_EDI.cs index 4aa313eb..a23b7344 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SE_EDI.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SE_EDI.cs @@ -38,10 +38,12 @@ public class BBAC_SE_EDI:FullAuditedAggregateRoot [Display(Name = "工厂")] public string Site { get; set; } - + [Display(Name = "生产码类型")] public string Extend1 { set; get; } public string Extend2 { set; get; } + [Display(Name = "生产码序列号")] public string Extend3 { set; get; } + [Display(Name ="车型")] public string Extend4 { set; get; } /// @@ -50,6 +52,11 @@ public class BBAC_SE_EDI:FullAuditedAggregateRoot [Display(Name = "是否有发运数据")] public bool IsHaveSeData { get; set; } + [Display(Name ="生产线")] + public string LineStationCode { set; get; } + + + public BBAC_SE_EDI() { } public BBAC_SE_EDI(Guid guid, string keyCode, string version, string lU, string pN, string seqNumber, string assemblyCode, string injectionCode, decimal qty, DateTime beginDate diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs index 0c2ffb05..ed9ca806 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs @@ -94,6 +94,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers invbillnum: string.Empty, partcode:itm.PartCode ); + _detailEntity.RealPartCode = itm.RealPartCode; _entityList.Add(_detailEntity); } await _repository.DbContext.BulkDeleteAsync(p_list); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_NOT_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_NOT_SA_MNG.cs index 356ae78e..626bf387 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_NOT_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_NOT_SA_MNG.cs @@ -98,6 +98,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers invbillnum: string.Empty, partcode:itm.PartCode ); + _detailEntity.RealPartCode = itm.RealPartCode; _entityList.Add(_detailEntity); } await _notRepository.DbContext.BulkDeleteAsync(p_list); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs index ae0214a1..daa09853 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs @@ -551,7 +551,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers );//厂内实际零件号 - detail.RELU = itm.RealPartCode;//厂内替换零件号 + detail.RELU = string.IsNullOrEmpty(itm.RealPartCode) ? itm.PartCode : itm.RealPartCode;//厂内替换零件号 detail.Extend2 = itm.ErpLoc;//ERP库位 bbacDetail.Add(detail); } @@ -700,7 +700,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers ); - entity.RELU = itm.RealPartCode;//厂内替换零件号 + entity.RELU = string.IsNullOrEmpty(itm.RealPartCode) ? itm.PartCode : itm.RealPartCode;//厂内替换零件号 entity.Extend2 = itm.ErpLoc;//ERP库位 bbacDetail.Add(entity @@ -852,7 +852,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers ); - entity.RELU = itm.RealPartCode;//厂内替换零件号 + entity.RELU =string.IsNullOrEmpty(itm.RealPartCode)?itm.PartCode:itm.RealPartCode;//厂内替换零件号 entity.Extend2 = itm.ErpLoc;//ERP库位 bbacDetail.Add(entity ); @@ -1449,16 +1449,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers if (salist.Count > 0) { - //foreach (var itm in invoiceMap)//分组影响和 - //{ - // var key = itm.Key;//发票票号 - // var ls = itm.Value;//结算分组号列表 - - - - // string str = $" EXEC [p_Invoice_generation_change] @invbillnum = {"'" + key + "'"},@groupNum = {"'" + string.Join(",", ls) + "'"},@businessType = NULL"; - // await _repository.DbContext.Database.ExecuteSqlRawAsync(str); - //} + await _repository.DbContext.BulkUpdateAsync(salist,new BulkConfig() { BatchSize=10000 }); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs index b47a54bd..484a3b52 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs @@ -124,7 +124,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers partcode: itm.PartCode, pobillnum:string.Empty ); - + _detailEntity.RealPartCode = itm.RealPartCode; _entityList.Add(_detailEntity); } await _repository.DbContext.BulkDeleteAsync(p_list); @@ -164,7 +164,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers partcode: itm.PartCode, pobillnum: string.Empty ); - + _detailEntity.RealPartCode =string.IsNullOrEmpty(itm.RealPartCode)?itm.PartCode:itm.RealPartCode; _entityList.Add(_detailEntity); } // _repository.DbContext.Database.BeginTransaction(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs index b353b069..cceb4d34 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs @@ -12,7 +12,7 @@ public class VmiLog : VmiBalanceBase { ConcurrencyStamp = Guid.NewGuid().ToString("N"); } - + public VmiLog(Guid id) : base(id) { ConcurrencyStamp = Guid.NewGuid().ToString("N"); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Code/CodeSettingRepository.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Code/CodeSettingRepository.cs index 59b0ce0a..08de90a5 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Code/CodeSettingRepository.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Code/CodeSettingRepository.cs @@ -1,4 +1,4 @@ -using EFCore.BulkExtensions; +using EFCore.BulkExtensions; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -13,7 +13,7 @@ using Win.Sfs.SettleAccount.Entities.Invoices; namespace Win.Sfs.SettleAccount.Repository.Code { - public class CodeSettingRepository: EfCoreRepository, ITransientDependency + public class CodeSettingRepository:EfCoreRepository, ITransientDependency { public CodeSettingRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { @@ -35,6 +35,14 @@ namespace Win.Sfs.SettleAccount.Repository.Code } return _list; } + + + + } + + + + } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs index c284f55f..a15c9ff9 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs @@ -439,6 +439,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// public virtual INVOICE_GRP GetInvoice(string inv_bill) { + return DbConnection.QueryFirst(string.Format("select * from set_INVOICE_GRP where InvbillNum='{0}'",inv_bill)); }