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>
|
/// MonitorPointMapping
|
/// </summary>
|
[Route("Monitor/MonitorPointMapping")]
|
[ApiDescriptionSettings("Monitor", Name = "监测点映射", Order = 770)]
|
public class MonitorPointMapping_Controller : IDynamicApiController
|
{
|
private readonly Service.MonitorPointMapping _service = new Service.MonitorPointMapping();
|
|
#region Query
|
|
/// <summary>
|
/// 通过 CorpID 获取
|
/// </summary>
|
[Route("GetByCorpID@V1.0")]
|
[HttpGet]
|
public List<MonitorPointMappingDto> GetByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var list = _service.GetByCorpID(input.CorpID);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorPointMapping, MonitorPointMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public MonitorPointMappingDto GetByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var model = _service.GetByID(input.CorpID, input.ID);
|
return model?.Adapt<Model.MonitorPointMapping, MonitorPointMappingDto>();
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<MonitorPointMappingDto> 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.MonitorPointMapping, MonitorPointMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ObjectType 和 ObjectID 获取
|
/// </summary>
|
[Route("GetByObjectTypeAndObjectID@V1.0")]
|
[HttpGet]
|
public List<MonitorPointMappingDto> GetByObjectTypeAndObjectID([FromQuery][Required] ObjectUnderCorpInput input)
|
{
|
var list = _service.GetByObjectTypeAndObjectID(input.CorpID, input.ObjectType, input.ObjectID);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorPointMapping, MonitorPointMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ObjectType 和 ObjectIds 获取
|
/// </summary>
|
[Route("GetByObjectTypeAndObjectIds@V1.0")]
|
[HttpGet]
|
public List<MonitorPointMappingDto> GetByObjectTypeAndObjectIds([FromQuery][Required] ObjectIdsUnderCorpInput input)
|
{
|
var ids = LongListHelper.ToList(input.ObjectIds);
|
var list = _service.GetByObjectTypeAndObjectIds(input.CorpID, input.ObjectType, ids);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorPointMapping, MonitorPointMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取
|
/// </summary>
|
[Route("GetByMonitorPointID@V1.0")]
|
[HttpGet]
|
public List<MonitorPointMappingDto> GetByMonitorPointID
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID
|
)
|
{
|
|
var list = _service.GetByMonitorPointID(CorpID, MonitorPointID);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorPointMapping, MonitorPointMappingDto>()).ToList();
|
return vm_list;
|
}
|
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert(AddMonitorPointMappingInput input)
|
{
|
if (input == null)
|
return default;
|
var model = input.Adapt<AddMonitorPointMappingInput, Model.MonitorPointMapping>();
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts(List<AddMonitorPointMappingInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var list = inputList.Select(x => x.Adapt<AddMonitorPointMappingInput, Model.MonitorPointMapping>()).ToList();
|
var bol = _service.Inserts(list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Update
|
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update(UpdateMonitorPointMappingInput input)
|
{
|
if (input == null)
|
return false;
|
var model = _service.GetByID(input.CorpID, input.ID);
|
if (model == null)
|
return false;
|
var rhs = new Model.MonitorPointMapping(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
[Route("Updates@V1.0")]
|
[HttpPut]
|
public bool Updates(List<UpdateMonitorPointMappingInput> 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.MonitorPointMapping>();
|
modelList.ForEach(x =>
|
{
|
var input = inputList.Find(t => t.ID == x.ID);
|
if (input != null)
|
{
|
var rhs = new Model.MonitorPointMapping(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;
|
}
|
|
/// <summary>
|
/// 更新 AccordParas
|
/// </summary>
|
[Route("UpdateAccordParas@V1.0")]
|
[HttpPut]
|
public bool UpdateAccordParas([Required] UpdateAccordParasUnderCorpInput input)
|
{
|
var bol = _service.UpdateAccordParas(input.CorpID, input.ID, input.AccordParas);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Set
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
[Route("SetOfObject@V1.0")]
|
[HttpPost]
|
public bool SetOfObject([Required] SetObjectMonitorPointMappingInput input)
|
{
|
var list = new List<Model.MonitorPointMapping>();
|
if (input.Items != null && input.Items.Count > 0)
|
{
|
list = input.Items.Select(x => new Model.MonitorPointMapping()
|
{
|
ID = x.ID,
|
CorpID = input.CorpID,
|
ObjectType = input.ObjectType,
|
ObjectID = input.ObjectID,
|
MonitorPointID = x.MonitorPointID,
|
SortCode = x.SortCode,
|
AccordParas = x.AccordParas
|
}).ToList();
|
}
|
|
var bol = _service.SetOfObject(input.CorpID, input.ObjectType, input.ObjectID, list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 删除
|
/// </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>
|
/// 删除
|
/// </summary>
|
[Route("DeleteByMonitorPointID@V1.0")]
|
[HttpDelete]
|
public DeleteReasonOutput DeleteByMonitorPointID([FromQuery][Required] MonitorPointIDUnderCorpInput input)
|
{
|
var bol = _service.DeleteByMonitorPointID(input.CorpID, input.MonitorPointID, out string Msg);
|
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
|
}
|
|
#endregion
|
|
}
|
}
|