@steedos-labs/plugin-workflow 3.0.0-beta.29 → 3.0.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/main/default/client/instance.client.js +2 -2
  2. package/main/default/manager/import.js +16 -1
  3. package/main/default/manager/push_manager.js +14 -6
  4. package/main/default/methods/trace_approve_cc.js +568 -0
  5. package/main/default/objectTranslations/instances.en/instances.en.objectTranslation.yml +212 -0
  6. package/main/default/objectTranslations/instances.zh-CN/instances.zh-CN.objectTranslation.yml +209 -0
  7. package/main/default/objects/flows/buttons/newexport.button.yml +1 -1
  8. package/main/default/objects/flows/buttons/newimport.button.yml +2 -1
  9. package/main/default/objects/flows/flows.object.yml +1 -0
  10. package/main/default/objects/instances/buttons/instance_cc.button.yml +1 -1
  11. package/main/default/objects/instances/buttons/instance_distribute.button.yml +3 -2
  12. package/main/default/objects/instances/buttons/instance_forward.button.yml +1 -1
  13. package/main/default/objects/instances/buttons/instance_reassign.button.yml +1 -16
  14. package/main/default/objects/instances/buttons/instance_relocate.button.yml +1 -1
  15. package/main/default/objects/instances/buttons/instance_retrieve.button.yml +106 -2
  16. package/main/default/objects/instances/buttons/instance_save.button.yml +1 -1
  17. package/main/default/objects/instances/listviews/monitor.listview.yml +0 -1
  18. package/main/default/pages/instance_tasks_list.page.amis.json +6 -99
  19. package/main/default/pages/instances_list.page.amis.json +6 -100
  20. package/main/default/routes/api_cc.router.js +5 -12
  21. package/main/default/routes/api_flow_permission.router.js +7 -2
  22. package/main/default/routes/api_workflow_instance_return.router.js +164 -167
  23. package/main/default/routes/api_workflow_reassign.router.js +200 -196
  24. package/main/default/routes/api_workflow_relocate.router.js +1 -1
  25. package/main/default/routes/api_workflow_retrieve.router.js +246 -237
  26. package/main/default/routes/export.router.js +5 -4
  27. package/main/default/routes/flow_form_design.ejs +2 -0
  28. package/main/default/routes/import.router.js +6 -7
  29. package/main/default/triggers/amis_form_design.trigger.js +1 -1
  30. package/main/default/utils/designerManager.js +1 -0
  31. package/package.json +3 -2
  32. package/package.service.js +20 -6
  33. package/src/webhook_queue.js +283 -0
  34. package/main/default/manager/index.js +0 -23
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 2022-12-24 14:52:54
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2022-12-31 11:19:56
4
+ * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
+ * @LastEditTime: 2025-10-05 16:12:03
6
6
  * @Description:
7
7
  */
8
8
  'use strict';
@@ -11,7 +11,6 @@ const express = require('express');
11
11
  const router = express.Router();
12
12
  const { requireAuthentication } = require("@steedos/auth");
13
13
  const _ = require('underscore');
