From 83d7689a2d5a8414888154f88d8a0a37070c9071 Mon Sep 17 00:00:00 2001 From: "liulb@mesnac.com" Date: Mon, 1 Apr 2024 16:09:36 +0800 Subject: [PATCH] . --- .../ViewModels/IndexPageViewModel.cs | 94 +++++++++++++++++-- .../Views/IndexPageView.xaml | 4 +- Aucma.Core.SheetMetal/appsettings.json | 4 +- .../AucamSheetMetalTaskService.cs | 39 +++++++- 4 files changed, 127 insertions(+), 14 deletions(-) diff --git a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs index 0ec0be6..9b8ab59 100644 --- a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs @@ -27,6 +27,7 @@ using Admin.Core.Model.Model_New; using Aucma.Core.SheetMetalTasks; using Microsoft.IdentityModel.Logging; using StackExchange.Profiling.Internal; +using Admin.Core.Service; /* * 首页信息 */ @@ -1210,6 +1211,11 @@ namespace Aucma.Core.SheetMetal.ViewModels string stationCode = Appsettings.app("StationInfo", "StationCode"); try { + if (SelectedCells==null) + { + MessageBox.Show("请选中要暂停的计划!"); + return; + } //获取当前计划的id string Id = SelectedCells.ID; if (string.IsNullOrEmpty(Id)) @@ -1225,7 +1231,7 @@ namespace Aucma.Core.SheetMetal.ViewModels bool result = await _taskExecutionPlanInfoServices.UpdateAsync(taskExecutionPlanInfo); if (result) { - await _taskExecutionPlanInfoServices.PlanMoveDown(objId.ToString(), stationCode); + // await _taskExecutionPlanInfoServices.PlanMoveDown(objId.ToString(), stationCode); MessageBox.Show($"暂停计划成功,任务号:[{SelectedCells.TaskCode}]"); await LoadData(); } @@ -1249,14 +1255,12 @@ namespace Aucma.Core.SheetMetal.ViewModels try { var list = planInfoDataGrid.ToJson(); - - if (SelectedCells==null) + + if (SelectedCells == null) { MessageBox.Show("请选中要执行下发的计划!"); return; } - - //获取当前计划的id string Id = SelectedCells.ID; @@ -1273,7 +1277,21 @@ namespace Aucma.Core.SheetMetal.ViewModels bool result = await _taskExecutionPlanInfoServices.UpdateAsync(taskExecutionPlanInfo); if (result) { - //await _taskExecutionPlanInfoServices.PlanMoveDown(objId.ToString(), stationCode); + List planInfo = await _executePlanInfoServices.QuerySheetMetalSendPlanData("1001"); + + var task = planInfo.First(d => d.ObjId == objId); + List execList = new List(); + + 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}]"); await LoadData(); } @@ -1283,8 +1301,70 @@ namespace Aucma.Core.SheetMetal.ViewModels { log.Error(ex.Message); } - } + } #endregion + + + + /// + /// 集合排序:将指定实体移动至第1位并将执行顺序整体后移 + /// + /// + /// + /// + private void SortTaskInfos(ref List 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]; + } + + } + } + + /// + /// 排序 + /// + /// + 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; + } + } + } + } } } diff --git a/Aucma.Core.SheetMetal/Views/IndexPageView.xaml b/Aucma.Core.SheetMetal/Views/IndexPageView.xaml index 4a5e0d0..c957a05 100644 --- a/Aucma.Core.SheetMetal/Views/IndexPageView.xaml +++ b/Aucma.Core.SheetMetal/Views/IndexPageView.xaml @@ -295,8 +295,8 @@ - -