AdoS8ReportsController.cs 1.6 KB

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