using OASystem.Domain.Dtos.Resource; using OASystem.Domain.Entities.District; using OASystem.Domain.Entities.Resource; using OASystem.Domain.Entities.System; using OASystem.Domain.ViewModels.Resource; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OASystem.Infrastructure.Repositories.Resource { public class MaterialCostRepository : BaseRepository { public MaterialCostRepository(SqlSugarClient sqlSugar) : base(sqlSugar) { } /// /// 获取物料成本分页列表 /// /// /// public async Task GetListAsync(QueryMaterialCostDto dto) { var query = _sqlSugar.Queryable((m, s, c) => new JoinQueryInfos( JoinType.Left, m.SetDataId == s.Id, JoinType.Left, m.CityId == c.Id )) .Where((m, s, c) => m.IsDel == 0); if (dto.TypeId.HasValue && dto.TypeId > 0) query = query.Where((m, s, c) => m.TypeId == dto.TypeId.Value); if (!string.IsNullOrEmpty(dto.Name)) query = query.Where((m, s, c) => m.Name.Contains(dto.Name)); if (dto.SetDataId.HasValue && dto.SetDataId > 0) query = query.Where((m, s, c) => m.SetDataId == dto.SetDataId.Value); if (dto.CityId.HasValue && dto.CityId > 0) query = query.Where((m, s, c) => m.CityId == dto.CityId.Value); int totalCount = 0; var list = await query.OrderBy((m, s, c) => m.Id, OrderByType.Desc) .Select((m, s, c) => new MaterialCostView { Id = m.Id, TypeId = m.TypeId, Name = m.Name, Price = m.Price, Number = m.Number, Unit = m.Unit, SetDataId = m.SetDataId, SetDataName = s.Name, CityId = m.CityId, CityName = c.CnName, Remark = m.Remark, CreateTime = m.CreateTime }) .ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount); return new MaterialCostListView { DataList = list, DataCount = totalCount, CurrPageIndex = dto.PageIndex, CurrPageSize = dto.PageSize }; } /// /// 获取单条详情 /// /// /// public async Task GetDetailAsync(int id) { return await _sqlSugar.Queryable((m, s, c) => new JoinQueryInfos( JoinType.Left, m.SetDataId == s.Id, JoinType.Left, m.CityId == c.Id )) .Where((m, s, c) => m.Id == id && m.IsDel == 0) .Select((m, s, c) => new MaterialCostView { Id = m.Id, TypeId = m.TypeId, Name = m.Name, Price = m.Price, Number = m.Number, Unit = m.Unit, SetDataId = m.SetDataId, SetDataName = s.Name, CityId = m.CityId, CityName = c.CnName, Remark = m.Remark, CreateTime = m.CreateTime }) .FirstAsync(); } } }