|
|
@ -110,38 +110,6 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
[HttpPost] |
|
|
|
public async Task<string> ImportAsync([FromForm] IFormFileCollection files) |
|
|
|
{ |
|
|
|
//业务类型
|
|
|
|
var businessType = EnumBusinessType.JisHBPO; |
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//结算单号
|
|
|
|
var hbpoSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
//结算主表
|
|
|
|
var hbpoSa = new HBPO_SA() |
|
|
|
{ |
|
|
|
BillNum = hbpoSaBillNum, |
|
|
|
State = "1", |
|
|
|
BusinessType = businessType |
|
|
|
}; |
|
|
|
//结算明细
|
|
|
|
var hbpoSaDetails = new List<HBPO_SA_DETAIL>(); |
|
|
|
//可结算单号
|
|
|
|
var hbpoCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
//可结算主表
|
|
|
|
var hbpoCanSa = new HBPO_CAN_SA() |
|
|
|
{ |
|
|
|
BillNum = hbpoCanSaBillNum, |
|
|
|
SettleBillNum = hbpoSaBillNum, |
|
|
|
State = SettleBillState.未结状态, |
|
|
|
BusinessType = businessType |
|
|
|
}; |
|
|
|
//可结算明细
|
|
|
|
var hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); |
|
|
|
//不可结算明细
|
|
|
|
var hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>(); |
|
|
|
//客户零件关系
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.UploadExcelImport<HBPO_SA_DETAIL_IMPORT_DTO>(files, _excelImportService); |
|
|
@ -152,22 +120,18 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
var importCN1HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN1")); |
|
|
|
var importCN5HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN5")); |
|
|
|
|
|
|
|
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1"); |
|
|
|
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5"); |
|
|
|
return ""; |
|
|
|
|
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//结算分组号
|
|
|
|
var hbpoSaGroupNums = importHBOPSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
var havPubSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
if (havPubSaGroupNums.Any() == true) |
|
|
|
var havHBPOSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
if (havHBPOSaGroupNums.Any() == true) |
|
|
|
{ |
|
|
|
foreach (var item in havPubSaGroupNums) |
|
|
|
foreach (var item in havHBPOSaGroupNums) |
|
|
|
{ |
|
|
|
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");
|
|
|
|
} |
|
|
|
|
|
|
|
if (checkList.Count > 0) |
|
|
@ -176,94 +140,14 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
//销售价格
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
|
|
|
|
importHBOPSaDetails.ForEach(importPubSaDetail => |
|
|
|
{ |
|
|
|
List<string> luList = importPubSaDetail.LU.Split(" ").ToList(); |
|
|
|
importPubSaDetail.LU = luList[0].Replace(" ", ""); |
|
|
|
if (luList.Count > 1) |
|
|
|
{ |
|
|
|
luList.RemoveAt(0); |
|
|
|
var luAssemble = luList.Select(t => t.Replace(" ", "")); |
|
|
|
importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
|
} |
|
|
|
|
|
|
|
importPubSaDetail.BillNum = hbpoSaBillNum; |
|
|
|
//importPubSaDetail.Site = "XX工厂";
|
|
|
|
importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU; |
|
|
|
|
|
|
|
//根据物料号、结算日期获取价格
|
|
|
|
var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime); |
|
|
|
importPubSaDetail.Price = priceListEntity?.Price ?? 0; |
|
|
|
importPubSaDetail.BusinessType = businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = importHBOPSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
/* |
|
|
|
* (不存在的客户零件号)差集 |
|
|
|
* 转换为厂内零件号 |
|
|
|
* 转换规则6个空格替换成“-” |
|
|
|
*/ |
|
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
|
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
if (importCN1HBOPSaDetails.Any()) |
|
|
|
{ |
|
|
|
var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, businessType.ToString()); |
|
|
|
materialRelationships.Add(materialRelationship); |
|
|
|
}); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 入库数据赋值
|
|
|
|
//结算明细
|
|
|
|
hbpoSaDetails = importHBOPSaDetails; |
|
|
|
|
|
|
|
//不可结算 结算分组号码(根据价格区分结算、不可结算)
|
|
|
|
var hbpoNotSaGroupNums = hbpoSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); |
|
|
|
var hbpoSaDetailsCanSes = hbpoSaDetails.FindAll(t => hbpoNotSaGroupNums.Contains(t.GroupNum) == false); |
|
|
|
var hbpoSaDetailsNotCanSes = hbpoSaDetails.FindAll(t => hbpoNotSaGroupNums.Contains(t.GroupNum) == true); |
|
|
|
|
|
|
|
//可结算明细
|
|
|
|
hbpoCanSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL>>(hbpoSaDetailsCanSes); |
|
|
|
//不可结算明细
|
|
|
|
hbpoNotSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL>, List<HBPO_NOT_SA_DETAIL>>(hbpoSaDetailsNotCanSes); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 添加入库
|
|
|
|
await _hbpoSaRepository.InsertAsync(hbpoSa); |
|
|
|
await _hbpoSaDetailRepository.InsertManyAsync(hbpoSaDetails); |
|
|
|
if (hbpoCanSaDetails.Count > 0) |
|
|
|
{ |
|
|
|
hbpoCanSa.InvGroupNum = hbpoCanSaDetails.Count.ToString(); |
|
|
|
hbpoCanSaDetails.ForEach(hbpoCanSaDetail => |
|
|
|
{ |
|
|
|
hbpoCanSaDetail.BillNum = hbpoCanSaDetail.InvGroupNum = hbpoCanSaBillNum; |
|
|
|
hbpoCanSaDetail.BusinessType = businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
await _hbpoCanSaRepository.InsertAsync(hbpoCanSa); |
|
|
|
await _hbpoCanSaDetailRepository.InsertManyAsync(hbpoCanSaDetails); |
|
|
|
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1"); |
|
|
|
} |
|
|
|
if (hbpoNotSaDetails.Count > 0) |
|
|
|
if (importCN5HBOPSaDetails.Any()) |
|
|
|
{ |
|
|
|
hbpoNotSaDetails.ForEach(hbpoNotSaDetail => |
|
|
|
{ |
|
|
|
hbpoNotSaDetail.BusinessType = businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
await _hbpoNotSaDetailRepository.InsertManyAsync(hbpoNotSaDetails); |
|
|
|
} |
|
|
|
if (materialRelationships.Count > 0) |
|
|
|
{ |
|
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); |
|
|
|
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5"); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
} |
|
|
@ -402,10 +286,8 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
/// <summary>
|
|
|
|
/// 结算数据处理
|
|
|
|
/// </summary>
|
|
|
|
private async Task<string> SaDataHandleAsync(List<HBPO_SA_DETAIL> hbpoSaDetails, string site) |
|
|
|
private async Task SaDataHandleAsync(List<HBPO_SA_DETAIL> hbpoSaDetails, string site) |
|
|
|
{ |
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//结算单号
|
|
|
|
var hbpoSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
//结算主表
|
|
|
@ -434,26 +316,6 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
//客户零件关系
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
//结算分组号
|
|
|
|
var hbpoSaGroupNums = hbpoSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
var havPubSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.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)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
//销售价格
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
@ -537,8 +399,6 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|