RuleConditionRepository.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Common.AppOptions;
  4. using GxPress.Common.Tools;
  5. using GxPress.Entity.WorkProcess;
  6. using GxPress.Repository.Interface.WorkProcess;
  7. using Microsoft.Extensions.Options;
  8. using Datory;
  9. namespace GxPress.Repository.Implement.WorkProcess
  10. {
  11. public class RuleConditionRepository : IRuleConditionRepository
  12. {
  13. private readonly Repository<RuleCondition> _repository;
  14. public RuleConditionRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor)
  15. {
  16. var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  17. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  18. _repository = new Repository<RuleCondition>(database);
  19. }
  20. public IDatabase Database => _repository.Database;
  21. public string TableName => _repository.TableName;
  22. public List<TableColumn> TableColumns => _repository.TableColumns;
  23. public async Task<int> InsertAsync(RuleCondition conditionRule)
  24. {
  25. return await _repository.InsertAsync(conditionRule);
  26. }
  27. public async Task<IEnumerable<RuleCondition>> GetListAsync(int nodeId)
  28. {
  29. return await _repository.GetAllAsync(Q
  30. .Where(nameof(RuleCondition.NodeId), nodeId)
  31. .OrderBy(nameof(RuleCondition.Id))
  32. );
  33. }
  34. public async Task DeleteByNodeIdListAsync(IEnumerable<int> nodeIdList)
  35. {
  36. await _repository.DeleteAsync(Q
  37. .WhereIn(nameof(RuleCondition.NodeId), nodeIdList)
  38. );
  39. }
  40. }
  41. }