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 028e8307..25c2909f 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 @@ -66,6 +66,11 @@ public class PUB_SAImportRequestDto /// [Display(Name = "期间")] public int Version { get; set; } + /// + /// 地点 + /// + [Display(Name = "地点")] + public string Site { get; set; } } /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs index ed086fb5..d7691e36 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs @@ -65,42 +65,36 @@ public class PriceListExportDto [Display(Name = "零件号")] [ExporterHeader(DisplayName = "客户零件号")] public string LU { get; set; } - /// /// 价格 /// [Display(Name = "价格")] [ExporterHeader(DisplayName = "价格")] public Decimal Price { set; get; } - /// /// 开始时间 /// [Display(Name = "开始时间")] [ExporterHeader(DisplayName = "开始时间")] public DateTime BeginTime { set; get; } - /// /// 结束时间 /// [Display(Name = "结束时间")] [ExporterHeader(DisplayName = "结束时间")] public DateTime EndTime { set; get; } - /// /// 客户编码 /// [Display(Name = "客户编码")] [ExporterHeader(DisplayName = "客户编码")] public string ClientCode { get; set; } - /// /// 合同签订时间 /// [Display(Name = "合同签订时间")] [ExporterHeader(DisplayName = "合同签订时间")] public DateTime Date { get; set; } - /// /// 合同号 /// @@ -112,8 +106,7 @@ public class PriceListExportDto /// /// 销售价格导入 /// -[ImportProject(Name = SettleAccountModuleName.PriceList)] -[Importer(HeaderRowIndex = 21)] +[Importer(HeaderRowIndex = 22)] public class PriceListImportDto { /// @@ -138,7 +131,7 @@ public class PriceListImportDto /// /// 价格 /// - [ImporterHeader(Name = "Total Price (Old)")] + [ImporterHeader(Name = "Total Price")] public decimal TotalPrice { get; set; } /// /// 开始时间 @@ -297,56 +290,58 @@ public class PriceListBJExportDto /// /// 客户备件价格导入 /// +[Importer(HeaderRowIndex = 22)] public class PriceListBJImportDto { /// - /// 客户零件号 + /// 合同签订时间 /// - [Display(Name = "客户零件号")] - [ImporterHeader(Name = "客户零件号")] - public string LU { get; set; } - + [ImporterHeader(IsIgnore = true)] + [ExcelImporterHeadDesc(Row = 1, Cell = 1)] + public string Date { get; set; } + /// + /// 合同号 + /// + [ImporterHeader(IsIgnore = true)] + [ExcelImporterHeadDesc(Row = 2, Cell = 1)] + public string ContractNo { get; set; } + /// + /// 零件号 + /// + [Display(Name = "零件号")] + [Required(ErrorMessage = "{0}是必填项")] + [ImporterHeader(Name = "Part No.")] + public string PartNo { get; set; } /// /// 价格 /// - [Display(Name = "价格")] - [ImporterHeader(Name = "价格")] - public decimal Price { get; set; } - + [ImporterHeader(Name = "Total Price")] + public decimal TotalPrice { get; set; } /// /// 开始时间 /// - [Display(Name = "开始时间")] - [ImporterHeader(Name = "开始时间")] - public DateTime BeginDate { set; get; } - + [ImporterHeader(Name = "Valid From")] + public DateTime ValidFrom { get; set; } /// /// 结束时间 /// - [Display(Name = "结束时间")] - [ImporterHeader(Name = "结束时间")] - public DateTime EndDate { set; get; } - + [ImporterHeader(Name = "Valid To")] + public DateTime ValidTo { get; set; } /// /// 客户编码 /// - [Display(Name = "客户编码")] - [ImporterHeader(Name = "客户编码")] - public string ClientCode { get; set; } - + [ImporterHeader(Name = "Plant")] + public string Plant { get; set; } /// - /// 合同签订时间 + /// ES1 /// - [Display(Name = "合同签订时间")] - [ImporterHeader(Name = "合同签订时间")] - public DateTime Date { get; set; } - + [ImporterHeader(Name = "ES1")] + public string ES1 { get; set; } /// - /// 合同号 + /// ES2 /// - [Display(Name = "合同号")] - [ImporterHeader(Name = "合同号")] - public string ContractNo { get; set; } + [ImporterHeader(Name = "ES2")] + public string ES2 { get; set; } } public class PriceListBJRequestDto : RequestInputBase diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs index 76239a8b..97e06950 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs @@ -31,6 +31,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ; [Route("api/settleaccount/[controller]/[action]")] public class BBAC_SA_SERVICE : SettleAccountApplicationBase { + /// + /// DbContext + /// + private readonly SettleAccountDbContext _settleAccountDbContext; /// /// BBAC结算仓储 /// @@ -79,7 +83,8 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase /// /// 构造 /// - public BBAC_SA_SERVICE(INormalEfCoreRepository bbacSaRepository, + public BBAC_SA_SERVICE(SettleAccountDbContext settleAccountDbContext, + INormalEfCoreRepository bbacSaRepository, INormalEfCoreRepository bbacSaDetailRepository, INormalEfCoreRepository bbacCanSaRepository, INormalEfCoreRepository bbacCanSaDetailRepository, @@ -93,6 +98,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase ICommonManager commonManager ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) { + _settleAccountDbContext = settleAccountDbContext; _bbacSaRepository = bbacSaRepository; _bbacSaDetailRepository = bbacSaDetailRepository; _bbacCanSaRepository = bbacCanSaRepository; @@ -400,7 +406,8 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase //导入的零件号集合 var importPubSaLUs = bbacSaDetails.Select(t => t.LU).Distinct(); //销售价格 - var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false).Where(t => importPubSaLUs.Contains(t.LU)).ToList(); + + var priceListEntitys = GetPriceListEntitys(importPubSaLUs); var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); bbacSaDetails.ForEach(bbacSaDetail => { @@ -507,5 +514,18 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase return (bbacSas, bbacSaDetails, bbacCanSas, bbacCanSaDetails, bbacNotSaDetails); } + + /// + /// 获取价格 + /// + private List GetPriceListEntitys(IEnumerable importSaLus) + { + var clientCode = Site; + return _settleAccountDbContext.Set() + .Where(t => t.IsCancel == false) + .Where(t => t.ClientCode == clientCode) + .Where(t => importSaLus.Contains(t.LU)) + .ToList(); + } #endregion } 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 186c333f..3a5e00c1 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 @@ -370,7 +370,9 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase //导入的零件号集合 var importPubSaLUs = hbpoSaDetails.Select(t => t.LU).Distinct(); //销售价格 - var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false).Where(t => importPubSaLUs.Contains(t.LU)).ToList(); + var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false) + .Where(t => t.ClientCode == "104T") + .Where(t => importPubSaLUs.Contains(t.LU)).ToList(); var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); hbpoSaDetails.ForEach(hbpoSaDetail => { 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 17361fa7..baaa6015 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 @@ -39,42 +39,34 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase /// PUB结算仓储 /// private readonly INormalEfCoreRepository _repository; - /// /// PUB结算明细仓储 /// private readonly INormalEfCoreRepository _pubSaDetailRepository; - /// /// PUB可结算仓储 /// private readonly INormalEfCoreRepository _pubCanSaRepository; - /// /// PUB可结算明细仓储 /// private readonly INormalEfCoreRepository _pubCanSaDetailRepository; - /// /// PUB不可结算明细仓储 /// private readonly INormalEfCoreRepository _pubNotSaDetailRepository; - /// /// 销售价格仓储 /// private readonly INormalEfCoreRepository _priceListRepository; - /// /// 备件价格仓储 /// private readonly INormalEfCoreRepository _priceBjListRepository; - /// /// 客户零件关系仓储 /// private readonly INormalEfCoreRepository _materialRelationshipRepository; - /// /// 替换件关系仓储 /// @@ -113,6 +105,14 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase /// 期间 /// private int _version; + /// + /// 业务类别 + /// + private EnumBusinessType businessType; + /// + /// 地点 + /// + private string site; #region 导入、导出 /// @@ -123,6 +123,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase { IActionResult result = new JsonResult(new { Code = 400 }); _version = pubSaImportRequestDto.Version; + businessType = pubSaImportRequestDto.BusinessType; + site = pubSaImportRequestDto.Site; switch (pubSaImportRequestDto.BusinessType) { case EnumBusinessType.ZhiGongJianBBAC: @@ -440,10 +442,21 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase importPubSaDetail.BusinessType = businessType; }); var lus = pubSaDetails.Select(t => t.LU).Distinct().ToList(); + + var clientCode = businessType switch + { + EnumBusinessType.ZhiGongJianBBAC => site, + EnumBusinessType.ZhiGongJianHBPO => "104T", + EnumBusinessType.BeiJian => "1040", + EnumBusinessType.YinDuJian => "1040", + _ => throw new UserFriendlyException($"业务编码错误", "400") + }; + if (businessType == EnumBusinessType.BeiJian) { //备件销售价格 var priceListEntitys = _priceBjListRepository.Where(t => t.IsCancel == false) + .Where(t => t.ClientCode == clientCode) .Where(t => lus.Contains(t.LU)).ToList(); pubSaDetails.ForEach(importPubSaDetail => { @@ -461,6 +474,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase { //销售价格 var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false) + .Where(t => t.ClientCode == clientCode) .Where(t => lus.Contains(t.LU)).ToList(); pubSaDetails.ForEach(importPubSaDetail => { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs index 5f80eb94..238be6be 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs @@ -14,6 +14,7 @@ using Volo.Abp.Caching; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.CommonManagers; +using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; @@ -29,7 +30,7 @@ namespace Win.Sfs.SettleAccount.Entities.Prices; public class PriceListAppService : SettleAccountApplicationBase { /// - /// 数据上下文 + /// DbContext /// private readonly SettleAccountDbContext _settleAccountDbContext; /// @@ -78,8 +79,29 @@ public class PriceListAppService : SettleAccountApplicationBase }; result = result.FindAll(p => filter.Contains(p.Plant)).ToList(); result.FindAll(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2); - var entityList = ObjectMapper.Map, List>(result); - var newPrice = entityList.GroupBy(p => p.LU).Select(p => p.FirstOrDefault()).ToList(); + var newPrice = ObjectMapper.Map, List>(result); + newPrice = newPrice.GroupBy(p => new { p.LU, p.ClientCode, p.BeginTime, p.EndTime }).Select(p => p.FirstOrDefault()).ToList(); + + #region 校验 + if (newPrice.Any()) + { + var query = from item1 in newPrice + join item2 in newPrice + on new { item1.LU, item1.ClientCode } equals new { item2.LU, item2.ClientCode } + where (item1.BeginTime > item2.BeginTime && item1.EndTime < item2.EndTime) || (item2.BeginTime > item1.BeginTime && item2.EndTime < item1.EndTime) || (item1.BeginTime == item2.BeginTime && item1.EndTime != item2.EndTime) || (item1.BeginTime != item2.BeginTime && item1.EndTime == item2.EndTime) + select item1.LU; + var repeat = query.Distinct().ToList(); + foreach (var item in repeat) + { + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间存在交集", string.Empty)); + } + } + if (checkList.Count > 0) + { + var fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); + return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName }); + } + #endregion var importLus = newPrice.Select(t => t.LU).Distinct().ToList(); var oldPrices = _settleAccountDbContext.Set() @@ -87,14 +109,14 @@ public class PriceListAppService : SettleAccountApplicationBase .Where(t => importLus.Contains(t.LU)) .ToList(); //系统中合同日期比导入文件中的合同日期晚 - var oldpriceNewDate = from oldprice in oldPrices + var oldPriceNewDate = from oldprice in oldPrices from newprice in newPrice where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date select oldprice; oldPrices.ForEach(t => t.IsCancel = true); - if (oldpriceNewDate.Any()) + if (oldPriceNewDate.Any()) { - oldPrices.FindAll(t => oldpriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); + oldPrices.FindAll(t => oldPriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); var importCancelLus = oldPrices.Select(t => t.LU).Distinct(); newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs index 0d733857..408ce3bc 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs @@ -12,6 +12,7 @@ using Volo.Abp.Caching; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.CommonManagers; +using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; @@ -57,13 +58,33 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase var result = await _exportImporter.UploadExcelImportByHeadDesc(files, _excelImportService).ConfigureAwait(false); var filter = new List { - "1040", - "1046", - "104T" + "1040" }; - result = result.Where(p => filter.Contains(p.ClientCode)).ToList(); - var entityList = ObjectMapper.Map, List>(result); - var newPrice = entityList.GroupBy(p => p.LU).Select(p => p.FirstOrDefault()).ToList(); + result = result.Where(p => filter.Contains(p.Plant)).ToList(); + result.FindAll(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2); + var newPrice = ObjectMapper.Map, List>(result); + newPrice = newPrice.GroupBy(p => new { p.LU, p.BeginDate, p.EndDate }).Select(p => p.FirstOrDefault()).ToList(); + + #region 校验 + if (newPrice.Any()) + { + var query = from item1 in newPrice + join item2 in newPrice + on item1.LU equals item2.LU + where (item1.BeginDate > item2.BeginDate && item1.EndDate < item2.EndDate) || (item2.BeginDate > item1.BeginDate && item2.EndDate < item1.EndDate) || (item1.BeginDate == item2.BeginDate && item1.EndDate != item2.EndDate) || (item1.BeginDate != item2.BeginDate && item1.EndDate == item2.EndDate) + select item1.LU; + var repeat = query.Distinct().ToList(); + foreach (var item in repeat) + { + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间存在交集", string.Empty)); + } + } + if (checkList.Count > 0) + { + var fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); + return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName }); + } + #endregion var importLus = newPrice.Select(t => t.LU).Distinct().ToList(); var oldPrices = _settleAccountDbContext.Set() @@ -71,14 +92,14 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase .Where(t => importLus.Contains(t.LU)) .ToList(); //系统中合同日期比导入文件中的合同日期晚 - var oldpriceNewDate = from oldprice in oldPrices + var oldPriceNewDate = from oldprice in oldPrices from newprice in newPrice where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date select oldprice; oldPrices.ForEach(t => t.IsCancel = true); - if (oldpriceNewDate.Any()) + if (oldPriceNewDate.Any()) { - oldPrices.FindAll(t => oldpriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); + oldPrices.FindAll(t => oldPriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); var importCancelLus = oldPrices.Select(t => t.LU).Distinct(); newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index ceb8bda0..3b24f6a3 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -577,7 +577,13 @@ namespace Win.Sfs.SettleAccount /// private void CreateMapPriceListBJ() { - CreateMap(); + CreateMap() + .ForMember(x => x.LU, y => y.MapFrom(y => y.PartNo)) + .ForMember(x => x.Price, y => y.MapFrom(y => y.TotalPrice)) + .ForMember(x => x.BeginDate, y => y.MapFrom(y => y.ValidFrom)) + .ForMember(x => x.EndDate, y => y.MapFrom(y => y.ValidTo)) + .ForMember(x => x.ClientCode, y => y.MapFrom(y => y.Plant)) + .ForMember(x => x.Date, y => y.MapFrom(y => DateTime.ParseExact(y.Date, "dd.MM.yyyy", System.Globalization.CultureInfo.CurrentCulture))); ; CreateMap().ReverseMap(); CreateMap().ReverseMap(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/PubSaSeCompareDiff.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/PubSaSeCompareDiff.cs index ff8f2efb..73ca86fc 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/PubSaSeCompareDiff.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/PubSaSeCompareDiff.cs @@ -11,6 +11,11 @@ namespace Win.Sfs.SettleAccount.Reports; /// public class PubSaSeCompareDiff { + /// + /// 期间 + /// + [Display(Name = "期间")] + public int Version { get; set; } /// /// Wms发货单号 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs index dcac44aa..381ef95c 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Drawing; using System.Linq; using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.SignalR; using Microsoft.OpenApi.Extensions; using SettleAccount.Domain.BQ; using SettleAccount.Job.SignalR; +using ShardingCore.Extensions; using Shouldly; using TaskJob.EventArgs; using TaskJob.Interfaces; @@ -178,7 +180,8 @@ namespace SettleAccount.Job.Services.Report /// /// 获取比对数据 /// - public List GetSaSeCompareData(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime) + [Obsolete] + private List GetSaSeCompareData(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime) { //印度件LU对比 if (businessType == EnumBusinessType.YinDuJian) @@ -264,7 +267,122 @@ namespace SettleAccount.Job.Services.Report /// /// 获取比对数据 /// - public List GetSaSeCompareDataYinDu(int version, DateTime seStartDateTime, DateTime seEndDateTime) + private List GetSaSeCompareDataOld(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime) + { + //印度件LU对比 + if (businessType == EnumBusinessType.YinDuJian) + { + return GetSaSeCompareDataYinDu(version, seStartDateTime, seEndDateTime); + } + //结算 + var saGroup = from sa in _settleAccountDbContext.Set() + where sa.BusinessType == businessType + group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem + select new + { + groupItem.Key.PN, + groupItem.Key.CustomerPartCodeNoSpace, + Id = groupItem.Max(t => t.Id), + Qty = groupItem.Sum(t => t.Qty), + Version = groupItem.Max(t => t.Version), + LU = groupItem.Max(t => t.LU), + SettleDate = groupItem.Max(t => t.SettleDate), + PartCode = groupItem.Max(t => t.PartCode), + }; + var saGroupByVersion = from sa in _settleAccountDbContext.Set() + where sa.BusinessType == businessType && sa.Version == version + group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem + select new + { + groupItem.Key.PN, + groupItem.Key.CustomerPartCodeNoSpace, + Qty = groupItem.Sum(t => t.Qty), + Version = groupItem.Max(t => t.Version), + LU = groupItem.Max(t => t.LU), + SettleDate = groupItem.Max(t => t.SettleDate), + PartCode = groupItem.Max(t => t.PartCode), + }; + //发运 + var seGroup = from se in _settleAccountDbContext.Set() + group se by new { se.PN, se.CustomerPartCodeNoSpace } into groupItem + select new + { + groupItem.Key.PN, + groupItem.Key.CustomerPartCodeNoSpace, + Qty = groupItem.Sum(t => t.Qty), + LU = groupItem.Max(t => t.LU), + WmsBillNum = groupItem.Max(t => t.WmsBillNum), + ShippingDate = groupItem.Max(t => t.ShippingDate), + FactoryPartCode = groupItem.Max(t => t.FactoryPartCode), + ToLocCode = groupItem.Max(t => t.ToLocCode), + ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) + }; + + //有结算无发运 + var haveSaNotHaveSeList = (from sa in saGroup + join se in seGroup + on new { sa.PN, sa.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace } + into temp + from se in temp.DefaultIfEmpty() + where se.PN == null + select new PubSaSeCompareDiff() + { + Version = sa.Version, + CustomerOfflineTime = sa.SettleDate, + PN = sa.PN, + SAQty = sa.Qty, + SaCustomerPartCode = sa.CustomerPartCodeNoSpace, + SaFactoryPartCode = sa.PartCode, + CustomerPartCode = sa.LU + }).ToList(); + //无结算有发运 + var notHaveSaHaveSeList = (from se in seGroup + join sa in saGroup + on new { se.PN, se.CustomerPartCodeNoSpace } equals new { sa.PN, sa.CustomerPartCodeNoSpace } + into temp + from sa in temp.DefaultIfEmpty() + where sa.PN == null + select new PubSaSeCompareDiff() + { + WmsBillNum = se.WmsBillNum, + ShippingDate = se.ShippingDate, + PN = se.PN, + SEQty = se.Qty, + ToLocCode = se.ToLocCode, + ToErpLocCode = se.ToErpLocCode, + SeCustomerPartCode = se.CustomerPartCodeNoSpace, + SeFactoryPartCode = se.FactoryPartCode, + CustomerPartCode = se.LU + }).ToList(); + + //有结算有发运 + var haveSaHaveSeList = (from sa in saGroupByVersion + from se in seGroup + where sa.PN == se.PN && sa.CustomerPartCodeNoSpace == se.CustomerPartCodeNoSpace + select new PubSaSeCompareDiff() + { + Version = sa.Version, + WmsBillNum = se.WmsBillNum, + ShippingDate = se.ShippingDate, + CustomerOfflineTime = sa.SettleDate, + PN = sa.PN, + SAQty = sa.Qty, + SEQty = se.Qty, + ToLocCode = se.ToLocCode, + ToErpLocCode = se.ToErpLocCode, + SeCustomerPartCode = se.CustomerPartCodeNoSpace, + SeFactoryPartCode = se.FactoryPartCode, + SaCustomerPartCode = sa.CustomerPartCodeNoSpace, + SaFactoryPartCode = sa.PartCode, + CustomerPartCode = sa.LU + }).ToList(); + return haveSaHaveSeList.Union(haveSaHaveSeList).Union(notHaveSaHaveSeList).ToList(); + } + + /// + /// 获取比对数据 + /// + private List GetSaSeCompareDataYinDu(int version, DateTime seStartDateTime, DateTime seEndDateTime) { var saGroup = from sa in _settleAccountDbContext.Set() where sa.BusinessType == EnumBusinessType.YinDuJian && sa.Version == version diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs index fb9fd5a2..6af50bd3 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs @@ -198,12 +198,10 @@ namespace SettleAccount.Job.Services.Report < 0 => EnumMappingType.None, _ => default, }; - o.ExtraProperties.Add("MappingType", mappingType); + o.MappingType = mappingType; return o; }).ToList(); _settleAccountDbContext.BulkUpdate(saDetailsUpdate); - _settleAccountDbContext.Set().FromSqlInterpolated($"SELECT * FROM dbo.Blogs"); - _settleAccountDbContext.Database.ExecuteSqlInterpolated($"SELECT * FROM dbo.Blogs"); } } }