using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Entity.Missive; using GxPress.Repository.Interface.Missive; using GxPress.Request.App.Missive; using Microsoft.Extensions.Options; using SqlKata; namespace GxPress.Repository.Implement.Missive { public class MissiveAnalyzeRepository : IMissiveAnalyzeRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypeStr; public MissiveAnalyzeRepository(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 InsertAsync(MissiveAnalyze missiveAnalyze) { return await _repository.InsertAsync(missiveAnalyze); } public async Task GetAsync(int id) { return await _repository.GetAsync(id); } public async Task GetAsync(Query query) { return await _repository.GetAsync(query); } public async Task UpdateAsync(MissiveAnalyze missiveAnalyze) { return await _repository.UpdateAsync(missiveAnalyze); } public async Task DeleteAsync(Query query) { return await _repository.DeleteAsync(query) > 0; } public async Task UpdateAsync(Query query) { return await _repository.UpdateAsync(query) > 0; } public async Task> GetAllAsync(Query query) { return await _repository.GetAllAsync(query); } public async Task GetCount(Query query) { return await _repository.CountAsync(query); } /// /// 设置 点赞 转发 收藏 /// /// /// /// public async Task SetMissiveAnalyzeAsync(MissiveAnalyzeRequest request) { var topicAnalyze = await _repository.GetAsync(Q .Where(nameof(MissiveAnalyze.AnalyzeType), request.MissiveAnalyzeType) .Where(nameof(MissiveAnalyze.MissiveId), request.MissiveId) .Where(nameof(MissiveAnalyze.UserId), request.UserId)); if (topicAnalyze != null && topicAnalyze.Id > 0) return await _repository.DeleteAsync(topicAnalyze.Id); var missiveAnalyze = new MissiveAnalyze { AnalyzeType = request.MissiveAnalyzeType, MissiveId = request.MissiveId, UserId = request.UserId }; return await InsertAsync(missiveAnalyze) > 0; } public async Task CountAsync(SqlKata.Query query) { return await _repository.CountAsync(query); } } }