添加二维大屏的一些接口
This commit is contained in:
parent
875090c8f6
commit
1c5b475696
|
|
@ -0,0 +1,52 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WcsMain.ApiServe.Service.BoardService;
|
||||
using WcsMain.ApiServe.Vo.Board;
|
||||
|
||||
namespace WcsMain.ApiServe.Controllers.BoardController;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 二维大屏数据接口
|
||||
/// </summary>
|
||||
[Route("api/board/board2")]
|
||||
[ApiController]
|
||||
public class Board2Controller(Board2Service board2Service) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取堆垛机运行效率
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getStackerRunningEfficiency")]
|
||||
public StackerRunningEfficiencyResponse GetStackerRunningEfficiency() => board2Service.GetStackerRunningEfficiency();
|
||||
|
||||
/// <summary>
|
||||
/// 根据堆垛机获取错误信息数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getErrByCrane")]
|
||||
public List<NameValueData<int>> GetErrByCrane() => board2Service.GetErrByCrane();
|
||||
|
||||
/// <summary>
|
||||
/// 根据故障类型获取错误信息数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getErrByCategory")]
|
||||
public List<NameValueData<int>> GetErrByCategory() => board2Service.GetErrByCategory();
|
||||
|
||||
/// <summary>
|
||||
/// 获取错误信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getErrInfo")]
|
||||
public List<ErrorDetail> GetErrInfo() => board2Service.GetErrInfo();
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getTaskCount")]
|
||||
public TaskCountResponse GetTaskCount() => board2Service.GetTaskCount();
|
||||
|
||||
|
||||
}
|
||||
179
WcsMain/ApiServe/Service/BoardService/Board2Service.cs
Normal file
179
WcsMain/ApiServe/Service/BoardService/Board2Service.cs
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
WcsMain/ApiServe/Vo/Board/ErrorDetail.cs
Normal file
32
WcsMain/ApiServe/Vo/Board/ErrorDetail.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Newtonsoft.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WcsMain.ApiServe.Vo.Board;
|
||||
|
||||
public class ErrorDetail
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
[JsonPropertyName("time")]
|
||||
public string? Time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备名称
|
||||
/// </summary>
|
||||
[JsonPropertyName("material")]
|
||||
public string? Material { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 故障信息
|
||||
/// </summary>
|
||||
[JsonPropertyName("faultName")]
|
||||
public string? FaultName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 故障代码
|
||||
/// </summary>
|
||||
[JsonPropertyName("faultCode")]
|
||||
public string? FaultCode { get; set; }
|
||||
|
||||
}
|
||||
17
WcsMain/ApiServe/Vo/Board/NameValueData.cs
Normal file
17
WcsMain/ApiServe/Vo/Board/NameValueData.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Newtonsoft.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WcsMain.ApiServe.Vo.Board;
|
||||
|
||||
/// <summary>
|
||||
/// 键值对数据
|
||||
/// </summary>
|
||||
public class NameValueData<T>
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("value")]
|
||||
public T? Value { get; set; }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using Newtonsoft.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WcsMain.ApiServe.Vo.Board;
|
||||
|
||||
/// <summary>
|
||||
/// 堆垛机效率返回类
|
||||
/// </summary>
|
||||
public class StackerRunningEfficiencyResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 效率
|
||||
/// </summary>
|
||||
[JsonPropertyName("data")]
|
||||
public int[]? Data { get; set; }
|
||||
|
||||
}
|
||||
17
WcsMain/ApiServe/Vo/Board/TaskCountResponse.cs
Normal file
17
WcsMain/ApiServe/Vo/Board/TaskCountResponse.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Newtonsoft.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WcsMain.ApiServe.Vo.Board;
|
||||
|
||||
public class TaskCountResponse
|
||||
{
|
||||
[JsonPropertyName("date")]
|
||||
public List<string>? Date { get; set; }
|
||||
|
||||
[JsonPropertyName("in")]
|
||||
public List<int>? In { get; set; }
|
||||
|
||||
[JsonPropertyName("out")]
|
||||
public List<int>? Out { get; set; }
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using WcsMain.Common;
|
||||
using WcsMain.DataBase.JoinTableEntity;
|
||||
using WcsMain.DataBase.TableEntity;
|
||||
using WcsMain.WcsAttribute.AutoFacAttribute;
|
||||
|
||||
|
|
@ -27,5 +28,76 @@ public class AppErrRecorDao
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AppErrRecord>? Query()
|
||||
{
|
||||
try
|
||||
{
|
||||
var sqlFuc = CommonTool.DbServe.Queryable<AppErrRecord>();
|
||||
return sqlFuc.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_ = ex;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询指定条数的数据
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public List<AppErrRecord>? Query(int count)
|
||||
{
|
||||
if(count < 1) return null;
|
||||
try
|
||||
{
|
||||
var sqlFuc = CommonTool.DbServe.Queryable<AppErrRecord>().Take(count);
|
||||
return sqlFuc.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_ = ex;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询最近一个月的故障列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AppErrorRecordJoin>? SelectErrorRecordWithJoin()
|
||||
{
|
||||
try
|
||||
{
|
||||
var sqlFuc = CommonTool.DbServe.Queryable<AppErrRecord>()
|
||||
.LeftJoin<AppBaseErr>((r, b) => r.ErrNo == b.ErrNo)
|
||||
.Where(r => r.CreateTime > DateTime.Now.AddMonths(-1))
|
||||
.Select((r, b) =>
|
||||
new AppErrorRecordJoin
|
||||
{
|
||||
Area = r.Area,
|
||||
ErrNo = r.ErrNo,
|
||||
EquipmentId = r.EquipmentId,
|
||||
CreateTime = r.CreateTime,
|
||||
ErrType = b.ErrType,
|
||||
ErrMsg = b.ErrMsg
|
||||
});
|
||||
return sqlFuc.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_ = ex;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -261,6 +261,49 @@ public class AppWmsTaskDao
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最近一个小时的任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AppWmsTask>? SelectRecentOneHour()
|
||||
{
|
||||
try
|
||||
{
|
||||
var sqlFuc = CommonTool.DbServe.Queryable<AppWmsTask>()
|
||||
.Where(w => w.CreateTime> DateTime.Now.AddHours(-1))
|
||||
.ToList();
|
||||
return sqlFuc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_ = ex;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最近几天的任务
|
||||
/// </summary>
|
||||
/// <param name="days"></param>
|
||||
/// <returns></returns>
|
||||
public List<AppWmsTask>? SelectRecenntDay(int days)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sqlFuc = CommonTool.DbServe.Queryable<AppWmsTask>()
|
||||
.Where(w => w.CreateTime > DateTime.Now.AddDays(-days))
|
||||
.OrderBy(o => o.CreateTime)
|
||||
.ToList();
|
||||
return sqlFuc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_ = ex;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置任务状态
|
||||
/// </summary>
|
||||
|
|
|
|||
52
WcsMain/DataBase/JoinTableEntity/AppErrorRecordJoin.cs
Normal file
52
WcsMain/DataBase/JoinTableEntity/AppErrorRecordJoin.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using SqlSugar;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WcsMain.DataBase.JoinTableEntity;
|
||||
|
||||
/// <summary>
|
||||
/// 报警信息联表查询
|
||||
/// </summary>
|
||||
public class AppErrorRecordJoin
|
||||
{
|
||||
/// <summary>
|
||||
/// 区域
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "area")]
|
||||
[JsonPropertyName("area")]
|
||||
public string? Area { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报警编号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "err_no")]
|
||||
[JsonPropertyName("errNo")]
|
||||
public int? ErrNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "equipment_id")]
|
||||
[JsonPropertyName("equipmentId")]
|
||||
public string? EquipmentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "create_time")]
|
||||
[JsonPropertyName("createTime")]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报警类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "err_type")]
|
||||
[JsonPropertyName("errType")]
|
||||
public string? ErrType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报警信息
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "err_msg")]
|
||||
[JsonPropertyName("errMsg")]
|
||||
public string? ErrMsg { get; set; }
|
||||
}
|
||||
|
|
@ -8,13 +8,13 @@
|
|||
"AllowedHosts": "*",
|
||||
"Settings": {
|
||||
"DBMysql": "server=10.90.36.71;port=3306;user=developer;password=developer;database=wcs_kate_suzhou;",
|
||||
"DBMysqlLocal": "server=192.168.234.134;port=3306;user=developer;password=developer;database=wcs_kate_suzhou;",
|
||||
"DBMysqlLocal": "server=192.168.3.254;port=3306;user=developer;password=developer;database=wcs_demo;",
|
||||
|
||||
"DBMssql": "Data Source=192.168.142.131;Initial Catalog=wcs;User Id=sa;Password=Sa123;",
|
||||
"DBMssqlLocal": "Data Source=192.168.142.131;Initial Catalog=wcs_stacker;User Id=sa;Password=Sa123;",
|
||||
|
||||
"ApplicationConfig": {
|
||||
"ApiOnly": false,
|
||||
"ApiOnly": true,
|
||||
"Language": "zh-CN"
|
||||
},
|
||||
"UseUrls": [ "http://*:18990" ]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user