using System.Collections.Generic; using System.Threading.Tasks; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Entity.WorkProcess; using GxPress.Repository.Interface.WorkProcess; using Microsoft.Extensions.Options; using Datory; namespace GxPress.Repository.Implement.WorkProcess { public class ProcessNodeRepository : IProcessNodeRepository { private readonly Repository _repository; private readonly IRuleCarbonCopyRepository _ruleCarbonCopyRepository; private readonly IRuleApproverCheckRepository _ruleApproverCheckRepository; private readonly IRuleConditionRepository _ruleConditionRepository; public ProcessNodeRepository(IOptionsMonitor dbOptionsAccessor, IRuleCarbonCopyRepository ruleCarbonCopyRepository, IRuleApproverCheckRepository ruleApproverCheckRepository, IRuleConditionRepository ruleConditionRepository) { var databaseType = StringUtils.ToEnum(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql); var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString); _repository = new Repository(database); _ruleCarbonCopyRepository = ruleCarbonCopyRepository; _ruleApproverCheckRepository = ruleApproverCheckRepository; _ruleConditionRepository = ruleConditionRepository; } public IDatabase Database => _repository.Database; public string TableName => _repository.TableName; public List TableColumns => _repository.TableColumns; public async Task> GetListAsync(int processId) { return await _repository.GetAllAsync(Q .Where(nameof(ProcessNode.ProcessId), processId) .OrderBy(nameof(ProcessNode.Id)) ); } public async Task InsertAsync(ProcessNode processNode) { return await _repository.InsertAsync(processNode); } public async Task DeleteByProcessIdAsync(int processId) { var nodeIdList = await _repository.GetAllAsync(Q .Select(nameof(ProcessNode.Id)) .Where(nameof(ProcessNode.ProcessId), processId) ); await _ruleCarbonCopyRepository.DeleteByNodeIdListAsync(nodeIdList); await _ruleApproverCheckRepository.DeleteByNodeIdListAsync(nodeIdList); await _ruleConditionRepository.DeleteByNodeIdListAsync(nodeIdList); await _repository.DeleteAsync(Q.Where(nameof(ProcessNode.ProcessId), processId)); } public async Task> GetListAsync(int processId, int parentId) { return await _repository.GetAllAsync(Q .Where(nameof(ProcessNode.ProcessId), processId) .Where(nameof(ProcessNode.ParentId), parentId) .OrderBy(nameof(ProcessNode.Id)) ); } public async Task> GetAllAsync(int processId) { return await _repository.GetAllAsync(Q .Where(nameof(ProcessNode.ProcessId), processId) .OrderBy(nameof(ProcessNode.Id)) ); } } }