Merge branch 'master' of http://121.41.2.71:3000/wyw/mh_jy_safe
This commit is contained in:
commit
061cb55e06
@ -0,0 +1,348 @@
|
||||
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));
|
||||
|
||||
// 年度场次 月度场次 月度人次
|
||||
//"文件学习", "日常培训", "专项培训"
|
||||
DataSet ds = ExecProcedure(filter.OrgId.Value, "proc_HomeSEtrInfo", dic);
|
||||
//三级安全教育
|
||||
DataSet dsSj = ExecProcedure(filter.OrgId.Value, "proc_HomeSESJtrInfo", dic);
|
||||
|
||||
#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;
|
||||
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");
|
||||
}
|
||||
|
||||
DataSet ds = ExecProcedure(filter.OrgId.Value, "proc_HomeSESubYearInfo", dic);
|
||||
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="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)
|
||||
{
|
||||
DataSet dataSet = new DataSet();
|
||||
string strConn = OPTenantDBConnService.GetConnByORGID(orgID);//获取数据库链接
|
||||
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("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
return dataSet;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user