AdoS0SubstituteSchemesController.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. [AllowAnonymous]
  11. [NonUnify]
  12. public class AdoS0SubstituteSchemesController : ControllerBase
  13. {
  14. private const long BlankRowId = 1000000000000000001L;
  15. private readonly SqlSugarRepository<IcSubstitute> _rep;
  16. public AdoS0SubstituteSchemesController(SqlSugarRepository<IcSubstitute> rep)
  17. {
  18. _rep = rep;
  19. }
  20. [HttpGet]
  21. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0SubstituteSchemeQueryDto q)
  22. {
  23. (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
  24. var query = _rep.AsQueryable()
  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. Id = BlankRowId,
  40. SubstituteCode = string.Empty,
  41. SubstituteStrategy = null,
  42. SubstituteMode = null,
  43. CreateTime = null,
  44. CompanyId = q.CompanyId,
  45. FactoryId = q.FactoryId,
  46. IsDeleted = 0
  47. };
  48. list.Insert(0, blank);
  49. return Ok(new { total = total + 1, page = q.Page, pageSize = q.PageSize, list });
  50. }
  51. }