| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales;
- /// <summary>
- /// S0 选择替代方案(源平台 ic_substitute;只读查询模型)
- /// </summary>
- [ApiController]
- [Route("api/s0/sales/substitute-schemes")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0SubstituteSchemesController : ControllerBase
- {
- private const long BlankRowId = 1000000000000000001L;
- private readonly SqlSugarRepository<IcSubstitute> _rep;
- public AdoS0SubstituteSchemesController(SqlSugarRepository<IcSubstitute> rep)
- {
- _rep = rep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0SubstituteSchemeQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(q.CompanyId.HasValue, x => x.CompanyId == q.CompanyId.Value)
- .WhereIF(q.FactoryId.HasValue, x => x.FactoryId == q.FactoryId.Value)
- .WhereIF(!string.IsNullOrWhiteSpace(q.SubstituteCode),
- x => x.SubstituteCode != null && x.SubstituteCode.Contains(q.SubstituteCode!))
- .WhereIF(true, x => x.IsDeleted == null || x.IsDeleted == 0);
- var total = await query.CountAsync();
- var list = await query
- .OrderByDescending(x => x.CreateTime)
- .Skip((q.Page - 1) * q.PageSize)
- .Take(q.PageSize)
- .ToListAsync();
- // 源平台:固定空白记录 UNION;这里在查询层拼装,避免落库。
- var blank = new IcSubstitute
- {
- Id = BlankRowId,
- SubstituteCode = string.Empty,
- SubstituteStrategy = null,
- SubstituteMode = null,
- CreateTime = null,
- CompanyId = q.CompanyId,
- FactoryId = q.FactoryId,
- IsDeleted = 0
- };
- list.Insert(0, blank);
- return Ok(new { total = total + 1, page = q.Page, pageSize = q.PageSize, list });
- }
- }
|