using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Repository.Interface.Media; using GxPress.Result.Media; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.Media { public class MediaLibraryRepository : IMediaLibraryRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public MediaLibraryRepository(IOptionsMonitor dbOptionsAccessor, IMapper mapper) { _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType; _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString; var databaseType = StringUtils.ToEnum(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql); var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString); _repository = new Repository(database); _mapper = mapper; } public IDatabase Database => _repository.Database; public string TableName => _repository.TableName; public List TableColumns => _repository.TableColumns; public async Task GetTaskAsync(int mediaId) { return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 1)); } public async Task GetAsync(int id) { return await _repository.GetAsync(id); } /// /// 获取视频 /// /// /// /// public async Task> GetAllAsync(int mediaId) { var selectColumn = new List(); selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.Id)); selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.Name)); selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.MediaId)); var result = await _repository.GetAllAsync(Q.Select(selectColumn.ToArray()).Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 0)); return result.Select(n => _mapper.Map(n)).ToList(); } } }