diff --git a/Entity/Api/Req/AddEquipAlarmInfoReq.cs b/Entity/Api/Req/AddEquipAlarmInfoReq.cs
new file mode 100644
index 0000000..a13f2bb
--- /dev/null
+++ b/Entity/Api/Req/AddEquipAlarmInfoReq.cs
@@ -0,0 +1,29 @@
+namespace Entity.Api.Req;
+
+public class AddEquipAlarmInfoReq
+{
+ ///
+ /// 设备类型编码
+ ///
+ public int EquipTypeCode { get; set; }
+ ///
+ /// 设备编码
+ ///
+ public string EquipCode { get; set; }
+ ///
+ /// 报警编码
+ ///
+ public string ErrorCode { get; set; }
+ ///
+ /// 报警等级
+ ///
+ public string ErrorLevel { get; set; }
+ ///
+ /// 报警描述
+ ///
+ public string ErrorMsg { get; set; }
+ ///
+ /// 处理方法
+ ///
+ public string ProcessMethod { get; set; }
+}
\ No newline at end of file
diff --git a/Entity/DbModel/Station/SysRunningFault.cs b/Entity/DbModel/Station/SysRunningFault.cs
new file mode 100644
index 0000000..bb4a1a5
--- /dev/null
+++ b/Entity/DbModel/Station/SysRunningFault.cs
@@ -0,0 +1,23 @@
+using SqlSugar;
+
+namespace Entity.DbModel.Station;
+
+///
+/// 系统运行时故障记录
+///
+[SugarTable("sys_running_falut")]
+public class SysRunningFault: BaseModel
+{
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
+ public int Id { get; set; }
+ ///
+ /// 故障描述
+ ///
+ [SugarColumn(ColumnName = "fault_describe")]
+ public string? FaultDescribe { get; set; }
+ ///
+ /// 故障发生时间
+ ///
+ [SugarColumn(ColumnName = "falust_happen_time")]
+ public DateTime? FalustHappenTime { get; set; }
+}
\ No newline at end of file
diff --git a/Repository/Station/SysRunningFaultRepository.cs b/Repository/Station/SysRunningFaultRepository.cs
new file mode 100644
index 0000000..be7439e
--- /dev/null
+++ b/Repository/Station/SysRunningFaultRepository.cs
@@ -0,0 +1,16 @@
+using System.Linq.Expressions;
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac.Attribute;
+using HybirdFrameworkCore.Entity;
+using SqlSugar;
+
+
+namespace Repository.Station;
+
+[Scope("SingleInstance")]
+public class SysRunningFaultRepository: BaseRepository
+{
+ public SysRunningFaultRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
+ {
+ }
+}
\ No newline at end of file
diff --git a/Service/Execute/Api/SoundApi.cs b/Service/Execute/Api/SoundApi.cs
index 21520fc..b11f8ab 100644
--- a/Service/Execute/Api/SoundApi.cs
+++ b/Service/Execute/Api/SoundApi.cs
@@ -1,4 +1,10 @@
+using Autofac;
+using Entity.Attr;
+using Entity.Constant;
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac;
using log4net;
+using Service.Station;
namespace Service.Execute.Api;
@@ -6,14 +12,18 @@ public class SoundApi
{
private static readonly string BASE_URL = "http://localhost:5038";
private static readonly ILog Log = LogManager.GetLogger("SoundApi");
-
+
+ static SysRunningFaultService sysRunningFaultService = AppInfo.Container.Resolve();
+
private static readonly HttpClient _httpClient = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(5)
};
+
public static void PlayOneSound(int soundNo)
{
+ SaveSysRunningFault(soundNo);
string url = BASE_URL + "/Api/PlayOneSound?soundcode=" + soundNo;
try
{
@@ -24,4 +34,22 @@ public class SoundApi
Log.Error($" SoundApi PlayOneSound e = {e}");
}
}
+
+ private static void SaveSysRunningFault(int soundNo)
+ {
+ if (Enum.TryParse(soundNo.ToString(), out InfoEnum.SwapInfo enumMember))
+ {
+ string soundContent= InfoExtend.GetSound(enumMember);
+ if (InfoExtend.GetSound(enumMember).Contains("失败")||InfoExtend.GetLed(enumMember).Contains("失败"))
+ {
+ sysRunningFaultService.InsertAsync(new SysRunningFault()
+ {
+ FaultDescribe=soundContent,
+ FalustHappenTime=DateTime.Now,
+ });
+ }
+ }
+ }
+
+
}
\ No newline at end of file
diff --git a/Service/Station/EquipAlarmDefineService.cs b/Service/Station/EquipAlarmDefineService.cs
new file mode 100644
index 0000000..778abba
--- /dev/null
+++ b/Service/Station/EquipAlarmDefineService.cs
@@ -0,0 +1,81 @@
+using Entity.Api.Req;
+using Entity.Constant;
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac.Attribute;
+using HybirdFrameworkCore.Entity;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using Repository.Station;
+
+namespace Service.Station;
+
+[Scope("SingleInstance")]
+public class EquipAlarmDefineService : BaseServices
+{
+ EquipAlarmDefineRepository _equipAlarmDefineRepository;
+
+ public EquipAlarmDefineService(EquipAlarmDefineRepository dal)
+ {
+ _equipAlarmDefineRepository = dal;
+ BaseDal = dal;
+ }
+
+ ///
+ /// 添加设备报警基础信息
+ ///
+ ///
+ public async Task> NewAddEquipAlarm(AddEquipAlarmInfoReq req)
+ {
+ var queryByClauseAsync = _equipAlarmDefineRepository.QueryByClauseAsync(
+ i => i.EquipCode == req.EquipCode && i.ErrorCode == req.ErrorCode);
+ var isExist = queryByClauseAsync.Result;
+ if (isExist != null)
+ {
+ return Result.Fail("已存在同名或同编码设备报警基础信息");
+ }
+
+ _equipAlarmDefineRepository.InsertAsync(new EquipAlarmDefine()
+ {
+ EquipTypeCode = req.EquipTypeCode,
+ EquipCode = req.EquipCode,
+ ErrorCode = req.ErrorCode,
+ ErrorLevel = req.ErrorLevel,
+ ErrorMsg = req.ErrorMsg,
+ ProcessMethod = req.ProcessMethod
+ });
+ return Result.Success(req.EquipCode + "成功添加" + req.ErrorCode + "设备报警基础信息");
+ }
+
+ ///
+ /// 模糊查询
+ ///
+ /// 查询关键字
+ ///
+ public async Task>> VagueQueryResult(int pageSize, string keyValue)
+ {
+ PageResult result = new PageResult();
+
+ var queryListByClauseAsync =
+ _equipAlarmDefineRepository.QueryListByClauseAsync(!string.IsNullOrEmpty(keyValue)
+ ? i => i.ErrorMsg.Contains(keyValue)
+ : null);
+ var result1 = queryListByClauseAsync.Result;
+ if (result1.Count > 0)
+ {
+ result.PageNum = result1.Count / pageSize;
+ result.ToTal = result1.Count;
+ result.Rows = result1;
+ result.PageSize = pageSize;
+ return Result>.Success(result);
+ }
+
+ return Result>.Fail(result);
+ }
+
+ public async Task> QueryAllEquipAlarm()
+ {
+ return await _equipAlarmDefineRepository.QueryListByClauseAsync(null);
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/Service/Station/SysRunningFaultService.cs b/Service/Station/SysRunningFaultService.cs
new file mode 100644
index 0000000..937ef10
--- /dev/null
+++ b/Service/Station/SysRunningFaultService.cs
@@ -0,0 +1,55 @@
+using Entity.Ammeter;
+using Entity.DbModel;
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac.Attribute;
+using Repository.Ammeter;
+using Repository.Station;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using AutoMapper;
+using Entity.Dto.Req;
+using Entity.Dto.Resp;
+using HybirdFrameworkCore.Entity;
+using Mapster;
+using SqlSugar;
+
+namespace Service.Station;
+
+[Scope("SingleInstance")]
+public class SysRunningFaultService : BaseServices
+{
+ private SysRunningFaultRepository _sysRunningFaultRep;
+ public SysRunningFaultService(SysRunningFaultRepository sysRunningFaultRep)
+ {
+ _sysRunningFaultRep = sysRunningFaultRep;
+ this.BaseDal = sysRunningFaultRep;
+ }
+
+ ///
+ /// 获取系统运行时故障信息
+ ///
+ ///
+ ///
+ public async Task> Page(int pageSize)
+ {
+ PageResult pageResult = new PageResult();
+ List sysRunningFaultList = await _sysRunningFaultRep.QueryListByClauseAsync(i=>i.FaultDescribe!="");
+ if (sysRunningFaultList.Count > 0)
+ {
+ pageResult.PageNum = sysRunningFaultList.Count/pageSize+1;
+ pageResult.ToTal = sysRunningFaultList.Count;
+ pageResult.Rows = sysRunningFaultList;
+ }
+ else
+ {
+ pageResult.PageNum = 0;
+ pageResult.ToTal = 0;
+ }
+ pageResult.PageSize = pageSize;
+ return pageResult;
+ }
+
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/Test/EquipAlarmDefineController.cs b/WebStarter/Controllers/Test/EquipAlarmDefineController.cs
new file mode 100644
index 0000000..b56e263
--- /dev/null
+++ b/WebStarter/Controllers/Test/EquipAlarmDefineController.cs
@@ -0,0 +1,135 @@
+using System.Data;
+using Entity.Api.Req;
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Entity;
+using Microsoft.AspNetCore.Mvc;
+using log4net;
+using Service.Station;
+using Magicodes.ExporterAndImporter.Excel;
+using OfficeOpenXml;
+
+namespace WebStarter.Controllers.Test;
+
+[ApiController]
+[Route("api/[controller]")]
+public class EquipAlarmDefineController : ControllerBase
+{
+ private static readonly ILog Log = LogManager.GetLogger(typeof(EquipAlarmDefineController));
+ private readonly EquipAlarmDefineService _equipAlarmDefineService;
+
+ public EquipAlarmDefineController(EquipAlarmDefineService equipAlarmDefineService)
+ {
+ this._equipAlarmDefineService = equipAlarmDefineService;
+ }
+
+ ///
+ /// 导出
+ ///
+ ///
+ [HttpPost("export")]
+ public async Task ExportSwapOrder()
+ {
+ List list = await _equipAlarmDefineService.QueryAllEquipAlarm();
+ IExcelExporter excelExporter = new ExcelExporter();
+ var res = await excelExporter.ExportAsByteArray(list);
+ return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
+ { FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "设备报警基础信息.xlsx" };
+ }
+
+ ///
+ /// 文件导入
+ ///
+ /// 文件路径
+ [HttpPost("fileImport")]
+ public void ImportDataFromExcel(string filePath)
+ {
+ var fileInfo = new FileInfo(filePath);
+
+ using (var package = new ExcelPackage(fileInfo))
+ {
+ // 操作第一个工作表
+ ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
+ int rowCount = worksheet.Dimension.End.Row;
+ int colCount = worksheet.Dimension.End.Column;
+ DataTable dt = new DataTable();
+ // 初始化一个列表来存储第一行的所有名称
+ List rowNames = new List();
+ // 遍历第一行的所有单元格
+ // 注意:Excel的索引通常是从1开始的,所以第一行是1,第一列也是1
+ for (int col = 1; col <= worksheet.Dimension.End.Column; col++)
+ {
+ string cellValue = worksheet.Cells[1, col].Value?.ToString() ?? string.Empty;
+ rowNames.Add(cellValue);
+ }
+ for (int col = 1; col <= colCount; col++)
+ {
+ dt.Columns.Add(worksheet.Cells[1, col].Value.ToString());
+ }
+ // 跳过标题行,从第二行开始读取数据
+ for (int row = 2; row <= rowCount; row++)
+ {
+ DataRow dr = dt.NewRow();
+
+ for (int col = 1; col <= colCount; col++)
+ {
+ dr[col - 1] = worksheet.Cells[row, col].Value ?? DBNull.Value;
+ }
+
+ dt.Rows.Add(dr);
+ }
+ //TODO::数据入库
+ }
+ }
+
+
+ ///
+ /// 删除
+ ///
+ /// ids id列表
+ ///
+ [HttpPost("DeleteByIds")]
+ public async Task> DeleteByIds([FromBody] List ids)
+ {
+ if (_equipAlarmDefineService.DeleteByIds(ids))
+ {
+ return Result.Success(true, "删除成功");
+ }
+ else
+ {
+ return Result.Fail("删除失败");
+ }
+ }
+
+ ///
+ /// 新增
+ ///
+ ///
+ ///
+ [HttpPost("Add")]
+ public async Task> Add([FromBody] AddEquipAlarmInfoReq req)
+ {
+ return await _equipAlarmDefineService.NewAddEquipAlarm(req);
+ }
+
+ ///
+ /// 查询所有设备报警基础信息
+ ///
+ ///
+ ///
+ [HttpPost("QueryPage/{pageSize}")]
+ public async Task>> QueryPage(int pageSize)
+ {
+ return await _equipAlarmDefineService.VagueQueryResult(pageSize, null);
+ }
+
+ ///
+ /// 模糊查询 设备报警基础信息
+ ///
+ ///
+ ///
+ [HttpPost("VagueQueryPage/{pageSize}/{keyValue}")]
+ public async Task>> QueryPage(int pageSize, string keyValue)
+ {
+ return await _equipAlarmDefineService.VagueQueryResult(pageSize, keyValue);
+ }
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/Test/SysRunningFaultController.cs b/WebStarter/Controllers/Test/SysRunningFaultController.cs
new file mode 100644
index 0000000..c83757d
--- /dev/null
+++ b/WebStarter/Controllers/Test/SysRunningFaultController.cs
@@ -0,0 +1,34 @@
+using Entity.DbModel.Station;
+using Entity.Dto.Req;
+using Entity.Dto.Resp;
+using HybirdFrameworkCore.Entity;
+using Microsoft.AspNetCore.Mvc;
+using Service.Station;
+
+namespace WebStarter.Controllers.Test;
+
+[ApiController]
+[Route("api/[controller]")]
+public class SysRunningFaultController
+{
+ private readonly SysRunningFaultService _sysRunningFaultService;
+
+ public SysRunningFaultController(SysRunningFaultService sysRunningFaultService)
+ {
+ _sysRunningFaultService = sysRunningFaultService;
+ }
+
+
+ ///
+ /// 查询系统设备运行时故障
+ ///
+ /// 每页显示多少条
+ ///
+ [HttpPost]
+ [Route("page")]
+ public async Task>> Page(int inputPage)
+ {
+ return Result>.Success(await _sysRunningFaultService.Page(inputPage));
+ }
+
+}
\ No newline at end of file