FlowService.Inbox.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Threading.Tasks;
  2. using GxPress.Entity.WorkFlowDto;
  3. using System.Linq;
  4. using Datory;
  5. using System.Collections.Generic;
  6. namespace GxPress.Service.Implement
  7. {
  8. public partial class FlowService
  9. {
  10. public async Task<bool> AddInboxAsyc(FlowDto flow)
  11. {
  12. var user = await _userRepository.GetAsync(flow.UserId);
  13. var process = await _processRepository.GetAsync(flow.ProcessId);
  14. //获取收件人
  15. //获取抄送人
  16. var flowDtos = await _flowTodoRepository.GetListByFlowIdAsync(flow.Id);
  17. var addressUserIds = flowDtos.Where(n => n.Type == nameof(GxPress.EnumConst.TodoTypeConst.ApproverCheck)).Select(n => n.UserId).ToList();
  18. var ccUserIds = flowDtos.Where(n => n.Type == nameof(GxPress.EnumConst.TodoTypeConst.CarbonCopy)).Select(n => n.UserId).ToList();
  19. //收件人
  20. var addressUsers = await _userRepository.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), addressUserIds));
  21. //抄送人
  22. var ccUsers = await _userRepository.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), ccUserIds));
  23. //中间件
  24. var middles = new List<Entity.Middle.Middle>();
  25. var middle = new Entity.Middle.Middle
  26. {
  27. MiddleId = flow.Id,
  28. FolderType = GxPress.EnumConst.FolderTypeConst.Notice.GetHashCode(),
  29. IsTop = false,
  30. AttributeValue = 1,
  31. ParentId = 0,
  32. UserId = flow.UserId,
  33. MiddleSonId = 0,
  34. IsAdmin = false,
  35. NoticeAddresseeType = 0,
  36. Title = $"{user.Name}{process.Name}申请",
  37. IsRead = false,
  38. TitleLong = "",
  39. Content = "",
  40. AddressUserComplete = Common.Tools.StringUtils.ObjectCollectionToString(addressUsers.Select(n => n.Name)),
  41. AddressUser = Common.Tools.StringUtils.ObjectCollectionToString(addressUsers.Select(n => n.Name), 10),
  42. CcUserComplete = Common.Tools.StringUtils.ObjectCollectionToString(ccUsers.Select(n => n.Name)),
  43. CcUser = Common.Tools.StringUtils.ObjectCollectionToString(ccUsers.Select(n => n.Name), 10),
  44. };
  45. middles.Add(middle);
  46. var users = addressUsers.ToList();
  47. users.AddRange(ccUsers);
  48. foreach (var item in users.Distinct())
  49. {
  50. middle = new Entity.Middle.Middle
  51. {
  52. MiddleId = flow.Id,
  53. FolderType = GxPress.EnumConst.FolderTypeConst.Notice.GetHashCode(),
  54. IsTop = false,
  55. AttributeValue = 1,
  56. ParentId = 0,
  57. UserId = flow.UserId,
  58. MiddleSonId = 0,
  59. IsAdmin = false,
  60. NoticeAddresseeType = 0,
  61. Title = $"{user.Name}{process.Name}申请",
  62. IsRead = false,
  63. TitleLong = "",
  64. Content = "",
  65. AddressUserComplete = Common.Tools.StringUtils.ObjectCollectionToString(addressUsers.Select(n => n.Name)),
  66. AddressUser = Common.Tools.StringUtils.ObjectCollectionToString(addressUsers.Select(n => n.Name), 10),
  67. CcUserComplete = Common.Tools.StringUtils.ObjectCollectionToString(ccUsers.Select(n => n.Name)),
  68. CcUser = Common.Tools.StringUtils.ObjectCollectionToString(ccUsers.Select(n => n.Name), 10),
  69. };
  70. middles.Add(middle);
  71. }
  72. await middleRepository.InsertAsync(middles);
  73. return true;
  74. }
  75. }
  76. }