学 赵
1 year ago
11 changed files with 543 additions and 26 deletions
@ -0,0 +1,374 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using EFCore.BulkExtensions; |
||||
|
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.Emailing; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; |
||||
|
using Win.Sfs.SettleAccount.Entities.CodeSettings; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
||||
|
{ |
||||
|
public class PendingDeductionDelService : ApplicationService, ITransientDependency, IExportJob |
||||
|
{ |
||||
|
|
||||
|
protected readonly SettleAccountDbContext _dbcontext; |
||||
|
|
||||
|
private readonly IEmailSender _emailSender; |
||||
|
|
||||
|
public PendingDeductionDelService( |
||||
|
SettleAccountDbContext dbcontext, |
||||
|
IEmailSender emailSender |
||||
|
) |
||||
|
{ |
||||
|
_emailSender = emailSender; |
||||
|
_dbcontext = dbcontext; |
||||
|
|
||||
|
} |
||||
|
[UnitOfWork(false)] |
||||
|
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 email = string.Empty; |
||||
|
// property.Where(p => p.Name == "CurrentUserEmail").FirstOrDefault().Value;
|
||||
|
var list = billList.Split(","); |
||||
|
var projectList = _dbcontext.Set<CodeSetting>().Where(p => p.Project == "库位"); |
||||
|
if (type == "JisBBAC" || type == "ZhiGongJianBBAC" || type == "MaiDanJianBBAC" || type == "BeiJian") |
||||
|
{ |
||||
|
var jisdetail = _dbcontext.Set<BBAC_PD_DETAIL>().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisBBAC);//jis
|
||||
|
if (jisdetail != null && jisdetail.Count() > 0) |
||||
|
{ |
||||
|
foreach (var itm in jisdetail) |
||||
|
{ |
||||
|
if (itm.Site == "1040" && string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC").Description; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC顺义").Description; |
||||
|
} |
||||
|
} |
||||
|
Sync(jisdetail.ToList(), EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
var mdetail = _dbcontext.Set<BBAC_PD_DETAIL>().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianBBAC);//买单件
|
||||
|
if (mdetail != null && mdetail.Count() > 0) |
||||
|
{ |
||||
|
foreach (var itm in jisdetail) |
||||
|
{ |
||||
|
if (itm.Site == "1040" && string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC").Description; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC顺义").Description; |
||||
|
} |
||||
|
} |
||||
|
Sync(mdetail.ToList(), EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
var detailist1 = _dbcontext.Set<PUB_PD_DETAIL>().Where(p => list.Contains(p.BillNum)).ToList(); |
||||
|
|
||||
|
if (detailist1.Count > 0) |
||||
|
{ |
||||
|
var zgbbaclist = detailist1.Where(p => p.BusinessType == EnumBusinessType.ZhiGongJianBBAC).ToList(); |
||||
|
foreach (var itm in zgbbaclist) |
||||
|
{ |
||||
|
if (itm.Site == "1040" && string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "ZhiGongJianBBAC").Description; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "ZhiGongJianBBAC顺义").Description; |
||||
|
} |
||||
|
} |
||||
|
Sync(zgbbaclist, EnumDeliverBjBmpBillType.JIT直供件, email, isout == "out" ? true : false); |
||||
|
var ydlist = detailist1.Where(p => p.BusinessType == EnumBusinessType.YinDuJian).ToList(); |
||||
|
if (ydlist.Count > 0) |
||||
|
{ |
||||
|
foreach (var itm in zgbbaclist) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "YinDuJian").Description; |
||||
|
} |
||||
|
} |
||||
|
Sync(ydlist, EnumDeliverBjBmpBillType.印度件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
var bjlist = detailist1.Where(p => p.BusinessType == EnumBusinessType.BeiJian).ToList(); |
||||
|
if (bjlist.Count > 0) |
||||
|
{ |
||||
|
foreach (var itm in bjlist) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "BeiJian").Description; |
||||
|
} |
||||
|
} |
||||
|
Sync(bjlist, EnumDeliverBjBmpBillType.北汽4S备件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
else if (type == "JisHBPO" || type == "ZhiGongJianHBPO" || type == "MaiDanJianHBPO") |
||||
|
{ |
||||
|
var detailist = _dbcontext.Set<HBPO_PD_DETAIL>().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisHBPO).ToList(); |
||||
|
foreach (var itm in detailist) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = "CC017"; |
||||
|
} |
||||
|
} |
||||
|
if(detailist.Count>0) |
||||
|
{ |
||||
|
Sync(detailist, EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
|
||||
|
var mdetail = _dbcontext.Set<HBPO_PD_DETAIL>().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianHBPO).ToList();//买单件
|
||||
|
foreach (var itm in mdetail) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = "CC017"; |
||||
|
} |
||||
|
} |
||||
|
if (mdetail.Count > 0) |
||||
|
{ |
||||
|
Sync(mdetail.ToList(), EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
|
||||
|
var detailist1 = _dbcontext.Set<PUB_PD_DETAIL>().Where(p => list.Contains(p.BillNum)).ToList(); |
||||
|
var zgbbaclist = detailist1.Where(p => p.BusinessType == EnumBusinessType.ZhiGongJianHBPO).ToList(); |
||||
|
foreach (var itm in zgbbaclist) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(itm.Extend2)) |
||||
|
{ |
||||
|
itm.Extend2 = "CC017"; |
||||
|
} |
||||
|
} |
||||
|
if (zgbbaclist.Count > 0) |
||||
|
{ |
||||
|
|
||||
|
Sync(zgbbaclist, EnumDeliverBjBmpBillType.JIT直供件, email, isout == "out" ? true : false); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
return id.ToString(); |
||||
|
} |
||||
|
//public List<T> GetPagedData<T>(List<T> dataList, int pageNumber, int pageSize)
|
||||
|
//{
|
||||
|
// int startIndex = (pageNumber - 1) * pageSize;
|
||||
|
|
||||
|
// return dataList.Skip(startIndex).Take(pageSize).ToList();
|
||||
|
//}
|
||||
|
//public int CalculatePageCount(int totalCount, int pageSize)
|
||||
|
//{
|
||||
|
// int pageCount = totalCount / pageSize;
|
||||
|
// if (totalCount % pageSize != 0)
|
||||
|
// {
|
||||
|
// pageCount += 1;
|
||||
|
// }
|
||||
|
// return pageCount;
|
||||
|
//}
|
||||
|
[UnitOfWork(false)] |
||||
|
public void Sync<T>(List<T> p_ls, EnumDeliverBjBmpBillType bussinessType, string p_email, bool flag = true) where T : PD_BASE, new() |
||||
|
{ |
||||
|
var query = from itm in p_ls |
||||
|
select new VmiLog() |
||||
|
{ |
||||
|
|
||||
|
CodeType = string.Empty, |
||||
|
BillTime = DateTime.Now, |
||||
|
ChangedTime = DateTime.Now, |
||||
|
Qty = itm.Qty, |
||||
|
RealPartCode = itm.RELU,//替换件 结算数据 RealPartCode->RELU
|
||||
|
RealCode = itm.RELU, |
||||
|
LogType = Entities.BQ.Vmi.VmiLogType.Type200, |
||||
|
ChangedQty = (flag == true) ? -itm.Qty : itm.Qty, |
||||
|
ChangedType = VmiType.Out, |
||||
|
//SubBillType = EnumDeliverSubBillType.小件BBAC,
|
||||
|
//BillType = EnumDeliverBjBmpBillType.JIS件,
|
||||
|
CustPartCode = itm.LU, |
||||
|
SettlementVinCode = itm.PN, |
||||
|
DeliverBillType = bussinessType, |
||||
|
VinCode = itm.PN, |
||||
|
OrderNum = itm.GroupNum, |
||||
|
ErpToLoc = itm.Extend2, //寄售库
|
||||
|
}; |
||||
|
var ls = query.ToList(); |
||||
|
foreach (var itm in ls) |
||||
|
{ |
||||
|
itm.SetId(GuidGenerator.Create()); |
||||
|
} |
||||
|
var _first = p_ls.FirstOrDefault(); |
||||
|
bool issucess = true; |
||||
|
using (var transaction = _dbcontext.Database.BeginTransaction()) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
// 执行批量数据操作
|
||||
|
if (ls != null && ls.Count > 0) |
||||
|
{ |
||||
|
var messagelist = new List<VmiMessage>(); |
||||
|
foreach (var item in ls) |
||||
|
{ |
||||
|
var message = new VmiMessage |
||||
|
{ |
||||
|
Message = System.Text.Json.JsonSerializer.Serialize(item), |
||||
|
}; |
||||
|
messagelist.Add(message); |
||||
|
} |
||||
|
_dbcontext.BulkInsert(messagelist); |
||||
|
_dbcontext.BulkInsert(ls, new BulkConfig() { }); |
||||
|
var billList = p_ls.Select(p => p.BillNum).Distinct().ToList();//同步数据的发票号
|
||||
|
var pdList = _dbcontext.Set<PUB_PD>().Where(p => billList.Contains(p.BillNum)).ToList();//扣减单内容
|
||||
|
var pdinvList = _dbcontext.Set<INVOICE_GRP>().Where(p => billList.Contains(p.InvbillNum)).ToList(); |
||||
|
if (pdList.Count > 0) |
||||
|
{ |
||||
|
if (flag == true) |
||||
|
{ |
||||
|
foreach (var item in pdList) |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
foreach (var item in pdinvList) |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(pdList); |
||||
|
_dbcontext.BulkUpdate(pdinvList); |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_dbcontext.BulkDelete(pdList); |
||||
|
_dbcontext.BulkDelete(p_ls); |
||||
|
} |
||||
|
} |
||||
|
var bbacList = _dbcontext.Set<BBAC_PD>().Where(p => billList.Contains(p.BillNum)).ToList(); |
||||
|
var bbacinvList = _dbcontext.Set<INVOICE_GRP>().Where(p => billList.Contains(p.InvbillNum)).ToList(); |
||||
|
if (bbacList.Count > 0) |
||||
|
{ |
||||
|
if (flag == true) |
||||
|
{ |
||||
|
foreach (var item in bbacList) |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
foreach (var item in bbacinvList) |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(bbacList); |
||||
|
_dbcontext.BulkUpdate(bbacinvList); |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_dbcontext.BulkDelete(pdList); |
||||
|
_dbcontext.BulkDelete(p_ls); |
||||
|
} |
||||
|
} |
||||
|
var hbpoList = _dbcontext.Set<HBPO_PD>().Where(p => billList.Contains(p.BillNum)).ToList(); |
||||
|
var hbpoinvList = _dbcontext.Set<INVOICE_GRP>().Where(p => billList.Contains(p.InvbillNum)).ToList();//发票
|
||||
|
if (hbpoList.Count > 0) |
||||
|
{ |
||||
|
if (flag == true) |
||||
|
{ |
||||
|
foreach (var item in hbpoList) |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
foreach (var item in hbpoinvList) |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(hbpoList); |
||||
|
_dbcontext.BulkUpdate(hbpoinvList); |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_dbcontext.BulkDelete(pdList); |
||||
|
_dbcontext.BulkDelete(p_ls); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// _emailSender.SendAsync(e)
|
||||
|
// 提交事务
|
||||
|
transaction.Commit(); |
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
issucess = false; |
||||
|
// 回滚事务
|
||||
|
transaction.Rollback(); |
||||
|
} |
||||
|
} |
||||
|
if (issucess ==false) |
||||
|
{ |
||||
|
var billList = p_ls.Select(p => p.BillNum).Distinct().ToList(); |
||||
|
var pdList = _dbcontext.Set<PUB_PD>().Where(p => billList.Contains(p.BillNum)).ToList(); |
||||
|
if (pdList.Count > 0) |
||||
|
{ |
||||
|
foreach (var item in pdList) |
||||
|
{ |
||||
|
if (flag == true) |
||||
|
{ |
||||
|
item.State = SettleBillState.客户已收票; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(pdList); |
||||
|
} |
||||
|
var bbacList = _dbcontext.Set<BBAC_PD>().Where(p => billList.Contains(p.BillNum)).ToList(); |
||||
|
if (bbacList.Count > 0) |
||||
|
{ |
||||
|
foreach (var item in bbacList) |
||||
|
{ |
||||
|
if (flag == true) |
||||
|
{ |
||||
|
item.State = SettleBillState.客户已收票; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(bbacList); |
||||
|
} |
||||
|
var hbpoList = _dbcontext.Set<HBPO_PD>().Where(p => billList.Contains(p.BillNum)).ToList(); |
||||
|
if (hbpoList.Count > 0) |
||||
|
{ |
||||
|
foreach (var item in hbpoList) |
||||
|
{ |
||||
|
if (flag == true) |
||||
|
{ |
||||
|
item.State = SettleBillState.客户已收票; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
item.State = SettleBillState.已扣减; |
||||
|
} |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(hbpoList); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue