using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Page; using GxPress.Common.Tools; using GxPress.Repository.Interface.Organization; using GxPress.Result.Organization; using Microsoft.Extensions.Options; using System; namespace GxPress.Repository.Implement.Organization { public class OrganizationRepository : IOrganizationRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public OrganizationRepository(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> GetAllAsync(OrganizationListRequest request) { var result = new PagedList(); var query = Q.NewQuery(); if (!string.IsNullOrEmpty(request.KeyWord)) query.WhereLike(nameof(Entity.tede2.Organization.Organization.Name), $"%{request.KeyWord}%"); result.Total = await _repository.CountAsync(query); result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.Organization.Organization.CreatedDate)).ForPage(request.Page, request.PerPage)); return result; } /// /// 修改 /// /// /// public async Task UpdateAsync(OrganizationUpdateRequest request) { var organization = await _repository.GetAsync(request.Id); if (request.IsClose > 0) organization.IsClose = request.IsClose == 1; if (request.IsDisable > 0) organization.IsDisable = request.IsDisable == 1; if (request.FacilityCount > 0) organization.FacilityCount = request.FacilityCount; if (!string.IsNullOrEmpty(request.LinkName)) organization.LinkName = request.LinkName; if (!string.IsNullOrEmpty(request.LinkPhone)) organization.LinkPhone = request.LinkPhone; if (!string.IsNullOrEmpty(request.Address)) organization.Address = request.Address; if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime)) { organization.BeginTime = Convert.ToDateTime(request.BeginTime); organization.EndTime = Convert.ToDateTime(request.EndTime); } if (!string.IsNullOrEmpty(request.OpenTime)) organization.OpenTime = Convert.ToDateTime(request.OpenTime); if (request.OpenStatus > 0) organization.OpenStatus = request.OpenStatus; return await _repository.UpdateAsync(organization); } /// /// 删除 /// /// /// public async Task DeleteAsync(List ids) { return await _repository.DeleteAsync(Q.WhereIn(nameof(Entity.tede2.Organization.Organization.Id), ids)) > 0; } /// /// 修改 /// /// /// public async Task UpdateIsDisableAsync(OrganizationUpdateDisableRequest request) { return await _repository.UpdateAsync(Q.WhereIn(nameof(Entity.tede2.Organization.Organization.Id), request.Ids).Set(nameof(Entity.tede2.Organization.Organization.IsDisable), request.IsDisable)) > 0; } /// /// 添加 /// /// /// public async Task InsertAsync(Entity.tede2.Organization.Organization model) { return await _repository.InsertAsync(model) > 0; } } }