namespace Yw.Application { /// /// SoftRegister /// [Route("Auth/Soft/Register")] [ApiDescriptionSettings("Auth", Name = "软件注册", Order = 4700)] public class SoftRegister_Controller : IDynamicApiController { private readonly Service.SoftRegister _service = new(); #region Query /// /// 通过 SoftwareID 获取 /// [Route("GetBySoftwareID@V1.0")] [HttpGet] public List GetBySoftwareID([FromQuery][Required] SoftwareIDInput input) { var list = _service.GetBySoftwareID(input.SoftwareID); var vmList = list?.Select(x => new SoftRegisterDto(x)).ToList(); return vmList; } /// /// 通过 ID 获取 /// [Route("GetByID@V1.0")] [HttpGet] public SoftRegisterDto GetByID([FromQuery][Required] IDInput input) { var model = _service.GetByID(input.ID); return model == null ? null : new SoftRegisterDto(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 SoftRegisterDto(x)).ToList(); return vmList; } #endregion #region Insert /// /// 插入一条 /// [Route("Insert@V1.0")] [HttpPost] public long Insert([Required] AddSoftRegisterInput input) { var software = new Service.Software().GetByID(input.SoftwareID); if (software == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"SoftwareID:{input.SoftwareID} 数据不存在"); } var model = new Model.SoftRegister() { ID = 0, SoftwareID = input.SoftwareID, Name = input.Name, UUID = null, CDKey = GuidCreater.CreateN(), RegistTime = null, FailureTime = input.FailureTime, SortCode = _service.GetMaxSortCode(input.SoftwareID) + 1, Description = input.Description, CreateTime = DateTime.Now, CreateUserID = UserManager.UserID, CreateUserName = UserManager.UserName }; var id = _service.Insert(model); return id; } #endregion #region Update /// /// 更新一条 /// [Route("Update@V1.0")] [HttpPut] public bool Update([Required] UpdateSoftRegisterInput input) { var model = _service.GetByID(input.ID); if (model == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在"); } var rhs = new Model.SoftRegister(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; } #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 #region Extensions /// /// 激活 /// [Route("Activate@V1.0")] [AllowAnonymous] [HttpPost] public bool Activate([Required] SoftRegisterActivateInput input) { var software = new Service.Software().GetByCode(input.Software); if (software == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"软件码:{input.Software} 不存在"); } var bol = _service.Activate(software.ID, input.CDKey, input.UUID, out string Msg); if (!bol) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg); } return bol; } /// /// 验证 /// [Route("Verify@V1.0")] [AllowAnonymous] [HttpPost] public bool Verify([Required] SoftRegisterVerifyInput input) { var software = new Service.Software().GetByCode(input.Software); if (software == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"软件码:{input.Software} 不存在"); } var bol = _service.Verify(software.ID, input.UUID, out string Msg); if (!bol) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg); } return bol; } #endregion } }