123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using AutoMapper;
- using Dapper;
- using Datory;
- using GxPress.Common.AppOptions;
- using GxPress.Common.Tools;
- using GxPress.Entity;
- using GxPress.EnumConst;
- using GxPress.Repository.Interface.AdminVerify;
- using Microsoft.Extensions.Options;
- using SqlKata;
- namespace GxPress.Repository.Implement.AdminVerify
- {
- public class AdminVerifyRepository : IAdminVerifyRepository
- {
- private readonly Repository<Entity.AdminVerify> _repository;
- private readonly IMapper _mapper;
- private readonly string _connectionString;
- private readonly string _databaseTypeStr;
- private readonly Repository<GroupUser> _groupUserRepository;
- public AdminVerifyRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
- {
- _databaseTypeStr = dbOptionsAccessor.CurrentValue.DatabaseType;
- _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
- var databaseType =
- StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
- var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
- _repository = new Repository<Entity.AdminVerify>(database);
- _groupUserRepository = new Repository<GroupUser>(database);
- _mapper = mapper;
- }
- public IDatabase Database => _repository.Database;
- public string TableName => _repository.TableName;
- public List<TableColumn> TableColumns => _repository.TableColumns;
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="adminVerify"></param>
- /// <returns></returns>
- public async Task<int> InsertAsync(Entity.AdminVerify adminVerify)
- {
- return await _repository.InsertAsync(adminVerify);
- }
- public async Task<bool> InsertAsync(List<Entity.AdminVerify> adminVerifys)
- {
- string sql = @"INSERT INTO `tede_admin_verify`(`Guid`,`CreatedDate`,`LastModifiedDate`,`VerifyType`,`DisposeType`,
- `AdminId`,`UserId`,`SourceId`,`Name`,`AvatarUrl`,`Remark`,`SourceType`,`SourceName`,`IsDelete`)VALUES";
- if (adminVerifys.Count == 0)
- return false;
- var sqlValue = "";
- foreach (var item in adminVerifys)
- {
- var guId = Guid.NewGuid().ToString();
- var createdDate = DateTime.Now.ToString();
- sqlValue += $@"('{guId}','{createdDate}','{createdDate}',{item.VerifyType.GetHashCode()},{item.DisposeType},{item.AdminId},{item.UserId},{item.SourceId},'{item.Name}','{item.AvatarUrl}','{item.Remark}',{item.SourceType},'{item.SourceName}','{item.IsDelete}'),";
- }
- sql = sql + sqlValue.Remove(sqlValue.Length - 1, 1);
- var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
- var database = new Database(databaseType, _connectionString);
- var connection = database.GetConnection();
- var result = await connection.ExecuteAsync(sql);
- return result > 0;
- }
- /// <summary>
- /// 清空
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="phone"></param>
- /// <returns></returns>
- public async Task<bool> DeleteAllAsync(int userId)
- {
- return await _repository.DeleteAsync(Q.Where(nameof(Entity.AdminVerify.AdminId), userId)) > 0;
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="id"></param>
- /// <param name="disposeTyeConst"></param>
- /// <returns></returns>
- public async Task<bool> UpdateAsync(int id, AdminVerifyTypeConst disposeTyeConst)
- {
- return await _repository.UpdateAsync(Q.Set(nameof(Entity.AdminVerify.DisposeType), disposeTyeConst).Where(nameof(Entity.AdminVerify.Id), id)) > 0;
- }
- /// <summary>
- /// 根据ID查询
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<Entity.AdminVerify> GetAsync(int id)
- {
- return await _repository.GetAsync(id);
- }
- /// <summary>
- /// 根据ID查询
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<Entity.AdminVerify> GetAsync(SqlKata.Query query)
- {
- return await _repository.GetAsync(query);
- }
- /// <summary>
- /// 根据用户查询
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="phone"></param>
- /// <returns></returns>
- public async Task<IEnumerable<Entity.AdminVerify>> GetAllAsync(SqlKata.Query query)
- {
- return await _repository.GetAllAsync(query);
- }
- /// <summary>
- /// 查询未处理
- /// </summary>
- /// <param name="userId"></param>
- /// <returns></returns>
- public async Task<int> GetUDisposeCount(int userId)
- {
- return await _repository.CountAsync(Q.Where(nameof(Entity.AdminVerify.AdminId), userId).Where(nameof(Entity.AdminVerify.DisposeType), AdminVerifyTypeConst.UDispose));
- }
- public async Task<bool> UpdateAsync(Query query)
- {
- return await _repository.UpdateAsync(query) > 0;
- }
- /// <summary>
- /// 获取用户的验证时间信息
- /// </summary>
- /// <param name="userId"></param>
- /// <returns></returns>
- public async Task<string> GetConfirmationDate(int userId)
- {
- var query = Q.NewQuery();
- query.Select(nameof(Entity.AdminVerify.CreatedDate));
- query.Where(nameof(Entity.AdminVerify.AdminId), userId);
- query.OrderByDesc(nameof(Entity.AdminVerify.CreatedDate));
- return await _repository.GetAsync<string>(query);
- }
- }
- }
|