diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs index bd781f4e..41019532 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs @@ -107,7 +107,10 @@ public class HBPOSaImportRequestDto /// 文件 /// public IFormFileCollection Files { get; set; } - + /// + /// 业务类别 + /// + public EnumBusinessType BusinessType { get; set; } /// /// 期间 /// @@ -175,6 +178,46 @@ public class HBPO_SA_DETAIL_IMPORT_DTO public string PN { get; set; } } +/// +/// 买单件HBPO导入 +/// +public class MaiDanJianHBPOImportDto +{ + /// + /// 结算日期 + /// + [Display(Name = "买单日期")] + [ImporterHeader(Name = "买单日期")] + public DateTime SettleDate { set; get; } + /// + /// 客户零件号 + /// + [Display(Name = "零件号")] + [Required(ErrorMessage = "{0}不能为空")] + [ImporterHeader(Name = "零件号")] + public string LU { get; set; } + /// + /// 生产号 + /// + [Display(Name = "现产品生产号")] + [ImporterHeader(Name = "现产品生产号")] + [Required(ErrorMessage = "{0}不能为空")] + public string PN { get; set; } + /// + /// 数量 + /// + [Display(Name = "数量")] + [ImporterHeader(Name = "数量")] + public decimal Qty { get; set; } + /// + /// 结算分组号 + /// + [Display(Name = "五联单号")] + [ImporterHeader(Name = "五联单号")] + [Required(ErrorMessage = "{0}不能为空")] + public string GroupNum { get; set; } +} + /// /// 结算明细导出请求 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs index e805ef29..028e8307 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs @@ -57,12 +57,10 @@ public class PUB_SAImportRequestDto /// 文件 /// public IFormFileCollection Files { get; set; } - /// /// 业务类别 /// public EnumBusinessType BusinessType { get; set; } - /// /// 期间 /// @@ -165,50 +163,6 @@ public class ZhiGongJianHBPOImportDto public string GroupNum { get; set; } } -/// -/// 买单件HBPO导入 -/// -public class MaiDanJianHBPOImportDto -{ - /// - /// 结算日期 - /// - [Display(Name = "买单日期")] - [ImporterHeader(Name = "买单日期")] - public DateTime SettleDate { set; get; } - - /// - /// 客户零件号 - /// - [Display(Name = "零件号")] - [Required(ErrorMessage = "{0}不能为空")] - [ImporterHeader(Name = "零件号")] - public string LU { get; set; } - - /// - /// 生产号 - /// - [Display(Name = "现产品生产号")] - [ImporterHeader(Name = "现产品生产号")] - [Required(ErrorMessage = "{0}不能为空")] - public string PN { get; set; } - - /// - /// 数量 - /// - [Display(Name = "数量")] - [ImporterHeader(Name = "数量")] - public decimal Qty { get; set; } - - /// - /// 结算分组号 - /// - [Display(Name = "五联单号")] - [ImporterHeader(Name = "五联单号")] - [Required(ErrorMessage = "{0}不能为空")] - public string GroupNum { get; set; } -} - /// /// 备件导入 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs index 317d971f..ede465f8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs +++ b/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 [HttpPost] public async Task ImportAsync([FromForm] HBPOSaImportRequestDto hbpoSaImportRequestDto) { + IActionResult result = new JsonResult(new { Code = 400 }); Version = hbpoSaImportRequestDto.Version; - #region 导入数据转换、数据校验 - ExportImporter _exportImporter = new ExportImporter(); - var result = await _exportImporter.UploadExcelImport(hbpoSaImportRequestDto.Files, _excelImportService).ConfigureAwait(false); - var importHBOPSaDetails = ObjectMapper.Map, List>(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(); - //结算分组号 - 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 #endregion #region 私有方法 + /// + /// JisHBPO导入 + /// + private async Task ImportJisHBPOAsync([FromForm] IFormFileCollection files) + { + ExportImporter _exportImporter = new ExportImporter(); + var result = await _exportImporter.UploadExcelImport(files, _excelImportService).ConfigureAwait(false); + var importHBOPSaDetails = ObjectMapper.Map, List>(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 = "导入成功" }); + } + + /// + /// 买单件HBPO导入 + /// + private async Task ImportMaiDanJianHBPOAsync([FromForm] IFormFileCollection files) + { + #region 导入数据转换 + var exportImporter = new ExportImporter(); + var importResults = await exportImporter.UploadExcelImport(files, _excelImportService).ConfigureAwait(false); + var importMaiDanHBPOSaDetails = ObjectMapper.Map, List>(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 = "导入成功" }); + } + /// /// 结算数据处理 /// @@ -275,7 +287,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase 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 private async Task<(List hbpoSas, List hbpoSaDetails, List hbpoCanSas, List hbpoCanSaDetails, List hbpoNotSaDetails)> GetHBPOSaDelItemsAsync(Guid id) { //结算主表 - List hbpoSas = new List(); + var hbpoSas = new List(); //结算明细 - List hbpoSaDetails = new List(); + var hbpoSaDetails = new List(); //可结算主表 - List hbpoCanSas = new List(); + var hbpoCanSas = new List(); //可结算明细 - List hbpoCanSaDetails = new List(); + var hbpoCanSaDetails = new List(); //不可结算 - List hbpoNotSaDetails = new List(); + var hbpoNotSaDetails = new List(); 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 //结算单据 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 return (hbpoSas, hbpoSaDetails, hbpoCanSas, hbpoCanSaDetails, hbpoNotSaDetails); } + + /// + /// 结算数据处理 + /// + private void HandleSaDetails(List 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; + }); + } + + /// + /// 数据校验 + /// + private async Task> CheckAsync(List hbpoSaDetails) + { + #region 数据校验 + //数据校验 + var checkList = new List(); + //结算分组号 + 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 } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs index 9fd1a10a..5097acda 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs @@ -127,23 +127,12 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase _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 return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianHBPO).ConfigureAwait(false); } - /// - /// 买单件HBPO导入 - /// - private async Task ImportMaiDanJianHBPOAsync([FromForm] IFormFileCollection files) - { - #region 导入数据转换 - ExportImporter _exportImporter = new ExportImporter(); - var importResults = await _exportImporter.UploadExcelImport(files, _excelImportService).ConfigureAwait(false); - - var importPubSaDetails = ObjectMapper.Map, List>(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); - } - /// /// 备件导入 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index db713adb..37704e7f 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -1069,6 +1069,7 @@ namespace Win.Sfs.SettleAccount CreateMap(); CreateMap(); + CreateMap(); } /// @@ -1103,7 +1104,6 @@ namespace Win.Sfs.SettleAccount CreateMap(); CreateMap(); - CreateMap(); CreateMap() .ForMember(x => x.ExtraProperties, y => y.MapFrom(d => new Dictionary()