ProcessNodeRepository.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 ProcessNodeRepository : IProcessNodeRepository
  12. {
  13. private readonly Repository<ProcessNode> _repository;
  14. private readonly IRuleCarbonCopyRepository _ruleCarbonCopyRepository;
  15. private readonly IRuleApproverCheckRepository _ruleApproverCheckRepository;
  16. private readonly IRuleConditionRepository _ruleConditionRepository;
  17. public ProcessNodeRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IRuleCarbonCopyRepository ruleCarbonCopyRepository, IRuleApproverCheckRepository ruleApproverCheckRepository, IRuleConditionRepository ruleConditionRepository)
  18. {
  19. var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  20. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  21. _repository = new Repository<ProcessNode>(database);
  22. _ruleCarbonCopyRepository = ruleCarbonCopyRepository;
  23. _ruleApproverCheckRepository = ruleApproverCheckRepository;
  24. _ruleConditionRepository = ruleConditionRepository;
  25. }
  26. public IDatabase Database => _repository.Database;
  27. public string TableName => _repository.TableName;
  28. public List<TableColumn> TableColumns => _repository.TableColumns;
  29. public async Task<IEnumerable<ProcessNode>> GetListAsync(int processId)
  30. {
  31. return await _repository.GetAllAsync(Q
  32. .Where(nameof(ProcessNode.ProcessId), processId)
  33. .OrderBy(nameof(ProcessNode.Id))
  34. );
  35. }
  36. public async Task<int> InsertAsync(ProcessNode processNode)
  37. {
  38. return await _repository.InsertAsync(processNode);
  39. }
  40. public async Task DeleteByProcessIdAsync(int processId)
  41. {
  42. var nodeIdList = await _repository.GetAllAsync<int>(Q
  43. .Select(nameof(ProcessNode.Id))
  44. .Where(nameof(ProcessNode.ProcessId), processId)
  45. );
  46. await _ruleCarbonCopyRepository.DeleteByNodeIdListAsync(nodeIdList);
  47. await _ruleApproverCheckRepository.DeleteByNodeIdListAsync(nodeIdList);
  48. await _ruleConditionRepository.DeleteByNodeIdListAsync(nodeIdList);
  49. await _repository.DeleteAsync(Q.Where(nameof(ProcessNode.ProcessId), processId));
  50. }
  51. public async Task<IEnumerable<ProcessNode>> GetListAsync(int processId, int parentId)
  52. {
  53. return await _repository.GetAllAsync(Q
  54. .Where(nameof(ProcessNode.ProcessId), processId)
  55. .Where(nameof(ProcessNode.ParentId), parentId)
  56. .OrderBy(nameof(ProcessNode.Id))
  57. );
  58. }
  59. public async Task<IEnumerable<ProcessNode>> GetAllAsync(int processId)
  60. {
  61. return await _repository.GetAllAsync(Q
  62. .Where(nameof(ProcessNode.ProcessId), processId)
  63. .OrderBy(nameof(ProcessNode.Id))
  64. );
  65. }
  66. }
  67. }