From 6cf5514e26aaa68865bbe40994dffbcb8a899d81 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 8 Aug 2024 13:44:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E8=AE=B0=E5=BD=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs index c04d82c5..937b44e0 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs @@ -325,12 +325,22 @@ namespace DS.WMS.Core.TaskPlat } catch (Exception ex) { + string exMessage; + if (ex is TargetInvocationException ex2 && ex2.InnerException != null) + { + exMessage = WriteLog("模块内部执行过程中发生异常", ex2.InnerException); + } + else + { + exMessage = WriteLog("模块外部调用过程中发生异常", ex); + } + flowLogDetail.ExceptionMessage = exMessage; + flowLog.IsComplete = false; flowLog.IsSuccess = false; flowLogDetail.IsComplete = false; flowLogDetail.IsSuccess = false; - flowLogDetail.ExceptionMessage = WriteLog("模块执行过程中发生异常", ex); await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync(); if (executeConfig.IsExceptionContinue) From a13e63064e752968f37e9b36c5e0073e6d3463c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Thu, 8 Aug 2024 14:14:23 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/TaskFlowDataContext.cs | 21 ++++++++++- .../TaskInteraction/ActionExecutionContext.cs | 10 ++++-- .../TaskInteraction/BusinessTaskMail.cs | 19 ++++++---- .../TaskInteraction/IActionExecutor.cs | 2 +- ...ionManager.cs => IActionManagerService.cs} | 2 +- .../TaskInteraction/ITaskMailService.cs | 7 ++++ ...tionManager.cs => ActionManagerService.cs} | 25 ++++++++++--- .../TaskInteraction/MailActionExecutor.cs | 36 +++++++++++++++++-- .../Op/Method/TaskInteraction/MailTemplate.cs | 13 ------- .../Method/TaskInteraction/TaskMailService.cs | 23 +++++++++--- .../Op/Method/TaskInteraction/TaskService.cs | 20 ++++++++--- 11 files changed, 136 insertions(+), 42 deletions(-) rename ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/{IActionManager.cs => IActionManagerService.cs} (93%) rename ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/{ActionManager.cs => ActionManagerService.cs} (63%) delete mode 100644 ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailTemplate.cs diff --git a/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs b/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs index 61e18b6c..29004542 100644 --- a/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs +++ b/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs @@ -1,4 +1,9 @@ -namespace DS.Module.Core.Data +using Microsoft.AspNetCore.DataProtection.KeyManagement; +using Newtonsoft.Json.Linq; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace DS.Module.Core.Data { /// /// 任务模块之间用于传入、获取数据的容器 @@ -26,6 +31,14 @@ } } + public IReadOnlyCollection Keys => dataContext.Keys; + + public object? this[string key] + { + get { return dataContext[key]; } + set { dataContext[key] = value; } + } + /// /// /// @@ -52,6 +65,10 @@ { return t; } + else if (value != null) + { + return (T)Convert.ChangeType(value, typeof(T)); + } } return default; } @@ -60,5 +77,7 @@ /// /// public bool ContainsKey(string key) => dataContext.ContainsKey(key); + + } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs index 98f6a748..c324bf65 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs @@ -1,5 +1,5 @@ -using DS.Module.Core.Data; -using DS.WMS.Core.Op.Entity.TaskInteraction; +using DS.WMS.Core.Op.Entity.TaskInteraction; +using SqlSugar; namespace DS.WMS.Core.Op.Dtos.TaskInteraction { @@ -8,8 +8,12 @@ namespace DS.WMS.Core.Op.Dtos.TaskInteraction /// public class ActionExecutionContext { - public BusinessTask Task { get; set; } + public BusinessTask TaskInfo { get; internal set; } + public IServiceProvider ServiceProvider { get; internal set; } + public ISqlSugarClient TenantDb { get; internal set; } + + public IDictionary AdditionalData { get; set; } = new Dictionary(); } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs index 8e4f869d..f43f9316 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs @@ -1,5 +1,4 @@ -using DS.Module.Core; -using DS.Module.Core.Data; +using DS.Module.Core.Data; using SqlSugar; namespace DS.WMS.Core.Op.Entity.TaskInteraction @@ -10,11 +9,11 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction [SugarTable("business_task_mail", "任务邮件发送配置")] public class BusinessTaskMail : BaseOrgModelV2 { - /// - /// 任务类型 - /// - [SugarColumn(ColumnDescription = "任务类型", IsNullable = false)] - public TaskBaseTypeEnum TaskType { get; set; } + ///// + ///// 任务类型 + ///// + //[SugarColumn(ColumnDescription = "任务类型", IsNullable = false)] + //public TaskBaseTypeEnum TaskType { get; set; } ///// ///// 任务状态 @@ -22,6 +21,12 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction //[SugarColumn(ColumnDescription = "任务状态", IsNullable = false)] //public TaskStatusEnum TaskStatus { get; set; } = TaskStatusEnum.Complete; + /// + /// 配置名称 + /// + [SugarColumn(ColumnDescription = "配置名称", Length = 100, IsNullable = false)] + public string Name { get; set; } = string.Empty; + /// /// 主题 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs index c0f9a988..fcdad699 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs @@ -10,7 +10,7 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction /// /// 执行特定动作 /// - /// + /// 执行上下文 /// Task ExecuteAsync(ActionExecutionContext context); } diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManagerService.cs similarity index 93% rename from ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs rename to ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManagerService.cs index d204de7e..7d427c53 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManagerService.cs @@ -6,7 +6,7 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction /// /// 动作执行管理 /// - public interface IActionManager + public interface IActionManagerService { /// /// 执行特定动作 diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs index 4e05522f..954841c7 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs @@ -23,6 +23,13 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction /// Task> GetAsync(long id); + /// + /// 根据配置名获取 + /// + /// + /// + Task GetAsync(string name); + /// /// 编辑 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs similarity index 63% rename from ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs rename to ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs index 2858c429..6bd174b6 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using DS.Module.Core.Data; +using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; using DS.WMS.Core.TaskPlat; @@ -9,14 +10,14 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// /// 动作执行管理 /// - public class ActionManager : ServiceBase, IActionManager + public class ActionManagerService : ServiceBase, IActionManagerService { Dictionary ExecutorMappings; /// /// 初始化 /// - public ActionManager(IServiceProvider serviceProvider) : base(serviceProvider) + public ActionManagerService(IServiceProvider serviceProvider) : base(serviceProvider) { ExecutorMappings = new Dictionary(); ExecutorMappings[TaskActionType.Mail] = new MailActionExecutor(); @@ -27,7 +28,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// /// 任务信息 /// - public async Task TriggerAction(BusinessTask businessTask) + public async Task TriggerAction(BusinessTask businessTask) { ArgumentNullException.ThrowIfNull(businessTask, nameof(businessTask)); @@ -41,13 +42,29 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction ); TaskFlowRuner taskFlow = new(TenantDb, ServiceProvider); - await taskFlow.Run(businessTask.TaskType, businessTask.BusinessId, dataContext); + await taskFlow.RunWithBsno(businessTask.TaskType, businessTask.BusinessId, dataContext); } public async Task ExecuteAsync(TaskFlowDataContext dataContext) { ArgumentNullException.ThrowIfNull(dataContext, nameof(dataContext)); + TaskActionType actionType = (TaskActionType)dataContext.Get("ActionType"); + if (ExecutorMappings.TryGetValue(actionType, out IActionExecutor executor)) + { + var context = new ActionExecutionContext + { + TaskInfo = dataContext.Get(TaskFlowDataNameConst.BusinessTask), + ServiceProvider = ServiceProvider, + TenantDb = TenantDb + }; + foreach (var key in dataContext.Keys) + { + context.AdditionalData[key] = dataContext[key]; + } + + await executor.ExecuteAsync(context); + } } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs index 4018a0e9..1b7ab530 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs @@ -1,13 +1,43 @@ -using DS.WMS.Core.Op.Dtos.TaskInteraction; +using DS.Module.Core.Extensions; +using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; +using Masuit.Tools.Systems; +using Microsoft.Extensions.DependencyInjection; +using RazorEngineCore; namespace DS.WMS.Core.Op.Method.TaskInteraction { + /// + /// 用于邮件发送的执行器 + /// public class MailActionExecutor : IActionExecutor { - public Task ExecuteAsync(ActionExecutionContext context) + /// + /// 发送邮件 + /// + /// + /// + public async Task ExecuteAsync(ActionExecutionContext context) { - throw new NotImplementedException(); + var service = context.ServiceProvider.GetRequiredService(); + var logService = context.ServiceProvider.GetRequiredService(); + + var mailName = context.AdditionalData["MailName"] as string; + if (mailName.IsNullOrEmpty()) + { + await logService.WriteLogAsync(context.TaskInfo, $"未配置【{context.TaskInfo.TaskType.GetDescription()}】任务的邮件设置"); + return; + } + var mailConfig = await service.GetAsync(mailName); + if (mailConfig == null) + { + await logService.WriteLogAsync(context.TaskInfo, $"未能获取名为【{mailName}】的邮件配置"); + return; + } + + IRazorEngine razorEngine = new RazorEngine(); + IRazorEngineCompiledTemplate titleTemplate = razorEngine.Compile(mailConfig.Title); + IRazorEngineCompiledTemplate contentTemplate = razorEngine.Compile(mailConfig.Content); } } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailTemplate.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailTemplate.cs deleted file mode 100644 index 6f18fcf3..00000000 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailTemplate.cs +++ /dev/null @@ -1,13 +0,0 @@ -using RazorEngineCore; - -namespace DS.WMS.Core.Op.Method.TaskInteraction -{ - internal class MailTemplate - { - - public MailTemplate() - { - IRazorEngine razorEngine = new RazorEngine(); - } - } -} diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs index 76bbae11..173340b4 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs @@ -38,12 +38,25 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// public async Task> GetAsync(long id) { - var entity = await TenantDb.Queryable().Includes(x => x.Receiver).Includes(x => x.Sender) + var entity = await TenantDb.Queryable() + .Includes(x => x.Receiver).Includes(x => x.Sender).Includes(x => x.Server).Includes(x => x.Attachments) .Where(x => x.Id == id).FirstAsync(); return DataResult.Success(entity); } + /// + /// 根据配置名获取 + /// + /// + /// + public async Task GetAsync(string name) + { + return await TenantDb.Queryable() + .Includes(x => x.Receiver).Includes(x => x.Sender).Includes(x => x.Server).Includes(x => x.Attachments) + .Where(x => x.Name == name).FirstAsync(); + } + /// /// 编辑 /// @@ -58,12 +71,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction { taskMail.Receiver ??= new(); taskMail.Sender ??= new(); + taskMail.Server ??= new(); - taskMail = await TenantDb.InsertNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).ExecuteReturnEntityAsync(); + taskMail = await TenantDb.InsertNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.Server).ExecuteReturnEntityAsync(); } else { - await TenantDb.UpdateNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).ExecuteCommandAsync(); + await TenantDb.UpdateNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.Server).ExecuteCommandAsync(); } if (taskMail.Attachments?.Count > 0) @@ -99,7 +113,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction try { await TenantDb.DeleteNav(x => model.Ids.Contains(x.Id)) - .Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.Attachments).ExecuteCommandAsync(); + .Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.Server).Include(x => x.Attachments) + .ExecuteCommandAsync(); await TenantDb.Ado.CommitTranAsync(); return DataResult.Success; diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs index f0f3d47a..2189f5c0 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs @@ -47,6 +47,11 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// protected Lazy FlowService { get; private set; } + /// + /// 工作流服务 + /// + protected Lazy ActionService { get; private set; } + /// /// 初始化 /// @@ -56,6 +61,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction ManagerService = provider.GetRequiredService(); LogService = provider.GetRequiredService(); FlowService = new Lazy(provider.GetRequiredService()); + ActionService = new Lazy(provider.GetRequiredService()); } /// @@ -462,6 +468,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (useTransaction) await TenantDb.Ado.CommitTranAsync(); + ActionService.Value.TriggerAction(task); return DataResult.Success(task.TaskStatus == TaskStatusEnum.Complete ? GetNextType(task) : null); } catch (Exception ex) @@ -556,7 +563,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction { BusinessId = callback.BusinessId, BusinessType = callback.BusinessType.GetValueOrDefault(), - TaskTypeName = (taskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT ? + TaskTypeName = (taskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT ? TaskBaseTypeEnum.ORDER_AUDIT_REJECTED : TaskBaseTypeEnum.RETURN_CABIN_REJECTED).ToString(), RecvUserIdList = [task.CreateBy] //通知任务发起人 }); @@ -622,7 +629,10 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction } var allocation = allocations.Find(x => x.CarrierId == carrierId); - //未找到匹配值 + //首先使用船公司匹配 + if (allocation == null) + allocation = allocations.Find(x => x.CarrierId == null); //使用默认值匹配 + if (allocation == null) return null; @@ -631,15 +641,15 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction { expr = expr.Or(x => x.IsCustomerService); } - else if (allocation.IsAllotOperator) + if (allocation.IsAllotOperator) { expr = expr.Or(x => x.IsOperator); } - else if (allocation.IsAllotSale) + if (allocation.IsAllotSale) { expr = expr.Or(x => x.IsSale); } - else if (allocation.IsAllotVouchingClerk) + if (allocation.IsAllotVouchingClerk) { expr = expr.Or(x => x.IsVouchingClerk); } From 39fc81dc28e13bee0f47e1c369203978c72457c7 Mon Sep 17 00:00:00 2001 From: cjy Date: Thu, 8 Aug 2024 14:39:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/StringExtensions.cs | 2 +- .../Sys/Interface/ISysPrintTemplateService.cs | 2 +- .../Sys/Method/SysPrintTemplateService.cs | 59 ++++++++++++++++--- .../Controllers/PrintTemplateController.cs | 4 +- .../Service/OpenPrintService.cs | 35 ++--------- 5 files changed, 59 insertions(+), 43 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Extensions/StringExtensions.cs b/ds-wms-service/DS.Module.Core/Extensions/StringExtensions.cs index a592e0c7..9a874df0 100644 --- a/ds-wms-service/DS.Module.Core/Extensions/StringExtensions.cs +++ b/ds-wms-service/DS.Module.Core/Extensions/StringExtensions.cs @@ -12,7 +12,7 @@ public static class StringExtensions /// /// /// - public static bool IsSqlInjection(string input) + public static bool IsSqlInjection(this string input) { string[] sqlCheckList = { "TRUNCATE", "INSERT", "UPDATE", "DELETE", "DROP", "--", ";", "'" }; foreach (string item in sqlCheckList) diff --git a/ds-wms-service/DS.WMS.Core/Sys/Interface/ISysPrintTemplateService.cs b/ds-wms-service/DS.WMS.Core/Sys/Interface/ISysPrintTemplateService.cs index 4ee2c263..1653bed2 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Interface/ISysPrintTemplateService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Interface/ISysPrintTemplateService.cs @@ -46,7 +46,7 @@ namespace DS.WMS.Core.Sys.Interface /// /// /// - public DataResult EditSysPrintTemplate(SysPrintTemplateReq req); + public Task EditSysPrintTemplate(SysPrintTemplateReq req); /// /// 打印模块删除 diff --git a/ds-wms-service/DS.WMS.Core/Sys/Method/SysPrintTemplateService.cs b/ds-wms-service/DS.WMS.Core/Sys/Method/SysPrintTemplateService.cs index edc7de8a..0774e9c6 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Method/SysPrintTemplateService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Method/SysPrintTemplateService.cs @@ -12,6 +12,7 @@ using DS.Module.SqlSugar; using DS.WMS.Core.Code.Entity; using Org.BouncyCastle.Ocsp; using System.Collections.Generic; +using Masuit.Tools.Strings; namespace DS.WMS.Core.Sys.Method { @@ -96,29 +97,71 @@ namespace DS.WMS.Core.Sys.Method .First(); return DataResult.Success(data, MultiLanguageConst.DataQuerySuccess); } - public DataResult EditSysPrintTemplate(SysPrintTemplateReq req) + + public async Task EditSysPrintTemplate(SysPrintTemplateReq req) { if (req.Id == 0) { - var isExist = db.Queryable().Where(x => x.TemplateCode == req.TemplateCode).WhereIF(req.CarrierId != 0, x => x.CarrierId == req.CarrierId).First(); - if (isExist != null) + if (db.Queryable().Where(x => x.TemplateCode == req.TemplateCode).WhereIF(req.CarrierId != 0, x => x.CarrierId == req.CarrierId).Any()) { - return DataResult.Failed("打印模板唯一编码已存在!"); + return await Task.FromResult(DataResult.Failed("打印模板唯一编码已存在!")); + } + + if (req.IsUseDataSource) { + + if (string.IsNullOrEmpty(req.SourceSql)) + { + return await Task.FromResult(DataResult.Failed("打印数据源不能为空!")); + } + if (!req.SourceSql.Contains(';')) + { + return await Task.FromResult(DataResult.Failed("数据源必须包含分号!")); + } + if (req.SourceSql.Substring(req.SourceSql.Length - 1, 1) != ";") + { + return await Task.FromResult(DataResult.Failed("数据源最后必须包含分号!")); + } + if (req.SourceSql.IsSqlInjection()) + { + return await Task.FromResult(DataResult.Failed("sql数据源包含非法字符,请检查!")); + } } + var data = req.Adapt(); - var entity = db.Insertable(data).ExecuteReturnEntity(); + var entity = await db.Insertable(data).ExecuteReturnEntityAsync(); return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess); } else { - var info = db.Queryable().Where(x => x.Id == req.Id).First(); + var info = await db.Queryable().Where(x => x.Id == req.Id).FirstAsync(); + + if (req.IsUseDataSource) + { + + if (string.IsNullOrEmpty(req.SourceSql)) + { + return await Task.FromResult(DataResult.Failed("打印数据源不能为空!")); + } + if (!req.SourceSql.Contains(';')) + { + return await Task.FromResult(DataResult.Failed("数据源必须包含分号!")); + } + if (req.SourceSql.Substring(req.SourceSql.Length - 1, 1) != ";") + { + return await Task.FromResult(DataResult.Failed("数据源最后必须包含分号!")); + } + if (req.SourceSql.IsSqlInjection()) + { + return await Task.FromResult(DataResult.Failed("sql数据源包含非法字符,请检查!")); + } + } info = req.Adapt(info); - db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); - return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess); + await db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess)); } } diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/PrintTemplateController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/PrintTemplateController.cs index 3f772ffb..38d2c907 100644 --- a/ds-wms-service/DS.WMS.MainApi/Controllers/PrintTemplateController.cs +++ b/ds-wms-service/DS.WMS.MainApi/Controllers/PrintTemplateController.cs @@ -94,9 +94,9 @@ public class PrintTemplateController : ApiController /// [HttpPost] [Route("EditSysPrintTemplate")] - public DataResult EditSysPrintTemplate([FromBody] SysPrintTemplateReq req) + public async Task EditSysPrintTemplate([FromBody] SysPrintTemplateReq req) { - var res = _invokeService.EditSysPrintTemplate(req); + var res = await _invokeService.EditSysPrintTemplate(req); return res; } diff --git a/ds-wms-service/DS.WMS.PrintApi/Service/OpenPrintService.cs b/ds-wms-service/DS.WMS.PrintApi/Service/OpenPrintService.cs index 34235e72..9b3e70b9 100644 --- a/ds-wms-service/DS.WMS.PrintApi/Service/OpenPrintService.cs +++ b/ds-wms-service/DS.WMS.PrintApi/Service/OpenPrintService.cs @@ -312,8 +312,7 @@ namespace DS.WMS.PrintApi.Service var printFileName = $"{fileName}.frx"; var printFile = Path.Combine(savePath, printFileName); - - + //写入CRX文件 using (FileStream fs = new FileStream(printFile, FileMode.Create)) { @@ -324,7 +323,6 @@ namespace DS.WMS.PrintApi.Service //生成报表 FastReport.Report report = new FastReport.Report(); report.Load(printFile); - var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder(); str.Json = JsonConvert.SerializeObject(data); if (report.Dictionary.Connections.Count == 0) @@ -336,34 +334,9 @@ namespace DS.WMS.PrintApi.Service Name = "Connection", }); } - //else { - // var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection; - // dataSource.ConnectionString = str.ConnectionString; - //} - - //var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection; - //var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder(); - //str.Json = JsonConvert.SerializeObject(data); - //dataSource.ConnectionString = str.ConnectionString; - //JsonSchemaGenerator generator = new JsonSchemaGenerator(); - //JsonSchema jsonSchema = generator.Generate() - - //report.Dictionary.Connections.Clear(); - - //var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection; - //var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder(); - //str.Json = JsonConvert.SerializeObject(data); - ////dataSource.ConnectionString = str.ConnectionString; - ////重置数据源 - //report.Dictionary.Connections.Add(new JsonDataSourceConnection() - //{ - // ConnectionString = str.ConnectionString, - // Alias = "JSON" - //}); - - - //report.Dictionary.Connections[0].ConnectionString = str.ConnectionString; - + + report.Save(printFile); + report.Prepare(); var printName = string.Empty; var saveFile = string.Empty;