diff --git a/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs b/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs new file mode 100644 index 00000000..c9b5ee1f --- /dev/null +++ b/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs @@ -0,0 +1,491 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Model; +using System.Data; + + +namespace BLL +{ + public class SGManPowerService + { + /// + /// 检查并发送人力资源预警 + /// + public static Model.ResponeData CheckAndSendPersonWarning() + { + var responeData = new Model.ResponeData(); + // 合并两个集合 + var allItems = new List(); + var projects = Funs.DB.Base_Project.Where(p => p.ProjectState == BLL.Const.ProjectState_1).ToList(); + // foreach (var project in projects) + // { + // 检查管理人员到期未到岗情况 + var items1 = CheckManagerNotArrived("c7ade79e-7646-4c59-a8fd-020a7e3138c6"); + + // 检查作业人员人力偏差情况 + var items2 = CheckWorkerDeviation("c7ade79e-7646-4c59-a8fd-020a7e3138c6"); + + + if (items1 != null) + { + allItems.AddRange(items1); + } + + if (items2 != null) + { + allItems.AddRange(items2); + } + + // } + responeData.data = allItems; + responeData.message = "人员预警"; + return responeData; + } + + + /// + /// 检查管理人员到期未到岗情况(超过一周发出预警) + /// + /// 项目ID + private static IEnumerable CheckManagerNotArrived(string projectId) + { + //获取计划的最新版本 + var version = "1"; + var sgMan = Funs.DB.JDGL_SGManPower.Where(x => x.ProjectId == projectId).OrderByDescending(x => x.Version) + .FirstOrDefault(); + if (sgMan != null) + { + version = sgMan.Version; + } + + // 先获取计划表超过一周的管理岗位有哪些 + var dataList = (from x in Funs.DB.JDGL_SGManPower + join p in Funs.DB.Base_WorkPost on x.WorkPostId equals p.WorkPostId into pp + from y in pp.DefaultIfEmpty() + where x.ProjectId == projectId && (y.PostType == "4" || y.PostType == "1") && + x.PlanDate <= DateTime.Now.AddDays(-7) && x.Version == version + select x).ToList(); + + var lItems = new List(); + //循环检查实际考勤中的人数 + foreach (var data in dataList) + { + //根据人员计划表获取计划中的管理人员数 + int num = getInOutRecordNum(data); + if (data.Quantity > num) + { + lItems = SendManagerWarning(data.UnitId, projectId, data.UnitWorkId, data.PlanDate, data.Quantity, num); + } + } + + return lItems; + } + + //获取实际考勤人员数 + private static int getInOutRecordNum(JDGL_SGManPower sgManPower) + { + string strSql = @" + SELECT e.UnitId, e.PostId, e.RecordDate, p.WorkAreaId as UnitWorkId + FROM T_d_EmployInOutRecord e INNER JOIN SitePerson_Person p ON e.IDCardNo = p.IdentityCard AND e.ProjectId = p.ProjectId + WHERE e.PostId IS NOT NULL AND e.PostId != '' + AND e.ProjectId = @ProjectId + AND e.RecordDate = @RecordDate + AND e.UnitId = @UnitId + AND e.PostId = @PostId"; + + var parameters = new List + { + new System.Data.SqlClient.SqlParameter("@ProjectId", sgManPower.ProjectId), + new System.Data.SqlClient.SqlParameter("@RecordDate", sgManPower.PlanDate), + new System.Data.SqlClient.SqlParameter("@UnitId", sgManPower.UnitId), + new System.Data.SqlClient.SqlParameter("@PostId", sgManPower.WorkPostId), + }; + + // 执行查询获取分组数据 + var dt = SQLHelper.GetDataTableRunText(strSql, parameters.ToArray()); + + // 创建一个新的DataTable来存储处理后的数据 + DataTable processedDt = dt.Clone(); + + foreach (System.Data.DataRow row in dt.Rows) + { + string ids = row["UnitWorkId"] != DBNull.Value ? row["UnitWorkId"].ToString() : string.Empty; + if (!string.IsNullOrEmpty(ids)) + { + string[] unitWorkIdArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string unitWorkId in unitWorkIdArray) + { + // 往processedDt里面添加数据,每个UnitWorkId一行 + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = unitWorkId.Trim(); + processedDt.Rows.Add(newRow); + } + } + else + { + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = string.Empty; + processedDt.Rows.Add(newRow); + } + } + + // 确定要用于后续处理的数据源 + IEnumerable dataSource = processedDt.AsEnumerable(); + + if (string.IsNullOrEmpty(sgManPower.UnitWorkId)) + { + dataSource = dataSource.Where(x => x["UnitWorkId"] == null); + } + else + { + dataSource = dataSource.Where(x => x["UnitWorkId"] != DBNull.Value && x["UnitWorkId"].ToString() == sgManPower.UnitWorkId); + } + + return dataSource.Count(); + } + + /// + /// 发送管理人员预警 + /// + /// 项目ID + /// 单位id + private static List SendManagerWarning(string unitId, string projectId, string unitWorkId, DateTime? planDate, int? quantity, int num) + { + // 发送预警信息 + var toDoItems = new List(); + + var unitWorks = (from x in Funs.DB.WBS_UnitWork + where x.UnitWorkId == unitWorkId + select new { x.UnitWorkId, x.UnitWorkName }).FirstOrDefault(); + + var projectUnits = (from x in Funs.DB.Project_ProjectUnit + join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId + where x.UnitId == unitId + select new { x.UnitId, y.UnitName, x.UnitType }).FirstOrDefault(); + if (projectUnits != null) + { + List toUserIds = new List(); + + // 施工单位人员推送至施工单位项目经理和总包单位施工经理 + if (projectUnits.UnitType == Const.ProjectUnitType_2) // 施工分包单位 + { + // 获取施工单位项目经理 + var constructionManagers = (from x in Funs.DB.Project_ProjectUser + where x.ProjectId == projectId && x.UnitId == unitId && x.IsPost == true && + x.RoleId.Contains(Const.ProjectManager) + select x).ToList(); + + if (constructionManagers.Count > 0) + { + foreach (var projectUser in constructionManagers) + { + toUserIds.Add(projectUser.UserId); + } + } + + // 获取总包单位施工经理 + var generalContractorUnit = Funs.DB.Project_ProjectUnit.FirstOrDefault(pu => + pu.ProjectId == projectId && pu.UnitType == Const.ProjectUnitType_1); // 总包单位 + + if (generalContractorUnit != null) + { + var constructionManagerGCs = (from x in Funs.DB.Project_ProjectUser + where x.ProjectId == projectId && x.UnitId == generalContractorUnit.UnitId && + x.IsPost == true && x.RoleId.Contains(Const.ConstructionManager) + select x).ToList(); + if (constructionManagerGCs.Count > 0) + { + foreach (var projectUser in constructionManagerGCs) + { + toUserIds.Add(projectUser.UserId); + } + } + } + } + // 总包单位人员推送到总包单位施工经理和项目经理 + else if (projectUnits.UnitType == Const.ProjectUnitType_1) // 总包单位 + { + // 获取总包单位施工经理 + var constructionManagers = (from x in Funs.DB.Project_ProjectUser + where x.ProjectId == projectId && x.UnitId == unitId && x.IsPost == true && + x.RoleId.Contains(Const.ConstructionManager) + select x).ToList(); + if (constructionManagers.Count() > 0) + { + foreach (var projectUser in constructionManagers) + { + toUserIds.Add(projectUser.UserId); + } + } + + // 获取总包单位项目经理 + var projectManagers = (from x in Funs.DB.Project_ProjectUser + where x.ProjectId == projectId && x.UnitId == unitId && x.IsPost == true && + x.RoleId.Contains(Const.ProjectManager) + select x).ToList(); + if (projectManagers.Count() > 0) + { + foreach (var projectUser in projectManagers) + { + toUserIds.Add(projectUser.UserId); + } + } + } + + string warningContent = string.Empty; + if (unitWorks != null) + { + warningContent = $"{projectUnits.UnitName}单位{unitWorks.UnitWorkName}装置计划{planDate}投入人力{quantity}人,实际考勤为{num}人。"; + } + else + { + warningContent = $"{projectUnits.UnitName}单位计划{planDate}投入人力{quantity}人,实际考勤为{num}人。"; + } + + foreach (var userId in toUserIds) + { + Model.ToDoItem toDoItem = new Model.ToDoItem(); + toDoItem.DataId = SQLHelper.GetNewID(typeof(Model.ToDoItem)); + toDoItem.MenuId = ""; + toDoItem.MenuName = "管理人员到岗预警"; + toDoItem.Content = warningContent; + toDoItem.UserId = userId; + toDoItem.UserName = UserService.GetUserNameByUserId(userId); + toDoItem.DataTime = DateTime.Now; + toDoItem.DataTimeStr = DateTime.Now.ToString("yyyy-MM-dd"); + toDoItem.PCUrl = ""; + toDoItem.UrlStr = "pages/exam/examjs"; + toDoItems.Add(toDoItem); + } + } + + return toDoItems; + } + + // /// + // /// 检查作业人员人力偏差情况(一周内累计偏差值超过计划的10%) + // /// + // /// 项目ID + private static IEnumerable CheckWorkerDeviation(string projectId) + { + //获取计划的最新版本 + var version = "1"; + var sgMan = Funs.DB.JDGL_SGManPower.Where(x => x.ProjectId == projectId).OrderByDescending(x => x.Version) + .FirstOrDefault(); + if (sgMan != null) + { + version = sgMan.Version; + } + + // 先获取计划表一周的作业岗位有哪些 + var dataList = (from x in Funs.DB.JDGL_SGManPower + join p in Funs.DB.Base_WorkPost on x.WorkPostId equals p.WorkPostId into pp + from y in pp.DefaultIfEmpty() + where x.ProjectId == projectId && (y.PostType == "2" || y.PostType == "3") && + x.PlanDate >= DateTime.Now.AddDays(-7) && x.PlanDate <= DateTime.Now && x.Version == version + group x by new + { + x.UnitId, + x.UnitWorkId, + x.WorkPostId + } + into g + select new + { + UnitId = g.Key.UnitId, + UnitWorkId = g.Key.UnitWorkId, + WorkPostId = g.Key.WorkPostId, + QuantitySum = g.Sum(x => x.Quantity) + }).ToList(); + + var lItems = new List(); + //循环检查实际考勤中的人数 + foreach (var data in dataList) + { + //根据人员计划表获取计划中的作业人员数 + int num = getInOutRecordNum1(data.UnitId, data.UnitWorkId, data.WorkPostId,projectId); + + // 计算偏差百分比 + if (data.QuantitySum > num) + { + double deviationPercentage = Math.Abs((double)((data.QuantitySum - num) / data.QuantitySum)); + // 如果偏差超过10%,发出预警 + if (deviationPercentage > 0.1) + { + lItems = SendWorkerDeviationWarning(data.UnitId, projectId, data.UnitWorkId, data.QuantitySum, 0); + } + } + } + + return lItems; + + } + + + //获取实际考勤人员数 + private static int getInOutRecordNum1(string unitId, string unitWorkId, string workPostId, string projectId) + { + string strSql = @" + SELECT e.UnitId, e.PostId, e.RecordDate, p.WorkAreaId as UnitWorkId + FROM T_d_EmployInOutRecord e INNER JOIN SitePerson_Person p ON e.IDCardNo = p.IdentityCard AND e.ProjectId = p.ProjectId + WHERE e.PostId IS NOT NULL AND e.PostId != '' + AND e.ProjectId = @ProjectId + AND e.UnitId = @UnitId + AND e.PostId = @PostId + AND e.RecordDate >= @StartDate + AND e.RecordDate <= @EndDate"; + + var parameters = new List + { + new System.Data.SqlClient.SqlParameter("@ProjectId", projectId), + new System.Data.SqlClient.SqlParameter("@UnitId", unitId), + new System.Data.SqlClient.SqlParameter("@PostId", workPostId), + new System.Data.SqlClient.SqlParameter("@StartDate", DateTime.Now.AddDays(-7)), + new System.Data.SqlClient.SqlParameter("@EndDate", DateTime.Now), + }; + + // 执行查询获取分组数据 + var dt = SQLHelper.GetDataTableRunText(strSql, parameters.ToArray()); + + // 创建一个新的DataTable来存储处理后的数据 + DataTable processedDt = dt.Clone(); + + foreach (System.Data.DataRow row in dt.Rows) + { + string ids = row["UnitWorkId"] != DBNull.Value ? row["UnitWorkId"].ToString() : string.Empty; + if (!string.IsNullOrEmpty(ids)) + { + string[] unitWorkIdArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string id in unitWorkIdArray) + { + // 往processedDt里面添加数据,每个UnitWorkId一行 + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = id.Trim(); + processedDt.Rows.Add(newRow); + } + } + else + { + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = string.Empty; + processedDt.Rows.Add(newRow); + } + } + + // 确定要用于后续处理的数据源 + IEnumerable dataSource = processedDt.AsEnumerable(); + + if (string.IsNullOrEmpty(unitWorkId)) + { + dataSource = dataSource.Where(x => x["UnitWorkId"] == null); + } + else + { + dataSource = dataSource.Where(x => x["UnitWorkId"] != DBNull.Value && x["UnitWorkId"].ToString() == unitWorkId); + } + + return dataSource.Count(); + } + + + /// + /// 发送作业人员偏差预警 + /// + /// 项目ID + /// 单位ID + /// 计划总人数 + /// 实际总人数 + /// 偏差百分比 + private static List SendWorkerDeviationWarning(string unitId, string projectId, string unitWorkId, int? quantity, int num) + { + + // 发送预警信息 + var toDoItems = new List(); + List toUserIds = new List(); + + var unitWorks = (from x in Funs.DB.WBS_UnitWork + where x.UnitWorkId == unitWorkId + select new { x.UnitWorkId, x.UnitWorkName }).FirstOrDefault(); + + var projectUnits = (from x in Funs.DB.Project_ProjectUnit + join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId + where x.UnitId == unitId + select new { x.UnitId, y.UnitName, x.UnitType }).FirstOrDefault(); + + // 获取施工单位项目经理 + var constructionManagers = (from x in Funs.DB.Project_ProjectUser + where x.ProjectId == projectId && x.UnitId == unitId && x.IsPost == true && + x.RoleId.Contains(Const.ProjectManager) + select x).ToList(); + + if (constructionManagers.Count > 0) + { + foreach (var projectUser in constructionManagers) + { + toUserIds.Add(projectUser.UserId); + } + } + // 获取总包单位施工经理 + var generalContractorUnit = Funs.DB.Project_ProjectUnit.FirstOrDefault(pu => + pu.ProjectId == projectId && pu.UnitType == Const.ProjectUnitType_1); // 总包单位 + + if (generalContractorUnit != null) + { + var constructionManagerGCs = (from x in Funs.DB.Project_ProjectUser + where x.ProjectId == projectId && x.UnitId == generalContractorUnit.UnitId && + x.IsPost == true && x.RoleId.Contains(Const.ConstructionManager) + select x).ToList(); + if (constructionManagerGCs.Count > 0) + { + foreach (var projectUser in constructionManagerGCs) + { + toUserIds.Add(projectUser.UserId); + } + } + } + + // 构建预警信息内容 + string warningContent = string.Empty; + if (unitWorks != null) + { + warningContent = + $"{projectUnits.UnitName}单位{unitWorks.UnitWorkName}装置计划投入人力{quantity}人,实际考勤为{num}人。"; + } + else + { + warningContent = $"{projectUnits.UnitName}单位计划投入人力{quantity}人,实际考勤为{num}人。"; + } + + // 发送预警信息 + foreach (var userId in toUserIds) + { + Model.ToDoItem toDoItem = new Model.ToDoItem(); + toDoItem.DataId = SQLHelper.GetNewID(typeof(Model.ToDoItem)); + toDoItem.MenuId = ""; + toDoItem.MenuName = "人力资源偏差预警"; + toDoItem.Content = warningContent; + toDoItem.UserId = userId; + toDoItem.UserName = UserService.GetUserNameByUserId(userId); + toDoItem.DataTime = DateTime.Now; + toDoItem.DataTimeStr = DateTime.Now.ToString("yyyy-MM-dd"); + toDoItem.PCUrl = ""; + toDoItem.UrlStr = "pages/exam/examjs"; + toDoItems.Add(toDoItem); + } + return toDoItems; + } + } +} \ No newline at end of file diff --git a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkChart.aspx.cs b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkChart.aspx.cs index 5af304f4..810b4f5d 100644 --- a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkChart.aspx.cs +++ b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkChart.aspx.cs @@ -30,6 +30,7 @@ namespace FineUIPro.Web.JDGL.SGManPower string startTime = Request.Params["StartTime"]; string endTime = Request.Params["EndTime"]; string workPostId = Request.Params["WorkPostId"]; + string unitWorkId = Request.Params["UnitWorkId"]; // 检查必要参数 if (string.IsNullOrEmpty(startTime) || string.IsNullOrEmpty(endTime)) @@ -43,13 +44,12 @@ namespace FineUIPro.Web.JDGL.SGManPower // 使用原生SQL查询直接在数据库中进行聚合计算,提高性能 string strSql = @" - SELECT - RecordDate, - COUNT(1) as TotalCount - FROM T_d_EmployInOutRecord - WHERE ProjectId = @ProjectId - AND RecordDate >= @StartDate - AND RecordDate <= @EndDate"; + SELECT e.UnitId, e.PostId, e.RecordDate, p.WorkAreaId as UnitWorkId + FROM T_d_EmployInOutRecord e INNER JOIN SitePerson_Person p ON e.IDCardNo = p.IdentityCard AND e.ProjectId = p.ProjectId + WHERE e.PostId IS NOT NULL AND e.PostId != '' + AND e.ProjectId = @ProjectId + AND e.RecordDate >= @StartDate + AND e.RecordDate <= @EndDate"; var parameters = new List { @@ -61,32 +61,79 @@ namespace FineUIPro.Web.JDGL.SGManPower // 添加单位筛选条件 if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null) { - strSql += " AND UnitId = @UnitId"; + strSql += " AND e.UnitId = @UnitId"; parameters.Add(new SqlParameter("@UnitId", unitId)); } // 添加岗位筛选条件 if (!string.IsNullOrEmpty(workPostId) && workPostId != Const._Null) { - strSql += " AND PostId = @WorkPostId"; + strSql += " AND e.PostId = @WorkPostId"; parameters.Add(new SqlParameter("@WorkPostId", workPostId)); } - // 按日期分组并排序 - strSql += " GROUP BY RecordDate ORDER BY RecordDate"; - // 执行查询 var dt = SQLHelper.GetDataTableRunText(strSql, parameters.ToArray()); + + // 创建一个新的DataTable来存储处理后的数据 + DataTable processedDt = dt.Clone(); + foreach (System.Data.DataRow row in dt.Rows) + { + string ids = row["UnitWorkId"] != DBNull.Value ? row["UnitWorkId"].ToString() : string.Empty; + if (!string.IsNullOrEmpty(ids)) + { + string[] unitWorkIdArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string id in unitWorkIdArray) + { + // 往processedDt里面添加数据,每个UnitWorkId一行 + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = id.Trim(); + processedDt.Rows.Add(newRow); + } + } + else + { + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = string.Empty; + processedDt.Rows.Add(newRow); + } + } + + // 确定要用于后续处理的数据源 + IEnumerable dataSource = processedDt.AsEnumerable(); + + // 如果选择了特定的装置进行筛选 + if (!string.IsNullOrEmpty(unitWorkId) && unitWorkId != Const._Null) + { + dataSource = dataSource.Where(x => x["UnitWorkId"] != DBNull.Value && x["UnitWorkId"].ToString() == unitWorkId); + } + + //针对dt中的数据进行分组 + var data = dataSource + .GroupBy(row => new { + RecordDate = row["RecordDate"] + }).Select(group => new + { + RecordDate = group.Key.RecordDate, + RecordCount = group.Count() + }).ToList(); + // 如果没有数据,显示提示信息 - if (dt.Rows.Count == 0) + if (data.Count == 0) { ShowNotify("在指定时间范围内没有找到人力统计数据", MessageBoxIcon.Warning); return; } // 根据数据点数量动态调整图表宽度,确保每个数据点有足够的显示空间 - int chartWidth = Math.Max(1000, dt.Rows.Count * 50); // 每个数据点至少50像素宽,最小1000像素 + int chartWidth = Math.Max(1000, data.Count * 50); // 每个数据点至少50像素宽,最小1000像素 // 创建图表数据对象 Model.DataSourceChart dataSourceChart = new Model.DataSourceChart @@ -106,17 +153,16 @@ namespace FineUIPro.Web.JDGL.SGManPower }; // 添加数据点 - foreach (DataRow row in dt.Rows) + foreach (var item in data) { - if (row["RecordDate"] != DBNull.Value) + if (item.RecordDate != null) { - DateTime recordDate = Convert.ToDateTime(row["RecordDate"]); - int totalCount = Convert.ToInt32(row["TotalCount"]); + DateTime recordDate = Convert.ToDateTime(item.RecordDate); Model.DataSourcePoint point = new Model.DataSourcePoint { PointText = recordDate.ToString("MM-dd"), - PointValue = totalCount.ToString() + PointValue = item.RecordCount.ToString() }; dataSourceTeam.DataSourcePoints.Add(point); } diff --git a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx index c3f47eee..aa3b99f4 100644 --- a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx +++ b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx @@ -46,6 +46,7 @@ + = @StartDate - AND RecordDate <= @EndDate"; + string strSql = @" + SELECT e.UnitId, e.PostId, e.RecordDate, p.WorkAreaId as UnitWorkId + FROM T_d_EmployInOutRecord e INNER JOIN SitePerson_Person p ON e.IDCardNo = p.IdentityCard AND e.ProjectId = p.ProjectId + WHERE e.PostId IS NOT NULL AND e.PostId != '' + AND e.ProjectId = @ProjectId + AND e.RecordDate >= @StartDate + AND e.RecordDate <= @EndDate"; var parameters = new List { @@ -196,36 +201,88 @@ namespace FineUIPro.Web.JDGL.SGManPower if (UnitId != Const._Null) { - strSql += " AND UnitId = @UnitId"; + strSql += " AND e.UnitId = @UnitId"; parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitId", UnitId)); } if (drpWorkPost.SelectedValue != Const._Null) { - strSql += " AND PostId = @PostId"; + strSql += " AND e.PostId = @PostId"; parameters.Add(new System.Data.SqlClient.SqlParameter("@PostId", drpWorkPost.SelectedValue)); } - strSql += " GROUP BY UnitId, PostId, RecordDate"; - // 执行查询获取分组数据 var dt = SQLHelper.GetDataTableRunText(strSql, parameters.ToArray()); + // 创建一个新的DataTable来存储处理后的数据 + DataTable processedDt = dt.Clone(); + + foreach (System.Data.DataRow row in dt.Rows) + { + string ids = row["UnitWorkId"] != DBNull.Value ? row["UnitWorkId"].ToString() : string.Empty; + if (!string.IsNullOrEmpty(ids)) + { + string[] unitWorkIdArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string unitWorkId in unitWorkIdArray) + { + // 往processedDt里面添加数据,每个UnitWorkId一行 + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = unitWorkId.Trim(); + processedDt.Rows.Add(newRow); + } + } + else + { + DataRow newRow = processedDt.NewRow(); + newRow["UnitId"] = row["UnitId"]; + newRow["PostId"] = row["PostId"]; + newRow["RecordDate"] = row["RecordDate"]; + newRow["UnitWorkId"] = string.Empty; + processedDt.Rows.Add(newRow); + } + } + + //针对dt中的数据进行分组 + var data = processedDt.AsEnumerable() + .GroupBy(row => new { + UnitId = row["UnitId"], + PostId = row["PostId"], + UnitWorkId = row["UnitWorkId"], + RecordDate = row["RecordDate"] + }).Select(group => new + { + UnitId = group.Key.UnitId, + PostId = group.Key.PostId, + UnitWorkId = group.Key.UnitWorkId, + RecordDate = group.Key.RecordDate, + RecordCount = group.Count() + }).ToList(); + + var data1 = data; + // 如果选择了特定的装置进行筛选 + if (drpUnitWork.SelectedValue != Const._Null) + { + data1 = data.Where(x => x.UnitWorkId.ToString() == drpUnitWork.SelectedValue).ToList(); + } + // 将数据转换为更易处理的格式 var groupedData = new List(); var groupedDict = new Dictionary(); - - foreach (System.Data.DataRow row in dt.Rows) + foreach (var item in data1) { - string key = $"{row["UnitId"]}_{row["PostId"]}"; - DateTime recordDate = Convert.ToDateTime(row["RecordDate"]); - int count = Convert.ToInt32(row["RecordCount"]); + string key = $"{item.UnitId}_{item.PostId}_{item.UnitWorkId}"; + DateTime recordDate = Convert.ToDateTime(item.RecordDate); + int count = Convert.ToInt32(item.RecordCount); if (!groupedDict.ContainsKey(key)) { dynamic group = new System.Dynamic.ExpandoObject(); - group.UnitId = row["UnitId"]; - group.PostId = row["PostId"]; + group.UnitId = item.UnitId; + group.PostId = item.PostId; + group.UnitWorkId = item.UnitWorkId; group.DailyCounts = new Dictionary(); group.TotalCount = 0; groupedDict[key] = group; @@ -244,9 +301,11 @@ namespace FineUIPro.Web.JDGL.SGManPower // 只获取当前页需要的单位和岗位信息,避免加载全部数据 var unitIds = pagedData.Where(x => x.UnitId != null).Select(x => x.UnitId.ToString()).Distinct().ToList(); var postIds = pagedData.Where(x => x.PostId != null).Select(x => x.PostId.ToString()).Distinct().ToList(); + var unitWorkIds = pagedData.Where(x => x.UnitWorkId != null).Select(x => x.UnitWorkId.ToString()).Distinct().ToList(); var units = new Dictionary(); var workPosts = new Dictionary(); + var unitWorks = new Dictionary(); if (unitIds.Any()) { @@ -269,6 +328,16 @@ namespace FineUIPro.Web.JDGL.SGManPower workPosts[p.WorkPostId] = p.WorkPostName; } } + if (unitWorkIds.Any()) + { + var unitWorkQuery = from p in Funs.DB.WBS_UnitWork + where unitWorkIds.Contains(p.UnitWorkId) + select new { p.UnitWorkId, p.UnitWorkName }; + foreach (var p in unitWorkQuery) + { + unitWorks[p.UnitWorkId] = p.UnitWorkName; + } + } foreach (var group in pagedData) { @@ -287,6 +356,15 @@ namespace FineUIPro.Web.JDGL.SGManPower row["UnitName"] = unitName; row["UnitId"] = group.UnitId ?? (object)DBNull.Value; + // 装置信息 + string unitWorkName = ""; + if (group.UnitWorkId != null && unitWorks.ContainsKey(group.UnitWorkId.ToString())) + { + unitWorkName = unitWorks[group.UnitWorkId.ToString()]; + } + row["UnitWorkName"] = unitWorkName; + row["UnitWorkId"] = group.UnitWorkId ?? (object)DBNull.Value; + // 岗位信息 string workPostName = ""; if (group.PostId != null && workPosts.ContainsKey(group.PostId.ToString())) @@ -450,9 +528,14 @@ namespace FineUIPro.Web.JDGL.SGManPower { urlParams += "&WorkPostId=" + drpWorkPost.SelectedValue; } + // 添加装置参数(如果已选择) + if (drpUnitWork.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpUnitWork.SelectedValue)) + { + urlParams += "&UnitWorkId=" + drpUnitWork.SelectedValue; + } PageContext.RegisterStartupScript( - Window2.GetShowReference(string.Format("ManPowerWorkChart.aspx?{0}", urlParams), "人力计划图表")); + Window2.GetShowReference(string.Format("ManPowerWorkChart.aspx?{0}", urlParams), "人力考勤图表")); } else { diff --git a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.designer.cs b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.designer.cs index ef9efffd..11ed5899 100644 --- a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.designer.cs +++ b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.designer.cs @@ -68,6 +68,15 @@ namespace FineUIPro.Web.JDGL.SGManPower /// protected global::FineUIPro.Toolbar Toolbar4; + /// + /// drpUnitWork 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::FineUIPro.DropDownList drpUnitWork; + /// /// drpWorkPost 控件。 /// diff --git a/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs b/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs new file mode 100644 index 00000000..bdbbb4b2 --- /dev/null +++ b/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs @@ -0,0 +1,31 @@ +using System; +using System.Web.Http; +using BLL; + +namespace WebAPI.Controllers.JDGL +{ + public class SGManPowerController : ApiController + { + + /// + /// 人力预警 + /// + /// + [HttpPost] + public Model.ResponeData ManPowerWarning() + { + var responeData = new Model.ResponeData(); + try + { + responeData = SGManPowerService.CheckAndSendPersonWarning(); + } + catch (Exception ex) + { + responeData.code = 0; + responeData.message = ex.ToString(); + } + return responeData; + } + + } +} \ No newline at end of file