From 452de01fb84084dcf28c62449b65797c7fcf4cf6 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Tue, 25 May 2021 00:49:12 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#I3SKUV=20=E5=A2=9E=E5=8A=A0API=E5=92=8CE?= =?UTF-8?q?F=E6=89=A7=E8=A1=8C=E6=95=88=E7=8E=87=E7=9A=84=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=20=E6=96=B0=E5=A2=9E=E6=B5=81=E7=A8=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A5=E5=8F=A3=20=E5=A2=9E=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=8F=8A=E6=92=A4=E9=94=80=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Helpers/ConfigHelper.cs | 22 ++++ OpenAuth.App/FlowInstance/FlowInstanceApp.cs | 37 ++++++- .../Request/UpdateFlowInstanceReq.cs | 63 +++++++++++ .../Controllers/FlowInstancesController.cs | 2 +- OpenAuth.Mvc/Program.cs | 6 +- OpenAuth.Mvc/appsettings.Production.json | 4 +- OpenAuth.Mvc/appsettings.json | 4 +- OpenAuth.Mvc/wwwroot/js/index.js | 2 +- OpenAuth.Repository/Domain/FlowInstance.cs | 4 +- .../Controllers/FlowInstancesController.cs | 10 +- OpenAuth.WebApi/OpenAuth.WebApi.csproj | 7 +- OpenAuth.WebApi/Program.cs | 10 +- OpenAuth.WebApi/Startup.cs | 20 +++- OpenAuth.WebApi/index.html | 103 ++++++++++++++++++ 14 files changed, 269 insertions(+), 25 deletions(-) create mode 100644 Infrastructure/Helpers/ConfigHelper.cs create mode 100644 OpenAuth.App/FlowInstance/Request/UpdateFlowInstanceReq.cs create mode 100644 OpenAuth.WebApi/index.html diff --git a/Infrastructure/Helpers/ConfigHelper.cs b/Infrastructure/Helpers/ConfigHelper.cs new file mode 100644 index 00000000..f3d6cfc6 --- /dev/null +++ b/Infrastructure/Helpers/ConfigHelper.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.Extensions.Configuration; + +namespace Infrastructure.Helpers +{ + public class ConfigHelper + { + public static IConfigurationRoot GetConfigRoot() + { + var configurationBuilder = new ConfigurationBuilder(); + configurationBuilder.SetBasePath(System.IO.Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile( + $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json", + optional: true) + .AddEnvironmentVariables(); + + var configuration = configurationBuilder.Build(); + return configuration; + } + } +} \ No newline at end of file diff --git a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs index 4fd4dfb8..4f74cca8 100644 --- a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs @@ -146,6 +146,29 @@ namespace OpenAuth.App UnitWork.Save(); return true; } + + /// + /// 更新流程 + /// 更新时可以修改表单内容,可以修改流程基本信息,但不能更换表单模版 + /// + /// + public void Update(UpdateFlowInstanceReq req) + { + var flowinstance = Get(req.Id); + + if (flowinstance.IsFinish != FlowInstanceStatus.Draft && + flowinstance.IsFinish != FlowInstanceStatus.Rejected) + { + throw new Exception("只能修改【草稿】和【驳回】状态的流程"); + } + + flowinstance.Description = req.Description; + flowinstance.Code = req.Code; + flowinstance.FrmData = req.FrmData; + flowinstance.DbName = req.DbName; + flowinstance.CustomName = req.CustomName; + Repository.Update(flowinstance); + } /// /// 节点审核 @@ -551,11 +574,6 @@ namespace OpenAuth.App } } - public void Update(FlowInstance flowScheme) - { - Repository.Update(flowScheme); - } - /// /// 返回用于处理流程节点 /// @@ -667,6 +685,11 @@ namespace OpenAuth.App { var user = _auth.GetCurrentUser().User; FlowInstance flowInstance = Get(request.FlowInstanceId); + if (flowInstance.IsFinish == FlowInstanceStatus.Draft + || flowInstance.IsFinish == FlowInstanceStatus.Finished) + { + throw new Exception("当前流程状态不能召回"); + } FlowRuntime wfruntime = new FlowRuntime(flowInstance); @@ -702,6 +725,10 @@ namespace OpenAuth.App public void Start(StartFlowInstanceReq request) { FlowInstance flowInstance = Get(request.FlowInstanceId); + if (flowInstance.IsFinish != FlowInstanceStatus.Draft) + { + throw new Exception("当前流程不是草稿状态,不能启动"); + } var wfruntime = new FlowRuntime(flowInstance); var user = _auth.GetCurrentUser(); diff --git a/OpenAuth.App/FlowInstance/Request/UpdateFlowInstanceReq.cs b/OpenAuth.App/FlowInstance/Request/UpdateFlowInstanceReq.cs new file mode 100644 index 00000000..757726ad --- /dev/null +++ b/OpenAuth.App/FlowInstance/Request/UpdateFlowInstanceReq.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a CodeSmith Template. +// +// DO NOT MODIFY contents of this file. Changes to this +// file will be lost if the code is regenerated. +// Author:Yubao Li +// +//------------------------------------------------------------------------------ + +using System.ComponentModel; + +namespace OpenAuth.App.Request +{ + /// + /// 创建工作流请求 + /// + public class UpdateFlowInstanceReq : NodeDesignateReq + { + + /// + /// 待更改的流程实例ID + /// + public string Id { get; set; } + + /// + /// 实例编号 + /// + [Description("实例编号")] + public string Code { get; set; } + /// + /// 自定义名称 + /// + [Description("自定义名称")] + public string CustomName { get; set; } + + /// + /// 数据库名称 + /// + [Description("数据库名称")] + public string DbName { get; set; } + /// + /// 表单数据 + /// + [Description("表单数据")] + public string FrmData { get; set; } + + + + /// + /// 所属部门 + /// + [Description("所属部门")] + public string OrgId { get; set; } + + /// + /// 实例备注 + /// + [Description("实例备注")] + public string Description { get; set; } + + } +} \ No newline at end of file diff --git a/OpenAuth.Mvc/Controllers/FlowInstancesController.cs b/OpenAuth.Mvc/Controllers/FlowInstancesController.cs index dfc4c652..8060a9c6 100644 --- a/OpenAuth.Mvc/Controllers/FlowInstancesController.cs +++ b/OpenAuth.Mvc/Controllers/FlowInstancesController.cs @@ -119,7 +119,7 @@ namespace OpenAuth.Mvc.Controllers //添加或修改 [HttpPost] - public string Update(FlowInstance obj) + public string Update(UpdateFlowInstanceReq obj) { try { diff --git a/OpenAuth.Mvc/Program.cs b/OpenAuth.Mvc/Program.cs index 33b7975e..194cea39 100644 --- a/OpenAuth.Mvc/Program.cs +++ b/OpenAuth.Mvc/Program.cs @@ -1,5 +1,6 @@ using System; using Autofac.Extensions.DependencyInjection; +using Infrastructure.Helpers; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -37,7 +38,10 @@ namespace OpenAuth.Mvc .UseServiceProviderFactory(new AutofacServiceProviderFactory()) //将默认ServiceProviderFactory指定为AutofacServiceProviderFactory .ConfigureWebHostDefaults(webBuilder => { - webBuilder.UseUrls("http://*:1802").UseStartup(); + var configuration = ConfigHelper.GetConfigRoot(); + var httpHost = configuration["AppSetting:HttpHost"]; + webBuilder.UseUrls(httpHost).UseStartup(); + Console.WriteLine($"启动成功,访问地址:{httpHost}"); }); } diff --git a/OpenAuth.Mvc/appsettings.Production.json b/OpenAuth.Mvc/appsettings.Production.json index ac3b39bd..b6b7b6d7 100644 --- a/OpenAuth.Mvc/appsettings.Production.json +++ b/OpenAuth.Mvc/appsettings.Production.json @@ -16,6 +16,8 @@ "Version": "demo", "DbTypes": { "OpenAuthDBContext":"MySql" //数据库类型:SqlServer、MySql、Oracle - } + }, + "RedisConf": "redistest.cq-p.com.cn:8001,password=share_redis@123", //redis配置 + "HttpHost": "http://*:1802" //启动绑定地址及端口 } } diff --git a/OpenAuth.Mvc/appsettings.json b/OpenAuth.Mvc/appsettings.json index 4ea00c35..7faf5ab2 100644 --- a/OpenAuth.Mvc/appsettings.json +++ b/OpenAuth.Mvc/appsettings.json @@ -17,6 +17,8 @@ "Version": "1.0", //如果为demo,则可以防止post提交 "DbTypes": { "OpenAuthDBContext":"SqlServer" //数据库类型:SqlServer、MySql、Oracle - } + }, + "RedisConf": "redistest.cq-p.com.cn:8001,password=share_redis@123", //redis配置 + "HttpHost": "http://*:1802" //启动绑定地址及端口 } } diff --git a/OpenAuth.Mvc/wwwroot/js/index.js b/OpenAuth.Mvc/wwwroot/js/index.js index 8b49b556..b28a9867 100644 --- a/OpenAuth.Mvc/wwwroot/js/index.js +++ b/OpenAuth.Mvc/wwwroot/js/index.js @@ -253,7 +253,7 @@ layui.config({ btn: ['火速围观'], moveType: 1, content: '
' + - '

