|
|
@ -22,6 +22,8 @@ using Win.Sfs.SettleAccount.Constant; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
|
using Win.Sfs.SettleAccount.Entities.Prices; |
|
|
|
using Win.Sfs.SettleAccount.ExcelImporter; |
|
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
@ -63,6 +65,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<PriceList, Guid> _priceListRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 客户零件关系仓储
|
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _materialRelationshipRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 替换件关系仓储
|
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
|
/// </summary>
|
|
|
@ -97,8 +109,37 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
[HttpPost] |
|
|
|
public async Task<string> ZGJImportAsync([FromForm] IFormFileCollection files) |
|
|
|
{ |
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//类型(直供件)
|
|
|
|
EnumBusinessType businessType = EnumBusinessType.ZhiGongJian; |
|
|
|
var businessType = EnumBusinessType.ZhiGongJian; |
|
|
|
//结算单号
|
|
|
|
var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
//结算主表
|
|
|
|
var pubSa = new PUB_SA() |
|
|
|
{ |
|
|
|
BillNum = pubSaBillNum, |
|
|
|
State = "1" |
|
|
|
}; |
|
|
|
//结算明细
|
|
|
|
var pubSaDetails = new List<PUB_SA_DETAIL>(); |
|
|
|
//可算单号
|
|
|
|
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
//可算主表
|
|
|
|
var pubCanSa = new PUB_CAN_SA() |
|
|
|
{ |
|
|
|
BillNum = pubCanSaBillNum, |
|
|
|
SettleBillNum = pubSaBillNum, |
|
|
|
State = SettleBillState.未结状态, |
|
|
|
BusinessType = businessType |
|
|
|
}; |
|
|
|
//可结算明细
|
|
|
|
var pubCanSaDetails = new List<PUB_CAN_SA_DETAIL>(); |
|
|
|
//不可结算明细
|
|
|
|
var pubNotSaDetails = new List<PUB_NOT_SA_DETAIL>(); |
|
|
|
|
|
|
|
|
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.UploadExcelImport<ZGJ_PUB_SA_DETAIL_IMPORT_DTO>(files, _excelImportService); |
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<ZGJ_PUB_SA_DETAIL_IMPORT_DTO>, List<PUB_SA_DETAIL>>(result); |
|
|
@ -106,15 +147,27 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
//结算分组号
|
|
|
|
var pubSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
//销售价格
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
//已存在的结算分组号
|
|
|
|
var havPubSaGroupNums = (await _pubSaDetailRepository.GetListAsync(t => pubSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
if (havPubSaGroupNums.Any() == true) |
|
|
|
{ |
|
|
|
foreach (var item in havPubSaGroupNums) |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty)); |
|
|
|
} |
|
|
|
//throw new UserFriendlyException($"导入失败,结算分组号({string.Join(",", havPubSaGroupNums)})已存在", "400");
|
|
|
|
} |
|
|
|
|
|
|
|
var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
var pubSa = new PUB_SA() |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
BillNum = pubSaBillNum, |
|
|
|
State = "1" |
|
|
|
}; |
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
//销售价格
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
|
|
|
|
importPubSaDetails.ForEach(importPubSaDetail => |
|
|
|
{ |
|
|
@ -136,28 +189,30 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
importPubSaDetail.Price = priceListEntity?.Price ?? 0; |
|
|
|
}); |
|
|
|
|
|
|
|
//可结算
|
|
|
|
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
var pubCanSa = new PUB_CAN_SA() |
|
|
|
{ |
|
|
|
BillNum = pubCanSaBillNum, |
|
|
|
SettleBillNum = pubSaBillNum, |
|
|
|
State = SettleBillState.未结状态, |
|
|
|
BusinessType = businessType |
|
|
|
}; |
|
|
|
////导入的零件号集合
|
|
|
|
//var importPubSaLUs = importPubSaDetails.Select(t => t.LU).Distinct();
|
|
|
|
//_materialRelationshipRepository.GetListAsync(t => t.)
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 入库数据赋值
|
|
|
|
//结算明细
|
|
|
|
pubSaDetails = importPubSaDetails; |
|
|
|
|
|
|
|
//不可结算 结算分组号码(根据价格区分结算、不可结算)
|
|
|
|
var pubNotSaGroupNums = importPubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); |
|
|
|
var pubSaDetailsCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false); |
|
|
|
var pubSaDetailsNotCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true); |
|
|
|
|
|
|
|
//可结算
|
|
|
|
var pubCanSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_CAN_SA_DETAIL>>(pubSaDetailsCanSes); |
|
|
|
//不可结算
|
|
|
|
var pubNotSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_NOT_SA_DETAIL>>(pubSaDetailsNotCanSes); |
|
|
|
//可结算明细
|
|
|
|
pubCanSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_CAN_SA_DETAIL>>(pubSaDetailsCanSes); |
|
|
|
//不可结算明细
|
|
|
|
pubNotSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_NOT_SA_DETAIL>>(pubSaDetailsNotCanSes); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
//添加入库
|
|
|
|
#region 添加入库
|
|
|
|
await _repository.InsertAsync(pubSa); |
|
|
|
await _pubSaDetailRepository.InsertManyAsync(importPubSaDetails); |
|
|
|
if (pubCanSaDetails.Count > 0) |
|
|
@ -182,6 +237,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
|
|
|
|
await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
} |
|
|
|
|
|
|
@ -245,7 +302,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
//验证可结算主表状态
|
|
|
|
if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.未结状态)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"该单据可结算单状态无法删除!"); |
|
|
|
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400"); |
|
|
|
} |
|
|
|
|
|
|
|
pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum); |
|
|
|