ProcessRequestLimitRepository.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ProcessRequestLimitRepository : IProcessRequestLimitRepository
  12. {
  13. private readonly Repository<ProcessRequestLimit> _repository;
  14. public ProcessRequestLimitRepository(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<ProcessRequestLimit>(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(ProcessRequestLimit limit)
  24. {
  25. return await _repository.InsertAsync(limit);
  26. }
  27. public async Task DeleteByProcessIdAsync(int processId)
  28. {
  29. await _repository.DeleteAsync(Q.Where(nameof(ProcessRequestLimit.ProcessId), processId));
  30. }
  31. public async Task<IEnumerable<ProcessRequestLimit>> GetListAsync(int processId)
  32. {
  33. return await _repository.GetAllAsync(Q
  34. .Where(nameof(ProcessRequestLimit.ProcessId), processId)
  35. .OrderByDesc(nameof(ProcessRequestLimit.Id))
  36. );
  37. }
  38. public async Task<IEnumerable<int>> GetProcessIdListByDepartmentIdAsync(int departmentId)
  39. {
  40. return await _repository.GetAllAsync<int>(Q
  41. .Select(nameof(ProcessRequestLimit.ProcessId))
  42. .Where(nameof(ProcessRequestLimit.DepartmentId), departmentId)
  43. .OrWhere(nameof(ProcessRequestLimit.DepartmentId), 0)
  44. );
  45. }
  46. public async Task<IEnumerable<int>> GetProcessIdListByDepartmentIdAsync(List<int> departmentIds)
  47. {
  48. return await _repository.GetAllAsync<int>(Q
  49. .Select(nameof(ProcessRequestLimit.ProcessId))
  50. .WhereIn(nameof(ProcessRequestLimit.DepartmentId), departmentIds)
  51. .OrWhere(nameof(ProcessRequestLimit.DepartmentId), 0)
  52. );
  53. }
  54. }
  55. }