626 lines
23 KiB
C#
626 lines
23 KiB
C#
using APT.BaseData.Domain.Entities;
|
||
using APT.BaseData.Domain.Entities.FM;
|
||
using APT.BaseData.Domain.Entities.OP;
|
||
using APT.BaseData.Domain.Enums;
|
||
using APT.BaseData.Domain.IServices.FM;
|
||
using APT.BaseData.Domain.IServices.OP;
|
||
using APT.BaseData.Services.Services.FM;
|
||
using APT.Infrastructure.Api;
|
||
using APT.Infrastructure.Core;
|
||
using APT.Migrations;
|
||
using APT.MS.Domain.Entities.BI;
|
||
using APT.MS.Domain.Entities.FO;
|
||
using APT.MS.Domain.Entities.HM;
|
||
using APT.MS.Domain.Entities.SC.BI;
|
||
using APT.MS.Domain.Entities.SE;
|
||
using APT.MS.Domain.Entities.SK;
|
||
using APT.MS.Domain.Enums;
|
||
using APT.MS.Domain.Enums.SK;
|
||
using APT.Utility;
|
||
using log4net.Core;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Data.SqlClient;
|
||
using NPOI.SS.Formula.Functions;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Data;
|
||
using System.Linq;
|
||
|
||
namespace APT.SC.WebApi.Controllers.Api.BI
|
||
{
|
||
/// <summary>
|
||
/// 年度监测汇总
|
||
/// </summary>
|
||
[Route("api/BI/BIHeadSE")]
|
||
public class BIHeadSEController : APTApiController<T_FM_WORK_TICKET_COMPLETION>
|
||
{
|
||
IOPTenantDBConnService OPTenantDBConnService { get; set; }
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="opTenantDBConnService"></param>
|
||
public BIHeadSEController(IOPTenantDBConnService opTenantDBConnService)
|
||
{
|
||
OPTenantDBConnService = opTenantDBConnService;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取首页 培训数据统计
|
||
/// </summary>
|
||
/// <param name="filter"></param>
|
||
[HttpPost, Route("SEtrInfo")]
|
||
public JsonActionResult<resultHomeSE> SEtrInfo([FromBody] KeywordFilter filter)
|
||
{
|
||
return SafeExecute(() =>
|
||
{
|
||
resultHomeSE result = new resultHomeSE();
|
||
|
||
List<string> listNAME = new List<string>() { "文件学习", "日常培训", "专项培训", "三级教育" };
|
||
List<int> YearCount = new List<int>();
|
||
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.Keyword))
|
||
{
|
||
try
|
||
{
|
||
dtSecrch = Convert.ToDateTime(filter.Keyword);
|
||
}
|
||
catch
|
||
{
|
||
dtSecrch = DateTime.Now;
|
||
}
|
||
}
|
||
|
||
dic.Add("@dtMin", dtSecrch.Year + "-01-01 00:00:00");
|
||
dic.Add("@dtMax", dtSecrch.Year + "-12-31 23:59:59");
|
||
|
||
DateTime dtMonth = Convert.ToDateTime(dtSecrch.Year + "-" + dtSecrch.Month + "-01 00:00:00");
|
||
dic.Add("@dtMonthMin", dtMonth);
|
||
dic.Add("@dtMonthMax", dtMonth.AddMonths(1).AddSeconds(-1));
|
||
|
||
string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value);
|
||
// 年度场次 月度场次 月度人次
|
||
//"文件学习", "日常培训", "专项培训"
|
||
DataSet ds = DBHelper.ExecProcedure(strConn, "proc_HomeSEtrInfo", dic, HttpContext.Request.Path);
|
||
//三级安全教育
|
||
DataSet dsSj = DBHelper.ExecProcedure(strConn, "proc_HomeSESJtrInfo", dic, HttpContext.Request.Path);
|
||
|
||
#region 数据处理
|
||
|
||
DataTable dtYR = ds.Tables[0];
|
||
DataTable dtMR = ds.Tables[1];
|
||
DataTable dtPR = ds.Tables[2];
|
||
|
||
DataTable dtYSj = dsSj.Tables[0];
|
||
DataTable dtMSj = dsSj.Tables[1];
|
||
DataTable dtPSj = dsSj.Tables[2];
|
||
|
||
int Count = 0;
|
||
for (int i = 0; i < 4; i++)
|
||
{
|
||
Count = 0;
|
||
if (i == 3)
|
||
{
|
||
//三级安全教育
|
||
foreach (DataRow item in dtYSj.Rows)
|
||
{
|
||
Count += (int.Parse(item[0].ToString()));
|
||
}
|
||
YearCount.Add(Count);
|
||
Count = 0;
|
||
foreach (DataRow item in dtMSj.Rows)
|
||
{
|
||
Count += (int.Parse(item[0].ToString()));
|
||
}
|
||
MonthRecordCount.Add(Count);
|
||
Count = 0;
|
||
foreach (DataRow item in dtPSj.Rows)
|
||
{
|
||
Count += (int.Parse(item[0].ToString()));
|
||
}
|
||
MonthPersonCount.Add(Count);
|
||
}
|
||
else
|
||
{
|
||
//培训教育
|
||
//年度场次
|
||
foreach (DataRow item in dtYR.Rows)
|
||
{
|
||
if (item["NAME"].ToString() == listNAME[i])
|
||
{
|
||
Count += (int.Parse(item["YCount"].ToString()));
|
||
}
|
||
}
|
||
YearCount.Add(Count);
|
||
//月度场次
|
||
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 dtPR.Rows)
|
||
{
|
||
if (item["NAME"].ToString() == listNAME[i])
|
||
{
|
||
Count += (int.Parse(item["YCount"].ToString()));
|
||
}
|
||
}
|
||
MonthPersonCount.Add(Count);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
result.listNAME = listNAME;
|
||
result.YearCount = YearCount;
|
||
result.MonthRecordCount = MonthRecordCount;
|
||
result.MonthPersonCount = MonthPersonCount;
|
||
result.Msg = "培训类型:listNAME 与 各数量对应 年度数量:YearCount(灰色) 培训场次:MonthRecordCount(黄色) 培训人次:MonthPersonCount(蓝色)";
|
||
return result;
|
||
});
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取首页 培训数据统计
|
||
/// </summary>
|
||
/// <param name="filter"></param>
|
||
[HttpPost, Route("HomeSESubYear")]
|
||
public JsonActionResult<List<SubYearCountRP>> HomeSESubYear([FromBody] KeywordFilter filter)
|
||
{
|
||
return SafeExecute(() =>
|
||
{
|
||
//"公司名称:CNAME 培训人次:PCount(蓝色) 培训场次:RCount(黄色)";
|
||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||
DateTime dtSecrch = DateTime.Now;
|
||
|
||
|
||
//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
|
||
{
|
||
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
|
||
{
|
||
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");
|
||
}
|
||
}
|
||
|
||
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];
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
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("SubMonthInfo")]
|
||
public JsonActionResult<List<SubYearCountRP>> SubMonthInfo([FromBody] KeywordFilter filter)
|
||
{
|
||
return SafeExecute(() =>
|
||
{
|
||
//"公司名称:CNAME 培训人次:PCount(蓝色) 培训场次:RCount(黄色)";
|
||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||
DateTime dtSecrch = DateTime.Now;
|
||
if (!string.IsNullOrEmpty(filter.Keyword))
|
||
{
|
||
try
|
||
{
|
||
dtSecrch = Convert.ToDateTime(filter.Keyword);
|
||
}
|
||
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");
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
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>
|
||
/// 主页面 年度 月度 培训统计
|
||
/// </summary>
|
||
public class resultHomeSE
|
||
{
|
||
public List<string> listNAME { get; set; }
|
||
public List<int> YearCount { get; set; }
|
||
public List<int> MonthRecordCount { get; set; }
|
||
public List<int> MonthPersonCount { get; set; }
|
||
public string Msg { get; set; }
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 年度 场次 人次
|
||
/// </summary>
|
||
public class SubYearCountRP
|
||
{
|
||
public string CName { get; set; }
|
||
public int PCount { get; set; }
|
||
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; }
|
||
}
|
||
}
|