From 96de25375e07b0c8c78045cdb59d2e04623d7198 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Wed, 11 Sep 2024 16:59:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=B9=E8=AE=AD=E9=9C=80=E6=B1=82=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommonController.cs | 17 +- Tiobon.Core.Api/Tiobon.Core.xml | 7 + Tiobon.Core.IServices/ICommonServices.cs | 2 + Tiobon.Core.Model/ServiceResult.cs | 1 + Tiobon.Core.Model/ViewModels/Menu.cs | 11 ++ Tiobon.Core.Services/CommonServices.cs | 182 +++++++++++++++++- .../Ghre/Ghre_RequestServices.cs | 11 +- Tiobon.Core/Tiobon.Core.xml | 7 + 8 files changed, 233 insertions(+), 5 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/CommonController.cs b/Tiobon.Core.Api/Controllers/CommonController.cs index 1a51b185..8e5226f2 100644 --- a/Tiobon.Core.Api/Controllers/CommonController.cs +++ b/Tiobon.Core.Api/Controllers/CommonController.cs @@ -125,6 +125,21 @@ public class CommonController : BaseApiController { return await _commonServices.GetFlowInfoAsync(param); } - + + #endregion + + + #region 流程提交处理 + /// + /// 流程提交处理 + /// + /// + /// + [HttpPost, Route("CommitFlow")] + public async Task CommitFlowAsync([FromBody] FlowCommitParam param) + { + return await _commonServices.CommitFlowAsync(param); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 7a34ef4d..1d122da1 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -304,6 +304,13 @@ + + + 流程提交处理 + + + + 构造函数 diff --git a/Tiobon.Core.IServices/ICommonServices.cs b/Tiobon.Core.IServices/ICommonServices.cs index a20f7fbc..4386f927 100644 --- a/Tiobon.Core.IServices/ICommonServices.cs +++ b/Tiobon.Core.IServices/ICommonServices.cs @@ -32,4 +32,6 @@ public interface ICommonServices : IBaseServices> Task> ImportExcelAsync(IFormFile file, string menuName, int langId, int userId); Task> GetFlowInfoAsync(FlowParam param); + + Task CommitFlowAsync(FlowCommitParam param); } diff --git a/Tiobon.Core.Model/ServiceResult.cs b/Tiobon.Core.Model/ServiceResult.cs index 8c996b7d..f27f30d1 100644 --- a/Tiobon.Core.Model/ServiceResult.cs +++ b/Tiobon.Core.Model/ServiceResult.cs @@ -27,6 +27,7 @@ public class ServiceResult /// 返回数据集合 /// public T Data { get; set; } + public T result { get; set; } /// /// 返回成功 diff --git a/Tiobon.Core.Model/ViewModels/Menu.cs b/Tiobon.Core.Model/ViewModels/Menu.cs index 2eeeeb01..71be8cae 100644 --- a/Tiobon.Core.Model/ViewModels/Menu.cs +++ b/Tiobon.Core.Model/ViewModels/Menu.cs @@ -255,4 +255,15 @@ public class FlowTableColumn public bool @required { get; set; } public bool multipleSelect { get; set; } public int rowNum { get; set; } +} +public class FlowCommitParam +{ + public string doType { get; set; } + public int? id { get; set; } + public object jsonParam { get; set; } + public int langId { get; set; } + public string menuName { get; set; } + public string timestamp { get; set; } + public string token { get; set; } + public int? userId { get; set; } } \ No newline at end of file diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index a85aa7a7..9d9f8a86 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -12,6 +12,7 @@ using Tiobon.Core.Common.Helper; using Tiobon.Core.DataAccess; using Tiobon.Core.IServices; using Tiobon.Core.Model; +using Tiobon.Core.Model.Models; using Tiobon.Core.Services.BASE; namespace Tiobon.Core.Services; @@ -2136,7 +2137,186 @@ public partial class CommonServices : BaseServices>, ICommon flowReturn.DT_TableDataT1 = await Db.Ado.GetDataTableAsync(sql); #endregion - return new ServiceResult() { Success = true, Message = "查询成功", Data = flowReturn }; + return new ServiceResult() { Success = true, Message = "查询成功", result = flowReturn }; + } + #endregion + + #region 流程提交处理 + /// + /// 流程提交处理 + /// + /// + /// + public async Task CommitFlowAsync(FlowCommitParam param) + { + var @InitmenuName = param.menuName; + int @FlowID = 0; + int @NeedOPLog = 1; + long @OperateLogID = 0; + + #region 写入日志 + var sql = $@"DECLARE @return_value int; + + DECLARE @OperateLogID bigint; + + + SET @OperateLogID = NULL; + + EXEC @return_value = GHR30.dbo.[PS_OperateLog] + @OpUserID = {param.userId}, + @OpType = {param.doType}, + @OpMenuNo = {param.menuName}, + @OpTableName = {param.menuName}, + @OpTableID = {param.id}, + @OpDetailInfo = '{param.jsonParam.ToString()}', + @OperateLogID = @OperateLogID out; + + SELECT @OperateLogID as N'@OperateLogID', @return_value as N'@Return Value';"; + await Db.Ado.ExecuteCommandAsync(sql); + #endregion + + sql = $"SELECT FlowID FROM Ghrs_Menu b WHERE b.Menuno = '{param.menuName}' AND b.IsEnable = 1"; + @FlowID = await Db.Ado.GetIntAsync(sql); + + + switch (param.menuName) + { + case "F_ESS_TrainRequestApply": + + #region 写入数据,并判断是否有错误 + switch (param.doType) + { + case "Apply": + case "BatchApply": + + #region 写入数据,并判断是否有错误 + string json = param.jsonParam.ToString(); + var dict = JsonHelper.JsonToObj(json); + + dict.SponsorId = GetStaffId(); + dict.RequestNo = await GenerateContinuousSequence("Ghre_Request", "RequestNo", "R"); + var id = await Db.Insertable(dict).ExecuteReturnSnowflakeIdAsync(); + + sql = $"SELECT MAX(id)+1 FROM Ghre_Request WHERE Id !='{id}'"; + var id1 = await Db.Ado.GetLongAsync(sql); + sql = $"UPDATE Ghre_Request SET Id={id1} WHERE Id ='{id}'"; + await Db.Ado.ExecuteCommandAsync(sql); + + id = id1; + #endregion + + #region 生成流程数据 + sql = @$"DECLARE @return_value int; + + DECLARE @ErrorMsg nvarchar(2000); + + SET @ErrorMsg = NULL; + + EXEC @return_value = GHR30.dbo.[PT_GHR30_FlowApply] + @ID = {id}, + @FlowID = {@FlowID}, + @UserID = {param.userId}, + @LangID = {param.langId}, + @ErrorMsg = @ErrorMsg out; + + SELECT @ErrorMsg as N'@ErrorMsg', @return_value as N'@Return Value';"; + + var message = await Db.Ado.GetStringAsync(sql); + + if (message.IsNotEmptyOrNull()) + return new ServiceResult() { Success = false, Message = message }; + + #endregion + + break; + } + #endregion + + break; + } + + return new ServiceResult() { Success = true, Message = "提交成功" }; + } + #endregion + + + #region MyRegion + public int? GetStaffId() + { + int? StaffId = null; + string sql = $"SELECT UserStaffID FROM Ghrs_User WHERE UserId='{App.User.ID}'"; + string StaffId1 = Convert.ToString(DbAccess.ExecuteScalar(sql)); + if (!StaffId1.IsNull()) + StaffId = Convert.ToInt32(StaffId1); + return StaffId; + } + #endregion + + #region 自动编号 + /// + /// 自动编号 + /// + /// 表名 + /// 栏位名 + /// 前缀 + /// + public async Task GenerateContinuousSequence(string tableCode, string columnCode, string prefixTemp, int length = 7, int tempLength = 6) + { + try + { + string result = string.Empty; + int sequence; + + #region 查询 + DbSelect dbSelect = new DbSelect(tableCode + " A", "A", null); + dbSelect.IsInitDefaultValue = false; + + if (!string.IsNullOrEmpty(prefixTemp)) + dbSelect.Select("MAX(SUBSTRING(A." + columnCode + "," + (prefixTemp.Length + 1).ToString() + "," + tempLength.ToString() + "))"); + else + dbSelect.Select("MAX(A." + columnCode + ")"); + //} + //dbSelect.Select("MAX(CONVERT(DECIMAL,SUBSTRING(A.ISSUE_NO," + (prefix.Length + dateString.Length + 1).ToString() + "," + tempLength.ToString() + ")))"); + if (!string.IsNullOrEmpty(prefixTemp)) + dbSelect.Where("SUBSTRING(A." + columnCode + ",1," + (prefixTemp.Length).ToString() + ")", " = ", prefixTemp); + dbSelect.Where("LEN(A." + columnCode + ")", "=", length); + string sql = dbSelect.GetSql(); + //await Db.Ado.GetScalarAsync(sql) + string maxSequence = Convert.ToString(await Db.Ado.GetScalarAsync(sql)); + #endregion + //tempLength = tempLength - dateString.Length; + if (string.IsNullOrEmpty(maxSequence)) + result = prefixTemp + Convert.ToString(1).PadLeft(tempLength, '0'); + else + { + if (!string.IsNullOrEmpty(prefixTemp)) + { + if (int.TryParse(maxSequence, out sequence)) + { + sequence += 1; + if (sequence.ToString().Length > tempLength) + throw new Exception("自动生成字串长度已经超过设定长度!"); + } + else + throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); + result = prefixTemp + sequence.ToString().PadLeft(tempLength, '0'); + } + else + { + if (int.TryParse(maxSequence, out sequence)) + { + sequence += 1; + if (sequence.ToString().Length > length) + throw new Exception("自动生成字串长度已经超过设定长度!"); + } + else + throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); + result = sequence.ToString().PadLeft(length, '0'); + } + } + return result; + } + catch (Exception) { throw; } } #endregion } diff --git a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs index 01ce69f5..290ecd9d 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs @@ -9,8 +9,6 @@ using Tiobon.Core.Common.UserManager; using Tiobon.Core.Model; using Tiobon.Core.Common.Helper; using Tiobon.Core.Common; -using Newtonsoft.Json.Linq; -using System.Collections.Generic; namespace Tiobon.Core.Services; @@ -85,7 +83,14 @@ public class Ghre_RequestServices : BaseServices Update(long Id, EditGhre_RequestInput entity) diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index 7a34ef4d..1d122da1 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -304,6 +304,13 @@ + + + 流程提交处理 + + + + 构造函数