AdoS8ConfigDashboardCellsController.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Admin.NET.Plugin.AiDOP.Infrastructure.S8;
  2. using Admin.NET.Plugin.AiDOP.Const.S8;
  3. using Admin.NET.Plugin.AiDOP.Entity.S8;
  4. using Admin.NET.Plugin.AiDOP.Infrastructure;
  5. using Admin.NET.Plugin.AiDOP.Service.S8;
  6. namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
  7. [ApiController]
  8. [Route("api/aidop/s8/config/dashboard-cells")]
  9. [NonUnify]
  10. public class AdoS8ConfigDashboardCellsController : ControllerBase
  11. {
  12. private readonly S8DashboardCellConfigService _svc;
  13. private readonly S8TrustedScopeResolver _scope;
  14. public AdoS8ConfigDashboardCellsController(S8DashboardCellConfigService svc, S8TrustedScopeResolver scope)
  15. {
  16. _svc = svc;
  17. _scope = scope;
  18. }
  19. [HttpGet]
  20. [S8Permission(S8PermissionCatalog.ConfigRead)]
  21. public async Task<IActionResult> ListAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1)
  22. {
  23. // Compatibility-only. Security scope is resolved server-side.
  24. _ = tenantId; _ = factoryId;
  25. var scope = await _scope.ResolveAsync();
  26. return Ok(await _svc.ListAsync(scope.TenantId, scope.FactoryId));
  27. }
  28. [HttpPost]
  29. [S8Permission(S8PermissionCatalog.ConfigDashboard)]
  30. public async Task<IActionResult> CreateAsync([FromBody] AdoS8DashboardCellConfig body)
  31. {
  32. try { return Ok(await _svc.CreateAsync(body, await _scope.ResolveAsync())); }
  33. catch (S8NotFoundException) { return NotFound(); }
  34. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  35. }
  36. [HttpPut("{id:long}")]
  37. [S8Permission(S8PermissionCatalog.ConfigDashboard)]
  38. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS8DashboardCellConfig body)
  39. {
  40. try { return Ok(await _svc.UpdateAsync(id, body, await _scope.ResolveAsync())); }
  41. catch (S8NotFoundException) { return NotFound(); }
  42. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  43. }
  44. [HttpDelete("{id:long}")]
  45. [S8Permission(S8PermissionCatalog.ConfigDashboard)]
  46. public async Task<IActionResult> DeleteAsync(long id)
  47. {
  48. try { await _svc.DeleteAsync(id, await _scope.ResolveAsync()); }
  49. catch (S8NotFoundException) { return NotFound(); }
  50. return Ok();
  51. }
  52. /// <summary>
  53. /// S8-CONFIG-GLOBAL-ROW-SEMANTICS-AND-KPI-TARGET-1:自定义本工厂。
  54. /// 入参是<b>平台默认行</b>的 Id;服务端复制其业务字段并盖章可信租户 / 工厂,存为工厂覆盖行。
  55. /// 平台默认行不被修改。
  56. /// </summary>
  57. [HttpPost("{globalId:long}/factory-override")]
  58. [S8Permission(S8PermissionCatalog.ConfigDashboard)]
  59. public async Task<IActionResult> CreateFactoryOverrideAsync(long globalId)
  60. {
  61. try { return Ok(await _svc.CreateFactoryOverrideAsync(globalId, await _scope.ResolveAsync())); }
  62. catch (S8NotFoundException) { return NotFound(); }
  63. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  64. }
  65. /// <summary>
  66. /// S8-CONFIG-GLOBAL-ROW-SEMANTICS-AND-KPI-TARGET-1:恢复平台默认。
  67. /// 入参是<b>当前工厂覆盖行</b>的 Id;只删除该覆盖行,平台默认行不受影响。
  68. /// </summary>
  69. [HttpDelete("{overrideId:long}/factory-override")]
  70. [S8Permission(S8PermissionCatalog.ConfigDashboard)]
  71. public async Task<IActionResult> ResetToGlobalDefaultAsync(long overrideId)
  72. {
  73. try { await _svc.ResetToGlobalDefaultAsync(overrideId, await _scope.ResolveAsync()); return Ok(new { overrideId, reset = true }); }
  74. catch (S8NotFoundException) { return NotFound(); }
  75. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  76. }
  77. }