MediaLibraryRepository.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using AutoMapper;
  6. using Datory;
  7. using GxPress.Common.AppOptions;
  8. using GxPress.Common.Tools;
  9. using GxPress.Repository.Interface.Media;
  10. using GxPress.Result.Media;
  11. using Microsoft.Extensions.Options;
  12. namespace GxPress.Repository.Implement.Media
  13. {
  14. public class MediaLibraryRepository : IMediaLibraryRepository
  15. {
  16. private readonly Repository<Entity.tede2.Media.MediaLibrary> _repository;
  17. private readonly IMapper _mapper;
  18. private readonly string _connectionString;
  19. private readonly string _databaseTypestr;
  20. public MediaLibraryRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  21. {
  22. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  23. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  24. var databaseType =
  25. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  26. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  27. _repository = new Repository<Entity.tede2.Media.MediaLibrary>(database);
  28. _mapper = mapper;
  29. }
  30. public IDatabase Database => _repository.Database;
  31. public string TableName => _repository.TableName;
  32. public List<TableColumn> TableColumns => _repository.TableColumns;
  33. public async Task<Entity.tede2.Media.MediaLibrary> GetTaskAsync(int mediaId)
  34. {
  35. return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 1));
  36. }
  37. public async Task<Entity.tede2.Media.MediaLibrary> GetAsync(int id)
  38. {
  39. return await _repository.GetAsync(id);
  40. }
  41. /// <summary>
  42. /// 获取视频
  43. /// </summary>
  44. /// <param name="mediaId"></param>
  45. /// <param name="TypeId"></param>
  46. /// <returns></returns>
  47. public async Task<List<MediaLibraryResult>> GetAllAsync(int mediaId)
  48. {
  49. var selectColumn = new List<string>();
  50. selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.Id));
  51. selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.Name));
  52. selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.MediaId));
  53. var result = await _repository.GetAllAsync<MediaLibraryResult>(Q.Select(selectColumn.ToArray()).Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 0));
  54. return result.Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
  55. }
  56. }
  57. }