语音播报中跟失败有关的语音入库,以及 页面故障的导入(功能待完善) 导出(待测试) 模糊查询(待测试)显示故障(待测试)

master
lch 3 months ago
parent 2a6f3b5623
commit 92f3b60bf0

@ -0,0 +1,29 @@
namespace Entity.Api.Req;
public class AddEquipAlarmInfoReq
{
/// <summary>
/// 设备类型编码
/// </summary>
public int EquipTypeCode { get; set; }
/// <summary>
/// 设备编码
/// </summary>
public string EquipCode { get; set; }
/// <summary>
/// 报警编码
/// </summary>
public string ErrorCode { get; set; }
/// <summary>
/// 报警等级
/// </summary>
public string ErrorLevel { get; set; }
/// <summary>
/// 报警描述
/// </summary>
public string ErrorMsg { get; set; }
/// <summary>
/// 处理方法
/// </summary>
public string ProcessMethod { get; set; }
}

@ -0,0 +1,23 @@
using SqlSugar;
namespace Entity.DbModel.Station;
/// <summary>
/// 系统运行时故障记录
/// </summary>
[SugarTable("sys_running_falut")]
public class SysRunningFault: BaseModel
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// 故障描述
/// </summary>
[SugarColumn(ColumnName = "fault_describe")]
public string? FaultDescribe { get; set; }
/// <summary>
/// 故障发生时间
/// </summary>
[SugarColumn(ColumnName = "falust_happen_time")]
public DateTime? FalustHappenTime { get; set; }
}

@ -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<SysRunningFault>
{
public SysRunningFaultRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -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<SysRunningFaultService>();
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<InfoEnum.SwapInfo>(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,
});
}
}
}
}

@ -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<EquipAlarmDefine>
{
EquipAlarmDefineRepository _equipAlarmDefineRepository;
public EquipAlarmDefineService(EquipAlarmDefineRepository dal)
{
_equipAlarmDefineRepository = dal;
BaseDal = dal;
}
/// <summary>
/// 添加设备报警基础信息
/// </summary>
/// <returns></returns>
public async Task<Result<string>> 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<string>.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<string>.Success(req.EquipCode + "成功添加" + req.ErrorCode + "设备报警基础信息");
}
/// <summary>
/// 模糊查询
/// </summary>
/// <param name="keyValue">查询关键字</param>
/// <returns></returns>
public async Task<Result<PageResult<EquipAlarmDefine>>> VagueQueryResult(int pageSize, string keyValue)
{
PageResult<EquipAlarmDefine> result = new PageResult<EquipAlarmDefine>();
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<PageResult<EquipAlarmDefine>>.Success(result);
}
return Result<PageResult<EquipAlarmDefine>>.Fail(result);
}
public async Task<List<EquipAlarmDefine>> QueryAllEquipAlarm()
{
return await _equipAlarmDefineRepository.QueryListByClauseAsync(null);
}
}

@ -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<SysRunningFault>
{
private SysRunningFaultRepository _sysRunningFaultRep;
public SysRunningFaultService(SysRunningFaultRepository sysRunningFaultRep)
{
_sysRunningFaultRep = sysRunningFaultRep;
this.BaseDal = sysRunningFaultRep;
}
/// <summary>
/// 获取系统运行时故障信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PageResult<SysRunningFault>> Page(int pageSize)
{
PageResult<SysRunningFault> pageResult = new PageResult<SysRunningFault>();
List<SysRunningFault> 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;
}
}

@ -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;
}
/// <summary>
/// 导出
/// </summary>
/// <returns></returns>
[HttpPost("export")]
public async Task<IActionResult> ExportSwapOrder()
{
List<EquipAlarmDefine> 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" };
}
/// <summary>
/// 文件导入
/// </summary>
/// <param name="filePath">文件路径</param>
[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<string> rowNames = new List<string>();
// 遍历第一行的所有单元格
// 注意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::数据入库
}
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids">ids id列表</param>
/// <returns></returns>
[HttpPost("DeleteByIds")]
public async Task<Result<bool>> DeleteByIds([FromBody] List<long> ids)
{
if (_equipAlarmDefineService.DeleteByIds(ids))
{
return Result<bool>.Success(true, "删除成功");
}
else
{
return Result<bool>.Fail("删除失败");
}
}
/// <summary>
/// 新增
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost("Add")]
public async Task<Result<string>> Add([FromBody] AddEquipAlarmInfoReq req)
{
return await _equipAlarmDefineService.NewAddEquipAlarm(req);
}
/// <summary>
/// 查询所有设备报警基础信息
/// </summary>
/// <param name="pageSize"></param>
/// <returns></returns>
[HttpPost("QueryPage/{pageSize}")]
public async Task<Result<PageResult<EquipAlarmDefine>>> QueryPage(int pageSize)
{
return await _equipAlarmDefineService.VagueQueryResult(pageSize, null);
}
/// <summary>
/// 模糊查询 设备报警基础信息
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost("VagueQueryPage/{pageSize}/{keyValue}")]
public async Task<Result<PageResult<EquipAlarmDefine>>> QueryPage(int pageSize, string keyValue)
{
return await _equipAlarmDefineService.VagueQueryResult(pageSize, keyValue);
}
}

@ -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;
}
/// <summary>
/// 查询系统设备运行时故障
/// </summary>
/// <param name="inputPage">每页显示多少条</param>
/// <returns></returns>
[HttpPost]
[Route("page")]
public async Task<Result<PageResult<SysRunningFault>>> Page(int inputPage)
{
return Result<PageResult<SysRunningFault>>.Success(await _sysRunningFaultService.Page(inputPage));
}
}
Loading…
Cancel
Save