|
|
@ -1,7 +1,9 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Globalization; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using DocumentFormat.OpenXml.Bibliography; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
@ -116,78 +118,20 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] HBPOSaImportRequestDto hbpoSaImportRequestDto) |
|
|
|
{ |
|
|
|
IActionResult result = new JsonResult(new { Code = 400 }); |
|
|
|
Version = hbpoSaImportRequestDto.Version; |
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.UploadExcelImport<HBPO_SA_DETAIL_IMPORT_DTO>(hbpoSaImportRequestDto.Files, _excelImportService).ConfigureAwait(false); |
|
|
|
var importHBOPSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL_IMPORT_DTO>, List<HBPO_SA_DETAIL>>(result); |
|
|
|
|
|
|
|
importHBOPSaDetails.ForEach(importHBOPSaDetail => |
|
|
|
{ |
|
|
|
importHBOPSaDetail.SetId(GuidGenerator.Create()); |
|
|
|
var lus = importHBOPSaDetail.LU.Split(" ").ToList(); |
|
|
|
importHBOPSaDetail.LU = lus[0].Replace(" ", ""); |
|
|
|
if (lus.Count > 1) |
|
|
|
{ |
|
|
|
lus.RemoveAt(0); |
|
|
|
var luAssemble = lus.Select(t => t.Replace(" ", "")); |
|
|
|
importHBOPSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
|
} |
|
|
|
importHBOPSaDetail.Version = Version; |
|
|
|
}); |
|
|
|
|
|
|
|
//Site包含CN1 亦庄
|
|
|
|
//Site包含CN5 顺义
|
|
|
|
var importCN1HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN1")); |
|
|
|
var importCN5HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN5")); |
|
|
|
|
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//结算分组号
|
|
|
|
var hbpoSaGroupNums = importHBOPSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
//已存在的结算分组号
|
|
|
|
var havHBPOSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
if (havHBPOSaGroupNums.Any() == true) |
|
|
|
switch (hbpoSaImportRequestDto.BusinessType) |
|
|
|
{ |
|
|
|
foreach (var item in havHBPOSaGroupNums) |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty)); |
|
|
|
} |
|
|
|
case EnumBusinessType.JisHBPO: |
|
|
|
result = await ImportJisHBPOAsync(hbpoSaImportRequestDto.Files).ConfigureAwait(false); |
|
|
|
break; |
|
|
|
case EnumBusinessType.MaiDanJianHBPO: |
|
|
|
result = await ImportMaiDanJianHBPOAsync(hbpoSaImportRequestDto.Files).ConfigureAwait(false); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (!checkList.Any()) |
|
|
|
{ |
|
|
|
//验证客户对应厂内零件号是否存在
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = (importCN1HBOPSaDetails.Select(t => t.LU).Union(importCN5HBOPSaDetails.Select(t => t.LU))).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
//不存在的客户零件号(差集)
|
|
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"客户零件号【{t}】对应厂内零件号系统中不存在", string.Empty)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, fileName = fileName }); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (importCN1HBOPSaDetails.Any()) |
|
|
|
{ |
|
|
|
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1"); |
|
|
|
} |
|
|
|
if (importCN5HBOPSaDetails.Any()) |
|
|
|
{ |
|
|
|
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5"); |
|
|
|
} |
|
|
|
|
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
return result; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -264,6 +208,74 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 私有方法
|
|
|
|
/// <summary>
|
|
|
|
/// JisHBPO导入
|
|
|
|
/// </summary>
|
|
|
|
private async Task<IActionResult> ImportJisHBPOAsync([FromForm] IFormFileCollection files) |
|
|
|
{ |
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.UploadExcelImport<HBPO_SA_DETAIL_IMPORT_DTO>(files, _excelImportService).ConfigureAwait(false); |
|
|
|
var importHBOPSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL_IMPORT_DTO>, List<HBPO_SA_DETAIL>>(result); |
|
|
|
|
|
|
|
HandleSaDetails(importHBOPSaDetails); |
|
|
|
|
|
|
|
//Site包含CN1 亦庄
|
|
|
|
//Site包含CN5 顺义
|
|
|
|
var importCN1HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN1")); |
|
|
|
var importCN5HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN5")); |
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
var checkList = await CheckAsync(importHBOPSaDetails).ConfigureAwait(false); |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, fileName = fileName }); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (importCN1HBOPSaDetails.Any()) |
|
|
|
{ |
|
|
|
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1").ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (importCN5HBOPSaDetails.Any()) |
|
|
|
{ |
|
|
|
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5").ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 买单件HBPO导入
|
|
|
|
/// </summary>
|
|
|
|
private async Task<IActionResult> ImportMaiDanJianHBPOAsync([FromForm] IFormFileCollection files) |
|
|
|
{ |
|
|
|
#region 导入数据转换
|
|
|
|
var exportImporter = new ExportImporter(); |
|
|
|
var importResults = await exportImporter.UploadExcelImport<MaiDanJianHBPOImportDto>(files, _excelImportService).ConfigureAwait(false); |
|
|
|
var importMaiDanHBPOSaDetails = ObjectMapper.Map<List<MaiDanJianHBPOImportDto>, List<HBPO_SA_DETAIL>>(importResults); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (!importMaiDanHBPOSaDetails.Any()) |
|
|
|
{ |
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
HandleSaDetails(importMaiDanHBPOSaDetails); |
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
var checkList = await CheckAsync(importMaiDanHBPOSaDetails).ConfigureAwait(false); |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, fileName = fileName }); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
await SaDataHandleAsync(importMaiDanHBPOSaDetails, "").ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 结算数据处理
|
|
|
|
/// </summary>
|
|
|
@ -275,7 +287,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
var hbpoSa = new HBPO_SA() |
|
|
|
{ |
|
|
|
BillNum = hbpoSaBillNum, |
|
|
|
State = "1", |
|
|
|
State = "0", |
|
|
|
BusinessType = _businessType, |
|
|
|
Site = site, |
|
|
|
Version = Version |
|
|
@ -374,15 +386,15 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
private async Task<(List<HBPO_SA> hbpoSas, List<HBPO_SA_DETAIL> hbpoSaDetails, List<HBPO_CAN_SA> hbpoCanSas, List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails, List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails)> GetHBPOSaDelItemsAsync(Guid id) |
|
|
|
{ |
|
|
|
//结算主表
|
|
|
|
List<HBPO_SA> hbpoSas = new List<HBPO_SA>(); |
|
|
|
var hbpoSas = new List<HBPO_SA>(); |
|
|
|
//结算明细
|
|
|
|
List<HBPO_SA_DETAIL> hbpoSaDetails = new List<HBPO_SA_DETAIL>(); |
|
|
|
var hbpoSaDetails = new List<HBPO_SA_DETAIL>(); |
|
|
|
//可结算主表
|
|
|
|
List<HBPO_CAN_SA> hbpoCanSas = new List<HBPO_CAN_SA>(); |
|
|
|
var hbpoCanSas = new List<HBPO_CAN_SA>(); |
|
|
|
//可结算明细
|
|
|
|
List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); |
|
|
|
var hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); |
|
|
|
//不可结算
|
|
|
|
List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>(); |
|
|
|
var hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>(); |
|
|
|
|
|
|
|
var hbpoSaEntity = await _hbpoSaRepository.FirstOrDefaultAsync(t => t.Id.Equals(id)).ConfigureAwait(false); |
|
|
|
if (hbpoSaEntity != null) |
|
|
@ -390,7 +402,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
//结算单据
|
|
|
|
string hbpoSaBillNum = hbpoSaEntity.BillNum; |
|
|
|
|
|
|
|
hbpoCanSas = await _hbpoCanSaRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); |
|
|
|
hbpoCanSas = await _hbpoCanSaRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum).ConfigureAwait(false); |
|
|
|
//验证可结算主表状态
|
|
|
|
if (hbpoCanSas.Any() && hbpoCanSas.Any(t => t.State != SettleBillState.未结状态)) |
|
|
|
{ |
|
|
@ -405,5 +417,65 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA> |
|
|
|
|
|
|
|
return (hbpoSas, hbpoSaDetails, hbpoCanSas, hbpoCanSaDetails, hbpoNotSaDetails); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 结算数据处理
|
|
|
|
/// </summary>
|
|
|
|
private void HandleSaDetails(List<HBPO_SA_DETAIL> hbpoSaDetails) |
|
|
|
{ |
|
|
|
hbpoSaDetails.ForEach(hbpoSaDetail => |
|
|
|
{ |
|
|
|
hbpoSaDetail.SetId(GuidGenerator.Create()); |
|
|
|
var lus = hbpoSaDetail.LU.Split(" ").ToList(); |
|
|
|
hbpoSaDetail.LU = lus[0].Replace(" ", ""); |
|
|
|
if (lus.Count > 1) |
|
|
|
{ |
|
|
|
lus.RemoveAt(0); |
|
|
|
var luAssemble = lus.Select(t => t.Replace(" ", "")); |
|
|
|
hbpoSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
|
} |
|
|
|
hbpoSaDetail.Version = Version; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 数据校验
|
|
|
|
/// </summary>
|
|
|
|
private async Task<List<ErrorExportDto>> CheckAsync(List<HBPO_SA_DETAIL> hbpoSaDetails) |
|
|
|
{ |
|
|
|
#region 数据校验
|
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
//结算分组号
|
|
|
|
var saGroupNums = hbpoSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
//已存在的结算分组号
|
|
|
|
var havPubSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => saGroupNums.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.Any()) |
|
|
|
{ |
|
|
|
//验证客户对应厂内零件号是否存在
|
|
|
|
//导入的零件号集合
|
|
|
|
var importSaLUs = hbpoSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
//不存在的客户零件号(差集)
|
|
|
|
var noExistSettleMaterialCodes = importSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"客户零件号【{t}】对应厂内零件号系统中不存在", string.Empty)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return checkList; |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|