108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MilliSim.Common.Dtos;
|
|
using MilliSim.Services;
|
|
using IAuthorizationService = MilliSim.Services.IAuthorizationService;
|
|
|
|
namespace MilliSim.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/authorizations")]
|
|
public class AuthorizationsController : ControllerBase
|
|
{
|
|
private readonly IAuthorizationService _authorizationService;
|
|
|
|
public AuthorizationsController(IAuthorizationService authorizationService)
|
|
{
|
|
_authorizationService = authorizationService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 授权列表(销售只能看自己客户的授权)
|
|
/// </summary>
|
|
[HttpGet]
|
|
[Authorize(Policy = "Staff")]
|
|
public async Task<IActionResult> GetList([FromQuery] AuthorizationQueryRequest request)
|
|
{
|
|
var result = await _authorizationService.GetAuthorizationsAsync(request);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 授权详情
|
|
/// </summary>
|
|
[HttpGet("{id:long}")]
|
|
[Authorize(Policy = "Staff")]
|
|
public async Task<IActionResult> GetById(long id)
|
|
{
|
|
var result = await _authorizationService.GetAuthorizationByIdAsync(id);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建授权(默认 365 天)
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Authorize(Policy = "Staff")]
|
|
public async Task<IActionResult> Create([FromBody] CreateAuthorizationRequest request)
|
|
{
|
|
var result = await _authorizationService.CreateAuthorizationAsync(request);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量授权
|
|
/// </summary>
|
|
[HttpPost("batch")]
|
|
[Authorize(Policy = "Staff")]
|
|
public async Task<IActionResult> Batch([FromBody] BatchAuthorizationRequest request)
|
|
{
|
|
var result = await _authorizationService.BatchAuthorizeAsync(request);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 续期(在原到期时间基础上加天数)
|
|
/// </summary>
|
|
[HttpPost("{id:long}/renew")]
|
|
[Authorize(Policy = "Staff")]
|
|
public async Task<IActionResult> Renew(long id, [FromBody] RenewAuthorizationRequest request)
|
|
{
|
|
var result = await _authorizationService.RenewAuthorizationAsync(id, request.Days);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消授权
|
|
/// </summary>
|
|
[HttpPost("{id:long}/cancel")]
|
|
[Authorize(Policy = "Staff")]
|
|
public async Task<IActionResult> Cancel(long id)
|
|
{
|
|
var result = await _authorizationService.CancelAuthorizationAsync(id);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查用户是否有授权(客户级授权,授权后可运行所有项目)
|
|
/// </summary>
|
|
[HttpGet("check")]
|
|
[Authorize]
|
|
public async Task<IActionResult> Check([FromQuery] long userId)
|
|
{
|
|
var result = await _authorizationService.CheckAuthorizationAsync(userId);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前客户的授权列表
|
|
/// </summary>
|
|
[HttpGet("my")]
|
|
[Authorize]
|
|
public async Task<IActionResult> My()
|
|
{
|
|
var result = await _authorizationService.GetMyAuthorizationsAsync();
|
|
return Ok(result);
|
|
}
|
|
}
|