10 changed files with 821 additions and 318 deletions
@ -0,0 +1,399 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Security.Policy; |
||||
|
using System.Text; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using DocumentFormat.OpenXml.Bibliography; |
||||
|
using EFCore.BulkExtensions; |
||||
|
using Minio.DataModel; |
||||
|
using SettleAccount.Domain.BQ; |
||||
|
using TaskJob.EventArgs; |
||||
|
using TaskJob.Interfaces; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Win.Sfs.SettleAccount.Bases; |
||||
|
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; |
||||
|
using Win.Sfs.SettleAccount.Entities.Prices; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
||||
|
{ |
||||
|
public class MakeCanSettlementService : ApplicationService, ITransientDependency, IExportJob |
||||
|
{ |
||||
|
protected readonly SettleAccountDbContext _dbcontext; |
||||
|
|
||||
|
public MakeCanSettlementService( |
||||
|
SettleAccountDbContext dbcontext |
||||
|
) |
||||
|
{ |
||||
|
_dbcontext = dbcontext; |
||||
|
} |
||||
|
[UnitOfWork(false)] |
||||
|
public string ExportFile(Guid id, List<string> exportName, List<CustomCondition> property) |
||||
|
{ |
||||
|
var conditions = property.Where(p => p.Name == "condition").FirstOrDefault().Value; |
||||
|
var businesstype = property.Where(p => p.Name == "businesstype").FirstOrDefault().Value; |
||||
|
var filers = JsonSerializer.Deserialize<List<FilterCondition>>(conditions); |
||||
|
if (businesstype == "JisBBAC") |
||||
|
{ |
||||
|
List<BBAC_CAN_SA> billList = new List<BBAC_CAN_SA>(); |
||||
|
List<BBAC_CAN_SA_DETAIL> billDetails = new List<BBAC_CAN_SA_DETAIL>(); |
||||
|
var bbacquery = _dbcontext.Set<BBAC_NOT_SA_DETAIL>().AsQueryable(); |
||||
|
if (filers.Count > 0) |
||||
|
{ |
||||
|
bbacquery = bbacquery.Where(filers.ToLambda<BBAC_NOT_SA_DETAIL>()); |
||||
|
} |
||||
|
var p_list = bbacquery.ToList(); |
||||
|
var jis1 = p_list.Where(p => p.Site == "1040").ToList(); |
||||
|
var jis2 = p_list.Where(p => p.Site == "1046").ToList(); |
||||
|
List<BBAC_NOT_SA_DETAIL> notlist = new List<BBAC_NOT_SA_DETAIL>(); |
||||
|
if (jis1.Count > 0)//1040
|
||||
|
{ |
||||
|
var pricelist = _dbcontext.Set<PriceList>().Where(p => p.ClientCode == "1040" && p.IsCancel == false).ToList(); |
||||
|
var query = from d in jis1 |
||||
|
join p in pricelist |
||||
|
on d.LU equals p.LU |
||||
|
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == "1040" |
||||
|
select new |
||||
|
{ |
||||
|
a = |
||||
|
new BBAC_CAN_SA_DETAIL() |
||||
|
{ |
||||
|
ContractDocID = d.ContractDocID, |
||||
|
IsMaiDan = d.IsMaiDan, |
||||
|
Version = d.Version, |
||||
|
KeyCode = d.KeyCode, |
||||
|
Site = "1040", |
||||
|
BusinessType = d.BusinessType, |
||||
|
ErpLoc = d.ErpLoc, |
||||
|
CreationTime = d.CreationTime, |
||||
|
GroupNum = d.GroupNum, |
||||
|
InvGroupNum = d.InvGroupNum, |
||||
|
LU = d.LU, |
||||
|
PN = d.PN, |
||||
|
SettleBillNum = d.SettleBillNum, |
||||
|
Price = p.Price, |
||||
|
SettleDate = d.SettleDate, |
||||
|
RealPartCode = d.RealPartCode, |
||||
|
PartCode = d.PartCode, |
||||
|
Qty = d.Qty |
||||
|
}, |
||||
|
b=d |
||||
|
}; |
||||
|
var bbac_can_list= query.Select(p => p.a).ToList(); |
||||
|
var bbac_not_list= query.Select(p => p.b).ToList(); |
||||
|
if(bbac_can_list.Count>0) |
||||
|
{ |
||||
|
notlist.AddRange(bbac_not_list); |
||||
|
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); |
||||
|
var entity = new BBAC_CAN_SA(); |
||||
|
entity.SetId(Guid.NewGuid()); |
||||
|
entity.BillNum = billNumber; |
||||
|
entity.InvGroupNum = billNumber; |
||||
|
entity.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); |
||||
|
entity.State = SettleBillState.未结状态; |
||||
|
entity.SettleBillNum = string.Empty; |
||||
|
entity.Site = "1040"; |
||||
|
entity.BusinessType = EnumBusinessType.JisBBAC; |
||||
|
billList.Add(entity); |
||||
|
|
||||
|
foreach (var itm in bbac_can_list) |
||||
|
{ |
||||
|
var _detailEntity = new BBAC_CAN_SA_DETAIL( |
||||
|
guid: GuidGenerator.Create(), |
||||
|
keyCode: itm.KeyCode, |
||||
|
version: itm.Version, |
||||
|
billNum: billNumber, |
||||
|
settleBillNum: itm.SettleBillNum, |
||||
|
lU: itm.LU, |
||||
|
pN: itm.PN, |
||||
|
site: itm.Site, |
||||
|
qty: itm.Qty, |
||||
|
price: itm.Price, |
||||
|
category: itm.BusinessType, |
||||
|
isReturn: itm.IsReturn, |
||||
|
settleDate: itm.SettleDate, |
||||
|
groupNum: itm.GroupNum, |
||||
|
invGroupNum: billNumber, |
||||
|
contactid: itm.ContractDocID, |
||||
|
invbillnum: string.Empty, |
||||
|
partcode: itm.PartCode |
||||
|
); |
||||
|
_detailEntity.RealPartCode = itm.RealPartCode; |
||||
|
billDetails.Add(_detailEntity); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if (jis2.Count > 0) |
||||
|
{ |
||||
|
var pricelist = _dbcontext.Set<PriceList>().Where(p => p.ClientCode == "1046" && p.IsCancel == false).ToList(); |
||||
|
var query = from d in jis2 |
||||
|
join p in pricelist |
||||
|
on d.LU equals p.LU |
||||
|
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == "1046" |
||||
|
select new |
||||
|
{ |
||||
|
a =new BBAC_CAN_SA_DETAIL() |
||||
|
{ |
||||
|
ContractDocID = d.ContractDocID, |
||||
|
IsMaiDan = d.IsMaiDan, |
||||
|
Version = d.Version, |
||||
|
KeyCode = d.KeyCode, |
||||
|
Site = "1046", |
||||
|
BusinessType = d.BusinessType, |
||||
|
ErpLoc = d.ErpLoc, |
||||
|
CreationTime = d.CreationTime, |
||||
|
GroupNum = d.GroupNum, |
||||
|
InvGroupNum = d.InvGroupNum, |
||||
|
LU = d.LU, |
||||
|
PN = d.PN, |
||||
|
SettleBillNum = d.SettleBillNum, |
||||
|
Price = p.Price, |
||||
|
SettleDate = d.SettleDate, |
||||
|
RealPartCode = d.RealPartCode, |
||||
|
PartCode = d.PartCode, |
||||
|
Qty = d.Qty |
||||
|
}, |
||||
|
b = d |
||||
|
}; |
||||
|
var bbac_can_list = query.Select(p => p.a).ToList(); |
||||
|
var bbac_not_list = query.Select(p => p.b).ToList(); |
||||
|
if (bbac_can_list.Count > 0) |
||||
|
{ |
||||
|
notlist.AddRange(bbac_not_list); |
||||
|
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); |
||||
|
var entity = new BBAC_CAN_SA(); |
||||
|
entity.SetId(Guid.NewGuid()); |
||||
|
entity.BillNum = billNumber; |
||||
|
entity.InvGroupNum = billNumber; |
||||
|
entity.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); |
||||
|
entity.State = SettleBillState.未结状态; |
||||
|
entity.SettleBillNum = string.Empty; |
||||
|
entity.Site = "1046"; |
||||
|
entity.BusinessType = EnumBusinessType.JisBBAC; |
||||
|
billList.Add(entity); |
||||
|
|
||||
|
foreach (var itm in bbac_can_list) |
||||
|
{ |
||||
|
var _detailEntity = new BBAC_CAN_SA_DETAIL( |
||||
|
guid: GuidGenerator.Create(), |
||||
|
keyCode: itm.KeyCode, |
||||
|
version: itm.Version, |
||||
|
billNum: billNumber, |
||||
|
settleBillNum: itm.SettleBillNum, |
||||
|
lU: itm.LU, |
||||
|
pN: itm.PN, |
||||
|
site: itm.Site, |
||||
|
qty: itm.Qty, |
||||
|
price: itm.Price, |
||||
|
category: itm.BusinessType, |
||||
|
isReturn: itm.IsReturn, |
||||
|
settleDate: itm.SettleDate, |
||||
|
groupNum: itm.GroupNum, |
||||
|
invGroupNum: billNumber, |
||||
|
contactid: itm.ContractDocID, |
||||
|
invbillnum: string.Empty, |
||||
|
partcode: itm.PartCode |
||||
|
); |
||||
|
_detailEntity.RealPartCode = itm.RealPartCode; |
||||
|
billDetails.Add(_detailEntity); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
bool issucess = true; |
||||
|
using (var transaction = _dbcontext.Database.BeginTransaction()) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
if (billDetails.Count > 0) |
||||
|
{ |
||||
|
_dbcontext.BulkDelete(notlist);//删除不可结数据
|
||||
|
_dbcontext.BulkInsert(billDetails);//插入可结主表
|
||||
|
_dbcontext.BulkInsert(billList);//插入可结明细
|
||||
|
var flaglist= _dbcontext.Set<BBAC_NOT_SA_DETAIL>().Where(p => p.IsReturn == true).ToList(); |
||||
|
foreach (var flag in flaglist) { |
||||
|
flag.IsReturn = false; |
||||
|
} |
||||
|
_dbcontext.BulkUpdate(flaglist);//插入可结明细
|
||||
|
issucess = true; |
||||
|
transaction.Commit(); |
||||
|
} |
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
issucess = false; |
||||
|
// 回滚事务
|
||||
|
transaction.Rollback(); |
||||
|
} |
||||
|
} |
||||
|
if (issucess == true) |
||||
|
{ |
||||
|
var result = from a in _dbcontext.Set<BBAC_SA_DETAIL>() |
||||
|
join b in _dbcontext.Set<BBAC_CAN_SA_DETAIL>() on new { a.KeyCode, a.BusinessType } equals new { b.KeyCode, b.BusinessType } |
||||
|
where a.Price == 0 |
||||
|
select new |
||||
|
{ |
||||
|
a, |
||||
|
b.Price |
||||
|
}; |
||||
|
foreach (var item in result) |
||||
|
{ |
||||
|
item.a.Price = item.Price; |
||||
|
} |
||||
|
var salist = result.Select(p => p.a).ToList(); |
||||
|
_dbcontext.BulkUpdate(salist);//更新结算数据
|
||||
|
} |
||||
|
} |
||||
|
if (businesstype == "JisHBPO") |
||||
|
{ |
||||
|
List<HBPO_NOT_SA_DETAIL> notlist = new List<HBPO_NOT_SA_DETAIL>(); |
||||
|
List<HBPO_CAN_SA> billList = new List<HBPO_CAN_SA>(); |
||||
|
List<HBPO_CAN_SA_DETAIL> billDetails = new List<HBPO_CAN_SA_DETAIL>(); |
||||
|
var bbacquery = _dbcontext.Set<HBPO_NOT_SA_DETAIL>().AsQueryable(); |
||||
|
if (filers.Count > 0) |
||||
|
{ |
||||
|
bbacquery = bbacquery.Where(filers.ToLambda<HBPO_NOT_SA_DETAIL>()); |
||||
|
} |
||||
|
var p_list = bbacquery.ToList(); |
||||
|
var jis1 = p_list.Where(p => p.Site == "104T").ToList(); |
||||
|
if (jis1.Count > 0) |
||||
|
{ |
||||
|
var pricelist = _dbcontext.Set<PriceList>().Where(p => p.ClientCode == "104T" && p.IsCancel == false).ToList(); |
||||
|
var query = from d in jis1 |
||||
|
join p in pricelist |
||||
|
on d.LU equals p.LU |
||||
|
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == "104T" |
||||
|
select new |
||||
|
{ |
||||
|
a = new HBPO_CAN_SA_DETAIL() |
||||
|
{ |
||||
|
Version = d.Version, |
||||
|
KeyCode = d.KeyCode, |
||||
|
Site = "104T", |
||||
|
BusinessType = d.BusinessType, |
||||
|
ErpLoc = d.ErpLoc, |
||||
|
CreationTime = d.CreationTime, |
||||
|
GroupNum = d.GroupNum, |
||||
|
InvGroupNum = d.InvGroupNum, |
||||
|
LU = d.LU, |
||||
|
PN = d.PN, |
||||
|
SettleBillNum = d.SettleBillNum, |
||||
|
Price = p.Price, |
||||
|
SettleDate = d.SettleDate, |
||||
|
RealPartCode = d.RealPartCode, |
||||
|
PartCode = d.PartCode, |
||||
|
Qty = d.Qty |
||||
|
}, |
||||
|
b = d |
||||
|
}; |
||||
|
|
||||
|
var hbpo_can_list = query.Select(p => p.a).ToList(); |
||||
|
var hbpo_not_list = query.Select(p => p.b).ToList(); |
||||
|
if (hbpo_can_list.Count > 0) |
||||
|
{ |
||||
|
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); |
||||
|
var entity = new HBPO_CAN_SA(); |
||||
|
entity.SetId(Guid.NewGuid()); |
||||
|
entity.BillNum = billNumber; |
||||
|
entity.InvGroupNum = billNumber; |
||||
|
entity.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); |
||||
|
entity.State = SettleBillState.未结状态; |
||||
|
entity.SettleBillNum = string.Empty; |
||||
|
entity.Site = "104T"; |
||||
|
entity.BusinessType = EnumBusinessType.JisBBAC; |
||||
|
billList.Add(entity); |
||||
|
notlist.AddRange(hbpo_not_list); |
||||
|
foreach (var itm in hbpo_can_list) |
||||
|
{ |
||||
|
var _detailEntity = new HBPO_CAN_SA_DETAIL( |
||||
|
guid: GuidGenerator.Create(), |
||||
|
keyCode: itm.KeyCode, |
||||
|
version: itm.Version, |
||||
|
billNum: billNumber, |
||||
|
settleBillNum: itm.SettleBillNum, |
||||
|
lU: itm.LU, |
||||
|
pN: itm.PN, |
||||
|
site: itm.Site, |
||||
|
qty: itm.Qty, |
||||
|
price: itm.Price, |
||||
|
businessType: itm.BusinessType, |
||||
|
settleDate: itm.SettleDate, |
||||
|
groupNum: itm.GroupNum, |
||||
|
invGroupNum: billNumber, |
||||
|
invbillnum: string.Empty, |
||||
|
partcode: itm.PartCode |
||||
|
); |
||||
|
_detailEntity.RealPartCode = itm.RealPartCode; |
||||
|
billDetails.Add(_detailEntity); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
bool issucess = true; |
||||
|
using (var transaction = _dbcontext.Database.BeginTransaction()) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
if (billDetails.Count > 0) |
||||
|
{ |
||||
|
_dbcontext.BulkDelete(p_list);//删除不可结数据
|
||||
|
_dbcontext.BulkInsert(billDetails);//插入可结明细
|
||||
|
_dbcontext.BulkInsert(billList);//插入可结主表
|
||||
|
var result = from a in _dbcontext.Set<HBPO_SA_DETAIL>() |
||||
|
join b in _dbcontext.Set<HBPO_CAN_SA_DETAIL>() on new { a.KeyCode, a.BusinessType } equals new { b.KeyCode, b.BusinessType } |
||||
|
where a.Price == 0 |
||||
|
select new |
||||
|
{ |
||||
|
a, |
||||
|
b.Price |
||||
|
}; |
||||
|
foreach (var item in result) |
||||
|
{ |
||||
|
item.a.Price = item.Price; |
||||
|
} |
||||
|
var salist = result.Select(p => p.a).ToList(); |
||||
|
_dbcontext.BulkUpdate(salist);//更新结算数据
|
||||
|
transaction.Commit(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
issucess = false;// 回滚事务
|
||||
|
transaction.Rollback(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
issucess = false;// 回滚事务
|
||||
|
transaction.Rollback(); |
||||
|
} |
||||
|
} |
||||
|
if (issucess == true) |
||||
|
{ |
||||
|
var result = from a in _dbcontext.Set<BBAC_SA_DETAIL>() |
||||
|
join b in _dbcontext.Set<BBAC_CAN_SA_DETAIL>() on new { a.KeyCode, a.BusinessType } equals new { b.KeyCode, b.BusinessType } |
||||
|
where a.Price == 0 |
||||
|
select new |
||||
|
{ |
||||
|
a, |
||||
|
b.Price |
||||
|
}; |
||||
|
foreach (var item in result) |
||||
|
{ |
||||
|
item.a.Price = item.Price; |
||||
|
} |
||||
|
var salist = result.Select(p => p.a).ToList(); |
||||
|
_dbcontext.BulkUpdate(salist);//更新结算数据
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return id.ToString(); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue