This commit is contained in:
何美荣 2026-01-20 14:10:41 +08:00
parent 835fa8fd00
commit d2c594c296

View File

@ -3,8 +3,8 @@ using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Entities.OP; using APT.BaseData.Domain.Entities.OP;
using APT.BaseData.Domain.Enums; using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.IServices.FM; using APT.BaseData.Domain.IServices.FM;
using APT.BaseData.Domain.IServices.OP;
using APT.BaseData.Services.Services.FM; using APT.BaseData.Services.Services.FM;
using APT.BaseData.Services.Services.OP;
using APT.Infrastructure.Api; using APT.Infrastructure.Api;
using APT.Infrastructure.Core; using APT.Infrastructure.Core;
using APT.Migrations; using APT.Migrations;
@ -26,6 +26,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using static APT.SC.WebApi.Controllers.Api.BI.BIKanBanController;
using static Google.Protobuf.WireFormat; using static Google.Protobuf.WireFormat;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using static NPOI.HSSF.Util.HSSFColor; using static NPOI.HSSF.Util.HSSFColor;
@ -38,11 +39,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
[Route("api/BI/BIKanBanController")] [Route("api/BI/BIKanBanController")]
public class BIKanBanController : APTApiController<T_FM_NOTIFICATION_TASK> public class BIKanBanController : APTApiController<T_FM_NOTIFICATION_TASK>
{ {
IOPTenantDBConnService OPTenantDBConnService { get; set; }
public BIKanBanController(IOPTenantDBConnService opTenantDBConnService)
{
OPTenantDBConnService = opTenantDBConnService;
}
/// <summary> /// <summary>
/// 返回所有 /// 返回所有
/// </summary> /// </summary>
@ -60,9 +56,9 @@ namespace APT.SC.WebApi.Controllers.Api.BI
public List<JobFinishRate> jobFinishRate { get; set; } public List<JobFinishRate> jobFinishRate { get; set; }
//各公司安全检查统计 //各公司安全检查统计
public List<SafeCheckSum> safeCheckSum { get; set; } public List<SafeCheckSum> safeCheckSum { get; set; }
/// <summary> //各公司危险作业统计
/// 培训教育 public List<LinkSum> linkSum { get; set; }
/// </summary>
public List<SETRAINSHOW> listSETrainSum { get; set; } public List<SETRAINSHOW> listSETrainSum { get; set; }
} }
@ -143,9 +139,14 @@ namespace APT.SC.WebApi.Controllers.Api.BI
public int qty { get; set; } public int qty { get; set; }
public int num { get; set; } public int num { get; set; }
} }
/// <summary>
/// 各公司危险作业统计
/// </summary>
public class LinkSum
{
public string name { get; set; }
public int qty { get; set; }
}
/// <summary> /// <summary>
/// 培训教育学时获取 /// 培训教育学时获取
/// </summary> /// </summary>
@ -170,7 +171,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
/// </summary> /// </summary>
public DateTime START_TIME { get; set; } public DateTime START_TIME { get; set; }
} }
public class SETRAINSHOW public class SETRAINSHOW
{ {
/// <summary> /// <summary>
@ -222,46 +222,100 @@ namespace APT.SC.WebApi.Controllers.Api.BI
public decimal SUM_TRAIN_HOUR_5 { get; set; } public decimal SUM_TRAIN_HOUR_5 { get; set; }
} }
/// <summary> /// <summary>
/// 返回看板所有接口 /// 返回看板所有接口
/// </summary> /// </summary>
/// <param name="filter">分页过滤实体</param> /// <param name="filter">分页过滤实体</param>
/// <returns></returns> /// <returns></returns>
[HttpPost, Route("ReturnAllData")] [HttpPost, Route("ReturnAllData")]
public ReturnAll ReturnAllData([FromBody] KeywordFilter filter) public JsonActionResult<ReturnAll> ReturnAllData([FromBody] KeywordFilter filter)
{ {
ReturnAll result = new ReturnAll(); string connhead = ConfigurationManager.ConnectionStrings["head"];
JsonActionResult<ReturnAll> result = new JsonActionResult<ReturnAll>();
result.Data = new ReturnAll();
DataTable tableRisk = new DataTable();
DataTable tableJob = new DataTable();
DataTable tableJobGroup = new DataTable();
DataTable tableHidden = new DataTable();
DataTable tableTask = new DataTable();
DataTable tableJobRate = new DataTable();
DataTable tableSafeCheck = new DataTable();
DataTable tableLink = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
//风险等级占比
string sqlRisk = "select * from vhome_risk_type_data ";
SqlCommand comRisk = new SqlCommand(sqlRisk, connection);
SqlDataAdapter riskData = new SqlDataAdapter(comRisk);
riskData.Fill(tableRisk);
result.Data.riskTypeRate = RiskTypeRateData(connhead, tableRisk);
//当日工作票排名前三
string sqlJob = "select * from vhome_jobtop3_today ";
SqlCommand comJob = new SqlCommand(sqlJob, connection);
SqlDataAdapter jobData = new SqlDataAdapter(comJob);
jobData.Fill(tableJob);
string sqlJobGroup = "select* from vhome_jobdata_today_group";
SqlCommand comJobGroup = new SqlCommand(sqlJobGroup, connection);
SqlDataAdapter jobGroupData = new SqlDataAdapter(comJobGroup);
jobGroupData.Fill(tableJobGroup);
result.Data.jobTodayTop3 = JobTodayTopData(connhead, filter.OrgId.Value, tableJob, tableJobGroup);
//隐患整改率
string sqlHidden = "select * from vhome_hidden_data_result ";
SqlCommand comHidden = new SqlCommand(sqlHidden, connection);
SqlDataAdapter hiddenData = new SqlDataAdapter(comHidden);
hiddenData.Fill(tableHidden);
result.Data.hiddenRectify = HiddenRectifyData(connhead, tableHidden);
//各事项排名前三
string sqlTask = "select * from vhome_task_data_result ";
SqlCommand comTask = new SqlCommand(sqlTask, connection);
SqlDataAdapter taskData = new SqlDataAdapter(comTask);
taskData.Fill(tableTask);
result.Data.taskTop3 = TaskTopData(connhead, tableTask);
//作业现场完成情况统计
string sqlJobRate = "select * from vhome_jobrecord_data ";
SqlCommand comJobRate = new SqlCommand(sqlJobRate, connection);
SqlDataAdapter jobRateData = new SqlDataAdapter(comJobRate);
jobRateData.Fill(tableJobRate);
result.Data.jobFinishRate = jobFinishRateData(connhead, tableJobRate);
//各公司安全检查统计
string sqlSafecCheck = "select * from vhome_check_total ";
SqlCommand comSafecCheck = new SqlCommand(sqlSafecCheck, connection);
SqlDataAdapter safecCheckData = new SqlDataAdapter(comSafecCheck);
safecCheckData.Fill(tableSafeCheck);
result.Data.safeCheckSum = safeCheckSumData(connhead, tableSafeCheck);
//各公司危险分类统计
string sqlLink = "select * from vhome_operationLink_data ";
SqlCommand comLink = new SqlCommand(sqlLink, connection);
SqlDataAdapter linkData = new SqlDataAdapter(comLink);
linkData.Fill(tableLink);
result.Data.linkSum = linkSumData(connhead, tableLink);
//培训教育 对应统计
var ListAllORG = GetEntities<T_FM_ORGANIZATION>(e => !e.IS_DELETED && e.CODE != "003", null, null).OrderBy(e => e.TENANT_CODE).ToList(); var ListAllORG = GetEntities<T_FM_ORGANIZATION>(e => !e.IS_DELETED && e.CODE != "003", null, null).OrderBy(e => e.TENANT_CODE).ToList();
string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value);//获取数据库链接 string strConn = OPTenantDBConnService.GetConnByORGID(filter.OrgId.Value);//获取数据库链接
List<string> listVNAME = new List<string>() { "vhome_Train_Hour" };//, "vhome_risk_type_data" List<string> listVNAME = new List<string>() { "vhome_Train_Hour" };//, "vhome_risk_type_data"
DataSet ds = new DataSet(); DataSet ds = new DataSet();
GETDBDATA(strConn, listVNAME, ref ds);//获取视图 数据 listVNAME 与 ds.Tables 一一对应 GETDBDATA(strConn, listVNAME, ref ds);//获取视图 数据 listVNAME 与 ds.Tables 一一对应
result.Data.listSETrainSum = GetTrainInfo(ds.Tables[0], ListAllORG);
//培训教育 对应统计
result.listSETrainSum = GetTrainInfo(ds.Tables[0], ListAllORG);
string connhead = ConfigurationManager.ConnectionStrings["head"];//删除吧 TPM是没有相对于配置 connection.Close();
//风险等级占比 }
result.riskTypeRate = RiskTypeRateData(connhead); catch (Exception ex)
//当日工作票排名前三 {
result.jobTodayTop3 = JobTodayTopData(connhead, filter.OrgId.Value); if (!string.IsNullOrEmpty(ex.StackTrace))
//隐患整改率 throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
result.hiddenRectify = HiddenRectifyData(connhead); else
//各事项排名前三 throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
result.taskTop3 = TaskTopData(connhead); }
//作业现场完成情况统计 }
result.jobFinishRate = jobFinishRateData(connhead);
//各公司安全检查统计
result.safeCheckSum = safeCheckSumData(connhead);
return result; return result;
} }
/// <summary> /// <summary>
/// 获取视图数据 /// 获取视图数据
/// </summary> /// </summary>
@ -301,32 +355,13 @@ namespace APT.SC.WebApi.Controllers.Api.BI
} }
} }
} }
/// <summary> /// <summary>
/// 风险等级占比 /// 风险等级占比
/// </summary> /// </summary>
/// <param name="filter">分页过滤实体</param> /// <param name="filter">分页过滤实体</param>
public List<RiskTypeRate> RiskTypeRateData(string connhead) public List<RiskTypeRate> RiskTypeRateData(string connhead, DataTable Table)
{ {
List<RiskTypeRate> result = new List<RiskTypeRate>(); List<RiskTypeRate> result = new List<RiskTypeRate>();
DataTable Table = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
string sql = "select * from vhome_risk_type_data ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table);
}
connection.Close();
if (Table != null && Table.Rows.Count > 0) if (Table != null && Table.Rows.Count > 0)
{ {
foreach (DataRow item in Table.Rows) foreach (DataRow item in Table.Rows)
@ -339,15 +374,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
}); });
} }
} }
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
}
}
return result; return result;
} }
@ -356,40 +382,10 @@ namespace APT.SC.WebApi.Controllers.Api.BI
/// </summary> /// </summary>
/// <param name="filter">参数</param> /// <param name="filter">参数</param>
/// <returns></returns> /// <returns></returns>
public List<JobTodayTop3> JobTodayTopData(string connhead, Guid orgId) public List<JobTodayTop3> JobTodayTopData(string connhead, Guid orgId, DataTable Table, DataTable Table2)
{ {
List<JobTodayTop3> result = new List<JobTodayTop3>(); List<JobTodayTop3> result = new List<JobTodayTop3>();
var details = new List<JobTodayDetail>(); var details = new List<JobTodayDetail>();
DataTable Table = new DataTable();
DataTable Table2 = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
string sql = "select * from vhome_jobtop3_today ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table);
}
string sql2 = "select * from vhome_jobdata_today_group ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table2);
}
connection.Close();
if (Table != null && Table.Rows.Count > 0) if (Table != null && Table.Rows.Count > 0)
{ {
foreach (DataRow item in Table.Rows) foreach (DataRow item in Table.Rows)
@ -433,15 +429,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
} }
} }
} }
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
}
}
return result; return result;
} }
@ -450,27 +437,9 @@ namespace APT.SC.WebApi.Controllers.Api.BI
/// </summary> /// </summary>
/// <param name="filter">参数</param> /// <param name="filter">参数</param>
/// <returns></returns> /// <returns></returns>
public HiddenRectify HiddenRectifyData(string connhead) public HiddenRectify HiddenRectifyData(string connhead, DataTable Table)
{ {
HiddenRectify result = new HiddenRectify(); HiddenRectify result = new HiddenRectify();
DataTable Table = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
string sql = "select * from vhome_hidden_data_result ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table);
}
connection.Close();
if (Table != null && Table.Rows.Count > 0) if (Table != null && Table.Rows.Count > 0)
{ {
result.qty = int.Parse(Table.Rows[0]["隐患数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["隐患数"].ToString()) : 0; result.qty = int.Parse(Table.Rows[0]["隐患数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["隐患数"].ToString()) : 0;
@ -478,15 +447,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
result.delayQty = int.Parse(Table.Rows[0]["延期整改数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["延期整改数"].ToString()) : 0; result.delayQty = int.Parse(Table.Rows[0]["延期整改数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["延期整改数"].ToString()) : 0;
result.rate = Table.Rows[0]["整改率"] != null ? Table.Rows[0]["整改率"].ToString() : null; result.rate = Table.Rows[0]["整改率"] != null ? Table.Rows[0]["整改率"].ToString() : null;
} }
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
}
}
return result; return result;
} }
@ -495,28 +455,10 @@ namespace APT.SC.WebApi.Controllers.Api.BI
/// </summary> /// </summary>
/// <param name="filter">参数</param> /// <param name="filter">参数</param>
/// <returns></returns> /// <returns></returns>
public List<TaskTop3> TaskTopData(string connhead) public List<TaskTop3> TaskTopData(string connhead, DataTable Table)
{ {
List<TaskTop3> result = new List<TaskTop3>(); List<TaskTop3> result = new List<TaskTop3>();
var dataTemps = new List<TaskTopTemp>(); var dataTemps = new List<TaskTopTemp>();
DataTable Table = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
string sql = "select * from vhome_task_data_result ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table);
}
connection.Close();
if (Table != null && Table.Rows.Count > 0) if (Table != null && Table.Rows.Count > 0)
{ {
foreach (DataRow item in Table.Rows) foreach (DataRow item in Table.Rows)
@ -553,15 +495,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
result.Add(TaskTop3); result.Add(TaskTop3);
} }
} }
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
}
}
return result; return result;
} }
@ -571,27 +504,9 @@ namespace APT.SC.WebApi.Controllers.Api.BI
/// </summary> /// </summary>
/// <param name="filter">参数</param> /// <param name="filter">参数</param>
/// <returns></returns> /// <returns></returns>
public List<JobFinishRate> jobFinishRateData(string connhead) public List<JobFinishRate> jobFinishRateData(string connhead, DataTable Table)
{ {
List<JobFinishRate> result = new List<JobFinishRate>(); List<JobFinishRate> result = new List<JobFinishRate>();
DataTable Table = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
string sql = "select * from vhome_jobrecord_data ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table);
}
connection.Close();
if (Table != null && Table.Rows.Count > 0) if (Table != null && Table.Rows.Count > 0)
{ {
foreach (DataRow item in Table.Rows) foreach (DataRow item in Table.Rows)
@ -605,15 +520,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
}); });
} }
} }
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
}
}
return result; return result;
} }
@ -623,27 +529,9 @@ namespace APT.SC.WebApi.Controllers.Api.BI
/// </summary> /// </summary>
/// <param name="filter">参数</param> /// <param name="filter">参数</param>
/// <returns></returns> /// <returns></returns>
public List<SafeCheckSum> safeCheckSumData(string connhead) public List<SafeCheckSum> safeCheckSumData(string connhead, DataTable Table)
{ {
List<SafeCheckSum> result = new List<SafeCheckSum>(); List<SafeCheckSum> result = new List<SafeCheckSum>();
DataTable Table = new DataTable();
using (SqlConnection connection = new SqlConnection(connhead))
{
try
{
connection.Open();
string sql = "select * from vhome_check_total ";
//if (dt != DateTime.Now.Date)
//{
// sql += " and crdate>='" + dt + "'";
//}
//sql += " order by crdate desc";
using (SqlCommand Com = new SqlCommand(sql, connection))
{
SqlDataAdapter Data = new SqlDataAdapter(Com);
Data.Fill(Table);
}
connection.Close();
if (Table != null && Table.Rows.Count > 0) if (Table != null && Table.Rows.Count > 0)
{ {
foreach (DataRow item in Table.Rows) foreach (DataRow item in Table.Rows)
@ -656,18 +544,29 @@ namespace APT.SC.WebApi.Controllers.Api.BI
}); });
} }
} }
return result;
} }
catch (Exception ex) /// <summary>
/// 各公司危险作业统计
/// </summary>
/// <param name="filter">参数</param>
/// <returns></returns>
public List<LinkSum> linkSumData(string connhead, DataTable Table)
{ {
if (!string.IsNullOrEmpty(ex.StackTrace)) List<LinkSum> result = new List<LinkSum>();
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace); if (Table != null && Table.Rows.Count > 0)
else {
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message); foreach (DataRow item in Table.Rows)
{
result.Add(new LinkSum()
{
name = item["NAME"] != null ? item["NAME"].ToString() : null,
qty = !string.IsNullOrEmpty(item["cnt"].ToString()) && int.Parse(item["cnt"].ToString()) != 0 ? int.Parse(item["cnt"].ToString()) : 0
});
} }
} }
return result; return result;
} }
/// <summary> /// <summary>
/// 数据整理 培训教育 /// 数据整理 培训教育
/// </summary> /// </summary>
@ -706,5 +605,6 @@ namespace APT.SC.WebApi.Controllers.Api.BI
} }
return dtInfo; return dtInfo;
} }
} }
} }