AdoS0ContractReviewCycleSyncFlagsController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
  2. using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
  3. namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales;
  4. /// <summary>
  5. /// 合同评审周期同步开关:工厂级一行。
  6. /// GET 行不存在时返回 IsSyncEnabled=false 兜底;PUT 走 upsert。
  7. /// </summary>
  8. [ApiController]
  9. [Route("api/s0/sales/contract-review-cycle-sync-flag")]
  10. [AllowAnonymous]
  11. [NonUnify]
  12. public class AdoS0ContractReviewCycleSyncFlagsController : ControllerBase
  13. {
  14. private readonly SqlSugarRepository<AdoS0ContractReviewCycleSyncFlag> _rep;
  15. public AdoS0ContractReviewCycleSyncFlagsController(SqlSugarRepository<AdoS0ContractReviewCycleSyncFlag> rep)
  16. => _rep = rep;
  17. [HttpGet]
  18. public async Task<IActionResult> GetByFactoryAsync([FromQuery] long factoryRefId)
  19. {
  20. if (factoryRefId <= 0) return BadRequest(new { message = "factoryRefId 不能为空" });
  21. var entity = await _rep.AsQueryable()
  22. .Where(x => x.FactoryRefId == factoryRefId)
  23. .FirstAsync();
  24. if (entity == null)
  25. {
  26. return Ok(new AdoS0ContractReviewCycleSyncFlagDto
  27. {
  28. FactoryRefId = factoryRefId,
  29. IsSyncEnabled = false,
  30. });
  31. }
  32. return Ok(new AdoS0ContractReviewCycleSyncFlagDto
  33. {
  34. Id = entity.Id,
  35. CompanyRefId = entity.CompanyRefId,
  36. FactoryRefId = entity.FactoryRefId,
  37. DomainCode = entity.DomainCode,
  38. IsSyncEnabled = entity.IsSyncEnabled,
  39. });
  40. }
  41. [HttpPut]
  42. public async Task<IActionResult> UpsertAsync([FromBody] AdoS0ContractReviewCycleSyncFlagUpsertDto dto)
  43. {
  44. var now = DateTime.Now;
  45. var entity = await _rep.AsQueryable()
  46. .Where(x => x.FactoryRefId == dto.FactoryRefId)
  47. .FirstAsync();
  48. if (entity == null)
  49. {
  50. entity = new AdoS0ContractReviewCycleSyncFlag
  51. {
  52. CompanyRefId = dto.CompanyRefId,
  53. FactoryRefId = dto.FactoryRefId,
  54. DomainCode = dto.DomainCode,
  55. IsSyncEnabled = dto.IsSyncEnabled,
  56. CreateUser = dto.CreateUser,
  57. CreateTime = now,
  58. };
  59. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  60. }
  61. else
  62. {
  63. entity.CompanyRefId = dto.CompanyRefId;
  64. entity.DomainCode = dto.DomainCode;
  65. entity.IsSyncEnabled = dto.IsSyncEnabled;
  66. entity.UpdateUser = dto.UpdateUser;
  67. entity.UpdateTime = now;
  68. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  69. }
  70. return Ok(new AdoS0ContractReviewCycleSyncFlagDto
  71. {
  72. Id = entity.Id,
  73. CompanyRefId = entity.CompanyRefId,
  74. FactoryRefId = entity.FactoryRefId,
  75. DomainCode = entity.DomainCode,
  76. IsSyncEnabled = entity.IsSyncEnabled,
  77. });
  78. }
  79. }