AdoS0OrderPriorityRulesController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
  2. using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
  3. using Admin.NET.Plugin.AiDOP.Infrastructure;
  4. namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales;
  5. /// <summary>
  6. /// S0 订单优先级配置(PriorityCode 语义)
  7. /// </summary>
  8. [ApiController]
  9. [Route("api/s0/sales/order-priority-rules")]
  10. [AllowAnonymous]
  11. [NonUnify]
  12. public class AdoS0OrderPriorityRulesController : ControllerBase
  13. {
  14. private readonly SqlSugarRepository<AdoS0PriorityCode> _rep;
  15. public AdoS0OrderPriorityRulesController(SqlSugarRepository<AdoS0PriorityCode> rep)
  16. {
  17. _rep = rep;
  18. }
  19. [HttpGet]
  20. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0PriorityCodeQueryDto q)
  21. {
  22. (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
  23. var query = _rep.AsQueryable()
  24. .WhereIF(!string.IsNullOrWhiteSpace(q.DomainCode), x => x.DomainCode == q.DomainCode)
  25. .WhereIF(!string.IsNullOrWhiteSpace(q.Descr), x => x.Descr.Contains(q.Descr!))
  26. .WhereIF(q.Priority.HasValue, x => x.Priority == q.Priority.Value)
  27. .WhereIF(q.OrderBy.HasValue, x => x.OrderBy == q.OrderBy.Value)
  28. .WhereIF(!string.IsNullOrWhiteSpace(q.SourceTable), x => x.SourceTable != null && x.SourceTable.Contains(q.SourceTable!))
  29. .WhereIF(!string.IsNullOrWhiteSpace(q.SourceColumn), x => x.SourceColumn != null && x.SourceColumn.Contains(q.SourceColumn!))
  30. .WhereIF(!string.IsNullOrWhiteSpace(q.Value), x => x.Value != null && x.Value.Contains(q.Value!))
  31. .WhereIF(q.IsActive.HasValue, x => x.IsActive == q.IsActive.Value)
  32. .WhereIF(
  33. !string.IsNullOrWhiteSpace(q.Keyword),
  34. x => x.Descr.Contains(q.Keyword!) ||
  35. (x.SourceTable != null && x.SourceTable.Contains(q.Keyword!)) ||
  36. (x.Value != null && x.Value.Contains(q.Keyword!)));
  37. var total = await query.CountAsync();
  38. var list = await query
  39. .OrderByDescending(x => x.CreateTime)
  40. .Skip((q.Page - 1) * q.PageSize)
  41. .Take(q.PageSize)
  42. .ToListAsync();
  43. foreach (var x in list)
  44. x.OrderByText = AdoS0SalesRules.PriorityCodeOrderByText(x.OrderBy);
  45. return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
  46. }
  47. [HttpGet("{id}")]
  48. public async Task<IActionResult> GetAsync(string id)
  49. {
  50. var item = await _rep.GetByIdAsync(id);
  51. if (item == null) return NotFound();
  52. item.OrderByText = AdoS0SalesRules.PriorityCodeOrderByText(item.OrderBy);
  53. return Ok(item);
  54. }
  55. [HttpPost]
  56. public async Task<IActionResult> CreateAsync([FromBody] AdoS0PriorityCodeUpsertDto dto)
  57. {
  58. var now = DateTime.Now;
  59. var entity = new AdoS0PriorityCode
  60. {
  61. Id = Guid.NewGuid().ToString("D").ToUpperInvariant(),
  62. DomainCode = dto.DomainCode,
  63. Descr = dto.Descr ?? string.Empty,
  64. Value = dto.Value,
  65. Priority = dto.Priority,
  66. OrderBy = dto.OrderBy,
  67. SourceTable = dto.SourceTable,
  68. SourceColumn = dto.SourceColumn,
  69. SourceType = dto.SourceType,
  70. SourceId = dto.SourceId,
  71. ValueType = dto.ValueType,
  72. ValueId = dto.ValueId,
  73. CustomerTypeCode = dto.CustomerTypeCode,
  74. OrderTypeCode = dto.OrderTypeCode,
  75. IsActive = dto.IsActive,
  76. CreateUser = dto.CreateUser,
  77. LegacyCreateUser = dto.LegacyCreateUser,
  78. CreateTime = now,
  79. UpdateUser = dto.UpdateUser,
  80. UpdateTime = null
  81. };
  82. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  83. return Ok(entity);
  84. }
  85. [HttpPut("{id}")]
  86. public async Task<IActionResult> UpdateAsync(string id, [FromBody] AdoS0PriorityCodeUpsertDto dto)
  87. {
  88. var entity = await _rep.GetByIdAsync(id);
  89. if (entity == null) return NotFound();
  90. entity.DomainCode = dto.DomainCode;
  91. entity.Descr = dto.Descr ?? string.Empty;
  92. entity.Value = dto.Value;
  93. entity.Priority = dto.Priority;
  94. entity.OrderBy = dto.OrderBy;
  95. entity.SourceTable = dto.SourceTable;
  96. entity.SourceColumn = dto.SourceColumn;
  97. entity.SourceType = dto.SourceType;
  98. entity.SourceId = dto.SourceId;
  99. entity.ValueType = dto.ValueType;
  100. entity.ValueId = dto.ValueId;
  101. entity.CustomerTypeCode = dto.CustomerTypeCode;
  102. entity.OrderTypeCode = dto.OrderTypeCode;
  103. entity.IsActive = dto.IsActive;
  104. entity.UpdateUser = dto.UpdateUser;
  105. entity.LegacyCreateUser = dto.LegacyCreateUser;
  106. entity.UpdateTime = DateTime.Now;
  107. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  108. return Ok(entity);
  109. }
  110. [HttpPatch("{id}/toggle-enabled")]
  111. public async Task<IActionResult> ToggleActiveAsync(string id, [FromBody] AdoS0PriorityCodeToggleActiveDto dto)
  112. {
  113. var entity = await _rep.GetByIdAsync(id);
  114. if (entity == null) return NotFound();
  115. entity.IsActive = dto.IsActive;
  116. entity.UpdateTime = DateTime.Now;
  117. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  118. return Ok(entity);
  119. }
  120. [HttpDelete("{id}")]
  121. public async Task<IActionResult> DeleteAsync(string id)
  122. {
  123. var item = await _rep.GetByIdAsync(id);
  124. if (item == null) return NotFound();
  125. await _rep.DeleteAsync(item);
  126. return Ok(new { message = "删除成功" });
  127. }
  128. }