mh_jy_safe/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIKanBanController.cs

711 lines
30 KiB
C#
Raw Normal View History

2026-01-20 11:05:15 +08:00
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;
2026-01-20 10:49:21 +08:00
using APT.BaseData.Domain.IServices.OP;
2026-01-20 11:05:15 +08:00
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;
2026-01-20 10:49:21 +08:00
using System.Linq;
2026-01-20 11:05:15 +08:00
using static Google.Protobuf.WireFormat;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using static NPOI.HSSF.Util.HSSFColor;
namespace APT.SC.WebApi.Controllers.Api.BI
{
/// <summary>
/// 看板
/// </summary>
[Route("api/BI/BIKanBanController")]
public class BIKanBanController : APTApiController<T_FM_NOTIFICATION_TASK>
2026-01-16 16:47:53 +08:00
{
2026-01-20 10:49:21 +08:00
IOPTenantDBConnService OPTenantDBConnService { get; set; }
public BIKanBanController(IOPTenantDBConnService opTenantDBConnService)
{
OPTenantDBConnService = opTenantDBConnService;
}
2026-01-16 16:47:53 +08:00
/// <summary>
/// 返回所有
/// </summary>
public class ReturnAll
{
//风险等级占比
public List<RiskTypeRate> riskTypeRate { get; set; }
//当日工作票排名前三
public List<JobTodayTop3> jobTodayTop3 { get; set; }
//隐患整改率
public HiddenRectify hiddenRectify { get; set; }
//各事项排名前三
public List<TaskTop3> taskTop3 { get; set; }
//作业现场完成情况统计
public List<JobFinishRate> jobFinishRate { get; set; }
//各公司安全检查统计
2026-01-20 11:05:15 +08:00
public List<SafeCheckSum> safeCheckSum { get; set; }
/// <summary>
/// 培训教育
/// </summary>
public List<SETRAINSHOW> listSETrainSum { get; set; }
}
2026-01-16 16:47:53 +08:00
/// <summary>
/// 风险等级占比
2026-01-20 11:05:15 +08:00
/// </summary>
public class RiskTypeRate
{
public string riskType { get; set; }
public int count { get; set; }
public string rate { get; set; }
2026-01-16 16:47:53 +08:00
}
/// <summary>
/// 当日工作票排名前三
2026-01-20 11:05:15 +08:00
/// </summary>
public class JobTodayTop3
2026-01-16 16:47:53 +08:00
{
2026-01-16 17:32:38 +08:00
public int totalQty { get; set; }
2026-01-20 11:05:15 +08:00
public int num { get; set; }
public string company { get; set; }
public List<JobTodayDetail> details { get; set; }
}
public class JobTodayDetail
2026-01-16 16:47:53 +08:00
{
2026-01-20 11:05:15 +08:00
public string company { get; set; }
public string jobName { get; set; }
public int qty { get; set; }
2026-01-16 16:47:53 +08:00
}
/// <summary>
/// 隐患整改率
2026-01-20 11:05:15 +08:00
/// </summary>
public class HiddenRectify
2026-01-16 16:47:53 +08:00
{
public int qty { get; set; }
public int ontimeQty { get; set; }
public int delayQty { get; set; }
2026-01-20 11:05:15 +08:00
public string rate { get; set; }
2026-01-16 16:47:53 +08:00
}
/// <summary>
/// 各事项排名前三
2026-01-20 11:05:15 +08:00
/// </summary>
public class TaskTopTemp
2026-01-16 16:47:53 +08:00
{
public int totalQty { get; set; }
2026-01-20 11:05:15 +08:00
public int qty { get; set; }
2026-01-16 16:47:53 +08:00
public string company { get; set; }
2026-01-20 11:05:15 +08:00
public string type { get; set; }
}
public class TaskTop3
2026-01-16 16:47:53 +08:00
{
2026-01-20 11:05:15 +08:00
public int totalQty { get; set; }
public string company { get; set; }
public List<TaskTopDetail> details { get; set; }
}
public class TaskTopDetail
{
public string name { get; set; }
public int qty { get; set; }
2026-01-16 16:47:53 +08:00
}
/// <summary>
/// 作业现场完成情况统计
2026-01-20 11:05:15 +08:00
/// </summary>
public class JobFinishRate
{
public string name { get; set; }
2026-01-16 16:47:53 +08:00
public int qty { get; set; }
public int finishQty { get; set; }
2026-01-20 11:05:15 +08:00
public string rate { get; set; }
2026-01-16 16:47:53 +08:00
}
/// <summary>
/// 各公司安全检查统计
/// </summary>
2026-01-20 11:05:15 +08:00
public class SafeCheckSum
{
public string company { get; set; }
2026-01-16 16:47:53 +08:00
public int qty { get; set; }
2026-01-20 11:05:15 +08:00
public int num { get; set; }
2026-01-16 16:47:53 +08:00
}
2026-01-20 10:49:21 +08:00
2026-01-20 11:05:15 +08:00
2026-01-20 10:49:21 +08:00
/// <summary>
/// 培训教育学时获取
/// </summary>
public class SETRAIN
{
/// <summary>
/// 公司名称
/// </summary>
public string CN { get; set; }
/// <summary>
///
/// </summary>
public Guid ORG_ID { get; set; }
/// <summary>
/// 培训时长
/// </summary>
public decimal TRAIN_HOUR { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime START_TIME { get; set; }
}
public class SETRAINSHOW
{
/// <summary>
/// 公司名称
/// </summary>
public string CN { get; set; }
/// <summary>
///
/// </summary>
public Guid ORG_ID { get; set; }
/// <summary>
/// 当前年月
/// </summary>
public DateTime dtNowYM { get; set; }
/// <summary>
/// 当前年月-1
/// </summary>
public DateTime dtNowYM_1 { get; set; }
public DateTime dtNowYM_2 { get; set; }
public DateTime dtNowYM_3 { get; set; }
public DateTime dtNowYM_4 { get; set; }
public DateTime dtNowYM_5 { get; set; }
/// <summary>
/// 当前月 培训时长总和
/// </summary>
public decimal SUM_TRAIN_HOUR { get; set; }
/// <summary>
/// 当前月-1 培训时长总和
/// </summary>
public decimal SUM_TRAIN_HOUR_1 { get; set; }
/// <summary>
/// 当前月-2 培训时长总和
/// </summary>
public decimal SUM_TRAIN_HOUR_2 { get; set; }
/// <summary>
/// 当前月-3 培训时长总和
/// </summary>
public decimal SUM_TRAIN_HOUR_3 { get; set; }
/// <summary>
/// 当前月-4 培训时长总和
/// </summary>
public decimal SUM_TRAIN_HOUR_4 { get; set; }
/// <summary>
/// 当前月-5 培训时长总和
/// </summary>
public decimal SUM_TRAIN_HOUR_5 { get; set; }
}
2026-01-20 11:05:15 +08:00
/// <summary>
/// 返回看板所有接口
/// </summary>
/// <param name="filter">分页过滤实体</param>
/// <returns></returns>
[HttpPost, Route("ReturnAllData")]
public ReturnAll ReturnAllData([FromBody] KeywordFilter filter)
{
2026-01-16 16:47:53 +08:00
ReturnAll result = new ReturnAll();
2026-01-20 10:49:21 +08:00
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);//获取数据库链接
List<string> listVNAME = new List<string>() { "vhome_Train_Hour" };//, "vhome_risk_type_data"
DataSet ds = new DataSet();
GETDBDATA(strConn, listVNAME, ref ds);//获取视图 数据 listVNAME 与 ds.Tables 一一对应
//培训教育 对应统计
result.listSETrainSum = GetTrainInfo(ds.Tables[0], ListAllORG);
string connhead = ConfigurationManager.ConnectionStrings["head"];//删除吧 TPM是没有相对于配置
2026-01-16 16:47:53 +08:00
//风险等级占比
2026-01-20 11:05:15 +08:00
result.riskTypeRate = RiskTypeRateData(connhead);
2026-01-16 16:47:53 +08:00
//当日工作票排名前三
2026-01-20 10:49:21 +08:00
result.jobTodayTop3 = JobTodayTopData(connhead, filter.OrgId.Value);
2026-01-16 16:47:53 +08:00
//隐患整改率
result.hiddenRectify = HiddenRectifyData(connhead);
//各事项排名前三
result.taskTop3 = TaskTopData(connhead);
//作业现场完成情况统计
result.jobFinishRate = jobFinishRateData(connhead);
//各公司安全检查统计
result.safeCheckSum = safeCheckSumData(connhead);
2026-01-20 11:05:15 +08:00
return result;
2026-01-16 16:47:53 +08:00
}
2026-01-20 10:49:21 +08:00
/// <summary>
/// 获取视图数据
/// </summary>
/// <param name="conn"></param>
/// <param name="listVNAME"></param>
/// <param name="DataADP">数据集</param>
/// <exception cref="Exception"></exception>
private void GETDBDATA(string conn, List<string> listVNAME, ref DataSet ds)
{
List<RiskTypeRate> result = new List<RiskTypeRate>();
//DataTable Table = new DataTable();
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();
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-20 10:49:21 +08:00
}
}
}
2026-01-20 11:05:15 +08:00
/// <summary>
/// 风险等级占比
/// </summary>
/// <param name="filter">分页过滤实体</param>
public List<RiskTypeRate> RiskTypeRateData(string connhead)
{
2026-01-16 16:47:53 +08:00
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();
2026-01-20 11:05:15 +08:00
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"
});
}
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
return result;
2026-01-16 16:47:53 +08:00
}
2026-01-20 10:49:21 +08:00
2026-01-20 11:05:15 +08:00
/// <summary>
/// 当日工作票排名前三
/// </summary>
/// <param name="filter">参数</param>
/// <returns></returns>
public List<JobTodayTop3> JobTodayTopData(string connhead, Guid orgId)
{
2026-01-16 16:47:53 +08:00
List<JobTodayTop3> result = new List<JobTodayTop3>();
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();
2026-01-20 11:05:15 +08:00
if (Table != null && Table.Rows.Count > 0)
{
foreach (DataRow item in Table.Rows)
{
var JobTodayTop3 = new JobTodayTop3();
JobTodayTop3.totalQty = int.Parse(item["今日总数"].ToString()) != 0 ? int.Parse(item["今日总数"].ToString()) : 0;
JobTodayTop3.num = int.Parse(item["排名"].ToString()) != 0 ? int.Parse(item["排名"].ToString()) : 0;
JobTodayTop3.company = item["公司名称"] != null ? item["公司名称"].ToString() : "";
result.Add(JobTodayTop3);
}
2026-01-16 16:47:53 +08:00
}
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_HM_OPERATION_STEP>(t => !t.IS_DELETED, new BaseFilter(orgId));
2026-01-20 10:49:21 +08:00
foreach (var da in result)
2026-01-16 16:47:53 +08:00
{
var temps = details.Where(t => t.company == da.company).ToList();
if (temps.Any())
{
var detailTemps = new List<JobTodayDetail>();
foreach (var de in temps)
{
var JobTodayDetail = new JobTodayDetail();
JobTodayDetail.qty = de.qty;
2026-01-20 10:49:21 +08:00
JobTodayDetail.jobName = steps.FirstOrDefault(t => t.ID == Guid.Parse(de.jobName))?.NAME;
2026-01-16 16:47:53 +08:00
JobTodayDetail.company = de.company;
detailTemps.Add(JobTodayDetail);
}
da.details = detailTemps;
}
}
}
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
return result;
2026-01-16 16:47:53 +08:00
}
2026-01-20 10:49:21 +08:00
2026-01-20 11:05:15 +08:00
/// <summary>
/// 隐患整改率
/// </summary>
/// <param name="filter">参数</param>
/// <returns></returns>
public HiddenRectify HiddenRectifyData(string connhead)
2026-01-16 16:47:53 +08:00
{
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();
2026-01-20 11:05:15 +08:00
if (Table != null && Table.Rows.Count > 0)
{
2026-01-16 16:47:53 +08:00
result.qty = int.Parse(Table.Rows[0]["隐患数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["隐患数"].ToString()) : 0;
2026-01-20 11:05:15 +08:00
result.ontimeQty = int.Parse(Table.Rows[0]["按期整改数"].ToString()) != 0 ? int.Parse(Table.Rows[0]["按期整改数"].ToString()) : 0;
2026-01-16 16:47:53 +08:00
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;
}
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
return result;
2026-01-16 16:47:53 +08:00
}
2026-01-20 10:49:21 +08:00
2026-01-20 11:05:15 +08:00
/// <summary>
/// 各事项排名前三
/// </summary>
/// <param name="filter">参数</param>
/// <returns></returns>
public List<TaskTop3> TaskTopData(string connhead)
{
2026-01-16 16:47:53 +08:00
List<TaskTop3> result = new List<TaskTop3>();
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();
2026-01-20 11:05:15 +08:00
if (Table != null && Table.Rows.Count > 0)
{
foreach (DataRow item in Table.Rows)
{
var JobTodayTop3 = new TaskTopTemp();
2026-01-16 16:47:53 +08:00
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() : "";
2026-01-20 11:05:15 +08:00
JobTodayTop3.type = item["类型"] != null ? item["类型"].ToString() : "";
dataTemps.Add(JobTodayTop3);
}
2026-01-16 16:47:53 +08:00
}
if (dataTemps != null && dataTemps.Any())
{
2026-01-20 10:49:21 +08:00
var dataGroup = dataTemps.GroupBy(t => new { t.company, t.totalQty }).ToList();
2026-01-16 16:47:53 +08:00
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<TaskTopDetail>();
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);
}
}
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
return result;
2026-01-20 10:49:21 +08:00
}
2026-01-16 16:47:53 +08:00
2026-01-20 11:05:15 +08:00
/// <summary>
/// 作业现场完成情况统计
/// </summary>
/// <param name="filter">参数</param>
/// <returns></returns>
public List<JobFinishRate> jobFinishRateData(string connhead)
{
2026-01-16 16:47:53 +08:00
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();
2026-01-20 11:05:15 +08:00
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,
2026-01-16 16:47:53 +08:00
finishQty = int.Parse(item["完成数"].ToString()) != 0 ? int.Parse(item["完成数"].ToString()) : 0,
2026-01-20 11:05:15 +08:00
rate = item["完成率"] != null ? item["完成率"].ToString() : null,
});
}
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
return result;
2026-01-16 16:47:53 +08:00
}
2026-01-20 10:49:21 +08:00
2026-01-16 16:47:53 +08:00
2026-01-20 11:05:15 +08:00
/// <summary>
/// 各公司安全检查统计
/// </summary>
/// <param name="filter">参数</param>
/// <returns></returns>
public List<SafeCheckSum> safeCheckSumData(string connhead)
{
2026-01-16 16:47:53 +08:00
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();
2026-01-20 11:05:15 +08:00
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,
});
}
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.StackTrace))
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
else
throw new Exception("【" + HttpContext.Request.Path + "】错误日志:[Message]" + ex.Message);
2026-01-16 16:47:53 +08:00
}
}
2026-01-20 11:05:15 +08:00
return result;
2026-01-20 10:49:21 +08:00
}
/// <summary>
/// 数据整理 培训教育
/// </summary>
/// <param name="dtTRAIN"></param>
/// <param name="listORG"></param>
/// <returns></returns>
private List<SETRAINSHOW> GetTrainInfo(DataTable dtTRAIN, List<T_FM_ORGANIZATION> listORG)
{
List<SETRAIN> ListTRAIN = DataHelper.TableToList<SETRAIN>(dtTRAIN);
List<SETRAINSHOW> dtInfo = new List<SETRAINSHOW>();
//所有公司 按月 倒推 6 个月的数据
List<DateTime> listDate = new List<DateTime>();
DateTime dtNowYM = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-01 00:00:00"));
for (int i = 0; i < 6; i++)
{
listDate.Add(dtNowYM.AddMonths(-1 * i));
}
foreach (var item in listORG)
{
SETRAINSHOW SUMCNPer = new SETRAINSHOW();
SUMCNPer.ORG_ID = item.ORG_ID.Value;
SUMCNPer.CN = item.NAME;
SUMCNPer.dtNowYM = dtNowYM;
SUMCNPer.dtNowYM_1 = listDate[1];
SUMCNPer.dtNowYM_2 = listDate[2];
SUMCNPer.dtNowYM_3 = listDate[3];
SUMCNPer.dtNowYM_4 = listDate[4];
SUMCNPer.dtNowYM_5 = listDate[5];
SUMCNPer.SUM_TRAIN_HOUR = ListTRAIN.Where(e => e.ORG_ID == SUMCNPer.ORG_ID && e.START_TIME.Year == listDate[0].Year && e.START_TIME.Month == listDate[0].Month).Sum(e => e.TRAIN_HOUR);
SUMCNPer.SUM_TRAIN_HOUR_1 = ListTRAIN.Where(e => e.ORG_ID == SUMCNPer.ORG_ID && e.START_TIME.Year == listDate[1].Year && e.START_TIME.Month == listDate[1].Month).Sum(e => e.TRAIN_HOUR);
SUMCNPer.SUM_TRAIN_HOUR_2 = ListTRAIN.Where(e => e.ORG_ID == SUMCNPer.ORG_ID && e.START_TIME.Year == listDate[2].Year && e.START_TIME.Month == listDate[2].Month).Sum(e => e.TRAIN_HOUR);
SUMCNPer.SUM_TRAIN_HOUR_3 = ListTRAIN.Where(e => e.ORG_ID == SUMCNPer.ORG_ID && e.START_TIME.Year == listDate[3].Year && e.START_TIME.Month == listDate[3].Month).Sum(e => e.TRAIN_HOUR);
SUMCNPer.SUM_TRAIN_HOUR_4 = ListTRAIN.Where(e => e.ORG_ID == SUMCNPer.ORG_ID && e.START_TIME.Year == listDate[4].Year && e.START_TIME.Month == listDate[4].Month).Sum(e => e.TRAIN_HOUR);
SUMCNPer.SUM_TRAIN_HOUR_5 = ListTRAIN.Where(e => e.ORG_ID == SUMCNPer.ORG_ID && e.START_TIME.Year == listDate[5].Year && e.START_TIME.Month == listDate[5].Month).Sum(e => e.TRAIN_HOUR);
dtInfo.Add(SUMCNPer);
}
return dtInfo;
}
2026-01-20 11:05:15 +08:00
}
}