看板 获取 培训教育相关数据 工具方法 执行存储过程、视图 获取 dataset
This commit is contained in:
parent
c3fbb4e6f6
commit
a3bf3e712d
@ -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,11 +185,61 @@ namespace APT.SC.WebApi.Controllers.Api.BI
|
||||
//"公司名称:CNAME 培训人次:PCount(蓝色) 培训场次:RCount(黄色)";
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
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
|
||||
{
|
||||
month = Convert.ToInt32(filter.Parameter2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
month = dtSecrch.Month;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(filter.Parameter1))
|
||||
{
|
||||
try
|
||||
{
|
||||
dtSecrch = Convert.ToDateTime(filter.Keyword);
|
||||
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
|
||||
{
|
||||
//年度查询
|
||||
if (!string.IsNullOrEmpty(filter.Parameter1))
|
||||
{
|
||||
try
|
||||
{
|
||||
dtSecrch = Convert.ToDateTime(filter.Parameter1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -205,8 +256,10 @@ namespace APT.SC.WebApi.Controllers.Api.BI
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行视图
|
||||
/// 获取首页 培训数据统计
|
||||
/// 年度各 公司培训分析
|
||||
/// 各公司 月度培训分析
|
||||
/// </summary>
|
||||
/// <param name="orgID"></param>
|
||||
/// <param name="proName"></param>
|
||||
/// <param name="dicParms">参数 key:@XXX value:val </param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private DataSet ExecProcedure(Guid orgID, string proName, Dictionary<string, object> dicParms)
|
||||
/// <param name="filter"></param>
|
||||
[HttpPost, Route("SubMonthInfo")]
|
||||
public JsonActionResult<List<SubYearCountRP>> SubMonthInfo([FromBody] KeywordFilter filter)
|
||||
{
|
||||
DataSet dataSet = new DataSet();
|
||||
string strConn = OPTenantDBConnService.GetConnByORGID(orgID);//获取数据库链接
|
||||
using (SqlConnection connection = new SqlConnection(strConn))
|
||||
return SafeExecute(() =>
|
||||
{
|
||||
//"公司名称:CNAME 培训人次:PCount(蓝色) 培训场次:RCount(黄色)";
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
DateTime dtSecrch = DateTime.Now;
|
||||
if (!string.IsNullOrEmpty(filter.Keyword))
|
||||
{
|
||||
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));
|
||||
dtSecrch = Convert.ToDateTime(filter.Keyword);
|
||||
}
|
||||
using (var adapter = new SqlDataAdapter(Com))
|
||||
catch
|
||||
{
|
||||
adapter.Fill(dataSet); // 自动处理多个结果集!
|
||||
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
|
||||
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
connection.Close();
|
||||
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<SubYearCountRP> listResult = new List<SubYearCountRP>();
|
||||
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
|
||||
{
|
||||
modelCheck.RCount += Count;
|
||||
}
|
||||
}
|
||||
return dataSet;
|
||||
|
||||
foreach (DataRow item in dtP.Rows)
|
||||
{
|
||||
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 listResult;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取子页 培训类型情况
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
[HttpPost, Route("SubTypeMonth")]
|
||||
public JsonActionResult<resultHomeSE> SubTypeMonth([FromBody] KeywordFilter filter)
|
||||
{
|
||||
return SafeExecute(() =>
|
||||
{
|
||||
resultHomeSE result = new resultHomeSE();
|
||||
List<string> listNAME = new List<string>() { "文件学习", "日常培训", "专项培训", "三级教育" };
|
||||
List<int> MonthRecordCount = new List<int>();
|
||||
List<int> MonthPersonCount = new List<int>();
|
||||
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 各公司证件统计
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
[HttpPost, Route("SubCertificateType")]
|
||||
public JsonActionResult<List<CertificateType>> SubCertificateType([FromBody] KeywordFilter filter)
|
||||
{
|
||||
return SafeExecute(() =>
|
||||
{
|
||||
List<CertificateType> result = new List<CertificateType>();
|
||||
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -345,4 +612,14 @@ namespace APT.SC.WebApi.Controllers.Api.BI
|
||||
public int RCount { get; set; }
|
||||
public string Msg { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 证书类型
|
||||
/// </summary>
|
||||
public class CertificateType
|
||||
{
|
||||
public string CNAME { get; set; }
|
||||
public string NAME { get; set; }
|
||||
public int TCOUNT { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
105
APT.Utility/DBHelper.cs
Normal file
105
APT.Utility/DBHelper.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行存储过程
|
||||
/// </summary>
|
||||
/// <param name="orgID"></param>
|
||||
/// <param name="proName"></param>
|
||||
/// <param name="dicParms">参数 key:@XXX value:val </param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static DataSet ExecProcedure(string strConn, string proName, Dictionary<string, object> 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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取视图数据
|
||||
/// </summary>
|
||||
/// <param name="conn"></param>
|
||||
/// <param name="listVNAME"></param>
|
||||
/// <param name="DataADP">数据集</param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static DataSet GetViewData(string conn, List<string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user