AdoS0SubstituteSchemesController.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 选择替代方案(源平台 ic_substitute;只读查询模型)
  7. /// </summary>
  8. [ApiController]
  9. [Route("api/s0/sales/substitute-schemes")]
  10. [NonUnify]
  11. public class AdoS0SubstituteSchemesController : ControllerBase
  12. {
  13. private const long BlankRowId = 1000000000000000001L;
  14. private readonly SqlSugarRepository<IcSubstitute> _rep;
  15. public AdoS0SubstituteSchemesController(SqlSugarRepository<IcSubstitute> rep)
  16. {
  17. _rep = rep;
  18. }
  19. [HttpGet]
  20. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0SubstituteSchemeQueryDto q)
  21. {
  22. if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
  23. (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
  24. var query = _rep.ScopedTo(tenantId)
  25. .WhereIF(q.CompanyId.HasValue, x => x.CompanyId == q.CompanyId.Value)
  26. .WhereIF(q.FactoryId.HasValue, x => x.FactoryId == q.FactoryId.Value)
  27. .WhereIF(!string.IsNullOrWhiteSpace(q.SubstituteCode),
  28. x => x.SubstituteCode != null && x.SubstituteCode.Contains(q.SubstituteCode!))
  29. .WhereIF(true, x => x.IsDeleted == null || x.IsDeleted == 0);
  30. var total = await query.CountAsync();
  31. var list = await query
  32. .OrderByDescending(x => x.CreateTime)
  33. .Skip((q.Page - 1) * q.PageSize)
  34. .Take(q.PageSize)
  35. .ToListAsync();
  36. // 源平台:固定空白记录 UNION;这里在查询层拼装,避免落库。
  37. var blank = new IcSubstitute
  38. {
  39. TenantId = tenantId,
  40. Id = BlankRowId,
  41. SubstituteCode = string.Empty,
  42. SubstituteStrategy = null,
  43. SubstituteMode = null,
  44. CreateTime = null,
  45. CompanyId = q.CompanyId,
  46. FactoryId = q.FactoryId,
  47. IsDeleted = 0
  48. };
  49. list.Insert(0, blank);
  50. return Ok(new { total = total + 1, page = q.Page, pageSize = q.PageSize, list });
  51. }
  52. }