故障列表显示及更新

master
CZ 3 months ago
parent b21150ee0a
commit 2a83e3d3c7

@ -0,0 +1,55 @@
using HybirdFrameworkCore.Entity;
namespace Entity.Api.Req;
public class EquipAlarmDefineReq: QueryPageModel
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
public int? Id { get; set; }
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
public string? EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
public string? ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
public string? ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
public string? ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
public string? ProcessMethod { get; set; }
}

@ -0,0 +1,56 @@
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
namespace Entity.Dto;
[ExcelExporter(Name = "设备报警基础信息", TableStyle = OfficeOpenXml.Table.TableStyles.None, AutoFitAllColumn = true)]
public class EquipAlarmDefineDto
{
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "设备类型编码", IsBold = true)]
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "设备编码", IsBold = true)]
public string EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警编码", IsBold = true)]
public string ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警等级", IsBold = true)]
public string ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警描述", IsBold = true)]
public string ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "处理方法", IsBold = true)]
public string ProcessMethod { get; set; }
}

@ -0,0 +1,220 @@
using AutoMapper;
using Entity.Api.Req;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Utils;
using Magicodes.ExporterAndImporter.Excel;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using SqlSugar;
namespace Service.Station;
[Scope("SingleInstance")]
public class EquipAlarmDefineService: BaseServices<EquipAlarmDefine>
{
EquipAlarmDefineRepository _elecPriceModelVersionRepository;
public EquipAlarmDefineService(EquipAlarmDefineRepository dal)
{
_elecPriceModelVersionRepository = dal;
BaseDal = dal;
}
/// <summary>
/// 查询未处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc<</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
public Result<PageResult<EquipAlarmDefine>> QueryEquipAlarmPage(EquipAlarmDefineReq req)
{
int totalCount = 0;
int EquipTypeCode = req.EquipTypeCode;
string EquipCode = req.EquipCode;
string ErrorCode = req.ErrorCode;
string ErrorLevel = req.ErrorLevel;
string ErrorMsg = req.ErrorMsg;
string ProcessMethod = req.ProcessMethod;
List<EquipAlarmDefine> list = BaseDal.Queryable()
.WhereIF(EquipTypeCode != -1, it => it.EquipTypeCode == EquipTypeCode)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(EquipCode), it => it.EquipCode == EquipCode)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(ErrorLevel), it => it.ErrorLevel == ErrorLevel)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(ErrorMsg), it => it.ErrorMsg.Contains(ErrorMsg))
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(ProcessMethod), it => it.ProcessMethod.Contains(ProcessMethod))
.ToList(); // 注意:这里添加了 ToList() 来确保执行查询
PageResult<EquipAlarmDefine> result = new PageResult<EquipAlarmDefine>()
{
PageNum = req.PageNum,
PageSize = req.PageSize,
ToTal = totalCount,
Rows = list
};
return Result<PageResult<EquipAlarmDefine>>.Success(result);
}
/// <summary>
/// 导出
/// </summary>
/// <returns></returns>
public async Task<IActionResult> ExportEquipAlarmRecord()
{
List<EquipAlarmDefine> equipAlarmRecords = await BaseDal.QueryAsync();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EquipAlarmDefineDto, EquipAlarmDefine>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<EquipAlarmDefineDto> logExList = mapper.Map<List<EquipAlarmDefineDto>>(equipAlarmRecords);
IExcelExporter excelExporter = new ExcelExporter();
var res = await excelExporter.ExportAsByteArray(logExList);
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "设备报警基础信息.xlsx" };
}
/// <summary>
/// 新增
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public async Task<Result<string>> Add([FromBody] EquipAlarmDefineReq req)
{
if (req.EquipCode == null)
{
return Result<string>.Fail("设备类型编码不能为空");
}
if (req.ErrorCode == null)
{
return Result<string>.Fail("报警编码不能为空");
}
if (req.ErrorLevel == null)
{
return Result<string>.Fail("报警等级不能为空");
}
if (req.ErrorMsg == null)
{
return Result<string>.Fail("报警描述不能为空");
}
var equipAlarmDefineTask =
BaseDal.QueryByClauseAsync(u =>
u.EquipTypeCode == req.EquipTypeCode && u.EquipCode == req.EquipCode && u.ErrorCode == req.ErrorCode &&
u.ErrorLevel == req.ErrorLevel);
await Task.WhenAll(equipAlarmDefineTask);
var isExist = equipAlarmDefineTask.Result;
if (isExist != null)
{
return Result<string>.Fail("已存在同名或同编码设备信息");
}
var equipInfo = req.Adapt<EquipAlarmDefine>();
var insertEquipInfoTask = BaseDal.InsertAsync(equipInfo);
await Task.WhenAll(insertEquipInfoTask);
var insertAsync = insertEquipInfoTask.Result;
if (insertAsync.Id > 0)
{
return Result<string>.Success("新增id" + insertAsync.Id);
}
return Result<string>.Fail("新增失败");
}
/// <summary>
/// 修改报警数据编码
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public async Task<Result<string>> Modify([FromBody] EquipAlarmDefineReq req)
{
// 查询 EquipInfo
var equipInfo = await BaseDal.QueryByClauseAsync(u => u.Id == req.Id);
if (equipInfo == null)
{
return Result<string>.Fail("id不存在");
}
if (req.EquipCode == null)
{
return Result<string>.Fail("设备类型编码不能为空");
}
if (req.ErrorCode == null)
{
return Result<string>.Fail("报警编码不能为空");
}
if (req.ErrorLevel == null)
{
return Result<string>.Fail("报警等级不能为空");
}
if (req.ErrorMsg == null)
{
return Result<string>.Fail("报警描述不能为空");
}
//判断是否重复
var equipAlarmDefineTask =
BaseDal.QueryByClauseAsync(u =>
u.EquipTypeCode == req.EquipTypeCode && u.EquipCode == req.EquipCode && u.ErrorCode == req.ErrorCode &&
u.ErrorLevel == req.ErrorLevel);
await Task.WhenAll(equipAlarmDefineTask);
var insertAsync = equipAlarmDefineTask.Result;
if (insertAsync.Id > 0)
{
return Result<string>.Success("新增id" + insertAsync.Id);
}
return Result<string>.Fail("修改失败");
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids">ids id列表</param>
/// <returns></returns>
[HttpPost("DeleteByIds")]
public async Task<Result<string>> DeleteByIds([FromBody] EquipAlarmDefineReq req)
{
// 查询 EquipInfo
var equipInfo = await BaseDal.QueryByClauseAsync(u => u.Id == req.Id);
if (equipInfo == null)
{
return Result<string>.Fail("id不存在");
}
// 查询 EquipNetInfo
var equipNetInfo = await BaseDal.QueryByClauseAsync(u => u.EquipCode == equipInfo.EquipCode);
if (equipNetInfo == null)
{
return Result<string>.Fail("不存在此编码");
}
var deleteEquipInfoTask = BaseDal.DeleteAsync(equipInfo);
await Task.WhenAll(deleteEquipInfoTask);
var deleteResult = deleteEquipInfoTask.Result;
if (deleteResult)
{
return Result<string>.Success("删除成功");
}
return Result<string>.Fail("删除失败");
}
}

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
namespace WebStarter.Controllers;
/// <summary>
/// 电池数据显示
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class BatteryController: ControllerBase
{
}

