using Aucma.Core.SheetMetal.Models; using Aucma.Core.SheetMetal.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using System.Linq; using System.Threading.Tasks; using Admin.Core.IService; using Microsoft.Extensions.DependencyInjection; using Aucma.Core.SheetMetal.Common; using Admin.Core.Model.Model_New; using Admin.Core.Tasks; using CommunityToolkit.Mvvm.Messaging; using LiveCharts; using LiveCharts.Wpf; using Admin.Core.Model; using System.Windows.Media; using log4net; using Admin.Core.Common; /* * 首页信息 * */ namespace Aucma.Core.SheetMetal.ViewModels { public partial class IndexPageViewModel : ObservableObject { protected readonly IExecutePlanInfoServices? _taskExecutionServices; int k = 100; public IndexPageViewModel() { _taskExecutionServices = App.ServiceProvider.GetService(); StationName = "U壳/侧板钣金生产"; //Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod; Job_SheetMetalTask_Quartz.SmShowDelegateEvent += UpdatePlanSHow;//计划内容展示 WeakReferenceMessenger.Default.Register(this, Recive); Task.Run(async () => { await LoadData(); await InitExecMethod(); }); InitEveryDayMethod(); } #region 订单统计 private async Task InitExecMethod() { string station = "1001"; ExecutePlanInfo info = await _taskExecutionServices.FirstAsync(d => d.ProductLineCode.Equals(station) && d.ExecuteStatus == 2); if (info == null) return; PlanNum = info.PlanAmount; RealQuantity = info.CompleteAmount; DiffQuantity =Math.Abs(info.CompleteAmount-info.PlanAmount); CompletionRate = info.CompleteAmount / info.PlanAmount; } #endregion #region 每日生产 /// /// 每日生产 /// /// private void InitEveryDayMethod() { ChartValues achievement = new ChartValues(); Random random = new Random(); for (int i = 0; i < 5; i++) { achievement.Add(random.Next(60, 100)); } var column = new ColumnSeries(); column.DataLabels = true; column.Title = "型号"; column.Values = achievement; column.Foreground = Brushes.White; ModelStatistics.Add(column); ProductionHourList = new List() { "12", "13", "14", "15", "16", }; ChartValues achievement2 = new ChartValues(); Random random2 = new Random(); for (int i = 0; i < 5; i++) { achievement2.Add(random2.Next(60, 100)); } var column2 = new ColumnSeries(); column2.DataLabels = true; column2.Title = "产量"; column2.Values = achievement2; column2.Foreground = Brushes.White; Achievement.Add(column2); //await InitExecMethod(); } #endregion #region 计划列表 #region 加载DataGrid数据 private async Task LoadData() { var list= await _taskExecutionServices.QueryAsync(d=>d.ProductLineCode.Contains("1001")); var execList= list.OrderBy(d=>d.ExecuteOrder); foreach (var item in execList) { TaskExecModel task=new TaskExecModel(); task.ID = item.ObjId.ToString(); task.OrderCode = item.OrderCode; task.MaterialCode = item.MaterialCode; task.MaterialName = item.MaterialName; task.TaskAmount = item.PlanAmount; task.CompleteAmount = item.CompleteAmount; task.BeginTime = item.BeginTime; task.IsExec = item.ExecuteStatus; PlanInfoDataGrid.Add(task); } } #endregion #region 向上 /// /// 向上 /// [RelayCommand] private async Task MoveUp(string Id) { string stationCode = Appsettings.app("StoreInfo", "StationCode"); bool result = await _taskExecutionServices.PlanMoveUp(Id, stationCode); if (result) { PlanInfoDataGrid.Clear(); LoadData(); } } #endregion #region 向下 /// /// 向下 /// [RelayCommand] private async Task MoveDown(string Id) { string stationCode = Appsettings.app("StoreInfo", "StationCode"); bool result = await _taskExecutionServices.PlanMoveDown(Id, stationCode); if (result) { PlanInfoDataGrid.Clear(); LoadData(); } } #endregion #region 删除 /// /// 删除 /// [RelayCommand] private async Task DeletePlan(string Id) { MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (MessageBoxResult.Yes == msg) { bool result = await _taskExecutionServices.ExecPlanDelete(Id); if (result) { PlanInfoDataGrid.Clear(); LoadData(); MessageBox.Show("执行计划删除成功", "系统信息"); } else { MessageBox.Show("执行计划删除失败", "系统信息"); } } } #endregion #region 下传计划 /// /// 下传计划 /// [RelayCommand] private async Task NextPass(string Id) { MessageBoxResult msg = MessageBox.Show("确定要下发计划吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (MessageBoxResult.Yes != msg) return; var model = await _taskExecutionServices.FirstAsync(d => d.ObjId == int.Parse(Id)); if (model.ExecuteStatus == 2) { MessageBox.Show("该计划正在执行中,请勿重复下传", "系统信息"); } else { var result = _taskExecutionServices.PlanNextPass(model); if (result != null) { //刷新列表 MessageBox.Show("执行计划已下达", "系统信息"); } else { MessageBox.Show("执行计划下达失败", "系统信息"); } } } #endregion #region 初始化datagrid private ObservableCollection planInfoDataGrid = new ObservableCollection(); public ObservableCollection PlanInfoDataGrid { get { return planInfoDataGrid; } set { planInfoDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #region 计划拆分执行 /// /// 计划拆分执行 /// [RelayCommand] private void SplitPlan() { SplitPlanView split=new SplitPlanView(); split.ShowDialog(); } #endregion #endregion #region 执行计划 #region 工位名称 private string _stationName; public string StationName { get => _stationName; set => SetProperty(ref _stationName, value); } #endregion #region 订单编号 private string _orderCode; public string OrderCode { get => _orderCode; set => SetProperty(ref _orderCode, value); } #endregion #region 计划编号 private string _planCode; public string PlanCode { get => _planCode; set => SetProperty(ref _planCode, value); } #endregion #region 产品型号 private string _productModel; public string ProductModel { get=>_productModel; set=> SetProperty(ref _productModel, value); } #endregion #region 开始时间 private string _beginTime; public string BeginTime { get => _beginTime; set => SetProperty(ref _beginTime, value); } #endregion #region 计划数量 private int _planNum; public int PlanNum { get => _planNum; set => SetProperty(ref _planNum, value); } /// /// 计划最大值 /// private int _planMaxNum; public int PlanMaxNum { get => _planMaxNum; set => SetProperty(ref _planMaxNum, value); } #endregion #region 实际数量 private int _realQuantity; public int RealQuantity { get => _realQuantity; set => SetProperty(ref _realQuantity, value); } #endregion #region 差异数量 private int _diffQuantity; public int DiffQuantity { get => _diffQuantity; set => SetProperty(ref _diffQuantity, value); } #endregion #region 完成率 private double _completionRate; public double CompletionRate { get => _completionRate; set => SetProperty(ref _completionRate, value); } #endregion #endregion #region 当日产量 #region 日产量柱状图X轴日期 /// /// 日产量柱状图X轴日期 /// private List productionHourList; public List ProductionHourList { get { return productionHourList; } set { productionHourList = value; } } #endregion /// /// 日产量柱状图 /// private SeriesCollection achievement = new SeriesCollection(); public SeriesCollection Achievement { get { return achievement; } set { achievement = value; } } #endregion #region 型号统计 #region 型号统计柱状图x轴物料类型 /// /// 型号统计柱状图x轴物料类型 /// private List materialNameList; public List MaterialNameList { get { return materialNameList; } set { materialNameList = value; } } #endregion #region 型号统计柱状图 /// /// 型号统计柱状图 /// private SeriesCollection modelStatistics = new SeriesCollection(); public SeriesCollection ModelStatistics { get { return modelStatistics; } set { modelStatistics = value; } } #endregion #endregion #region 刷新列表-其他界面刷新该方法 /// /// 刷新列表 /// /// /// private async void Recive(object recipient, object message) { PlanInfoDataGrid.Clear(); await LoadData(); } #endregion #region 刷新界面显示数据 /// /// 刷新界面显示数据 /// /// /// public Task UpdatePlanSHow(ExecutePlanInfo info) { if (info == null) return Task.CompletedTask; System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { PlanMaxNum = info.PlanAmount; OrderCode = info.OrderCode; PlanCode = info.ProductPlanCode; ProductModel = info.MaterialName; BeginTime = info.BeginTime.ToString(); })); return Task.CompletedTask; } #endregion } }