@steedos-labs/plugin-workflow 3.0.96 → 3.0.98

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.
@@ -1,5 +1,5 @@
1
1
  waitForThing(window, 'antd').then(function(){
2
- var v = '3.0.96';
2
+ var v = '3.0.98';
3
3
  loadJs('/amis-renderer/amis-renderer.js?v=' + v);
4
4
  loadCss('/amis-renderer/amis-renderer.css?v=' + v)
5
5
  })
@@ -1676,8 +1676,23 @@ UUFlowManager.workflow_engine = async function (approve_from_client, current_use
1676
1676
  const t8 = Date.now();
1677
1677
  // Update instance
1678
1678
  const t8_1 = Date.now();
1679
+ // 当步骤发生流转时,current_step_name 的变更必须经由 objectql 写入,
1680
+ // 以触发 instances 的 afterUpdate(uuflowManager.triggerRecordInstanceQueue),
1681
+ // 否则 instance_record_queue 不会生成同步记录。
1682
+ // 这里先把 current_step_name 从原子 raw 写入中剥离(保留 $push traces 等原子性),
1683
+ // raw 写入后 DB 仍保留旧的 current_step_name,再由 objectql 单独应用新步骤名,
1684
+ // 使 afterUpdate 检测到 current_step_name 变化并触发同步。
1685
+ const nextStepNameForQueue = updateObj.$set ? updateObj.$set.current_step_name : undefined;
1686
+ const prevStepNameForQueue = updatedInstance.current_step_name;
1687
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== prevStepNameForQueue;
1688
+ if (stepNameChangedForQueue) {
1689
+ delete updateObj.$set.current_step_name;
1690
+ }
1679
1691
  const instancesCollection = await getCollection('instances');
1680
1692
  await instancesCollection.updateOne({ _id: instance_id }, updateObj);
1693
+ if (stepNameChangedForQueue) {
1694
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
1695
+ }
1681
1696
  console.log(`[workflow/engine] [workflow_engine] second updateOne took ${Date.now() - t8_1}ms`);
1682
1697
 
1683
1698
  // Insert new instance tasks if needed
@@ -1980,6 +1995,14 @@ UUFlowManager.handleSkipProcessed = async function (instance_id, flow, maxDepth
1980
1995
  }
1981
1996
  }
1982
1997
 
