AdoS8ReportsController.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Admin.NET.Plugin.AiDOP.Infrastructure.S8;
  2. using Admin.NET.Plugin.AiDOP.Const.S8;
  3. using Admin.NET.Plugin.AiDOP.Dto.S8;
  4. using Admin.NET.Plugin.AiDOP.Service.S8;
  5. namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
  6. [ApiController]
  7. [Route("api/aidop/s8/reports")]
  8. [NonUnify]
  9. public class AdoS8ReportsController : ControllerBase
  10. {
  11. private readonly S8ManualReportService _svc;
  12. public AdoS8ReportsController(S8ManualReportService svc) => _svc = svc;
  13. [HttpGet("form-options")]
  14. [S8Permission(S8PermissionCatalog.ExceptionRead)]
  15. // Compatibility-only. Security scope is resolved server-side
  16. // (S8ManualReportService.ResolveTrustedScopeAsync 覆盖入参)。
  17. public async Task<IActionResult> FormOptionsAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1) =>
  18. Ok(await _svc.GetFormOptionsAsync(tenantId, factoryId));
  19. [HttpPost]
  20. [S8Permission(S8PermissionCatalog.ExceptionCreate)]
  21. public async Task<IActionResult> CreateAsync([FromBody] AdoS8ManualReportCreateDto dto)
  22. {
  23. try { return Ok(await _svc.CreateAsync(dto)); }
  24. catch (S8NotFoundException) { return NotFound(); }
  25. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  26. }
  27. [HttpGet("{id:long}")]
  28. [S8Permission(S8PermissionCatalog.ExceptionRead)]
  29. public async Task<IActionResult> GetAsync(long id)
  30. {
  31. var e = await _svc.GetAsync(id);
  32. return e == null ? NotFound() : Ok(e);
  33. }
  34. [HttpPost("{id:long}/attachments")]
  35. [S8Permission(S8PermissionCatalog.ExceptionCreate)]
  36. public async Task<IActionResult> AttachmentsAsync(long id, [FromBody] AdoS8AttachmentCreateDto dto)
  37. {
  38. try { return Ok(await _svc.AddAttachmentAsync(id, dto)); }
  39. catch (S8NotFoundException) { return NotFound(); }
  40. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  41. }
  42. }