|
|
@ -10,6 +10,8 @@ using Win.Sfs.Shared.RepositoryBase; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using System.Security.Cryptography; |
|
|
|
using Win.Sfs.SettleAccount.Bases.DomainServices; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
{ |
|
|
@ -27,6 +29,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
private readonly INormalEfCoreRepository<PUB_CAN_SA, Guid> _repository; |
|
|
|
private readonly INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> _detailRepository; |
|
|
|
private readonly INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> _notRepository; |
|
|
|
private readonly BaseDomainService _service; |
|
|
|
|
|
|
|
public PUB_NOT_SA_MNG() |
|
|
|
{ |
|
|
@ -36,14 +39,85 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
( |
|
|
|
INormalEfCoreRepository<PUB_CAN_SA, Guid> repository, |
|
|
|
INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> detailRepository, |
|
|
|
INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> notRepository |
|
|
|
INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> notRepository, |
|
|
|
BaseDomainService service |
|
|
|
) |
|
|
|
{ |
|
|
|
_service = service; |
|
|
|
_repository = repository; |
|
|
|
_detailRepository = detailRepository; |
|
|
|
_notRepository = notRepository; |
|
|
|
} |
|
|
|
public virtual async Task<bool> GenerateSettlementOrder(List<PUB_NOT_SA_DETAIL> p_list) |
|
|
|
public virtual async Task<List<string>> GenerateSettlementOrder(List<PUB_NOT_SA_DETAIL> p_list) |
|
|
|
{ |
|
|
|
List<string> errors = new List<string>(); |
|
|
|
var query = p_list.Select(p => p.BusinessType).Distinct(); |
|
|
|
foreach (var itm in query.ToList()) |
|
|
|
{ |
|
|
|
errors.Add("选择项有不在同一业务的数据!"); |
|
|
|
|
|
|
|
} |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
return errors; |
|
|
|
} |
|
|
|
|
|
|
|
var first= p_list.FirstOrDefault(); |
|
|
|
if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO |
|
|
|
|| first.BusinessType == EnumBusinessType.BeiJian |
|
|
|
) |
|
|
|
{ |
|
|
|
var ls = p_list.Select(p => p.GroupNum).Distinct().ToList(); |
|
|
|
var notlist = _notRepository.Where(p => ls.Contains(p.GroupNum)).ToList();//JIT_ASN整发
|
|
|
|
var priceErrors = await _service.CheckPriceList(notlist); |
|
|
|
if (priceErrors.Count > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in priceErrors) |
|
|
|
{ |
|
|
|
errors.Add($"发货单号或交付识别号零件{itm.LU}结算日期{itm.SettleDate}无价格区间数据"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
return errors; |
|
|
|
} |
|
|
|
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); |
|
|
|
var _entity = new PUB_CAN_SA(); |
|
|
|
_entity.BillNum = billNumber; |
|
|
|
_entity.InvGroupNum = billNumber; |
|
|
|
_entity.Version = DateTime.Now.Year + DateTime.Now.Month; |
|
|
|
_entity.State = SettleBillState.未结状态; |
|
|
|
_entity.SettleBillNum = string.Empty; |
|
|
|
var _entityList = new List<PUB_CAN_SA_DETAIL>(); |
|
|
|
foreach (var itm in notlist) |
|
|
|
{ |
|
|
|
var _detailEntity = new PUB_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 |
|
|
|
); |
|
|
|
|
|
|
|
_entityList.Add(_detailEntity); |
|
|
|
} |
|
|
|
await _notRepository.DbContext.BulkDeleteAsync(p_list); |
|
|
|
await _repository.DbContext.BulkInsertAsync(new List<PUB_CAN_SA>() { _entity }); |
|
|
|
await _repository.DbContext.BulkInsertAsync(_entityList); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); |
|
|
|
var _entity = new PUB_CAN_SA(); |
|
|
@ -71,7 +145,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: billNumber, |
|
|
|
invbillnum: string.Empty, |
|
|
|
partcode:itm.PartCode |
|
|
|
partcode: itm.PartCode |
|
|
|
); |
|
|
|
|
|
|
|
_entityList.Add(_detailEntity); |
|
|
@ -79,7 +153,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
await _notRepository.DbContext.BulkDeleteAsync(p_list); |
|
|
|
await _repository.DbContext.BulkInsertAsync(new List<PUB_CAN_SA>() { _entity }); |
|
|
|
await _repository.DbContext.BulkInsertAsync(_entityList); |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return errors; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|