namespace Yw.Application
{
///
/// UserLoginAccount
///
[Route("Auth/User/Login/Account")]
[ApiDescriptionSettings("Auth", Name = "用户登录账户", Order = 6900)]
public class UserLoginAccount_Controller : IDynamicApiController
{
private readonly Service.UserLoginAccount _service = new();
#region Query
///
/// 通过 UserID 获取
///
[Route("GetByUserID@V1.0")]
[HttpGet]
public List GetByUserID([FromQuery][Required] UserIDInput input)
{
var list = _service.GetByUserID(input.UserID);
var vmList = list?.Select(x => new UserLoginAccountDto(x)).ToList();
return vmList;
}
///
/// 通过 UserID 获取系统账户
///
[Route("GetSystemByUserID@V1.0")]
[HttpGet]
public List GetSystemByUserID([FromQuery][Required] UserIDInput input)
{
var loginType = new Service.UserLoginType().GetByIdentifier(LoginType.System);
if (loginType == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.L001, "登录类型数据异常");
}
if (loginType.Mode != eLoginMode.Inside)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.L001, "登录模式注册错误");
}
var list = _service.GetByUserIDAndLoginTypeID(input.UserID, loginType.ID);
var vmList = list?.Select(x => new UserLoginAccountDto(x)).ToList();
return vmList;
}
///
/// 通过 ID 获取
///
[Route("GetByID@V1.0")]
[HttpGet]
public UserLoginAccountDto GetByID([FromQuery][Required] IDInput input)
{
var model = _service.GetByID(input.ID);
return model == null ? null : new UserLoginAccountDto(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 UserLoginAccountDto(x)).ToList();
return vmList;
}
#endregion
#region Update
///
/// 更新系统账户密码
///
[Route("UpdateSystemLoginPwd@V1.0")]
[HttpPut]
public bool UpdateSystemLoginPwd([Required] UpdateLoginPwdInput input)
{
var model = _service.GetByID(input.ID);
if (model == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在");
}
var bol = _service.UpdateCredential(input.ID, input.LoginPwd);
return bol;
}
///
/// 重置系统账户密码
///
[Route("ResetSystemLoginPwd@V1.0")]
[HttpPut]
public bool ResetSystemLoginPwd([Required] IDInput input)
{
var model = _service.GetByID(input.ID);
if (model == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在");
}
var bol = _service.UpdateCredential(input.ID, ConfigHelper.DefaultLoginPwd);
return bol;
}
#endregion
}
}