|
|
@ -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<BBAC_SEC_DETAIL, Guid> _bbacSecRepository; |
|
|
|
protected readonly INormalEfCoreRepository<HBPO_SEC_DETAIL, Guid> _hbpoSecRepository; |
|
|
|
protected readonly INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> _pubSecRepository; |
|
|
|
protected readonly INormalEfCoreRepository<BBAC_PD_DETAIL, Guid> _bbacRepository; |
|
|
|
protected readonly INormalEfCoreRepository<HBPO_PD_DETAIL, Guid> _hbpoRepository; |
|
|
|
protected readonly INormalEfCoreRepository<PUB_PD_DETAIL, Guid> _pubRepository; |
|
|
|
protected readonly INormalEfCoreRepository<CodeSetting, Guid> _codesetRepository; |
|
|
|
protected readonly INormalEfCoreRepository<VmiLog, Guid> _vmiRepository; |
|
|
|
|
|
|
|
protected readonly SettleAccountDbContext _dbcontext; |
|
|
|
|
|
|
|
public PendingDeductionService( |
|
|
|
INormalEfCoreRepository<BBAC_SEC_DETAIL, Guid> bbacSecRepository, |
|
|
|
INormalEfCoreRepository<HBPO_SEC_DETAIL, Guid> hbpoSecRepository, |
|
|
|
INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> pubSecRepository, |
|
|
|
INormalEfCoreRepository<BBAC_PD_DETAIL, Guid> bbacRepository, |
|
|
|
INormalEfCoreRepository<HBPO_PD_DETAIL, Guid> hbpoRepository, |
|
|
|
INormalEfCoreRepository<PUB_PD_DETAIL, Guid> pubRepository, |
|
|
|
INormalEfCoreRepository<CodeSetting, Guid> codesetRepository, |
|
|
|
INormalEfCoreRepository<VmiLog, Guid> 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<string> exportName, List<CustomCondition> 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<CodeSetting>().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<BBAC_PD_DETAIL>().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisBBAC);//jis
|
|
|
|
Sync(jisdetail.ToList(),isout=="out"?true:false); |
|
|
|
var mdetail = _dbcontext.Set<BBAC_PD_DETAIL>().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<HBPO_PD_DETAIL>().Where(p => list.Contains(p.BillNum) && p.BusinessType== EnumBusinessType.JisHBPO).ToList(); |
|
|
|
Sync(detailist, isout == "out" ? true : false); |
|
|
|
var mdetail = _dbcontext.Set<HBPO_PD_DETAIL>().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<PUB_PD_DETAIL>().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<T>(List<T> p_ls) where T : PD_BASE,new() |
|
|
|
public void Sync<T>(List<T> 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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|