123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Datory;
- using GxPress.Common.Tools;
- using GxPress.Entity.WorkFlow;
- using GxPress.Entity.WorkFlowDto;
- using GxPress.EnumConst;
- namespace GxPress.Service.Implement
- {
- public partial class FlowService
- {
- /// <summary>
- /// 添加工作流
- /// </summary>
- /// <param name="flow"></param>
- /// <returns></returns>
- public async Task<int> AddAsync(FlowDto flow)
- {
- flow.Id = await _flowRepository.InsertAsync(new Flow
- {
- State = FlowState.Checking,
- ProcessId = flow.ProcessId,
- UserId = flow.UserId,
- IsRead = false
- });
- foreach (var flowField in flow.Fields)
- {
- await _flowFieldValueRepository.InsertAsync(new FlowFieldValue
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- FieldId = flowField.Id,
- UserId = flow.UserId,
- FieldType = flowField.Type,
- StringValue = flowField.Value,
- StringValues = flowField.Value,
- IntValue = StringUtils.ToInt(flowField.Value)
- });
- }
- //添加审核人
- if (flow.ApproverCheckUserIds != null)
- {
- for (int i = 0; i < flow.ApproverCheckUserIds.Count(); i++)
- {
- var todo = new FlowTodo
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- UserId = flow.ApproverCheckUserIds[i],
- Type = nameof(TodoTypeConst.ApproverCheck),
- IsDone = false,
- IsOperate = i == 0,
- };
- await _flowTodoRepository.InsertAsync(todo);
- if (i == 0)
- {
- //发送短信
- var user = await _userRepository.GetAsync(todo.UserId);
- //Common.Sms.AliySms.FolwCheckSendSms(user.Phone);
- //Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
- await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
- }
- }
- }
- if (flow.CarbonCopyUserIds != null)
- {
- foreach (var userId in flow.CarbonCopyUserIds)
- {
- var todo = new FlowTodo
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- UserId = userId,
- Type = nameof(TodoTypeConst.CarbonCopy),
- IsDone = false,
- IsOperate = false
- };
- await _flowTodoRepository.InsertAsync(todo);
- }
- }
- var nodes = await _processService.GetAllAsync(flow.ProcessId);
- foreach (var processNodeDto in nodes.Where(n => n.ParentId == 0))
- {
- if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Start))
- {
- await NodeExecuteAsync(flow, processNodeDto);
- }
- //插入审核人
- if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver) && processNodeDto.ParentId == 0)
- {
- await NodeExecuteAsync(flow, processNodeDto);
- //break;
- }
- if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Switch))
- {
- //工作流条件
- await NodeExecuteSwitchAsync(flow, processNodeDto);
- }
- if (processNodeDto.Type == nameof(ProcessNodeTypeConst.End))
- {
- await NodeExecuteAsync(flow, processNodeDto);
- break;
- }
- }
- //创建工作流
- foreach (var item in flow.flowAttachments)
- {
- item.FlowId = flow.Id;
- item.TypeId = 1;
- }
- await flowAttachmentRepository.InsertsAsync(flow.flowAttachments);
- return flow.Id;
- }
- public async Task<int> ReAddAsync(int flowId)
- {
- var flow = await GetAsync(flowId);
- if (flow == null) return 0;
- flow.Id = await _flowRepository.InsertAsync(new Flow
- {
- ProcessId = flow.ProcessId,
- State = FlowState.Checking,
- UserId = flow.UserId
- });
- //获取上一个的文件
- var flowAttachments = (await flowAttachmentRepository.GetAllAsync(flowId)).ToList();
- foreach (var item in flowAttachments)
- {
- item.FlowId = flow.Id;
- item.TypeId = 1;
- }
- await flowAttachmentRepository.InsertsAsync(flowAttachments);
- if (flow.Fields != null)
- {
- foreach (var flowField in flow.Fields)
- {
- await _flowFieldValueRepository.InsertAsync(new FlowFieldValue
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- FieldId = flowField.Id,
- UserId = flow.UserId,
- FieldType = flowField.Type,
- StringValue = flowField.Value,
- StringValues = flowField.Value,
- IntValue = StringUtils.ToInt(flowField.Value)
- });
- }
- }
- for (int i = 0; i < flow.ApproverCheckUserIds.Count(); i++)
- {
- var todo = new FlowTodo
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- UserId = flow.ApproverCheckUserIds[i],
- Type = nameof(TodoTypeConst.ApproverCheck),
- IsDone = false,
- IsOperate = i == 0,
- };
- await _flowTodoRepository.InsertAsync(todo);
- }
- if (flow.ApproverCheckUserIds != null)
- {
- foreach (var userId in flow.ApproverCheckUserIds)
- {
- var todo = new FlowTodo
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- UserId = userId,
- Type = nameof(TodoTypeConst.CarbonCopy),
- IsDone = false
- };
- await _flowTodoRepository.InsertAsync(todo);
- }
- }
- var nodes = await GetNodesAsync(flow, await _processService.GetNodesAsync(flow.ProcessId, 0));
- if (nodes != null)
- {
- foreach (var processNodeDto in nodes)
- {
- if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Start) ||
- processNodeDto.Type == nameof(ProcessNodeTypeConst.End))
- {
- await NodeExecuteAsync(flow, processNodeDto);
- }
- else if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver))
- {
- await NodeExecuteAsync(flow, processNodeDto);
- }
- }
- }
- await DeleteAsync(flow.Id);
- return flow.Id;
- }
- /// <summary>
- /// 上会待定
- /// </summary>
- /// <param name="flowId"></param>
- /// <param name="userId"></param>
- /// <returns></returns>
- public async Task<bool> ActionsWait(int flowId, int userId)
- {
- var flowTode = await _flowTodoRepository.GetAsync(flowId);
- if (flowTode == null)
- return false;
- flowTode.IsDone = true;
- flowTode.DoneType = 2;
- flowTode.IsChecked = false;
- return await _flowTodoRepository.UpdateAsync(flowTode);
- }
- }
- }
|