人力预警

This commit is contained in:
geh 2026-01-23 11:37:01 +08:00
parent 7100520461
commit 179eed5b87
5 changed files with 554 additions and 8 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Model; using Model;
using System.Data; using System.Data;
using System.Data.SqlClient;
namespace BLL namespace BLL
@ -771,5 +772,251 @@ namespace BLL
return toDoItems; return toDoItems;
} }
/// <summary>
/// 每周执行一次统计上周人力不足
/// </summary>
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<SqlParameter> listStr = new List<SqlParameter>();
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<string> userIds = new List<string>();
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();
}
}
}
}
}
}
}
/// <summary>
/// 发送管理人员预警
/// </summary>
/// <param name="projectId">项目ID</param>
/// <param name="unitId">单位id</param>
private static List<string> getUserIds(string unitId, string projectId)
{
// 发送预警信息
List<string> toUserIds = new List<string>();
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;
}
/// <summary>
/// 发送作业人员偏差预警
/// </summary>
/// <param name="projectId">项目ID</param>
/// <param name="unitId">单位ID</param>
private static List<string> getUserIds2(string unitId, string projectId)
{
// 发送预警信息
List<string> toUserIds = new List<string>();
// 获取施工单位项目经理
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;
}
} }
} }

View File

@ -185,6 +185,15 @@ namespace FineUIPro.Web.JDGL.SGManPower
var getData = Funs.DB.SitePerson_Checking_Statistics.Where(x => var getData = Funs.DB.SitePerson_Checking_Statistics.Where(x =>
x.ProjectId == this.CurrUser.LoginProjectId && x.IntoOutTime >= Convert.ToDateTime(StartTime) && x.IntoOutTime <= Convert.ToDateTime(EndTime)); 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 dt = this.LINQToDataTable(getData.ToList());
// 创建一个新的DataTable来存储处理后的数据 // 创建一个新的DataTable来存储处理后的数据
DataTable processedDt = dt.Clone(); DataTable processedDt = dt.Clone();

View File

@ -2300,6 +2300,9 @@ namespace Model
partial void InsertSGManPower_WarningResult(SGManPower_WarningResult instance); partial void InsertSGManPower_WarningResult(SGManPower_WarningResult instance);
partial void UpdateSGManPower_WarningResult(SGManPower_WarningResult instance); partial void UpdateSGManPower_WarningResult(SGManPower_WarningResult instance);
partial void DeleteSGManPower_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 InsertSitePerson_Checking(SitePerson_Checking instance);
partial void UpdateSitePerson_Checking(SitePerson_Checking instance); partial void UpdateSitePerson_Checking(SitePerson_Checking instance);
partial void DeleteSitePerson_Checking(SitePerson_Checking instance); partial void DeleteSitePerson_Checking(SitePerson_Checking instance);
@ -8939,6 +8942,14 @@ namespace Model
} }
} }
public System.Data.Linq.Table<SGManPower_WarningWeeklyStatisticsResult> SGManPower_WarningWeeklyStatisticsResult
{
get
{
return this.GetTable<SGManPower_WarningWeeklyStatisticsResult>();
}
}
public System.Data.Linq.Table<SitePerson_Checking> SitePerson_Checking public System.Data.Linq.Table<SitePerson_Checking> SitePerson_Checking
{ {
get 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 public string ControlPointType
{ {
get 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 public string AcceptanceSite
{ {
get 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<bool> _IsRead;
private System.Nullable<System.DateTime> _StartDate;
private System.Nullable<System.DateTime> _EndDate;
private System.Nullable<int> _PlanQuantity;
private System.Nullable<int> _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<bool> value);
partial void OnIsReadChanged();
partial void OnStartDateChanging(System.Nullable<System.DateTime> value);
partial void OnStartDateChanged();
partial void OnEndDateChanging(System.Nullable<System.DateTime> value);
partial void OnEndDateChanged();
partial void OnPlanQuantityChanging(System.Nullable<int> value);
partial void OnPlanQuantityChanged();
partial void OnActualQuantityChanging(System.Nullable<int> 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<bool> 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<System.DateTime> 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<System.DateTime> 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<int> 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<int> 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")] [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.SitePerson_Checking")]
public partial class SitePerson_Checking : INotifyPropertyChanging, INotifyPropertyChanged 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 public string AcceptanceSite
{ {
get 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 public string AcceptanceSite
{ {
get get

View File

@ -11,13 +11,13 @@ namespace WebAPI.Controllers.JDGL
/// 人力预警 /// 人力预警
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public Model.ResponeData getManPowerWarning(string userId) public Model.ResponeData getSGPersonWarningStatistics()
{ {
var responeData = new Model.ResponeData(); var responeData = new Model.ResponeData();
try try
{ {
var list = SGManPowerService.CheckAndSendPersonWarning(userId); SGManPowerService.SGPersonWarningStatistics();
responeData.data = list; responeData.data = "1";
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -104,7 +104,8 @@ namespace WebAPI.Filter
"CNCECServer*PostGetHSSEData", "CNCECServer*PostGetHSSEData",
"CNCECServer*PostGetCQMSData", "CNCECServer*PostGetCQMSData",
"CNCECServer*PostGetHJGLData", "CNCECServer*PostGetHJGLData",
"AIAlarmEvent*alarmEvent" "AIAlarmEvent*alarmEvent",
"SGManPower*getSGPersonWarningStatistics",
}; };
/// <summary> /// <summary>