using AutoMapper;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Station;
namespace WebStarter.Controllers;
///
/// 换电设备报警等级
///
[ApiController]
[Route("api/[controller]")]
public class EquipAlarmLevelController : ControllerBase
{
private readonly EquipAlarmLevelService equipAlarmLevelService;
public EquipAlarmLevelController(EquipAlarmLevelService equipAlarmLevelService)
{
this.equipAlarmLevelService = equipAlarmLevelService;
}
///
/// 查询故障等级信息
///
/// 查询参数
///
[HttpPost]
[Route("QueryEquipAlarmLevel")]
public Result> QueryEquipAlarmLevel([FromBody] QueryEquipAlarmLevelReq eqmFaultLevelReq)
{
return Result>.Success(equipAlarmLevelService.QueryEqmFaultInfo(eqmFaultLevelReq));
}
///
/// 添加故障等级信息
///
/// 添加参数
///
[HttpPost]
[Route("AddEquipAlarmLevel")]
public Result AddEquipAlarmLevel([FromBody] AddEquipAlarmLevelReq eqmFaultLevelReq)
{
//映射数据
var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap());
IMapper mapper = config.CreateMapper();
EquipAlarmLevel baseEqmFaultLevel = mapper.Map(eqmFaultLevelReq);
//TODO Id换成等级字段
var eqmFaultLevel = equipAlarmLevelService.QueryByClause(u => u.Id == eqmFaultLevelReq.Id);
if (eqmFaultLevel!=null)
{
return Result.Fail("插入失败!已有改等级信息");
}
else
{
// 更改
if (equipAlarmLevelService.Insert(baseEqmFaultLevel) != 0)
{
return Result.Success("插入成功");
}
else
{
return Result.Fail("插入失败");
}
}
}
///
/// 更改故障等级信息
///
/// 更改信息
///
[HttpPost]
[Route("ModifyEquipAlarmLevel")]
public Result ModifyEquipAlarmLevel([FromBody] ModifyEquipAlarmLevelReq eqmFaultLevelReq)
{
var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap());
IMapper mapper = config.CreateMapper();
EquipAlarmLevel baseEqmFaultLevel = mapper.Map(eqmFaultLevelReq);
if (equipAlarmLevelService.Update(baseEqmFaultLevel))
{
return Result.Success("更改成功");
}
else
{
return Result.Fail("更改失败");
}
}
///
/// 删除故障等级信息
///
/// 自增id数组
///
[HttpPost]
[Route("RemoveEquipAlarmLevel")]
public Result RemoveEquipAlarmLevel([FromBody] int[] ids)
{
if (equipAlarmLevelService.DeleteByIds(ids))
{
return Result.Success("删除成功");
}
else
{
return Result.Fail("删除失败");
}
}
}