14
- const Fiber = function(fun){console.log('TODO Fiber...')}
15
14
  const {
16
15
  insert_instance_tasks,
17
16
  update_instance_tasks,
@@ -19,6 +18,7 @@ const {
19
18
  } = require('../manager/instance_tasks_manager')
20
19
  const UUFlowManager = require('../manager/uuflow_manager');
21
20
  const pushManager = require('../manager/push_manager');
21
+ const { getCollection, _makeNewID } = require('../utils/collection');
22
22
  /**
23
23
  @api {post} /api/workflow/retrieve 取回
24
24
  @apiVersion 0.0.0
@@ -41,253 +41,262 @@ router.post('/api/workflow/retrieve', requireAuthentication, async function (req
41
41
  const spaceId = userSession.spaceId;
42
42
  const userId = userSession.userId;
43
43
  const isSpaceAdmin = userSession.is_space_admin;
44
- Fiber(async function () {
45
- try {
46
- var current_user, current_user_info, e, hashData;
47
- current_user_info = Object.assign({}, userSession, { _id: userSession.userId })
48
- current_user = current_user_info._id;
49
- hashData = req.body;
50
- _.each(hashData['Instances'], function (instance_from_client) {
51
- var cc_users, flow, handler_info, i, ins, instance, instance_id, last_trace, last_trace_id, newApprove, newTrace, now, old_inbox_users, org_info, previous_step, previous_trace, previous_trace_approves, previous_trace_id, previous_trace_name, previous_trace_step_id, r, retrieve_approve, retrieve_comment, retrieve_type, setObj, space_id, space_user, the_trace, traces;
52
- instance = UUFlowManager.getInstance(instance_from_client["_id"]);
53
- retrieve_comment = instance_from_client['retrieve_comment'];
54
- // 验证instance为审核中状态
55
- // UUFlowManager.isInstancePending(instance)
56
- // 校验申请单是当前用户已审核过的单子或者当前用户是提交人或申请人
57
- if ((!instance.outbox_users.includes(current_user)) && (instance.submitter !== current_user && instance.applicant !== current_user)) {
58
- throw new Error('当前用户不符合取回条件');
59
- }
60
- retrieve_type = "";
61
- traces = instance.traces;
62
- //获取最新的trace, 即取回步骤
63
- last_trace = _.last(traces);
64
- last_trace_id = last_trace._id;
65
- previous_trace_id = last_trace.previous_trace_ids[0];
66
- previous_trace = _.find(traces, function (t) {
67
- return t._id === previous_trace_id;
68
- });
69
- previous_trace_step_id = previous_trace.step;
70
- previous_trace_name = previous_trace.name;
71
- flow = UUFlowManager.getFlow(instance.flow);
72
- previous_step = UUFlowManager.getStep(instance, flow, previous_trace_step_id);
73
- if (previous_step.step_type === "counterSign") {
74
- throw new Error('会签不能取回');
44
+
45
+ const instancesCollection = await getCollection('instances');
46
+ const usersCollection = await getCollection('users');
47
+ const spaceUsersCollection = await getCollection('space_users');
48
+ const organizationsCollection = await getCollection('organizations');
49
+
50
+ var current_user, current_user_info, e, hashData;
51
+ current_user_info = Object.assign({}, userSession, { _id: userSession.userId })
52
+ current_user = current_user_info._id;
53
+ hashData = req.body;
54
+ var cc_users, flow, handler_info, i, ins, instance, instance_id, last_trace, last_trace_id, newApprove, newTrace, now, old_inbox_users, org_info, previous_step, previous_trace, previous_trace_approves, previous_trace_id, previous_trace_name, previous_trace_step_id, r, retrieve_approve, retrieve_comment, retrieve_type, setObj, space_id, space_user, the_trace, traces;
55
+ instance = await UUFlowManager.getInstance(hashData["_id"]);
56
+ retrieve_comment = hashData['retrieve_comment'];
57
+ // 验证instance为审核中状态
58
+ // UUFlowManager.isInstancePending(instance)
59
+ // 校验申请单是当前用户已审核过的单子或者当前用户是提交人或申请人
60
+ if ((!instance.outbox_users.includes(current_user)) && (instance.submitter !== current_user && instance.applicant !== current_user)) {
61
+ throw new Error('当前用户不符合取回条件');
62
+ }
63
+ retrieve_type = "";
64
+ traces = instance.traces;
65
+ //获取最新的trace, 即取回步骤
66
+ last_trace = _.last(traces);
67
+ last_trace_id = last_trace._id;
68
+ previous_trace_id = last_trace.previous_trace_ids[0];
69
+ previous_trace = _.find(traces, function (t) {
70
+ return t._id === previous_trace_id;
71
+ });
72
+ previous_trace_step_id = previous_trace.step;
73
+ previous_trace_name = previous_trace.name;
74
+ flow = await UUFlowManager.getFlow(instance.flow);
75
+ previous_step = await UUFlowManager.getStep(instance, flow, previous_trace_step_id);
76
+ if (previous_step.step_type === "counterSign") {
77
+ throw new Error('会签不能取回');
78
+ }
79
+ // 取回步骤的前一个步骤处理人唯一(即排除掉传阅和转发的approve后,剩余的approve只有一个)并且是当前用户
80
+ previous_trace_approves = _.filter(previous_trace.approves, function (a) {
81
+ return a.type !== 'cc' && a.type !== 'distribute' && a.type !== 'forward' && ['approved', 'submitted', 'rejected'].includes(a.judge);
82
+ });
83
+ if (previous_trace_approves.length === 1 && (previous_trace_approves[0].user === current_user || previous_trace_approves[0].handler === current_user)) {
84
+ retrieve_type = 'normal'; // 申请单正常流转的取回,即非传阅取回
85
+ }
86
+ i = traces.length;
87
+ retrieve_approve = {};
88
+ while (i > 0) {
89
+ _.each(traces[i - 1].approves, function (a) {
90
+ if (a.type === 'cc' && a.is_finished === true && a.user === current_user) {
91
+ retrieve_type = 'cc';
92
+ return retrieve_approve = a;
93
+ }
94
+ });
95
+ if (retrieve_type === 'cc') {
96
+ break;
97
+ }
98
+ i--;
99
+ }
100
+ if (retrieve_type === 'normal') {
101
+ // 获取一个flow
102
+ flow = await UUFlowManager.getFlow(instance.flow);
103
+ previous_step = await UUFlowManager.getStep(instance, flow, previous_trace_step_id);
104
+ space_id = instance.space;
105
+ instance_id = instance._id;
106
+ old_inbox_users = instance.inbox_users;
107
+ setObj = new Object;
108
+ now = new Date;
109
+ const finishedApproveIds = []
110
+ let retrieve_appr_id = ''
111
+
112
+
113
+ for (const t of traces) {
114
+ var current_space_user, current_user_organization, retrieve_appr;
115
+ if (t._id === last_trace_id) {
116
+ if (!t.approves) {
117
+ t.approves = new Array;
75
118
  }
76
- // 取回步骤的前一个步骤处理人唯一(即排除掉传阅和转发的approve后,剩余的approve只有一个)并且是当前用户
77
- previous_trace_approves = _.filter(previous_trace.approves, function (a) {
78
- return a.type !== 'cc' && a.type !== 'distribute' && a.type !== 'forward' && ['approved', 'submitted', 'rejected'].includes(a.judge);
119
+ // 更新当前trace.approve记录
120
+ _.each(t.approves, function (appr) {
121
+ if (appr.is_finished === false && appr.type !== "cc") {
122
+ appr.start_date = now;
123
+ appr.finish_date = now;
124
+ appr.read_date = now;
125
+ appr.is_error = false;
126
+ appr.is_read = true;
127
+ appr.is_finished = true;
128
+ appr.judge = "terminated";
129
+ appr.cost_time = appr.finish_date - appr.start_date;
130
+
131
+ finishedApproveIds.push(appr._id)
132
+ }
79
133
  });
80
- if (previous_trace_approves.length === 1 && (previous_trace_approves[0].user === current_user || previous_trace_approves[0].handler === current_user)) {
81
- retrieve_type = 'normal'; // 申请单正常流转的取回,即非传阅取回
82
- }
83
- i = traces.length;
84
- retrieve_approve = {};
85
- while (i > 0) {
86
- _.each(traces[i - 1].approves, function (a) {
87
- if (a.type === 'cc' && a.is_finished === true && a.user === current_user) {
88
- retrieve_type = 'cc';
89
- return retrieve_approve = a;
90
- }
91
- });
92
- if (retrieve_type === 'cc') {
93
- break;
134
+ // 在同一trace下插入取回操作者的approve记录
135
+ current_space_user = await UUFlowManager.getSpaceUser(space_id, current_user);
136
+
137
+ current_user_organization = await organizationsCollection.findOne({ _id: current_space_user.organization }, {
138
+ projection: {
139
+ name: 1,
140
+ fullname: 1
94
141
  }
95
- i--;
96
- }
97
- if (retrieve_type === 'normal') {
98
- // 获取一个flow
99
- flow = UUFlowManager.getFlow(instance.flow);
100
- previous_step = UUFlowManager.getStep(instance, flow, previous_trace_step_id);
101
- space_id = instance.space;
102
- instance_id = instance._id;
103
- old_inbox_users = instance.inbox_users;
104
- setObj = new Object;
105
- now = new Date;
106
- const finishedApproveIds = []
107
- let retrieve_appr_id = ''
108
- _.each(traces, function (t) {
109
- var current_space_user, current_user_organization, retrieve_appr;
110
- if (t._id === last_trace_id) {
111
- if (!t.approves) {
112
- t.approves = new Array;
113
- }
114
- // 更新当前trace.approve记录
115
- _.each(t.approves, function (appr) {
116
- if (appr.is_finished === false && appr.type !== "cc") {
117
- appr.start_date = now;
118
- appr.finish_date = now;
119
- appr.read_date = now;
120
- appr.is_error = false;
121
- appr.is_read = true;
122
- appr.is_finished = true;
123
- appr.judge = "terminated";
124
- appr.cost_time = appr.finish_date - appr.start_date;
142
+ })
125
143
 
126
- finishedApproveIds.push(appr._id)
127
- }
128
- });
129
- // 在同一trace下插入取回操作者的approve记录
130
- current_space_user = UUFlowManager.getSpaceUser(space_id, current_user);
131
- current_user_organization = db.organizations.findOne(current_space_user.organization, {
132
- fields: {
133
- name: 1,
134
- fullname: 1
135
- }
136
- });
137
- retrieve_appr = new Object;
138
- retrieve_appr._id = _makeNewID();
139
- retrieve_appr.instance = instance_id;
140
- retrieve_appr.trace = t._id;
141
- retrieve_appr.is_finished = true;
142
- retrieve_appr.user = current_user;
143
- retrieve_appr.user_name = current_user_info.name;
144
- retrieve_appr.handler = current_user;
145
- retrieve_appr.handler_name = current_user_info.name;
146
- retrieve_appr.handler_organization = current_space_user.organization;
147
- retrieve_appr.handler_organization_name = current_user_organization.name;
148
- retrieve_appr.handler_organization_fullname = current_user_organization.fullname;
149
- retrieve_appr.start_date = now;
150
- retrieve_appr.finish_date = now;
151
- retrieve_appr.due_date = t.due_date;
152
- retrieve_appr.read_date = now;
153
- retrieve_appr.judge = "retrieved";
154
- retrieve_appr.is_read = true;
155
- retrieve_appr.description = retrieve_comment;
156
- retrieve_appr.is_error = false;
157
- retrieve_appr.values = new Object;
158
- retrieve_appr.cost_time = retrieve_appr.finish_date - retrieve_appr.start_date;
159
- t.approves.push(retrieve_appr);
160
- // 更新当前trace记录
161
- t.is_finished = true;
162
- t.finish_date = now;
163
- return t.judge = "retrieved";
164
- }
165
- });
166
- // 插入下一步trace记录
167
- newTrace = new Object;
168
- newTrace._id = _makeNewID();
169
- newTrace.instance = instance_id;
170
- newTrace.previous_trace_ids = [last_trace_id];
171
- newTrace.is_finished = false;
172
- newTrace.step = previous_trace_step_id;
173
- newTrace.name = previous_trace_name;
174
- newTrace.start_date = now;
175
- newTrace.due_date = UUFlowManager.getDueDate(previous_step.timeout_hours, space_id);
176
- newTrace.approves = [];
177
- // 插入下一步trace.approve记录
178
- newApprove = new Object;
179
- newApprove._id = _makeNewID();
180
- newApprove.instance = instance_id;
181
- newApprove.trace = newTrace._id;
182
- newApprove.is_finished = false;
183
- newApprove.user = current_user;
184
- handler_info = db.users.findOne(current_user, {
185
- fields: {
186
- name: 1
187
- }
188
- });
189
- newApprove.user_name = handler_info.name;
190
- newApprove.handler = current_user;
191
- newApprove.handler_name = handler_info.name;
192
- space_user = UUFlowManager.getSpaceUser(space_id, current_user);
193
- // 获取next_step_user所在的部门信息
194
- org_info = UUFlowManager.getSpaceUserOrgInfo(space_user);
195
- newApprove.handler_organization = org_info["organization"];
196
- newApprove.handler_organization_name = org_info["organization_name"];
197
- newApprove.handler_organization_fullname = org_info["organization_fullname"];
198
- newApprove.start_date = now;
199
- newApprove.due_date = newTrace.due_date;
200
- newApprove.is_read = false;
201
- newApprove.is_error = false;
202
- newApprove.values = new Object;
203
- UUFlowManager.setRemindInfo(instance.values, newApprove);
204
- newTrace.approves.push(newApprove);
205
- setObj.inbox_users = [current_user];
206
- setObj.modified = now;
207
- setObj.modified_by = current_user;
208
- traces.push(newTrace);
209
- setObj.traces = traces;
210
- setObj.state = "pending";
211
- setObj.is_archived = false;
212
- setObj.current_step_name = previous_trace_name;
213
- setObj.current_step_auto_submit = UUFlowManager.getCurrentStepAutoSubmit(flow.timeout_auto_submit, previous_step.lines);
214
- r = db.instances.update({
215
- _id: instance_id
216
- }, {
217
- $set: setObj
218
- });
144
+ retrieve_appr = new Object;
145
+ retrieve_appr._id = _makeNewID();
146
+ retrieve_appr.instance = instance_id;
147
+ retrieve_appr.trace = t._id;
148
+ retrieve_appr.is_finished = true;
149
+ retrieve_appr.user = current_user;
150
+ retrieve_appr.user_name = current_user_info.name;
151
+ retrieve_appr.handler = current_user;
152
+ retrieve_appr.handler_name = current_user_info.name;
153
+ retrieve_appr.handler_organization = current_space_user.organization;
154
+ retrieve_appr.handler_organization_name = current_user_organization.name;
155
+ retrieve_appr.handler_organization_fullname = current_user_organization.fullname;
156
+ retrieve_appr.start_date = now;
157
+ retrieve_appr.finish_date = now;
158
+ retrieve_appr.due_date = t.due_date;
159
+ retrieve_appr.read_date = now;
160
+ retrieve_appr.judge = "retrieved";
161
+ retrieve_appr.is_read = true;
162
+ retrieve_appr.description = retrieve_comment;
163
+ retrieve_appr.is_error = false;
164
+ retrieve_appr.values = new Object;
165
+ retrieve_appr.cost_time = retrieve_appr.finish_date - retrieve_appr.start_date;
166
+ t.approves.push(retrieve_appr);
167
+ // 更新当前trace记录
168
+ t.is_finished = true;
169
+ t.finish_date = now;
170
+ t.judge = "retrieved";
171
+ }
172
+ };
173
+ // 插入下一步trace记录
174
+ newTrace = new Object;
175
+ newTrace._id = _makeNewID();
176
+ newTrace.instance = instance_id;
177
+ newTrace.previous_trace_ids = [last_trace_id];
178
+ newTrace.is_finished = false;
179
+ newTrace.step = previous_trace_step_id;
180
+ newTrace.name = previous_trace_name;
181
+ newTrace.start_date = now;
182
+ newTrace.due_date = await UUFlowManager.getDueDate(previous_step.timeout_hours, space_id);
183
+ newTrace.approves = [];
184
+ // 插入下一步trace.approve记录
185
+ newApprove = new Object;
186
+ newApprove._id = _makeNewID();
187
+ newApprove.instance = instance_id;
188
+ newApprove.trace = newTrace._id;
189
+ newApprove.is_finished = false;
190
+ newApprove.user = current_user;
219
191
 
220
- // 更新被取回的approve
221
- update_many_instance_tasks(instance_id, last_trace_id, finishedApproveIds)
222
- // 插入取回操作的approve
223
- insert_instance_tasks(instance_id, last_trace_id, retrieve_appr_id)
224
- // 插入新步骤的approve
225
- insert_instance_tasks(instance_id, newTrace._id, newApprove._id)
192
+ handler_info = await usersCollection.findOne({ _id: current_user }, {
193
+ projection: {
194
+ name: 1
195
+ }
196
+ })
226
197
 
227
- if (r) {
228
- // 给被删除的inbox_users 和 当前用户 发送push
229
- pushManager.send_message_current_user(current_user_info);
230
- _.each(old_inbox_users, function (user_id) {
231
- if (user_id !== current_user) {
232
- return pushManager.send_message_to_specifyUser("current_user", user_id);
233
- }
234
- });
235
- ins = UUFlowManager.getInstance(instance_id);
236
- // 如果已经配置webhook并已激活则触发
237
- return pushManager.triggerWebhook(ins.flow, ins, {}, 'retrieve', current_user, ins.inbox_users);
238
- }
239
- } else if (retrieve_type === 'cc') {
240
- setObj = new Object;
241
- now = new Date;
242
- instance_id = instance._id;
243
- the_trace = _.find(traces, function (t) {
244
- return t._id === retrieve_approve.trace;
245
- });
246
- _.each(the_trace.approves, function (a) {
247
- if (a._id === retrieve_approve._id) {
248
- a.is_finished = false;
249
- a.finish_date = void 0;
250
- a.judge = void 0;
251
- return a.cost_time = void 0;
252
- }
253
- });
254
- cc_users = instance.cc_users;
255
- cc_users.push(current_user);
256
- setObj.modified = now;
257
- setObj.modified_by = current_user;
258
- setObj.state = "pending";
259
- setObj.is_archived = false;
260
- setObj.cc_users = cc_users;
261
- setObj['traces.$.approves'] = the_trace.approves;
262
- r = db.instances.update({
263
- _id: instance_id,
264
- 'traces._id': retrieve_approve.trace
265
- }, {
266
- $set: setObj
267
- });
198
+ newApprove.user_name = handler_info.name;
199
+ newApprove.handler = current_user;
200
+ newApprove.handler_name = handler_info.name;
201
+ space_user = await UUFlowManager.getSpaceUser(space_id, current_user);
202
+ // 获取next_step_user所在的部门信息
203
+ org_info = await UUFlowManager.getSpaceUserOrgInfo(space_user);
204
+ newApprove.handler_organization = org_info["organization"];
205
+ newApprove.handler_organization_name = org_info["organization_name"];
206
+ newApprove.handler_organization_fullname = org_info["organization_fullname"];
207
+ newApprove.start_date = now;
208
+ newApprove.due_date = newTrace.due_date;
209
+ newApprove.is_read = false;
210
+ newApprove.is_error = false;
211
+ newApprove.values = new Object;
212
+ await UUFlowManager.setRemindInfo(instance.values, newApprove);
213
+ newTrace.approves.push(newApprove);
214
+ setObj.inbox_users = [current_user];
215
+ setObj.modified = now;
216
+ setObj.modified_by = current_user;
217
+ traces.push(newTrace);
218
+ setObj.traces = traces;
219
+ setObj.state = "pending";
220
+ setObj.is_archived = false;
221
+ setObj.current_step_name = previous_trace_name;
222
+ setObj.current_step_auto_submit = await UUFlowManager.getCurrentStepAutoSubmit(flow.timeout_auto_submit, previous_step.lines);
268
223
 
269
- update_instance_tasks(instance_id, retrieve_approve.trace, retrieve_approve._id)
224
+ r = await instancesCollection.updateOne({
225
+ _id: instance_id,
226
+ }, {
227
+ $set: setObj,
228
+ });
270
229
 
271
- if (r) {
272
- pushManager.send_message_current_user(current_user_info);
273
- }
274
- ins = UUFlowManager.getInstance(instance_id);
275
- // 如果已经配置webhook并已激活则触发
276
- return pushManager.triggerWebhook(ins.flow, ins, {}, 'retrieve', current_user, [current_user]);
230
+ // 更新被取回的approve
231
+ await update_many_instance_tasks(instance_id, last_trace_id, finishedApproveIds)
232
+ // 插入取回操作的approve
233
+ await insert_instance_tasks(instance_id, last_trace_id, retrieve_appr_id)
234
+ // 插入新步骤的approve
235
+ await insert_instance_tasks(instance_id, newTrace._id, newApprove._id)
236
+
237
+ if (r) {
238
+ // 给被删除的inbox_users 和 当前用户 发送push
239
+ await pushManager.send_message_current_user(current_user_info);
240
+ for (const user_id of old_inbox_users) {
241
+ if (user_id !== current_user) {
242
+ await pushManager.send_message_to_specifyUser("current_user", user_id);
277
243
  }
278
- });
244
+ };
245
+ ins = await UUFlowManager.getInstance(instance_id);
246
+ // 如果已经配置webhook并已激活则触发
247
+ await pushManager.triggerWebhook(ins.flow, ins, {}, 'retrieve', current_user, ins.inbox_users);
248
+ }
249
+ } else if (retrieve_type === 'cc') {
250
+ setObj = new Object;
251
+ now = new Date;
252
+ instance_id = instance._id;
253
+ the_trace = _.find(traces, function (t) {
254
+ return t._id === retrieve_approve.trace;
255
+ });
256
+ _.each(the_trace.approves, function (a) {
257
+ if (a._id === retrieve_approve._id) {
258
+ a.is_finished = false;
259
+ a.finish_date = void 0;
260
+ a.judge = void 0;
261
+ return a.cost_time = void 0;
262
+ }
263
+ });
264
+ cc_users = instance.cc_users;
265
+ cc_users.push(current_user);
266
+ setObj.modified = now;
267
+ setObj.modified_by = current_user;
268
+ setObj.state = "pending";
269
+ setObj.is_archived = false;
270
+ setObj.cc_users = cc_users;
271
+ setObj['traces.$.approves'] = the_trace.approves;
272
+ r = await instancesCollection.updateOne({
273
+ _id: instance_id,
274
+ 'traces._id': retrieve_approve.trace
275
+ }, {
276
+ $set: setObj,
277
+ });
279
278
 
280
- res.status(200).send({});
281
- } catch (e) {
282
- console.error(e);
283
- res.status(200).send({
284
- errors: [{ errorMessage: e.message }]
285
- });
279
+ await update_instance_tasks(instance_id, retrieve_approve.trace, retrieve_approve._id)
280
+
281
+ if (r) {
282
+ await pushManager.send_message_current_user(current_user_info);
286
283
  }
287
- }).run()
284
+ ins = UUFlowManager.getInstance(instance_id);
285
+ // 如果已经配置webhook并已激活则触发
286
+ await pushManager.triggerWebhook(ins.flow, ins, {}, 'retrieve', current_user, [current_user]);
287
+ }
288
+
289
+ res.status(200).send({
290
+ status: 0,
291
+ data: {}
292
+ });
293
+
288
294
  } catch (e) {
295
+ console.log(e);
289
296
  res.status(200).send({
290
- errors: [{ errorMessage: e.message }]
297
+ status: -1,
298
+ msg: e.message,
299
+ data: {}
291
300
  });
292
301
  }
293
302
  });
@@ -18,8 +18,9 @@ const { getCollection } = require('../utils/collection');
18
18
 
19
19
  const exportByFlowIds = async function (flowIds, res) {
20
20
  const db = {
21
- forms: getCollection('forms'),
22
- spaces: getCollection('spaces')
21
+ forms: await getCollection('forms'),
22
+ flows: await getCollection('flows'),
23
+ spaces: await getCollection('spaces')
23
24
  }
24
25
  var fileNames, flows, zip;
25
26
  flows = await db.flows.find({
@@ -47,12 +48,12 @@ const exportByFlowIds = async function (flowIds, res) {
47
48
  } else {
48
49
  fileNames[fileName] = 1;
49
50
  }
50
- return zip.file(`${fileName}.json`, new Buffer(JSON.stringify(data), 'utf-8'));
51
+ zip.file(`${fileName}.json`, new Buffer(JSON.stringify(data), 'utf-8'));
51
52
  }
52
53
  res.setHeader('Content-type', 'application/octet-stream');
53
54
  res.setHeader('Content-Disposition', 'attachment;filename=' + encodeURI('导出的流程文件') + '.zip');
54
55
  return zip.generateNodeStream().pipe(res).on('finish', function () {
55
- return console.log("text file written.");
56
+ console.log("text file written.");
56
57
  });
57
58
  };
58
59
 
@@ -136,6 +136,8 @@
136
136
  {
137
137
  record:forms__findOne(id: "${id}"){
138
138
  _id,
139
+ name,
140
+ description,
139
141
  amis_schema,
140
142
  current
141
143
  }
@@ -138,12 +138,12 @@ router.post('/api/workflow/import/form', requireAuthentication, async function (
138
138
  } catch (e) {
139
139
  console.log(e)
140
140
  if (e.reason && e.details) {
141
- return fail[filename] = {
141
+ fail[filename] = {
142
142
  reason: e.reason,
143
143
  details: e.details
144
144
  };
145
145
  } else {
146
- return fail[filename] = e.reason || e.message;
146
+ fail[filename] = e.reason || e.message;
147
147
  }
148
148
  }
149
149
  }
@@ -152,16 +152,15 @@ router.post('/api/workflow/import/form', requireAuthentication, async function (
152
152
  } else {
153
153
  res.statusCode = 500;
154
154
  }
155
- return res.end(JSON.stringify({
156
- multiple: multiple,
157
- fail: fail,
158
- success: success
155
+ res.end(JSON.stringify({
156
+ status: res.statusCode ? 0 : 1,
157
+ msg: fail
159
158
  }));
160
159
  } catch (error) {
161
160
  console.log(error)
162
161
  msg = "无效的JSON文件";
163
162
  res.statusCode = 500;
164
- return res.end(msg);
163
+ res.end(msg);
165
164
  }
166
165
  });
167
166
  } catch (e) {
@@ -534,7 +534,7 @@ module.exports = {
534
534
 
535
535
  // 数据库更新操作:将forms表current的fields字段更新为最终数组
536
536
  form.current.fields = getFinalFormFields(inputFields);
537
- form.current.amis_schema = amis_schema;
537
+ form.current.amis_schema = this.doc.amis_schema;
538
538
  form.current.style = formSchema.style;
539
539
  form.current.mode = formSchema.mode;
540
540
  form.current.wizard_mode = formSchema.wizard_mode;
@@ -224,6 +224,7 @@ async function updateForm(formId, form, forms, flows, currentUserId) {
224
224
  current.style = form["current"]["style"];
225
225
  current.mode = form["current"]["mode"];
226
226
  current.wizard_mode = form["current"]["wizard_mode"];
227
+ current.amis_schema = form["current"]["amis_schema"]
227
228
 
228
229
  formUpdateObj.$set = {
229
230
  'current': current,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos-labs/plugin-workflow",
3
- "version": "3.0.0-beta.29",
3
+ "version": "3.0.0-beta.31",
4
4
  "main": "package.service.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -12,7 +12,8 @@
12
12
  "he": "1.2.0",
13
13
  "lodash": "^4.17.21",
14
14
  "node-schedule": "^2.0.0",
15
- "formidable": "2.0.1"
15
+ "formidable": "2.0.1",
16
+ "jszip": "3.10.1"
16
17
  },
17
18
  "private": false,
18
19
  "publishConfig": {