using Microsoft.AspNetCore.Mvc;
|
using System.Net;
|
using System.Net.Http.Headers;
|
using Microsoft.Extensions.Hosting.Internal;
|
using Microsoft.AspNetCore.Http.Extensions;
|
using IStation.Untity;
|
using Furion.DynamicApiController;
|
using System.ComponentModel.DataAnnotations;
|
using Mapster;
|
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// PumpCurveMapping
|
/// </summary>
|
[Route("Product/PumpCurveMapping")]
|
[ApiDescriptionSettings("Product", Name = "泵曲线映射", Order = 390)]
|
public partial class PumpCurveMapping_Controller : IDynamicApiController
|
{
|
private readonly Service.PumpCurveMapping _service = new Service.PumpCurveMapping();
|
|
#region Query
|
|
/// <summary>
|
/// 通过 CorpID 获取
|
/// </summary>
|
[Route("GetByCorpID@V1.0")]
|
[HttpGet]
|
public List<PumpCurveMappingDto> GetByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var list = _service.GetByCorpID(input.CorpID);
|
var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveMapping, PumpCurveMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public PumpCurveMappingDto GetByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var model = _service.GetByID(input.CorpID, input.ID);
|
return model?.Adapt<Model.PumpCurveMapping, PumpCurveMappingDto>();
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<PumpCurveMappingDto> GetByIds([FromQuery][Required] IdsUnderCorpInput input)
|
{
|
var ids = LongListHelper.ToList(input.Ids);
|
var list = _service.GetByIds(input.CorpID, ids);
|
var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveMapping, PumpCurveMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取
|
/// </summary>
|
[Route("GetByPumpID@V1.0")]
|
[HttpGet]
|
public List<PumpCurveMappingDto> GetByPumpID
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "PumpID 必须大于0")]
|
long PumpID
|
)
|
{
|
var list = _service.GetByPumpID(CorpID, PumpID);
|
var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveMapping, PumpCurveMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 CurveID 获取
|
/// </summary>
|
[Route("GetByCurveID@V1.0")]
|
[HttpGet]
|
public List<PumpCurveMappingDto> GetByCurveID
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CurveID 必须大于0")]
|
long CurveID
|
)
|
{
|
var list = _service.GetByCurveID(CorpID, CurveID);
|
var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveMapping, PumpCurveMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 PumpID 获取
|
/// </summary>
|
[Route("IsExistByPumpID@V1.0")]
|
[HttpGet]
|
public bool IsExistByPumpID
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "PumpID 必须大于0")]
|
long PumpID
|
)
|
{
|
var bol = _service.IsExistByPumpID(CorpID, PumpID);
|
return bol;
|
}
|
|
/// <summary>
|
/// 通过 CurveID 获取
|
/// </summary>
|
[Route("IsExistByCurveID@V1.0")]
|
[HttpGet]
|
public bool IsExistByCurveID
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CurveID 必须大于0")]
|
long CurveID
|
)
|
{
|
var bol = _service.IsExistByCurveID(CorpID, CurveID);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert(AddPumpCurveMappingInput input)
|
{
|
if (input == null)
|
return default;
|
var model = input.Adapt<AddPumpCurveMappingInput, Model.PumpCurveMapping>();
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts(List<AddPumpCurveMappingInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var list = inputList.Select(x => x.Adapt<AddPumpCurveMappingInput, Model.PumpCurveMapping>()).ToList();
|
var bol = _service.Inserts(list);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update(UpdatePumpCurveMappingInput input)
|
{
|
if (input == null)
|
return false;
|
var model = _service.GetByID(input.CorpID, input.ID);
|
if (model == null)
|
return false;
|
var rhs = new Model.PumpCurveMapping(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
[Route("Updates@V1.0")]
|
[HttpPut]
|
public bool Updates(List<UpdatePumpCurveMappingInput> inputList)
|
{
|
if (inputList == null || inputList.Count() < 1)
|
{
|
return false;
|
}
|
var corpIds = inputList.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count > 1)
|
return false;
|
var modelList = _service.GetByIds(corpIds[0], inputList.Select(x => x.ID).ToList());
|
if (modelList == null || modelList.Count < 1)
|
return false;
|
var rhsList = new List<Model.PumpCurveMapping>();
|
modelList.ForEach(x => {
|
var input = inputList.Find(t => t.ID == x.ID);
|
if (input != null)
|
{
|
var rhs = new Model.PumpCurveMapping(x);
|
input.Adapt(rhs);
|
rhsList.Add(rhs);
|
}
|
});
|
if (rhsList.Count < 1)
|
return false;
|
var bol = _service.Updates(rhsList);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
[Route("UpdateSortCode@V1.0")]
|
[HttpPut]
|
public bool UpdateSortCode([Required] UpdateSortCodeUnderCorpInput input)
|
{
|
var bol = _service.UpdateSortCode(input.CorpID, input.ID, input.SortCode);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
[Route("UpdateSorter@V1.0")]
|
[HttpPut]
|
public bool UpdateSorter([Required] UpdateSorterUnderCorpInput input)
|
{
|
if (input.Sorters == null || input.Sorters.Count < 1)
|
return false;
|
var list = input.Sorters.Select(x => x.Adapt<UpdateSortCodeInput, Model.Sorter>()).ToList();
|
var bol = _service.UpdateSorter(input.CorpID, list);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Set
|
|
/// <summary>
|
/// 设置工作曲线
|
/// </summary>
|
[Route("SetWorkingCurve@V1.0")]
|
[HttpPost]
|
public bool SetWorkingCurve([Required] SetWorkingCurveInput input)
|
{
|
var bol = _service.SetWorkingCurve(input.CorpID, input.PumpID, input.ID) ;
|
return bol;
|
}
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
[Route("SetByCurveID@V1.0")]
|
[HttpPost]
|
public bool SetByCurveID([Required] SetObjectPumpCurveMappingInput input)
|
{
|
var list = new List<Model.PumpCurveMapping>();
|
if (input.Items != null && input.Items.Count > 0)
|
{
|
if (input.Items.GroupBy(x => x.PumpID).Max(x => x.Count()) > 1)
|
{
|
throw new Exception("PumpID存在重复项");
|
}
|
|
|
list = input.Items.Select(x => new Model.PumpCurveMapping()
|
{
|
CorpID = input.CorpID,
|
CurveID = input.CurveID,
|
ID = x.ID,
|
PumpID = x.PumpID,
|
OtherName = x.OtherName,
|
IsWorking = x.IsWorking,
|
SortCode = x.SortCode,
|
}).ToList();
|
}
|
var bol = _service.SetByCurveID(input.CorpID, input.CurveID, list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 通过 ID 删除
|
/// </summary>
|
[Route("DeleteByID@V1.0")]
|
[HttpDelete]
|
public DeleteReasonOutput DeleteByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var bol = _service.DeleteByID(input.CorpID, input.ID, out string Msg);
|
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
|
}
|
|
/// <summary>
|
/// 通过 ID 删除 同时删除曲线
|
/// </summary>
|
[Route("DeleteWithCurveByID@V1.0")]
|
[HttpDelete]
|
public DeleteReasonOutput DeleteWithCurveByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var bol = _service.DeleteWithCurveByID(input.CorpID, input.ID, out string Msg);
|
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
|
}
|
|
#endregion
|
|
}
|
}
|