施工人力
This commit is contained in:
@@ -0,0 +1,377 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Services;
|
||||
using BLL;
|
||||
|
||||
namespace FineUIPro.Web.JDGL.SGManPower
|
||||
{
|
||||
public partial class ManPowerStat : PageBase
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#region Ajax方法
|
||||
|
||||
/// <summary>
|
||||
/// 通过Ajax获取图表数据
|
||||
/// </summary>
|
||||
/// <param name="type">数据类型: total, annual, monthly</param>
|
||||
/// <param name="chart">图表标识: One, Two, Three, Four</param>
|
||||
/// <returns>序列化的图表数据</returns>
|
||||
[WebMethod(EnableSession = true)]
|
||||
public static string GetChartData(string type, string chart, string year = null, string month = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建页面实例以访问非静态方法
|
||||
ManPowerStat pageInstance = new ManPowerStat();
|
||||
|
||||
string title = "";
|
||||
switch (chart)
|
||||
{
|
||||
case "One":
|
||||
title = "五环管理人员统计分析";
|
||||
break;
|
||||
case "Two":
|
||||
title = "施工单位管理人员统计分析";
|
||||
break;
|
||||
case "Three":
|
||||
title = "作业人员统计分析";
|
||||
break;
|
||||
case "Four":
|
||||
title = "过程人力统计分析";
|
||||
break;
|
||||
}
|
||||
|
||||
string result = pageInstance.GetManpowerData(type, title, year, month);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常日志
|
||||
throw new Exception("数据获取失败: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助方法
|
||||
|
||||
// ... existing code ...
|
||||
/// <summary>
|
||||
/// 获取人力统计数据
|
||||
/// </summary>
|
||||
/// <param name="filterType">筛选类型</param>
|
||||
/// <param name="chartTitle">图表标题</param>
|
||||
/// <param name="year">年份(可选)</param>
|
||||
/// <param name="month">月份(可选)</param>
|
||||
/// <returns>BusinessColumn对象</returns>
|
||||
public string GetManpowerData(string filterType, string chartTitle, string year = null, string month = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Model.SingleSerie> series = new List<Model.SingleSerie>();
|
||||
Model.BusinessColumn businessColumn = new Model.BusinessColumn();
|
||||
List<string> listCategories = new List<string>();
|
||||
businessColumn.title = chartTitle;
|
||||
businessColumn.xFontNum = 8;
|
||||
|
||||
// 延迟执行查询,只获取需要的数据
|
||||
var actualBaseQuery = Funs.DB.T_d_EmployInOutRecord.Where(x =>
|
||||
x.ProjectId == this.CurrUser.LoginProjectId);
|
||||
|
||||
var planBaseQuery =
|
||||
Funs.DB.JDGL_SGManPower.Where(x => x.ProjectId == this.CurrUser.LoginProjectId);
|
||||
|
||||
//var UnitType = string.Empty; //1:总包 2:分包
|
||||
// var PostType = string.Empty; //1:一般管理岗位 4:特种管理岗位
|
||||
var Units = (from x in Funs.DB.Project_ProjectUnit
|
||||
join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == "2"
|
||||
select x.UnitId).ToList();
|
||||
|
||||
var workPosts = (from x in Funs.DB.Base_WorkPost
|
||||
where (x.PostType == "1" || x.PostType == "4")
|
||||
select x.WorkPostId).ToList();
|
||||
|
||||
if (chartTitle == "五环管理人员统计分析")
|
||||
{
|
||||
actualBaseQuery = actualBaseQuery.Where(x => x.UnitId == Const.UnitId_CWCEC);
|
||||
planBaseQuery = planBaseQuery.Where(x => x.UnitId == Const.UnitId_CWCEC);
|
||||
}
|
||||
else if (chartTitle == "施工单位管理人员统计分析")
|
||||
{
|
||||
actualBaseQuery =
|
||||
actualBaseQuery.Where(x => Units.Contains(x.UnitId) && workPosts.Contains(x.PostId));
|
||||
planBaseQuery =
|
||||
planBaseQuery.Where(x => Units.Contains(x.UnitId) && workPosts.Contains(x.WorkPostId));
|
||||
}
|
||||
else if (chartTitle == "作业人员统计分析")
|
||||
{
|
||||
actualBaseQuery =
|
||||
actualBaseQuery.Where(x => Units.Contains(x.UnitId) && !workPosts.Contains(x.PostId));
|
||||
planBaseQuery =
|
||||
planBaseQuery.Where(x => Units.Contains(x.UnitId) && !workPosts.Contains(x.WorkPostId));
|
||||
}
|
||||
else if (chartTitle == "过程人力统计分析")
|
||||
{
|
||||
}
|
||||
|
||||
// 根据年份或月份筛选数据
|
||||
if (filterType == "annual" && !string.IsNullOrEmpty(year))
|
||||
{
|
||||
int selectedYear = int.Parse(year);
|
||||
actualBaseQuery = actualBaseQuery.Where(x =>
|
||||
x.RecordDate.HasValue && x.RecordDate.Value.Year == selectedYear);
|
||||
planBaseQuery =
|
||||
planBaseQuery.Where(x => x.PlanDate.HasValue && x.PlanDate.Value.Year == selectedYear);
|
||||
}
|
||||
else if (filterType == "monthly" && !string.IsNullOrEmpty(year) && !string.IsNullOrEmpty(month))
|
||||
{
|
||||
int selectedYear = int.Parse(year);
|
||||
int selectedMonth = int.Parse(month);
|
||||
actualBaseQuery = actualBaseQuery.Where(x => x.RecordDate.HasValue &&
|
||||
x.RecordDate.Value.Year == selectedYear &&
|
||||
x.RecordDate.Value.Month == selectedMonth);
|
||||
planBaseQuery = planBaseQuery.Where(x => x.PlanDate.HasValue &&
|
||||
x.PlanDate.Value.Year == selectedYear &&
|
||||
x.PlanDate.Value.Month == selectedMonth);
|
||||
}
|
||||
|
||||
// 根据筛选类型进行不同的分组统计
|
||||
Dictionary<DateTime, double> actualData;
|
||||
Dictionary<DateTime, double> planData;
|
||||
|
||||
switch (filterType)
|
||||
{
|
||||
case "annual":
|
||||
// 按月分组(年度视图显示每个月的数据)
|
||||
var actualAnnualQuery = from x in actualBaseQuery
|
||||
where x.RecordDate.HasValue
|
||||
group x by new { x.RecordDate.Value.Year, x.RecordDate.Value.Month }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
ActualCount = g.Count()
|
||||
};
|
||||
|
||||
var planAnnualQuery = from x in planBaseQuery
|
||||
where x.PlanDate.HasValue
|
||||
group x by new { x.PlanDate.Value.Year, x.PlanDate.Value.Month }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
PlanCount = g.Sum(x => x.Quantity ?? 0)
|
||||
};
|
||||
|
||||
actualData = actualAnnualQuery.ToDictionary(
|
||||
x => new DateTime(x.Year, x.Month, 1),
|
||||
x => (double)x.ActualCount);
|
||||
|
||||
planData = planAnnualQuery.ToDictionary(
|
||||
x => new DateTime(x.Year, x.Month, 1),
|
||||
x => (double)x.PlanCount);
|
||||
break;
|
||||
|
||||
case "monthly":
|
||||
// 按天分组(月度视图显示每天的数据)
|
||||
var actualMonthlyQuery = from x in actualBaseQuery
|
||||
where x.RecordDate.HasValue
|
||||
group x by new { x.RecordDate.Value.Year, x.RecordDate.Value.Month, x.RecordDate.Value.Day }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
Day = g.Key.Day,
|
||||
ActualCount = g.Count()
|
||||
};
|
||||
|
||||
var planMonthlyQuery = from x in planBaseQuery
|
||||
where x.PlanDate.HasValue
|
||||
group x by new { x.PlanDate.Value.Year, x.PlanDate.Value.Month, x.PlanDate.Value.Day }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
Day = g.Key.Day,
|
||||
PlanCount = g.Sum(x => x.Quantity ?? 0)
|
||||
};
|
||||
|
||||
actualData = actualMonthlyQuery.ToDictionary(
|
||||
x => new DateTime(x.Year, x.Month, x.Day),
|
||||
x => (double)x.ActualCount);
|
||||
|
||||
planData = planMonthlyQuery.ToDictionary(
|
||||
x => new DateTime(x.Year, x.Month, x.Day),
|
||||
x => (double)x.PlanCount);
|
||||
break;
|
||||
|
||||
case "total":
|
||||
default:
|
||||
// 按月分组(默认情况)
|
||||
var actualDefaultQuery = from x in actualBaseQuery
|
||||
where x.RecordDate.HasValue
|
||||
group x by new { x.RecordDate.Value.Year, x.RecordDate.Value.Month }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
ActualCount = g.Count()
|
||||
};
|
||||
|
||||
var planDefaultQuery = from x in planBaseQuery
|
||||
where x.PlanDate.HasValue
|
||||
group x by new { x.PlanDate.Value.Year, x.PlanDate.Value.Month }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
PlanCount = g.Sum(x => x.Quantity ?? 0)
|
||||
};
|
||||
|
||||
actualData = actualDefaultQuery.ToDictionary(
|
||||
x => new DateTime(x.Year, x.Month, 1),
|
||||
x => (double)x.ActualCount);
|
||||
|
||||
planData = planDefaultQuery.ToDictionary(
|
||||
x => new DateTime(x.Year, x.Month, 1),
|
||||
x => (double)x.PlanCount);
|
||||
break;
|
||||
}
|
||||
|
||||
// 获取所有日期并排序
|
||||
var allDates = actualData.Keys.Union(planData.Keys).Distinct().OrderBy(d => d).ToList();
|
||||
|
||||
// 准备数据系列
|
||||
List<double> actualSeries =
|
||||
allDates.Select(date => actualData.ContainsKey(date) ? actualData[date] : 0).ToList();
|
||||
List<double> planSeries =
|
||||
allDates.Select(date => planData.ContainsKey(date) ? planData[date] : 0).ToList();
|
||||
|
||||
// 准备类别(横坐标)
|
||||
switch (filterType)
|
||||
{
|
||||
case "annual":
|
||||
// 显示选定年份的12个月份
|
||||
listCategories = allDates.Select(date => date.ToString("yyyy年MM月")).ToList();
|
||||
break;
|
||||
case "monthly":
|
||||
// 显示选定月份的每日数据
|
||||
listCategories = allDates.Select(date => date.ToString("MM月dd日")).ToList();
|
||||
break;
|
||||
case "total":
|
||||
default:
|
||||
listCategories = allDates.Select(date => date.ToString("yyyy年MM月")).ToList();
|
||||
break;
|
||||
}
|
||||
|
||||
// 实际数据系列
|
||||
Model.SingleSerie actualSerie = new Model.SingleSerie
|
||||
{
|
||||
name = "实际",
|
||||
data = actualSeries
|
||||
};
|
||||
series.Add(actualSerie);
|
||||
|
||||
// 计划数据系列
|
||||
Model.SingleSerie planSerie = new Model.SingleSerie
|
||||
{
|
||||
name = "计划",
|
||||
data = planSeries
|
||||
};
|
||||
series.Add(planSerie);
|
||||
|
||||
businessColumn.categories = listCategories;
|
||||
businessColumn.series = series;
|
||||
return JsonConvert.SerializeObject(businessColumn);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常日志
|
||||
// LogHelper.Error("获取人力统计数据失败", ex);
|
||||
throw new Exception("数据获取失败: " + ex.Message);
|
||||
}
|
||||
}
|
||||
// ... existing code ...
|
||||
|
||||
#endregion
|
||||
|
||||
#region 五环管理人员统计分析
|
||||
|
||||
/// <summary>
|
||||
/// 五环管理人员统计分析
|
||||
/// </summary>
|
||||
public string One
|
||||
{
|
||||
get
|
||||
{
|
||||
string dataType = Request.QueryString["type"] ?? "total";
|
||||
return GetManpowerData(dataType, "五环管理人员统计分析");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 施工单位管理人员统计分析
|
||||
|
||||
/// <summary>
|
||||
/// 施工单位管理人员统计分析
|
||||
/// </summary>
|
||||
public string Two
|
||||
{
|
||||
get
|
||||
{
|
||||
string dataType = Request.QueryString["type"] ?? "total";
|
||||
return GetManpowerData(dataType, "施工单位管理人员统计分析");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 作业人员统计分析
|
||||
|
||||
/// <summary>
|
||||
/// 作业人员统计分析
|
||||
/// </summary>
|
||||
public string Three
|
||||
{
|
||||
get
|
||||
{
|
||||
string dataType = Request.QueryString["type"] ?? "total";
|
||||
return GetManpowerData(dataType, "作业人员统计分析");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 过程人力统计分析
|
||||
|
||||
/// <summary>
|
||||
/// 过程人力统计分析
|
||||
/// </summary>
|
||||
public string Four
|
||||
{
|
||||
get
|
||||
{
|
||||
string dataType = Request.QueryString["type"] ?? "total";
|
||||
return GetManpowerData(dataType, "过程人力统计分析");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user