change - 图表随mes上班时间联动

dev
liuwf 1 year ago
parent bd8a8f3ca7
commit c6ca8c12bb

@ -1,5 +1,6 @@
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.ViewModels;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -11,6 +12,10 @@ namespace Admin.Core.IService
public interface IBaseBomInfoServices : IBaseServices<BaseBomInfo>
{
/// <summary>
/// 获取系统班组时间
/// </summary>
public Task<List<WorkTime>> getWorkTime();
/// <summary>
/// 根据成品物料码获取自己BOM信息
/// </summary>

@ -2,6 +2,7 @@
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Model.ViewModels;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -12,7 +13,11 @@ namespace Admin.Core.IService
/// </summary>
public interface IOffLineInfoServices : IBaseServices<OffLineInfo>
{
/// <summary>
/// 图表统计,按白夜班时间
/// </summary>
public Task<List<ChartsByTime>> QueryCharts(DateTime startTime, DateTime endTime);
}
}

@ -0,0 +1,18 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Model.ViewModels
{
[SugarTable("PRODUCT_OFFLINE", "AUCMA_SCADA")]
public class ChartsByTime
{
[SugarColumn(ColumnName = "HourlyTime")]
public string time { get; set; }
[SugarColumn(ColumnName = "AMOUNT")]
public int Amount { get; set; }
}
}

@ -0,0 +1,32 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Model.ViewModels
{
/// <summary>
/// 条码绑定扫描类型统计
/// </summary>
[SugarTable("VIEW_CURRENT_TEAM_TIME", "AUCMA_MES")]
public class WorkTime
{
/// <summary>
/// 开始时间
/// </summary>
[SugarColumn(ColumnName = "START_TIME")]
public DateTime startTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
[SugarColumn(ColumnName = "END_TIME")]
public DateTime endTime { get; set; }
[SugarColumn(ColumnName = "HOUR_TIME")]
public string hourTime { get; set; }
[SugarColumn(ColumnName = "TEAM_NAME")]
public string teamName { get; set; }
}
}

@ -2,9 +2,11 @@
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Model.ViewModels;
using log4net;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.IdentityModel.Logging;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,6 +24,26 @@ namespace Admin.Core.Service
base.BaseDal = dal;
}
/// <summary>
/// 获取系统班组时间
/// </summary>
public async Task<List<WorkTime>> getWorkTime()
{
try
{
List<WorkTime> list = null;
var _db = this.BaseDal.Db;
list = await _db.Ado.SqlQueryAsync<WorkTime>("SELECT * FROM VIEW_CURRENT_TEAM_TIME ORDER BY START_TIME");
return list;
}
catch (Exception)
{
return null;
}
}
/// <param name="materialCode"></param>
/// <returns></returns>
public async Task<BaseBomInfo> GetBomInfoByMaterialCode(string materialCode)
{
BaseBomInfo bomInfo = null;

@ -2,6 +2,10 @@
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Model.ViewModels;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Admin.Core.Service
{
@ -13,5 +17,22 @@ namespace Admin.Core.Service
this._dal = dal;
base.BaseDal = dal;
}
/// <summary>
/// 图表统计,按白夜班时间
/// </summary>
public async Task<List<ChartsByTime>> QueryCharts(DateTime startTime, DateTime endTime)
{
try
{
List<ChartsByTime> list = null;
var _db = this.BaseDal.Db;
list = await _db.Ado.SqlQueryAsync<ChartsByTime>($"WITH AllHours AS (SELECT TO_CHAR(to_date('{startTime}', 'YYYY-MM-DD HH24:MI:SS') + (LEVEL-1)/24, 'YYYY-MM-DD HH24') AS Hour FROM dual CONNECT BY LEVEL <= 12)SELECT AllHours.Hour AS HourlyTime, COUNT(PRODUCT_OFFLINE.PRODUCT_SCANTIME) AS Amount FROM AllHours LEFT JOIN AUCMA_SCADA.PRODUCT_OFFLINE ON AllHours.Hour = TO_CHAR(PRODUCT_OFFLINE.PRODUCT_SCANTIME, 'YYYY-MM-DD HH24') AND PRODUCT_OFFLINE.PRODUCT_SCANTIME >= TO_DATE('{startTime}', 'YYYY-MM-DD HH24:MI:SS') AND PRODUCT_OFFLINE.PRODUCT_SCANTIME <= TO_DATE('{endTime}', 'YYYY-MM-DD HH24:MI:SS') GROUP BY AllHours.Hour ORDER BY AllHours.Hour");
return list;
}
catch (Exception)
{
return null;
}
}
}
}

