FlowService.Recall.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Threading.Tasks;
  2. using Datory;
  3. using GxPress.EnumConst;
  4. using System.Transactions;
  5. namespace GxPress.Service.Implement
  6. {
  7. public partial class FlowService
  8. {
  9. /// <summary>
  10. /// 撤回
  11. /// </summary>
  12. /// <param name="flowId"></param>
  13. /// <returns></returns>
  14. public async Task<bool> RecallAsync(int flowId, int userId)
  15. {
  16. try
  17. {
  18. using (var transactions = new TransactionScope())
  19. {
  20. var flow = await _flowRepository.GetAsync(flowId);
  21. if (flow == null || flow.UserId != userId)
  22. throw new Common.Exceptions.BusinessException("非本人操作!");
  23. var query = Q.NewQuery();
  24. query.Where(nameof(Entity.Notice.SourceId), flowId);
  25. query.Where(nameof(Entity.Notice.TypeValue), AllTypeConst.MySubmitted.GetHashCode());
  26. query.Where(nameof(Entity.Notice.UserId), userId);
  27. var notice = await _noticeRepository.GetAsync(query);
  28. if (notice == null)
  29. return false;
  30. //删除middle
  31. query = Q.NewQuery();
  32. query.Where(nameof(Entity.Middle.Middle.FolderType), AllTypeConst.Inbox.GetHashCode());
  33. query.Where(nameof(Entity.Middle.Middle.MiddleId), notice.Id);
  34. query.WhereNot(nameof(Entity.Middle.Middle.UserId), flow.UserId);
  35. await middleRepository.DeleteAsync(query);
  36. //修改状态
  37. query = Q.NewQuery();
  38. query.Where(nameof(Entity.Middle.Middle.FolderType), AllTypeConst.Inbox.GetHashCode());
  39. query.Where(nameof(Entity.Middle.Middle.MiddleId), notice.Id);
  40. query.Where(nameof(Entity.Middle.Middle.UserId), flow.UserId);
  41. query.Set(nameof(Entity.Middle.Middle.IsRecall), true);
  42. await middleRepository.UpdateAsync(query);
  43. transactions.Complete();
  44. }
  45. }
  46. catch
  47. {
  48. return false;
  49. }
  50. return true;
  51. }
  52. }
  53. }