diff --git a/WcsMain/ApiServe/Controllers/BoardController/Board2Controller.cs b/WcsMain/ApiServe/Controllers/BoardController/Board2Controller.cs
new file mode 100644
index 0000000..1c79047
--- /dev/null
+++ b/WcsMain/ApiServe/Controllers/BoardController/Board2Controller.cs
@@ -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;
+
+
+///
+/// 二维大屏数据接口
+///
+[Route("api/board/board2")]
+[ApiController]
+public class Board2Controller(Board2Service board2Service) : ControllerBase
+{
+ ///
+ /// 获取堆垛机运行效率
+ ///
+ ///
+ [HttpGet("getStackerRunningEfficiency")]
+ public StackerRunningEfficiencyResponse GetStackerRunningEfficiency() => board2Service.GetStackerRunningEfficiency();
+
+ ///
+ /// 根据堆垛机获取错误信息数量
+ ///
+ ///
+ [HttpGet("getErrByCrane")]
+ public List> GetErrByCrane() => board2Service.GetErrByCrane();
+
+ ///
+ /// 根据故障类型获取错误信息数量
+ ///
+ ///
+ [HttpGet("getErrByCategory")]
+ public List> GetErrByCategory() => board2Service.GetErrByCategory();
+
+ ///
+ /// 获取错误信息
+ ///
+ ///
+ [HttpGet("getErrInfo")]
+ public List GetErrInfo() => board2Service.GetErrInfo();
+
+ ///
+ /// 获取任务数量
+ ///
+ ///
+ [HttpGet("getTaskCount")]
+ public TaskCountResponse GetTaskCount() => board2Service.GetTaskCount();
+
+
+}
diff --git a/WcsMain/ApiServe/Service/BoardService/Board2Service.cs b/WcsMain/ApiServe/Service/BoardService/Board2Service.cs
new file mode 100644
index 0000000..9bb2515
--- /dev/null
+++ b/WcsMain/ApiServe/Service/BoardService/Board2Service.cs
@@ -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;
+
+///
+/// 二维大屏 controller service
+///
+[Service]
+public class Board2Service(AppWmsTaskDao wmsTaskDao, AppErrRecorDao appErrRecorDao)
+{
+
+ //private List? _appBaseErrs;
+
+ ///
+ /// 获取堆垛机运行效率
+ ///
+ ///
+ public StackerRunningEfficiencyResponse GetStackerRunningEfficiency()
+ {
+ int[] data = [0, 0, 0, 0, 0];
+ if (CommonData.AppLocations == null)
+ {
+ return new StackerRunningEfficiencyResponse() { Data = data };
+ }
+ List? 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 };
+ }
+
+ ///
+ /// 根据堆垛机获取错误信息数量
+ ///
+ ///
+ public List> GetErrByCrane()
+ {
+ List? appErrorRecordJoins = appErrRecorDao.SelectErrorRecordWithJoin();
+ if(appErrorRecordJoins == null)
+ {
+ return [];
+ }
+ List names = [];
+ foreach (var appErrorRecordJoin in appErrorRecordJoins)
+ {
+ if (!names.Contains(appErrorRecordJoin.EquipmentId!))
+ {
+ names.Add(appErrorRecordJoin.EquipmentId!);
+ }
+ }
+ List counts = [];
+ foreach (var name in names)
+ {
+ int count = appErrorRecordJoins.FindAll(f => f.EquipmentId == name).Count;
+ counts.Add(count);
+ }
+ List> nameValueDatas = [];
+ for (int i = 0; i < names.Count; i++)
+ {
+ nameValueDatas.Add(new NameValueData() { Name = string.Concat("#", names[i].AsSpan(names[i].Length - 1, 1)), Value = counts[i] });
+ }
+ return nameValueDatas;
+ }
+
+ ///
+ /// 根据故障类型获取错误信息数量
+ ///
+ ///
+ public List> GetErrByCategory()
+ {
+ List? appErrorRecordJoins = appErrRecorDao.SelectErrorRecordWithJoin();
+ if (appErrorRecordJoins == null)
+ {
+ return [];
+ }
+ List names = [];
+ foreach (var appErrorRecordJoin in appErrorRecordJoins)
+ {
+ if (!names.Contains(appErrorRecordJoin.ErrType!))
+ {
+ names.Add(appErrorRecordJoin.ErrType!);
+ }
+ }
+ List counts = [];
+ foreach (var name in names)
+ {
+ int count = appErrorRecordJoins.FindAll(f => f.ErrType == name).Count;
+ counts.Add(count);
+ }
+ List> nameValueDatas = [];
+ for (int i = 0; i < names.Count; i++)
+ {
+ nameValueDatas.Add(new NameValueData() { Name = names[i], Value = counts[i] });
+ }
+ return nameValueDatas;
+ }
+
+ ///
+ /// 获取错误信息
+ ///
+ ///
+ public List GetErrInfo()
+ {
+ List? appErrorRecordJoins = appErrRecorDao.SelectErrorRecordWithJoin();
+ if (appErrorRecordJoins == null)
+ {
+ return [];
+ }
+ List errors = new List();
+ 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;
+ }
+
+ ///
+ /// 获取任务数量
+ ///
+ ///
+ public TaskCountResponse GetTaskCount()
+ {
+ List? 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;
+ }
+
+
+}
diff --git a/WcsMain/ApiServe/Vo/Board/ErrorDetail.cs b/WcsMain/ApiServe/Vo/Board/ErrorDetail.cs
new file mode 100644
index 0000000..f66eb31
--- /dev/null
+++ b/WcsMain/ApiServe/Vo/Board/ErrorDetail.cs
@@ -0,0 +1,32 @@
+using Newtonsoft.Json;
+using System.Text.Json.Serialization;
+
+namespace WcsMain.ApiServe.Vo.Board;
+
+public class ErrorDetail
+{
+ ///
+ /// 时间
+ ///
+ [JsonPropertyName("time")]
+ public string? Time { get; set; }
+
+ ///
+ /// 设备名称
+ ///
+ [JsonPropertyName("material")]
+ public string? Material { get; set; }
+
+ ///
+ /// 故障信息
+ ///
+ [JsonPropertyName("faultName")]
+ public string? FaultName { get; set; }
+
+ ///
+ /// 故障代码
+ ///
+ [JsonPropertyName("faultCode")]
+ public string? FaultCode { get; set; }
+
+}
diff --git a/WcsMain/ApiServe/Vo/Board/NameValueData.cs b/WcsMain/ApiServe/Vo/Board/NameValueData.cs
new file mode 100644
index 0000000..d2d5afd
--- /dev/null
+++ b/WcsMain/ApiServe/Vo/Board/NameValueData.cs
@@ -0,0 +1,17 @@
+using Newtonsoft.Json;
+using System.Text.Json.Serialization;
+
+namespace WcsMain.ApiServe.Vo.Board;
+
+///
+/// 键值对数据
+///
+public class NameValueData
+{
+ [JsonPropertyName("name")]
+ public string? Name { get; set; }
+
+ [JsonPropertyName("value")]
+ public T? Value { get; set; }
+
+}
diff --git a/WcsMain/ApiServe/Vo/Board/StackerRunningEfficiencyResponse.cs b/WcsMain/ApiServe/Vo/Board/StackerRunningEfficiencyResponse.cs
new file mode 100644
index 0000000..92c34a6
--- /dev/null
+++ b/WcsMain/ApiServe/Vo/Board/StackerRunningEfficiencyResponse.cs
@@ -0,0 +1,17 @@
+using Newtonsoft.Json;
+using System.Text.Json.Serialization;
+
+namespace WcsMain.ApiServe.Vo.Board;
+
+///
+/// 堆垛机效率返回类
+///
+public class StackerRunningEfficiencyResponse
+{
+ ///
+ /// 效率
+ ///
+ [JsonPropertyName("data")]
+ public int[]? Data { get; set; }
+
+}
diff --git a/WcsMain/ApiServe/Vo/Board/TaskCountResponse.cs b/WcsMain/ApiServe/Vo/Board/TaskCountResponse.cs
new file mode 100644
index 0000000..e1ea450
--- /dev/null
+++ b/WcsMain/ApiServe/Vo/Board/TaskCountResponse.cs
@@ -0,0 +1,17 @@
+using Newtonsoft.Json;
+using System.Text.Json.Serialization;
+
+namespace WcsMain.ApiServe.Vo.Board;
+
+public class TaskCountResponse
+{
+ [JsonPropertyName("date")]
+ public List? Date { get; set; }
+
+ [JsonPropertyName("in")]
+ public List? In { get; set; }
+
+ [JsonPropertyName("out")]
+ public List? Out { get; set; }
+
+}
diff --git a/WcsMain/DataBase/Dao/AppErrRecorDao.cs b/WcsMain/DataBase/Dao/AppErrRecorDao.cs
index 6b30911..9afb6d1 100644
--- a/WcsMain/DataBase/Dao/AppErrRecorDao.cs
+++ b/WcsMain/DataBase/Dao/AppErrRecorDao.cs
@@ -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
}
}
+ ///
+ /// 查询所有数据
+ ///
+ ///
+ public List? Query()
+ {
+ try
+ {
+ var sqlFuc = CommonTool.DbServe.Queryable();
+ return sqlFuc.ToList();
+ }
+ catch (Exception ex)
+ {
+ _ = ex;
+ return null;
+ }
+ }
+
+ ///
+ /// 查询指定条数的数据
+ ///
+ ///
+ ///
+ public List? Query(int count)
+ {
+ if(count < 1) return null;
+ try
+ {
+ var sqlFuc = CommonTool.DbServe.Queryable().Take(count);
+ return sqlFuc.ToList();
+ }
+ catch (Exception ex)
+ {
+ _ = ex;
+ return null;
+ }
+ }
+
+ ///
+ /// 查询最近一个月的故障列表
+ ///
+ ///
+ public List? SelectErrorRecordWithJoin()
+ {
+ try
+ {
+ var sqlFuc = CommonTool.DbServe.Queryable()
+ .LeftJoin((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;
+ }
+ }
+
+
+
+
}
diff --git a/WcsMain/DataBase/Dao/AppWmsTaskDao.cs b/WcsMain/DataBase/Dao/AppWmsTaskDao.cs
index 17d9322..0f453db 100644
--- a/WcsMain/DataBase/Dao/AppWmsTaskDao.cs
+++ b/WcsMain/DataBase/Dao/AppWmsTaskDao.cs
@@ -261,6 +261,49 @@ public class AppWmsTaskDao
}
}
+ ///
+ /// 获取最近一个小时的任务
+ ///
+ ///
+ public List? SelectRecentOneHour()
+ {
+ try
+ {
+ var sqlFuc = CommonTool.DbServe.Queryable()
+ .Where(w => w.CreateTime> DateTime.Now.AddHours(-1))
+ .ToList();
+ return sqlFuc;
+ }
+ catch (Exception ex)
+ {
+ _ = ex;
+ return default;
+ }
+ }
+
+ ///
+ /// 获取最近几天的任务
+ ///
+ ///
+ ///
+ public List? SelectRecenntDay(int days)
+ {
+ try
+ {
+ var sqlFuc = CommonTool.DbServe.Queryable()
+ .Where(w => w.CreateTime > DateTime.Now.AddDays(-days))
+ .OrderBy(o => o.CreateTime)
+ .ToList();
+ return sqlFuc;
+ }
+ catch (Exception ex)
+ {
+ _ = ex;
+ return default;
+ }
+ }
+
+
///
/// 重置任务状态
///
diff --git a/WcsMain/DataBase/JoinTableEntity/AppErrorRecordJoin.cs b/WcsMain/DataBase/JoinTableEntity/AppErrorRecordJoin.cs
new file mode 100644
index 0000000..359d822
--- /dev/null
+++ b/WcsMain/DataBase/JoinTableEntity/AppErrorRecordJoin.cs
@@ -0,0 +1,52 @@
+using SqlSugar;
+using System.Text.Json.Serialization;
+
+namespace WcsMain.DataBase.JoinTableEntity;
+
+///
+/// 报警信息联表查询
+///
+public class AppErrorRecordJoin
+{
+ ///
+ /// 区域
+ ///
+ [SugarColumn(ColumnName = "area")]
+ [JsonPropertyName("area")]
+ public string? Area { get; set; }
+
+ ///
+ /// 报警编号
+ ///
+ [SugarColumn(ColumnName = "err_no")]
+ [JsonPropertyName("errNo")]
+ public int? ErrNo { get; set; }
+
+ ///
+ /// 设备号
+ ///
+ [SugarColumn(ColumnName = "equipment_id")]
+ [JsonPropertyName("equipmentId")]
+ public string? EquipmentId { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnName = "create_time")]
+ [JsonPropertyName("createTime")]
+ public DateTime? CreateTime { get; set; }
+
+ ///
+ /// 报警类型
+ ///
+ [SugarColumn(ColumnName = "err_type")]
+ [JsonPropertyName("errType")]
+ public string? ErrType { get; set; }
+
+ ///
+ /// 报警信息
+ ///
+ [SugarColumn(ColumnName = "err_msg")]
+ [JsonPropertyName("errMsg")]
+ public string? ErrMsg { get; set; }
+}
diff --git a/WcsMain/appsettings.json b/WcsMain/appsettings.json
index cc39f90..b733ed3 100644
--- a/WcsMain/appsettings.json
+++ b/WcsMain/appsettings.json
@@ -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" ]