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);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
<f:Toolbar ID="Toolbar4" Position="Top" runat="server" ToolbarAlign="Right">
|
||||
<Items>
|
||||
<f:DropDownList runat="server" ID="drpUnitWork" Label="装置"></f:DropDownList>
|
||||
<f:DropDownList runat="server" ID="drpWorkPost" Label="岗位"></f:DropDownList>
|
||||
<f:ToolbarFill runat="server"/>
|
||||
<f:Button ID="btnQuery" ToolTip="查询" Text="查询" Icon="SystemSearch" runat="server" EnablePostBack="true"
|
||||
|
||||
@@ -39,13 +39,15 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
|
||||
// 添加隐藏列来存储额外的ID信息
|
||||
GridTable.Columns.Add("UnitId");
|
||||
GridTable.Columns.Add("UnitWorkId");
|
||||
GridTable.Columns.Add("WorkPostId");
|
||||
|
||||
ListItem[] list = new ListItem[4];
|
||||
ListItem[] list = new ListItem[5];
|
||||
list[0] = new ListItem("序号", "SerialNumber");
|
||||
list[1] = new ListItem("单位", "UnitName");
|
||||
list[2] = new ListItem("岗位", "WorkPostName");
|
||||
list[3] = new ListItem("累计", "TotalCount");
|
||||
list[2] = new ListItem("装置", "UnitWorkName");
|
||||
list[3] = new ListItem("岗位", "WorkPostName");
|
||||
list[4] = new ListItem("累计", "TotalCount");
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
@@ -137,7 +139,7 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
// 设置Grid的PageSize与下拉框默认值一致
|
||||
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
||||
WorkPostService.InitWorkPostDropDownList(this.drpWorkPost, true); //岗位
|
||||
|
||||
UnitWorkService.InitUnitWorkDownList(drpUnitWork, this.CurrUser.LoginProjectId, true); //单位工程(装置)
|
||||
// 绑定表格
|
||||
this.BindGrid();
|
||||
}
|
||||
@@ -158,14 +160,16 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
{
|
||||
GridTable.Columns.Add("Id");
|
||||
GridTable.Columns.Add("UnitId");
|
||||
GridTable.Columns.Add("UnitWorkId");
|
||||
GridTable.Columns.Add("WorkPostId");
|
||||
|
||||
// 添加动态日期列(这部分已经在InitGrid中定义了)
|
||||
ListItem[] list = new ListItem[4];
|
||||
ListItem[] list = new ListItem[5];
|
||||
list[0] = new ListItem("序号", "SerialNumber");
|
||||
list[1] = new ListItem("单位", "UnitName");
|
||||
list[2] = new ListItem("岗位", "WorkPostName");
|
||||
list[3] = new ListItem("累计", "TotalCount");
|
||||
list[2] = new ListItem("装置", "UnitWorkName");
|
||||
list[3] = new ListItem("岗位", "WorkPostName");
|
||||
list[4] = new ListItem("累计", "TotalCount");
|
||||
foreach (var item in list)
|
||||
{
|
||||
GridTable.Columns.Add(item.Value);
|
||||
@@ -180,12 +184,13 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
}
|
||||
|
||||
// 使用原生SQL查询来提高性能,直接在数据库层面进行分组统计
|
||||
string strSql = @"
|
||||
SELECT UnitId, PostId, RecordDate, COUNT(1) as RecordCount
|
||||
FROM T_d_EmployInOutRecord
|
||||
WHERE ProjectId = @ProjectId
|
||||
AND RecordDate >= @StartDate
|
||||
AND RecordDate <= @EndDate";
|
||||
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<System.Data.SqlClient.SqlParameter>
|
||||
{
|
||||
@@ -196,36 +201,88 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
|
||||
if (UnitId != Const._Null)
|
||||
{
|
||||
strSql += " AND UnitId = @UnitId";
|
||||
strSql += " AND e.UnitId = @UnitId";
|
||||
parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitId", UnitId));
|
||||
}
|
||||
|
||||
if (drpWorkPost.SelectedValue != Const._Null)
|
||||
{
|
||||
strSql += " AND PostId = @PostId";
|
||||
strSql += " AND e.PostId = @PostId";
|
||||
parameters.Add(new System.Data.SqlClient.SqlParameter("@PostId", drpWorkPost.SelectedValue));
|
||||
}
|
||||
|
||||
strSql += " GROUP BY UnitId, PostId, 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 unitWorkId in unitWorkIdArray)
|
||||
{
|
||||
// 往processedDt里面添加数据,每个UnitWorkId一行
|
||||
DataRow newRow = processedDt.NewRow();
|
||||
newRow["UnitId"] = row["UnitId"];
|
||||
newRow["PostId"] = row["PostId"];
|
||||
newRow["RecordDate"] = row["RecordDate"];
|
||||
newRow["UnitWorkId"] = unitWorkId.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);
|
||||
}
|
||||
}
|
||||
|
||||
//针对dt中的数据进行分组
|
||||
var data = processedDt.AsEnumerable()
|
||||
.GroupBy(row => new {
|
||||
UnitId = row["UnitId"],
|
||||
PostId = row["PostId"],
|
||||
UnitWorkId = row["UnitWorkId"],
|
||||
RecordDate = row["RecordDate"]
|
||||
}).Select(group => new
|
||||
{
|
||||
UnitId = group.Key.UnitId,
|
||||
PostId = group.Key.PostId,
|
||||
UnitWorkId = group.Key.UnitWorkId,
|
||||
RecordDate = group.Key.RecordDate,
|
||||
RecordCount = group.Count()
|
||||
}).ToList();
|
||||
|
||||
var data1 = data;
|
||||
// 如果选择了特定的装置进行筛选
|
||||
if (drpUnitWork.SelectedValue != Const._Null)
|
||||
{
|
||||
data1 = data.Where(x => x.UnitWorkId.ToString() == drpUnitWork.SelectedValue).ToList();
|
||||
}
|
||||
|
||||
// 将数据转换为更易处理的格式
|
||||
var groupedData = new List<dynamic>();
|
||||
var groupedDict = new Dictionary<string, dynamic>();
|
||||
|
||||
foreach (System.Data.DataRow row in dt.Rows)
|
||||
foreach (var item in data1)
|
||||
{
|
||||
string key = $"{row["UnitId"]}_{row["PostId"]}";
|
||||
DateTime recordDate = Convert.ToDateTime(row["RecordDate"]);
|
||||
int count = Convert.ToInt32(row["RecordCount"]);
|
||||
string key = $"{item.UnitId}_{item.PostId}_{item.UnitWorkId}";
|
||||
DateTime recordDate = Convert.ToDateTime(item.RecordDate);
|
||||
int count = Convert.ToInt32(item.RecordCount);
|
||||
|
||||
if (!groupedDict.ContainsKey(key))
|
||||
{
|
||||
dynamic group = new System.Dynamic.ExpandoObject();
|
||||
group.UnitId = row["UnitId"];
|
||||
group.PostId = row["PostId"];
|
||||
group.UnitId = item.UnitId;
|
||||
group.PostId = item.PostId;
|
||||
group.UnitWorkId = item.UnitWorkId;
|
||||
group.DailyCounts = new Dictionary<DateTime, int>();
|
||||
group.TotalCount = 0;
|
||||
groupedDict[key] = group;
|
||||
@@ -244,9 +301,11 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
// 只获取当前页需要的单位和岗位信息,避免加载全部数据
|
||||
var unitIds = pagedData.Where(x => x.UnitId != null).Select(x => x.UnitId.ToString()).Distinct().ToList();
|
||||
var postIds = pagedData.Where(x => x.PostId != null).Select(x => x.PostId.ToString()).Distinct().ToList();
|
||||
var unitWorkIds = pagedData.Where(x => x.UnitWorkId != null).Select(x => x.UnitWorkId.ToString()).Distinct().ToList();
|
||||
|
||||
var units = new Dictionary<string, string>();
|
||||
var workPosts = new Dictionary<string, string>();
|
||||
var unitWorks = new Dictionary<string, string>();
|
||||
|
||||
if (unitIds.Any())
|
||||
{
|
||||
@@ -269,6 +328,16 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
workPosts[p.WorkPostId] = p.WorkPostName;
|
||||
}
|
||||
}
|
||||
if (unitWorkIds.Any())
|
||||
{
|
||||
var unitWorkQuery = from p in Funs.DB.WBS_UnitWork
|
||||
where unitWorkIds.Contains(p.UnitWorkId)
|
||||
select new { p.UnitWorkId, p.UnitWorkName };
|
||||
foreach (var p in unitWorkQuery)
|
||||
{
|
||||
unitWorks[p.UnitWorkId] = p.UnitWorkName;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var group in pagedData)
|
||||
{
|
||||
@@ -287,6 +356,15 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
row["UnitName"] = unitName;
|
||||
row["UnitId"] = group.UnitId ?? (object)DBNull.Value;
|
||||
|
||||
// 装置信息
|
||||
string unitWorkName = "";
|
||||
if (group.UnitWorkId != null && unitWorks.ContainsKey(group.UnitWorkId.ToString()))
|
||||
{
|
||||
unitWorkName = unitWorks[group.UnitWorkId.ToString()];
|
||||
}
|
||||
row["UnitWorkName"] = unitWorkName;
|
||||
row["UnitWorkId"] = group.UnitWorkId ?? (object)DBNull.Value;
|
||||
|
||||
// 岗位信息
|
||||
string workPostName = "";
|
||||
if (group.PostId != null && workPosts.ContainsKey(group.PostId.ToString()))
|
||||
@@ -450,9 +528,14 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
{
|
||||
urlParams += "&WorkPostId=" + drpWorkPost.SelectedValue;
|
||||
}
|
||||
// 添加装置参数(如果已选择)
|
||||
if (drpUnitWork.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpUnitWork.SelectedValue))
|
||||
{
|
||||
urlParams += "&UnitWorkId=" + drpUnitWork.SelectedValue;
|
||||
}
|
||||
|
||||
PageContext.RegisterStartupScript(
|
||||
Window2.GetShowReference(string.Format("ManPowerWorkChart.aspx?{0}", urlParams), "人力计划图表"));
|
||||
Window2.GetShowReference(string.Format("ManPowerWorkChart.aspx?{0}", urlParams), "人力考勤图表"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -68,6 +68,15 @@ namespace FineUIPro.Web.JDGL.SGManPower
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.Toolbar Toolbar4;
|
||||
|
||||
/// <summary>
|
||||
/// drpUnitWork 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.DropDownList drpUnitWork;
|
||||
|
||||
/// <summary>
|
||||
/// drpWorkPost 控件。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user