namespace HStation.Application { /// /// TransferFileUser /// [Route("Transfer/File/User")] [AllowAnonymous] [ApiDescriptionSettings("TransferFile", Name = "用户", Order = 10000)] public class TransferFileUser_Controller : IDynamicApiController { private readonly Service.TransferFileUser _service = new(); #region Query /// /// 获取所有 /// [Route("GetAll@V1.0")] [HttpGet] public List GetAll() { var list = _service.GetAll(); var vmList = list?.Select(x => new TransferFileUserDto(x)).ToList(); return vmList; } /// /// 通过 ID 获取 /// [Route("GetByID@V1.0")] [HttpGet] public TransferFileUserDto GetByID([FromQuery][Required] IDInput input) { var model = _service.GetByID(input.ID); return model == null ? null : new TransferFileUserDto(model); } /// /// 通过 Ids 获取 /// [Route("GetByIds@V1.0")] [HttpGet] public List GetByIds([FromQuery][Required] IdsInput model) { var ids = LongListHelper.ToList(model.Ids); var list = _service.GetByIds(ids); var vmList = list?.Select(x => new TransferFileUserDto(x)).ToList(); return vmList; } /// /// 通过 Name 获取 /// [Route("GetByName@V1.0")] [HttpGet] public TransferFileUserDto GetByName([FromQuery][Required] NameInput input) { var model = _service.GetByName(input.Name); return model == null ? null : new TransferFileUserDto(model); } #endregion #region Insert /// /// 插入一条 /// [Route("Insert@V1.0")] [HttpPost] public long Insert([Required] AddTransferFileUserInput input) { if (_service.IsExistName(input.Name)) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name}", "名称已存在"); } var model = input.Adapt(); model.SortCode = _service.GetMaxSortCode() + 1; var id = _service.Insert(model); return id; } #endregion #region Update /// /// 更新一条 /// [Route("Update@V1.0")] [HttpPut] public bool Update([Required] UpdateTransferFileUserInput input) { var model = _service.GetByID(input.ID); if (model == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在"); } if (_service.IsExistNameExceptID(input.Name, input.ID)) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name}", "名称已存在"); } var rhs = new Model.TransferFileUser(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) { var list = inputList.Select(x => x.Adapt()).ToList(); var bol = _service.UpdateSorter(list); return bol; } /// /// 激活 /// [Route("Active@V1.0")] [HttpPost] public bool Active([Required] ActiveTransferFileUserInput input) { var model = _service.GetByName(input.Name); if (model == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name} 不存在"); } var bol = _service.Active(model.ID, out string Msg); if (!bol) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg); } return bol; } /// /// 失效 /// [Route("Invalid@V1.0")] [HttpPost] public bool Invalid([Required] InvalidTransferFileUserInput input) { var model = _service.GetByName(input.Name); if (model == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name} 不存在"); } var bol = _service.Invalid(model.ID, input.InvalidTime, out string Msg); if (!bol) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg); } return bol; } #endregion #region Exist /// /// 判断 Name 是否存在 /// [Route("IsExistName@V1.0")] [HttpGet] public bool IsExistName([FromQuery][Required] NameInput input) { var bol = _service.IsExistName(input.Name); return bol; } /// /// 判断 Name 是否存在 ExceptID /// [Route("IsExistNameExceptID@V1.0")] [HttpGet] public bool IsExistNameExceptID([FromQuery][Required] NameExceptInput input) { var bol = _service.IsExistNameExceptID(input.Name, input.ExceptID); return bol; } #endregion #region Delete /// /// 通过 ID 删除 /// [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.D999, msg, default(bool)); } return bol; } #endregion } }