using System; 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.Request.OrganizationUser; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.Organization { public class OrganizationUserRepository : IOrganizationUserRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public OrganizationUserRepository(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> GetSearchAllAsync(OrganizationUserSearchRequest request) { var query = Q.NewQuery(); if (!string.IsNullOrEmpty(request.KeyWord)) { query.Where(n => n.OrWhereLike(nameof(Entity.tede2.Organization.OrganizationUser.UserName), $"%request.KeyWord%"). OrWhereLike(nameof(Entity.tede2.Organization.OrganizationUser.LoginAccountNumber), $"%request.KeyWord%")); } if (request.OrganizationId > 0) query.Where(nameof(Entity.tede2.Organization.OrganizationUser.OrganizationId), request.OrganizationId); var result = new PagedList(); result.Total = await _repository.CountAsync(query); result.Items = await _repository.GetAllAsync(query); return result; } public async Task UpdateAsync(OrganizationUserUpdateRequest request) { var model = await _repository.GetAsync(request.Id); if (!string.IsNullOrEmpty(request.LoginAccountNumber)) model.LoginAccountNumber = request.LoginAccountNumber; if (!string.IsNullOrEmpty(request.UserName)) model.UserName = request.UserName; if (!string.IsNullOrEmpty(request.Phone)) model.Phone = request.Phone; if (!string.IsNullOrEmpty(request.MacAddress)) model.MacAddress = request.MacAddress; if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime)) { if (DateTime.TryParse(request.BeginTime, out var beginTme) && DateTime.TryParse(request.EndTime, out var endTime)) { model.BeginTime = beginTme; model.EndTime = endTime; } } if (!string.IsNullOrEmpty(request.OpenTime)) { if (DateTime.TryParse(request.BeginTime, out var OpenTime)) model.OpenTime = OpenTime; } if (request.OpenStatus > 0) model.OpenStatus = request.OpenStatus; if (request.IsClose > 0) model.IsClose = request.IsClose == 1; if (request.IsDisable > 0) model.IsDisable = request.IsDisable == 1; if (request.OrganizationId > 0) model.OrganizationId = request.OrganizationId; return await _repository.UpdateAsync(model); } public async Task InsertAsync(Entity.tede2.Organization.OrganizationUser model) { return await _repository.InsertAsync(model) > 0; } public async Task> GetAllAsync(List ids) { var list = await _repository.GetAllAsync(Q.WhereIn(nameof(Entity.tede2.Organization.OrganizationUser.Id), ids)); return list; } public async Task DeleteAsync(List ids) { return await _repository.DeleteAsync(Q.WhereIn(nameof(Entity.tede2.Organization.OrganizationUser.Id), ids)) > 0; } public async Task UpdateDisableAsync(OrganizationUserDisableUpdateRequest request) { return await _repository.UpdateAsync(Q.WhereIn(nameof(Entity.tede2.Organization.OrganizationUser.Id), request.Ids).Set(nameof(Entity.tede2.Organization.OrganizationUser.IsDisable), request.IsDisable)) > 0; } } }