namespace Yw.Application
{
///
/// PumpCurveExMapping
///
[Route("Curve/Pump/Mapping/Extension")]
[ApiDescriptionSettings("Curve", Name = "泵曲线映射拓展", Order = 8000)]
public partial class PumpCurveExMapping_Controller : IDynamicApiController
{
private readonly Service.PumpCurveExMapping _service = new();
#region Query
///
/// 通过 PumpID 获取
///
[Route("GetByPumpID@V1.0")]
[HttpGet]
public List GetByPumpID([FromQuery][Required] PumpIDInput input)
{
var list = _service.GetByPumpID(input.PumpID);
var vmList = list?.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
return vmList;
}
///
/// 通过 PumpIds 获取
///
[Route("GetByPumpIds@V1.0")]
[HttpGet]
public List GetByPumpIds([FromQuery][Required] PumpIdsInput input)
{
var ids = LongListHelper.ToList(input.PumpIds);
var list = _service.GetByPumpIds(ids);
var vmList = list?.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
return vmList;
}
///
/// 通过 ID 获取
///
[Route("GetByID@V1.0")]
[HttpGet]
public PumpCurveExMappingDto GetByID([FromQuery][Required] IDInput input)
{
var model = _service.GetByID(input.ID);
return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
}
///
/// 通过 Ids 获取
///
[Route("GetByIds@V1.0")]
[HttpGet]
public List GetByIds([FromQuery][Required] IdsInput input)
{
var ids = LongListHelper.ToList(input.Ids);
var list = _service.GetByIds(ids);
var vmList = list?.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
return vmList;
}
///
/// 通过 PumpID 获取工作曲线
///
[Route("GetWorkingByPumpID@V1.0")]
[HttpGet]
public PumpCurveExMappingDto GetWorkingByPumpID([FromQuery][Required] PumpIDInput input)
{
var model = _service.GetWorkingByPumpID(input.PumpID);
return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
}
///
/// 通过 PumpID 获取默认曲线
///
[Route("GetDefaultByPumpID@V1.0")]
[HttpGet]
public PumpCurveExMappingDto GetDefaultByPumpID([FromQuery][Required] PumpIDInput input)
{
var model = _service.GetDefaultByPumpID(input.PumpID);
return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
}
#endregion
#region Insert
///
/// 插入一条
///
[Route("Insert@V1.0")]
[HttpPost]
public long Insert([Required] AddPumpCurveExMappingInput input)
{
var curve = input.Adapt();
var mapping = input.Adapt();
mapping.SortCode = new Service.PumpCurveMapping().GetMaxSortCodeByPumpID(input.PumpID) + 1;
var id = _service.Insert(curve, mapping);
return id;
}
#endregion
#region Update
///
/// 更新一条
///
[Route("Update@V1.0")]
[HttpPut]
public bool Update([Required] UpdatePumpCurveExMappingInput input)
{
var curveModel = new Service.PumpCurve().GetByID(input.CurveID);
if (curveModel == null)
{
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"CurveID:{input.CurveID} 数据不存在");
}
var curveRhs = new Model.PumpCurve(curveModel);
var mappingModel = new Service.PumpCurveMapping().GetByID(input.MappingID);
if (mappingModel == null)
{
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"MappingID:{input.MappingID} 数据不存在");
}
var mappingRhs = new Model.PumpCurveMapping(mappingModel);
input.Adapt(curveRhs);
input.Adapt(mappingRhs);
var bol = _service.Update(curveRhs, mappingRhs);
return bol;
}
#endregion
#region Delete
///
/// 通过 ID 删除(如果曲线没有其他关联关系,则同时删除曲线)
///
public bool DeleteByID(long ID)
{
var bol = new Service.PumpCurveMapping().DeleteExByID(ID, out string Msg);
if (!bol)
{
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D999, Msg);
}
return bol;
}
#endregion
}
}