diff --git a/Tiobon.Core.Api/Controllers/CommonController.cs b/Tiobon.Core.Api/Controllers/CommonController.cs index 1085cf42..0e1991b9 100644 --- a/Tiobon.Core.Api/Controllers/CommonController.cs +++ b/Tiobon.Core.Api/Controllers/CommonController.cs @@ -145,9 +145,9 @@ public class CommonController : BaseApiController #endregion - #region 流程提交处理 + #region 调用存储过程封装 /// - /// 流程提交处理 + /// 调用存储过程封装 /// /// /// @@ -157,5 +157,16 @@ public class CommonController : BaseApiController return await _commonServices.getPostCommonAES(param); } + /// + /// 调用存储过程封装 + /// + /// + /// + [HttpPost, Route("getPostCommon")] + public async Task> getPostCommon([FromBody] JObject param) + { + return await _commonServices.getPostCommon(param); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.IServices/ICommonServices.cs b/Tiobon.Core.IServices/ICommonServices.cs index b6877414..af49f011 100644 --- a/Tiobon.Core.IServices/ICommonServices.cs +++ b/Tiobon.Core.IServices/ICommonServices.cs @@ -39,4 +39,6 @@ public interface ICommonServices : IBaseServices> Task CommitFlowAsync(FlowCommitParam param); Task> getPostCommonAES(JObject param); + + Task> getPostCommon(JObject param); } diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 10639ea8..b1f3af72 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -2963,7 +2963,7 @@ public partial class CommonServices : BaseServices>, ICommon } #endregion - public async Task> getPostCommonAES(JObject param) + public async Task> getPostCommonAES(JObject param) { try { @@ -3047,105 +3047,6 @@ public partial class CommonServices : BaseServices>, ICommon // 导出Excel ExportExcel 直接下载 ExportExcel2 预下载 if (_commonType == "ExportExcel" || _commonType == "ExportExcel2") { - // tisking 20240118 add 保存当前导出列 - //string SaveEEConfig = string.Format(@" - // delete [dbo].[Ghrs_ExportExcelByUserConfig] where UserID = {0} and MenuName = '{1}'; - - // insert into [dbo].[Ghrs_ExportExcelByUserConfig] - // (UserID,MenuName,ExportSet,CreateBy,CreateProg,CreateTime) - // select {0} ,'{1}','{2}',{0},'GHR30.getPostCommonAES.ExportExcel2',GETDATE()", - // userID, menuName, exportSet); - //try - //{ - // await Db.Ado.ExecuteCommandAsync(SaveEEConfig); - //} - //catch (Exception) - //{ - //} - - - //IList list = new List(); - //string TableTitle = ""; - //string fileName = ""; - //for (int RowNums = 0; RowNums < ds.Tables.Count; RowNums = RowNums + 2) - //{ - // DataTable Exdt = ds.Tables[RowNums]; - // string Fileds = ds.Tables[RowNums + 1].Rows[0]["Fileds"].ToString(); - // string HeaderName = ds.Tables[RowNums + 1].Rows[0]["HeaderName"].ToString(); - // TableTitle = ds.Tables[RowNums + 1].Rows[0]["TableTitle"].ToString(); - // string IsTitle = ds.Tables[RowNums + 1].Rows[0]["IsTitle"].ToString(); - - // string SheetName = ""; - - // try - // { - // fileName = ds.Tables[RowNums + 1].Rows[0]["FileName"].ToString(); - // SheetName = ds.Tables[RowNums + 1].Rows[0]["SheetName"].ToString(); - // } - // catch (Exception) - // { - // } - - // if (string.IsNullOrEmpty(fileName)) - // fileName = TableTitle; - - // //关键字替换 - // string invalidChars = @"[\\/:*?""<>|]"; // 使用正则表达式替换特殊符号为空字符串 - // fileName = Regex.Replace(fileName, invalidChars, ""); - - // int TitleFontSize = Convert.ToInt32(ds.Tables[RowNums + 1].Rows[0]["TitleFontSize"].ToString()); - // int HeadFontSize = Convert.ToInt32(ds.Tables[RowNums + 1].Rows[0]["HeadFontSize"].ToString()); - // int BodyFontSize = Convert.ToInt32(ds.Tables[RowNums + 1].Rows[0]["BodyFontSize"].ToString()); - // int DefaultWidth = Convert.ToInt32(ds.Tables[RowNums + 1].Rows[0]["DefaultWidth"].ToString()); - - // DefaultWidth = 0; - - - // list.Add(new NPOIModel(Exdt, - // Fileds, //字段 - // !String.IsNullOrEmpty(SheetName) ? SheetName : TableTitle, //sheetName - // HeaderName, //表头 - // IsTitle == "Y" ? TableTitle : "",// 标题 - // 0,// 是否添加序号 - // TitleFontSize, // 标题大小 - // HeadFontSize, // 表头大小 - // BodyFontSize, // 正文大小 - // DefaultWidth // 默认宽度 0为自适应 其余值为默认宽度 需大于0 - // )); - //} - //string ExportMessage = "导出成功"; - //string ExportType = "success"; - //int ExportCode = 0; - - //// 文件名称 - //fileName = fileName + "_" + userID + "_" + (DateTime.Now.ToString("yyyyMMddHHmmssfff")) + ".xls"; - //if (_commonType == "ExportExcel2") - //{ - // try - // { - // NPOIHelper.ExportPath(fileName, list, menuName); - // } - // catch (Exception ex) - // { - // ExportMessage = "导出失败:" + ex.ToString(); - // ExportType = "error"; - // ExportCode = 1; - // } - // Dictionary excelData = new Dictionary{ - // {"result", ""}, - // {"tableTitle", TableTitle}, - // {"fileName", @"\File\DownLoad\"+fileName}, - // {"message",ExportMessage}, - // {"type",ExportType}, - // {"code",ExportCode} - // }; - // return Json(excelData); - //} - //// 直接下载 - //if (_commonType == "ExportExcel1") - //{ - // return ResponseMessage(NPOIHelper.ExportResponse(fileName, list)); - //} } // 此块为存储过程返回的信息 DT_ProcedureResult @@ -3280,4 +3181,191 @@ public partial class CommonServices : BaseServices>, ICommon } } + public async Task> getPostCommon(JObject param) + { + try + { + string procName = ""; + string _commonType = ""; // 类别 + string userID = ""; + IEnumerable properties = param.Properties(); + var dic = new Dictionary(); + foreach (JProperty item in properties) + { + if (item.Name == "procName") + { + procName = item.Value.ToString(); + continue; + } + + if (item.Name == "commonType") + { + _commonType = item.Value.ToString(); + continue; + } + if (item.Name == "userId") + { + userID = item.Value.ToString(); + } + + string jokey = item.Name; + string joValue = item.Value.ToString(); + dic.Add(jokey, joValue); + } + + // procName = "PT_GHR30_Menu_GetWhere"; + // DataTable dtResult = DataAccess.SelectDate("Demo", procName, spParaList); + // DataSet ds = GetProcedureDateSet("Demo", procName, "63", "1", "", "", "", "N", "", "1", "100", "3"); + DataSet ds = await Db.Ado.UseStoredProcedure().GetDataSetAllAsync(procName, dic); + // 导出Excel ExportExcel 直接下载 ExportExcel2 预下载 + + // 此块为存储过程返回的信息 DT_ProcedureResult + DataTable DT_ProcedureResult = null; + DataTable dt = ds.Tables[0]; + string strJson = "{"; + int i = 1; + foreach (DataColumn dc in dt.Columns) + { + if (dt.Rows[0][dc.ColumnName].ToString() == "DT_ProcedureResult") + { + DT_ProcedureResult = ds.Tables[i]; + } + else + { + strJson = strJson + "\"" + dt.Rows[0][dc.ColumnName].ToString() + "\":"; + String json = JsonConvert.SerializeObject(ds.Tables[i]); + + bool tableIsJson = false; + // 根据 table 的栏位名是否为 #Json#开头来判断,是否有Json对象 + foreach (DataColumn dcDetail in ds.Tables[i].Columns) + { + if (dcDetail.ColumnName.StartsWith("#Json#")) + { + tableIsJson = true; + break; + } + } + if (tableIsJson) + { + dynamic dyn = JsonConvert.DeserializeObject(json); + // DT_TableDataT1 + if (ds.Tables[i].Rows.Count == 1 && (!dt.Rows[0][dc.ColumnName].ToString().StartsWith("DT_TableData")))// 单行数据 + { + var obj = dyn[0]; + foreach (DataColumn dcDetail in ds.Tables[i].Columns) + { + if (dcDetail.ColumnName.StartsWith("#Json#")) + { + try + { + obj[dcDetail.ColumnName] = (JToken)JsonConvert.DeserializeObject((string)obj[dcDetail.ColumnName]); + } + catch + { } + } + } + dyn = obj; + } + else + { + foreach (var obj in dyn) // 逐行逐列判断 + { + foreach (DataColumn dcDetail in ds.Tables[i].Columns) + { + if (dcDetail.ColumnName.StartsWith("#Json#")) + { + try + { + obj[dcDetail.ColumnName] = (JToken)JsonConvert.DeserializeObject((string)obj[dcDetail.ColumnName]); + } + catch + { } + } + } + } + } + json = JsonConvert.SerializeObject(dyn); + json = json.Replace("#Json#", ""); + } + strJson = strJson + json; + if (i < ds.Tables.Count - 1) // 第一个table定义 各表的内容 + strJson = strJson + ","; + } + i = i + 1; + } + strJson = strJson + "}"; + string isOK = "0"; + string ErrorMsg = ""; + string WarnMsg = ""; + string SuccessMsg = ""; + string type = "success"; + string message = ""; + if (DT_ProcedureResult.Rows.Count == 1) + { + isOK = DT_ProcedureResult.Rows[0]["IsOK"].ToString(); + ErrorMsg = DT_ProcedureResult.Rows[0]["ErrorMsg"].ToString(); + WarnMsg = DT_ProcedureResult.Rows[0]["WarnMsg"].ToString(); + SuccessMsg = DT_ProcedureResult.Rows[0]["SuccessMsg"].ToString(); + if (isOK == "0") + { + if (!string.IsNullOrEmpty(WarnMsg)) + { + type = "warning"; + message = WarnMsg; + } + else + { + type = "success"; + message = SuccessMsg; + } + } + else + { + type = "error"; + message = ErrorMsg; + } + /* + if (!string.IsNullOrEmpty(isOK)) + { + type = "error"; + message = ErrorMsg; + } + else if (!string.IsNullOrEmpty(WarnMsg)) + { + type = "warning"; + message = WarnMsg; + } + if (!string.IsNullOrEmpty(SuccessMsg)) + { + type = "success"; + message = SuccessMsg; + } */ + } + var data = new Dictionary + { + {"result", JObject.Parse(strJson)}, + {"message",message}, + {"type",type}, + {"code",int.Parse(isOK)} + }; + foreach (DataColumn dcProcedureResult in DT_ProcedureResult.Columns) + { + if (dcProcedureResult.ColumnName != "IsOK" && dcProcedureResult.ColumnName != "ErrorMsg" && + dcProcedureResult.ColumnName != "WarnMsg" && dcProcedureResult.ColumnName != "SuccessMsg") + data.Add(dcProcedureResult.ColumnName, DT_ProcedureResult.Rows[0][dcProcedureResult.ColumnName].ToString()); + } + return data; + } + catch (Exception e) + { + var data = new Dictionary + { + {"result", "{}"}, + {"message",e.Message}, + {"type","error"}, + {"code",1} + }; + return data; + } + } }