AdoS8ConfigDashboardCellsController.cs 3.2 KB

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