namespace Yw.Application
|
{
|
/// <summary>
|
/// DmaSiteMapping
|
/// </summary>
|
[Route("Dma/Site/Mapping")]
|
[ApiDescriptionSettings("DMA", Name = "Dma点位映射", Order = 7000)]
|
public class DmaSiteMapping_Controller : IDynamicApiController
|
{
|
private readonly Service.DmaSiteMapping _service = new Service.DmaSiteMapping();
|
|
#region Query
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
[Route("GetAll@V1.0")]
|
[HttpGet]
|
public List<DmaSiteMappingDto> GetAll()
|
{
|
var list = _service.GetAll();
|
var vmList = list?.Select(x => new DmaSiteMappingDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public DmaSiteMappingDto GetByID([FromQuery][Required] IDInput input)
|
{
|
var model = _service.GetByID(input.ID);
|
return model == null ? null : new DmaSiteMappingDto(model);
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<DmaSiteMappingDto> GetByIds([FromQuery][Required] IdsInput input)
|
{
|
var ids = LongListHelper.ToList(input.Ids);
|
var list = _service.GetByIds(ids);
|
var vmList = list?.Select(x => new DmaSiteMappingDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 SiteID 获取
|
/// </summary>
|
[Route("GetBySiteID@V1.0")]
|
[HttpGet]
|
public List<DmaSiteMappingDto> GetBySiteID([FromQuery][Required] SiteIDInput input)
|
{
|
var list = _service.GetBySiteID(input.SiteID);
|
var vmList = list?.Select(x => new DmaSiteMappingDto(x)).ToList();
|
return vmList;
|
}
|
|
|
/// <summary>
|
/// 通过 AreaID 获取
|
/// </summary>
|
[Route("GetByAreaID@V1.0")]
|
[HttpGet]
|
public List<DmaSiteMappingDto> GetByAreaID([FromQuery][Required] AreaIDInput input)
|
{
|
var list = _service.GetByAreaID(input.AreaID);
|
var vmList = list?.Select(x => new DmaSiteMappingDto(x)).ToList();
|
return vmList;
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert([Required] AddDmaSiteMappingInput input)
|
{
|
var area = new Yw.Service.DmaArea().GetByID(input.AreaID);
|
if (area == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"AreaID:{input.AreaID} 数据不存在");
|
}
|
var site = new Yw.Service.DmaSite().GetByID(input.SiteID);
|
if (site == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"SiteID:{input.SiteID} 数据不存在");
|
}
|
var model = input.Adapt<AddDmaSiteMappingInput, Model.DmaSiteMapping>();
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts([Required] List<AddDmaSiteMappingInput> inputList)
|
{
|
var serviceArea = new Yw.Service.DmaArea();
|
var serviceSite = new Yw.Service.DmaSite();
|
foreach (var item in inputList)
|
{
|
var area = serviceArea.GetByID(item.AreaID);
|
if (area == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"AreaID:{item.AreaID} 数据不存在");
|
}
|
var site = serviceSite.GetByID(item.SiteID);
|
if (site == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"SiteID:{item.SiteID} 数据不存在");
|
}
|
}
|
var list = inputList.Select(x => x.Adapt<AddDmaSiteMappingInput, Model.DmaSiteMapping>()).ToList();
|
var bol = _service.Inserts(list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update([Required] UpdateDmaSiteMappingInput input)
|
{
|
var model = _service.GetByID(input.ID);
|
if (model == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"ID:{input.ID} 数据不存在");
|
}
|
var rhs = new Model.DmaSiteMapping(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
[Route("Updates@V1.0")]
|
[HttpPut]
|
public bool Updates(List<UpdateDmaSiteMappingInput> inputList)
|
{
|
var modelList = _service.GetByIds(inputList.Select(x => x.ID).ToList());
|
if (modelList == null || modelList.Count < 1)
|
{
|
return false;
|
}
|
var rhsList = new List<Model.DmaSiteMapping>();
|
modelList.ForEach(x =>
|
{
|
var input = inputList.Find(t => t.ID == x.ID);
|
if (input != null)
|
{
|
var rhs = new Model.DmaSiteMapping(x);
|
input.Adapt(rhs);
|
rhsList.Add(rhs);
|
}
|
});
|
if (rhsList.Count < 1)
|
{
|
return false;
|
}
|
var bol = _service.Updates(rhsList);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新 Direction
|
/// </summary>
|
[Route("UpdateDirection@V1.0")]
|
[HttpPut]
|
public bool UpdateDirection([Required] UpdateDirectionInput input)
|
{
|
var bol = _service.UpdateDirection(input.ID, (eDirection)input.Direction);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Exist
|
|
/// <summary>
|
/// 通过 AreaID 判断是否存在
|
/// </summary>
|
[Route("IsExistByAreaID@V1.0")]
|
[HttpGet]
|
public bool IsExistByAreaID([FromQuery][Required] AreaIDInput input)
|
{
|
var bol = _service.IsExistByAreaID(input.AreaID);
|
return bol;
|
}
|
|
/// <summary>
|
/// 通过 SiteID 判断是否存在
|
/// </summary>
|
[Route("IsExistBySiteID@V1.0")]
|
[HttpGet]
|
public bool IsExistBySiteID([FromQuery][Required] SiteIDInput input)
|
{
|
var bol = _service.IsExistBySiteID(input.SiteID);
|
return bol;
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
[Route("DeleteByID@V1.0")]
|
[HttpDelete]
|
public bool DeleteByID([FromQuery][Required] IDInput input)
|
{
|
var bol = _service.DeleteByID(input.ID, out string Msg);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, Msg);
|
}
|
return bol;
|
}
|
|
#endregion
|
|
}
|
}
|