From ffeeb4957350b8f1605eda4487b3b0061b0f6992 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BD=95=E7=BE=8E=E8=8D=A3?=
<10755671+mei-rong-he@user.noreply.gitee.com>
Date: Fri, 16 Jan 2026 16:47:53 +0800
Subject: [PATCH] =?UTF-8?q?=E7=9C=8B=E6=9D=BF=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Api/BIController/BIKanBanController.cs | 525 ++++++++++++++++++
.../APT.SC.WebApi/appsettings.Test.json | 3 +-
2 files changed, 527 insertions(+), 1 deletion(-)
create mode 100644 APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIKanBanController.cs
diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIKanBanController.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIKanBanController.cs
new file mode 100644
index 0000000..9b7d509
--- /dev/null
+++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIKanBanController.cs
@@ -0,0 +1,525 @@
+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.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.BS;
+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.Enums;
+using APT.Utility;
+using InfluxData.Net.InfluxDb.Enums;
+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;
+using static Google.Protobuf.WireFormat;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
+using static NPOI.HSSF.Util.HSSFColor;
+
+namespace APT.SC.WebApi.Controllers.Api.BI
+{
+ ///
+ /// 看板
+ ///
+ [Route("api/BI/BIKanBanController")]
+ public class BIKanBanController : APTApiController
+ {
+ ///
+ /// 返回所有
+ ///
+ public class ReturnAll
+ {
+ //风险等级占比
+ public List riskTypeRate { get; set; }
+ //当日工作票排名前三
+ public List jobTodayTop3 { get; set; }
+ //隐患整改率
+ public HiddenRectify hiddenRectify { get; set; }
+ //各事项排名前三
+ public List taskTop3 { get; set; }
+ //作业现场完成情况统计
+ public List jobFinishRate { get; set; }
+ //各公司安全检查统计
+ public List safeCheckSum { get; set; }
+ }
+
+ ///
+ /// 风险等级占比
+ ///
+ public class RiskTypeRate
+ {
+ public string riskType { get; set; }
+ public int count { get; set; }
+ public string rate { get; set; }
+ }
+ ///
+ /// 当日工作票排名前三
+ ///
+ public class JobTodayTop3
+ {
+ public int num { get; set; }
+ public string company { get; set; }
+ public List details { get; set; }
+ }
+ public class JobTodayDetail
+ {
+ public string company { get; set; }
+ public string jobName { get; set; }
+ public int qty { get; set; }
+ }
+ ///
+ /// 隐患整改率
+ ///
+ public class HiddenRectify
+ {
+ public int qty { get; set; }
+
+ public int ontimeQty { get; set; }
+ public int delayQty { get; set; }
+
+ public string rate { get; set; }
+ }
+ ///
+ /// 各事项排名前三
+ ///
+ public class TaskTopTemp
+ {
+ public int totalQty { get; set; }
+ public int qty { get; set; }
+ public string company { get; set; }
+ public string type { get; set; }
+ }
+ public class TaskTop3
+ {
+ public int totalQty { get; set; }
+ public string company { get; set; }
+ public List details { get; set; }
+ }
+ public class TaskTopDetail
+ {
+ public string name { get; set; }
+ public int qty { get; set; }
+ }
+ ///
+ /// 作业现场完成情况统计
+ ///
+ public class JobFinishRate
+ {
+ public string name { get; set; }
+ public int qty { get; set; }
+ public int finishQty { get; set; }
+ public string rate { get; set; }
+ }
+ ///
+ /// 各公司安全检查统计
+ ///
+ public class SafeCheckSum
+ {
+ public string company { get; set; }
+ public int qty { get; set; }
+ public int num { get; set; }
+ }
+ ///
+ /// 返回看板所有接口
+ ///
+ /// 分页过滤实体
+ ///
+ [HttpPost, Route("ReturnAllData")]
+ public ReturnAll ReturnAllData([FromBody] KeywordFilter filter)
+ {
+ string connhead = ConfigurationManager.ConnectionStrings["head"];
+ ReturnAll result = new ReturnAll();
+ //风险等级占比
+ result.riskTypeRate = RiskTypeRateData(connhead);
+ //当日工作票排名前三
+ result.jobTodayTop3 = JobTodayTopData(connhead,filter.OrgId.Value);
+ //隐患整改率
+ result.hiddenRectify = HiddenRectifyData(connhead);
+ //各事项排名前三
+ result.taskTop3 = TaskTopData(connhead);
+ //作业现场完成情况统计
+ result.jobFinishRate = jobFinishRateData(connhead);
+ //各公司安全检查统计
+ result.safeCheckSum = safeCheckSumData(connhead);
+
+ return result;
+ }
+ ///
+ /// 风险等级占比
+ ///
+ /// 分页过滤实体
+ public List RiskTypeRateData(string connhead)
+ {
+ List result = new List();
+ 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)
+ {
+ foreach (DataRow item in Table.Rows)
+ {
+ result.Add(new RiskTypeRate()
+ {
+ riskType = item["风险类别"] != null ? item["风险类别"].ToString() : null,
+ count = int.Parse(item["数量"].ToString()) != 0 ? int.Parse(item["数量"].ToString()) : 0,
+ rate = item["占比"] != null ? item["占比"].ToString() : "0"
+ });
+ }
+ }
+ }
+ 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;
+ }
+
+ ///
+ /// 当日工作票排名前三
+ ///
+ /// 参数
+ ///
+ public List JobTodayTopData(string connhead,Guid orgId)
+ {
+ List result = new List();
+ var details = new List();
+ 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)
+ {
+ foreach (DataRow item in Table.Rows)
+ {
+ var JobTodayTop3 = new JobTodayTop3();
+ JobTodayTop3.num = int.Parse(item["排名"].ToString()) != 0 ? int.Parse(item["排名"].ToString()) : 0;
+ JobTodayTop3.company = item["公司名称"] != null ? item["公司名称"].ToString() : "";
+ result.Add(JobTodayTop3);
+ }
+ }
+ if (Table2 != null && Table2.Rows.Count > 0)
+ {
+ foreach (DataRow item2 in Table2.Rows)
+ {
+ var JobTodayDetail = new JobTodayDetail();
+ JobTodayDetail.qty = int.Parse(item2["cnt"].ToString()) != 0 ? int.Parse(item2["cnt"].ToString()) : 0;
+ JobTodayDetail.jobName = item2["stepid"] != null ? item2["stepid"].ToString() : null;
+ JobTodayDetail.company = item2["db_name"] != null ? item2["db_name"].ToString() : null;
+ details.Add(JobTodayDetail);
+ }
+ }
+ if (result != null && result.Any())
+ {
+ var steps = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId));
+ foreach (var da in result)
+ {
+ var temps = details.Where(t => t.company == da.company).ToList();
+ if (temps.Any())
+ {
+ var detailTemps = new List();
+ foreach (var de in temps)
+ {
+ var JobTodayDetail = new JobTodayDetail();
+ JobTodayDetail.qty = de.qty;
+ JobTodayDetail.jobName = steps.FirstOrDefault(t=>t.ID == Guid.Parse(de.jobName))?.NAME;
+ JobTodayDetail.company = de.company;
+ detailTemps.Add(JobTodayDetail);
+ }
+ da.details = detailTemps;
+ }
+ }
+ }
+ }
+ 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;
+ }
+
+ ///
+ /// 隐患整改率
+ ///
+ /// 参数
+ ///
+ public HiddenRectify HiddenRectifyData(string connhead)
+ {
+ 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)
+ {
+ result.qty = int.Parse(Table.Rows[0]["隐患数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["隐患数"].ToString()) : 0;
+ result.ontimeQty = 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;
+ }
+ }
+ 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;
+ }
+
+ ///
+ /// 各事项排名前三
+ ///
+ /// 参数
+ ///
+ public List TaskTopData(string connhead)
+ {
+ List result = new List();
+ var dataTemps = new List();
+ 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)
+ {
+ foreach (DataRow item in Table.Rows)
+ {
+ var JobTodayTop3 = new TaskTopTemp();
+ JobTodayTop3.totalQty = int.Parse(item["待办总数"].ToString()) != 0 ? int.Parse(item["待办总数"].ToString()) : 0;
+ JobTodayTop3.qty = int.Parse(item["数量"].ToString()) != 0 ? int.Parse(item["数量"].ToString()) : 0;
+ JobTodayTop3.company = item["公司名称"] != null ? item["公司名称"].ToString() : "";
+ JobTodayTop3.type = item["类型"] != null ? item["类型"].ToString() : "";
+ dataTemps.Add(JobTodayTop3);
+ }
+ }
+ if (dataTemps != null && dataTemps.Any())
+ {
+ var dataGroup = dataTemps.GroupBy(t => new { t.company,t.totalQty }).ToList();
+ foreach (var da in dataGroup)
+ {
+ var TaskTop3 = new TaskTop3();
+ TaskTop3.company = da.Key.company;
+ TaskTop3.totalQty = da.Key.totalQty;
+ var temps = dataTemps.Where(t => t.company == da.Key.company).ToList();
+ if (temps.Any())
+ {
+ var detailTemps = new List();
+ foreach (var de in temps)
+ {
+ var JobTodayDetail = new TaskTopDetail();
+ JobTodayDetail.qty = de.qty;
+ JobTodayDetail.name = de.type;
+ detailTemps.Add(JobTodayDetail);
+ }
+ TaskTop3.details = detailTemps;
+ }
+ 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;
+ }
+
+
+ ///
+ /// 作业现场完成情况统计
+ ///
+ /// 参数
+ ///
+ public List jobFinishRateData(string connhead)
+ {
+ List result = new List();
+ 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)
+ {
+ foreach (DataRow item in Table.Rows)
+ {
+ result.Add(new JobFinishRate()
+ {
+ name = item["表单名称"] != null ? item["表单名称"].ToString() : null,
+ qty = int.Parse(item["总数"].ToString()) != 0 ? int.Parse(item["总数"].ToString()) : 0,
+ finishQty = int.Parse(item["完成数"].ToString()) != 0 ? int.Parse(item["完成数"].ToString()) : 0,
+ rate = item["完成率"] != null ? item["完成率"].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;
+ }
+
+
+ ///
+ /// 各公司安全检查统计
+ ///
+ /// 参数
+ ///
+ public List safeCheckSumData(string connhead)
+ {
+ List result = new List();
+ 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)
+ {
+ foreach (DataRow item in Table.Rows)
+ {
+ result.Add(new SafeCheckSum()
+ {
+ company = item["公司名称"] != null ? item["公司名称"].ToString() : null,
+ qty = int.Parse(item["数量"].ToString()) != 0 ? int.Parse(item["数量"].ToString()) : 0,
+ num = int.Parse(item["排名"].ToString()) != 0 ? int.Parse(item["排名"].ToString()) : 0,
+ });
+ }
+ }
+ }
+ 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;
+ }
+ }
+}
diff --git a/APT.MicroApi/APT.SC.WebApi/appsettings.Test.json b/APT.MicroApi/APT.SC.WebApi/appsettings.Test.json
index 5ccd5cd..d79e9b7 100644
--- a/APT.MicroApi/APT.SC.WebApi/appsettings.Test.json
+++ b/APT.MicroApi/APT.SC.WebApi/appsettings.Test.json
@@ -1,7 +1,8 @@
{
"ConnectionStrings": {
//"default": "User ID=postgres;Password=dfdn!energy;Host=36.134.166.114;Port=5432;Database=mh_op;CommandTimeout=1024;"
- "default": "Server=121.41.2.71;Database=mh_jy_ops;uid=sa;pwd=mhsafe!2021;"
+ "default": "Server=121.41.2.71;Database=mh_jy_ops;uid=sa;pwd=mhsafe!2021;",
+ "head": "Server=124.117.209.78;Database=mh_jy_head;uid=sa;pwd=JySafe@2025*;"
},
"AppSettings": {
"DataBaseType": "sqlserver",