diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs index e314443..1638e9f 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs @@ -85,11 +85,12 @@ namespace APT.SC.WebApi.Controllers.Api.BI dic.Add("@dtMonthMin", dtMonth); dic.Add("@dtMonthMax", dtMonth.AddMonths(1).AddSeconds(-1)); + string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value); // 年度场次 月度场次 月度人次 //"文件学习", "日常培训", "专项培训" - DataSet ds = ExecProcedure(filter.OrgId.Value, "proc_HomeSEtrInfo", dic); + DataSet ds = DBHelper.ExecProcedure(strConn, "proc_HomeSEtrInfo", dic, HttpContext.Request.Path); //三级安全教育 - DataSet dsSj = ExecProcedure(filter.OrgId.Value, "proc_HomeSESJtrInfo", dic); + DataSet dsSj = DBHelper.ExecProcedure(strConn, "proc_HomeSESJtrInfo", dic, HttpContext.Request.Path); #region 数据处理 @@ -184,29 +185,81 @@ namespace APT.SC.WebApi.Controllers.Api.BI //"公司名称:CNAME 培训人次:PCount(蓝色) 培训场次:RCount(黄色)"; Dictionary dic = new Dictionary(); DateTime dtSecrch = DateTime.Now; - if (!string.IsNullOrEmpty(filter.Keyword)) + + + //filter.Parameter1 年 + //filter.Parameter2 月 + if (string.IsNullOrEmpty(filter.Parameter1)) { + throw new Exception("传参有误!"); + } + + if (!string.IsNullOrEmpty(filter.Parameter2)) + { + int year = dtSecrch.Year; + int month = dtSecrch.Month; + //查询月度 try { - dtSecrch = Convert.ToDateTime(filter.Keyword); + month = Convert.ToInt32(filter.Parameter2); } catch { - dtSecrch = DateTime.Now; + month = dtSecrch.Month; } - } - dic.Add("@dtMin", dtSecrch.Year + "-01-01 00:00:00"); - if (dtSecrch.Year == DateTime.Now.Year) - { - dic.Add("@dtMax", ""); + if (!string.IsNullOrEmpty(filter.Parameter1)) + { + try + { + year = Convert.ToInt32(filter.Parameter1); + } + catch + { + year = dtSecrch.Year; + } + } + dtSecrch = Convert.ToDateTime(year + "-" + month + "-01 00:00:00"); + dic.Add("@dtMin", dtSecrch.ToString("yyyy-MM-dd 00:00:00")); + + + if (dtSecrch.Year == DateTime.Now.Year && dtSecrch.Month == DateTime.Now.Month) + { + dic.Add("@dtMax", ""); + } + else + { + dic.Add("@dtMax", dtSecrch.AddYears(1).AddSeconds(-1)); + } } else { - dic.Add("@dtMax", dtSecrch.Year + "-12-31 23:59:59"); + //年度查询 + if (!string.IsNullOrEmpty(filter.Parameter1)) + { + try + { + dtSecrch = Convert.ToDateTime(filter.Parameter1); + } + catch + { + dtSecrch = DateTime.Now; + } + } + + dic.Add("@dtMin", dtSecrch.Year + "-01-01 00:00:00"); + if (dtSecrch.Year == DateTime.Now.Year) + { + dic.Add("@dtMax", ""); + } + else + { + dic.Add("@dtMax", dtSecrch.Year + "-12-31 23:59:59"); + } } - DataSet ds = ExecProcedure(filter.OrgId.Value, "proc_HomeSESubYearInfo", dic); + string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value); + DataSet ds = DBHelper.ExecProcedure(strConn, "proc_HomeSESubYearMonthInfo", dic, HttpContext.Request.Path); DataTable dtR = ds.Tables[0]; DataTable dtP = ds.Tables[1]; @@ -275,51 +328,265 @@ namespace APT.SC.WebApi.Controllers.Api.BI }); } + /// - /// 执行视图 + /// 获取首页 培训数据统计 + /// 年度各 公司培训分析 + /// 各公司 月度培训分析 /// - /// - /// - /// 参数 key:@XXX value:val - /// - /// - private DataSet ExecProcedure(Guid orgID, string proName, Dictionary dicParms) + /// + [HttpPost, Route("SubMonthInfo")] + public JsonActionResult> SubMonthInfo([FromBody] KeywordFilter filter) { - DataSet dataSet = new DataSet(); - string strConn = OPTenantDBConnService.GetConnByORGID(orgID);//获取数据库链接 - using (SqlConnection connection = new SqlConnection(strConn)) + return SafeExecute(() => { - try + //"公司名称:CNAME 培训人次:PCount(蓝色) 培训场次:RCount(黄色)"; + Dictionary dic = new Dictionary(); + DateTime dtSecrch = DateTime.Now; + if (!string.IsNullOrEmpty(filter.Keyword)) { - connection.Open(); - string sql = proName; - using (SqlCommand Com = new SqlCommand(sql, connection)) + try { - Com.CommandType = CommandType.StoredProcedure; - foreach (var item in dicParms) - { - Com.Parameters.Add(new SqlParameter(item.Key, item.Value)); - } - using (var adapter = new SqlDataAdapter(Com)) - { - adapter.Fill(dataSet); // 自动处理多个结果集! - } + dtSecrch = Convert.ToDateTime(filter.Keyword); + } + catch + { + dtSecrch = DateTime.Now; } } - catch (Exception ex) + + dic.Add("@dtMin", dtSecrch.Year + "-01-01 00:00:00"); + if (dtSecrch.Year == DateTime.Now.Year) { - if (!string.IsNullOrEmpty(ex.StackTrace)) - throw new Exception("错误日志:[StackTrace]" + ex.StackTrace); + dic.Add("@dtMax", ""); + } + else + { + dic.Add("@dtMax", dtSecrch.Year + "-12-31 23:59:59"); + } + + string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value); + DataSet ds = DBHelper.ExecProcedure(strConn, "proc_HomeSESubMonthInfo", dic, HttpContext.Request.Path); + DataTable dtR = ds.Tables[0]; + DataTable dtP = ds.Tables[1]; + + List listResult = new List(); + string Name = string.Empty; + int Count = 0; + SubYearCountRP modelCheck = null; + foreach (DataRow item in dtR.Rows) + { + Name = item["CNAME"].ToString(); + try + { + Count = int.Parse(item["RCount"].ToString()); + } + catch + { + Count = 0; + } + + modelCheck = listResult.FirstOrDefault(e => e.CName == Name); + if (modelCheck == null) + { + modelCheck = new SubYearCountRP(); + modelCheck.CName = Name; + modelCheck.RCount = Count; + modelCheck.PCount = 0; + listResult.Add(modelCheck); + } else - throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message); + { + modelCheck.RCount += Count; + } } - finally + + foreach (DataRow item in dtP.Rows) { - connection.Close(); + try + { + Count = int.Parse(item["PCount"].ToString()); + } + catch + { + Count = 0; + } + if (Count == 0) + continue; + + Name = item["CNAME"].ToString(); + modelCheck = listResult.FirstOrDefault(e => e.CName == Name); + if (modelCheck == null) + { + //除非执行存储过程异常一般不会 得去找原因 + modelCheck = new SubYearCountRP(); + modelCheck.CName = Name; + modelCheck.RCount = 0; + modelCheck.PCount = Count; + listResult.Add(modelCheck); + } + else + { + modelCheck.PCount += Count; + } } - } - return dataSet; + + return listResult; + }); } + + + /// + /// 获取子页 培训类型情况 + /// + /// + [HttpPost, Route("SubTypeMonth")] + public JsonActionResult SubTypeMonth([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + resultHomeSE result = new resultHomeSE(); + List listNAME = new List() { "文件学习", "日常培训", "专项培训", "三级教育" }; + List MonthRecordCount = new List(); + List MonthPersonCount = new List(); + + Dictionary dic = new Dictionary(); + DateTime dtSecrch = DateTime.Now; + if (!string.IsNullOrEmpty(filter.Parameter1)) + { + try + { + dtSecrch = Convert.ToDateTime(filter.Parameter1); + } + catch + { + dtSecrch = DateTime.Now; + } + } + dtSecrch = Convert.ToDateTime(dtSecrch.ToString("yyyy-MM-01 00:00:00")); + dic.Add("@dtMin", dtSecrch.ToString("yyyy-MM-01 00:00:00")); + dic.Add("@dtMax", dtSecrch.AddMonths(1).AddSeconds(-1)); + + // 场次 人次 + //"文件学习", "日常培训", "专项培训"、三级安全教育 + string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value); + DataSet ds = DBHelper.ExecProcedure(strConn, "proc_HomeSESubTypeMonthInfo", dic, HttpContext.Request.Path); + #region 数据处理 + + DataTable dtMR = ds.Tables[0]; + DataTable dtMP = ds.Tables[1]; + DataTable dtSR = ds.Tables[2]; + DataTable dtSP = ds.Tables[3]; + + int Count = 0; + for (int i = 0; i < 4; i++) + { + Count = 0; + if (i == 3) + { + //三级安全教育 + Count = 0; + foreach (DataRow item in dtSR.Rows) + { + Count += (int.Parse(item[0].ToString())); + } + MonthRecordCount.Add(Count); + Count = 0; + foreach (DataRow item in dtSP.Rows) + { + Count += (int.Parse(item[0].ToString())); + } + MonthPersonCount.Add(Count); + } + else + { + //场次 + Count = 0; + foreach (DataRow item in dtMR.Rows) + { + if (item["NAME"].ToString() == listNAME[i]) + { + Count += (int.Parse(item["YCount"].ToString())); + } + } + MonthRecordCount.Add(Count); + //人次 + Count = 0; + foreach (DataRow item in dtMP.Rows) + { + if (item["NAME"].ToString() == listNAME[i]) + { + Count += (int.Parse(item["YCount"].ToString())); + } + } + MonthPersonCount.Add(Count); + } + } + + #endregion + + result.listNAME = listNAME; + result.MonthRecordCount = MonthRecordCount; + result.MonthPersonCount = MonthPersonCount; + result.Msg = "培训类型:listNAME 与 各数量对应 培训场次:MonthRecordCount(黄色) 培训人次:MonthPersonCount(蓝色)"; + return result; + }); + } + + + /// + /// 各公司证件统计 + /// + /// + [HttpPost, Route("SubCertificateType")] + public JsonActionResult> SubCertificateType([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + List result = new List(); + + Dictionary dic = new Dictionary(); + DateTime dtSecrch = DateTime.Now; + if (!string.IsNullOrEmpty(filter.Parameter1)) + { + try + { + dtSecrch = Convert.ToDateTime(filter.Parameter1); + } + catch + { + dtSecrch = DateTime.Now; + } + } + + dic.Add("@dtMin", dtSecrch.ToString("yyyy-MM-dd 00:00:00")); + string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value); + DataSet ds = DBHelper.ExecProcedure(strConn, "proc_HomeSESubCertificateType", dic, HttpContext.Request.Path); + + DataTable tb = ds.Tables[0]; + int Count = 0; + int RCount = tb.Rows.Count; + CertificateType mode = null; + for (int i = 0; i < RCount; i++) + { + mode = new CertificateType(); + mode.NAME = tb.Rows[i]["Name"].ToString(); + mode.CNAME = tb.Rows[i]["CNAME"].ToString(); + try + { + Count = int.Parse(tb.Rows[i]["TCount"].ToString()); + } + catch + { + Count = 0; + } + mode.TCOUNT = Count; + result.Add(mode); + } + return result; + }); + } + } /// @@ -345,4 +612,14 @@ namespace APT.SC.WebApi.Controllers.Api.BI public int RCount { get; set; } public string Msg { get; set; } } + + /// + /// 证书类型 + /// + public class CertificateType + { + public string CNAME { get; set; } + public string NAME { get; set; } + public int TCOUNT { get; set; } + } } diff --git a/APT.Utility/DBHelper.cs b/APT.Utility/DBHelper.cs new file mode 100644 index 0000000..dd07497 --- /dev/null +++ b/APT.Utility/DBHelper.cs @@ -0,0 +1,105 @@ +using APT.Infrastructure.Core; +using Microsoft.AspNetCore.Http; +using Microsoft.Data.SqlClient; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; + +namespace APT.Utility +{ + public static partial class DBHelper + { + /// + /// 执行存储过程 + /// + /// + /// + /// 参数 key:@XXX value:val + /// + /// + public static DataSet ExecProcedure(string strConn, string proName, Dictionary dicParms, string errorPath) + { + DataSet dataSet = new DataSet(); + + using (SqlConnection connection = new SqlConnection(strConn)) + { + try + { + connection.Open(); + string sql = proName; + using (SqlCommand Com = new SqlCommand(sql, connection)) + { + Com.CommandType = CommandType.StoredProcedure; + foreach (var item in dicParms) + { + Com.Parameters.Add(new SqlParameter(item.Key, item.Value)); + } + using (var adapter = new SqlDataAdapter(Com)) + { + adapter.Fill(dataSet); // 自动处理多个结果集! + } + } + } + catch (Exception ex) + { + if (!string.IsNullOrEmpty(ex.StackTrace)) + throw new Exception("错误日志:[StackTrace]" + ex.StackTrace); + else + throw new Exception("【" + errorPath + "】错误日志:[Message]" + ex.Message); + } + finally + { + connection.Close(); + } + } + return dataSet; + } + + + /// + /// 获取视图数据 + /// + /// + /// + /// 数据集 + /// + public static DataSet GetViewData(string conn, List listVNAME, string errorPath) + { + DataSet ds = new DataSet(); + using (SqlConnection connection = new SqlConnection(conn)) + { + try + { + connection.Open(); + string sql = string.Empty; + foreach (var item in listVNAME) + { + sql += string.Format(" select * from {0} ", item); + } + + using (SqlCommand Com = new SqlCommand(sql, connection)) + { + SqlDataAdapter DataADP = new SqlDataAdapter(Com); + DataADP.Fill(ds); + } + connection.Close(); + } + catch (Exception ex) + { + if (!string.IsNullOrEmpty(ex.StackTrace)) + throw new Exception("错误日志:[StackTrace]" + ex.StackTrace); + else + throw new Exception("【" + errorPath + "】错误日志:[Message]" + ex.Message); + } + } + return ds; + } + } +}