liulb@mesnac.com 11 months ago
parent c12b23a282
commit 83d7689a2d

@ -27,6 +27,7 @@ using Admin.Core.Model.Model_New;
using Aucma.Core.SheetMetalTasks; using Aucma.Core.SheetMetalTasks;
using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Logging;
using StackExchange.Profiling.Internal; using StackExchange.Profiling.Internal;
using Admin.Core.Service;
/* /*
* *
*/ */
@ -1210,6 +1211,11 @@ namespace Aucma.Core.SheetMetal.ViewModels
string stationCode = Appsettings.app("StationInfo", "StationCode"); string stationCode = Appsettings.app("StationInfo", "StationCode");
try try
{ {
if (SelectedCells==null)
{
MessageBox.Show("请选中要暂停的计划!");
return;
}
//获取当前计划的id //获取当前计划的id
string Id = SelectedCells.ID; string Id = SelectedCells.ID;
if (string.IsNullOrEmpty(Id)) if (string.IsNullOrEmpty(Id))
@ -1225,7 +1231,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
bool result = await _taskExecutionPlanInfoServices.UpdateAsync(taskExecutionPlanInfo); bool result = await _taskExecutionPlanInfoServices.UpdateAsync(taskExecutionPlanInfo);
if (result) if (result)
{ {
await _taskExecutionPlanInfoServices.PlanMoveDown(objId.ToString(), stationCode); // await _taskExecutionPlanInfoServices.PlanMoveDown(objId.ToString(), stationCode);
MessageBox.Show($"暂停计划成功,任务号:[{SelectedCells.TaskCode}]"); MessageBox.Show($"暂停计划成功,任务号:[{SelectedCells.TaskCode}]");
await LoadData(); await LoadData();
} }
@ -1249,14 +1255,12 @@ namespace Aucma.Core.SheetMetal.ViewModels
try try
{ {
var list = planInfoDataGrid.ToJson(); var list = planInfoDataGrid.ToJson();
if (SelectedCells==null) if (SelectedCells == null)
{ {
MessageBox.Show("请选中要执行下发的计划!"); MessageBox.Show("请选中要执行下发的计划!");
return; return;
} }
//获取当前计划的id //获取当前计划的id
string Id = SelectedCells.ID; string Id = SelectedCells.ID;
@ -1273,7 +1277,21 @@ namespace Aucma.Core.SheetMetal.ViewModels
bool result = await _taskExecutionPlanInfoServices.UpdateAsync(taskExecutionPlanInfo); bool result = await _taskExecutionPlanInfoServices.UpdateAsync(taskExecutionPlanInfo);
if (result) if (result)
{ {
//await _taskExecutionPlanInfoServices.PlanMoveDown(objId.ToString(), stationCode); List<SheetMetaSendPlanInfoView> planInfo = await _executePlanInfoServices.QuerySheetMetalSendPlanData("1001");
var task = planInfo.First(d => d.ObjId == objId);
List<ExecutePlanInfo> execList = new List<ExecutePlanInfo>();
task.ExecuteStatus = 1;
SortTaskInfos(ref planInfo, objId);
planInfo.ForEach(async t =>
{
ExecutePlanInfo executePlanInfo = await _executePlanInfoServices.FirstAsync(d=>d.ObjId==t.ObjId);
executePlanInfo.ExecuteOrder = t.ExecuteOrder;
execList.Add(executePlanInfo);
});
bool plan = await _taskExecutionPlanInfoServices.UpdateAsync(execList);
MessageBox.Show($"下发计划成功,任务号:[{SelectedCells.TaskCode}]"); MessageBox.Show($"下发计划成功,任务号:[{SelectedCells.TaskCode}]");
await LoadData(); await LoadData();
} }
@ -1283,8 +1301,70 @@ namespace Aucma.Core.SheetMetal.ViewModels
{ {
log.Error(ex.Message); log.Error(ex.Message);
} }
} }
#endregion #endregion
/// <summary>
/// 集合排序将指定实体移动至第1位并将执行顺序整体后移
/// </summary>
/// <param name="info"></param>
/// <param name="objId"></param>
/// <exception cref="ArgumentException"></exception>
private void SortTaskInfos(ref List<SheetMetaSendPlanInfoView> info, int objId)
{
if (info == null)
{
throw new ArgumentException($"执行计划排序异常:参数为空");
}
if (objId <= 0)
{
throw new ArgumentException($"执行计划排序异常:主键无效");
}
var taskExecutionPlanInfo = info.First(d => d.ObjId == objId);
if (taskExecutionPlanInfo != null)
{
info.Remove(taskExecutionPlanInfo);
info.Insert(0, taskExecutionPlanInfo);
int[] order = new int[info.Count];
for (int i = 0; i < info.Count; i++)
{
order[i] = info[i].ExecuteOrder;
}
BubbleSort(ref order);
for (int i = 0; i < info.Count; i++)
{
info[i].ExecuteOrder = order[i];
}
}
}
/// <summary>
/// 排序
/// </summary>
/// <param name="arr"></param>
public static void BubbleSort(ref int[] arr)
{
int n = arr.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
} }
} }

