From 179eed5b87ee97d588be801a40eab07b9ce67968 Mon Sep 17 00:00:00 2001 From: geh <1923421292@qq.com> Date: Fri, 23 Jan 2026 11:37:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=8A=9B=E9=A2=84=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs | 247 +++++++++++++++ .../JDGL/SGManPower/ManPowerWorkGrid.aspx.cs | 9 + SGGL/Model/Model.cs | 297 +++++++++++++++++- .../Controllers/JDGL/SGManPowerController.cs | 6 +- SGGL/WebAPI/Filter/TestPermissionAttribute.cs | 3 +- 5 files changed, 554 insertions(+), 8 deletions(-) diff --git a/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs b/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs index 90b24a15..3c972a1b 100644 --- a/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs +++ b/SGGL/BLL/JDGL/SGManPower/SGManPowerService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Model; using System.Data; +using System.Data.SqlClient; namespace BLL @@ -771,5 +772,251 @@ namespace BLL return toDoItems; } + + + /// + /// 每周执行一次统计上周人力不足 + /// + public static void SGPersonWarningStatistics() + { + // 获取上周的开始时间和结束时间 + DateTime today = DateTime.Today; + int dayOfWeek = (int)today.DayOfWeek; + if (dayOfWeek == 0) dayOfWeek = 7; // 将周日设为7,保证周一为1 + + DateTime lastWeekStart = today.AddDays(-(dayOfWeek + 6)).Date; // 上周一 00:00:00 + DateTime lastWeekEnd = today.AddDays(-dayOfWeek).Date.AddDays(1).AddSeconds(-1); // 上周日 23:59:59 + + var strSql = + @" + WITH LatestVersions AS ( + SELECT ProjectId, MAX(Version) AS MaxVersion + FROM JDGL_SGManPower + GROUP BY ProjectId + ) + SELECT + p.ProjectId, + p.UnitId, + (CASE + WHEN w.PostType IN ('1', '4') THEN '1' + WHEN w.PostType IN ('2', '3') THEN '2' + ELSE '' + END) AS PersonCategory, + SUM(p.Quantity) AS PlanQuantity, + SUM(ISNULL(a.num, 0)) AS ActualQuantity + FROM JDGL_SGManPower p + LEFT JOIN (SELECT ProjectId,UnitId,WorkPostId,IntoOutTime,WorkAreaId,num FROM SitePerson_Checking_Statistics) a + ON p.ProjectId = a.ProjectId + AND p.UnitId = a.UnitId + AND p.WorkPostId = a.WorkPostId + AND p.PlanDate = a.IntoOutTime + AND (CHARINDEX(',' + p.UnitWorkId + ',', ',' + ISNULL(a.WorkAreaId, '') + ',') > 0 + OR (ISNULL(a.WorkAreaId, '') = '' AND ISNULL(p.UnitWorkId, '') = '')) + LEFT JOIN Base_WorkPost w ON p.WorkPostId = w.WorkPostId + WHERE p.PlanDate <= @lastWeekEnd and p.PlanDate >= @lastWeekStart + GROUP BY + p.ProjectId, + p.UnitId, + (CASE + WHEN w.PostType IN ('1', '4') THEN '1' + WHEN w.PostType IN ('2', '3') THEN '2' + ELSE '' + END) + "; + List listStr = new List(); + listStr.Add(new SqlParameter("@lastWeekStart", lastWeekStart)); + listStr.Add(new SqlParameter("@lastWeekEnd", lastWeekEnd)); + SqlParameter[] parameter = listStr.ToArray(); + DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); + + + foreach (DataRow row in tb.Rows) + { + string PersonCategory = row["PersonCategory"].ToString(); + string UnitId = row["UnitId"].ToString(); + string ProjectId = row["ProjectId"].ToString(); + int planQty = Convert.ToInt32(row["PlanQuantity"]); + int actualQty = Convert.ToInt32(row["ActualQuantity"]); + + if (planQty > actualQty && planQty > 0) + { + + bool isPass = (planQty - actualQty) * 100 > planQty * 10; + if (isPass) + { + if (!string.IsNullOrEmpty(PersonCategory)) + { + List userIds = new List(); + if (PersonCategory == "1") //管理人员 + { + userIds = getUserIds(UnitId, ProjectId); + } + else if (PersonCategory == "2") //作业人员 + { + userIds = getUserIds2(UnitId, ProjectId); + } + + if (userIds.Count > 0) + { + foreach (var userId in userIds) + { + Model.SGManPower_WarningWeeklyStatisticsResult warningWeeklyStatisticsResult = + new Model.SGManPower_WarningWeeklyStatisticsResult + { + ResultId = SQLHelper.GetNewID(typeof(Model.SGManPower_WarningWeeklyStatisticsResult)), + UnitId = UnitId, + ProjectId = ProjectId, + WorkPostType = PersonCategory, + UserId = userId, + IsRead = false, + StartDate = lastWeekStart, + EndDate = lastWeekEnd, + PlanQuantity = planQty, + ActualQuantity = actualQty, + }; + Funs.DB.SGManPower_WarningWeeklyStatisticsResult.InsertOnSubmit( + warningWeeklyStatisticsResult); + Funs.DB.SubmitChanges(); + } + } + } + } + } + } + } + + + /// + /// 发送管理人员预警 + /// + /// 项目ID + /// 单位id + private static List getUserIds(string unitId, string projectId) + { + // 发送预警信息 + List toUserIds = new List(); + 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) + { + // 施工单位人员推送至施工单位项目经理和总包单位施工经理 + 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); + } + } + } + } + + return toUserIds; + } + + + /// + /// 发送作业人员偏差预警 + /// + /// 项目ID + /// 单位ID + private static List getUserIds2(string unitId, string projectId) + { + // 发送预警信息 + List toUserIds = new List(); + + // 获取施工单位项目经理 + 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); + } + } + } + + return toUserIds; + } + } } \ No newline at end of file diff --git a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.cs b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.cs index e59fef56..993a4e51 100644 --- a/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.cs +++ b/SGGL/FineUIPro.Web/JDGL/SGManPower/ManPowerWorkGrid.aspx.cs @@ -185,6 +185,15 @@ namespace FineUIPro.Web.JDGL.SGManPower var getData = Funs.DB.SitePerson_Checking_Statistics.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.IntoOutTime >= Convert.ToDateTime(StartTime) && x.IntoOutTime <= Convert.ToDateTime(EndTime)); + if (!string.IsNullOrEmpty(this.UnitId) && this.UnitId != Const._Null) + { + getData = getData.Where(x => x.UnitId == this.UnitId); + } + + if (drpWorkPost.SelectedValue != Const._Null) + { + getData = getData.Where(x => x.WorkPostId == drpWorkPost.SelectedValue); + } DataTable dt = this.LINQToDataTable(getData.ToList()); // 创建一个新的DataTable来存储处理后的数据 DataTable processedDt = dt.Clone(); diff --git a/SGGL/Model/Model.cs b/SGGL/Model/Model.cs index 1b4fc535..39bb04bb 100644 --- a/SGGL/Model/Model.cs +++ b/SGGL/Model/Model.cs @@ -2300,6 +2300,9 @@ namespace Model partial void InsertSGManPower_WarningResult(SGManPower_WarningResult instance); partial void UpdateSGManPower_WarningResult(SGManPower_WarningResult instance); partial void DeleteSGManPower_WarningResult(SGManPower_WarningResult instance); + partial void InsertSGManPower_WarningWeeklyStatisticsResult(SGManPower_WarningWeeklyStatisticsResult instance); + partial void UpdateSGManPower_WarningWeeklyStatisticsResult(SGManPower_WarningWeeklyStatisticsResult instance); + partial void DeleteSGManPower_WarningWeeklyStatisticsResult(SGManPower_WarningWeeklyStatisticsResult instance); partial void InsertSitePerson_Checking(SitePerson_Checking instance); partial void UpdateSitePerson_Checking(SitePerson_Checking instance); partial void DeleteSitePerson_Checking(SitePerson_Checking instance); @@ -8939,6 +8942,14 @@ namespace Model } } + public System.Data.Linq.Table SGManPower_WarningWeeklyStatisticsResult + { + get + { + return this.GetTable(); + } + } + public System.Data.Linq.Table SitePerson_Checking { get @@ -302085,7 +302096,7 @@ namespace Model } } - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ControlPointType", DbType="NVarChar(100)")] + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ControlPointType", DbType="NVarChar(50)")] public string ControlPointType { get @@ -302105,7 +302116,7 @@ namespace Model } } - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AcceptanceSite", DbType="NVarChar(200)")] + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AcceptanceSite", DbType="NVarChar(50)")] public string AcceptanceSite { get @@ -352860,6 +352871,284 @@ namespace Model } } + [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.SGManPower_WarningWeeklyStatisticsResult")] + public partial class SGManPower_WarningWeeklyStatisticsResult : INotifyPropertyChanging, INotifyPropertyChanged + { + + private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); + + private string _ResultId; + + private string _ProjectId; + + private string _UnitId; + + private string _WorkPostType; + + private string _UserId; + + private System.Nullable _IsRead; + + private System.Nullable _StartDate; + + private System.Nullable _EndDate; + + private System.Nullable _PlanQuantity; + + private System.Nullable _ActualQuantity; + + #region 可扩展性方法定义 + partial void OnLoaded(); + partial void OnValidate(System.Data.Linq.ChangeAction action); + partial void OnCreated(); + partial void OnResultIdChanging(string value); + partial void OnResultIdChanged(); + partial void OnProjectIdChanging(string value); + partial void OnProjectIdChanged(); + partial void OnUnitIdChanging(string value); + partial void OnUnitIdChanged(); + partial void OnWorkPostTypeChanging(string value); + partial void OnWorkPostTypeChanged(); + partial void OnUserIdChanging(string value); + partial void OnUserIdChanged(); + partial void OnIsReadChanging(System.Nullable value); + partial void OnIsReadChanged(); + partial void OnStartDateChanging(System.Nullable value); + partial void OnStartDateChanged(); + partial void OnEndDateChanging(System.Nullable value); + partial void OnEndDateChanged(); + partial void OnPlanQuantityChanging(System.Nullable value); + partial void OnPlanQuantityChanged(); + partial void OnActualQuantityChanging(System.Nullable value); + partial void OnActualQuantityChanged(); + #endregion + + public SGManPower_WarningWeeklyStatisticsResult() + { + OnCreated(); + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ResultId", DbType="NVarChar(50) NOT NULL", CanBeNull=false, IsPrimaryKey=true)] + public string ResultId + { + get + { + return this._ResultId; + } + set + { + if ((this._ResultId != value)) + { + this.OnResultIdChanging(value); + this.SendPropertyChanging(); + this._ResultId = value; + this.SendPropertyChanged("ResultId"); + this.OnResultIdChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProjectId", DbType="NVarChar(50)")] + public string ProjectId + { + get + { + return this._ProjectId; + } + set + { + if ((this._ProjectId != value)) + { + this.OnProjectIdChanging(value); + this.SendPropertyChanging(); + this._ProjectId = value; + this.SendPropertyChanged("ProjectId"); + this.OnProjectIdChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UnitId", DbType="NVarChar(50)")] + public string UnitId + { + get + { + return this._UnitId; + } + set + { + if ((this._UnitId != value)) + { + this.OnUnitIdChanging(value); + this.SendPropertyChanging(); + this._UnitId = value; + this.SendPropertyChanged("UnitId"); + this.OnUnitIdChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_WorkPostType", DbType="NVarChar(5)")] + public string WorkPostType + { + get + { + return this._WorkPostType; + } + set + { + if ((this._WorkPostType != value)) + { + this.OnWorkPostTypeChanging(value); + this.SendPropertyChanging(); + this._WorkPostType = value; + this.SendPropertyChanged("WorkPostType"); + this.OnWorkPostTypeChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="NVarChar(50)")] + public string UserId + { + get + { + return this._UserId; + } + set + { + if ((this._UserId != value)) + { + this.OnUserIdChanging(value); + this.SendPropertyChanging(); + this._UserId = value; + this.SendPropertyChanged("UserId"); + this.OnUserIdChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsRead", DbType="Bit")] + public System.Nullable IsRead + { + get + { + return this._IsRead; + } + set + { + if ((this._IsRead != value)) + { + this.OnIsReadChanging(value); + this.SendPropertyChanging(); + this._IsRead = value; + this.SendPropertyChanged("IsRead"); + this.OnIsReadChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_StartDate", DbType="Date")] + public System.Nullable StartDate + { + get + { + return this._StartDate; + } + set + { + if ((this._StartDate != value)) + { + this.OnStartDateChanging(value); + this.SendPropertyChanging(); + this._StartDate = value; + this.SendPropertyChanged("StartDate"); + this.OnStartDateChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EndDate", DbType="Date")] + public System.Nullable EndDate + { + get + { + return this._EndDate; + } + set + { + if ((this._EndDate != value)) + { + this.OnEndDateChanging(value); + this.SendPropertyChanging(); + this._EndDate = value; + this.SendPropertyChanged("EndDate"); + this.OnEndDateChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_PlanQuantity", DbType="Int")] + public System.Nullable PlanQuantity + { + get + { + return this._PlanQuantity; + } + set + { + if ((this._PlanQuantity != value)) + { + this.OnPlanQuantityChanging(value); + this.SendPropertyChanging(); + this._PlanQuantity = value; + this.SendPropertyChanged("PlanQuantity"); + this.OnPlanQuantityChanged(); + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ActualQuantity", DbType="Int")] + public System.Nullable ActualQuantity + { + get + { + return this._ActualQuantity; + } + set + { + if ((this._ActualQuantity != value)) + { + this.OnActualQuantityChanging(value); + this.SendPropertyChanging(); + this._ActualQuantity = value; + this.SendPropertyChanged("ActualQuantity"); + this.OnActualQuantityChanged(); + } + } + } + + public event PropertyChangingEventHandler PropertyChanging; + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void SendPropertyChanging() + { + if ((this.PropertyChanging != null)) + { + this.PropertyChanging(this, emptyChangingEventArgs); + } + } + + protected virtual void SendPropertyChanged(String propertyName) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + } + [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.SitePerson_Checking")] public partial class SitePerson_Checking : INotifyPropertyChanging, INotifyPropertyChanged { @@ -429241,7 +429530,7 @@ namespace Model } } - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AcceptanceSite", DbType="NVarChar(200)")] + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AcceptanceSite", DbType="NVarChar(50)")] public string AcceptanceSite { get @@ -448558,7 +448847,7 @@ namespace Model } } - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AcceptanceSite", DbType="NVarChar(200)")] + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AcceptanceSite", DbType="NVarChar(50)")] public string AcceptanceSite { get diff --git a/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs b/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs index 9b3f88b1..b9fa8b28 100644 --- a/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs +++ b/SGGL/WebAPI/Controllers/JDGL/SGManPowerController.cs @@ -11,13 +11,13 @@ namespace WebAPI.Controllers.JDGL /// 人力预警 /// /// - public Model.ResponeData getManPowerWarning(string userId) + public Model.ResponeData getSGPersonWarningStatistics() { var responeData = new Model.ResponeData(); try { - var list = SGManPowerService.CheckAndSendPersonWarning(userId); - responeData.data = list; + SGManPowerService.SGPersonWarningStatistics(); + responeData.data = "1"; } catch (Exception ex) { diff --git a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs index df4e59ad..0ea7f719 100644 --- a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs +++ b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs @@ -104,7 +104,8 @@ namespace WebAPI.Filter "CNCECServer*PostGetHSSEData", "CNCECServer*PostGetCQMSData", "CNCECServer*PostGetHJGLData", - "AIAlarmEvent*alarmEvent" + "AIAlarmEvent*alarmEvent", + "SGManPower*getSGPersonWarningStatistics", }; ///