OrganizationRepository.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using AutoMapper;
  4. using Datory;
  5. using GxPress.Common.AppOptions;
  6. using GxPress.Common.Page;
  7. using GxPress.Common.Tools;
  8. using GxPress.Repository.Interface.Organization;
  9. using GxPress.Result.Organization;
  10. using Microsoft.Extensions.Options;
  11. using System;
  12. namespace GxPress.Repository.Implement.Organization
  13. {
  14. public class OrganizationRepository : IOrganizationRepository
  15. {
  16. private readonly Repository<Entity.tede2.Organization.Organization> _repository;
  17. private readonly IMapper _mapper;
  18. private readonly string _connectionString;
  19. private readonly string _databaseTypestr;
  20. public OrganizationRepository(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.Organization.Organization>(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. /// <summary>
  33. /// 机构列表
  34. /// </summary>
  35. /// <param name="request"></param>
  36. /// <returns></returns>
  37. public async Task<PagedList<Entity.tede2.Organization.Organization>> GetAllAsync(OrganizationListRequest request)
  38. {
  39. var result = new PagedList<Entity.tede2.Organization.Organization>();
  40. var query = Q.NewQuery();
  41. if (!string.IsNullOrEmpty(request.KeyWord))
  42. query.WhereLike(nameof(Entity.tede2.Organization.Organization.Name), $"%{request.KeyWord}%");
  43. result.Total = await _repository.CountAsync(query);
  44. result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.Organization.Organization.CreatedDate)).ForPage(request.Page, request.PerPage));
  45. return result;
  46. }
  47. /// <summary>
  48. /// 修改
  49. /// </summary>
  50. /// <param name="request"></param>
  51. /// <returns></returns>
  52. public async Task<bool> UpdateAsync(OrganizationUpdateRequest request)
  53. {
  54. var organization = await _repository.GetAsync(request.Id);
  55. if (request.IsClose > 0)
  56. organization.IsClose = request.IsClose == 1;
  57. if (request.IsDisable > 0)
  58. organization.IsDisable = request.IsDisable == 1;
  59. if (request.FacilityCount > 0)
  60. organization.FacilityCount = request.FacilityCount;
  61. if (!string.IsNullOrEmpty(request.LinkName))
  62. organization.LinkName = request.LinkName;
  63. if (!string.IsNullOrEmpty(request.LinkPhone))
  64. organization.LinkPhone = request.LinkPhone;
  65. if (!string.IsNullOrEmpty(request.Address))
  66. organization.Address = request.Address;
  67. if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
  68. {
  69. organization.BeginTime = Convert.ToDateTime(request.BeginTime);
  70. organization.EndTime = Convert.ToDateTime(request.EndTime);
  71. }
  72. if (!string.IsNullOrEmpty(request.OpenTime))
  73. organization.OpenTime = Convert.ToDateTime(request.OpenTime);
  74. if (request.OpenStatus > 0)
  75. organization.OpenStatus = request.OpenStatus;
  76. return await _repository.UpdateAsync(organization);
  77. }
  78. /// <summary>
  79. /// 删除
  80. /// </summary>
  81. /// <param name="request"></param>
  82. /// <returns></returns>
  83. public async Task<bool> DeleteAsync(List<int> ids)
  84. {
  85. return await _repository.DeleteAsync(Q.WhereIn(nameof(Entity.tede2.Organization.Organization.Id), ids)) > 0;
  86. }
  87. /// <summary>
  88. /// 修改
  89. /// </summary>
  90. /// <param name="request"></param>
  91. /// <returns></returns>
  92. public async Task<bool> UpdateIsDisableAsync(OrganizationUpdateDisableRequest request)
  93. {
  94. return await _repository.UpdateAsync(Q.WhereIn(nameof(Entity.tede2.Organization.Organization.Id), request.Ids).Set(nameof(Entity.tede2.Organization.Organization.IsDisable), request.IsDisable)) > 0;
  95. }
  96. /// <summary>
  97. /// 添加
  98. /// </summary>
  99. /// <param name="request"></param>
  100. /// <returns></returns>
  101. public async Task<bool> InsertAsync(Entity.tede2.Organization.Organization model)
  102. {
  103. return await _repository.InsertAsync(model) > 0;
  104. }
  105. }
  106. }