郑重提示:OpenAuth.Core 2.0新版上线,如以前访问过本站点请清空缓存后访问

' + + '

郑重提示:OpenAuth.Core 3.1新版上线,如以前访问过本站点请清空缓存后访问

' + '

喜欢的,快快star吧!

', success: function(layero){ var btn = layero.find('.layui-layer-btn'); diff --git a/OpenAuth.Repository/Domain/FlowInstance.cs b/OpenAuth.Repository/Domain/FlowInstance.cs index a38ed63b..a8e843e0 100644 --- a/OpenAuth.Repository/Domain/FlowInstance.cs +++ b/OpenAuth.Repository/Domain/FlowInstance.cs @@ -162,9 +162,9 @@ namespace OpenAuth.Repository.Domain [Description("实例备注")] public string Description { get; set; } /// - /// 是否完成 + /// 是否完成,当前节点的状态也通过该值表示 /// - [Description("是否完成")] + [Description("是否完成,当前节点的状态也通过该值表示")] public int IsFinish { get; set; } /// /// 执行人 diff --git a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs index d5eec81a..6e60cd64 100644 --- a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs +++ b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs @@ -121,10 +121,14 @@ namespace OpenAuth.WebApi.Controllers return result; } - - //添加或修改 + + /// + /// 更新流程 + /// + /// 更新时可以修改表单内容,可以修改流程基本信息,但不能更换表单模版 + /// [HttpPost] - public Response Update(FlowInstance obj) + public Response Update(UpdateFlowInstanceReq obj) { var result = new Response(); try diff --git a/OpenAuth.WebApi/OpenAuth.WebApi.csproj b/OpenAuth.WebApi/OpenAuth.WebApi.csproj index 8a09a2de..bce925ac 100644 --- a/OpenAuth.WebApi/OpenAuth.WebApi.csproj +++ b/OpenAuth.WebApi/OpenAuth.WebApi.csproj @@ -1,7 +1,7 @@  - net5.0 + netcoreapp3.1 @@ -21,6 +21,7 @@ + @@ -30,6 +31,10 @@ + + + + diff --git a/OpenAuth.WebApi/Program.cs b/OpenAuth.WebApi/Program.cs index 4c8713c2..024aa92c 100644 --- a/OpenAuth.WebApi/Program.cs +++ b/OpenAuth.WebApi/Program.cs @@ -1,6 +1,7 @@ using System; using Autofac.Extensions.DependencyInjection; using Infrastructure; +using Infrastructure.Helpers; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -41,14 +42,7 @@ namespace OpenAuth.WebApi new AutofacServiceProviderFactory()) //将默认ServiceProviderFactory指定为AutofacServiceProviderFactory .ConfigureWebHostDefaults(webBuilder => { - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.SetBasePath(System.IO.Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json", - optional: true) - .AddEnvironmentVariables(); - - var configuration = configurationBuilder.Build(); + var configuration = ConfigHelper.GetConfigRoot(); var httpHost = configuration["AppSetting:HttpHost"]; webBuilder.UseUrls(httpHost).UseStartup(); diff --git a/OpenAuth.WebApi/Startup.cs b/OpenAuth.WebApi/Startup.cs index b135c2be..31a12e74 100644 --- a/OpenAuth.WebApi/Startup.cs +++ b/OpenAuth.WebApi/Startup.cs @@ -62,6 +62,18 @@ namespace OpenAuth.WebApi options.Audience = "openauthapi"; }); } + // 添加MiniProfiler服务 + services.AddMiniProfiler(options => + { + // 设定访问分析结果URL的路由基地址 + options.RouteBasePath = "/profiler"; + + options.ColorScheme = StackExchange.Profiling.ColorScheme.Auto; + options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.BottomLeft; + options.PopupShowTimeWithChildren = true; + options.PopupShowTrivial = true; + options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(); + }).AddEntityFramework();//显示SQL语句及耗时 //添加swagger services.AddSwaggerGen(option => @@ -160,6 +172,8 @@ namespace OpenAuth.WebApi services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"])); + + //设置定时启动的任务 services.AddHostedService(); } @@ -217,13 +231,17 @@ namespace OpenAuth.WebApi //配置ServiceProvider AutofacContainerModule.ConfigServiceProvider(app.ApplicationServices); + + app.UseMiniProfiler(); app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => - { + { + c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("OpenAuth.WebApi.index.html"); + foreach (var controller in GetControllers()) { c.SwaggerEndpoint($"/swagger/{controller.Name.Replace("Controller", "")}/swagger.json", diff --git a/OpenAuth.WebApi/index.html b/OpenAuth.WebApi/index.html new file mode 100644 index 00000000..d1255563 --- /dev/null +++ b/OpenAuth.WebApi/index.html @@ -0,0 +1,103 @@ + + + + + + + + + + OpenAuth.Net接口 - 最好用的.net权限工作流框架|.net core快速开发框架|.net core权限管理|.net core工作流 + + + + + + + + + %(HeadContent) + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + \ No newline at end of file