@ -295,8 +295,8 @@
<StackPanel > <StackPanel >
<WrapPanel VerticalAlignment="Center" HorizontalAlignment="Right" > <WrapPanel VerticalAlignment="Center" HorizontalAlignment="Right" >
<TextBlock Text="计划列表" FontSize="20" FontWeight="Bold" Foreground="White" /> <TextBlock Text="计划列表" FontSize="20" FontWeight="Bold" Foreground="White" />
<!--<Button Content="暂停计划" Command="{Binding StopCommand}" Width="100" Height="30" Background="YellowGreen" Margin="300 0 0 0" />--> <Button Content="暂停计划" Command="{Binding StopCommand}" Width="100" Height="30" Background="YellowGreen" Margin="300 0 0 0" />
<Button Content="手动下发" Command="{Binding ManualCommand}" Width="100" Height="30" Background="OrangeRed" Margin="380 0 0 0" /> <Button Content="手动下发" Command="{Binding ManualCommand}" Width="100" Height="30" Background="OrangeRed" Margin="10 0 0 0" />
</WrapPanel> </WrapPanel>
</StackPanel> </StackPanel>

@ -133,7 +133,7 @@
"EquipName": "SidePanelPlc", "EquipName": "SidePanelPlc",
"PlcType": "Melsec", "PlcType": "Melsec",
"Enabled": true, "Enabled": true,
"IP": "127.0.0.1", //"10.10.91.1", "IP": "10.10.91.1",
"Port": 5552 "Port": 5552
}, },
{ {
@ -141,7 +141,7 @@
"EquipName": "BackPanelPLC", "EquipName": "BackPanelPLC",
"PlcType": "Melsec", "PlcType": "Melsec",
"Enabled": true, "Enabled": true,
"IP": "127.0.0.1", //"10.10.91.6", "IP":"10.10.91.6",
"Port": 5553 "Port": 5553
} }
] ]

