AdoS0OrderPriorityRulesController.cs 6.2 KB

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