diff --git a/ds-wms-service/DS.WMS.Core/Application/Method/InvoiceApplicationService.cs b/ds-wms-service/DS.WMS.Core/Application/Method/InvoiceApplicationService.cs index e88a4a82..e1ec1337 100644 --- a/ds-wms-service/DS.WMS.Core/Application/Method/InvoiceApplicationService.cs +++ b/ds-wms-service/DS.WMS.Core/Application/Method/InvoiceApplicationService.cs @@ -67,14 +67,15 @@ namespace DS.WMS.Core.Application.Method Email = x.Email, CellPhoneNO = x.CellPhoneNO, InvoiceRemark = x.InvoiceRemark, //开票要求 + CreateByName = x.CreateUserName, ApplyAmountRMB = SqlFunc.Subqueryable().Where(y => x.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount), ApplyAmountUSD = SqlFunc.Subqueryable().Where(y => x.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount), //原币金额 OriginalAmountList = SqlFunc.Subqueryable().Where(y => x.Id == y.ApplicationId) - .GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = y.OriginalAmount }) + .GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = SqlFunc.AggregateSum(y.OriginalAmount) }) }).ToQueryPageAsync(request.PageCondition); - if (result.Data.Count > 0) + if (result.Data?.Count > 0) { var ids = result.Data.Select(x => x.Id); var fees = await TenantDb.Queryable() @@ -88,9 +89,6 @@ namespace DS.WMS.Core.Application.Method f.SettlementAmount, }).ToListAsync(); - //关联用户名称 - var userIds = result.Data.Select(x => x.CreateBy).Distinct(); - var users = await Db.Queryable().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync(); foreach (var item in result.Data) { item.UnsettledList = fees.Where(x => x.ApplicationId == item.Id).GroupBy(x => x.Currency) @@ -99,7 +97,6 @@ namespace DS.WMS.Core.Application.Method Currency = x.Key, Amount = x.Sum(y => y.Amount - y.SettlementAmount) }).ToList(); - item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName; } //result.AdditionalData = new Dictionary diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs index 1f03b09b..5a773c97 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs @@ -37,9 +37,13 @@ namespace DS.WMS.Core.Invoice.Method SqlFunc.Subqueryable().Where(d => d.ApplicationId == a.Id && d.Category == DetailCategory.InvoiceApplication && (d.OriginalAmount - d.OriginalProcessedAmount) != 0).Any()) .Select(a => new InvoiceApplicationDto { + CreateByName = a.CreateUserName, AmountRMB = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount - y.ProcessedAmount), AmountUSD = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount - y.ProcessedAmount), AmountOther = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency != FeeCurrency.RMB_CODE && y.Currency != FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount - y.ProcessedAmount), + //申请金额 + ApplyAmountRMB = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount), + ApplyAmountUSD = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount), //原币金额 OriginalAmountList = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId) .GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = SqlFunc.AggregateSum(y.OriginalAmount) }) @@ -50,9 +54,6 @@ namespace DS.WMS.Core.Invoice.Method if (result.Data?.Count > 0) { - var userIds = result.Data.Select(x => x.CreateBy).Distinct(); - var users = await Db.Queryable().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync(); - var orgIds = result.Data.Where(x => x.SaleDeptId.HasValue).Select(x => x.SaleDeptId) .Union(result.Data.Where(x => x.OrgId.HasValue).Select(x => x.OrgId)) .Distinct(); @@ -64,8 +65,6 @@ namespace DS.WMS.Core.Invoice.Method foreach (var item in result.Data) { - item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName; - item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName; item.OrgName = orgs.Find(x => x.Id == item.OrgId)?.OrgName; diff --git a/ds-wms-service/DS.WMS.Core/ServiceBase.cs b/ds-wms-service/DS.WMS.Core/ServiceBase.cs index 1b4f4eb9..8bf5b83b 100644 --- a/ds-wms-service/DS.WMS.Core/ServiceBase.cs +++ b/ds-wms-service/DS.WMS.Core/ServiceBase.cs @@ -4,6 +4,8 @@ using DS.Module.UserModule; using DS.WMS.Core.Flow.Entity; using DS.WMS.Core.Sys.Interface; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Layouts; using SqlSugar; namespace DS.WMS.Core @@ -47,6 +49,11 @@ namespace DS.WMS.Core } } + /// + /// 日志记录对象 + /// + public Lazy> Logger { get; private set; } + /// /// 初始化 /// @@ -58,6 +65,7 @@ namespace DS.WMS.Core Db = serviceProvider.GetRequiredService(); SaasService = serviceProvider.GetRequiredService(); commonService = new Lazy(serviceProvider.GetRequiredService()); + Logger = new Lazy>(serviceProvider.GetRequiredService>()); } /// diff --git a/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs b/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs index ba873c5b..735243a4 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs @@ -231,6 +231,7 @@ namespace DS.WMS.Core.Settlement.Method .InnerJoin((a, d) => a.Id == d.ApplicationId && d.ApplyAmount - d.ProcessedAmount != 0) .InnerJoin((a, d, f) => d.RecordId == f.Id) .InnerJoin((a, d, f, s) => f.BusinessId == s.Id && f.BusinessType == BusinessType.OceanShippingExport) + .Where(request.GetConditionalModels(Db)) .GroupBy((a, d) => a.Id); if (request.OtherQueryCondition != null) @@ -246,7 +247,6 @@ namespace DS.WMS.Core.Settlement.Method query = query.Where(a => a.Status == PaymentApplicationStatus.AuditPassed || a.Status == PaymentApplicationStatus.PartialSettlement || a.Status == PaymentApplicationStatus.SettlementCompleted); } - var whereList = request.GetConditionalModels(Db); var result = await query.Select(a => new PaymentApplicationDtoV2 { AmountRMB = a.AmountRMB == null ? 0 : a.AmountRMB.Value, //RMB申请金额 @@ -262,7 +262,7 @@ namespace DS.WMS.Core.Settlement.Method UnSettledOther = SqlFunc.Subqueryable().Where(d => d.ApplicationId == a.Id && d.Currency != FeeCurrency.RMB_CODE && d.Currency != FeeCurrency.USD_CODE) .Select(d => SqlFunc.AggregateSum(d.ApplyAmount - d.ProcessedAmount)), SettlementTypeName = a.SettlementType.StlName, //结算方式 - }, true).MergeTable().Where(whereList).ToQueryPageAsync(request.PageCondition); + }, true).MergeTable().ToQueryPageAsync(request.PageCondition); if (result.Data?.Count > 0) { diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessDataProvider.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessDataProvider.cs index 150e412f..c0a86687 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessDataProvider.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessDataProvider.cs @@ -19,7 +19,7 @@ namespace DS.WMS.Core.TaskInteraction.Entity /// 数据源程序类型名 /// [SugarColumn(ColumnDescription = "数据源程序类型名", Length = 100, IsNullable = true)] - public string TypeName { get; set; } = string.Empty; + public string? TypeName { get; set; } /// /// 数据源名称 @@ -39,12 +39,6 @@ namespace DS.WMS.Core.TaskInteraction.Entity [SugarColumn(ColumnDescription = "数据源内容", IsNullable = true)] public string? Content { get; set; } - /// - /// 数据源类型 - /// - [SugarColumn(ColumnDescription = "数据源类型")] - public DataProviderType Type { get; set; } - /// /// 创建人 /// @@ -57,34 +51,4 @@ namespace DS.WMS.Core.TaskInteraction.Entity [SugarColumn(ColumnDescription = "创建时间", IsNullable = false)] public DateTime CreateTime { get; set; } } - - /// - /// 数据源类型 - /// - public enum DataProviderType - { - /// - /// 自定义 - /// - [Description("自定义")] - Custom = 0, - - /// - /// 固定 - /// - [Description("固定")] - Fixed = 1, - - /// - /// 数据库 - /// - [Description("数据库")] - Database = 2, - - /// - /// 网络 - /// - [Description("网络")] - Network = 3 - } } diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskMail.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskMail.cs index 2f3cd1ba..916a47e5 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskMail.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskMail.cs @@ -46,6 +46,12 @@ namespace DS.WMS.Core.TaskInteraction.Entity [SugarColumn(ColumnDescription = "是否业务邮件")] public bool IsBusiness { get; set; } + /// + /// 数据源类型 + /// + [SugarColumn(ColumnDescription = "数据源类型")] + public DataProviderType Type { get; set; } + /// /// 数据源提供程序ID /// @@ -129,5 +135,47 @@ namespace DS.WMS.Core.TaskInteraction.Entity /// [Description("费用确认")] CostConfirmation = 6, + + /// + /// 账单 + /// + [Description("账单")] + Bill = 7, + } + + /// + /// 数据源类型 + /// + public enum DataProviderType + { + /// + /// 默认 + /// + [Description("默认")] + Default = 0, + + /// + /// 自定义 + /// + [Description("自定义")] + Custom = 1, + + /// + /// 固定 + /// + [Description("固定")] + Fixed = 2, + + /// + /// 数据库 + /// + [Description("数据库")] + Database = 3, + + /// + /// 网络 + /// + [Description("网络")] + Network = 4 } } diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/DataProvider/DefaultNetworkProvider.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/DataProvider/DefaultNetworkProvider.cs new file mode 100644 index 00000000..db70714b --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/DataProvider/DefaultNetworkProvider.cs @@ -0,0 +1,39 @@ +using DS.Module.Core; +using DS.WMS.Core.TaskInteraction.Dtos; +using DS.WMS.Core.TaskInteraction.Interface; +using Newtonsoft.Json; + +namespace DS.WMS.Core.TaskInteraction.Method.DataProvider +{ + /// + /// 默认网络提供程序 + /// + public class DefaultNetworkProvider : ServiceBase, IDataProvider + { + /// + /// 初始化 + /// + /// + public DefaultNetworkProvider(IServiceProvider provider) : base(provider) + { + } + + /// + /// 执行网络请求 + /// + /// + /// + public async Task FetchDataAsync(DataFetchContext context) + { + using (ApiFox api = new()) + { + var response = await api.SendRequestAsync(HttpMethod.Get, context.Content); + if (response.IsSuccessStatusCode) + { + var json = await response.Content.ReadAsStringAsync(); + context.Data = JsonConvert.DeserializeObject(json); + } + } + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/Jobs/BillSendingTaskJob.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/Jobs/BillSendingTaskJob.cs index 56e0658a..dd87473f 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/Jobs/BillSendingTaskJob.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/Jobs/BillSendingTaskJob.cs @@ -1,16 +1,45 @@ -using DS.WMS.Core.TaskInteraction.Dtos; +using DS.WMS.Core.Sys.Entity; +using DS.WMS.Core.TaskInteraction.Dtos; +using DS.WMS.Core.TaskInteraction.Entity; using DS.WMS.Core.TaskInteraction.Interface; +using Microsoft.Extensions.Logging; namespace DS.WMS.Core.TaskInteraction.Method.Jobs { /// /// 账单发送定时任务 /// - public class BillSendingTaskJob : ITaskJob + public class BillSendingTaskJob : ServiceBase, ITaskJob { + const string BILL_MAIL_TEMPLATE = "BILL_MAIL_TEMPLATE"; + + /// + /// 初始化 + /// + /// + public BillSendingTaskJob(IServiceProvider serviceProvider) : base(serviceProvider) + { + } + + /// + /// 账单发送 + /// + /// + /// public async Task ExecuteAsync(TaskJobContext context) { + var config = await Db.Queryable().Where(x => x.Code == BILL_MAIL_TEMPLATE).FirstAsync(); + if (config == null) + { + Logger.Value.LogWarning("未配置账单邮件模板"); + return; + } + long id = long.Parse(config.Value); + var mailTemplate = await TenantDb.Queryable().FirstAsync(x => x.Id == id); + MailGenerator generator = new(ServiceProvider); + var model = await generator.GetBusinessModelAsync(mailTemplate, context.JobInfo.BusinessId, context.JobInfo.BusinessType); + await generator.SendAsync(mailTemplate, model); } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailGenerator.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailGenerator.cs index c40575d4..957c3990 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailGenerator.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailGenerator.cs @@ -78,7 +78,7 @@ namespace DS.WMS.Core.TaskInteraction.Method BusinessType = bsType }; - if (taskMail.Provider == null) + if (taskMail.Type == DataProviderType.Default) { actionManager ??= ServiceProvider.GetRequiredService(); model.Primary = await actionManager.GetBusinessDataAsync(bsId, bsType.GetValueOrDefault()); @@ -86,19 +86,35 @@ namespace DS.WMS.Core.TaskInteraction.Method else { IDataProvider? dataProvider = null; - switch (taskMail.Provider.Type) + BusinessDataProvider? provider1 = null; + switch (taskMail.Type) { case DataProviderType.Custom: - if (string.IsNullOrEmpty(taskMail.Provider.TypeName)) + if (taskMail.ProviderId == null) return model; - var type = Type.GetType(taskMail.Provider.TypeName, true); + provider1 = await TenantDb.Queryable().Where(x => x.Id == taskMail.ProviderId) + .Select(x => new BusinessDataProvider + { + TypeName = x.TypeName, + Content = x.Content + }).FirstAsync(); + var type = Type.GetType(provider1.TypeName, true); dataProvider = ConstructorExtensions.CreateInstance(type, [ServiceProvider]) as IDataProvider; dataProvider ??= ConstructorExtensions.CreateInstance(type) as IDataProvider; break; case DataProviderType.Fixed: - model.Primary = JsonConvert.DeserializeObject(taskMail.Content!); + if (taskMail.ProviderId == null) + return model; + + provider1 = await TenantDb.Queryable().Where(x => x.Id == taskMail.ProviderId) + .Select(x => new BusinessDataProvider + { + TypeName = x.TypeName, + Content = x.Content + }).FirstAsync(); + model.Primary = JsonConvert.DeserializeObject(provider1.Content); break; case DataProviderType.Database: @@ -106,7 +122,7 @@ namespace DS.WMS.Core.TaskInteraction.Method break; case DataProviderType.Network: - + dataProvider = new DefaultNetworkProvider(ServiceProvider); break; } @@ -117,7 +133,7 @@ namespace DS.WMS.Core.TaskInteraction.Method ServiceProvider = ServiceProvider, BusinessId = bsId, BusinessType = bsType, - Content = taskMail.Content, + Content = provider1.Content, }; await dataProvider.FetchDataAsync(context); model.Primary = context.Data; @@ -367,12 +383,14 @@ namespace DS.WMS.Core.TaskInteraction.Method long tenantId = long.Parse(User.TenantId); string requestUrl = config["TaskMail:FileBaseUrl"] + config["TaskMail:SQLPrint"]; + object? obj = templateModel.GetPropertyValue(nameof(MailTemplateModel.Primary), Flags.InstancePublic); + string json = JsonConvert.SerializeObject(obj ??= new { Id = templateModel.BusinessId }); + foreach (var item in mailConfig.Attachments) { - object? obj = templateModel.GetPropertyValue(nameof(MailTemplateModel.Primary), Flags.InstancePublic); var req = new OpenPrintReq { - ParamJsonStr = JsonConvert.SerializeObject(obj), + ParamJsonStr = json, PrintType = ((int)FileFormat.PDF).ToString(), TemplateId = item.TemplateId, TenantId = tenantId diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs index b763e907..760bcd59 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -3264,8 +3264,8 @@ namespace DS.WMS.Core.TaskPlat.Method || s.CustomerNum.Contains(queryDto.OtherQueryCondition.BusinessNo) || t.TASK_NO.Contains(queryDto.OtherQueryCondition.BusinessNo) || (isHasOrderParentIdList == true && orderParentIdList!.Contains(s.Id))) - .WhereIF(!string.IsNullOrEmpty(queryDto.OtherQueryCondition.PortLoadCode), (t, a, s) => queryDto.OtherQueryCondition.PortLoadCode == s.LoadPortCode || portLoadTaskIdList.Contains(t.Id)) - .WhereIF(!string.IsNullOrEmpty(queryDto.OtherQueryCondition.PortDischargeCode), (t, a, s) => queryDto.OtherQueryCondition.PortDischargeCode == s.DischargePortCode || portDischargeTaskIdList.Contains(t.Id)) + .WhereIF(!string.IsNullOrEmpty(queryDto.OtherQueryCondition.PortLoadCode), (a, t, s) => queryDto.OtherQueryCondition.PortLoadCode == s.LoadPortCode || portLoadTaskIdList.Contains(t.Id)) + .WhereIF(!string.IsNullOrEmpty(queryDto.OtherQueryCondition.PortDischargeCode), (a, t, s) => queryDto.OtherQueryCondition.PortDischargeCode == s.DischargePortCode || portDischargeTaskIdList.Contains(t.Id)) .GroupBy((a, t) => new { t.TASK_TYPE, t.STATUS, a.Status, }) .Select((a, t) => new TaskGroupTotal() {