施工人力

This commit is contained in:
geh
2025-12-01 10:24:34 +08:00
parent da23e72a7f
commit 07b7d8426a
11 changed files with 561 additions and 212 deletions
@@ -30,7 +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"];
string workAreaId = Request.Params["WorkAreaId"];
// 检查必要参数
if (string.IsNullOrEmpty(startTime) || string.IsNullOrEmpty(endTime))
@@ -42,87 +42,84 @@ namespace FineUIPro.Web.JDGL.SGManPower
DateTime startDate = Convert.ToDateTime(startTime);
DateTime endDate = Convert.ToDateTime(endTime);
// 使用原生SQL查询直接在数据库中进行聚合计算,提高性能
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<SqlParameter>
{
new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId),
new SqlParameter("@StartDate", startDate),
new SqlParameter("@EndDate", endDate)
};
var getData = Funs.DB.SitePerson_Checking_Statistics.Where(x =>
x.ProjectId == this.CurrUser.LoginProjectId && x.IntoOutTime >= startDate && x.IntoOutTime <= endDate);
// 添加单位筛选条件
if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null)
{
strSql += " AND e.UnitId = @UnitId";
parameters.Add(new SqlParameter("@UnitId", unitId));
getData = getData.Where(x => x.UnitId == unitId);
}
// 添加岗位筛选条件
if (!string.IsNullOrEmpty(workPostId) && workPostId != Const._Null)
{
strSql += " AND e.PostId = @WorkPostId";
parameters.Add(new SqlParameter("@WorkPostId", workPostId));
getData = getData.Where(x => x.WorkPostId == workPostId);
}
// 执行查询
var dt = SQLHelper.GetDataTableRunText(strSql, parameters.ToArray());
DataTable dt = this.LINQToDataTable(getData.ToList());
// 创建一个新的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
{
// string ids = row["WorkAreaId"] != DBNull.Value ? row["WorkAreaId"].ToString() : string.Empty;
// string names = row["WorkAreaName"] != DBNull.Value ? row["WorkAreaName"].ToString() : string.Empty;
// if (!string.IsNullOrEmpty(names))
// {
// string[] unitWorkNameArray =
// names.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// string[] unitWorkIdArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// for (var i = 0; i < unitWorkNameArray.Length; i++)
// {
// // 往processedDt里面添加数据,每个UnitWorkId一行
// DataRow newRow = processedDt.NewRow();
// newRow["UnitId"] = row["UnitId"];
// newRow["UnitName"] = row["UnitName"];
// newRow["WorkPostId"] = row["WorkPostId"];
// newRow["WorkPostName"] = row["WorkPostName"];
// newRow["IntoOutTime"] = row["IntoOutTime"] ?? DBNull.Value;
// newRow["WorkAreaId"] = unitWorkIdArray[i].Trim();
// newRow["WorkAreaName"] = unitWorkNameArray[i].Trim();
// newRow["num"] = row["num"] != DBNull.Value ? Convert.ToInt32(row["num"]) : 0;
// a++;
// 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;
newRow["UnitName"] = row["UnitName"];
newRow["WorkPostId"] = row["WorkPostId"];
newRow["WorkPostName"] = row["WorkPostName"];
newRow["IntoOutTime"] = row["IntoOutTime"] ?? DBNull.Value;
newRow["WorkAreaId"] = row["WorkAreaId"];
newRow["WorkAreaName"] = row["WorkAreaName"];
newRow["num"] = row["num"] != DBNull.Value ? Convert.ToInt32(row["num"]) : 0;
processedDt.Rows.Add(newRow);
}
// }
}
// 确定要用于后续处理的数据源
IEnumerable<DataRow> dataSource = processedDt.AsEnumerable();
// 如果选择了特定的装置进行筛选
if (!string.IsNullOrEmpty(unitWorkId) && unitWorkId != Const._Null)
if (!string.IsNullOrEmpty(workAreaId) && workAreaId != Const._Null)
{
dataSource = dataSource.Where(x => x["UnitWorkId"] != DBNull.Value && x["UnitWorkId"].ToString() == unitWorkId);
dataSource = dataSource.Where(x => x["WorkAreaId"] != DBNull.Value && x["WorkAreaId"].ToString() == workAreaId);
}
var da = dataSource.ToList();
//针对dt中的数据进行分组
var data = dataSource
.GroupBy(row => new {
RecordDate = row["RecordDate"]
IntoOutTime = row["IntoOutTime"]
}).Select(group => new
{
RecordDate = group.Key.RecordDate,
RecordCount = group.Count()
}).ToList();
IntoOutTime = group.Key.IntoOutTime,
RecordCount = group.Sum(row => row["num"] != DBNull.Value ? Convert.ToInt32(row["num"]) : 0)
}).OrderBy(x => x.IntoOutTime).ToList();
// 如果没有数据,显示提示信息
@@ -155,13 +152,13 @@ namespace FineUIPro.Web.JDGL.SGManPower
// 添加数据点
foreach (var item in data)
{
if (item.RecordDate != null)
if (item.IntoOutTime != null)
{
DateTime recordDate = Convert.ToDateTime(item.RecordDate);
DateTime IntoOutTime = Convert.ToDateTime(item.IntoOutTime);
Model.DataSourcePoint point = new Model.DataSourcePoint
{
PointText = recordDate.ToString("MM-dd"),
PointText = IntoOutTime.ToString("MM-dd"),
PointValue = item.RecordCount.ToString()
};
dataSourceTeam.DataSourcePoints.Add(point);