AdoS0OrderPriorityRulesController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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(q.CompanyRefId.HasValue, x => x.CompanyRefId == q.CompanyRefId.Value)
  25. .WhereIF(q.FactoryRefId.HasValue, x => x.FactoryRefId == q.FactoryRefId.Value)
  26. .WhereIF(!string.IsNullOrWhiteSpace(q.DomainCode), x => x.DomainCode == q.DomainCode)
  27. .WhereIF(!string.IsNullOrWhiteSpace(q.Descr), x => x.Descr.Contains(q.Descr!))
  28. .WhereIF(q.Priority.HasValue, x => x.Priority == q.Priority.Value)
  29. .WhereIF(!string.IsNullOrWhiteSpace(q.SourceTable), x => x.SourceTable != null && x.SourceTable.Contains(q.SourceTable!))
  30. .WhereIF(!string.IsNullOrWhiteSpace(q.SourceColumn), x => x.SourceColumn != null && x.SourceColumn.Contains(q.SourceColumn!))
  31. .WhereIF(!string.IsNullOrWhiteSpace(q.Value), x => x.Value != null && x.Value.Contains(q.Value!))
  32. .WhereIF(q.IsActive.HasValue, x => x.IsActive == q.IsActive.Value)
  33. .WhereIF(
  34. !string.IsNullOrWhiteSpace(q.Keyword),
  35. x => x.Descr.Contains(q.Keyword!) ||
  36. (x.SourceTable != null && x.SourceTable.Contains(q.Keyword!)) ||
  37. (x.Value != null && x.Value.Contains(q.Keyword!)));
  38. var total = await query.CountAsync();
  39. var list = await query
  40. .OrderByDescending(x => x.CreateTime)
  41. .Skip((q.Page - 1) * q.PageSize)
  42. .Take(q.PageSize)
  43. .ToListAsync();
  44. foreach (var x in list)
  45. x.OrderByText = AdoS0SalesRules.PriorityCodeOrderByText(x.OrderByCode);
  46. return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
  47. }
  48. [HttpGet("{id:long}")]
  49. public async Task<IActionResult> GetAsync(long id)
  50. {
  51. var item = await _rep.GetByIdAsync(id);
  52. if (item == null) return NotFound();
  53. item.OrderByText = AdoS0SalesRules.PriorityCodeOrderByText(item.OrderByCode);
  54. return Ok(item);
  55. }
  56. [HttpPost]
  57. public async Task<IActionResult> CreateAsync([FromBody] AdoS0PriorityCodeUpsertDto dto)
  58. {
  59. var now = DateTime.Now;
  60. var entity = new AdoS0PriorityCode
  61. {
  62. CompanyRefId = dto.CompanyRefId,
  63. FactoryRefId = dto.FactoryRefId,
  64. DomainCode = dto.DomainCode,
  65. Descr = dto.Descr,
  66. Value = dto.Value,
  67. Priority = dto.Priority,
  68. OrderByCode = dto.OrderByCode,
  69. SourceTable = dto.SourceTable,
  70. SourceColumn = dto.SourceColumn,
  71. SourceType = dto.SourceType,
  72. SourceId = dto.SourceId,
  73. ValueType = dto.ValueType,
  74. ValueId = dto.ValueId,
  75. IsActive = dto.IsActive,
  76. CreateUser = dto.CreateUser,
  77. CreateTime = now,
  78. UpdateUser = dto.UpdateUser,
  79. UpdateTime = null
  80. };
  81. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  82. return Ok(entity);
  83. }
  84. [HttpPut("{id:long}")]
  85. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0PriorityCodeUpsertDto dto)
  86. {
  87. var entity = await _rep.GetByIdAsync(id);
  88. if (entity == null) return NotFound();
  89. entity.CompanyRefId = dto.CompanyRefId;
  90. entity.FactoryRefId = dto.FactoryRefId;
  91. entity.DomainCode = dto.DomainCode;
  92. entity.Descr = dto.Descr;
  93. entity.Value = dto.Value;
  94. entity.Priority = dto.Priority;
  95. entity.OrderByCode = dto.OrderByCode;
  96. entity.SourceTable = dto.SourceTable;
  97. entity.SourceColumn = dto.SourceColumn;
  98. entity.SourceType = dto.SourceType;
  99. entity.SourceId = dto.SourceId;
  100. entity.ValueType = dto.ValueType;
  101. entity.ValueId = dto.ValueId;
  102. entity.IsActive = dto.IsActive;
  103. entity.UpdateUser = dto.UpdateUser;
  104. entity.UpdateTime = DateTime.Now;
  105. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  106. return Ok(entity);
  107. }
  108. [HttpPatch("{id:long}/toggle-enabled")]
  109. public async Task<IActionResult> ToggleActiveAsync(long id, [FromBody] AdoS0PriorityCodeToggleActiveDto dto)
  110. {
  111. var entity = await _rep.GetByIdAsync(id);
  112. if (entity == null) return NotFound();
  113. entity.IsActive = dto.IsActive;
  114. entity.UpdateTime = DateTime.Now;
  115. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  116. return Ok(entity);
  117. }
  118. [HttpDelete("{id:long}")]
  119. public async Task<IActionResult> DeleteAsync(long id)
  120. {
  121. var item = await _rep.GetByIdAsync(id);
  122. if (item == null) return NotFound();
  123. await _rep.DeleteAsync(item);
  124. return Ok(new { message = "删除成功" });
  125. }
  126. }