@ -1,6 +1,5 @@
using Admin.Core.Common; using Admin.Core.Common;
using Admin.Core.IService; using Admin.Core.IService;
using Admin.Core.Model.Model_New;
using Admin.Core.Model; using Admin.Core.Model;
using Admin.Core.Model.ViewModels; using Admin.Core.Model.ViewModels;
using System.Text; using System.Text;
@ -73,6 +72,7 @@ namespace Aucma.Core.SheetMetalTasks
bool sideFlag = true;//前板标识 bool sideFlag = true;//前板标识
bool statusFlag = true;//计划任务状态标识 bool statusFlag = true;//计划任务状态标识
bool complatePlanFlag = true;//计划完成 bool complatePlanFlag = true;//计划完成
#region 构造函数 #region 构造函数
/// <summary> /// <summary>
/// 构造函数 /// 构造函数
@ -214,7 +214,6 @@ namespace Aucma.Core.SheetMetalTasks
SendPlanTaskToSidPanel(planInfo, obj_sidePanel, smSyncModel.SmProductId.ObjToInt()); SendPlanTaskToSidPanel(planInfo, obj_sidePanel, smSyncModel.SmProductId.ObjToInt());
//UpdateSidPanelPlanTaskByComplate(planInfo); //UpdateSidPanelPlanTaskByComplate(planInfo);
// sideFlag = false; // sideFlag = false;
} }
if (planInfo.PlanType == 1) if (planInfo.PlanType == 1)
@ -299,9 +298,17 @@ namespace Aucma.Core.SheetMetalTasks
#region PLC反馈信号逻辑处理 #region PLC反馈信号逻辑处理
//循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中 //循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中
bool isFlag = true; bool isFlag = true;
bool isTaskFlag = true;
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
do do
{ {
//判断当前是否有手动下发的任务,有退出当前方法
isTaskFlag = GetNewTask(planInfo.ObjId);
if (isTaskFlag)
{
break;
}
int answer = obj_sidePanel.plc.ReadInt16("D6021"); int answer = obj_sidePanel.plc.ReadInt16("D6021");
if (answer == 2) if (answer == 2)
{ {
@ -310,10 +317,15 @@ namespace Aucma.Core.SheetMetalTasks
RefreshExecInfoEvent?.Invoke($"计划【{planInfo.TaskCode}】,收到前板板设备应答信号,复位应答地址", "White"); RefreshExecInfoEvent?.Invoke($"计划【{planInfo.TaskCode}】,收到前板板设备应答信号,复位应答地址", "White");
startTime = DateTime.Now; startTime = DateTime.Now;
isFlag = false; isFlag = false;
break;
} }
Thread.Sleep(3000); Thread.Sleep(3000);
} while (isFlag); } while (isFlag);
if (isTaskFlag) return ;
//更新计划状态为2执行中 //更新计划状态为2执行中
planInfo.ExecuteStatus = 2; planInfo.ExecuteStatus = 2;
bool result = _executePlanInfoServices.UpdateSheetMetalExecutePlanInfo(planInfo.ObjId, planInfo.ExecuteStatus, startTime).Result; bool result = _executePlanInfoServices.UpdateSheetMetalExecutePlanInfo(planInfo.ObjId, planInfo.ExecuteStatus, startTime).Result;
@ -595,9 +607,17 @@ namespace Aucma.Core.SheetMetalTasks
#region PLC反馈信号逻辑处理 #region PLC反馈信号逻辑处理
//循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中 //循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中
bool isFlag = true; bool isFlag = true;
bool isTaskFlag = true;
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
do do
{ {
//判断当前是否有手动下发的任务,有退出当前方法
isTaskFlag = GetNewTask(planInfo.ObjId);
if (isTaskFlag)
{
break;
}
int backPalnelAnswer = obj_backPanel.plc.ReadInt16("D4021"); int backPalnelAnswer = obj_backPanel.plc.ReadInt16("D4021");
Console.WriteLine($"【{DateTime.Now.ToString("HH:m:s")}】===>应答信号:{backPalnelAnswer}"); Console.WriteLine($"【{DateTime.Now.ToString("HH:m:s")}】===>应答信号:{backPalnelAnswer}");
if (backPalnelAnswer == 2) if (backPalnelAnswer == 2)
@ -611,6 +631,8 @@ namespace Aucma.Core.SheetMetalTasks
Thread.Sleep(2000); Thread.Sleep(2000);
} while (isFlag); } while (isFlag);
if (isTaskFlag) return;
//更新计划状态为2执行中 //更新计划状态为2执行中
planInfo.ExecuteStatus = 2; planInfo.ExecuteStatus = 2;
bool result = _executePlanInfoServices.UpdateSheetMetalExecutePlanInfo(planInfo.ObjId, planInfo.ExecuteStatus, startTime).Result; bool result = _executePlanInfoServices.UpdateSheetMetalExecutePlanInfo(planInfo.ObjId, planInfo.ExecuteStatus, startTime).Result;
@ -1495,7 +1517,7 @@ namespace Aucma.Core.SheetMetalTasks
complatePlanFlag = false; complatePlanFlag = false;
try try
{ {
var planInfoList = _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Contains(stationCode) && d.PlanAmount != d.CompleteAmount).Result; var planInfoList = _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Contains(stationCode) && d.PlanAmount > d.CompleteAmount).Result;
if (planInfoList == null || planInfoList.Count == 0) return; if (planInfoList == null || planInfoList.Count == 0) return;
var list = from d in planInfoList var list = from d in planInfoList
@ -1999,5 +2021,16 @@ namespace Aucma.Core.SheetMetalTasks
} }
} }
#endregion #endregion
public bool GetNewTask(int Id)
{
List<SheetMetaSendPlanInfoView> planInfoList = _executePlanInfoServices.QuerySheetMetalSendPlanData("1001").Result;
if (planInfoList == null || planInfoList.Count == 0) return false;
var task= planInfoList.FirstOrDefault(d=>d.ExecuteStatus==2&& d.ObjId!= Id);
if (task == null) return false;
else return true;
}
} }
} }

Loading…
Cancel
Save