process.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { ApprovalWay, ProcessStatus, IProcess, ApprovalStatus, IProcedureProcess } from '@sc/types';
  2. import { isEmpty } from 'lodash-es';
  3. // 获取流程某个环节审批状态
  4. export const getProcessStatus = (process: IProcess) => {
  5. const { approvalWay, accounts } = process.participantInfo;
  6. // 指定用户 退回上一环节为上报审批时,判断流程状态和指定用户一样
  7. if (approvalWay === ApprovalWay.ACCOUNT || approvalWay === ApprovalWay.REPORT) {
  8. const { status } = accounts[0];
  9. return status;
  10. }
  11. // 会签 或者 依次审批
  12. if (approvalWay === ApprovalWay.JOINTLYSIGN || approvalWay === ApprovalWay.ORDERAPPROVAL) {
  13. // 只要有一个人审批回退,即失败
  14. if (accounts.some(account => account.status === ProcessStatus.FAILED)) return ProcessStatus.FAILED;
  15. // 所有人都通过,即成功
  16. if (accounts.every(account => account.status === ProcessStatus.APPROVED)) return ProcessStatus.APPROVED;
  17. // 所有人都等待, 即等待
  18. if (accounts.every(account => account.status === ProcessStatus.WAITING)) return ProcessStatus.WAITING;
  19. // 否则正在进行
  20. return ProcessStatus.ACTIVATING;
  21. }
  22. // 或签
  23. if (approvalWay === ApprovalWay.ORSIGN) {
  24. // 只要有一个人审批回退,即失败
  25. if (accounts.some(account => account.status === ProcessStatus.FAILED)) return ProcessStatus.FAILED;
  26. // 只要有一个人审批通过,即成功
  27. if (accounts.some(account => account.status === ProcessStatus.APPROVED)) return ProcessStatus.APPROVED;
  28. // 所有人都等待, 即等待
  29. if (accounts.every(account => account.status === ProcessStatus.WAITING)) return ProcessStatus.WAITING;
  30. // 否则正在进行
  31. return ProcessStatus.ACTIVATING;
  32. }
  33. // 默认等待
  34. return ProcessStatus.WAITING;
  35. };
  36. // 获取流程的状态
  37. export const getApprovalStatus = (processes: IProcess[]) => {
  38. if (isEmpty(processes)) {
  39. return undefined;
  40. }
  41. const lastProcess = processes[processes.length - 1];
  42. const lastProcessStatus = getProcessStatus(lastProcess);
  43. // 审批通过
  44. if (lastProcessStatus === ProcessStatus.APPROVED) {
  45. return ApprovalStatus.APPROVED;
  46. }
  47. // 正在审批
  48. return ApprovalStatus.PROCESSING;
  49. };
  50. // 获取当前的环节(整个流程结束之后,当前环节为 null)
  51. export const getCurrentProcess = (processes: IProcess[]) => {
  52. if (isEmpty(processes)) {
  53. return null;
  54. }
  55. for (let i = 0; i < processes.length; i += 1) {
  56. const {
  57. participantInfo: { approvalWay, accounts },
  58. } = processes[i];
  59. // 指定用户 或 上报审批
  60. if (approvalWay === ApprovalWay.ACCOUNT || approvalWay === ApprovalWay.REPORT) {
  61. const { status } = accounts[0];
  62. if (status === ProcessStatus.ACTIVATING) {
  63. return processes[i];
  64. }
  65. }
  66. // 会签 或者 依次审批
  67. if (approvalWay === ApprovalWay.JOINTLYSIGN || approvalWay === ApprovalWay.ORDERAPPROVAL) {
  68. if (
  69. accounts.every(account => account.status !== ProcessStatus.FAILED) &&
  70. accounts.some(account => account.status === ProcessStatus.ACTIVATING)
  71. ) {
  72. return processes[i];
  73. }
  74. }
  75. // 或签
  76. if (approvalWay === ApprovalWay.ORSIGN) {
  77. if (accounts.every(account => account.status === ProcessStatus.ACTIVATING)) {
  78. return processes[i];
  79. }
  80. }
  81. }
  82. return null;
  83. };
  84. // 获取某个环节的前一个环节
  85. export const getPrevProcess = (processes: IProcess[], curProcess: IProcess) => {
  86. if (isEmpty(processes)) {
  87. return null;
  88. }
  89. for (let i = 1; i < processes.length; i += 1) {
  90. const process = processes[i];
  91. if (process.ID === curProcess.ID) {
  92. return processes[i - 1];
  93. }
  94. }
  95. return null;
  96. };
  97. // 获取某个环节的下一个环节
  98. export const getNextProcess = (processes: IProcess[], curProcess: IProcess) => {
  99. if (isEmpty(processes)) {
  100. return null;
  101. }
  102. for (let i = 0; i < processes.length - 1; i += 1) {
  103. const process = processes[i];
  104. if (process.ID === curProcess.ID) {
  105. return processes[i + 1];
  106. }
  107. }
  108. return null;
  109. };
  110. // 获取上报环节
  111. export const getReportProcess = (processes: IProcess[]) => {
  112. if (isEmpty(processes)) {
  113. return null;
  114. }
  115. return processes[0];
  116. };
  117. // 是否是上报环节
  118. export const isReportProcess = (process: IProcess) => {
  119. return process.participantInfo && process.participantInfo.approvalWay === ApprovalWay.REPORT;
  120. };