AdoS8ReportsController.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. [S8ExceptionAction(S8ExceptionActionCode.View)]
  15. // Compatibility-only. Security scope is resolved server-side
  16. // (S8ManualReportService.ResolveTrustedTenantId 忽略入参)。
  17. public async Task<IActionResult> FormOptionsAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1)
  18. {
  19. _ = tenantId; _ = factoryId;
  20. return Ok(await _svc.GetFormOptionsAsync());
  21. }
  22. [HttpPost]
  23. [S8ExceptionAction(S8ExceptionActionCode.Create)]
  24. public async Task<IActionResult> CreateAsync([FromBody] AdoS8ManualReportCreateDto dto)
  25. {
  26. try { return Ok(await _svc.CreateAsync(dto)); }
  27. catch (S8NotFoundException) { return NotFound(); }
  28. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  29. }
  30. [HttpGet("{id:long}")]
  31. [S8ExceptionAction(S8ExceptionActionCode.View)]
  32. public async Task<IActionResult> GetAsync(long id)
  33. {
  34. var e = await _svc.GetAsync(id);
  35. return e == null ? NotFound() : Ok(e);
  36. }
  37. [HttpPost("{id:long}/attachments")]
  38. [S8ExceptionAction(S8ExceptionActionCode.Create)]
  39. public async Task<IActionResult> AttachmentsAsync(long id, [FromBody] AdoS8AttachmentCreateDto dto)
  40. {
  41. try { return Ok(await _svc.AddAttachmentAsync(id, dto)); }
  42. catch (S8NotFoundException) { return NotFound(); }
  43. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  44. }
  45. }