Browse Source

买单件BBAC结算列表查询

master
mahao 1 year ago
parent
commit
4752aadcf5
  1. 45
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs
  2. 46
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs
  3. 224
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs
  4. 40
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs
  5. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

45
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs

@ -107,7 +107,10 @@ public class HBPOSaImportRequestDto
/// 文件
/// </summary>
public IFormFileCollection Files { get; set; }
/// <summary>
/// 业务类别
/// </summary>
public EnumBusinessType BusinessType { get; set; }
/// <summary>
/// 期间
/// </summary>
@ -175,6 +178,46 @@ public class HBPO_SA_DETAIL_IMPORT_DTO
public string PN { get; set; }
}
/// <summary>
/// 买单件HBPO导入
/// </summary>
public class MaiDanJianHBPOImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "买单日期")]
[ImporterHeader(Name = "买单日期")]
public DateTime SettleDate { set; get; }
/// <summary>
/// 客户零件号
/// </summary>
[Display(Name = "零件号")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "零件号")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "现产品生产号")]
[ImporterHeader(Name = "现产品生产号")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "数量")]
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "五联单号")]
[ImporterHeader(Name = "五联单号")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary>
/// 结算明细导出请求
/// </summary>

46
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs

@ -57,12 +57,10 @@ public class PUB_SAImportRequestDto
/// 文件
/// </summary>
public IFormFileCollection Files { get; set; }
/// <summary>
/// 业务类别
/// </summary>
public EnumBusinessType BusinessType { get; set; }
/// <summary>
/// 期间
/// </summary>
@ -165,50 +163,6 @@ public class ZhiGongJianHBPOImportDto
public string GroupNum { get; set; }
}
/// <summary>
/// 买单件HBPO导入
/// </summary>
public class MaiDanJianHBPOImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "买单日期")]
[ImporterHeader(Name = "买单日期")]
public DateTime SettleDate { set; get; }
/// <summary>
/// 客户零件号
/// </summary>
[Display(Name = "零件号")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "零件号")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "现产品生产号")]
[ImporterHeader(Name = "现产品生产号")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "数量")]
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "五联单号")]
[ImporterHeader(Name = "五联单号")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary>
/// 备件导入
/// </summary>

224
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs

@ -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
}

40
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs

@ -127,23 +127,12 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
_version = pubSaImportRequestDto.Version;
switch (pubSaImportRequestDto.BusinessType)
{
case EnumBusinessType.None:
break;
case EnumBusinessType.JisBBAC:
break;
case EnumBusinessType.JisHBPO:
break;
case EnumBusinessType.ZhiGongJianBBAC:
result = await ImportZhiGongJianBBACAsync(pubSaImportRequestDto.Files).ConfigureAwait(false);
break;
case EnumBusinessType.ZhiGongJianHBPO:
result = await ImportZhiGongJianHBPOAsync(pubSaImportRequestDto.Files).ConfigureAwait(false);
break;
case EnumBusinessType.MaiDanJianBBAC:
break;
case EnumBusinessType.MaiDanJianHBPO:
result = await ImportMaiDanJianHBPOAsync(pubSaImportRequestDto.Files).ConfigureAwait(false);
break;
case EnumBusinessType.BeiJian:
result = await ImportBeiJianAsync(pubSaImportRequestDto.Files).ConfigureAwait(false);
break;
@ -296,35 +285,6 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianHBPO).ConfigureAwait(false);
}
/// <summary>
/// 买单件HBPO导入
/// </summary>
private async Task<IActionResult> ImportMaiDanJianHBPOAsync([FromForm] IFormFileCollection files)
{
#region 导入数据转换
ExportImporter _exportImporter = new ExportImporter();
var importResults = await _exportImporter.UploadExcelImport<MaiDanJianHBPOImportDto>(files, _excelImportService).ConfigureAwait(false);
var importPubSaDetails = ObjectMapper.Map<List<MaiDanJianHBPOImportDto>, List<PUB_SA_DETAIL>>(importResults);
#endregion
if (!importPubSaDetails.Any())
{
return new JsonResult(new { Code = 200, Message = "导入成功" });
}
#region 数据校验
var checkList = await CheckAsync(importPubSaDetails);
if (checkList.Count > 0)
{
string fileName = await ExportErrorReportAsync(checkList);
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, fileName = fileName });
}
#endregion
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.BeiJian).ConfigureAwait(false);
}
/// <summary>
/// 备件导入
/// </summary>

2
code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

@ -1069,6 +1069,7 @@ namespace Win.Sfs.SettleAccount
CreateMap<HBPO_SA_DETAIL, HBPO_SA_DETAIL_EXPORT_DTO>();
CreateMap<HBPO_SA_DETAIL_IMPORT_DTO, HBPO_SA_DETAIL>();
CreateMap<MaiDanJianHBPOImportDto, HBPO_SA_DETAIL>();
}
/// <summary>
@ -1103,7 +1104,6 @@ namespace Win.Sfs.SettleAccount
CreateMap<ZhiGongJianBBACImportDto, PUB_SA_DETAIL>();
CreateMap<ZhiGongJianHBPOImportDto, PUB_SA_DETAIL>();
CreateMap<MaiDanJianHBPOImportDto, PUB_SA_DETAIL>();
CreateMap<BeiJianImportDto, PUB_SA_DETAIL>()
.ForMember(x => x.ExtraProperties, y => y.MapFrom(d =>
new Dictionary<string, object>()

Loading…
Cancel
Save