@ -0,0 +1,82 @@
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using log4net;
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using Service.Station;
namespace WebStarter.Controllers;
/// <summary>
/// 报警数据编码
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class EquipAlarmDefineController: ControllerBase
{
private static readonly ILog Log = LogManager.GetLogger(typeof(EquipAlarmDefineController));
private readonly EquipAlarmDefineService equipAlarmDefineRepository;
public EquipAlarmDefineController(EquipAlarmDefineService equipAlarmDefineRepository)
{
this.equipAlarmDefineRepository = equipAlarmDefineRepository;
}
/// <summary>
/// 查询分页数据
/// </summary>
/// <returns></returns>
[HttpPost("QueryPage")]
public Result<PageResult<EquipAlarmDefine>> QueryPage([FromBody] EquipAlarmDefineReq req)
{
return equipAlarmDefineRepository.QueryEquipAlarmPage(req);
}
/// <summary>
/// 导出未处理报警
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("ExportEquipAlarmRecord")]
public async Task<IActionResult> ExportEquipAlarmRecord()
{
return await equipAlarmDefineRepository.ExportEquipAlarmRecord();
}
/// <summary>
/// 新增
/// </summary>
/// <returns></returns>
[HttpPost("Add")]
public async Task<Result<string>> Add([FromBody] EquipAlarmDefineReq req)
{
return await equipAlarmDefineRepository.Add(req);
}
/// <summary>
/// 修改报警数据编码
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost("Modify")]
public async Task<Result<string>> Modify([FromBody] EquipAlarmDefineReq req)
{
return await equipAlarmDefineRepository.Modify(req);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids">ids id列表</param>
/// <returns></returns>
[HttpPost("DeleteByIds")]
public async Task<Result<string>> DeleteByIds([FromBody] EquipAlarmDefineReq req)
{
return await equipAlarmDefineRepository.DeleteByIds(req);
}
}
Loading…
Cancel
Save