diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs index c73775eb..cd7042ff 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs @@ -2,14 +2,9 @@ using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.DirectoryServices.ActiveDirectory; using System.Linq; using System.Reflection; -using System.Security.Policy; using System.Threading.Tasks; -using DocumentFormat.OpenXml.Spreadsheet; -using DocumentFormat.OpenXml.Drawing; -using DocumentFormat.OpenXml.Wordprocessing; using EFCore.BulkExtensions; using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Csv; @@ -17,17 +12,13 @@ using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.CodeAnalysis.Operations; -using Microsoft.OpenApi.Writers; +using Microsoft.Extensions.Logging; +using Polly; using SettleAccount.Domain.BQ; -using ShardingCore.Extensions; using Shouldly; using SqlSugar; -using Volo.Abp; using Volo.Abp.Application.Dtos; -using Volo.Abp.Application.Services; using Volo.Abp.Data; -using Volo.Abp.Domain.Entities; using Volo.Abp.Uow; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; @@ -35,23 +26,13 @@ using Win.Sfs.SettleAccount.Bases; using Win.Sfs.SettleAccount.Bases.DomainServices; using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.Constant; -using Win.Sfs.SettleAccount.Customers; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Managers; -using Win.Sfs.SettleAccount.Entities.BQ.Syncs; -using Win.Sfs.SettleAccount.Entities.BQ.Temp; -using Win.Sfs.SettleAccount.Entities.Invoices; using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; -using Win.Sfs.Shared.RepositoryBase; -using static Dm.parser.LVal; -using static LinqToDB.Sql; using Win.Sfs.Shared.Filter; -using Polly; -using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; -using Microsoft.Extensions.Logging; -using Castle.Core.Logging; +using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ { @@ -65,10 +46,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// private readonly SettleAccountDbContext _settleAccountDbContext; /// - /// WMS数据上下文 - /// - private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; - /// /// 数据中心数据上下文 /// private readonly ExChangeCenterDbContext _exChangeCenterDbContext; @@ -86,7 +63,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public INVOICE_SERVICE( ILogger logger, SettleAccountDbContext settleAccountDbContext, - WMSBJBMPTDbContext wmsBJBMPTContext, ExChangeCenterDbContext exChangeCenterDbContext, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, @@ -106,7 +82,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { _logger = logger; _settleAccountDbContext = settleAccountDbContext; - _wmsBJBMPTContext = wmsBJBMPTContext; _exChangeCenterDbContext = exChangeCenterDbContext; _baseservice = baseservice; _repository = repository; @@ -218,7 +193,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); invoiceGrp.State = SettleBillState.已提交QAD; //构建发票同步Qad状态表数据 - await BindInvoiceSyncQadAsync(taskId, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum).ConfigureAwait(false); + await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, "").ConfigureAwait(false); await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); var retryPolicyAsync = Policy.Handle().WaitAndRetryAsync(new[] { @@ -299,27 +274,23 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); //构建发票同步Qad状态表数据 - await BindInvoiceSyncQadAsync(taskId, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum).ConfigureAwait(false); + await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, "").ConfigureAwait(false); } } /// /// 构建发票同步Qad状态表数据 /// - [HttpPost] - public async Task InvoiceSyncQad(string invbillNum) + private async Task BindInvoiceSyncQadAsync(TEA_TASK_SUB teaTaskSub, string invoiceNumber, string sasInvoiceNumber, string customer, string voucher) { - var invoiceSyncQad = new InvoiceSyncQad(GuidGenerator.Create(), "", ""); - await _settleAccountDbContext.Set().AddAsync(invoiceSyncQad).ConfigureAwait(false); - await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false); - } - - /// - /// 构建发票同步Qad状态表数据 - /// - private async Task BindInvoiceSyncQadAsync(Guid taskID, string invoiceNumber, string sasInvoiceNumber) - { - var invoiceSyncQad = new InvoiceSyncQad(taskID, invoiceNumber, sasInvoiceNumber); + var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber) + { + TaskName = teaTaskSub.TableName, + Domain = teaTaskSub.Domain, + Site = teaTaskSub.Site, + Customer = customer, + Voucher = voucher + }; await _settleAccountDbContext.Set().AddAsync(invoiceSyncQad).ConfigureAwait(false); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/InvoiceSyncQadService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/InvoiceSyncQadService.cs index 29f7ca8a..46bd611c 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/InvoiceSyncQadService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/InvoiceSyncQadService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using SettleAccount.Domain.BQ; using Shouldly; using Volo.Abp.Application.Dtos; @@ -13,6 +14,7 @@ using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.ExcelImporter; +using Win.Sfs.SettleAccount.Options; using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ @@ -26,10 +28,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { private readonly ILogger _logger; private readonly INormalEfCoreRepository _repository; + private readonly IOptions _globalConfigOptions; public InvoiceSyncQadService( ILogger logger, INormalEfCoreRepository repository, + IOptions globalConfigOptions, IDistributedCache cache, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, @@ -38,6 +42,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { _logger = logger; _repository = repository; + _globalConfigOptions = globalConfigOptions; } #region 导入、导出 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 09354e02..3fe8e0b1 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 @@ -533,7 +533,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ EnumBusinessType.ZhiGongJianBBAC => site, EnumBusinessType.ZhiGongJianHBPO => "104T", EnumBusinessType.BeiJian => "1049", - EnumBusinessType.YinDuJian => "1040", + EnumBusinessType.YinDuJian => "1041", _ => throw new UserFriendlyException($"业务编码错误", "400") }; site = clientCode; @@ -542,7 +542,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { //备件销售价格 var priceListEntitys = _priceBjListRepository.Where(t => t.IsCancel == false) - .Where(t => t.ClientCode == clientCode) .Where(t => lus.Contains(t.LU)).ToList(); pubSaDetails.ForEach(importPubSaDetail => { @@ -556,11 +555,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ importPubSaDetail.Price = priceListEntity?.Price ?? 0; }); } - else if(businessType == EnumBusinessType.YinDuJian) + else if (businessType == EnumBusinessType.YinDuJian) { //印度销售价格 var priceListEntitys = _priceYinDuListRepository.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/BQ/Syncs/InvoiceSyncQadInvocable.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/InvoiceSyncQadInvocable.cs new file mode 100644 index 00000000..73e764c3 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/InvoiceSyncQadInvocable.cs @@ -0,0 +1,59 @@ +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading.Tasks; +using Coravel.Invocable; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using SettleAccount.Domain.BQ; +using Win.Sfs.SettleAccount.EntityFrameworkCore; +using Win.Sfs.SettleAccount.Options; + +namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs +{ + public class InvoiceSyncQadInvocable : IInvocable + { + private readonly ILogger _logger; + private readonly GlobalConfigOptions _globalConfigOptions; + private readonly ISettleAccountDbContext _settleAccountDbContext; + /// + /// 数据中心数据上下文 + /// + private readonly ExChangeCenterDbContext _exChangeCenterDbContext; + + public InvoiceSyncQadInvocable( + ILogger logger, + IOptions options, + ISettleAccountDbContext settleAccountDbContext, + ExChangeCenterDbContext exChangeCenterDbContext) + { + _logger = logger; + _globalConfigOptions = options.Value; + _settleAccountDbContext = settleAccountDbContext; + _exChangeCenterDbContext = exChangeCenterDbContext; + } + + /// + /// 执行 + /// + public async Task Invoke() + { + await Task.CompletedTask.ConfigureAwait(false); + + if (!_globalConfigOptions.IsSyncInvoiceQadState) + { + return; + } + + var invoiceSyncQads = _settleAccountDbContext.Set().Where(t => t.TaskState == 0 || t.TaskState == 1).OrderBy(t => t.CreationTime).Take(1000).ToList(); + + if (!invoiceSyncQads.Any()) + { + _globalConfigOptions.IsSyncInvoiceQadState = false; + return; + } + + var taskIDs = invoiceSyncQads.Select(t => t.TaskID); + var TeaTaskSubs = _exChangeCenterDbContext.TEA_TASK_SUB.Where(t => taskIDs.Contains(t.TaskID)).ToList(); + } + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Options/GlobalConfigOptions.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Options/GlobalConfigOptions.cs new file mode 100644 index 00000000..6d1c8e7b --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Options/GlobalConfigOptions.cs @@ -0,0 +1,13 @@ +namespace Win.Sfs.SettleAccount.Options +{ + /// + /// 全局配置选项 + /// + public class GlobalConfigOptions + { + /// + /// 是否同步发票Qad状态 + /// + public bool IsSyncInvoiceQadState { get; set; } + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Options/SeConfigOptions.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Options/SeConfigOptions.cs deleted file mode 100644 index 1489e155..00000000 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Options/SeConfigOptions.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Win.Sfs.SettleAccount.Options -{ - /// - /// 发运配置选项 - /// - public class SeConfigOptions - { - } -}