From 8e25b6e8e3abba6f33bd72ff9a745e60cff50ec2 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Fri, 18 Nov 2022 23:28:35 +0800 Subject: [PATCH] =?UTF-8?q?fix=20issue=20#I61V1D=20=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E4=B8=8D=E8=83=BD=E5=85=B3=E8=81=94=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/FlowInstance/FlowInstanceApp.cs | 60 +++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs index 0bc52962..73d4637d 100644 --- a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs @@ -28,7 +28,10 @@ using System.Threading.Tasks; using Infrastructure.Const; using Infrastructure.Helpers; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json.Linq; using OpenAuth.Repository; +using OpenAuth.Repository.QueryObj; +using Yitter.IdGenerator; namespace OpenAuth.App { @@ -43,12 +46,13 @@ namespace OpenAuth.App private IHttpClientFactory _httpClientFactory; private IServiceProvider _serviceProvider; private SysMessageApp _messageApp; + private DbExtension _dbExtension; public FlowInstanceApp(IUnitWork unitWork, IRepository repository , RevelanceManagerApp app, FlowSchemeApp flowSchemeApp, FormApp formApp, IHttpClientFactory httpClientFactory, IAuth auth, IServiceProvider serviceProvider, - SysMessageApp messageApp) + SysMessageApp messageApp, DbExtension dbExtension) : base(unitWork, repository, auth) { _revelanceApp = app; @@ -57,6 +61,7 @@ namespace OpenAuth.App _httpClientFactory = httpClientFactory; _serviceProvider = serviceProvider; _messageApp = messageApp; + _dbExtension = dbExtension; } #region 流程处理API @@ -126,6 +131,59 @@ namespace OpenAuth.App icf.Add(flowInstance.Id, flowInstance.FrmData); } + //如果工作流配置的表单配置有对应的数据库 + if (!string.IsNullOrEmpty(form.DbName)) + { + var dbcolumns = _dbExtension.GetDbTableStructure(form.DbName); + var json = JsonHelper.Instance.Deserialize(addFlowInstanceReq.FrmData); + var columnstr = string.Empty; //字段 + var valstr = string.Empty; //值字符串 + + + foreach (var column in dbcolumns) + { + if (column.ColumnName == "Id" || column.ColumnName=="id") + { + var options = new IdGeneratorOptions() + { + Method = 1, + WorkerId = 1 + }; + + YitIdHelper.SetIdGenerator(options); + columnstr += "Id,"; + valstr += "'" + YitIdHelper.NextId().ToString() + "',"; + continue; + } + + var val = json[column.ColumnName]; + if (val == null) + { + switch (column.EntityType) + { + case "int": + val = 0; + break; + case "string": + val = ""; + break; + case "DateTime": + val = DateTime.Now.ToString("yyyy-MM-dd"); + break; + } + } + + if(val == null) continue; + columnstr += column.ColumnName + ","; + valstr += "'" + val + "',"; + } + + columnstr = columnstr.TrimEnd(','); + valstr = valstr.TrimEnd(','); + var sql = $"insert into {form.DbName}({columnstr}) values ({valstr})"; + UnitWork.ExecuteSql(sql); + } + #endregion 根据运行实例改变当前节点状态 #region 流程操作记录