@steedos/migrate 2.5.0-beta.9 → 2.5.1
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.
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2023-01-10 17:18:23
|
|
4
4
|
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
-
* @LastEditTime: 2023-
|
|
5
|
+
* @LastEditTime: 2023-05-17 10:42:47
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
'use strict'
|
|
9
9
|
|
|
10
10
|
const client = require("../client");
|
|
11
|
+
const _ = require('lodash')
|
|
11
12
|
|
|
12
13
|
module.exports.up = async function (next) {
|
|
13
14
|
await client.connect()
|
|
14
15
|
const db = client.db()
|
|
15
16
|
const instanceColl = db.collection('instances')
|
|
16
17
|
const tasksColl = db.collection('instance_tasks')
|
|
18
|
+
const formColl = db.collection('forms')
|
|
17
19
|
// 若已有instance_tasks则不执行
|
|
18
20
|
const tasksCount = await tasksColl.find({}).count()
|
|
19
21
|
if (tasksCount > 0) {
|
|
@@ -24,6 +26,8 @@ module.exports.up = async function (next) {
|
|
|
24
26
|
await instanceColl.find({}).forEach(async function (insDoc) {
|
|
25
27
|
var docs = [];
|
|
26
28
|
var latestApproveIndexMap = {}
|
|
29
|
+
const formDoc = await formColl.findOne({ _id: insDoc.form })
|
|
30
|
+
const extras = caculateExtras(insDoc.values, formDoc, insDoc.form_version)
|
|
27
31
|
insDoc.traces.forEach(function (tDoc, tIdx) {
|
|
28
32
|
if (tIdx == 0 && (!insDoc.distribute_from_instance && !insDoc.forward_from_instance)) {
|
|
29
33
|
// 只有分发或转发的申请单,开始节点生成instance_tasks
|
|
@@ -54,6 +58,7 @@ module.exports.up = async function (next) {
|
|
|
54
58
|
aDoc['keywords'] = insDoc.keywords;
|
|
55
59
|
aDoc['is_archived'] = insDoc.is_archived;
|
|
56
60
|
aDoc['category'] = insDoc.category;
|
|
61
|
+
aDoc['extras'] = extras;
|
|
57
62
|
docs.push(aDoc)
|
|
58
63
|
if (aDoc.is_finished) { //记录下需要设置is_latest_approve的游标,如有重复审批则更新为最新的
|
|
59
64
|
latestApproveIndexMap[aDoc.handler] = docs.length - 1
|
|
@@ -71,9 +76,11 @@ module.exports.up = async function (next) {
|
|
|
71
76
|
if (docs.length > 0) {
|
|
72
77
|
try {
|
|
73
78
|
await tasksColl.insertMany(docs);
|
|
79
|
+
if (extras) {
|
|
80
|
+
await instanceColl.updateOne({ _id: insDoc._id }, { $set: { extras: extras } })
|
|
81
|
+
}
|
|
74
82
|
} catch (e) {
|
|
75
|
-
|
|
76
|
-
printjson(docs.length)
|
|
83
|
+
console.error(e);
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
})
|
|
@@ -86,3 +93,65 @@ module.exports.down = async function (next) {
|
|
|
86
93
|
const tasksColl = db.collection('instance_tasks')
|
|
87
94
|
await tasksColl.remove({})
|
|
88
95
|
}
|
|
96
|
+
|
|
97
|
+
// 计算出在表单字段中选择了列表显示的字段
|
|
98
|
+
function caculateExtras(values, formDoc, formVersionId) {
|
|
99
|
+
if (_.isEmpty(values) || _.isEmpty(formDoc) || _.isEmpty(formVersionId)) {
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const extras = {}
|
|
104
|
+
const formVersion = getFormVersion(formDoc, formVersionId)
|
|
105
|
+
if (formVersion) {
|
|
106
|
+
_.each(formVersion.fields, function (field) {
|
|
107
|
+
if (field.is_list_display) {
|
|
108
|
+
extras[field.code] = values[field.code]
|
|
109
|
+
} else if (field.type === 'table') {
|
|
110
|
+
// 表格
|
|
111
|
+
if (values[field.code]) {
|
|
112
|
+
const tableExtras = []
|
|
113
|
+
_.each(values[field.code], function (s_value) {
|
|
114
|
+
const rowValues = {}
|
|
115
|
+
_.each(field.fields, function (s_field) {
|
|
116
|
+
if (s_field.is_list_display) {
|
|
117
|
+
rowValues[s_field.code] = s_value[s_field.code]
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (!_.isEmpty(rowValues)) {
|
|
121
|
+
tableExtras.push(rowValues)
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
if (!_.isEmpty(tableExtras)) {
|
|
125
|
+
extras[field.code] = tableExtras
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} else if (field.type === 'section') {
|
|
129
|
+
// 分组
|
|
130
|
+
_.each(field.fields, function (s_field) {
|
|
131
|
+
if (s_field.is_list_display) {
|
|
132
|
+
extras[s_field.code] = values[s_field.code]
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if (_.isEmpty(extras)) {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return extras
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getFormVersion(form, form_version) {
|
|
148
|
+
var form_v = null;
|
|
149
|
+
if (form_version === form.current._id) {
|
|
150
|
+
form_v = form.current;
|
|
151
|
+
} else {
|
|
152
|
+
form_v = _.find(form.historys, function (form_h) {
|
|
153
|
+
return form_version === form_h._id;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return form_v;
|
|
157
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/migrate",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Migration scripts for steedos",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "793bcd4718210c693aa52d0280e9b1b2a8d3230e"
|
|
16
16
|
}
|