180 lines
6.0 KiB
C#
180 lines
6.0 KiB
C#
using System.Collections.Generic;
|
|
using WcsMain.ApiServe.Vo.Board;
|
|
using WcsMain.Common;
|
|
using WcsMain.DataBase.Dao;
|
|
using WcsMain.DataBase.JoinTableEntity;
|
|
using WcsMain.DataBase.TableEntity;
|
|
using WcsMain.Enum.Stacker;
|
|
using WcsMain.WcsAttribute.AutoFacAttribute;
|
|
|
|
namespace WcsMain.ApiServe.Service.BoardService;
|
|
|
|
/// <summary>
|
|
/// 二维大屏 controller service
|
|
/// </summary>
|
|
[Service]
|
|
public class Board2Service(AppWmsTaskDao wmsTaskDao, AppErrRecorDao appErrRecorDao)
|
|
{
|
|
|
|
//private List<AppBaseErr>? _appBaseErrs;
|
|
|
|
/// <summary>
|
|
/// 获取堆垛机运行效率
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public StackerRunningEfficiencyResponse GetStackerRunningEfficiency()
|
|
{
|
|
int[] data = [0, 0, 0, 0, 0];
|
|
if (CommonData.AppLocations == null)
|
|
{
|
|
return new StackerRunningEfficiencyResponse() { Data = data };
|
|
}
|
|
List<AppWmsTask>? wmsTasks = wmsTaskDao.SelectRecentOneHour();
|
|
if(wmsTasks == null)
|
|
{
|
|
return new StackerRunningEfficiencyResponse() { Data = data };
|
|
}
|
|
foreach (var wmsTask in wmsTasks)
|
|
{
|
|
if(wmsTask.TaskType == (int)WmsTaskTypeEnum.inTask)
|
|
{
|
|
var location = CommonData.AppLocations.Find(f => f.WmsLocation == wmsTask.Destination);
|
|
if(location != null)
|
|
{
|
|
data[(int)location.EquipmentId! - 1]++;
|
|
}
|
|
}
|
|
else if (wmsTask.TaskType == (int)WmsTaskTypeEnum.outTask)
|
|
{
|
|
var location = CommonData.AppLocations.Find(f => f.WmsLocation == wmsTask.Origin);
|
|
if (location != null)
|
|
{
|
|
data[(int)location.EquipmentId! - 1]++;
|
|
}
|
|
}
|
|
}
|
|
return new StackerRunningEfficiencyResponse() { Data = data };
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据堆垛机获取错误信息数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<NameValueData<int>> GetErrByCrane()
|
|
{
|
|
List<AppErrorRecordJoin>? appErrorRecordJoins = appErrRecorDao.SelectErrorRecordWithJoin();
|
|
if(appErrorRecordJoins == null)
|
|
{
|
|
return [];
|
|
}
|
|
List<string> names = [];
|
|
foreach (var appErrorRecordJoin in appErrorRecordJoins)
|
|
{
|
|
if (!names.Contains(appErrorRecordJoin.EquipmentId!))
|
|
{
|
|
names.Add(appErrorRecordJoin.EquipmentId!);
|
|
}
|
|
}
|
|
List<int> counts = [];
|
|
foreach (var name in names)
|
|
{
|
|
int count = appErrorRecordJoins.FindAll(f => f.EquipmentId == name).Count;
|
|
counts.Add(count);
|
|
}
|
|
List<NameValueData<int>> nameValueDatas = [];
|
|
for (int i = 0; i < names.Count; i++)
|
|
{
|
|
nameValueDatas.Add(new NameValueData<int>() { Name = string.Concat("#", names[i].AsSpan(names[i].Length - 1, 1)), Value = counts[i] });
|
|
}
|
|
return nameValueDatas;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据故障类型获取错误信息数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<NameValueData<int>> GetErrByCategory()
|
|
{
|
|
List<AppErrorRecordJoin>? appErrorRecordJoins = appErrRecorDao.SelectErrorRecordWithJoin();
|
|
if (appErrorRecordJoins == null)
|
|
{
|
|
return [];
|
|
}
|
|
List<string> names = [];
|
|
foreach (var appErrorRecordJoin in appErrorRecordJoins)
|
|
{
|
|
if (!names.Contains(appErrorRecordJoin.ErrType!))
|
|
{
|
|
names.Add(appErrorRecordJoin.ErrType!);
|
|
}
|
|
}
|
|
List<int> counts = [];
|
|
foreach (var name in names)
|
|
{
|
|
int count = appErrorRecordJoins.FindAll(f => f.ErrType == name).Count;
|
|
counts.Add(count);
|
|
}
|
|
List<NameValueData<int>> nameValueDatas = [];
|
|
for (int i = 0; i < names.Count; i++)
|
|
{
|
|
nameValueDatas.Add(new NameValueData<int>() { Name = names[i], Value = counts[i] });
|
|
}
|
|
return nameValueDatas;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取错误信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ErrorDetail> GetErrInfo()
|
|
{
|
|
List<AppErrorRecordJoin>? appErrorRecordJoins = appErrRecorDao.SelectErrorRecordWithJoin();
|
|
if (appErrorRecordJoins == null)
|
|
{
|
|
return [];
|
|
}
|
|
List<ErrorDetail> errors = new List<ErrorDetail>();
|
|
int i = 0;
|
|
foreach(var appErrorRecordJoin in appErrorRecordJoins)
|
|
{
|
|
errors.Add(new ErrorDetail()
|
|
{
|
|
Time = ((DateTime)appErrorRecordJoin.CreateTime!).ToString("MM-dd HH:mm:ss"),
|
|
Material = string.Concat("#", appErrorRecordJoin.EquipmentId!.AsSpan(appErrorRecordJoin.EquipmentId!.Length - 1, 1)),
|
|
FaultName = appErrorRecordJoin.ErrMsg!,
|
|
FaultCode = appErrorRecordJoin.ErrNo!.ToString()
|
|
});
|
|
i++;
|
|
if(i >= 5)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return errors;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取任务数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public TaskCountResponse GetTaskCount()
|
|
{
|
|
List<AppWmsTask>? recentDaysTask = wmsTaskDao.SelectRecenntDay(7);
|
|
if(recentDaysTask == null)
|
|
{
|
|
return new TaskCountResponse() { Date = [], In = [], Out = [] };
|
|
}
|
|
TaskCountResponse taskCountResponse = new() { Date = [], In = [], Out = [] };
|
|
for(int j = 7; j >= 0; j--)
|
|
{
|
|
string date = DateTime.Now.AddDays(-j).ToString("MM-dd");
|
|
taskCountResponse.Date.Add(DateTime.Now.AddDays(-j).ToString("MM-dd"));
|
|
taskCountResponse.In.Add(recentDaysTask.FindAll(f => f.TaskType == (int)WmsTaskTypeEnum.inTask && ((DateTime)f.CreateTime!).ToString("MM-dd") == date).Count);
|
|
taskCountResponse.Out.Add(recentDaysTask.FindAll(f => f.TaskType == (int)WmsTaskTypeEnum.outTask && ((DateTime)f.CreateTime!).ToString("MM-dd") == date).Count);
|
|
}
|
|
return taskCountResponse;
|
|
}
|
|
|
|
|
|
}
|