using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using GxPress.Entity.WorkFlow; using GxPress.EnumConst; using GxPress.Request.App.Flow; using GxPress.Result.App.Flow; namespace GxPress.Service.Implement { public partial class FlowService { public async Task ListAllAsync(int page, int perPage, int processId, string state, string startDate, string endDate) { var flowList = await _flowRepository.GetFlowListAllAsync(page, perPage, processId, state, startDate, endDate); var items = await GetFlowListResultListAsync(flowList.Items); if (state == nameof(FlowState.Meeting)) { foreach (var item in items) item.State = FlowState.Meeting; } return new ListResult { Count = flowList.Total, Items = items }; } public async Task ListMyCheckingAsync(int userId, FlowListRequest request, string source = "") { var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.ApproverCheck), false, request); var items = new List(); foreach (var todoIdFlowId in todoIdFlowIdList) { var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId); if (flow != null) { items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId, source)); } } //var flowList = await _flowRepository.GetListByIdListAsync(flowIdList, request.Page, request.PerPage); //var items = await GetFlowListResultListAsync(flowList); return new ListResult { Count = await _flowTodoRepository.GetCountAsync(userId, nameof(TodoTypeConst.ApproverCheck), false, request), Items = items }; } public async Task ListMyCheckedAsync(int userId, FlowListRequest request, string source = "") { var flowList = await _flowTodoRepository.GetMyCheckedTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.ApproverCheck), true, request); var items = new List(); foreach (var item in flowList) { var flow = await _flowRepository.GetAsync(item.FlowId); items.Add(await GetFlowListResultAsync(flow, item.TodoId, source)); } return new ListResult { Count = await _flowTodoRepository.GetMyCheckedCountAsync(userId, nameof(TodoTypeConst.ApproverCheck), true, request), Items = items }; } public async Task ListSubmittedCheckingAsync(int userId, FlowListRequest request, string source = "") { var flowList = await _flowRepository.GetListByUserIdAsync(userId, true, request); var items = await GetFlowListResultListAsync(flowList, source); return new ListResult { Count = await _flowRepository.GetCountByUserIdAsync(userId, true, request), //Count = items.Count(), Items = items }; } public async Task ListSubmittedCheckedAsync(int userId, FlowListRequest request) { var flowList = await _flowRepository.GetListByUserIdAsync(userId, false, request); var items = await GetFlowListResultListAsync(flowList); return new ListResult { Count = await _flowRepository.GetCountByUserIdAsync(userId, false, request), Items = items }; } public async Task ListCcUnreadAsync(int userId, FlowListRequest request) { var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.CarbonCopy), request, false); var items = new List(); foreach (var todoIdFlowId in todoIdFlowIdList) { var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId); if (flow != null) { items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId)); } } return new ListResult { Count = await _flowTodoRepository.GetReadCountAsync(userId, nameof(TodoTypeConst.CarbonCopy), request, false), Items = items }; } public async Task ListCcAllAsync(int userId, FlowListRequest request, string source = "") { var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.CarbonCopy), request, true); var items = new List(); foreach (var todoIdFlowId in todoIdFlowIdList) { var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId); if (flow != null) { items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId, source)); } } return new ListResult { Count = await _flowTodoRepository.GetReadCountAsync(userId, nameof(TodoTypeConst.CarbonCopy), request, true), Items = items }; } private async Task> GetFlowListResultListAsync(IEnumerable flowList, string source = "") { var resultList = flowList.Select(async x => { var user = await _userRepository.GetAsync(x.UserId); var result = new FlowListResult { Id = x.Id, ProcessId = x.ProcessId, UserId = x.UserId, State = x.State, ProcessNodeId = x.ProcessNodeId, CreatedDate = x.CreatedDate, Guid = x.Guid }; var (title, summaries) = await GetFlowTitleAndSummaryAsync(user, x.ProcessId, x.Id); result.Title = title; result.AvatarUrl = _userRepository.GetAvatarUrl(user); result.Summaries = summaries; if (source == nameof(FlowListTypeConst.SubmittedChecking)) result.IsRead = true; else result.IsRead = x.IsRead; return result; }); return await Task.WhenAll(resultList); } private async Task GetFlowListResultAsync(Flow flow, int todoId, string source = "") { var user = await _userRepository.GetAsync(flow.UserId); //获取todo var tode = await _flowTodoRepository.GetAsync(todoId); var result = new FlowListResult { Id = tode.FlowId, TodoId = todoId, ProcessId = flow.ProcessId, UserId = flow.UserId, State = flow.State, ProcessNodeId = flow.ProcessNodeId, CreatedDate = flow.CreatedDate, Guid = flow.Guid }; // if (tode != null) // { // if (tode.IsDone && tode.IsChecked) // result.State = FlowState.Checked; // else if (tode.IsDone && !tode.IsChecked) // result.State = FlowState.Denied; // else // result.State = FlowState.Checking; // } var (title, summaries) = await GetFlowTitleAndSummaryAsync(user, flow.ProcessId, flow.Id); result.Title = title; result.AvatarUrl = _userRepository.GetAvatarUrl(user); result.Summaries = summaries; if (source == nameof(FlowListTypeConst.MyChecking) || source == nameof(FlowListTypeConst.MyChecked)) result.IsRead = tode == null ? true : tode.IsDone; else if (source == nameof(FlowListTypeConst.CcAll) || source == nameof(FlowListTypeConst.SubmittedChecking)) result.IsRead = true; else result.IsRead = tode == null ? true : tode.IsRead; return result; } } }