From 2d1f32532ef97a439be76d0511f28f7a247c3698 Mon Sep 17 00:00:00 2001 From: mahao Date: Wed, 2 Aug 2023 14:29:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9EJis=E7=BB=93=E7=AE=97=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/Dtos/PUB_SA_DTO.cs | 176 +++++++++++ .../Entities/BQ/PUB_SA_SERVICE.cs | 296 +++++++++++++++++- ...ttleAccountApplicationAutoMapperProfile.cs | 4 + 3 files changed, 472 insertions(+), 4 deletions(-) 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 afc591b0..926de242 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,6 +57,182 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos public EnumBusinessType BusinessType { get; set; } } + /// + /// 直供件BBAC导入 + /// + public class ZhiGongJianBBACImportDto + { + /// + /// 结算日期 + /// + [Display(Name = "Pstng Date")] + [ImporterHeader(Name = "Pstng Date")] + public DateTime SettleDate { set; get; } + + /// + /// 零件号 + /// + [Display(Name = "Material")] + [Required(ErrorMessage = "{0}不能为空")] + [ImporterHeader(Name = "Material")] + public string LU { get; set; } + + /// + /// 生产号 + /// + [Display(Name = "External Delivery ID")] + [ImporterHeader(Name = "External Delivery ID")] + [Required(ErrorMessage = "{0}不能为空")] + public string PN { get; set; } + + /// + /// 数量 + /// + [Display(Name = "Quantity")] + [ImporterHeader(Name = "Quantity")] + public decimal Qty { get; set; } + + /// + /// 结算分组号 + /// + [Display(Name = "Delivery")] + [ImporterHeader(Name = "Delivery")] + [Required(ErrorMessage = "{0}不能为空")] + public string GroupNum { get; set; } + } + + /// + /// 直供件HBPO导入 + /// + public class ZhiGongJianHBPOImportDto + { + /// + /// 结算日期 + /// + [Display(Name = "结算日期")] + [ImporterHeader(IsIgnore = true)] + 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; } + } + + /// + /// 备件导入 + /// + public class BeiJianImportDto + { + /// + /// 结算日期 + /// + [Display(Name = "结算日期")] + [ImporterHeader(IsIgnore = true)] + 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; } + } + + /// + /// 印度件导入 + /// + public class YinDuJianImportDto + { + /// + /// 结算日期 + /// + [Display(Name = "Delivery Date")] + [ImporterHeader(Name = "Delivery Date")] + public DateTime SettleDate { set; get; } + + /// + /// 零件号 + /// + [Display(Name = "Material")] + [Required(ErrorMessage = "{0}不能为空")] + [ImporterHeader(Name = "Material")] + public string LU { get; set; } + + /// + /// 生产号 + /// + [Display(Name = "External Delivery ID")] + [ImporterHeader(Name = "External Delivery ID")] + [Required(ErrorMessage = "{0}不能为空")] + public string PN { get; set; } + + /// + /// 数量 + /// + [Display(Name = "数量")] + [ImporterHeader(Name = "Item")] + public decimal Qty { get; set; } + + /// + /// 结算分组号 + /// + [Display(Name = "External Delivery ID")] + [ImporterHeader(Name = "External Delivery ID")] + [Required(ErrorMessage = "{0}不能为空")] + public string GroupNum { get; set; } + } + /// /// 导入 /// 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 57545332..75c4e6cb 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 @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; +using Magicodes.ExporterAndImporter.Core.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -107,7 +109,36 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase [HttpPost] public async Task ImportByBusinessTypeAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto) { - return await ImportAsync(pubSaImportRequestDto.Files, pubSaImportRequestDto.BusinessType); + string result = string.Empty; + //return await ImportAsync(pubSaImportRequestDto.Files, pubSaImportRequestDto.BusinessType); + switch (pubSaImportRequestDto.BusinessType) + { + case EnumBusinessType.None: + break; + case EnumBusinessType.JisBBAC: + break; + case EnumBusinessType.JisHBPO: + break; + case EnumBusinessType.ZhiGongJianBBAC: + result = await ImportZhiGongJianBBACAsync(pubSaImportRequestDto.Files); + break; + case EnumBusinessType.ZhiGongJianHBPO: + result = await ImportZhiGongJianHBPOAsync(pubSaImportRequestDto.Files); + break; + case EnumBusinessType.MaiDanJianBBAC: + break; + case EnumBusinessType.MaiDanJianHBPO: + break; + case EnumBusinessType.BeiJian: + result = await ImportBeiJianAsync(pubSaImportRequestDto.Files); + break; + case EnumBusinessType.YinDuJian: + result = await ImportYinDuJianAsync(pubSaImportRequestDto.Files); + break; + default: + break; + } + return result; } #endregion @@ -155,7 +186,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase { throw; } - + //删除 if (pubSas.Any()) { @@ -242,6 +273,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase /// /// 导入 /// + [Obsolete(message: "过时废弃")] private async Task ImportAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) { //数据校验 @@ -393,6 +425,262 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase return ApplicationConsts.SuccessStr; } + /// + /// 直供件BBAC导入 + /// + private async Task ImportZhiGongJianBBACAsync([FromForm] IFormFileCollection files) + { + #region 导入数据转换 + ExportImporter _exportImporter = new ExportImporter(); + var importResults = await _exportImporter.UploadExcelImport(files, _excelImportService); + var importPubSaDetails = ObjectMapper.Map, List>(importResults); + #endregion + + #region 数据校验 + var checkList = await CheckAsync(importPubSaDetails); + if (checkList.Count > 0) + { + return await ExportErrorReportAsync(checkList); + } + #endregion + + return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianBBAC); + } + + /// + /// 直供件HBPO导入 + /// + private async Task ImportZhiGongJianHBPOAsync([FromForm] IFormFileCollection files) + { + #region 导入数据转换 + ExportImporter _exportImporter = new ExportImporter(); + var importResults = await _exportImporter.UploadExcelImport(files, _excelImportService); + + //截取结算分组前8位为结算日期 + importResults.ForEach(importResult => + { + importResult.SettleDate = DateTime.ParseExact(importResult.GroupNum.Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture); + }); + + var importPubSaDetails = ObjectMapper.Map, List>(importResults); + #endregion + + #region 数据校验 + var checkList = await CheckAsync(importPubSaDetails); + if (checkList.Count > 0) + { + return await ExportErrorReportAsync(checkList); + } + #endregion + + return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianHBPO); + } + + /// + /// 备件导入 + /// + private async Task ImportBeiJianAsync([FromForm] IFormFileCollection files) + { + #region 导入数据转换 + ExportImporter _exportImporter = new ExportImporter(); + var importResults = await _exportImporter.UploadExcelImport(files, _excelImportService); + + importResults.ForEach(importResult => + { + importResult.SettleDate = DateTime.Now; + }); + + var importPubSaDetails = ObjectMapper.Map, List>(importResults); + #endregion + + #region 数据校验 + var checkList = await CheckAsync(importPubSaDetails); + if (checkList.Count > 0) + { + return await ExportErrorReportAsync(checkList); + } + #endregion + + return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.BeiJian); + } + + /// + /// 备件导入 + /// + private async Task ImportYinDuJianAsync([FromForm] IFormFileCollection files) + { + #region 导入数据转换 + ExportImporter _exportImporter = new ExportImporter(); + var importResults = await _exportImporter.UploadExcelImport(files, _excelImportService); + var importPubSaDetails = ObjectMapper.Map, List>(importResults); + #endregion + + #region 数据校验 + var checkList = await CheckAsync(importPubSaDetails); + if (checkList.Count > 0) + { + return await ExportErrorReportAsync(checkList); + } + #endregion + + return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.YinDuJian); + } + + /// + /// 数据校验 + /// + private async Task> CheckAsync(List pubSaDetails) + { + #region 数据校验 + //数据校验 + var checkList = new List(); + //结算分组号 + var pubSaGroupNums = pubSaDetails.Select(t => t.GroupNum).Distinct(); + //已存在的结算分组号 + 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)); + } + } + return checkList; + #endregion + } + + /// + /// 结算数据处理 + /// + private async Task SaDataHandleAsync(List pubSaDetails, EnumBusinessType businessType) + { + //客户零件关系 + var materialRelationships = new List(); + + #region 处理结算数据 + //销售价格 + var priceListEntitys = await _priceListRepository.GetAllAsync(); + + pubSaDetails.ForEach(importPubSaDetail => + { + List 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.BusinessType = businessType; + 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; + }); + + //导入的零件号集合 + var importPubSaLUs = pubSaDetails.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 => + { + var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, businessType.ToString()); + materialRelationships.Add(materialRelationship); + }); + #endregion + + #region 添加入库 + await SeDataEntryAsync(pubSaDetails); + if (materialRelationships.Count > 0) + { + await _materialRelationshipRepository.InsertManyAsync(materialRelationships); + } + #endregion + + return ApplicationConsts.SuccessStr; + } + + /// + /// 结算数据入库 + /// + private async Task SeDataEntryAsync(List pubSaDetails) + { + //业务类型 + EnumBusinessType businessType = pubSaDetails.First().BusinessType; + //结算单号 + var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); + //结算主表 + var pubSa = new PUB_SA() + { + BillNum = pubSaBillNum, + State = "1", + BusinessType = businessType + }; + //可结算单号 + var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); + //可结算主表 + var pubCanSa = new PUB_CAN_SA() + { + BillNum = pubCanSaBillNum, + SettleBillNum = pubSaBillNum, + State = SettleBillState.未结状态, + BusinessType = businessType + }; + + #region 入库数据赋值 + pubSaDetails.ForEach(pubSaDetail => + { + pubSaDetail.BillNum = pubSaBillNum; + }); + //不可结算 结算分组号码(根据价格区分结算、不可结算) + var pubNotSaGroupNums = pubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); + var pubSaDetailsCanSes = pubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false); + var pubSaDetailsNotCanSes = pubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true); + + //可结算明细 + var pubCanSaDetails = ObjectMapper.Map, List>(pubSaDetailsCanSes); + //不可结算明细 + var pubNotSaDetails = ObjectMapper.Map, List>(pubSaDetailsNotCanSes); + #endregion + + #region 添加入库 + await _repository.InsertAsync(pubSa); + await _pubSaDetailRepository.InsertManyAsync(pubSaDetails); + if (pubCanSaDetails.Count > 0) + { + pubCanSa.InvGroupNum = pubCanSaDetails.Count.ToString(); + pubCanSaDetails.ForEach(pubCanSaDetail => + { + pubCanSaDetail.BillNum = pubCanSaDetail.InvGroupNum = pubCanSaBillNum; + pubCanSaDetail.BusinessType = businessType; + }); + + await _pubCanSaRepository.InsertAsync(pubCanSa); + await _pubCanSaDetailRepository.InsertManyAsync(pubCanSaDetails); + } + if (pubNotSaDetails.Count > 0) + { + pubNotSaDetails.ForEach(pubNotSaDetail => + { + pubNotSaDetail.BusinessType = businessType; + }); + + await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); + } + #endregion + } + /// /// 获取结算关联项 /// @@ -417,7 +705,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase pubCanSas = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); //验证可结算主表状态 - if (pubCanSas.Any(t => t.State != SettleBillState.未结状态) == false) + if (pubCanSas.Any() && pubCanSas.Any(t => t.State != SettleBillState.未结状态)) { throw new UserFriendlyException($"{pubSaBillNum} 该单据可结算单状态无法删除!", "400"); } @@ -428,7 +716,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase pubNotSaDetails = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); } - return (pubSas, pubSaDetails, pubCanSas , pubCanSaDetails, pubNotSaDetails); + return (pubSas, pubSaDetails, pubCanSas, pubCanSaDetails, pubNotSaDetails); } #endregion } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index b911f33d..053b9c19 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -1021,6 +1021,10 @@ namespace Win.Sfs.SettleAccount CreateMap(); CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); } ///