1
This commit is contained in:
@@ -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<SqlParameter>
|
||||
{
|
||||
@@ -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<DataRow> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user