1998
+ // current_step_name 的变更必须经由 objectql 写入,以触发 instances 的 afterUpdate
1999
+ // (uuflowManager.triggerRecordInstanceQueue),否则滑步到结束不会生成 instance_record_queue 台账同步记录。
2000
+ const nextStepNameForQueue = otherSetObj1.current_step_name;
2001
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== instance.current_step_name;
2002
+ if (stepNameChangedForQueue) {
2003
+ delete otherSetObj1.current_step_name;
2004
+ }
2005
+
1983
2006
  if (Object.keys(traceSetObj1).length > 0) {
1984
2007
  await instancesCollection.updateOne(
1985
2008
  { _id: instance_id },
@@ -2000,6 +2023,10 @@ UUFlowManager.handleSkipProcessed = async function (instance_id, flow, maxDepth
2000
2023
  }
2001
2024
  );
2002
2025
 
2026
+ if (stepNameChangedForQueue) {
2027
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
2028
+ }
2029
+
2003
2030
  // Update instance tasks for skipped approves
2004
2031
  for (const approve of shouldSkipApproves) {
2005
2032
  await update_instance_tasks(instance_id, lastTrace._id, approve._id);
@@ -2124,6 +2151,14 @@ UUFlowManager.handleSkipProcessed = async function (instance_id, flow, maxDepth
2124
2151
  }
2125
2152
  }
2126
2153
 
2154
+ // current_step_name 的变更必须经由 objectql 写入,以触发 instances 的 afterUpdate
2155
+ // (uuflowManager.triggerRecordInstanceQueue),否则滑步到下一步不会生成 instance_record_queue 台账同步记录。
2156
+ const nextStepNameForQueue = otherSetObj2.current_step_name;
2157
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== instance.current_step_name;
2158
+ if (stepNameChangedForQueue) {
2159
+ delete otherSetObj2.current_step_name;
2160
+ }
2161
+
2127
2162
  if (Object.keys(traceSetObj2).length > 0) {
2128
2163
  await instancesCollection.updateOne(
2129
2164
  { _id: instance_id },
@@ -2144,6 +2179,10 @@ UUFlowManager.handleSkipProcessed = async function (instance_id, flow, maxDepth
2144
2179
  }
2145
2180
  );
2146
2181
 
2182
+ if (stepNameChangedForQueue) {
2183
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
2184
+ }
2185
+
2147
2186
  // Update instance tasks for skipped approves
2148
2187
  for (const approve of shouldSkipApproves) {
2149
2188
  await update_instance_tasks(instance_id, lastTrace._id, approve._id);
@@ -5007,6 +5046,14 @@ UUFlowManager.relocate = async function (instance_from_client, current_user_info
5007
5046
  setObj.traces = traces;
5008
5047
 
5009
5048
  // Update instance
5049
+ // current_step_name 的变更必须经由 objectql 写入,以触发 instances 的 afterUpdate
5050
+ // (uuflowManager.triggerRecordInstanceQueue),否则移交不会生成 instance_record_queue 台账同步记录。
5051
+ const nextStepNameForQueue = setObj.current_step_name;
5052
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== instance.current_step_name;
5053
+ if (stepNameChangedForQueue) {
5054
+ delete setObj.current_step_name;
5055
+ }
5056
+
5010
5057
  const updateOperation = setObj.state === 'completed'
5011
5058
  ? { $set: setObj }
5012
5059
  : { $set: setObj, $unset: { finish_date: 1 } };
@@ -5016,6 +5063,10 @@ UUFlowManager.relocate = async function (instance_from_client, current_user_info
5016
5063
  updateOperation
5017
5064
  );
5018
5065
 
5066
+ if (stepNameChangedForQueue) {
5067
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
5068
+ }
5069
+
5019
5070
  if (result.modifiedCount > 0) {
5020
5071
  // Update instance tasks
5021
5072
  await remove_many_instance_tasks(finishedApproveIds);
@@ -16,6 +16,7 @@ const {
16
16
  } = require('../manager/instance_tasks_manager')
17
17
  const UUFlowManager = require('../manager/uuflow_manager');
18
18
  const { getCollection, _makeNewID } = require('../utils/collection');
19
+ const { getObject } = require('@steedos/objectql');
19
20
 
20
21
  router.post('/api/workflow/v2/instance/return', requireAuthentication, async function (req, res) {
21
22
  try {
@@ -157,6 +158,15 @@ router.post('/api/workflow/v2/instance/return', requireAuthentication, async fun
157
158
  setObj.modified_by = current_user;
158
159
  setObj.values = ins.values;
159
160
  setObj.current_step_name = pre_trace.name;
161
+
162
+ // current_step_name 的变更必须经由 objectql 写入,以触发 instances 的 afterUpdate
163
+ // (uuflowManager.triggerRecordInstanceQueue),否则退回不会生成 instance_record_queue 台账同步记录。
164
+ const nextStepNameForQueue = setObj.current_step_name;
165
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== ins.current_step_name;
166
+ if (stepNameChangedForQueue) {
167
+ delete setObj.current_step_name;
168
+ }
169
+
160
170
  r = await instancesCollection.updateOne({
161
171
  _id: instance_id,
162
172
  'traces._id': last_trace._id
@@ -181,6 +191,11 @@ router.post('/api/workflow/v2/instance/return', requireAuthentication, async fun
181
191
  { $set: { processed_user_ids: [ins.applicant] } }
182
192
  );
183
193
 
194
+ // 台账同步:经 objectql 重新写入 current_step_name,触发 afterUpdate 生成同步记录
195
+ if (stepNameChangedForQueue) {
196
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
197
+ }
198
+
184
199
  if (r && b) {
185
200
  await pushManager.send_message_to_specifyUser("current_user", current_user);
186
201
  instance = await UUFlowManager.getInstance(instance_id);
@@ -16,6 +16,7 @@ const PermissionManager = require('../manager/permission_manager');
16
16
  const UUFlowManager = require('../manager/uuflow_manager');
17
17
  const pushManager = require('../manager/push_manager');
18
18
  const { _makeNewID, getCollection } = require('../utils/collection');
19
+ const { getObject } = require('@steedos/objectql');
19
20
 
20
21
  /**
21
22
  * Terminate a workflow instance
@@ -168,11 +169,23 @@ router.post("/api/workflow/v2/instance/terminate", requireAuthentication, async
168
169
  // Update instance
169
170
  const instancesCollection = await getCollection('instances');
170
171
 
172
+ // current_step_name 的变更必须经由 objectql 写入,以触发 instances 的 afterUpdate
173
+ // (uuflowManager.triggerRecordInstanceQueue),否则取消申请不会生成 instance_record_queue 台账同步记录。
174
+ const nextStepNameForQueue = setObj.current_step_name;
175
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== instance.current_step_name;
176
+ if (stepNameChangedForQueue) {
177
+ delete setObj.current_step_name;
178
+ }
179
+
171
180
  const result = await instancesCollection.updateOne(
172
181
  { _id: instance_id },
173
182
  { $set: setObj }
174
183
  );
175
184
 
185
+ if (stepNameChangedForQueue) {
186
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
187
+ }
188
+
176
189
  if (result.modifiedCount > 0) {
177
190
  // Remove instance tasks
178
191
  await remove_many_instance_tasks(finishedApproveIds);
@@ -19,6 +19,7 @@ const {
19
19
  const UUFlowManager = require('../manager/uuflow_manager');
20
20
  const pushManager = require('../manager/push_manager');
21
21
  const { getCollection, _makeNewID } = require('../utils/collection');
22
+ const { getObject } = require('@steedos/objectql');
22
23
  /**
23
24
  @api {post} /api/workflow/retrieve 取回
24
25
  @apiVersion 0.0.0
@@ -252,12 +253,24 @@ router.post('/api/workflow/retrieve', requireAuthentication, async function (req
252
253
  setObj.current_step_name = previous_trace_name;
253
254
  setObj.current_step_auto_submit = await UUFlowManager.getCurrentStepAutoSubmit(flow.timeout_auto_submit, previous_step.lines);
254
255
 
256
+ // current_step_name 的变更必须经由 objectql 写入,以触发 instances 的 afterUpdate
257
+ // (uuflowManager.triggerRecordInstanceQueue),否则取回不会生成 instance_record_queue 台账同步记录。
258
+ const nextStepNameForQueue = setObj.current_step_name;
259
+ const stepNameChangedForQueue = nextStepNameForQueue !== undefined && nextStepNameForQueue !== instance.current_step_name;
260
+ if (stepNameChangedForQueue) {
261
+ delete setObj.current_step_name;
262
+ }
263
+
255
264
  r = await instancesCollection.updateOne({
256
265
  _id: instance_id,
257
266
  }, {
258
267
  $set: setObj,
259
268
  });
260
269
 
270
+ if (stepNameChangedForQueue) {
271
+ await getObject('instances').update(instance_id, { current_step_name: nextStepNameForQueue });
272
+ }
273
+
261
274
  // 更新被取回的approve
262
275
  await update_many_instance_tasks(instance_id, last_trace_id, finishedApproveIds)
263
276
  // 插入取回操作的approve
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos-labs/plugin-workflow",
3
- "version": "3.0.96",
3
+ "version": "3.0.98",
4
4
  "main": "package.service.js",
5
5
  "license": "MIT",
6
6
  "files": [