@ -129,10 +129,11 @@ namespace Aucma.Core.CodeBinding.ViewModels
{
}
}
// 修改为统计近一天
// 修改为统计近一天白班或夜班
private async void LoadCharts()
{
List<CodeBindCharts> list = await _codeBindingRecordServices.QueryCharts();
List<CodeBindCharts> list = await _codeBindingRecordServices.QueryCharts();
// 图表赋值
ChartValues<double> achievement = new ChartValues<double>();
List<string> chartList = new List<string>();

@ -0,0 +1,15 @@
using NPOI.OpenXmlFormats.Dml.Chart;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.ProductOffLine.Models
{
public class ChartsByTime
{
public string time;
public int Amount;
}
}

@ -35,6 +35,7 @@ using System.Windows;
using System.Collections.ObjectModel;
using Aucma.Core.ProductOffLine.Models;
using System.Globalization;
using Admin.Core.Model.ViewModels;
/*
@ -51,17 +52,18 @@ namespace Aucma.Core.ProductOffLine.ViewModels
private readonly IOffLineInfoServices? _offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>();
System.Timers.Timer timer = new System.Timers.Timer(1000 * 1);//界面刷新定时器
private readonly IBaseBomInfoServices? _baseBomInfoServices;
private OffLineBusiness offLineBusiness = OffLineBusiness.Instance;
int a = 0;
public IndexPageViewModel()
{
offLineBusiness.test();
_offLineInfoServices = App.ServiceProvider.GetService<IOffLineInfoServices>();
_baseBomInfoServices = App.ServiceProvider.GetService<IBaseBomInfoServices>();
InitEveryDayMethod();
// 刷新界面信息
RefreshPageListen();
}
#region 参数定义
@ -303,10 +305,29 @@ namespace Aucma.Core.ProductOffLine.ViewModels
}
#endregion
private void InitEveryDayMethod()
private async void InitEveryDayMethod()
{
LoadData();
BeginTime = DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss");
List<WorkTime> listTime = await _baseBomInfoServices.getWorkTime();
if (listTime == null) return;
List<Admin.Core.Model.ViewModels.ChartsByTime> list = await _offLineInfoServices.QueryCharts(listTime[0].startTime, listTime[11].startTime);
if (list == null) return;
List<string> xList =new List<string>();
ChartValues<double> achievement2 = new ChartValues<double>();
for (int i = 0; i < 12; i++)
{
xList.Add(list[i].time.Substring(11, 2)+":00");
achievement2.Add(list[i].Amount);
}
var column2 = new ColumnSeries();
column2.DataLabels = true;
column2.Title = "产量";
column2.Values = achievement2;
column2.Foreground = Brushes.White;
Achievement.Add(column2);
ProductionHourList = xList;
ChartValues<double> achievement = new ChartValues<double>();
Random random = new Random();
for (int i = 0; i < 5; i++)
@ -329,29 +350,6 @@ namespace Aucma.Core.ProductOffLine.ViewModels
"SC-439背板",
"SC-439VAM,元气森林,C",
};
ProductionHourList = new List<string>()
{
"12",
"13",
"14",
"15",
"16",
};
ChartValues<double> achievement2 = new ChartValues<double>();
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);
// 加载datagrid
}
public async void LoadData()
{

@ -245,6 +245,7 @@
</Border>
<Border Grid.Row="1" BorderBrush="#0288d1" BorderThickness="0" CornerRadius="5" Background="Transparent" >
<lvc:CartesianChart Series="{Binding Achievement, UpdateSourceTrigger=PropertyChanged}" >
<lvc:CartesianChart.AxisX>
<lvc:Axis Labels="{Binding ProductionHourList}" FontSize="15">
<lvc:Axis.Separator>

Loading…
Cancel
Save