namespace IStation.Application
{
///
/// LogicArea
///
[Route("SZJT/Logic/Area")]
[ApiDescriptionSettings("SZJT", Name = "区域", Order = 90000)]
public class LogicArea_Controller : IDynamicApiController
{
private readonly Service.LogicArea _service = new();
#region Query
///
/// 获取所有
///
[Route("GetAll@V1.0")]
[HttpGet]
public List GetAll()
{
var list = _service.GetAll();
var vmList = list?.Select(x => new LogicAreaDto(x)).ToList();
return vmList;
}
///
/// 通过 ID 获取
///
[Route("GetByID@V1.0")]
[HttpGet]
public LogicAreaDto GetByID([FromQuery][Required] IDInput input)
{
var model = _service.GetByID(input.ID);
return model == null ? null : new LogicAreaDto(model);
}
///
/// 通过 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 LogicAreaDto(x)).ToList();
return vmList;
}
///
/// 通过 PolicyID 获取
///
[Route("GetByPolicyID@V1.0")]
[HttpGet]
public List GetByPolicyID([FromQuery][Required] PolicyIDInput input)
{
var list = _service.GetByPolicyID(input.PolicyID);
var vmList = list?.Select(x => new LogicAreaDto(x)).ToList();
return vmList;
}
#endregion
#region Insert
///
/// 插入一条
///
[Route("Insert@V1.0")]
[HttpPost]
public long Insert([Required] AddLogicAreaInput input)
{
var policy = new Service.LogicPolicy().GetByID(input.PolicyID);
if (policy == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"PolicyID:{input.PolicyID} 数据不存在");
}
if (!string.IsNullOrEmpty(input.Code))
{
if (_service.IsExistCode(input.Code))
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Code:{input.Code}", "编码已存在");
}
}
if (!string.IsNullOrEmpty(input.TagName))
{
if (_service.IsExistTagName(input.TagName))
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"TagName:{input.TagName}", "标记已存在");
}
}
var model = input.Adapt();
model.SortCode = _service.GetMaxSortCodeByPolicyID(input.PolicyID) + 1;
var id = _service.Insert(model);
return id;
}
#endregion
#region Update
///
/// 更新一条
///
[Route("Update@V1.0")]
[HttpPut]
public bool Update([Required] UpdateLogicAreaInput input)
{
var model = _service.GetByID(input.ID);
if (model == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在");
}
if (!string.IsNullOrEmpty(input.Code))
{
if (_service.IsExistCodeExceptID(input.Code, input.ID))
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Code:{input.Code}", "编码已存在");
}
}
if (!string.IsNullOrEmpty(input.TagName))
{
if (_service.IsExistTagNameExceptID(input.TagName, input.ID))
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"TagName:{input.TagName}", "标记已存在");
}
}
var rhs = new Model.LogicArea(model);
input.Adapt(rhs);
var bol = _service.Update(rhs);
return bol;
}
///
/// 更新排序码
///
[Route("UpdateSortCode@V1.0")]
[HttpPut]
public bool UpdateSortCode([Required] UpdateSortCodeInput input)
{
var bol = _service.UpdateSortCode(input.ID, input.SortCode);
return bol;
}
///
/// 更新排序
///
[Route("UpdateSorter@V1.0")]
[HttpPut]
public bool UpdateSorter([Required] List inputList)
{
if (inputList == null || inputList.Count < 1)
{
return false;
}
var list = inputList.Select(x => x.Adapt()).ToList();
var bol = _service.UpdateSorter(list);
return bol;
}
///
/// 更新 Paras
///
[Route("UpdateParas@V1.0")]
[HttpPut]
public bool UpdateParas([Required] UpdateParasInput input)
{
var bol = _service.UpdateParas(input.ID, input.Paras);
return bol;
}
///
/// 更新 Flags
///
[Route("UpdateFlags@V1.0")]
[HttpPut]
public bool UpdateFlags([Required] UpdateFlagsInput input)
{
var bol = _service.UpdateFlags(input.ID, input.Flags);
return bol;
}
///
/// 更新TagName
///
[Route("UpdateTagName@V1.0")]
[HttpPut]
public bool UpdateTagName([Required] UpdateTagNameInput input)
{
if (!string.IsNullOrEmpty(input.TagName))
{
if (_service.IsExistTagNameExceptID(input.TagName, input.ID))
{
throw Oops.Oh(InternalErrorCodes.V001, $"TagName:{input.TagName}", "标记名称已存在");
}
}
var bol = _service.UpdateTagName(input.ID, input.TagName);
return bol;
}
///
/// 更新 UseStatus
///
[Route("UpdateUseStatus@V1.0")]
[HttpPut]
public bool UpdateUseStatus([Required] UpdateUseStatusInput input)
{
var bol = _service.UpdateUseStatus(input.ID, (Yw.Model.eUseStatus)input.UseStatus);
return bol;
}
#endregion
#region Exist
///
/// 判断 Code 是否存在
///
[Route("IsExistCode@V1.0")]
[HttpGet]
public bool IsExistCode([FromQuery][Required] CodeInput input)
{
var bol = _service.IsExistCode(input.Code);
return bol;
}
///
/// 判断 Code 是否存在 ExceptID
///
[Route("IsExistCodeExceptID@V1.0")]
[HttpGet]
public bool IsExistCodeExceptID([FromQuery][Required] CodeExceptInput input)
{
var bol = _service.IsExistCodeExceptID(input.Code, input.ExceptID);
return bol;
}
///
/// 判断TagName是否存在
///
[Route("IsExistTagName@V1.0")]
[HttpGet]
public bool IsExistTagName([FromQuery][Required] TagNameInput input)
{
var bol = _service.IsExistTagName(input.TagName);
return bol;
}
///
/// 判断TagName是否存在 ExceptID
///
[Route("IsExistTagNameExceptID@V1.0")]
[HttpGet]
public bool IsExistTagNameExceptID([FromQuery][Required] TagNameExceptInput input)
{
var bol = _service.IsExistTagNameExceptID(input.TagName, input.ExceptID);
return bol;
}
#endregion
#region Delete
///
/// 删除
///
[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, InternalErrorCodes.D001, Msg);
}
return bol;
}
#endregion
}
}