VipEquityRepository.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using AutoMapper;
  5. using Datory;
  6. using GxPress.Common.AppOptions;
  7. using GxPress.Common.Tools;
  8. using GxPress.Repository.Interface.VipEquity;
  9. using GxPress.Request.VipEquity;
  10. using GxPress.Result.VipEquity;
  11. using Microsoft.Extensions.Options;
  12. namespace GxPress.Repository.Implement.VipEquity
  13. {
  14. public class VipEquityRepository : IVipEquityRepository
  15. {
  16. private readonly Repository<Entity.tede2.VipEquity.VipEquity> _repository;
  17. private readonly IMapper _mapper;
  18. private readonly string _connectionString;
  19. private readonly string _databaseTypestr;
  20. public VipEquityRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  21. {
  22. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  23. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  24. var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  25. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  26. _repository = new Repository<Entity.tede2.VipEquity.VipEquity>(database);
  27. _mapper = mapper;
  28. }
  29. public IDatabase Database => _repository.Database;
  30. public string TableName => _repository.TableName;
  31. public List<TableColumn> TableColumns => _repository.TableColumns;
  32. public async Task<IEnumerable<VipEquityResult>> GetAllAsync()
  33. {
  34. var result = await _repository.GetAllAsync(Q.OrderByDesc(nameof(Entity.tede2.VipEquity.VipEquity.CreatedDate)));
  35. var items = result.Select(n => _mapper.Map<VipEquityResult>(n)).ToList();
  36. foreach (var item in items)
  37. {
  38. item.VipTypeValue = ((GxPress.EnumConst.VipCardTypeConst)item.VipType).GetDescriptionOriginal();
  39. }
  40. return items;
  41. }
  42. public async Task<bool> UpdateAsync(VipEquityUpdateRequest request)
  43. {
  44. var model = await _repository.GetAsync(request.Id);
  45. if (request.IosPrice > 0)
  46. model.IosPrice = request.IosPrice;
  47. if (request.OtherPrice > 0)
  48. model.OtherPrice = request.OtherPrice;
  49. if (request.VipType > 0)
  50. model.VipType = request.VipType;
  51. return await _repository.UpdateAsync(model);
  52. }
  53. public async Task<bool> InsertAsync(Entity.tede2.VipEquity.VipEquity model)
  54. {
  55. return await _repository.InsertAsync(model) > 0;
  56. }
  57. /// <summary>
  58. /// 根据Id删除
  59. /// </summary>
  60. /// <param name="id"></param>
  61. /// <returns></returns>
  62. public async Task<bool> DeleteAsync(int id)
  63. {
  64. return await _repository.DeleteAsync(id);
  65. }
  66. /// <summary>
  67. /// 查询
  68. /// </summary>
  69. /// <param name="id"></param>
  70. /// <returns></returns>
  71. public async Task<Entity.tede2.VipEquity.VipEquity> GetAsync(int id)
  72. {
  73. return await _repository.GetAsync(id);
  74. }
  75. /// <summary>
  76. /// 查询1 月 2 季度 3 年 4连续月
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <returns></returns>
  80. public async Task<Entity.tede2.VipEquity.VipEquity> GetByVipTypeAsync(int vipType)
  81. {
  82. return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.VipEquity.VipEquity.VipType),vipType));
  83. }
  84. }
  85. }