人力预警
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user