20251023 排产计划

This commit is contained in:
2025-10-23 16:35:37 +08:00
parent b5c375e631
commit 05a92b528d
5 changed files with 594 additions and 83 deletions
@@ -7,6 +7,7 @@ using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.PreDesign
{
@@ -199,7 +200,6 @@ namespace FineUIPro.Web.HJGL.PreDesign
e.Node.Nodes.Clear();
BindNodes(e.Node);
}
}
#endregion
@@ -211,6 +211,153 @@ namespace FineUIPro.Web.HJGL.PreDesign
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
#region
string projectId = this.CurrUser.LoginProjectId;
string steelType = string.Empty;//材质id
//统计生产看板当日已完成量、次日应完成量、累计已完成量、已完成百分比、已完成百分比汇总
if (tvControlItem.SelectedNode.CommandName == "流水段")//点击流水段
{
var planLists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, tvControlItem.SelectedNode.Text, tvControlItem.SelectedNode.ParentNode.NodeID);
if (planLists.Count > 0)
{
foreach (var item in planLists)
{
var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(item.ProductionSchedulingPlanId);
if (plan != null)
{
if (plan.Material == "碳钢")
{
steelType = "1";
}
else if (plan.Material == "不锈钢")
{
steelType = "2";
}
else if (plan.Material == "铬钼钢")
{
steelType = "3";
}
else if (plan.Material == "低合金钢")
{
steelType = "4";
}
else if (plan.Material == "镍合金钢")
{
steelType = "5";
}
else if (plan.Material == "钛合金钢")
{
steelType = "6";
}
else if (plan.Material == "其他")
{
steelType = "7";
}
//当日已完成量
var currentDay = BLL.WeldJointService.GetCurrentDaySizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber);
if (currentDay != null)
{
plan.OnDayCompleteDyne = currentDay;
}
else
{
plan.OnDayCompleteDyne = 0;
}
plan.CompletedCount = BLL.WeldJointService.GetSizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber, "2");//累计已完成量
if (plan.Dain > 0)
{
plan.CompletedRate = (plan.CompletedCount / plan.Dain) * 100;//已完成百分比
}
else
{
plan.CompletedRate = 0;
}
if (plan.PriorityTotalDyne > 0)
{
decimal? completeDinSum = BLL.WeldJointService.GetSizeSumByUnitWorkIdAndFlowingSection(projectId, plan.PipelineId, plan.FlowNum, "2");//完成总达因
plan.TotalCompletedRate = (completeDinSum / plan.PriorityTotalDyne) * 100;//已完成百分比汇总
}
else
{
plan.TotalCompletedRate = 0;
}
BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(plan);
}
}
}
}
else if (tvControlItem.SelectedNode.CommandName.Split('|').Length == 2)//点击单位工程
{
var planLists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByUnitWorkId(this.CurrUser.LoginProjectId, tvControlItem.SelectedNode.NodeID);
if (planLists.Count > 0)
{
foreach (var item in planLists)
{
var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(item.ProductionSchedulingPlanId);
if (plan != null)
{
if (plan.Material == "碳钢")
{
steelType = "1";
}
else if (plan.Material == "不锈钢")
{
steelType = "2";
}
else if (plan.Material == "铬钼钢")
{
steelType = "3";
}
else if (plan.Material == "低合金钢")
{
steelType = "4";
}
else if (plan.Material == "镍合金钢")
{
steelType = "5";
}
else if (plan.Material == "钛合金钢")
{
steelType = "6";
}
else if (plan.Material == "其他")
{
steelType = "7";
}
//当日已完成量
var currentDay = BLL.WeldJointService.GetCurrentDaySizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber);
if (currentDay != null)
{
plan.OnDayCompleteDyne = currentDay;
}
else
{
plan.OnDayCompleteDyne = 0;
}
plan.CompletedCount = BLL.WeldJointService.GetSizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber, "2");//累计已完成量
if (plan.Dain > 0)
{
plan.CompletedRate = (plan.CompletedCount / plan.Dain) * 100;//已完成百分比
}
else
{
plan.CompletedRate = 0;
}
if (plan.PriorityTotalDyne > 0)
{
decimal? completeDinSum = BLL.WeldJointService.GetSizeSumByUnitWorkIdAndFlowingSection(projectId, plan.PipelineId, plan.FlowNum, "2");//完成总达因
plan.TotalCompletedRate = (completeDinSum / plan.PriorityTotalDyne) * 100;//已完成百分比汇总
}
else
{
plan.TotalCompletedRate = 0;
}
BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(plan);
}
}
}
}
#endregion
this.BindGrid();
}
@@ -597,34 +744,22 @@ namespace FineUIPro.Web.HJGL.PreDesign
var newPlan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(rowId);
if (newPlan != null)
{
if (!string.IsNullOrEmpty(values.Value<string>("TotalPriority")))
{
newPlan.TotalPriority = values.Value<string>("TotalPriority");
}
else
if (!string.IsNullOrEmpty(totalPriority))
{
newPlan.TotalPriority = totalPriority;
totalPriority = string.Empty;
}
else
{
newPlan.TotalPriority = values.Value<string>("TotalPriority");
totalPriority = newPlan.TotalPriority;
}
newPlan.PlanStartDate = Funs.GetNewDateTime(values.Value<string>("PlanStartDate"));
newPlan.PlanEndDate = Funs.GetNewDateTime(values.Value<string>("PlanEndDate"));
newPlan.Days = Funs.GetNewInt(values.Value<string>("Days"));
newPlan.AvgDailyWorkload = Funs.GetNewDecimal(values.Value<string>("AvgDailyWorkload"));
newPlan.NextDayCompleteDyne = Funs.GetNewDecimal(values.Value<string>("NextDayCompleteDyne"));
BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(newPlan);
//更新合并单元格的总达因(按材质)优先级
if (!string.IsNullOrEmpty(newPlan.TotalPriority))
{
var pLists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByMaterialLists(this.CurrUser.LoginProjectId, newPlan.FlowNum, newPlan.PipelineId, newPlan.Material);
foreach (var item in pLists)
{
if (string.IsNullOrEmpty(item.TotalPriority))
{
totalPriority = newPlan.TotalPriority;
}
}
}
}
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
@@ -932,16 +1067,24 @@ namespace FineUIPro.Web.HJGL.PreDesign
#region
protected void ddlPageSize2_SelectedIndexChanged(object sender, EventArgs e)
{
Grid2.PageSize = Convert.ToInt32(ddlPageSize2.SelectedValue);
this.BindGrid2();
}
protected void Grid2_Sort(object sender, GridSortEventArgs e)
{
this.BindGrid2();
}
protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e)
{
this.BindGrid2();
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid2()
{
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
@@ -961,17 +1104,22 @@ namespace FineUIPro.Web.HJGL.PreDesign
/// <param name="e"></param>
protected void Grid2_RowDataBound(object sender, GridRowEventArgs e)
{
DataRowView row = e.DataItem as DataRowView;
//DataRowView row = e.DataItem as DataRowView;
double avgDailyWorkload = 0;
double nextDayCompleteDyne = 0;
if (row["AvgDayCompleteDia"] != null && !string.IsNullOrEmpty(row["AvgDayCompleteDia"].ToString()))
{
avgDailyWorkload = Convert.ToDouble(row["AvgDayCompleteDia"]);//平均每日应完成工作量
}
if (row["NextDayComplete"] != null && !string.IsNullOrEmpty(row["NextDayComplete"].ToString()))
{
nextDayCompleteDyne = Convert.ToDouble(row["NextDayComplete"]);//次日应完成量
}
//if (row["AvgDayCompleteDia"] != null && !string.IsNullOrEmpty(row["AvgDayCompleteDia"].ToString()))
//{
// avgDailyWorkload = Convert.ToDouble(row["AvgDayCompleteDia"]);//平均每日应完成工作量
//}
//if (row["NextDayComplete"] != null && !string.IsNullOrEmpty(row["NextDayComplete"].ToString()))
//{
// nextDayCompleteDyne = Convert.ToDouble(row["NextDayComplete"]);//次日应完成量
//}
//avgDailyWorkload=(e.RowID["lblAvgDayCompleteDia") as AspNet.Label).Text
avgDailyWorkload = Convert.ToDouble((e.Row.FindControl("lblAvgDayCompleteDia") as AspNet.Label).Text);//平均每日应完成工作量
nextDayCompleteDyne = Convert.ToDouble((e.Row.FindControl("lblNextDayComplete") as AspNet.Label).Text); //次日应完成量(平均)
if (avgDailyWorkload < nextDayCompleteDyne)
{
e.RowCssClass = "color1";
@@ -979,5 +1127,168 @@ namespace FineUIPro.Web.HJGL.PreDesign
}
#endregion
#region
/// <summary>
/// 获取有效总天数
/// </summary>
/// <param name="projectId"></param>
/// <param name="unitWorkId"></param>
/// <param name="flowNum"></param>
/// <returns></returns>
public static int getTotalDays(string projectId, string unitWorkId, string flowNum)
{
var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId);
List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>();
foreach (var item in lists)
{
if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue)
{
var dateRanges = new List<(DateTime, DateTime)>
{
(new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)),
};
combinedList.AddRange(dateRanges);
}
}
return GetEffectiveDaysLinq(combinedList);
}
/// <summary>
/// 获取剩余天数
/// </summary>
/// <param name="projectId"></param>
/// <param name="unitWorkId"></param>
/// <param name="flowNum"></param>
/// <returns></returns>
public static int getRemainingDays(string projectId, string unitWorkId, string flowNum)
{
var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId);
List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>();
foreach (var item in lists)
{
if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue)
{
if (item.PlanEndDate > DateTime.Now)
{
var dateRanges = new List<(DateTime, DateTime)>
{
(new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)),
};
combinedList.AddRange(dateRanges);
}
}
}
return GetEffectiveDaysLinq(combinedList);
}
/// <summary>
/// 获取平均每日应完成工作量
/// </summary>
/// <param name="projectId"></param>
/// <param name="unitWorkId"></param>
/// <param name="flowNum"></param>
/// <returns></returns>
public static double getAvgDayCompleteDia(string projectId, string unitWorkId, string flowNum)
{
double AvgDayCompleteDia = 0;
int totalDays = 0;
var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId);
List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>();
foreach (var item in lists)
{
if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue)
{
var dateRanges = new List<(DateTime, DateTime)>
{
(new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)),
};
combinedList.AddRange(dateRanges);
}
}
totalDays = GetEffectiveDaysLinq(combinedList);
///总达因
decimal? dia = (from x in Funs.DB.HJGL_WeldJoint
join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId
where x.ProjectId == projectId && y.UnitWorkId == unitWorkId && y.FlowingSection == flowNum
&& x.JointAttribute == "预制口"
select x.Size).Sum();
if (totalDays > 0)
{
//平均每日应完成工作量=总达因/有效总天数
AvgDayCompleteDia = Math.Round(Convert.ToDouble(dia / totalDays), 2);
}
return AvgDayCompleteDia;
}
/// <summary>
/// 获取次日应完成量(平均)
/// </summary>
/// <param name="projectId"></param>
/// <param name="unitWorkId"></param>
/// <param name="flowNum"></param>
/// <returns></returns>
public static double getNextDayComplete(string projectId, string unitWorkId, string flowNum)
{
double nextDayComplete = 0;
int remainingDays = 0;
var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId);
List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>();
foreach (var item in lists)
{
if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue)
{
if (item.PlanEndDate > DateTime.Now)
{
var dateRanges = new List<(DateTime, DateTime)>
{
(new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)),
};
combinedList.AddRange(dateRanges);
}
}
}
remainingDays = GetEffectiveDaysLinq(combinedList);
///总达因
decimal? totalDia = (from x in Funs.DB.HJGL_WeldJoint
join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId
where x.ProjectId == projectId && y.UnitWorkId == unitWorkId && y.FlowingSection == flowNum
&& x.JointAttribute == "预制口"
select x.Size).Sum();
//完成达因
decimal? completedDia = (from x in Funs.DB.HJGL_WeldJoint
join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId
where x.ProjectId == projectId && y.UnitWorkId == unitWorkId && y.FlowingSection == flowNum
&& x.JointAttribute == "预制口" && x.WeldingDailyId != null && x.WeldingDailyId != ""
select x.Size).Sum();
if (remainingDays > 0)
{
//次日应完成量(平均)=(总达因-完成达因)/剩余天数
nextDayComplete = Math.Round(Convert.ToDouble((totalDia - completedDia) / remainingDays), 2);
}
return nextDayComplete;
}
/// <summary>
/// 生成所有日期并去重
/// </summary>
/// <param name="dateRanges"></param>
/// <returns></returns>
public static int GetEffectiveDaysLinq(List<(DateTime start, DateTime end)> dateRanges)
{
if (dateRanges == null || !dateRanges.Any())
return 0;
// 生成所有日期并去重
var allDates = dateRanges
.SelectMany(range =>
Enumerable.Range(0, (range.end - range.start).Days + 1)
.Select(offset => range.start.AddDays(offset).Date))
.Distinct();
return allDates.Count();
}
#endregion
}
}