liuwf 1 year ago
commit 74a64f9f51

@ -54,12 +54,24 @@ namespace Aucma.Core.BoxFoam.ViewModels
CollectionFoamLine.RefreshBoxFoamDataDelegateEvent += InitData;
timer2.Elapsed += new System.Timers.ElapsedEventHandler(RealTimeFoamingTask); //到达时间的时候执行事件;
timer2.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer2.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer2.Start();//timer.Start()的内部原理还是设置timer.Enabled = true
InitEveryDayMethod();
//Task.WaitAll(InitData());
//timer2.Elapsed += new System.Timers.ElapsedEventHandler(RealTimeFoamingTask); //到达时间的时候执行事件;
//timer2.AutoReset = true;//设置是执行一次false还是一直执行(true)
//timer2.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
//timer2.Start();//timer.Start()的内部原理还是设置timer.Enabled = true
//Task.WaitAll(InitData
//
Task.Run(() =>
{
while (true)
{
Thread.Sleep(3000);
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
InitEveryDayMethod();
}));
}
});
}
@ -70,52 +82,50 @@ namespace Aucma.Core.BoxFoam.ViewModels
/// <returns></returns>
private Task InitEveryDayMethod()
{
App.Current.Dispatcher.BeginInvoke((Action)(() =>
ProductionHourList = new List<string>();
List<WorkTime> listTime = _baseBomInfoServices.getWorkTime().Result;
foreach (WorkTime time in listTime)
{
ProductionHourList.Add(time.hourTime);
}
// 货道列表
List<BoxFoamData> list = _boxFoamDataServices.QueryAsync(x=>x.ProductLineCode.Equals("CX_02") && x.StationCode=="1005").Result;
ModelStatistics.Clear();
ProductionHourList = new List<string>();
List<WorkTime> listTime = _baseBomInfoServices.getWorkTime().Result;
ProductionHourList.Clear();
foreach (WorkTime time in listTime)
{
ProductionHourList.Add(time.hourTime);
}
// 货道列表
List<BoxFoamData> list = _boxFoamDataServices.QueryAsync(x => x.ProductLineCode.Equals("CX_02") && x.StationCode == "1005").Result;
if(list != null)
{
ChartValues<double> achievement = new ChartValues<double>();
//Achievement.Clear();
#region 按时间统计
achievement.Add(list.Sum(x => x.AnHour));
achievement.Add(list.Sum(x => x.TwoHour));
achievement.Add(list.Sum(x => x.ThreeHour));
achievement.Add(list.Sum(x => x.FourHour));
achievement.Add(list.Sum(x => x.FiveHour));
achievement.Add(list.Sum(x => x.SixHour));
achievement.Add(list.Sum(x => x.SevenHour));
achievement.Add(list.Sum(x => x.EightHour));
achievement.Add(list.Sum(x => x.NineHour));
achievement.Add(list.Sum(x => x.TenHour));
achievement.Add(list.Sum(x => x.ElevenHour));
achievement.Add(list.Sum(x => x.TwelveHour));
if(list.Count > 0) {
achievement.Add(list.Sum(x => x.AnHour));
achievement.Add(list.Sum(x => x.TwoHour));
achievement.Add(list.Sum(x => x.ThreeHour));
achievement.Add(list.Sum(x => x.FourHour));
achievement.Add(list.Sum(x => x.FiveHour));
achievement.Add(list.Sum(x => x.SixHour));
achievement.Add(list.Sum(x => x.SevenHour));
achievement.Add(list.Sum(x => x.EightHour));
achievement.Add(list.Sum(x => x.NineHour));
achievement.Add(list.Sum(x => x.TenHour));
achievement.Add(list.Sum(x => x.ElevenHour));
achievement.Add(list.Sum(x => x.TwelveHour));
}
var column = new ColumnSeries();
column.DataLabels = true;
column.Title = "当日小时产量统计";
column.Values = achievement;
column.Foreground = Brushes.White;
Achievement.Clear();
Achievement.Add(column);
#endregion
#region 按类型统计
MaterialNameList = new List<string>();
ChartValues<int> achievement2 = new ChartValues<int>();
MaterialNameList.Clear();
//foreach(BoxFoamData space in list)
//{
// MaterialNameList.Add(space.Fixtureboxtype);
//}
var grouped = list.GroupBy(x => x.Fixtureboxtype);
foreach (var item in grouped)
{
@ -124,19 +134,17 @@ namespace Aucma.Core.BoxFoam.ViewModels
MaterialNameList.Add(item.Key);
achievement2.Add(flattenedList.Sum());
}
ModelStatistics.Clear();
var column2 = new ColumnSeries();
column2.DataLabels = true;
column2.Title = "当日型号产量统计";
column2.Values = achievement2;
column2.Foreground = Brushes.White;
ModelStatistics.Clear();
ModelStatistics.Add(column2);
#endregion
}));
}
//await InitExecMethod();
return Task.CompletedTask;
@ -332,144 +340,7 @@ namespace Aucma.Core.BoxFoam.ViewModels
}
#endregion
Semaphore semaphore = new Semaphore(1, 1);
/// <summary>
/// 将采集到的数据保存
/// </summary>
/// <param name="mode"></param>
public async void RealTimeFoamingTask(object? sender, ElapsedEventArgs e)
{
semaphore.WaitOne();
//刷新统计图表
InitEveryDayMethod();
try
{
string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
DateTime now = DateTime.Now;
CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync(d => d.StartTime <= now && d.EndTime >= now);
if (currentTeamTime!=null)
{
//比较计划更新数据
ExecHourDataAsync(productLineCode);
}
else
{
// 白夜班切换
ShiftChangeAsync(productLineCode);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
semaphore.Release();
}
}
public async void ExecHourDataAsync(string productLineCode)
{
List<FixtureStatus> bLis = CollectionFoamLine.listFixtureStatus;
if (bLis.Count == 0) return;
List<BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
List<BoxFoamDataRealTime> bfds = await _boxFoamDataRealTimeServices.QueryAsync();
for (int j = 0; j < bLis.Count; j++)
{
try
{
if (string.IsNullOrEmpty(bLis[j].FixtureBoxType)) continue;
BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == bLis[j].FixtureBoxType && d.PlanAmount > d.CompleteAmount);
if (plan != null)
{
int complateAmount = 0;
BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
if (bfd != null)
{
//更新计划数量
complateAmount = bLis[j].Yield - bfd.FixtureProductioncapacity;
UpdateClampData(bLis[j], bfd);
}
else
{
FixtureStatus fixtureStatus = bLis[j];
SaveClampData(productLineCode, fixtureStatus);
}
plan.CompleteAmount = plan.CompleteAmount + complateAmount;
if (complateAmount>0)
{
//保存历史记录
BoxFoamDataRealTimeHistory history = new BoxFoamDataRealTimeHistory();
history.PlantCode = bfd.PlantCode;
history.ProductlineCode = bfd.ProductlineCode;
history.ProcessCode = bfd.ProcessCode;
history.StationCode= bfd.StationCode;
history.FixtureProductioncapacity = bLis[j].Yield;
history.FixtureCuringtimesettingvalue = bLis[j].PlanCuringTime.ToString();
history.FixtureActualtime = bLis[j].RealCuringTime.ToString();
history.ModeInternaltemperature = bLis[j].InternalTemperature;
history.ModeOutsidetemperature = bLis[j].InternalTemperature;
history.UpdatedTime = DateTime.Now;
//事务合并
await _boxFoamDataRealTimeHistoryServices.AddAsync(history);
await _boxFoamPlanServices.UpdateAsync(plan);
}
}
else
{
//更新小时数据
BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
if (bfd != null)
{
UpdateClampData(bLis[j], bfd);
}
else
{
SaveClampData(productLineCode, bLis[j]);
}
}
}
catch { }
}
}
private async void ShiftChangeAsync(string productLineCode)
{
try
{
//切换班组计划
var currentTeamTimeList = await _sysUserInfoServices.GetTeamData();
if (currentTeamTimeList.Count == 0) return;
// 夹具
var list = await _boxFoamDataRealTimeServices.QueryAsync(d => d.ProductlineCode == productLineCode);
//更新计划表操作
CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
// 更新当班时间
currentTeamTime.TeamName = currentTeamTimeList.First().TeamName;
currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime);
currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime);
bool result = await _currentTeamTimeServices.UpdateAsync(currentTeamTime);
if (result)
{
//清空 当班计划
// var realTimeList = await _boxFoamDataRealTimeHistoryServices.QueryAsync(d => d.ProductlineCode == productLineCode);
var plan = await _boxFoamPlanServices.QueryAsync(d => d.ProductLineCode == productLineCode);
await _boxFoamPlanServices.DeletesAsync(plan);
}
}
catch { }
}
#region 更新夹具型号
@ -528,5 +399,144 @@ namespace Aucma.Core.BoxFoam.ViewModels
}
#endregion
#region 原逻辑 Delete By wenjy 2024-01-09 14:38:00
//Semaphore semaphore = new Semaphore(1, 1);
///// <summary>
///// 将采集到的数据保存
///// </summary>
///// <param name="mode"></param>
//public async void RealTimeFoamingTask(object? sender, ElapsedEventArgs e)
//{
// semaphore.WaitOne();
// try
// {
// string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
// DateTime now = DateTime.Now;
// CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync(d => d.StartTime <= now && d.EndTime >= now);
// if (currentTeamTime!=null)
// {
// //比较计划更新数据
// ExecHourDataAsync(productLineCode);
// }
// else
// {
// // 白夜班切换
// ShiftChangeAsync(productLineCode);
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
// finally
// {
// semaphore.Release();
// }
//}
//public async void ExecHourDataAsync(string productLineCode)
//{
// List<FixtureStatus> bLis = CollectionFoamLine.listFixtureStatus;
// if (bLis.Count == 0) return;
// List<BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
// List<BoxFoamDataRealTime> bfds = await _boxFoamDataRealTimeServices.QueryAsync();
// for (int j = 0; j < bLis.Count; j++)
// {
// try
// {
// if (string.IsNullOrEmpty(bLis[j].FixtureBoxType)) continue;
// BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == bLis[j].FixtureBoxType && d.PlanAmount > d.CompleteAmount);
// if (plan != null)
// {
// int complateAmount = 0;
// BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
// if (bfd != null)
// {
// //更新计划数量
// complateAmount = bLis[j].Yield - bfd.FixtureProductioncapacity;
// UpdateClampData(bLis[j], bfd);
// }
// else
// {
// FixtureStatus fixtureStatus = bLis[j];
// SaveClampData(productLineCode, fixtureStatus);
// }
// plan.CompleteAmount = plan.CompleteAmount + complateAmount;
// if (complateAmount>0)
// {
// //保存历史记录
// BoxFoamDataRealTimeHistory history = new BoxFoamDataRealTimeHistory();
// history.PlantCode = bfd.PlantCode;
// history.ProductlineCode = bfd.ProductlineCode;
// history.ProcessCode = bfd.ProcessCode;
// history.StationCode= bfd.StationCode;
// history.FixtureProductioncapacity = bLis[j].Yield;
// history.FixtureCuringtimesettingvalue = bLis[j].PlanCuringTime.ToString();
// history.FixtureActualtime = bLis[j].RealCuringTime.ToString();
// history.ModeInternaltemperature = bLis[j].InternalTemperature;
// history.ModeOutsidetemperature = bLis[j].InternalTemperature;
// history.UpdatedTime = DateTime.Now;
// //事务合并
// await _boxFoamDataRealTimeHistoryServices.AddAsync(history);
// await _boxFoamPlanServices.UpdateAsync(plan);
// }
// }
// else
// {
// //更新小时数据
// BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId);
// if (bfd != null)
// {
// UpdateClampData(bLis[j], bfd);
// }
// else
// {
// SaveClampData(productLineCode, bLis[j]);
// }
// }
// }
// catch { }
// }
//}
//private async void ShiftChangeAsync(string productLineCode)
//{
// try
// {
// //切换班组计划
// var currentTeamTimeList = await _sysUserInfoServices.GetTeamData();
// if (currentTeamTimeList.Count == 0) return;
// // 夹具
// var list = await _boxFoamDataRealTimeServices.QueryAsync(d => d.ProductlineCode == productLineCode);
// //更新计划表操作
// CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync();
// // 更新当班时间
// currentTeamTime.TeamName = currentTeamTimeList.First().TeamName;
// currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime);
// currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime);
// bool result = await _currentTeamTimeServices.UpdateAsync(currentTeamTime);
// if (result)
// {
// //清空 当班计划
// // var realTimeList = await _boxFoamDataRealTimeHistoryServices.QueryAsync(d => d.ProductlineCode == productLineCode);
// var plan = await _boxFoamPlanServices.QueryAsync(d => d.ProductLineCode == productLineCode);
// await _boxFoamPlanServices.DeletesAsync(plan);
// }
// }
// catch { }
//}
#endregion
}
}

Loading…
Cancel
Save