You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Aucma.Core.SheetMetal/ViewModels/StatisticsPageViewModel.cs

176 lines
7.3 KiB
C#

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;
1 year ago
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<MaterialComplateInfo> materialComplateInfos = new List<MaterialComplateInfo>();
1 year ago
protected readonly IProductPlanInfoServices? _productPlanInfoServices;
protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices;
protected readonly IRecordBackPanelComplateServices _backPanelComplateServices;
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
1 year ago
public StatisticsPageViewModel()
{
1 year ago
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
_sidePanelComplateServices = App.ServiceProvider.GetService<IRecordSidePanelComplateServices>();
_backPanelComplateServices = App.ServiceProvider.GetService<IRecordBackPanelComplateServices>();
_executePlanInfoServices = App.ServiceProvider.GetService<IExecutePlanInfoServices>();
Task.WaitAll(LoadData());
1 year ago
}
#region 加载DataGrid数据
1 year ago
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;
1 year ago
int i = 1;
1 year ago
foreach (var item in list)
{
int sidePanelComplete = GetSidePanelCompleteData(sidePanelComplateList, item.OrderCode, "1001");
int backPanelComplete = GetBackPanelCompleteData(sidePanelComplateList, item.OrderCode, "1001");
1 year ago
MaterialDataGrid.Add(new MaterialComplateInfo() {
No = i,
ProductPlanCode = item.PlanCode,
1 year ago
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
1 year ago
PlanAmount = item.PlanAmount,
1 year ago
CompleteAmount = item.CompleteAmount,
SidePanelComplete = sidePanelComplete,
BackPanelComplete = backPanelComplete,
1 year ago
BeginTime = item.BeginTime.ToString(),
EndTime = item.EndTime.ToString(),
Status= item.CompleteAmount== item.PlanAmount?"完成":"未完成"
});
1 year ago
i++;
1 year ago
}
}
private async Task LoadDateData(string result)
1 year ago
{
string station = Appsettings.app("StationInfo", "StationCode");
var list = _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station)).Result;
var sidePanelComplateList = _sidePanelComplateServices.QueryAsync(d => d.ProductlineCode == station).Result;
int i = 1;
var productPlanInfoList = list.Where(d => d.OrderCode.Contains(result) || d.PlanCode.Contains(result) || d.MaterialCode.Contains(result) || d.MaterialName.Contains(result)).ToList();
foreach (var item in productPlanInfoList)
1 year ago
{
int sidePanelComplete = GetSidePanelCompleteData(sidePanelComplateList, item.OrderCode, station);
int backPanelComplete = GetBackPanelCompleteData(sidePanelComplateList, item.OrderCode, station);
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<MaterialComplateInfo> materialDataGrid = new ObservableCollection<MaterialComplateInfo>();
public ObservableCollection<MaterialComplateInfo> MaterialDataGrid
{
get { return materialDataGrid; }
set
{
materialDataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 查询
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private async Task ExecQuery(string result)
{
if (string.IsNullOrEmpty(result))
{
MessageBox.Show("查询条件不能为空!");
return;
}
1 year ago
//System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
//{
if (!string.IsNullOrEmpty(result))
{
1 year ago
MaterialDataGrid.Clear();
1 year ago
await LoadDateData(result);
1 year ago
}
else
{
MaterialDataGrid.Clear();
1 year ago
await LoadData();
1 year ago
}
}
#endregion
/// <summary>
/// 围板完成数量
/// </summary>
/// <param name="sidePanelComplate"></param>
/// <param name="orderCode">订单</param>
/// <param name="productLineCode">工位</param>
/// <returns></returns>
public int GetSidePanelCompleteData(List<RecordSidePanelComplate> sidePanelComplate, string orderCode, string productLineCode)
{
try
{
var execList = _executePlanInfoServices.QueryAsync(d => d.OrderCode == orderCode && d.ProductPlanCode == productLineCode).Result;
List<string> 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<RecordSidePanelComplate> sidePanelComplate, string orderCode, string productLineCode)
{
try
{
var execList = _executePlanInfoServices.QueryAsync(d => d.OrderCode == orderCode && d.ProductPlanCode == productLineCode).Result;
List<string> taskCodeList = execList.Select(x => x.TaskCode).ToList();
var list = _backPanelComplateServices.QueryAsync(d => taskCodeList.Contains(d.PlanCode)).Result;
return list.Count;
}
catch (Exception)
{
return 0;
}
}
}
}