123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Datory;
- using GxPress.Entity.WorkFlow;
- using GxPress.EnumConst;
- using GxPress.Request.Notice;
- using GxPress.Result;
- using Newtonsoft.Json;
- namespace GxPress.Service.Implement
- {
- public partial class FlowService
- {
- /// <summary>
- /// 审核
- /// </summary>
- /// <param name="todoId"></param>
- /// <param name="isChecked"></param>
- /// <param name="message"></param>
- /// <returns></returns>
- public async Task CheckAsync(int todoId, bool isChecked, string message)
- {
- //拼接
- var query = Q.NewQuery();
- var todo = await _flowTodoRepository.GetAsync(todoId);
- todo.IsChecked = isChecked;
- todo.Message = message;
- todo.IsDone = true;
- //是否当前操作
- todo.IsOperate = false;
- todo.DoneType = 0;
- var updated = await _flowTodoRepository.UpdateAsync(todo);
- var flow = await GetAsync(todo.FlowId);
- await _flowMessageRepository.InsertAsync(new FlowMessage
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- UserId = todo.UserId,
- Type = nameof(TodoTypeConst.ApproverCheck),
- Message = message
- });
- if (isChecked)
- {
- //修改状态
- if (todo.IsCaseOr && todo.ParentId > 0)
- {
- query = Q.NewQuery();
- query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), todo.ParentId);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId);
- var flowDtos = await _flowTodoRepository.GetAllAsync(query);
- foreach (var item in flowDtos)
- {
- item.IsOperate = false;
- item.IsDone = true;
- item.IsChecked = true;
- await _flowTodoRepository.UpdateAsync(item);
- }
- }
- //是否审核通过
- var checkedCount = await _flowTodoRepository.CheckedCountAsync(flow.Id);
- var allCount = await _flowTodoRepository.AllCountAsync(flow.Id);
- //判断是否最后一个通过
- if (checkedCount == allCount)
- {
- await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
- //发送短信
- var user = await _userRepository.GetAsync(flow.UserId);
- //Common.Sms.AliySms.FolwStatusSendSms(user.Phone);
- // Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "3c70cbdbcd1e45449b2830871387bdfe");
- await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "3c70cbdbcd1e45449b2830871387bdfe", flow.Id, AllTypeConst.Flow.GetHashCode());
- }
- else
- {
- //修改可操作人
- var flowTodo = await _flowTodoRepository.GetUCheckedAsync(todo.FlowId);
- //或签
- if (flowTodo.IsCaseOr && flowTodo.ParentId > 0)
- {
- query = Q.NewQuery();
- query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), flowTodo.ParentId);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), flowTodo.IsCaseOr);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowTodo.FlowId);
- var flowDtos = await _flowTodoRepository.GetAllAsync(query);
- foreach (var item in flowDtos)
- {
- item.IsOperate = true;
- await _flowTodoRepository.UpdateAsync(item);
- //发送短信
- var user = await _userRepository.GetAsync(item.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());
- }
- }
- //会签
- else if (!flowTodo.IsCaseOr && flowTodo.ParentId > 0)
- {
- if (flowTodo.IsOperate == false)
- {
- query = Q.NewQuery();
- query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), flowTodo.ParentId);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), flowTodo.IsCaseOr);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowTodo.FlowId);
- var flowDtos = await _flowTodoRepository.GetAllAsync(query);
- foreach (var item in flowDtos)
- {
- item.IsOperate = true;
- await _flowTodoRepository.UpdateAsync(item);
- //发送短信
- var user = await _userRepository.GetAsync(item.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());
- }
- }
- }
- else
- {
- flowTodo.IsOperate = true;
- await _flowTodoRepository.UpdateAsync(flowTodo);
- //发送短信
- var user = await _userRepository.GetAsync(flowTodo.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());
- }
- }
- }
- else
- {
- //修改工作流程状态
- await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Denied));
- //发送短信
- var user = await _userRepository.GetAsync(flow.UserId);
- //Common.Sms.AliySms.FolwStatusSendSms(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());
- }
- }
- public async Task<bool> RemindAsync(int flowId, int userId)
- {
- var flow = await GetFlowResult(flowId);
- var flowDto = await _flowRepository.GetAsync(flowId);
- var todo = await _flowTodoRepository.GetAsync(Q.Where(nameof(FlowTodo.FlowId), flowId).Where(nameof(FlowTodo.IsOperate), true));
- if (todo == null)
- return false;
- if (todo.IsRemind)
- return true;
- var user = await _userRepository.GetAsync(todo.UserId);
- //发送通知
- var request = new NoticeInRequest();
- request.Title = "工作流催办";
- request.UserId = flowDto.UserId;
- request.AddresseeUserMiddles = new List<Request.UserMiddle.UserMiddleInRequest>();
- request.AddresseeUserMiddles.Add(new Request.UserMiddle.UserMiddleInRequest { MiddleType = 10, SourceType = 0, SourceId = todo.UserId, SourceName = user.Name });
- request.NoticeType = NoticeTypeConst.Send;
- //构建数据
- var resultJson = new List<ContentJsonData>();
- // var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
- // foreach (var item in contentJsonData)
- // item.File = StringUtils.AddDomain(item.File);
- // result.Data = contentJsonData;
- //文字
- var resultJsonText = new ContentJsonData();
- resultJsonText.Title = "催办工作流程";
- resultJsonText.Type = 1;
- resultJson.Add(resultJsonText);
- //审批
- var resultJsonFlow = new ContentJsonData();
- resultJsonFlow.Type = 14;
- resultJsonFlow.Id = flowId;
- resultJsonFlow.Title = flow.Name;
- resultJson.Add(resultJsonFlow);
- request.Content = JsonConvert.SerializeObject(resultJson);
- var boolValue = await _noticeService.InsertAsync(request);
- todo.IsRemind = true;
- await _flowTodoRepository.UpdateAsync(todo);
- return false;
- }
- public async Task TransferCheckAsync(int todoId, List<int> transferUserIds, string message, List<int> fileIds)
- {
- var todo = await _flowTodoRepository.GetAsync(todoId);
- // await _flowTodoRepository.DeleteAsync(todo.Id);
- var flow = await GetAsync(todo.FlowId);
- await _flowMessageRepository.InsertAsync(new FlowMessage
- {
- ProcessId = flow.ProcessId,
- FlowId = flow.Id,
- UserId = todo.UserId,
- Type = nameof(TodoTypeConst.ApproverCheck),
- Message = message,
- FileIds = fileIds
- });
- //修改或签状态
- if (todo.IsCaseOr && todo.ParentId > 0)
- {
- var query = Q.NewQuery();
- query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), todo.ParentId);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true);
- query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId);
- var flowDtos = await _flowTodoRepository.GetAllAsync(query);
- foreach (var item in flowDtos)
- {
- item.IsOperate = item.UserId == todo.UserId ? true : false;
- item.IsDone = true;
- item.IsChecked = true;
- await _flowTodoRepository.UpdateAsync(item);
- }
- }
- //判断是否存在专审 存在就提示
- // var flowTodo = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
- // if (flowTodo.Select(n => n.UserId).Any(n => transferUserIds.Contains(n)))
- // {
- // throw new Exception("转审人或者审核人已存在!");
- // }
- if (transferUserIds.Count > 0)
- {
- //获取其他审核人
- var flowTodos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Sort), ">", todo.Sort));
- foreach (var item in flowTodos)
- {
- item.Sort = item.Sort + transferUserIds.Count;
- await _flowTodoRepository.UpdateSortAsync(item);
- }
- }
- var sort = 1;
- foreach (var transferUserId in transferUserIds)
- {
- var flowTo = new Entity.WorkFlow.FlowTodo();
- flowTo.UserId = transferUserId;
- flowTo.IsChecked = false;
- flowTo.IsDone = false;
- flowTo.IsRead = false;
- flowTo.FlowId = flow.Id;
- flowTo.ProcessId = flow.ProcessId;
- flowTo.Type = nameof(TodoTypeConst.ApproverCheck);
- flowTo.IsOperate = sort == 1 ? true : false;
- flowTo.Sort = todo.Sort + sort;
- await _flowTodoRepository.InsertAsync(flowTo);
- sort++;
- if (flowTo.IsOperate)
- {
- //发送短信
- var user = await _userRepository.GetAsync(transferUserId);
- await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
- }
- }
- //修改当前用户状态
- todo.Message = message;
- todo.IsDone = true;
- todo.FileIds = fileIds;
- todo.IsChecked = true;
- todo.IsOperate = false;
- //已转审
- todo.IsReferral = true;
- await _flowTodoRepository.UpdateAsync(todo);
- }
- }
- }
|