|
|
|
@ -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("删除失败");
|
|
|
|
|
}
|
|
|
|
|
}
|