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; /// /// S0 选择替代方案(源平台 ic_substitute;只读查询模型) /// [ApiController] [Route("api/s0/sales/substitute-schemes")] [AllowAnonymous] [NonUnify] public class AdoS0SubstituteSchemesController : ControllerBase { private const long BlankRowId = 1000000000000000001L; private readonly SqlSugarRepository _rep; public AdoS0SubstituteSchemesController(SqlSugarRepository rep) { _rep = rep; } [HttpGet] public async Task 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 }); } }