using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Aucma.Core.SheetMetal.Models; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Admin.Core.IService; using Admin.Core.Service; using Microsoft.Extensions.DependencyInjection; using Admin.Core.Model; using StackExchange.Profiling.Internal; using Admin.Core.Common; namespace Aucma.Core.SheetMetal.ViewModels { public partial class StatisticsPageViewModel : ObservableObject { List materialComplateInfos = new List(); protected readonly IProductPlanInfoServices? _productPlanInfoServices; protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices; protected readonly IRecordBackPanelComplateServices _backPanelComplateServices; protected readonly IExecutePlanInfoServices? _executePlanInfoServices; public StatisticsPageViewModel() { _productPlanInfoServices = App.ServiceProvider.GetService(); _sidePanelComplateServices = App.ServiceProvider.GetService(); _backPanelComplateServices = App.ServiceProvider.GetService(); _executePlanInfoServices = App.ServiceProvider.GetService(); Task.WaitAll(LoadData()); } #region 加载DataGrid数据 private async Task LoadData() { string station = Appsettings.app("StationInfo", "StationCode"); var list = _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station)).Result; var sidePanelComplateList = _sidePanelComplateServices.QueryAsync(d => d.ProductlineCode == "1001").Result; int i = 1; foreach (var item in list) { int sidePanelComplete = GetSidePanelCompleteData(sidePanelComplateList, item.OrderCode, "1001"); int backPanelComplete = GetBackPanelCompleteData(sidePanelComplateList, item.OrderCode, "1001"); MaterialDataGrid.Add(new MaterialComplateInfo() { No = i, ProductPlanCode = item.PlanCode, MaterialCode = item.MaterialCode, MaterialName = item.MaterialName, PlanAmount = item.PlanAmount, CompleteAmount = item.CompleteAmount, SidePanelComplete = sidePanelComplete, BackPanelComplete = backPanelComplete, BeginTime = item.BeginTime.ToString(), EndTime = item.EndTime.ToString(), Status= item.CompleteAmount== item.PlanAmount?"完成":"未完成" }); i++; } } #endregion #region 初始化datagrid private ObservableCollection materialDataGrid = new ObservableCollection(); public ObservableCollection MaterialDataGrid { get { return materialDataGrid; } set { materialDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #region 查询 /// /// 查询 /// [RelayCommand] private async Task ExecQuery(object obj) { var result = (StatisticModel)obj; if (string.IsNullOrEmpty(result.BeginTime)) { MessageBox.Show("开始时间不能为空!"); return; } if (string.IsNullOrEmpty(result.EndTime)) { MessageBox.Show("结束时间不能为空!"); return; } //System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => //{ if (!string.IsNullOrEmpty(result.BeginTime)) { var beginTime =DateTime.Parse(result.BeginTime); var endTime = DateTime.Parse(result.EndTime); MaterialDataGrid.Clear(); string station = Appsettings.app("StationInfo", "StationCode"); var list = _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station)).Result; foreach (var item in list.Where(d=>d.BeginTime> beginTime&& d.EndTime < endTime)) { MaterialDataGrid.Add(new MaterialComplateInfo() { ProductPlanCode = item.PlanCode, MaterialCode = item.MaterialCode, MaterialName = item.MaterialName, PlanAmount = item.PlanAmount, CompleteAmount = item.CompleteAmount, BeginTime = item.BeginTime.ToString(), EndTime = item.EndTime.ToString(), }); } } else { MaterialDataGrid.Clear(); LoadData(); } } #endregion /// /// 围板完成数量 /// /// /// 订单 /// 工位 /// public int GetSidePanelCompleteData(List sidePanelComplate, string orderCode, string productLineCode) { try { var execList = _executePlanInfoServices.QueryAsync(d => d.OrderCode == orderCode && d.ProductPlanCode == productLineCode).Result; List taskCodeList = execList.Select(x => x.TaskCode).ToList(); var list = _sidePanelComplateServices.QueryAsync(d => taskCodeList.Contains(d.PlanCode)).Result; return list.Count; } catch (Exception) { return 0; } } public int GetBackPanelCompleteData(List sidePanelComplate, string orderCode, string productLineCode) { try { var execList = _executePlanInfoServices.QueryAsync(d => d.OrderCode == orderCode && d.ProductPlanCode == productLineCode).Result; List taskCodeList = execList.Select(x => x.TaskCode).ToList(); var list = _backPanelComplateServices.QueryAsync(d => taskCodeList.Contains(d.PlanCode)).Result; return list.Count; } catch (Exception) { return 0; } } } }