@steedos-labs/content-compliance 0.7.19 → 0.7.21
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.
- package/dist/index.js +1 -0
- package/lib/actions/addBulkMaterials.d.ts +15 -0
- package/lib/actions/addBulkMaterials.js +69 -0
- package/lib/actions/addBulkMaterials.js.map +1 -0
- package/lib/actions/briefFlows.d.ts +14 -0
- package/lib/actions/briefFlows.js +46 -0
- package/lib/actions/briefFlows.js.map +1 -0
- package/lib/actions/bypassApproval.d.ts +10 -0
- package/lib/actions/bypassApproval.js +269 -0
- package/lib/actions/bypassApproval.js.map +1 -0
- package/lib/actions/bypassMaterial.d.ts +10 -0
- package/lib/actions/bypassMaterial.js +190 -0
- package/lib/actions/bypassMaterial.js.map +1 -0
- package/lib/actions/calculateSpotCheckRates.d.ts +13 -0
- package/lib/actions/calculateSpotCheckRates.js +94 -0
- package/lib/actions/calculateSpotCheckRates.js.map +1 -0
- package/lib/actions/confirmDeployment.d.ts +7 -0
- package/lib/actions/confirmDeployment.js +31 -0
- package/lib/actions/confirmDeployment.js.map +1 -0
- package/lib/actions/dashboard_sync_data.d.ts +7 -0
- package/lib/actions/dashboard_sync_data.js +30 -0
- package/lib/actions/dashboard_sync_data.js.map +1 -0
- package/lib/actions/fixStuckPersonnelReview.d.ts +20 -0
- package/lib/actions/fixStuckPersonnelReview.js +145 -0
- package/lib/actions/fixStuckPersonnelReview.js.map +1 -0
- package/lib/actions/hasDuplicateMaterials.d.ts +9 -0
- package/lib/actions/hasDuplicateMaterials.js +30 -0
- package/lib/actions/hasDuplicateMaterials.js.map +1 -0
- package/lib/actions/imageComparison.d.ts +34 -0
- package/lib/actions/imageComparison.js +95 -0
- package/lib/actions/imageComparison.js.map +1 -0
- package/lib/actions/index.d.ts +27 -0
- package/lib/actions/index.js +31 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/actions/initCollaborator.d.ts +13 -0
- package/lib/actions/initCollaborator.js +87 -0
- package/lib/actions/initCollaborator.js.map +1 -0
- package/lib/actions/initUrgentQuota.d.ts +17 -0
- package/lib/actions/initUrgentQuota.js +99 -0
- package/lib/actions/initUrgentQuota.js.map +1 -0
- package/lib/actions/migrateReviewCompletedDate.d.ts +21 -0
- package/lib/actions/migrateReviewCompletedDate.js +150 -0
- package/lib/actions/migrateReviewCompletedDate.js.map +1 -0
- package/lib/actions/migrateSpotCheckData.d.ts +23 -0
- package/lib/actions/migrateSpotCheckData.js +143 -0
- package/lib/actions/migrateSpotCheckData.js.map +1 -0
- package/lib/actions/migrateSpotCheckDepartments.d.ts +25 -0
- package/lib/actions/migrateSpotCheckDepartments.js +142 -0
- package/lib/actions/migrateSpotCheckDepartments.js.map +1 -0
- package/lib/actions/postponeDeployment.d.ts +7 -0
- package/lib/actions/postponeDeployment.js +30 -0
- package/lib/actions/postponeDeployment.js.map +1 -0
- package/lib/actions/postponeReview.d.ts +7 -0
- package/lib/actions/postponeReview.js +30 -0
- package/lib/actions/postponeReview.js.map +1 -0
- package/lib/actions/progress.d.ts +18 -0
- package/lib/actions/progress.js +71 -0
- package/lib/actions/progress.js.map +1 -0
- package/lib/actions/rule.d.ts +7 -0
- package/lib/actions/rule.js +27 -0
- package/lib/actions/rule.js.map +1 -0
- package/lib/actions/sendToContentHub.d.ts +7 -0
- package/lib/actions/sendToContentHub.js +37 -0
- package/lib/actions/sendToContentHub.js.map +1 -0
- package/lib/actions/spotCheckMaterial.d.ts +46 -0
- package/lib/actions/spotCheckMaterial.js +591 -0
- package/lib/actions/spotCheckMaterial.js.map +1 -0
- package/lib/actions/submit.d.ts +7 -0
- package/lib/actions/submit.js +48 -0
- package/lib/actions/submit.js.map +1 -0
- package/lib/actions/submitKids.d.ts +7 -0
- package/lib/actions/submitKids.js +30 -0
- package/lib/actions/submitKids.js.map +1 -0
- package/lib/actions/submitMaterial.d.ts +7 -0
- package/lib/actions/submitMaterial.js +30 -0
- package/lib/actions/submitMaterial.js.map +1 -0
- package/lib/actions/submitPreReview.d.ts +7 -0
- package/lib/actions/submitPreReview.js +34 -0
- package/lib/actions/submitPreReview.js.map +1 -0
- package/lib/actions/terminate.d.ts +7 -0
- package/lib/actions/terminate.js +30 -0
- package/lib/actions/terminate.js.map +1 -0
- package/lib/actions/urgentApproval.d.ts +14 -0
- package/lib/actions/urgentApproval.js +51 -0
- package/lib/actions/urgentApproval.js.map +1 -0
- package/lib/const.d.ts +1 -0
- package/lib/const.js +6 -0
- package/lib/const.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1238 -0
- package/lib/index.js.map +1 -0
- package/lib/methods/AI.d.ts +1 -0
- package/lib/methods/AI.js +45 -0
- package/lib/methods/AI.js.map +1 -0
- package/lib/methods/__tests__/__mocks__/empty.d.ts +2 -0
- package/lib/methods/__tests__/__mocks__/empty.js +4 -0
- package/lib/methods/__tests__/__mocks__/empty.js.map +1 -0
- package/lib/methods/__tests__/postponeReview.test.d.ts +1 -0
- package/lib/methods/__tests__/postponeReview.test.js +102 -0
- package/lib/methods/__tests__/postponeReview.test.js.map +1 -0
- package/lib/methods/__tests__/urgent.test.d.ts +1 -0
- package/lib/methods/__tests__/urgent.test.js +121 -0
- package/lib/methods/__tests__/urgent.test.js.map +1 -0
- package/lib/methods/agent.d.ts +4 -0
- package/lib/methods/agent.js +86 -0
- package/lib/methods/agent.js.map +1 -0
- package/lib/methods/approval_engine.d.ts +40 -0
- package/lib/methods/approval_engine.js +2302 -0
- package/lib/methods/approval_engine.js.map +1 -0
- package/lib/methods/consts.d.ts +209 -0
- package/lib/methods/consts.js +46 -0
- package/lib/methods/consts.js.map +1 -0
- package/lib/methods/content_hub.d.ts +2 -0
- package/lib/methods/content_hub.js +228 -0
- package/lib/methods/content_hub.js.map +1 -0
- package/lib/methods/dashboard_sync_data.d.ts +4 -0
- package/lib/methods/dashboard_sync_data.js +346 -0
- package/lib/methods/dashboard_sync_data.js.map +1 -0
- package/lib/methods/docx.d.ts +3 -0
- package/lib/methods/docx.js +12 -0
- package/lib/methods/docx.js.map +1 -0
- package/lib/methods/image_comparison.d.ts +39 -0
- package/lib/methods/image_comparison.js +454 -0
- package/lib/methods/image_comparison.js.map +1 -0
- package/lib/methods/index.d.ts +7 -0
- package/lib/methods/index.js +11 -0
- package/lib/methods/index.js.map +1 -0
- package/lib/methods/material.d.ts +15 -0
- package/lib/methods/material.js +756 -0
- package/lib/methods/material.js.map +1 -0
- package/lib/methods/notification.d.ts +4 -0
- package/lib/methods/notification.js +270 -0
- package/lib/methods/notification.js.map +1 -0
- package/lib/methods/password_expiry.d.ts +1 -0
- package/lib/methods/password_expiry.js +151 -0
- package/lib/methods/password_expiry.js.map +1 -0
- package/lib/methods/pls.d.ts +1 -0
- package/lib/methods/pls.js +217 -0
- package/lib/methods/pls.js.map +1 -0
- package/lib/methods/urgent.d.ts +20 -0
- package/lib/methods/urgent.js +259 -0
- package/lib/methods/urgent.js.map +1 -0
- package/main/default/objects/pepsico_material_approval/listviews/all.listview.yml +3 -2
- package/main/default/objects/pepsico_material_approval/listviews/collaboration.listview.yml +3 -2
- package/main/default/objects/pepsico_material_approval/listviews/handle.listview.yml +3 -2
- package/main/default/objects/pepsico_material_approval/listviews/handle_postpone.listview.yml +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,2302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.postponeReview = exports.getPostponeReviewDepartmentType = exports.hasReviewed = exports.submitContent = exports.submitPreReviewContent = exports.submitKidsContent = exports.rejectContent = exports.approvalContent = exports.postponeDeployment = exports.confirmDeployment = exports.terminate = exports.advanceApproval = exports.hasNonPreReviewDepartments = exports.getPreReviewStatuses = exports.getDeptEffectiveStatus = exports.isDeptReviewComplete = exports.hasAnyPreReviewer = exports.getApproverStepRule = exports.getDefApproverStepRule = void 0;
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var consts_1 = require("./consts");
|
|
7
|
+
var amis_formula_1 = require("amis-formula");
|
|
8
|
+
var lodash_1 = require("lodash");
|
|
9
|
+
var material_1 = require("./material");
|
|
10
|
+
var content_hub_1 = require("./content_hub");
|
|
11
|
+
var AI_1 = require("./AI");
|
|
12
|
+
var notification_1 = require("./notification");
|
|
13
|
+
var agent_1 = require("./agent");
|
|
14
|
+
var const_1 = require("../const");
|
|
15
|
+
var _ = require("lodash");
|
|
16
|
+
var getDefApproverStepRule = function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
17
|
+
var rules, rule;
|
|
18
|
+
return tslib_1.__generator(this, function (_a) {
|
|
19
|
+
switch (_a.label) {
|
|
20
|
+
case 0: return [4, ctx.getObject('pepsico_flow_rule').find({
|
|
21
|
+
filters: ['fu5nvp', '=', true], fields: ['_id', 'name', 'skip_approve']
|
|
22
|
+
})];
|
|
23
|
+
case 1:
|
|
24
|
+
rules = _a.sent();
|
|
25
|
+
rule = rules.length > 0 ? rules[0] : null;
|
|
26
|
+
if (!rule) {
|
|
27
|
+
throw new Error('未找到审批流规则');
|
|
28
|
+
}
|
|
29
|
+
return [2, rule];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}); };
|
|
33
|
+
exports.getDefApproverStepRule = getDefApproverStepRule;
|
|
34
|
+
var getApproverStepRule = function (ctx, ruleId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
35
|
+
var rule_1, rules, rule;
|
|
36
|
+
return tslib_1.__generator(this, function (_a) {
|
|
37
|
+
switch (_a.label) {
|
|
38
|
+
case 0:
|
|
39
|
+
if (!ruleId) return [3, 2];
|
|
40
|
+
return [4, ctx.getObject('pepsico_flow_rule').findOne(ruleId)];
|
|
41
|
+
case 1:
|
|
42
|
+
rule_1 = _a.sent();
|
|
43
|
+
if (!rule_1) {
|
|
44
|
+
throw new Error('未找到审批流规则');
|
|
45
|
+
}
|
|
46
|
+
return [2, rule_1];
|
|
47
|
+
case 2: return [4, ctx.getObject('pepsico_flow_rule').find({
|
|
48
|
+
fields: ['_id', 'name', 'skip_approve'],
|
|
49
|
+
sort: 'created asc',
|
|
50
|
+
top: 1
|
|
51
|
+
})];
|
|
52
|
+
case 3:
|
|
53
|
+
rules = _a.sent();
|
|
54
|
+
rule = rules.length > 0 ? rules[0] : null;
|
|
55
|
+
if (!rule) {
|
|
56
|
+
throw new Error('未找到审批流规则');
|
|
57
|
+
}
|
|
58
|
+
return [2, rule];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}); };
|
|
62
|
+
exports.getApproverStepRule = getApproverStepRule;
|
|
63
|
+
var isSkipApprover = function (ctx, materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
64
|
+
var rule;
|
|
65
|
+
return tslib_1.__generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0: return [4, (0, exports.getApproverStepRule)(ctx, materialApproval.pepsico_flow_rule)];
|
|
68
|
+
case 1:
|
|
69
|
+
rule = _a.sent();
|
|
70
|
+
if (rule.skip_approve) {
|
|
71
|
+
return [2, (0, amis_formula_1.evaluate)(rule.skip_approve, materialApproval)];
|
|
72
|
+
}
|
|
73
|
+
return [2, false];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}); };
|
|
77
|
+
var hasAnyPreReviewer = function (materialApproval, approvalType) {
|
|
78
|
+
if (approvalType === consts_1.Step.personnel_review) {
|
|
79
|
+
return !!materialApproval.pre_reviewer;
|
|
80
|
+
}
|
|
81
|
+
return !!(materialApproval.pre_ns_reviewer || materialApproval.pre_legal_reviewer ||
|
|
82
|
+
materialApproval.pre_sra_reviewer || materialApproval.pre_ca_reviewer);
|
|
83
|
+
};
|
|
84
|
+
exports.hasAnyPreReviewer = hasAnyPreReviewer;
|
|
85
|
+
var isDeptReviewComplete = function (materialApproval, deptPrefix) {
|
|
86
|
+
var preReviewerField = deptPrefix === 'approval' ? 'pre_reviewer' : "pre_".concat(deptPrefix, "_reviewer");
|
|
87
|
+
var preStatusField = deptPrefix === 'approval' ? 'pre_approval_status' : "pre_".concat(deptPrefix, "_approval_status");
|
|
88
|
+
var formalStatusField = deptPrefix === 'approval' ? 'approval_status' : "".concat(deptPrefix, "_approval_status");
|
|
89
|
+
var hasPreReviewer = !!materialApproval[preReviewerField];
|
|
90
|
+
console.log('isDeptReviewComplete1', hasPreReviewer);
|
|
91
|
+
if (hasPreReviewer) {
|
|
92
|
+
if (!(0, exports.hasReviewed)(materialApproval[preStatusField]))
|
|
93
|
+
return false;
|
|
94
|
+
if (materialApproval[preStatusField] === false)
|
|
95
|
+
return true;
|
|
96
|
+
return (0, exports.hasReviewed)(materialApproval[formalStatusField]);
|
|
97
|
+
}
|
|
98
|
+
console.log('isDeptReviewComplete2', materialApproval[formalStatusField], (0, exports.hasReviewed)(materialApproval[formalStatusField]));
|
|
99
|
+
return (0, exports.hasReviewed)(materialApproval[formalStatusField]);
|
|
100
|
+
};
|
|
101
|
+
exports.isDeptReviewComplete = isDeptReviewComplete;
|
|
102
|
+
var getDeptEffectiveStatus = function (materialApproval, deptPrefix) {
|
|
103
|
+
var preReviewerField = deptPrefix === 'approval' ? 'pre_reviewer' : "pre_".concat(deptPrefix, "_reviewer");
|
|
104
|
+
var preStatusField = deptPrefix === 'approval' ? 'pre_approval_status' : "pre_".concat(deptPrefix, "_approval_status");
|
|
105
|
+
var formalStatusField = deptPrefix === 'approval' ? 'approval_status' : "".concat(deptPrefix, "_approval_status");
|
|
106
|
+
var hasPreReviewer = !!materialApproval[preReviewerField];
|
|
107
|
+
if (hasPreReviewer && materialApproval[preStatusField] === false) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return materialApproval[formalStatusField];
|
|
111
|
+
};
|
|
112
|
+
exports.getDeptEffectiveStatus = getDeptEffectiveStatus;
|
|
113
|
+
var getApproverStep = function (ctx, materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
114
|
+
var rule, skipApprover, reView, approvalType;
|
|
115
|
+
return tslib_1.__generator(this, function (_a) {
|
|
116
|
+
switch (_a.label) {
|
|
117
|
+
case 0: return [4, (0, exports.getApproverStepRule)(ctx, materialApproval.pepsico_flow_rule)];
|
|
118
|
+
case 1:
|
|
119
|
+
rule = _a.sent();
|
|
120
|
+
return [4, isSkipApprover(ctx, materialApproval)];
|
|
121
|
+
case 2:
|
|
122
|
+
skipApprover = _a.sent();
|
|
123
|
+
if (skipApprover) {
|
|
124
|
+
return [2, consts_1.Step.conclusion];
|
|
125
|
+
}
|
|
126
|
+
reView = (0, amis_formula_1.evaluate)(rule.name, materialApproval);
|
|
127
|
+
console.log("getApproverStep-".concat(materialApproval._id), reView, typeof reView, rule.name, JSON.stringify(materialApproval));
|
|
128
|
+
approvalType = reView ? consts_1.Step.personnel_review : consts_1.Step.departmental_review;
|
|
129
|
+
return [2, approvalType];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}); };
|
|
133
|
+
var getApproveType = function (ctx, materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
134
|
+
var rule, reView;
|
|
135
|
+
return tslib_1.__generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0: return [4, (0, exports.getApproverStepRule)(ctx, materialApproval.pepsico_flow_rule)];
|
|
138
|
+
case 1:
|
|
139
|
+
rule = _a.sent();
|
|
140
|
+
reView = (0, amis_formula_1.evaluate)(rule.name, materialApproval);
|
|
141
|
+
if (reView) {
|
|
142
|
+
return [2, consts_1.Step.personnel_review];
|
|
143
|
+
}
|
|
144
|
+
return [2, consts_1.Step.departmental_review];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}); };
|
|
148
|
+
var getNextStep = function (ctx, materialApproval, action) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
149
|
+
var nextStep, _a, _b;
|
|
150
|
+
return tslib_1.__generator(this, function (_c) {
|
|
151
|
+
switch (_c.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
nextStep = consts_1.Step.draft;
|
|
154
|
+
_a = materialApproval.current_step;
|
|
155
|
+
switch (_a) {
|
|
156
|
+
case consts_1.Step.draft: return [3, 1];
|
|
157
|
+
case consts_1.Step.ai_review: return [3, 2];
|
|
158
|
+
case consts_1.Step.departmental_review: return [3, 6];
|
|
159
|
+
case consts_1.Step.personnel_review: return [3, 6];
|
|
160
|
+
case consts_1.Step.submitter_revisions: return [3, 7];
|
|
161
|
+
case consts_1.Step.awaiting_deployment: return [3, 9];
|
|
162
|
+
}
|
|
163
|
+
return [3, 10];
|
|
164
|
+
case 1:
|
|
165
|
+
if (_.includes(const_1.DCO_TYPES, materialApproval.classification)) {
|
|
166
|
+
nextStep = consts_1.Step.conclusion;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
nextStep = consts_1.Step.ai_review;
|
|
170
|
+
}
|
|
171
|
+
return [3, 11];
|
|
172
|
+
case 2:
|
|
173
|
+
if (!(action == consts_1.ApprovalStatus.approved)) return [3, 4];
|
|
174
|
+
return [4, getApproverStep(ctx, materialApproval)];
|
|
175
|
+
case 3:
|
|
176
|
+
_b = _c.sent();
|
|
177
|
+
return [3, 5];
|
|
178
|
+
case 4:
|
|
179
|
+
_b = consts_1.Step.draft;
|
|
180
|
+
_c.label = 5;
|
|
181
|
+
case 5:
|
|
182
|
+
nextStep = _b;
|
|
183
|
+
return [3, 11];
|
|
184
|
+
case 6:
|
|
185
|
+
nextStep = (action == consts_1.ApprovalStatus.approved || action == consts_1.ApprovalStatus.pass) ? consts_1.Step.awaiting_deployment : consts_1.Step.submitter_revisions;
|
|
186
|
+
return [3, 11];
|
|
187
|
+
case 7: return [4, getApproverStep(ctx, materialApproval)];
|
|
188
|
+
case 8:
|
|
189
|
+
nextStep = _c.sent();
|
|
190
|
+
return [3, 11];
|
|
191
|
+
case 9:
|
|
192
|
+
nextStep = consts_1.Step.conclusion;
|
|
193
|
+
return [3, 11];
|
|
194
|
+
case 10: return [3, 11];
|
|
195
|
+
case 11:
|
|
196
|
+
console.log('[getNextStep]', JSON.stringify({
|
|
197
|
+
action: action,
|
|
198
|
+
nextStep: nextStep
|
|
199
|
+
}));
|
|
200
|
+
return [2, nextStep];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); };
|
|
204
|
+
var getNextApprovers = function (ctx, materialApproval, nextStep) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
205
|
+
var approves, _a, preNsAgents, nsAgents, preLegalAgents, legalAgents, preSraAgents, sraAgents, preCaAgents, caAgents, kidsAgents, preAgents, perAgents, kidsAgents;
|
|
206
|
+
return tslib_1.__generator(this, function (_b) {
|
|
207
|
+
switch (_b.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
approves = [];
|
|
210
|
+
_a = nextStep;
|
|
211
|
+
switch (_a) {
|
|
212
|
+
case consts_1.Step.draft: return [3, 1];
|
|
213
|
+
case consts_1.Step.ai_review: return [3, 2];
|
|
214
|
+
case consts_1.Step.departmental_review: return [3, 3];
|
|
215
|
+
case consts_1.Step.personnel_review: return [3, 22];
|
|
216
|
+
case consts_1.Step.submitter_revisions: return [3, 29];
|
|
217
|
+
case consts_1.Step.awaiting_deployment: return [3, 30];
|
|
218
|
+
}
|
|
219
|
+
return [3, 31];
|
|
220
|
+
case 1:
|
|
221
|
+
approves = (0, lodash_1.concat)(approves, {
|
|
222
|
+
userIds: [materialApproval.owner],
|
|
223
|
+
type: consts_1.ProcessApprovalType.Others
|
|
224
|
+
});
|
|
225
|
+
return [3, 32];
|
|
226
|
+
case 2:
|
|
227
|
+
approves = (0, lodash_1.concat)(approves, {
|
|
228
|
+
userIds: [process.env.PEPSICO_CONTENT_APPROVAL_AI_USERID],
|
|
229
|
+
type: consts_1.ProcessApprovalType.AI
|
|
230
|
+
});
|
|
231
|
+
return [3, 32];
|
|
232
|
+
case 3:
|
|
233
|
+
console.log('[getNextApprovers] departmental_review 串行判断:', JSON.stringify({
|
|
234
|
+
pre_ns_reviewer: materialApproval.pre_ns_reviewer,
|
|
235
|
+
pre_ns_approval_status: materialApproval.pre_ns_approval_status,
|
|
236
|
+
pre_legal_reviewer: materialApproval.pre_legal_reviewer,
|
|
237
|
+
pre_legal_approval_status: materialApproval.pre_legal_approval_status,
|
|
238
|
+
pre_sra_reviewer: materialApproval.pre_sra_reviewer,
|
|
239
|
+
pre_sra_approval_status: materialApproval.pre_sra_approval_status,
|
|
240
|
+
pre_ca_reviewer: materialApproval.pre_ca_reviewer,
|
|
241
|
+
pre_ca_approval_status: materialApproval.pre_ca_approval_status,
|
|
242
|
+
}));
|
|
243
|
+
if (!(materialApproval.pre_ns_reviewer && materialApproval.pre_ns_approval_status != true && materialApproval.pre_ns_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 5];
|
|
244
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.pre_ns_reviewer])];
|
|
245
|
+
case 4:
|
|
246
|
+
preNsAgents = _b.sent();
|
|
247
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, preNsAgents), { type: consts_1.ProcessApprovalType.PreNS }));
|
|
248
|
+
return [3, 7];
|
|
249
|
+
case 5:
|
|
250
|
+
if (!(materialApproval.ns_approval_status != true && materialApproval.ns_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 7];
|
|
251
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, materialApproval.ns_reviewer)];
|
|
252
|
+
case 6:
|
|
253
|
+
nsAgents = _b.sent();
|
|
254
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, nsAgents), { type: consts_1.ProcessApprovalType.NS }));
|
|
255
|
+
_b.label = 7;
|
|
256
|
+
case 7:
|
|
257
|
+
if (!(materialApproval.pre_legal_reviewer && materialApproval.pre_legal_approval_status != true && materialApproval.pre_legal_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 9];
|
|
258
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.pre_legal_reviewer])];
|
|
259
|
+
case 8:
|
|
260
|
+
preLegalAgents = _b.sent();
|
|
261
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, preLegalAgents), { type: consts_1.ProcessApprovalType.PreLegal }));
|
|
262
|
+
return [3, 11];
|
|
263
|
+
case 9:
|
|
264
|
+
if (!(materialApproval.legal_approval_status != true && materialApproval.legal_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 11];
|
|
265
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, materialApproval.legal_reviewer)];
|
|
266
|
+
case 10:
|
|
267
|
+
legalAgents = _b.sent();
|
|
268
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, legalAgents), { type: consts_1.ProcessApprovalType.Legal }));
|
|
269
|
+
_b.label = 11;
|
|
270
|
+
case 11:
|
|
271
|
+
if (!(materialApproval.pre_sra_reviewer && materialApproval.pre_sra_approval_status != true && materialApproval.pre_sra_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 13];
|
|
272
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.pre_sra_reviewer])];
|
|
273
|
+
case 12:
|
|
274
|
+
preSraAgents = _b.sent();
|
|
275
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, preSraAgents), { type: consts_1.ProcessApprovalType.PreSRA }));
|
|
276
|
+
return [3, 15];
|
|
277
|
+
case 13:
|
|
278
|
+
if (!(materialApproval.sra_approval_status != true && materialApproval.sra_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 15];
|
|
279
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, materialApproval.sra_reviewer)];
|
|
280
|
+
case 14:
|
|
281
|
+
sraAgents = _b.sent();
|
|
282
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, sraAgents), { type: consts_1.ProcessApprovalType.SRA }));
|
|
283
|
+
_b.label = 15;
|
|
284
|
+
case 15:
|
|
285
|
+
if (!(materialApproval.pre_ca_reviewer && materialApproval.pre_ca_approval_status != true && materialApproval.pre_ca_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 17];
|
|
286
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.pre_ca_reviewer])];
|
|
287
|
+
case 16:
|
|
288
|
+
preCaAgents = _b.sent();
|
|
289
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, preCaAgents), { type: consts_1.ProcessApprovalType.PreCA }));
|
|
290
|
+
return [3, 19];
|
|
291
|
+
case 17:
|
|
292
|
+
if (!(materialApproval.ca_approval_status != true && materialApproval.ca_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 19];
|
|
293
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, materialApproval.ca_reviewer)];
|
|
294
|
+
case 18:
|
|
295
|
+
caAgents = _b.sent();
|
|
296
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, caAgents), { type: consts_1.ProcessApprovalType.CA }));
|
|
297
|
+
_b.label = 19;
|
|
298
|
+
case 19:
|
|
299
|
+
if (!(materialApproval.child_files == 'yes' && materialApproval.kids_approval_status != true && materialApproval.kids_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 21];
|
|
300
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.kids_reviewer])];
|
|
301
|
+
case 20:
|
|
302
|
+
kidsAgents = _b.sent();
|
|
303
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, kidsAgents), { type: consts_1.ProcessApprovalType.Kids }));
|
|
304
|
+
_b.label = 21;
|
|
305
|
+
case 21: return [3, 32];
|
|
306
|
+
case 22:
|
|
307
|
+
if (!(materialApproval.pre_reviewer && materialApproval.pre_approval_status != true && materialApproval.pre_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 24];
|
|
308
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.pre_reviewer])];
|
|
309
|
+
case 23:
|
|
310
|
+
preAgents = _b.sent();
|
|
311
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, preAgents), { type: consts_1.ProcessApprovalType.Preguding }));
|
|
312
|
+
return [3, 26];
|
|
313
|
+
case 24:
|
|
314
|
+
if (!(materialApproval.approval_status !== consts_1.ApprovalStatus.pass)) return [3, 26];
|
|
315
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, materialApproval.reviewer)];
|
|
316
|
+
case 25:
|
|
317
|
+
perAgents = _b.sent();
|
|
318
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, perAgents), { type: consts_1.ProcessApprovalType.guding }));
|
|
319
|
+
_b.label = 26;
|
|
320
|
+
case 26:
|
|
321
|
+
if (!(materialApproval.child_files == 'yes' && materialApproval.kids_approval_status != true && materialApproval.kids_approval_status !== consts_1.ApprovalStatus.pass)) return [3, 28];
|
|
322
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, [materialApproval.kids_reviewer])];
|
|
323
|
+
case 27:
|
|
324
|
+
kidsAgents = _b.sent();
|
|
325
|
+
approves = (0, lodash_1.concat)(approves, tslib_1.__assign(tslib_1.__assign({}, kidsAgents), { type: consts_1.ProcessApprovalType.Kids }));
|
|
326
|
+
_b.label = 28;
|
|
327
|
+
case 28: return [3, 32];
|
|
328
|
+
case 29:
|
|
329
|
+
approves = (0, lodash_1.concat)(approves, {
|
|
330
|
+
userIds: [materialApproval.owner],
|
|
331
|
+
type: consts_1.ProcessApprovalType.Others
|
|
332
|
+
});
|
|
333
|
+
return [3, 32];
|
|
334
|
+
case 30:
|
|
335
|
+
approves = (0, lodash_1.concat)(approves, {
|
|
336
|
+
userIds: [materialApproval.material_owner_id],
|
|
337
|
+
type: consts_1.ProcessApprovalType.Others
|
|
338
|
+
});
|
|
339
|
+
return [3, 32];
|
|
340
|
+
case 31: return [3, 32];
|
|
341
|
+
case 32: return [2, (0, lodash_1.uniq)(approves)];
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}); };
|
|
345
|
+
var canSubmit = function (materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
346
|
+
return tslib_1.__generator(this, function (_a) {
|
|
347
|
+
if (materialApproval.review_status === consts_1.ReviewStatus.terminated) {
|
|
348
|
+
throw new Error("已中止审核.");
|
|
349
|
+
}
|
|
350
|
+
if (materialApproval.current_step === consts_1.Step.conclusion) {
|
|
351
|
+
throw new Error("已审核完成.");
|
|
352
|
+
}
|
|
353
|
+
return [2, true];
|
|
354
|
+
});
|
|
355
|
+
}); };
|
|
356
|
+
var getReviewStatus = function (nextStep) {
|
|
357
|
+
if (nextStep === consts_1.Step.draft) {
|
|
358
|
+
return consts_1.ReviewStatus.draft;
|
|
359
|
+
}
|
|
360
|
+
else if (nextStep === consts_1.Step.conclusion) {
|
|
361
|
+
return true ? consts_1.ReviewStatus.approved : consts_1.ReviewStatus.rejected;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
return consts_1.ReviewStatus.under_review;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var updateUserStepStatus = function (ctx, materialApproval, _a) {
|
|
368
|
+
var approvalStatus = _a.approvalStatus, approveField = _a.approveField;
|
|
369
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
370
|
+
var user, filters, process, process_1, process_1_1, item, processOthers, processOthers_1, processOthers_1_1, item_1, e_1_1, e_2_1;
|
|
371
|
+
var e_2, _b, e_1, _c;
|
|
372
|
+
return tslib_1.__generator(this, function (_d) {
|
|
373
|
+
switch (_d.label) {
|
|
374
|
+
case 0:
|
|
375
|
+
user = ctx.meta.user;
|
|
376
|
+
filters = [
|
|
377
|
+
["owner", "=", user.userId],
|
|
378
|
+
["pepsico_material_approval", "=", materialApproval._id],
|
|
379
|
+
["current_step", "=", materialApproval.current_step],
|
|
380
|
+
["space", "=", materialApproval.space],
|
|
381
|
+
["approved", "=", 'progess']
|
|
382
|
+
];
|
|
383
|
+
if (approveField && approveField === 'kids_approval_status') {
|
|
384
|
+
filters.push(["type", "=", 'Kids']);
|
|
385
|
+
}
|
|
386
|
+
else if (approveField === 'ca_approval_status') {
|
|
387
|
+
filters.push(["type", "=", 'CA']);
|
|
388
|
+
}
|
|
389
|
+
else if (approveField === 'sra_approval_status') {
|
|
390
|
+
filters.push(["type", "=", 'SRA']);
|
|
391
|
+
}
|
|
392
|
+
else if (approveField === 'ns_approval_status') {
|
|
393
|
+
filters.push(["type", "=", 'NS']);
|
|
394
|
+
}
|
|
395
|
+
else if (approveField === 'legal_approval_status') {
|
|
396
|
+
filters.push(["type", "=", 'Legal']);
|
|
397
|
+
}
|
|
398
|
+
else if (approveField === 'approval_status') {
|
|
399
|
+
filters.push(["type", "=", 'guding']);
|
|
400
|
+
}
|
|
401
|
+
else if (approveField === 'pre_ns_approval_status') {
|
|
402
|
+
filters.push(["type", "=", 'PreNS']);
|
|
403
|
+
}
|
|
404
|
+
else if (approveField === 'pre_legal_approval_status') {
|
|
405
|
+
filters.push(["type", "=", 'PreLegal']);
|
|
406
|
+
}
|
|
407
|
+
else if (approveField === 'pre_sra_approval_status') {
|
|
408
|
+
filters.push(["type", "=", 'PreSRA']);
|
|
409
|
+
}
|
|
410
|
+
else if (approveField === 'pre_ca_approval_status') {
|
|
411
|
+
filters.push(["type", "=", 'PreCA']);
|
|
412
|
+
}
|
|
413
|
+
else if (approveField === 'pre_approval_status') {
|
|
414
|
+
filters.push(["type", "=", 'Preguding']);
|
|
415
|
+
}
|
|
416
|
+
return [4, ctx.getObject("pepsico_approval_process").find({
|
|
417
|
+
filters: filters,
|
|
418
|
+
top: 1,
|
|
419
|
+
sort: "modified asc"
|
|
420
|
+
})];
|
|
421
|
+
case 1:
|
|
422
|
+
process = _d.sent();
|
|
423
|
+
_d.label = 2;
|
|
424
|
+
case 2:
|
|
425
|
+
_d.trys.push([2, 15, 16, 17]);
|
|
426
|
+
process_1 = tslib_1.__values(process), process_1_1 = process_1.next();
|
|
427
|
+
_d.label = 3;
|
|
428
|
+
case 3:
|
|
429
|
+
if (!!process_1_1.done) return [3, 14];
|
|
430
|
+
item = process_1_1.value;
|
|
431
|
+
return [4, ctx.getObject("pepsico_approval_process").update(item._id, {
|
|
432
|
+
submitted: new Date(),
|
|
433
|
+
modified: new Date(),
|
|
434
|
+
modified_by: user.userId,
|
|
435
|
+
approved: approvalStatus || 'submit'
|
|
436
|
+
})];
|
|
437
|
+
case 4:
|
|
438
|
+
_d.sent();
|
|
439
|
+
return [4, ctx.getObject("pepsico_approval_process").find({
|
|
440
|
+
filters: [
|
|
441
|
+
["owner", "!=", user.userId],
|
|
442
|
+
["pepsico_material_approval", "=", materialApproval._id],
|
|
443
|
+
["current_step", "=", materialApproval.current_step],
|
|
444
|
+
["space", "=", materialApproval.space],
|
|
445
|
+
["approved", "=", 'progess'],
|
|
446
|
+
["type", "=", item.type]
|
|
447
|
+
],
|
|
448
|
+
sort: "modified desc"
|
|
449
|
+
})];
|
|
450
|
+
case 5:
|
|
451
|
+
processOthers = _d.sent();
|
|
452
|
+
_d.label = 6;
|
|
453
|
+
case 6:
|
|
454
|
+
_d.trys.push([6, 11, 12, 13]);
|
|
455
|
+
processOthers_1 = (e_1 = void 0, tslib_1.__values(processOthers)), processOthers_1_1 = processOthers_1.next();
|
|
456
|
+
_d.label = 7;
|
|
457
|
+
case 7:
|
|
458
|
+
if (!!processOthers_1_1.done) return [3, 10];
|
|
459
|
+
item_1 = processOthers_1_1.value;
|
|
460
|
+
return [4, ctx.getObject("pepsico_approval_process").update(item_1._id, {
|
|
461
|
+
modified: new Date(),
|
|
462
|
+
modified_by: user.userId,
|
|
463
|
+
approved: ''
|
|
464
|
+
})];
|
|
465
|
+
case 8:
|
|
466
|
+
_d.sent();
|
|
467
|
+
_d.label = 9;
|
|
468
|
+
case 9:
|
|
469
|
+
processOthers_1_1 = processOthers_1.next();
|
|
470
|
+
return [3, 7];
|
|
471
|
+
case 10: return [3, 13];
|
|
472
|
+
case 11:
|
|
473
|
+
e_1_1 = _d.sent();
|
|
474
|
+
e_1 = { error: e_1_1 };
|
|
475
|
+
return [3, 13];
|
|
476
|
+
case 12:
|
|
477
|
+
try {
|
|
478
|
+
if (processOthers_1_1 && !processOthers_1_1.done && (_c = processOthers_1.return)) _c.call(processOthers_1);
|
|
479
|
+
}
|
|
480
|
+
finally { if (e_1) throw e_1.error; }
|
|
481
|
+
return [7];
|
|
482
|
+
case 13:
|
|
483
|
+
process_1_1 = process_1.next();
|
|
484
|
+
return [3, 3];
|
|
485
|
+
case 14: return [3, 17];
|
|
486
|
+
case 15:
|
|
487
|
+
e_2_1 = _d.sent();
|
|
488
|
+
e_2 = { error: e_2_1 };
|
|
489
|
+
return [3, 17];
|
|
490
|
+
case 16:
|
|
491
|
+
try {
|
|
492
|
+
if (process_1_1 && !process_1_1.done && (_b = process_1.return)) _b.call(process_1);
|
|
493
|
+
}
|
|
494
|
+
finally { if (e_2) throw e_2.error; }
|
|
495
|
+
return [7];
|
|
496
|
+
case 17: return [2];
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFieldValue) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
502
|
+
var userId, set, approvalNew, approvals, index, postponedUsers, postponeRecords, postponeRecords_1, postponeRecords_1_1, pr, prUserIds, e_3_1;
|
|
503
|
+
var _a, e_3, _b;
|
|
504
|
+
return tslib_1.__generator(this, function (_c) {
|
|
505
|
+
switch (_c.label) {
|
|
506
|
+
case 0:
|
|
507
|
+
userId = ctx.meta.user.userId;
|
|
508
|
+
if (!approveField) return [3, 13];
|
|
509
|
+
set = (_a = {},
|
|
510
|
+
_a[approveField] = approveFieldValue,
|
|
511
|
+
_a);
|
|
512
|
+
if (!userId) return [3, 11];
|
|
513
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
514
|
+
case 1:
|
|
515
|
+
approvalNew = _c.sent();
|
|
516
|
+
approvals = approvalNew.person_pending_approve || [];
|
|
517
|
+
index = (0, lodash_1.findIndex)(approvals, function (item) { return item === userId; });
|
|
518
|
+
if (index !== -1) {
|
|
519
|
+
(0, lodash_1.pullAt)(approvals, index);
|
|
520
|
+
}
|
|
521
|
+
set.person_pending_approve = approvals;
|
|
522
|
+
set.$push = {
|
|
523
|
+
person_approved: userId
|
|
524
|
+
};
|
|
525
|
+
postponedUsers = approvalNew.review_postponed_users || [];
|
|
526
|
+
if (!postponedUsers.includes(userId)) return [3, 11];
|
|
527
|
+
set.review_postponed_users = postponedUsers.filter(function (uid) { return uid !== userId; });
|
|
528
|
+
return [4, ctx.getObject('pepsico_review_postpone').directFind({
|
|
529
|
+
filters: [
|
|
530
|
+
['pepsico_material_approval', '=', recordId],
|
|
531
|
+
['notification_sent', '=', false],
|
|
532
|
+
['is_marker', '!=', true]
|
|
533
|
+
]
|
|
534
|
+
})];
|
|
535
|
+
case 2:
|
|
536
|
+
postponeRecords = _c.sent();
|
|
537
|
+
_c.label = 3;
|
|
538
|
+
case 3:
|
|
539
|
+
_c.trys.push([3, 8, 9, 10]);
|
|
540
|
+
postponeRecords_1 = tslib_1.__values(postponeRecords), postponeRecords_1_1 = postponeRecords_1.next();
|
|
541
|
+
_c.label = 4;
|
|
542
|
+
case 4:
|
|
543
|
+
if (!!postponeRecords_1_1.done) return [3, 7];
|
|
544
|
+
pr = postponeRecords_1_1.value;
|
|
545
|
+
prUserIds = pr.postponed_user_ids ? pr.postponed_user_ids.split(',').filter(Boolean) : [];
|
|
546
|
+
if (!prUserIds.includes(userId)) return [3, 6];
|
|
547
|
+
return [4, ctx.getObject('pepsico_review_postpone').directUpdate(pr._id, {
|
|
548
|
+
notification_sent: true
|
|
549
|
+
})];
|
|
550
|
+
case 5:
|
|
551
|
+
_c.sent();
|
|
552
|
+
_c.label = 6;
|
|
553
|
+
case 6:
|
|
554
|
+
postponeRecords_1_1 = postponeRecords_1.next();
|
|
555
|
+
return [3, 4];
|
|
556
|
+
case 7: return [3, 10];
|
|
557
|
+
case 8:
|
|
558
|
+
e_3_1 = _c.sent();
|
|
559
|
+
e_3 = { error: e_3_1 };
|
|
560
|
+
return [3, 10];
|
|
561
|
+
case 9:
|
|
562
|
+
try {
|
|
563
|
+
if (postponeRecords_1_1 && !postponeRecords_1_1.done && (_b = postponeRecords_1.return)) _b.call(postponeRecords_1);
|
|
564
|
+
}
|
|
565
|
+
finally { if (e_3) throw e_3.error; }
|
|
566
|
+
return [7];
|
|
567
|
+
case 10:
|
|
568
|
+
console.log("[updateApproveFieldStatus] \u5EF6\u540E\u5BA1\u6838\u4EBA\u63D0\u524D\u5BA1\u6838\uFF0C\u5DF2\u6E05\u7406 review_postponed_users: ".concat(userId));
|
|
569
|
+
_c.label = 11;
|
|
570
|
+
case 11:
|
|
571
|
+
console.log('[updateApproveFieldStatus]', JSON.stringify({ recordId: recordId, set: set }));
|
|
572
|
+
return [4, ctx.getObject('pepsico_material_approval').update(recordId, set)];
|
|
573
|
+
case 12:
|
|
574
|
+
_c.sent();
|
|
575
|
+
_c.label = 13;
|
|
576
|
+
case 13: return [2];
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}); };
|
|
580
|
+
var changeApprovalProcess = function (ctx, materialApproval, _a) {
|
|
581
|
+
var nextStep = _a.nextStep, nextApprovers = _a.nextApprovers, description = _a.description;
|
|
582
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
583
|
+
var user, count, now, sUsers, _b, nextApprovers_1, nextApprovers_1_1, nextApprover, _c, _d, userId, spaceUsers, e_4_1, e_5_1;
|
|
584
|
+
var e_5, _e, e_4, _f, _g;
|
|
585
|
+
return tslib_1.__generator(this, function (_h) {
|
|
586
|
+
switch (_h.label) {
|
|
587
|
+
case 0:
|
|
588
|
+
console.log("[changeApprovalProcess]", nextStep, nextApprovers, description);
|
|
589
|
+
user = ctx.meta.user;
|
|
590
|
+
if (!(!materialApproval.current_step || materialApproval.current_step == consts_1.Step.draft)) return [3, 3];
|
|
591
|
+
return [4, ctx.getObject("pepsico_approval_process").count({
|
|
592
|
+
filters: [
|
|
593
|
+
["pepsico_material_approval", "=", materialApproval._id],
|
|
594
|
+
["space", "=", materialApproval.space]
|
|
595
|
+
]
|
|
596
|
+
})];
|
|
597
|
+
case 1:
|
|
598
|
+
count = _h.sent();
|
|
599
|
+
if (!(count == 0)) return [3, 3];
|
|
600
|
+
now = new Date();
|
|
601
|
+
return [4, ctx.getObject('pepsico_approval_process').insert({
|
|
602
|
+
pepsico_material_approval: materialApproval._id,
|
|
603
|
+
owner: user.userId,
|
|
604
|
+
review_department: user.organization._id,
|
|
605
|
+
current_step: consts_1.Step.draft,
|
|
606
|
+
space: materialApproval.space,
|
|
607
|
+
created: now,
|
|
608
|
+
created_by: user.userId,
|
|
609
|
+
modified: now,
|
|
610
|
+
modified_by: user.userId,
|
|
611
|
+
name: description,
|
|
612
|
+
submitted: now,
|
|
613
|
+
approved: 'submit'
|
|
614
|
+
})];
|
|
615
|
+
case 2:
|
|
616
|
+
_h.sent();
|
|
617
|
+
_h.label = 3;
|
|
618
|
+
case 3:
|
|
619
|
+
sUsers = null;
|
|
620
|
+
_b = nextStep;
|
|
621
|
+
switch (_b) {
|
|
622
|
+
case consts_1.Step.draft: return [3, 4];
|
|
623
|
+
case consts_1.Step.ai_review: return [3, 4];
|
|
624
|
+
case consts_1.Step.departmental_review: return [3, 4];
|
|
625
|
+
case consts_1.Step.personnel_review: return [3, 4];
|
|
626
|
+
case consts_1.Step.submitter_revisions: return [3, 4];
|
|
627
|
+
case consts_1.Step.awaiting_deployment: return [3, 4];
|
|
628
|
+
case consts_1.Step.conclusion: return [3, 21];
|
|
629
|
+
}
|
|
630
|
+
return [3, 23];
|
|
631
|
+
case 4:
|
|
632
|
+
_h.trys.push([4, 18, 19, 20]);
|
|
633
|
+
nextApprovers_1 = tslib_1.__values(nextApprovers), nextApprovers_1_1 = nextApprovers_1.next();
|
|
634
|
+
_h.label = 5;
|
|
635
|
+
case 5:
|
|
636
|
+
if (!!nextApprovers_1_1.done) return [3, 17];
|
|
637
|
+
nextApprover = nextApprovers_1_1.value;
|
|
638
|
+
_h.label = 6;
|
|
639
|
+
case 6:
|
|
640
|
+
_h.trys.push([6, 12, 13, 14]);
|
|
641
|
+
_c = (e_4 = void 0, tslib_1.__values(nextApprover.userIds)), _d = _c.next();
|
|
642
|
+
_h.label = 7;
|
|
643
|
+
case 7:
|
|
644
|
+
if (!!_d.done) return [3, 11];
|
|
645
|
+
userId = _d.value;
|
|
646
|
+
return [4, ctx.getObject('space_users').directFind({ filters: [['user', '=', userId], ['space', '=', materialApproval.space]] })];
|
|
647
|
+
case 8:
|
|
648
|
+
spaceUsers = _h.sent();
|
|
649
|
+
return [4, ctx.getObject('pepsico_approval_process').insert({
|
|
650
|
+
pepsico_material_approval: materialApproval._id,
|
|
651
|
+
owner: userId,
|
|
652
|
+
type: nextApprover.type,
|
|
653
|
+
review_department: spaceUsers.length > 0 ? spaceUsers[0].organization : null,
|
|
654
|
+
current_step: nextStep,
|
|
655
|
+
approved: "progess",
|
|
656
|
+
space: materialApproval.space,
|
|
657
|
+
created: new Date(),
|
|
658
|
+
created_by: user.userId,
|
|
659
|
+
modified: new Date(),
|
|
660
|
+
modified_by: user.userId,
|
|
661
|
+
name: description
|
|
662
|
+
})];
|
|
663
|
+
case 9:
|
|
664
|
+
_h.sent();
|
|
665
|
+
_h.label = 10;
|
|
666
|
+
case 10:
|
|
667
|
+
_d = _c.next();
|
|
668
|
+
return [3, 7];
|
|
669
|
+
case 11: return [3, 14];
|
|
670
|
+
case 12:
|
|
671
|
+
e_4_1 = _h.sent();
|
|
672
|
+
e_4 = { error: e_4_1 };
|
|
673
|
+
return [3, 14];
|
|
674
|
+
case 13:
|
|
675
|
+
try {
|
|
676
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
677
|
+
}
|
|
678
|
+
finally { if (e_4) throw e_4.error; }
|
|
679
|
+
return [7];
|
|
680
|
+
case 14:
|
|
681
|
+
if (!nextApprover.type) return [3, 16];
|
|
682
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(materialApproval._id, (_g = {},
|
|
683
|
+
_g["handler_".concat((0, lodash_1.toLower)(nextApprover.type))] = nextApprover.userIds,
|
|
684
|
+
_g))];
|
|
685
|
+
case 15:
|
|
686
|
+
_h.sent();
|
|
687
|
+
_h.label = 16;
|
|
688
|
+
case 16:
|
|
689
|
+
nextApprovers_1_1 = nextApprovers_1.next();
|
|
690
|
+
return [3, 5];
|
|
691
|
+
case 17: return [3, 20];
|
|
692
|
+
case 18:
|
|
693
|
+
e_5_1 = _h.sent();
|
|
694
|
+
e_5 = { error: e_5_1 };
|
|
695
|
+
return [3, 20];
|
|
696
|
+
case 19:
|
|
697
|
+
try {
|
|
698
|
+
if (nextApprovers_1_1 && !nextApprovers_1_1.done && (_e = nextApprovers_1.return)) _e.call(nextApprovers_1);
|
|
699
|
+
}
|
|
700
|
+
finally { if (e_5) throw e_5.error; }
|
|
701
|
+
return [7];
|
|
702
|
+
case 20: return [3, 24];
|
|
703
|
+
case 21: return [4, ctx.getObject('pepsico_approval_process').insert({
|
|
704
|
+
pepsico_material_approval: materialApproval._id,
|
|
705
|
+
current_step: consts_1.Step.conclusion,
|
|
706
|
+
space: materialApproval.space,
|
|
707
|
+
created: new Date(),
|
|
708
|
+
created_by: user.userId,
|
|
709
|
+
modified: new Date(),
|
|
710
|
+
modified_by: user.userId,
|
|
711
|
+
name: description
|
|
712
|
+
})];
|
|
713
|
+
case 22:
|
|
714
|
+
_h.sent();
|
|
715
|
+
return [3, 24];
|
|
716
|
+
case 23: return [3, 24];
|
|
717
|
+
case 24: return [2];
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
};
|
|
722
|
+
var setPersonView = function (ctx, materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
723
|
+
var approvalType, personView;
|
|
724
|
+
return tslib_1.__generator(this, function (_a) {
|
|
725
|
+
switch (_a.label) {
|
|
726
|
+
case 0: return [4, getApproveType(ctx, materialApproval)];
|
|
727
|
+
case 1:
|
|
728
|
+
approvalType = _a.sent();
|
|
729
|
+
personView = [];
|
|
730
|
+
if (approvalType === consts_1.Step.personnel_review) {
|
|
731
|
+
personView = (0, lodash_1.concat)(materialApproval.reviewer, materialApproval.assistance);
|
|
732
|
+
if (materialApproval.pre_reviewer) {
|
|
733
|
+
personView = (0, lodash_1.concat)(personView, materialApproval.pre_reviewer);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
else {
|
|
737
|
+
personView = (0, lodash_1.concat)(materialApproval.sra_reviewer, materialApproval.ns_reviewer, materialApproval.ca_reviewer, materialApproval.legal_reviewer, materialApproval.sra_assistance, materialApproval.ns_assistance, materialApproval.ca_assistance, materialApproval.legal_assistance);
|
|
738
|
+
if (materialApproval.pre_ns_reviewer)
|
|
739
|
+
personView = (0, lodash_1.concat)(personView, materialApproval.pre_ns_reviewer);
|
|
740
|
+
if (materialApproval.pre_legal_reviewer)
|
|
741
|
+
personView = (0, lodash_1.concat)(personView, materialApproval.pre_legal_reviewer);
|
|
742
|
+
if (materialApproval.pre_sra_reviewer)
|
|
743
|
+
personView = (0, lodash_1.concat)(personView, materialApproval.pre_sra_reviewer);
|
|
744
|
+
if (materialApproval.pre_ca_reviewer)
|
|
745
|
+
personView = (0, lodash_1.concat)(personView, materialApproval.pre_ca_reviewer);
|
|
746
|
+
}
|
|
747
|
+
if (materialApproval.child_files == 'yes') {
|
|
748
|
+
personView = (0, lodash_1.concat)(personView, materialApproval.kids_reviewer);
|
|
749
|
+
}
|
|
750
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(materialApproval._id, {
|
|
751
|
+
$push: {
|
|
752
|
+
person_view: {
|
|
753
|
+
$each: (0, lodash_1.compact)((0, lodash_1.uniq)(personView))
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
approval_type: approvalType
|
|
757
|
+
})];
|
|
758
|
+
case 2:
|
|
759
|
+
_a.sent();
|
|
760
|
+
return [2];
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
}); };
|
|
764
|
+
var PRE_TO_FORMAL_MAPPING = {
|
|
765
|
+
'pre_ns_approval_status': { reviewerField: 'ns_reviewer', type: consts_1.ProcessApprovalType.NS, statusField: 'ns_approval_status' },
|
|
766
|
+
'pre_legal_approval_status': { reviewerField: 'legal_reviewer', type: consts_1.ProcessApprovalType.Legal, statusField: 'legal_approval_status' },
|
|
767
|
+
'pre_sra_approval_status': { reviewerField: 'sra_reviewer', type: consts_1.ProcessApprovalType.SRA, statusField: 'sra_approval_status' },
|
|
768
|
+
'pre_ca_approval_status': { reviewerField: 'ca_reviewer', type: consts_1.ProcessApprovalType.CA, statusField: 'ca_approval_status' },
|
|
769
|
+
'pre_approval_status': { reviewerField: 'reviewer', type: consts_1.ProcessApprovalType.guding, statusField: 'approval_status' },
|
|
770
|
+
};
|
|
771
|
+
var addFormalReviewerAfterPreApproval = function (ctx, recordId, approveField, materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
772
|
+
var info, formalStatus, reviewerIds, userIds, agents, user, _a, _b, userId, spaceUsers, e_6_1, currentApproval, pendingApprove, newPending;
|
|
773
|
+
var e_6, _c, _d, _e, _f;
|
|
774
|
+
return tslib_1.__generator(this, function (_g) {
|
|
775
|
+
switch (_g.label) {
|
|
776
|
+
case 0:
|
|
777
|
+
info = PRE_TO_FORMAL_MAPPING[approveField];
|
|
778
|
+
if (!info)
|
|
779
|
+
return [2];
|
|
780
|
+
formalStatus = materialApproval[info.statusField];
|
|
781
|
+
if (formalStatus === true || formalStatus === consts_1.ApprovalStatus.pass)
|
|
782
|
+
return [2];
|
|
783
|
+
reviewerIds = materialApproval[info.reviewerField];
|
|
784
|
+
if (!reviewerIds || (Array.isArray(reviewerIds) && reviewerIds.length === 0))
|
|
785
|
+
return [2];
|
|
786
|
+
userIds = Array.isArray(reviewerIds) ? reviewerIds : [reviewerIds];
|
|
787
|
+
return [4, (0, agent_1.getReviewerAgentsInfo)(ctx, materialApproval.space, userIds)];
|
|
788
|
+
case 1:
|
|
789
|
+
agents = _g.sent();
|
|
790
|
+
user = ctx.meta.user;
|
|
791
|
+
_g.label = 2;
|
|
792
|
+
case 2:
|
|
793
|
+
_g.trys.push([2, 8, 9, 10]);
|
|
794
|
+
_a = tslib_1.__values(agents.userIds), _b = _a.next();
|
|
795
|
+
_g.label = 3;
|
|
796
|
+
case 3:
|
|
797
|
+
if (!!_b.done) return [3, 7];
|
|
798
|
+
userId = _b.value;
|
|
799
|
+
return [4, ctx.getObject('space_users').directFind({
|
|
800
|
+
filters: [['user', '=', userId], ['space', '=', materialApproval.space]]
|
|
801
|
+
})];
|
|
802
|
+
case 4:
|
|
803
|
+
spaceUsers = _g.sent();
|
|
804
|
+
return [4, ctx.getObject('pepsico_approval_process').insert({
|
|
805
|
+
pepsico_material_approval: materialApproval._id,
|
|
806
|
+
owner: userId,
|
|
807
|
+
type: info.type,
|
|
808
|
+
review_department: spaceUsers.length > 0 ? spaceUsers[0].organization : null,
|
|
809
|
+
current_step: materialApproval.current_step,
|
|
810
|
+
approved: "progess",
|
|
811
|
+
space: materialApproval.space,
|
|
812
|
+
created: new Date(),
|
|
813
|
+
created_by: user.userId,
|
|
814
|
+
modified: new Date(),
|
|
815
|
+
modified_by: user.userId,
|
|
816
|
+
name: ''
|
|
817
|
+
})];
|
|
818
|
+
case 5:
|
|
819
|
+
_g.sent();
|
|
820
|
+
_g.label = 6;
|
|
821
|
+
case 6:
|
|
822
|
+
_b = _a.next();
|
|
823
|
+
return [3, 3];
|
|
824
|
+
case 7: return [3, 10];
|
|
825
|
+
case 8:
|
|
826
|
+
e_6_1 = _g.sent();
|
|
827
|
+
e_6 = { error: e_6_1 };
|
|
828
|
+
return [3, 10];
|
|
829
|
+
case 9:
|
|
830
|
+
try {
|
|
831
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
832
|
+
}
|
|
833
|
+
finally { if (e_6) throw e_6.error; }
|
|
834
|
+
return [7];
|
|
835
|
+
case 10: return [4, ctx.getObject('pepsico_material_approval').directUpdate(materialApproval._id, (_d = {},
|
|
836
|
+
_d["handler_".concat((0, lodash_1.toLower)(info.type))] = agents.userIds,
|
|
837
|
+
_d))];
|
|
838
|
+
case 11:
|
|
839
|
+
_g.sent();
|
|
840
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
841
|
+
case 12:
|
|
842
|
+
currentApproval = _g.sent();
|
|
843
|
+
pendingApprove = currentApproval.person_pending_approve || [];
|
|
844
|
+
newPending = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(pendingApprove, agents.userIds)));
|
|
845
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(materialApproval._id, (_e = {
|
|
846
|
+
person_pending_approve: newPending
|
|
847
|
+
},
|
|
848
|
+
_e[info.statusField] = '',
|
|
849
|
+
_e))];
|
|
850
|
+
case 13:
|
|
851
|
+
_g.sent();
|
|
852
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], [info.statusField, '=', false]], (_f = {}, _f[info.statusField] = '', _f))];
|
|
853
|
+
case 14:
|
|
854
|
+
_g.sent();
|
|
855
|
+
console.log("[addFormalReviewerAfterPreApproval] \u9884\u5BA1\u5B57\u6BB5 ".concat(approveField, " \u901A\u8FC7, \u8FFD\u52A0\u6B63\u5F0F\u5BA1\u6838\u4EBA:"), agents.userIds);
|
|
856
|
+
return [4, (0, notification_1.sendNotifications)(ctx, materialApproval, agents.userIds, '请审批')];
|
|
857
|
+
case 15:
|
|
858
|
+
_g.sent();
|
|
859
|
+
return [2];
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}); };
|
|
863
|
+
var getPreReviewStatuses = function (materialApproval) {
|
|
864
|
+
var statuses = [];
|
|
865
|
+
if (materialApproval.pre_ns_reviewer) {
|
|
866
|
+
statuses.push({ dept: 'NS', status: materialApproval.pre_ns_approval_status, preField: 'pre_ns_approval_status', deptApprovalField: 'ns_approval_status' });
|
|
867
|
+
}
|
|
868
|
+
if (materialApproval.pre_legal_reviewer) {
|
|
869
|
+
statuses.push({ dept: 'Legal', status: materialApproval.pre_legal_approval_status, preField: 'pre_legal_approval_status', deptApprovalField: 'legal_approval_status' });
|
|
870
|
+
}
|
|
871
|
+
if (materialApproval.pre_sra_reviewer) {
|
|
872
|
+
statuses.push({ dept: 'SRA', status: materialApproval.pre_sra_approval_status, preField: 'pre_sra_approval_status', deptApprovalField: 'sra_approval_status' });
|
|
873
|
+
}
|
|
874
|
+
if (materialApproval.pre_ca_reviewer) {
|
|
875
|
+
statuses.push({ dept: 'CA', status: materialApproval.pre_ca_approval_status, preField: 'pre_ca_approval_status', deptApprovalField: 'ca_approval_status' });
|
|
876
|
+
}
|
|
877
|
+
return statuses;
|
|
878
|
+
};
|
|
879
|
+
exports.getPreReviewStatuses = getPreReviewStatuses;
|
|
880
|
+
var hasNonPreReviewDepartments = function (materialApproval) {
|
|
881
|
+
var isPositive = function (status) { return status === true || status === consts_1.ApprovalStatus.approved || status === consts_1.ApprovalStatus.pass; };
|
|
882
|
+
if (!materialApproval.pre_ns_reviewer && !isPositive(materialApproval.ns_approval_status))
|
|
883
|
+
return true;
|
|
884
|
+
if (!materialApproval.pre_legal_reviewer && !isPositive(materialApproval.legal_approval_status))
|
|
885
|
+
return true;
|
|
886
|
+
if (!materialApproval.pre_sra_reviewer && !isPositive(materialApproval.sra_approval_status))
|
|
887
|
+
return true;
|
|
888
|
+
if (!materialApproval.pre_ca_reviewer && !isPositive(materialApproval.ca_approval_status))
|
|
889
|
+
return true;
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
exports.hasNonPreReviewDepartments = hasNonPreReviewDepartments;
|
|
893
|
+
var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
894
|
+
var actionLabel, user, record, nextStep, skipApprover, nextApprovers, _nextApprovers, nextApprovers_2, nextApprovers_2_1, reviewer, fieldName, status, e_7_1, nextApproversUserIds_1, nextApproversClientUserIds_1, setDoc, nextApprovers_3, nextApprovers_3_1, nextApprover, e_8_1, setDoc_1, postponedUserIds_1, now, visibleAfter, pastPostponeRecords, postponedDepts, _loop_1, nextApprovers_4, nextApprovers_4_1, reviewer, e_9_1, currentRecord, currentPostponed, newPostponed, currentMarkerUsers, newMarkerUsers, notifyUserIds, initiator, materialOwner, error_1;
|
|
895
|
+
var e_7, _a, _b, _c, e_8, _d, e_9, _e;
|
|
896
|
+
return tslib_1.__generator(this, function (_f) {
|
|
897
|
+
switch (_f.label) {
|
|
898
|
+
case 0:
|
|
899
|
+
_f.trys.push([0, 95, , 96]);
|
|
900
|
+
actionLabel = '请查看';
|
|
901
|
+
user = ctx.meta.user;
|
|
902
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
903
|
+
case 1:
|
|
904
|
+
record = _f.sent();
|
|
905
|
+
console.log('[advanceApproval]', record.current_step, record.person_pending_approve, user.userId);
|
|
906
|
+
return [4, canSubmit(record)];
|
|
907
|
+
case 2:
|
|
908
|
+
_f.sent();
|
|
909
|
+
return [4, getNextStep(ctx, record, currentStepApprovalStatus)];
|
|
910
|
+
case 3:
|
|
911
|
+
nextStep = _f.sent();
|
|
912
|
+
return [4, isSkipApprover(ctx, record)];
|
|
913
|
+
case 4:
|
|
914
|
+
skipApprover = _f.sent();
|
|
915
|
+
if (!(nextStep === consts_1.Step.conclusion && skipApprover)) return [3, 8];
|
|
916
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(record._id, {
|
|
917
|
+
is_skip_approver: true
|
|
918
|
+
})];
|
|
919
|
+
case 5:
|
|
920
|
+
_f.sent();
|
|
921
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany(['pepsico_material_approval', '=', record._id], {
|
|
922
|
+
is_skip_approver: true
|
|
923
|
+
})];
|
|
924
|
+
case 6:
|
|
925
|
+
_f.sent();
|
|
926
|
+
return [4, setPersonView(ctx, record)];
|
|
927
|
+
case 7:
|
|
928
|
+
_f.sent();
|
|
929
|
+
_f.label = 8;
|
|
930
|
+
case 8: return [4, getNextApprovers(ctx, record, nextStep)];
|
|
931
|
+
case 9:
|
|
932
|
+
nextApprovers = _f.sent();
|
|
933
|
+
if (!(record.current_step === consts_1.Step.submitter_revisions && (nextStep === consts_1.Step.departmental_review || nextStep === consts_1.Step.personnel_review))) return [3, 23];
|
|
934
|
+
_nextApprovers = [];
|
|
935
|
+
_f.label = 10;
|
|
936
|
+
case 10:
|
|
937
|
+
_f.trys.push([10, 18, 19, 20]);
|
|
938
|
+
nextApprovers_2 = tslib_1.__values(nextApprovers), nextApprovers_2_1 = nextApprovers_2.next();
|
|
939
|
+
_f.label = 11;
|
|
940
|
+
case 11:
|
|
941
|
+
if (!!nextApprovers_2_1.done) return [3, 17];
|
|
942
|
+
reviewer = nextApprovers_2_1.value;
|
|
943
|
+
fieldName = (0, material_1.getApproverFieldByType)(reviewer.type);
|
|
944
|
+
console.log("getApproverFieldByType", reviewer.type, fieldName);
|
|
945
|
+
if (!fieldName) {
|
|
946
|
+
return [3, 16];
|
|
947
|
+
}
|
|
948
|
+
return [4, (0, material_1.getUserReviewedAllMaterialsStatus)(ctx, record._id, fieldName)];
|
|
949
|
+
case 12:
|
|
950
|
+
status = _f.sent();
|
|
951
|
+
console.log("getUserReviewedAllMaterialsStatus", record._id, fieldName, status);
|
|
952
|
+
if (!(status === consts_1.ApprovalStatus.approved)) return [3, 14];
|
|
953
|
+
console.log("[advanceApproval] \u81EA\u52A8\u66F4\u65B0\u5BA1\u6279\u5355\u4E0A\u7684\u72B6\u6001\u5B57\u6BB5", recordId, (_b = {},
|
|
954
|
+
_b[fieldName] = consts_1.ApprovalStatus.approved,
|
|
955
|
+
_b));
|
|
956
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, (_c = {},
|
|
957
|
+
_c[fieldName] = true,
|
|
958
|
+
_c))];
|
|
959
|
+
case 13:
|
|
960
|
+
_f.sent();
|
|
961
|
+
return [3, 15];
|
|
962
|
+
case 14:
|
|
963
|
+
if (status === consts_1.ApprovalStatus.pass) {
|
|
964
|
+
console.log("[advanceApproval] \u90E8\u95E8\u5DF2\u8DF3\u8FC7\uFF0C\u4FDD\u6301bypass\u72B6\u6001", recordId, fieldName);
|
|
965
|
+
}
|
|
966
|
+
else {
|
|
967
|
+
_nextApprovers.push(reviewer);
|
|
968
|
+
}
|
|
969
|
+
_f.label = 15;
|
|
970
|
+
case 15:
|
|
971
|
+
;
|
|
972
|
+
_f.label = 16;
|
|
973
|
+
case 16:
|
|
974
|
+
nextApprovers_2_1 = nextApprovers_2.next();
|
|
975
|
+
return [3, 11];
|
|
976
|
+
case 17: return [3, 20];
|
|
977
|
+
case 18:
|
|
978
|
+
e_7_1 = _f.sent();
|
|
979
|
+
e_7 = { error: e_7_1 };
|
|
980
|
+
return [3, 20];
|
|
981
|
+
case 19:
|
|
982
|
+
try {
|
|
983
|
+
if (nextApprovers_2_1 && !nextApprovers_2_1.done && (_a = nextApprovers_2.return)) _a.call(nextApprovers_2);
|
|
984
|
+
}
|
|
985
|
+
finally { if (e_7) throw e_7.error; }
|
|
986
|
+
return [7];
|
|
987
|
+
case 20:
|
|
988
|
+
if (!(_nextApprovers.length > 0)) return [3, 21];
|
|
989
|
+
nextApprovers = _nextApprovers;
|
|
990
|
+
return [3, 23];
|
|
991
|
+
case 21:
|
|
992
|
+
nextStep = consts_1.Step.awaiting_deployment;
|
|
993
|
+
return [4, getNextApprovers(ctx, record, nextStep)];
|
|
994
|
+
case 22:
|
|
995
|
+
nextApprovers = _f.sent();
|
|
996
|
+
_f.label = 23;
|
|
997
|
+
case 23:
|
|
998
|
+
console.log("[advanceApproval] currentStepApprovalStatus:", currentStepApprovalStatus, " nextStep:", nextStep, " nextApprovers:", nextApprovers);
|
|
999
|
+
nextApproversUserIds_1 = [];
|
|
1000
|
+
nextApproversClientUserIds_1 = [];
|
|
1001
|
+
(0, lodash_1.map)(nextApprovers, function (item) {
|
|
1002
|
+
nextApproversUserIds_1 = (0, lodash_1.concat)(nextApproversUserIds_1, item.userIds);
|
|
1003
|
+
nextApproversClientUserIds_1 = (0, lodash_1.concat)(nextApproversClientUserIds_1, item.clientUserIds);
|
|
1004
|
+
});
|
|
1005
|
+
setDoc = {
|
|
1006
|
+
current_step: nextStep,
|
|
1007
|
+
review_status: getReviewStatus(nextStep),
|
|
1008
|
+
person_pending_approve: nextApproversUserIds_1,
|
|
1009
|
+
$push: {
|
|
1010
|
+
person_view: {
|
|
1011
|
+
$each: (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.difference)(nextApproversClientUserIds_1, nextApproversUserIds_1)))
|
|
1012
|
+
},
|
|
1013
|
+
person_approved: {
|
|
1014
|
+
$each: record.person_pending_approve
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
if (!(record.current_step === consts_1.Step.draft)) return [3, 25];
|
|
1019
|
+
setDoc.draft_submitted = new Date();
|
|
1020
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany(['pepsico_material_approval', '=', record._id], {
|
|
1021
|
+
draft_submitted: setDoc.draft_submitted
|
|
1022
|
+
})];
|
|
1023
|
+
case 24:
|
|
1024
|
+
_f.sent();
|
|
1025
|
+
_f.label = 25;
|
|
1026
|
+
case 25:
|
|
1027
|
+
if (record.current_step === consts_1.Step.ai_review) {
|
|
1028
|
+
setDoc.ai_reviewed_date = new Date();
|
|
1029
|
+
}
|
|
1030
|
+
if (record.current_step === consts_1.Step.departmental_review || record.current_step === consts_1.Step.personnel_review) {
|
|
1031
|
+
setDoc.re_reviewed_date = new Date();
|
|
1032
|
+
}
|
|
1033
|
+
if (!(nextStep === consts_1.Step.awaiting_deployment)) return [3, 27];
|
|
1034
|
+
setDoc.review_completed_date = new Date();
|
|
1035
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany(['pepsico_material_approval', '=', record._id], {
|
|
1036
|
+
review_completed_date: setDoc.review_completed_date
|
|
1037
|
+
})];
|
|
1038
|
+
case 26:
|
|
1039
|
+
_f.sent();
|
|
1040
|
+
_f.label = 27;
|
|
1041
|
+
case 27:
|
|
1042
|
+
if (record.current_step === consts_1.Step.awaiting_deployment) {
|
|
1043
|
+
setDoc.awaiting_deployment_date = new Date();
|
|
1044
|
+
}
|
|
1045
|
+
if (!(record.current_step === consts_1.Step.conclusion)) return [3, 29];
|
|
1046
|
+
setDoc.conclusion_date = new Date();
|
|
1047
|
+
if (!!record.review_completed_date) return [3, 29];
|
|
1048
|
+
setDoc.review_completed_date = setDoc.conclusion_date;
|
|
1049
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany(['pepsico_material_approval', '=', record._id], {
|
|
1050
|
+
review_completed_date: setDoc.review_completed_date
|
|
1051
|
+
})];
|
|
1052
|
+
case 28:
|
|
1053
|
+
_f.sent();
|
|
1054
|
+
_f.label = 29;
|
|
1055
|
+
case 29:
|
|
1056
|
+
if (record.current_step === consts_1.Step.submitter_revisions) {
|
|
1057
|
+
setDoc.submitter_revision_date = new Date();
|
|
1058
|
+
console.log("[advanceApproval] \u68C0\u6D4B\u5230\u4FEE\u6539\u540E\u63D0\u4EA4\u573A\u666F, \u6807\u8BB0\u56FE\u7247\u5BF9\u6BD4\u4EFB\u52A1: ".concat(recordId));
|
|
1059
|
+
setDoc.image_comparison_status = 'pending';
|
|
1060
|
+
setDoc.image_comparison_at = new Date();
|
|
1061
|
+
setDoc.image_comparison_failed_count = 0;
|
|
1062
|
+
}
|
|
1063
|
+
return [4, ctx.getObject('pepsico_material_approval').update(recordId, setDoc)];
|
|
1064
|
+
case 30:
|
|
1065
|
+
_f.sent();
|
|
1066
|
+
return [4, changeApprovalProcess(ctx, record, {
|
|
1067
|
+
nextStep: nextStep,
|
|
1068
|
+
nextApprovers: nextApprovers,
|
|
1069
|
+
description: ""
|
|
1070
|
+
})];
|
|
1071
|
+
case 31:
|
|
1072
|
+
_f.sent();
|
|
1073
|
+
if (!(nextStep === consts_1.Step.ai_review)) return [3, 33];
|
|
1074
|
+
console.time('callAIReview: ' + recordId);
|
|
1075
|
+
return [4, (0, AI_1.callAIReview)(ctx, recordId)];
|
|
1076
|
+
case 32:
|
|
1077
|
+
_f.sent();
|
|
1078
|
+
console.timeEnd('callAIReview: ' + recordId);
|
|
1079
|
+
_f.label = 33;
|
|
1080
|
+
case 33:
|
|
1081
|
+
_f.trys.push([33, 69, 70, 71]);
|
|
1082
|
+
nextApprovers_3 = tslib_1.__values(nextApprovers), nextApprovers_3_1 = nextApprovers_3.next();
|
|
1083
|
+
_f.label = 34;
|
|
1084
|
+
case 34:
|
|
1085
|
+
if (!!nextApprovers_3_1.done) return [3, 68];
|
|
1086
|
+
nextApprover = nextApprovers_3_1.value;
|
|
1087
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.CA)) return [3, 37];
|
|
1088
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1089
|
+
ca_approval_status: ''
|
|
1090
|
+
})];
|
|
1091
|
+
case 35:
|
|
1092
|
+
_f.sent();
|
|
1093
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['ca_approval_status', '=', false]], {
|
|
1094
|
+
ca_approval_status: ''
|
|
1095
|
+
})];
|
|
1096
|
+
case 36:
|
|
1097
|
+
_f.sent();
|
|
1098
|
+
_f.label = 37;
|
|
1099
|
+
case 37:
|
|
1100
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.Legal)) return [3, 40];
|
|
1101
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1102
|
+
legal_approval_status: ''
|
|
1103
|
+
})];
|
|
1104
|
+
case 38:
|
|
1105
|
+
_f.sent();
|
|
1106
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['legal_approval_status', '=', false]], {
|
|
1107
|
+
legal_approval_status: ''
|
|
1108
|
+
})];
|
|
1109
|
+
case 39:
|
|
1110
|
+
_f.sent();
|
|
1111
|
+
_f.label = 40;
|
|
1112
|
+
case 40:
|
|
1113
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.NS)) return [3, 43];
|
|
1114
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1115
|
+
ns_approval_status: ''
|
|
1116
|
+
})];
|
|
1117
|
+
case 41:
|
|
1118
|
+
_f.sent();
|
|
1119
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['ns_approval_status', '=', false]], {
|
|
1120
|
+
ns_approval_status: ''
|
|
1121
|
+
})];
|
|
1122
|
+
case 42:
|
|
1123
|
+
_f.sent();
|
|
1124
|
+
_f.label = 43;
|
|
1125
|
+
case 43:
|
|
1126
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.SRA)) return [3, 46];
|
|
1127
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1128
|
+
sra_approval_status: ''
|
|
1129
|
+
})];
|
|
1130
|
+
case 44:
|
|
1131
|
+
_f.sent();
|
|
1132
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['sra_approval_status', '=', false]], {
|
|
1133
|
+
sra_approval_status: ''
|
|
1134
|
+
})];
|
|
1135
|
+
case 45:
|
|
1136
|
+
_f.sent();
|
|
1137
|
+
_f.label = 46;
|
|
1138
|
+
case 46:
|
|
1139
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.guding)) return [3, 49];
|
|
1140
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1141
|
+
approval_status: ''
|
|
1142
|
+
})];
|
|
1143
|
+
case 47:
|
|
1144
|
+
_f.sent();
|
|
1145
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['approval_status', '=', false]], {
|
|
1146
|
+
approval_status: ''
|
|
1147
|
+
})];
|
|
1148
|
+
case 48:
|
|
1149
|
+
_f.sent();
|
|
1150
|
+
_f.label = 49;
|
|
1151
|
+
case 49:
|
|
1152
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.Kids)) return [3, 52];
|
|
1153
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1154
|
+
kids_approval_status: ''
|
|
1155
|
+
})];
|
|
1156
|
+
case 50:
|
|
1157
|
+
_f.sent();
|
|
1158
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['kids_approval_status', '=', false]], {
|
|
1159
|
+
kids_approval_status: ''
|
|
1160
|
+
})];
|
|
1161
|
+
case 51:
|
|
1162
|
+
_f.sent();
|
|
1163
|
+
_f.label = 52;
|
|
1164
|
+
case 52:
|
|
1165
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.PreNS)) return [3, 55];
|
|
1166
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1167
|
+
pre_ns_approval_status: ''
|
|
1168
|
+
})];
|
|
1169
|
+
case 53:
|
|
1170
|
+
_f.sent();
|
|
1171
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['pre_ns_approval_status', '=', false]], {
|
|
1172
|
+
pre_ns_approval_status: ''
|
|
1173
|
+
})];
|
|
1174
|
+
case 54:
|
|
1175
|
+
_f.sent();
|
|
1176
|
+
_f.label = 55;
|
|
1177
|
+
case 55:
|
|
1178
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.PreLegal)) return [3, 58];
|
|
1179
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1180
|
+
pre_legal_approval_status: ''
|
|
1181
|
+
})];
|
|
1182
|
+
case 56:
|
|
1183
|
+
_f.sent();
|
|
1184
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['pre_legal_approval_status', '=', false]], {
|
|
1185
|
+
pre_legal_approval_status: ''
|
|
1186
|
+
})];
|
|
1187
|
+
case 57:
|
|
1188
|
+
_f.sent();
|
|
1189
|
+
_f.label = 58;
|
|
1190
|
+
case 58:
|
|
1191
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.PreSRA)) return [3, 61];
|
|
1192
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1193
|
+
pre_sra_approval_status: ''
|
|
1194
|
+
})];
|
|
1195
|
+
case 59:
|
|
1196
|
+
_f.sent();
|
|
1197
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['pre_sra_approval_status', '=', false]], {
|
|
1198
|
+
pre_sra_approval_status: ''
|
|
1199
|
+
})];
|
|
1200
|
+
case 60:
|
|
1201
|
+
_f.sent();
|
|
1202
|
+
_f.label = 61;
|
|
1203
|
+
case 61:
|
|
1204
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.PreCA)) return [3, 64];
|
|
1205
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1206
|
+
pre_ca_approval_status: ''
|
|
1207
|
+
})];
|
|
1208
|
+
case 62:
|
|
1209
|
+
_f.sent();
|
|
1210
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['pre_ca_approval_status', '=', false]], {
|
|
1211
|
+
pre_ca_approval_status: ''
|
|
1212
|
+
})];
|
|
1213
|
+
case 63:
|
|
1214
|
+
_f.sent();
|
|
1215
|
+
_f.label = 64;
|
|
1216
|
+
case 64:
|
|
1217
|
+
if (!(nextApprover.type === consts_1.ProcessApprovalType.Preguding)) return [3, 67];
|
|
1218
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1219
|
+
pre_approval_status: ''
|
|
1220
|
+
})];
|
|
1221
|
+
case 65:
|
|
1222
|
+
_f.sent();
|
|
1223
|
+
return [4, ctx.getObject('pepsico_material').directUpdateMany([['pepsico_material_approval', '=', recordId], ['pre_approval_status', '=', false]], {
|
|
1224
|
+
pre_approval_status: ''
|
|
1225
|
+
})];
|
|
1226
|
+
case 66:
|
|
1227
|
+
_f.sent();
|
|
1228
|
+
_f.label = 67;
|
|
1229
|
+
case 67:
|
|
1230
|
+
nextApprovers_3_1 = nextApprovers_3.next();
|
|
1231
|
+
return [3, 34];
|
|
1232
|
+
case 68: return [3, 71];
|
|
1233
|
+
case 69:
|
|
1234
|
+
e_8_1 = _f.sent();
|
|
1235
|
+
e_8 = { error: e_8_1 };
|
|
1236
|
+
return [3, 71];
|
|
1237
|
+
case 70:
|
|
1238
|
+
try {
|
|
1239
|
+
if (nextApprovers_3_1 && !nextApprovers_3_1.done && (_d = nextApprovers_3.return)) _d.call(nextApprovers_3);
|
|
1240
|
+
}
|
|
1241
|
+
finally { if (e_8) throw e_8.error; }
|
|
1242
|
+
return [7];
|
|
1243
|
+
case 71:
|
|
1244
|
+
if (!(nextStep === consts_1.Step.departmental_review || nextStep === consts_1.Step.personnel_review)) return [3, 73];
|
|
1245
|
+
return [4, setPersonView(ctx, record)];
|
|
1246
|
+
case 72:
|
|
1247
|
+
_f.sent();
|
|
1248
|
+
_f.label = 73;
|
|
1249
|
+
case 73:
|
|
1250
|
+
if (!(record.current_step === consts_1.Step.departmental_review || record.current_step === consts_1.Step.personnel_review)) return [3, 75];
|
|
1251
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1252
|
+
materials_remove_share_link_from_onedrive_status: 'pending'
|
|
1253
|
+
})];
|
|
1254
|
+
case 74:
|
|
1255
|
+
_f.sent();
|
|
1256
|
+
_f.label = 75;
|
|
1257
|
+
case 75:
|
|
1258
|
+
if (!(nextStep === consts_1.Step.awaiting_deployment)) return [3, 77];
|
|
1259
|
+
return [4, pendingDeployment(ctx, recordId)];
|
|
1260
|
+
case 76:
|
|
1261
|
+
_f.sent();
|
|
1262
|
+
_f.label = 77;
|
|
1263
|
+
case 77:
|
|
1264
|
+
if (!(nextStep === consts_1.Step.awaiting_deployment || (nextStep === consts_1.Step.conclusion && record.current_step === consts_1.Step.ai_review))) return [3, 79];
|
|
1265
|
+
setDoc_1 = {
|
|
1266
|
+
materials_download_from_onedrive_status: 'pending'
|
|
1267
|
+
};
|
|
1268
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, setDoc_1)];
|
|
1269
|
+
case 78:
|
|
1270
|
+
_f.sent();
|
|
1271
|
+
_f.label = 79;
|
|
1272
|
+
case 79:
|
|
1273
|
+
if (currentStepApprovalStatus === consts_1.ApprovalStatus.rejected) {
|
|
1274
|
+
actionLabel = '内容审批被驳回';
|
|
1275
|
+
}
|
|
1276
|
+
if (currentStepApprovalStatus === consts_1.ApprovalStatus.approved
|
|
1277
|
+
&& (nextStep === consts_1.Step.departmental_review || nextStep === consts_1.Step.personnel_review)) {
|
|
1278
|
+
actionLabel = '请审批';
|
|
1279
|
+
}
|
|
1280
|
+
if (nextStep === consts_1.Step.awaiting_deployment) {
|
|
1281
|
+
actionLabel = "\u5185\u5BB9\u5BA1\u6279\u5DF2\u901A\u8FC7\u5F85\u4E0A\u7EBF";
|
|
1282
|
+
}
|
|
1283
|
+
postponedUserIds_1 = [];
|
|
1284
|
+
if (!(nextStep === consts_1.Step.departmental_review || nextStep === consts_1.Step.personnel_review)) return [3, 91];
|
|
1285
|
+
now = new Date();
|
|
1286
|
+
visibleAfter = new Date(now.getTime() + 3 * 24 * 60 * 60 * 1000);
|
|
1287
|
+
return [4, ctx.getObject('pepsico_review_postpone').directFind({
|
|
1288
|
+
filters: [
|
|
1289
|
+
['pepsico_material_approval', '=', recordId],
|
|
1290
|
+
['is_marker', '=', true]
|
|
1291
|
+
]
|
|
1292
|
+
})];
|
|
1293
|
+
case 80:
|
|
1294
|
+
pastPostponeRecords = _f.sent();
|
|
1295
|
+
if (!(pastPostponeRecords && pastPostponeRecords.length > 0)) return [3, 91];
|
|
1296
|
+
postponedDepts = new Set(pastPostponeRecords.map(function (r) { return r.department_type; }));
|
|
1297
|
+
_loop_1 = function (reviewer) {
|
|
1298
|
+
var deptUserIds, deptMarkers, deptMarkers_1, deptMarkers_1_1, marker, e_10_1;
|
|
1299
|
+
var e_10, _g;
|
|
1300
|
+
return tslib_1.__generator(this, function (_h) {
|
|
1301
|
+
switch (_h.label) {
|
|
1302
|
+
case 0:
|
|
1303
|
+
if (!postponedDepts.has(reviewer.type))
|
|
1304
|
+
return [2, "continue"];
|
|
1305
|
+
deptUserIds = reviewer.userIds || [];
|
|
1306
|
+
deptMarkers = pastPostponeRecords.filter(function (r) { return r.department_type === reviewer.type; });
|
|
1307
|
+
_h.label = 1;
|
|
1308
|
+
case 1:
|
|
1309
|
+
_h.trys.push([1, 6, 7, 8]);
|
|
1310
|
+
deptMarkers_1 = (e_10 = void 0, tslib_1.__values(deptMarkers)), deptMarkers_1_1 = deptMarkers_1.next();
|
|
1311
|
+
_h.label = 2;
|
|
1312
|
+
case 2:
|
|
1313
|
+
if (!!deptMarkers_1_1.done) return [3, 5];
|
|
1314
|
+
marker = deptMarkers_1_1.value;
|
|
1315
|
+
return [4, ctx.getObject('pepsico_review_postpone').directUpdate(marker._id, {
|
|
1316
|
+
is_marker: false,
|
|
1317
|
+
visible_after: visibleAfter,
|
|
1318
|
+
notification_sent: false,
|
|
1319
|
+
postponed_user_ids: deptUserIds.join(','),
|
|
1320
|
+
modified: now,
|
|
1321
|
+
modified_by: user.userId
|
|
1322
|
+
})];
|
|
1323
|
+
case 3:
|
|
1324
|
+
_h.sent();
|
|
1325
|
+
_h.label = 4;
|
|
1326
|
+
case 4:
|
|
1327
|
+
deptMarkers_1_1 = deptMarkers_1.next();
|
|
1328
|
+
return [3, 2];
|
|
1329
|
+
case 5: return [3, 8];
|
|
1330
|
+
case 6:
|
|
1331
|
+
e_10_1 = _h.sent();
|
|
1332
|
+
e_10 = { error: e_10_1 };
|
|
1333
|
+
return [3, 8];
|
|
1334
|
+
case 7:
|
|
1335
|
+
try {
|
|
1336
|
+
if (deptMarkers_1_1 && !deptMarkers_1_1.done && (_g = deptMarkers_1.return)) _g.call(deptMarkers_1);
|
|
1337
|
+
}
|
|
1338
|
+
finally { if (e_10) throw e_10.error; }
|
|
1339
|
+
return [7];
|
|
1340
|
+
case 8:
|
|
1341
|
+
postponedUserIds_1 = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(postponedUserIds_1, deptUserIds)));
|
|
1342
|
+
return [2];
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
};
|
|
1346
|
+
_f.label = 81;
|
|
1347
|
+
case 81:
|
|
1348
|
+
_f.trys.push([81, 86, 87, 88]);
|
|
1349
|
+
nextApprovers_4 = tslib_1.__values(nextApprovers), nextApprovers_4_1 = nextApprovers_4.next();
|
|
1350
|
+
_f.label = 82;
|
|
1351
|
+
case 82:
|
|
1352
|
+
if (!!nextApprovers_4_1.done) return [3, 85];
|
|
1353
|
+
reviewer = nextApprovers_4_1.value;
|
|
1354
|
+
return [5, _loop_1(reviewer)];
|
|
1355
|
+
case 83:
|
|
1356
|
+
_f.sent();
|
|
1357
|
+
_f.label = 84;
|
|
1358
|
+
case 84:
|
|
1359
|
+
nextApprovers_4_1 = nextApprovers_4.next();
|
|
1360
|
+
return [3, 82];
|
|
1361
|
+
case 85: return [3, 88];
|
|
1362
|
+
case 86:
|
|
1363
|
+
e_9_1 = _f.sent();
|
|
1364
|
+
e_9 = { error: e_9_1 };
|
|
1365
|
+
return [3, 88];
|
|
1366
|
+
case 87:
|
|
1367
|
+
try {
|
|
1368
|
+
if (nextApprovers_4_1 && !nextApprovers_4_1.done && (_e = nextApprovers_4.return)) _e.call(nextApprovers_4);
|
|
1369
|
+
}
|
|
1370
|
+
finally { if (e_9) throw e_9.error; }
|
|
1371
|
+
return [7];
|
|
1372
|
+
case 88:
|
|
1373
|
+
if (!(postponedUserIds_1.length > 0)) return [3, 91];
|
|
1374
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1375
|
+
case 89:
|
|
1376
|
+
currentRecord = _f.sent();
|
|
1377
|
+
currentPostponed = currentRecord.review_postponed_users || [];
|
|
1378
|
+
newPostponed = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(currentPostponed, postponedUserIds_1)));
|
|
1379
|
+
currentMarkerUsers = currentRecord.postpone_marker_users || [];
|
|
1380
|
+
newMarkerUsers = currentMarkerUsers.filter(function (uid) { return !postponedUserIds_1.includes(uid); });
|
|
1381
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1382
|
+
review_postponed_users: newPostponed,
|
|
1383
|
+
postpone_marker_users: newMarkerUsers
|
|
1384
|
+
})];
|
|
1385
|
+
case 90:
|
|
1386
|
+
_f.sent();
|
|
1387
|
+
console.log("[advanceApproval] \u81EA\u52A8\u5EF6\u540E\u5BA1\u6838\u4EBA: ".concat(postponedUserIds_1, ", visibleAfter: ").concat(visibleAfter));
|
|
1388
|
+
_f.label = 91;
|
|
1389
|
+
case 91:
|
|
1390
|
+
notifyUserIds = postponedUserIds_1.length > 0
|
|
1391
|
+
? nextApproversUserIds_1.filter(function (id) { return !postponedUserIds_1.includes(id); })
|
|
1392
|
+
: nextApproversUserIds_1;
|
|
1393
|
+
return [4, (0, notification_1.sendNotifications)(ctx, record, notifyUserIds, actionLabel)];
|
|
1394
|
+
case 92:
|
|
1395
|
+
_f.sent();
|
|
1396
|
+
if (!(nextStep === consts_1.Step.awaiting_deployment)) return [3, 94];
|
|
1397
|
+
initiator = record.owner;
|
|
1398
|
+
materialOwner = record.material_owner_id;
|
|
1399
|
+
if (!(initiator && materialOwner && initiator !== materialOwner)) return [3, 94];
|
|
1400
|
+
console.log("[advanceApproval] \u901A\u77E5\u53D1\u8D77\u4EBA\u5BA1\u6838\u5B8C\u6210: initiator=".concat(initiator, ", material_owner=").concat(materialOwner));
|
|
1401
|
+
return [4, (0, notification_1.sendNotifications)(ctx, record, [initiator], '审核完成')];
|
|
1402
|
+
case 93:
|
|
1403
|
+
_f.sent();
|
|
1404
|
+
_f.label = 94;
|
|
1405
|
+
case 94: return [2, {}];
|
|
1406
|
+
case 95:
|
|
1407
|
+
error_1 = _f.sent();
|
|
1408
|
+
console.error('[advanceApproval] Error:', error_1.message, error_1.stack);
|
|
1409
|
+
throw error_1;
|
|
1410
|
+
case 96: return [2];
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
}); };
|
|
1414
|
+
exports.advanceApproval = advanceApproval;
|
|
1415
|
+
var terminate = function (ctx, recordId, description) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
1416
|
+
var user, record, records, records_1, records_1_1, process_2, e_11_1;
|
|
1417
|
+
var e_11, _a;
|
|
1418
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1419
|
+
switch (_b.label) {
|
|
1420
|
+
case 0:
|
|
1421
|
+
user = ctx.meta.user;
|
|
1422
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1423
|
+
case 1:
|
|
1424
|
+
record = _b.sent();
|
|
1425
|
+
if (!(record.owner === user.userId || user.is_space_admin || (0, lodash_1.includes)(record.person_pending_approve, user.userId))) return [3, 13];
|
|
1426
|
+
return [4, ctx.getObject('pepsico_approval_process').insert({
|
|
1427
|
+
pepsico_material_approval: record._id,
|
|
1428
|
+
current_step: consts_1.Step.conclusion,
|
|
1429
|
+
owner: user.userId,
|
|
1430
|
+
space: record.space,
|
|
1431
|
+
created: new Date(),
|
|
1432
|
+
created_by: user.userId,
|
|
1433
|
+
modified: new Date(),
|
|
1434
|
+
modified_by: user.userId,
|
|
1435
|
+
approvalStatus: 'terminate',
|
|
1436
|
+
name: description
|
|
1437
|
+
})];
|
|
1438
|
+
case 2:
|
|
1439
|
+
_b.sent();
|
|
1440
|
+
return [4, ctx.getObject('pepsico_approval_process').directFind({
|
|
1441
|
+
filters: [['pepsico_material_approval', '=', record._id], ['approved', '=', 'progess']]
|
|
1442
|
+
})];
|
|
1443
|
+
case 3:
|
|
1444
|
+
records = _b.sent();
|
|
1445
|
+
_b.label = 4;
|
|
1446
|
+
case 4:
|
|
1447
|
+
_b.trys.push([4, 9, 10, 11]);
|
|
1448
|
+
records_1 = tslib_1.__values(records), records_1_1 = records_1.next();
|
|
1449
|
+
_b.label = 5;
|
|
1450
|
+
case 5:
|
|
1451
|
+
if (!!records_1_1.done) return [3, 8];
|
|
1452
|
+
process_2 = records_1_1.value;
|
|
1453
|
+
return [4, ctx.getObject('pepsico_approval_process').directUpdate(process_2._id, {
|
|
1454
|
+
approved: '',
|
|
1455
|
+
modified: new Date(),
|
|
1456
|
+
modified_by: user.userId,
|
|
1457
|
+
})];
|
|
1458
|
+
case 6:
|
|
1459
|
+
_b.sent();
|
|
1460
|
+
_b.label = 7;
|
|
1461
|
+
case 7:
|
|
1462
|
+
records_1_1 = records_1.next();
|
|
1463
|
+
return [3, 5];
|
|
1464
|
+
case 8: return [3, 11];
|
|
1465
|
+
case 9:
|
|
1466
|
+
e_11_1 = _b.sent();
|
|
1467
|
+
e_11 = { error: e_11_1 };
|
|
1468
|
+
return [3, 11];
|
|
1469
|
+
case 10:
|
|
1470
|
+
try {
|
|
1471
|
+
if (records_1_1 && !records_1_1.done && (_a = records_1.return)) _a.call(records_1);
|
|
1472
|
+
}
|
|
1473
|
+
finally { if (e_11) throw e_11.error; }
|
|
1474
|
+
return [7];
|
|
1475
|
+
case 11: return [4, ctx.getObject('pepsico_material_approval').update(recordId, {
|
|
1476
|
+
current_step: consts_1.Step.conclusion,
|
|
1477
|
+
review_status: consts_1.ReviewStatus.terminated,
|
|
1478
|
+
termination_date: new Date(),
|
|
1479
|
+
person_pending_approve: [],
|
|
1480
|
+
termination_type: record.owner === user.userId ? '发起人中止' : '审批人中止'
|
|
1481
|
+
})];
|
|
1482
|
+
case 12:
|
|
1483
|
+
_b.sent();
|
|
1484
|
+
return [2, {}];
|
|
1485
|
+
case 13: throw new Error('Sorry, you don’t have permission to terminate the review.');
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
}); };
|
|
1489
|
+
exports.terminate = terminate;
|
|
1490
|
+
var pendingDeployment = function (ctx, recordId) {
|
|
1491
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1492
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1493
|
+
switch (_a.label) {
|
|
1494
|
+
case 0: return [4, ctx.getObject('pepsico_material_approval').update(recordId, {
|
|
1495
|
+
launch: 'pending'
|
|
1496
|
+
})];
|
|
1497
|
+
case 1:
|
|
1498
|
+
_a.sent();
|
|
1499
|
+
return [2];
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
};
|
|
1504
|
+
var confirmDeployment = function (ctx, recordId, data) {
|
|
1505
|
+
if (data === void 0) { data = {
|
|
1506
|
+
content_rule: null
|
|
1507
|
+
}; }
|
|
1508
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1509
|
+
var user, record;
|
|
1510
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1511
|
+
switch (_a.label) {
|
|
1512
|
+
case 0:
|
|
1513
|
+
user = ctx.meta.user;
|
|
1514
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1515
|
+
case 1:
|
|
1516
|
+
record = _a.sent();
|
|
1517
|
+
if (user.userId !== record.material_owner_id) {
|
|
1518
|
+
throw new Error('只有材料拥有者才能执行此操作.');
|
|
1519
|
+
}
|
|
1520
|
+
if (record.current_step !== consts_1.Step.awaiting_deployment) {
|
|
1521
|
+
return [2, {}];
|
|
1522
|
+
}
|
|
1523
|
+
if (!!(0, lodash_1.includes)(record.person_pending_approve, user.userId)) return [3, 3];
|
|
1524
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, { person_pending_approve: [user.userId] })];
|
|
1525
|
+
case 2:
|
|
1526
|
+
_a.sent();
|
|
1527
|
+
record.person_pending_approve = [user.userId];
|
|
1528
|
+
_a.label = 3;
|
|
1529
|
+
case 3: return [4, updateUserStepStatus(ctx, record, { approvalStatus: consts_1.ApprovalStatus.submit, approveField: '' })];
|
|
1530
|
+
case 4:
|
|
1531
|
+
_a.sent();
|
|
1532
|
+
return [4, ctx.getObject('pepsico_material_approval').update(recordId, {
|
|
1533
|
+
launch: 'launched',
|
|
1534
|
+
content_rule: data.content_rule,
|
|
1535
|
+
aunch_time: new Date()
|
|
1536
|
+
})];
|
|
1537
|
+
case 5:
|
|
1538
|
+
_a.sent();
|
|
1539
|
+
return [4, (0, exports.advanceApproval)(ctx, recordId, consts_1.ApprovalStatus.submit)];
|
|
1540
|
+
case 6:
|
|
1541
|
+
_a.sent();
|
|
1542
|
+
return [4, (0, content_hub_1.inventoryApprovalMaterial)(ctx, recordId)];
|
|
1543
|
+
case 7:
|
|
1544
|
+
_a.sent();
|
|
1545
|
+
return [2, {}];
|
|
1546
|
+
}
|
|
1547
|
+
});
|
|
1548
|
+
});
|
|
1549
|
+
};
|
|
1550
|
+
exports.confirmDeployment = confirmDeployment;
|
|
1551
|
+
var postponeDeployment = function (ctx, recordId, data) {
|
|
1552
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1553
|
+
var user, record;
|
|
1554
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1555
|
+
switch (_a.label) {
|
|
1556
|
+
case 0:
|
|
1557
|
+
user = ctx.meta.user;
|
|
1558
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1559
|
+
case 1:
|
|
1560
|
+
record = _a.sent();
|
|
1561
|
+
if (user.userId !== record.material_owner_id) {
|
|
1562
|
+
throw new Error('只有材料拥有者才能执行此操作.');
|
|
1563
|
+
}
|
|
1564
|
+
if (!(record.current_step === consts_1.Step.awaiting_deployment)) return [3, 5];
|
|
1565
|
+
if (!!(0, lodash_1.includes)(record.person_pending_approve, user.userId)) return [3, 3];
|
|
1566
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, { person_pending_approve: [user.userId] })];
|
|
1567
|
+
case 2:
|
|
1568
|
+
_a.sent();
|
|
1569
|
+
_a.label = 3;
|
|
1570
|
+
case 3: return [4, ctx.getObject('pepsico_material_approval').update(recordId, {
|
|
1571
|
+
launch: 'postpone',
|
|
1572
|
+
postpone_launch_date: data.postpone_launch_date
|
|
1573
|
+
})];
|
|
1574
|
+
case 4:
|
|
1575
|
+
_a.sent();
|
|
1576
|
+
_a.label = 5;
|
|
1577
|
+
case 5: return [2, {}];
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1582
|
+
exports.postponeDeployment = postponeDeployment;
|
|
1583
|
+
var approvalContent = function (ctx, recordId, _a) {
|
|
1584
|
+
var approveField = _a.approveField, _b = _a.materialStatus, materialStatus = _b === void 0 ? consts_1.ApprovalStatus.approved : _b;
|
|
1585
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1586
|
+
var user, approvalOld, fieldStatus, approvalNew, currentStepApprovalStatus, isPositive, isPass, effectiveStatuses, allPositive, allPass, effectiveStatus;
|
|
1587
|
+
return tslib_1.__generator(this, function (_c) {
|
|
1588
|
+
switch (_c.label) {
|
|
1589
|
+
case 0:
|
|
1590
|
+
user = ctx.meta.user;
|
|
1591
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1592
|
+
case 1:
|
|
1593
|
+
approvalOld = _c.sent();
|
|
1594
|
+
if (approvalOld.current_step != consts_1.Step.draft && !(0, lodash_1.includes)(approvalOld.person_pending_approve, user.userId)) {
|
|
1595
|
+
return [2, {}];
|
|
1596
|
+
}
|
|
1597
|
+
fieldStatus = materialStatus === consts_1.ApprovalStatus.pass ? consts_1.ApprovalStatus.pass : true;
|
|
1598
|
+
return [4, updateApproveFieldStatus(ctx, recordId, approveField, fieldStatus)];
|
|
1599
|
+
case 2:
|
|
1600
|
+
_c.sent();
|
|
1601
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1602
|
+
case 3:
|
|
1603
|
+
approvalNew = _c.sent();
|
|
1604
|
+
currentStepApprovalStatus = fieldStatus === true ? consts_1.ApprovalStatus.approved : fieldStatus;
|
|
1605
|
+
return [4, updateUserStepStatus(ctx, approvalNew, { approvalStatus: currentStepApprovalStatus, approveField: approveField })];
|
|
1606
|
+
case 4:
|
|
1607
|
+
_c.sent();
|
|
1608
|
+
if (!(PRE_TO_FORMAL_MAPPING[approveField] && (fieldStatus === true || fieldStatus === consts_1.ApprovalStatus.pass))) return [3, 6];
|
|
1609
|
+
return [4, addFormalReviewerAfterPreApproval(ctx, recordId, approveField, approvalNew)];
|
|
1610
|
+
case 5:
|
|
1611
|
+
_c.sent();
|
|
1612
|
+
_c.label = 6;
|
|
1613
|
+
case 6:
|
|
1614
|
+
isPositive = function (status) { return status === true || status === consts_1.ApprovalStatus.approved || status === consts_1.ApprovalStatus.pass; };
|
|
1615
|
+
isPass = function (status) { return status === consts_1.ApprovalStatus.pass; };
|
|
1616
|
+
if (approvalNew.current_step === consts_1.Step.departmental_review) {
|
|
1617
|
+
if (!(0, exports.isDeptReviewComplete)(approvalNew, 'ns') || !(0, exports.isDeptReviewComplete)(approvalNew, 'legal') ||
|
|
1618
|
+
!(0, exports.isDeptReviewComplete)(approvalNew, 'sra') || !(0, exports.isDeptReviewComplete)(approvalNew, 'ca')) {
|
|
1619
|
+
console.log('[approvalContent]: 有部门审核周期未完成, 只结束当前用户审批任务,不推进审批进度.');
|
|
1620
|
+
return [2, {}];
|
|
1621
|
+
}
|
|
1622
|
+
effectiveStatuses = [
|
|
1623
|
+
(0, exports.getDeptEffectiveStatus)(approvalNew, 'ns'),
|
|
1624
|
+
(0, exports.getDeptEffectiveStatus)(approvalNew, 'legal'),
|
|
1625
|
+
(0, exports.getDeptEffectiveStatus)(approvalNew, 'sra'),
|
|
1626
|
+
(0, exports.getDeptEffectiveStatus)(approvalNew, 'ca')
|
|
1627
|
+
];
|
|
1628
|
+
allPositive = effectiveStatuses.every(isPositive);
|
|
1629
|
+
if (allPositive) {
|
|
1630
|
+
allPass = effectiveStatuses.every(isPass);
|
|
1631
|
+
currentStepApprovalStatus = allPass ? consts_1.ApprovalStatus.pass : consts_1.ApprovalStatus.approved;
|
|
1632
|
+
}
|
|
1633
|
+
else {
|
|
1634
|
+
currentStepApprovalStatus = consts_1.ApprovalStatus.rejected;
|
|
1635
|
+
}
|
|
1636
|
+
console.log('[approvalContent]: 部门复审完成, 结果为:', currentStepApprovalStatus);
|
|
1637
|
+
}
|
|
1638
|
+
else if (approvalNew.current_step === consts_1.Step.personnel_review) {
|
|
1639
|
+
if (!(0, exports.isDeptReviewComplete)(approvalNew, 'approval')) {
|
|
1640
|
+
console.log('[approvalContent]: 固定人员审核周期未完成, 只结束当前用户审批任务,不推进审批进度.');
|
|
1641
|
+
return [2, {}];
|
|
1642
|
+
}
|
|
1643
|
+
effectiveStatus = (0, exports.getDeptEffectiveStatus)(approvalNew, 'approval');
|
|
1644
|
+
if (isPositive(effectiveStatus)) {
|
|
1645
|
+
currentStepApprovalStatus = isPass(effectiveStatus) ? consts_1.ApprovalStatus.pass : consts_1.ApprovalStatus.approved;
|
|
1646
|
+
}
|
|
1647
|
+
else {
|
|
1648
|
+
currentStepApprovalStatus = consts_1.ApprovalStatus.rejected;
|
|
1649
|
+
}
|
|
1650
|
+
console.log('[approvalContent]: 固定人员复审完成, 结果为:', currentStepApprovalStatus);
|
|
1651
|
+
}
|
|
1652
|
+
if (approvalNew.child_files == 'yes') {
|
|
1653
|
+
if (!(0, exports.hasReviewed)(approvalNew.kids_approval_status)) {
|
|
1654
|
+
console.log('[approvalContent]: kids审核人未审批, 只结束当前用户审批任务,不推进审批进度.');
|
|
1655
|
+
return [2, {}];
|
|
1656
|
+
}
|
|
1657
|
+
if (approvalNew.kids_approval_status == false) {
|
|
1658
|
+
currentStepApprovalStatus = consts_1.ApprovalStatus.rejected;
|
|
1659
|
+
}
|
|
1660
|
+
console.log('[approvalContent]: kids审核完成, 结果为:', currentStepApprovalStatus);
|
|
1661
|
+
}
|
|
1662
|
+
console.log("[approvalContent] \u63A8\u8FDB\u5BA1\u6279\u8FDB\u5EA6,\u53C2\u6570\u4E3A \u5BA1\u6279\u5355: ".concat(recordId, " \u5F53\u524D\u6B65\u9AA4: ").concat(approvalNew.current_step, " \u5BA1\u6279\u7ED3\u679C\u4E3A: ").concat(currentStepApprovalStatus));
|
|
1663
|
+
return [4, (0, exports.advanceApproval)(ctx, recordId, currentStepApprovalStatus)];
|
|
1664
|
+
case 7:
|
|
1665
|
+
_c.sent();
|
|
1666
|
+
return [2, {}];
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
});
|
|
1670
|
+
};
|
|
1671
|
+
exports.approvalContent = approvalContent;
|
|
1672
|
+
var rejectContent = function (ctx, recordId, _a) {
|
|
1673
|
+
var approveField = _a.approveField;
|
|
1674
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1675
|
+
var user, approvalOld, approvalNew, currentStepApprovalStatus, isPositive;
|
|
1676
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1677
|
+
switch (_b.label) {
|
|
1678
|
+
case 0:
|
|
1679
|
+
user = ctx.meta.user;
|
|
1680
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1681
|
+
case 1:
|
|
1682
|
+
approvalOld = _b.sent();
|
|
1683
|
+
if (approvalOld.current_step != consts_1.Step.draft && !(0, lodash_1.includes)(approvalOld.person_pending_approve, user.userId)) {
|
|
1684
|
+
return [2, {}];
|
|
1685
|
+
}
|
|
1686
|
+
return [4, updateApproveFieldStatus(ctx, recordId, approveField, false)];
|
|
1687
|
+
case 2:
|
|
1688
|
+
_b.sent();
|
|
1689
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1690
|
+
case 3:
|
|
1691
|
+
approvalNew = _b.sent();
|
|
1692
|
+
currentStepApprovalStatus = consts_1.ApprovalStatus.rejected;
|
|
1693
|
+
return [4, updateUserStepStatus(ctx, approvalNew, { approvalStatus: consts_1.ApprovalStatus.rejected, approveField: approveField })];
|
|
1694
|
+
case 4:
|
|
1695
|
+
_b.sent();
|
|
1696
|
+
isPositive = function (status) { return status === true || status === consts_1.ApprovalStatus.approved || status === consts_1.ApprovalStatus.pass; };
|
|
1697
|
+
if (approvalNew.current_step === consts_1.Step.departmental_review) {
|
|
1698
|
+
if (!(0, exports.isDeptReviewComplete)(approvalNew, 'ns') || !(0, exports.isDeptReviewComplete)(approvalNew, 'legal') ||
|
|
1699
|
+
!(0, exports.isDeptReviewComplete)(approvalNew, 'sra') || !(0, exports.isDeptReviewComplete)(approvalNew, 'ca')) {
|
|
1700
|
+
console.log('[rejectContent]: 有部门审核周期未完成, 只结束当前用户审批任务,不推进审批进度.');
|
|
1701
|
+
return [2, {}];
|
|
1702
|
+
}
|
|
1703
|
+
console.log('[rejectContent]: 部门复审完成');
|
|
1704
|
+
}
|
|
1705
|
+
else if (approvalNew.current_step === consts_1.Step.personnel_review) {
|
|
1706
|
+
if (!(0, exports.isDeptReviewComplete)(approvalNew, 'approval')) {
|
|
1707
|
+
console.log('[rejectContent]: 固定人员审核周期未完成, 只结束当前用户审批任务,不推进审批进度.');
|
|
1708
|
+
return [2, {}];
|
|
1709
|
+
}
|
|
1710
|
+
console.log('[rejectContent]: 固定人员复审完成');
|
|
1711
|
+
}
|
|
1712
|
+
if (approvalNew.child_files == 'yes') {
|
|
1713
|
+
if (!(0, exports.hasReviewed)(approvalNew.kids_approval_status)) {
|
|
1714
|
+
console.log('[rejectContent]: kids审核人未审批, 只结束当前用户审批任务,不推进审批进度.');
|
|
1715
|
+
return [2, {}];
|
|
1716
|
+
}
|
|
1717
|
+
console.log('[rejectContent]: kids审核完成');
|
|
1718
|
+
}
|
|
1719
|
+
console.log("[rejectContent] \u63A8\u8FDB\u5BA1\u6279\u8FDB\u5EA6,\u53C2\u6570\u4E3A \u5BA1\u6279\u5355: ".concat(recordId, " \u5F53\u524D\u6B65\u9AA4: ").concat(approvalNew.current_step, " \u5BA1\u6279\u7ED3\u679C\u4E3A: ").concat(currentStepApprovalStatus));
|
|
1720
|
+
return [4, (0, exports.advanceApproval)(ctx, recordId, currentStepApprovalStatus)];
|
|
1721
|
+
case 5:
|
|
1722
|
+
_b.sent();
|
|
1723
|
+
return [2, {}];
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
});
|
|
1727
|
+
};
|
|
1728
|
+
exports.rejectContent = rejectContent;
|
|
1729
|
+
var submitKidsContent = function (ctx, recordId, currentStepApprovalStatus) {
|
|
1730
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1731
|
+
var approveField;
|
|
1732
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1733
|
+
switch (_a.label) {
|
|
1734
|
+
case 0:
|
|
1735
|
+
if (currentStepApprovalStatus != consts_1.ApprovalStatus.approved && currentStepApprovalStatus != consts_1.ApprovalStatus.rejected) {
|
|
1736
|
+
throw new Error('无效的审核状态.');
|
|
1737
|
+
}
|
|
1738
|
+
approveField = "kids_approval_status";
|
|
1739
|
+
if (!(currentStepApprovalStatus === consts_1.ApprovalStatus.approved)) return [3, 2];
|
|
1740
|
+
return [4, (0, exports.approvalContent)(ctx, recordId, { approveField: approveField })];
|
|
1741
|
+
case 1:
|
|
1742
|
+
_a.sent();
|
|
1743
|
+
return [3, 4];
|
|
1744
|
+
case 2: return [4, (0, exports.rejectContent)(ctx, recordId, { approveField: approveField })];
|
|
1745
|
+
case 3:
|
|
1746
|
+
_a.sent();
|
|
1747
|
+
_a.label = 4;
|
|
1748
|
+
case 4: return [2];
|
|
1749
|
+
}
|
|
1750
|
+
});
|
|
1751
|
+
});
|
|
1752
|
+
};
|
|
1753
|
+
exports.submitKidsContent = submitKidsContent;
|
|
1754
|
+
var submitPreReviewContent = function (ctx, recordId, currentStepApprovalStatus) {
|
|
1755
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1756
|
+
var user, approval, approveField, processRecords, type;
|
|
1757
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1758
|
+
switch (_a.label) {
|
|
1759
|
+
case 0:
|
|
1760
|
+
if (currentStepApprovalStatus != consts_1.ApprovalStatus.approved && currentStepApprovalStatus != consts_1.ApprovalStatus.rejected) {
|
|
1761
|
+
throw new Error('无效的审核状态.');
|
|
1762
|
+
}
|
|
1763
|
+
user = ctx.meta.user;
|
|
1764
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1765
|
+
case 1:
|
|
1766
|
+
approval = _a.sent();
|
|
1767
|
+
if (approval.current_step !== consts_1.Step.departmental_review && approval.current_step !== consts_1.Step.personnel_review) {
|
|
1768
|
+
throw new Error('当前步骤不支持预审操作');
|
|
1769
|
+
}
|
|
1770
|
+
if (!(0, lodash_1.includes)(approval.person_pending_approve, user.userId)) {
|
|
1771
|
+
throw new Error('您不是当前预审人');
|
|
1772
|
+
}
|
|
1773
|
+
approveField = '';
|
|
1774
|
+
if (approval.pre_reviewer === user.userId) {
|
|
1775
|
+
approveField = 'pre_approval_status';
|
|
1776
|
+
}
|
|
1777
|
+
else if (approval.pre_ns_reviewer === user.userId) {
|
|
1778
|
+
approveField = 'pre_ns_approval_status';
|
|
1779
|
+
}
|
|
1780
|
+
else if (approval.pre_legal_reviewer === user.userId) {
|
|
1781
|
+
approveField = 'pre_legal_approval_status';
|
|
1782
|
+
}
|
|
1783
|
+
else if (approval.pre_sra_reviewer === user.userId) {
|
|
1784
|
+
approveField = 'pre_sra_approval_status';
|
|
1785
|
+
}
|
|
1786
|
+
else if (approval.pre_ca_reviewer === user.userId) {
|
|
1787
|
+
approveField = 'pre_ca_approval_status';
|
|
1788
|
+
}
|
|
1789
|
+
if (!!approveField) return [3, 3];
|
|
1790
|
+
return [4, ctx.getObject("pepsico_approval_process").find({
|
|
1791
|
+
filters: [
|
|
1792
|
+
["owner", "=", user.userId],
|
|
1793
|
+
["pepsico_material_approval", "=", recordId],
|
|
1794
|
+
["current_step", "=", approval.current_step],
|
|
1795
|
+
["space", "=", approval.space],
|
|
1796
|
+
["approved", "=", 'progess']
|
|
1797
|
+
],
|
|
1798
|
+
top: 1,
|
|
1799
|
+
sort: "modified desc"
|
|
1800
|
+
})];
|
|
1801
|
+
case 2:
|
|
1802
|
+
processRecords = _a.sent();
|
|
1803
|
+
if (processRecords.length > 0) {
|
|
1804
|
+
type = processRecords[0].type;
|
|
1805
|
+
if (type === consts_1.ProcessApprovalType.PreNS)
|
|
1806
|
+
approveField = 'pre_ns_approval_status';
|
|
1807
|
+
else if (type === consts_1.ProcessApprovalType.PreLegal)
|
|
1808
|
+
approveField = 'pre_legal_approval_status';
|
|
1809
|
+
else if (type === consts_1.ProcessApprovalType.PreSRA)
|
|
1810
|
+
approveField = 'pre_sra_approval_status';
|
|
1811
|
+
else if (type === consts_1.ProcessApprovalType.PreCA)
|
|
1812
|
+
approveField = 'pre_ca_approval_status';
|
|
1813
|
+
else if (type === consts_1.ProcessApprovalType.Preguding)
|
|
1814
|
+
approveField = 'pre_approval_status';
|
|
1815
|
+
}
|
|
1816
|
+
_a.label = 3;
|
|
1817
|
+
case 3:
|
|
1818
|
+
if (!approveField) {
|
|
1819
|
+
throw new Error('无法确定预审字段');
|
|
1820
|
+
}
|
|
1821
|
+
if (!(currentStepApprovalStatus === consts_1.ApprovalStatus.approved)) return [3, 5];
|
|
1822
|
+
return [4, (0, exports.approvalContent)(ctx, recordId, { approveField: approveField })];
|
|
1823
|
+
case 4:
|
|
1824
|
+
_a.sent();
|
|
1825
|
+
return [3, 7];
|
|
1826
|
+
case 5: return [4, (0, exports.rejectContent)(ctx, recordId, { approveField: approveField })];
|
|
1827
|
+
case 6:
|
|
1828
|
+
_a.sent();
|
|
1829
|
+
_a.label = 7;
|
|
1830
|
+
case 7: return [2];
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
});
|
|
1834
|
+
};
|
|
1835
|
+
exports.submitPreReviewContent = submitPreReviewContent;
|
|
1836
|
+
var submitContent = function (ctx, recordId, currentStepApprovalStatus, skip) {
|
|
1837
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1838
|
+
var approvalNew, user, allow, aProcess, aProcess_1, aProcess_1_1, item, e_12_1, approvalType, allTrue1, allTrue, spaceUsers, owner, materials, pendingXmlToWordMaterials, pendingUploadMaterials;
|
|
1839
|
+
var e_12, _a;
|
|
1840
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1841
|
+
switch (_b.label) {
|
|
1842
|
+
case 0: return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1843
|
+
case 1:
|
|
1844
|
+
approvalNew = _b.sent();
|
|
1845
|
+
user = ctx.meta.user;
|
|
1846
|
+
allow = false;
|
|
1847
|
+
if (!(approvalNew.current_step === consts_1.Step.ai_review && user.is_space_admin && skip === true)) return [3, 10];
|
|
1848
|
+
console.log("".concat(user.name, "(").concat(user.userId, ")\u63D0\u4EA4\u4E86AI\u5BA1\u6838\u6B65\u9AA4:"), recordId);
|
|
1849
|
+
allow = true;
|
|
1850
|
+
return [4, ctx.getObject("pepsico_approval_process").find({
|
|
1851
|
+
filters: [
|
|
1852
|
+
["owner", "=", process.env.PEPSICO_CONTENT_APPROVAL_AI_USERID],
|
|
1853
|
+
["pepsico_material_approval", "=", recordId],
|
|
1854
|
+
["current_step", "=", consts_1.Step.ai_review],
|
|
1855
|
+
["space", "=", approvalNew.space],
|
|
1856
|
+
["approved", "=", 'progess']
|
|
1857
|
+
],
|
|
1858
|
+
top: 1,
|
|
1859
|
+
sort: "modified desc"
|
|
1860
|
+
})];
|
|
1861
|
+
case 2:
|
|
1862
|
+
aProcess = _b.sent();
|
|
1863
|
+
console.log('管理员提交了AI审核步骤, 修改审批历史: process.length:', aProcess.length, JSON.stringify({
|
|
1864
|
+
filters: [
|
|
1865
|
+
["owner", "=", process.env.PEPSICO_CONTENT_APPROVAL_AI_USERID],
|
|
1866
|
+
["pepsico_material_approval", "=", recordId],
|
|
1867
|
+
["current_step", "=", consts_1.Step.ai_review],
|
|
1868
|
+
["space", "=", approvalNew.space],
|
|
1869
|
+
["approved", "=", 'progess']
|
|
1870
|
+
],
|
|
1871
|
+
top: 1,
|
|
1872
|
+
sort: "modified desc"
|
|
1873
|
+
}));
|
|
1874
|
+
_b.label = 3;
|
|
1875
|
+
case 3:
|
|
1876
|
+
_b.trys.push([3, 8, 9, 10]);
|
|
1877
|
+
aProcess_1 = tslib_1.__values(aProcess), aProcess_1_1 = aProcess_1.next();
|
|
1878
|
+
_b.label = 4;
|
|
1879
|
+
case 4:
|
|
1880
|
+
if (!!aProcess_1_1.done) return [3, 7];
|
|
1881
|
+
item = aProcess_1_1.value;
|
|
1882
|
+
console.log('管理员提交了AI审核步骤, 修改审批历史: process Id:', item._id);
|
|
1883
|
+
return [4, ctx.getObject("pepsico_approval_process").directUpdate(item._id, {
|
|
1884
|
+
submitted: new Date(),
|
|
1885
|
+
modified: new Date(),
|
|
1886
|
+
modified_by: user.userId,
|
|
1887
|
+
approved: 'skip'
|
|
1888
|
+
})];
|
|
1889
|
+
case 5:
|
|
1890
|
+
_b.sent();
|
|
1891
|
+
_b.label = 6;
|
|
1892
|
+
case 6:
|
|
1893
|
+
aProcess_1_1 = aProcess_1.next();
|
|
1894
|
+
return [3, 4];
|
|
1895
|
+
case 7: return [3, 10];
|
|
1896
|
+
case 8:
|
|
1897
|
+
e_12_1 = _b.sent();
|
|
1898
|
+
e_12 = { error: e_12_1 };
|
|
1899
|
+
return [3, 10];
|
|
1900
|
+
case 9:
|
|
1901
|
+
try {
|
|
1902
|
+
if (aProcess_1_1 && !aProcess_1_1.done && (_a = aProcess_1.return)) _a.call(aProcess_1);
|
|
1903
|
+
}
|
|
1904
|
+
finally { if (e_12) throw e_12.error; }
|
|
1905
|
+
return [7];
|
|
1906
|
+
case 10:
|
|
1907
|
+
if (allow != true && approvalNew.current_step != consts_1.Step.draft && !(0, lodash_1.includes)(approvalNew.person_pending_approve, user.userId)) {
|
|
1908
|
+
return [2, {}];
|
|
1909
|
+
}
|
|
1910
|
+
if (!(approvalNew.is_external && approvalNew.current_step === consts_1.Step.draft && approvalNew.external_submitted != true)) return [3, 14];
|
|
1911
|
+
if (!(approvalNew.owner === user.userId)) return [3, 13];
|
|
1912
|
+
if (!approvalNew.internal_collaborator) {
|
|
1913
|
+
throw new Error('请先选择内部协作者');
|
|
1914
|
+
}
|
|
1915
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1916
|
+
owner: approvalNew.internal_collaborator,
|
|
1917
|
+
external_submitted: true
|
|
1918
|
+
})];
|
|
1919
|
+
case 11:
|
|
1920
|
+
_b.sent();
|
|
1921
|
+
return [4, (0, notification_1.sendNotifications)(ctx, approvalNew, [approvalNew.internal_collaborator], '协助提交材料审批单')];
|
|
1922
|
+
case 12:
|
|
1923
|
+
_b.sent();
|
|
1924
|
+
_b.label = 13;
|
|
1925
|
+
case 13: return [2];
|
|
1926
|
+
case 14:
|
|
1927
|
+
if (!(approvalNew.current_step === consts_1.Step.draft)) return [3, 22];
|
|
1928
|
+
return [4, getApproveType(ctx, approvalNew)];
|
|
1929
|
+
case 15:
|
|
1930
|
+
approvalType = _b.sent();
|
|
1931
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalNew._id, {
|
|
1932
|
+
approval_type: approvalType
|
|
1933
|
+
})];
|
|
1934
|
+
case 16:
|
|
1935
|
+
_b.sent();
|
|
1936
|
+
if (!false) return [3, 19];
|
|
1937
|
+
return [4, (0, material_1.deleteBulkDocOneDriveShareLink)(ctx, recordId)];
|
|
1938
|
+
case 17:
|
|
1939
|
+
allTrue1 = _b.sent();
|
|
1940
|
+
if (allTrue1 != true) {
|
|
1941
|
+
return [2, {
|
|
1942
|
+
status: 500,
|
|
1943
|
+
msg: '更新素材失败, 请稍后重试',
|
|
1944
|
+
data: {}
|
|
1945
|
+
}];
|
|
1946
|
+
}
|
|
1947
|
+
return [4, (0, material_1.downloadBulkFromOneDriveDoc)(ctx, recordId)];
|
|
1948
|
+
case 18:
|
|
1949
|
+
allTrue = _b.sent();
|
|
1950
|
+
if (allTrue != true) {
|
|
1951
|
+
return [2, {
|
|
1952
|
+
status: 500,
|
|
1953
|
+
msg: '更新素材失败, 请稍后重试',
|
|
1954
|
+
data: {}
|
|
1955
|
+
}];
|
|
1956
|
+
}
|
|
1957
|
+
_b.label = 19;
|
|
1958
|
+
case 19:
|
|
1959
|
+
if (!(approvalNew && approvalNew.material_owner)) return [3, 22];
|
|
1960
|
+
return [4, ctx.getObject('space_users').find({
|
|
1961
|
+
filters: [['email', '=', approvalNew.material_owner], ['space', '=', approvalNew.space]]
|
|
1962
|
+
})];
|
|
1963
|
+
case 20:
|
|
1964
|
+
spaceUsers = _b.sent();
|
|
1965
|
+
if (!(spaceUsers && spaceUsers.length > 0)) return [3, 22];
|
|
1966
|
+
owner = spaceUsers[0];
|
|
1967
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
1968
|
+
material_owner_id: owner.user
|
|
1969
|
+
})];
|
|
1970
|
+
case 21:
|
|
1971
|
+
_b.sent();
|
|
1972
|
+
_b.label = 22;
|
|
1973
|
+
case 22:
|
|
1974
|
+
console.log("[submitContent] \u6B65\u9AA4\u63D0\u4EA4\uFF0C\u53C2\u6570\u4E3A \u5BA1\u6279\u5355: ".concat(recordId, " \u5F53\u524D\u6B65\u9AA4: ").concat(approvalNew.current_step, " \u5BA1\u6279\u7ED3\u679C\u4E3A: ").concat(currentStepApprovalStatus));
|
|
1975
|
+
if (!(approvalNew.current_step === consts_1.Step.ai_review && currentStepApprovalStatus === consts_1.ApprovalStatus.approved)) return [3, 32];
|
|
1976
|
+
return [4, (0, material_1.getOneDriveMaterials)(ctx, recordId)];
|
|
1977
|
+
case 23:
|
|
1978
|
+
materials = _b.sent();
|
|
1979
|
+
if (!(approvalNew.materials_xml_to_word_status != 'completed')) return [3, 26];
|
|
1980
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalNew._id, {
|
|
1981
|
+
materials_download_from_onedrive_failed_count: 0,
|
|
1982
|
+
materials_download_from_onedrive_status: 'not_started',
|
|
1983
|
+
materials_remove_share_link_from_onedrive_failed_count: 0,
|
|
1984
|
+
materials_remove_share_link_from_onedrive_status: 'not_started',
|
|
1985
|
+
materials_uploaded_to_onedrive_failed_count: 0,
|
|
1986
|
+
materials_uploaded_to_onedrive_status: 'not_started'
|
|
1987
|
+
})];
|
|
1988
|
+
case 24:
|
|
1989
|
+
_b.sent();
|
|
1990
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
1991
|
+
case 25:
|
|
1992
|
+
approvalNew = _b.sent();
|
|
1993
|
+
_b.label = 26;
|
|
1994
|
+
case 26:
|
|
1995
|
+
if (!(approvalNew.materials_uploaded_to_onedrive_status != 'completed')) return [3, 32];
|
|
1996
|
+
console.log('materials:', materials.length);
|
|
1997
|
+
if (!(materials.length === 0)) return [3, 28];
|
|
1998
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalNew._id, {
|
|
1999
|
+
materials_uploaded_to_onedrive_status: 'no_materials',
|
|
2000
|
+
materials_xml_to_word_status: 'no_materials'
|
|
2001
|
+
})];
|
|
2002
|
+
case 27:
|
|
2003
|
+
_b.sent();
|
|
2004
|
+
return [3, 32];
|
|
2005
|
+
case 28:
|
|
2006
|
+
pendingXmlToWordMaterials = materials.filter(function (material) {
|
|
2007
|
+
return material.xml_converted_word !== true;
|
|
2008
|
+
});
|
|
2009
|
+
console.log('pendingXmlToWordMaterials:', pendingXmlToWordMaterials.length);
|
|
2010
|
+
if (!(pendingXmlToWordMaterials.length > 0 && approvalNew.materials_xml_to_word_status != 'no_materials')) return [3, 30];
|
|
2011
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalNew._id, {
|
|
2012
|
+
materials_xml_to_word_status: 'pending'
|
|
2013
|
+
})];
|
|
2014
|
+
case 29:
|
|
2015
|
+
_b.sent();
|
|
2016
|
+
return [2];
|
|
2017
|
+
case 30:
|
|
2018
|
+
pendingUploadMaterials = materials.filter(function (material) {
|
|
2019
|
+
return material.uploaded_to_onedrive !== true;
|
|
2020
|
+
});
|
|
2021
|
+
console.log('pendingUploadMaterials:', pendingUploadMaterials.length);
|
|
2022
|
+
if (!(pendingUploadMaterials.length > 0)) return [3, 32];
|
|
2023
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalNew._id, {
|
|
2024
|
+
materials_uploaded_to_onedrive_status: 'pending'
|
|
2025
|
+
})];
|
|
2026
|
+
case 31:
|
|
2027
|
+
_b.sent();
|
|
2028
|
+
return [2];
|
|
2029
|
+
case 32:
|
|
2030
|
+
console.time('updateUserStepStatus: ' + recordId);
|
|
2031
|
+
return [4, updateUserStepStatus(ctx, approvalNew, { approvalStatus: currentStepApprovalStatus, approveField: '' })];
|
|
2032
|
+
case 33:
|
|
2033
|
+
_b.sent();
|
|
2034
|
+
console.timeEnd('updateUserStepStatus: ' + recordId);
|
|
2035
|
+
console.time('advanceApproval: ' + recordId);
|
|
2036
|
+
return [4, (0, exports.advanceApproval)(ctx, recordId, currentStepApprovalStatus)];
|
|
2037
|
+
case 34:
|
|
2038
|
+
_b.sent();
|
|
2039
|
+
console.timeEnd('advanceApproval: ' + recordId);
|
|
2040
|
+
return [2];
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
});
|
|
2044
|
+
};
|
|
2045
|
+
exports.submitContent = submitContent;
|
|
2046
|
+
var hasReviewed = function (approvalStatus) {
|
|
2047
|
+
if (approvalStatus === true || approvalStatus === false || approvalStatus === consts_1.ApprovalStatus.pass || approvalStatus === consts_1.ApprovalStatus.approved) {
|
|
2048
|
+
return true;
|
|
2049
|
+
}
|
|
2050
|
+
return false;
|
|
2051
|
+
};
|
|
2052
|
+
exports.hasReviewed = hasReviewed;
|
|
2053
|
+
var TYPE_TO_REVIEWER_FIELD = (_a = {},
|
|
2054
|
+
_a[consts_1.ProcessApprovalType.NS] = 'ns_reviewer',
|
|
2055
|
+
_a[consts_1.ProcessApprovalType.Legal] = 'legal_reviewer',
|
|
2056
|
+
_a[consts_1.ProcessApprovalType.SRA] = 'sra_reviewer',
|
|
2057
|
+
_a[consts_1.ProcessApprovalType.CA] = 'ca_reviewer',
|
|
2058
|
+
_a[consts_1.ProcessApprovalType.guding] = 'reviewer',
|
|
2059
|
+
_a[consts_1.ProcessApprovalType.Kids] = 'kids_reviewer',
|
|
2060
|
+
_a[consts_1.ProcessApprovalType.PreNS] = 'pre_ns_reviewer',
|
|
2061
|
+
_a[consts_1.ProcessApprovalType.PreLegal] = 'pre_legal_reviewer',
|
|
2062
|
+
_a[consts_1.ProcessApprovalType.PreSRA] = 'pre_sra_reviewer',
|
|
2063
|
+
_a[consts_1.ProcessApprovalType.PreCA] = 'pre_ca_reviewer',
|
|
2064
|
+
_a[consts_1.ProcessApprovalType.Preguding] = 'pre_reviewer',
|
|
2065
|
+
_a);
|
|
2066
|
+
var TYPE_TO_HANDLER_FIELD = (_b = {},
|
|
2067
|
+
_b[consts_1.ProcessApprovalType.NS] = 'handler_ns',
|
|
2068
|
+
_b[consts_1.ProcessApprovalType.Legal] = 'handler_legal',
|
|
2069
|
+
_b[consts_1.ProcessApprovalType.SRA] = 'handler_sra',
|
|
2070
|
+
_b[consts_1.ProcessApprovalType.CA] = 'handler_ca',
|
|
2071
|
+
_b[consts_1.ProcessApprovalType.guding] = 'handler_guding',
|
|
2072
|
+
_b[consts_1.ProcessApprovalType.Kids] = 'handler_kids',
|
|
2073
|
+
_b[consts_1.ProcessApprovalType.PreNS] = 'handler_prens',
|
|
2074
|
+
_b[consts_1.ProcessApprovalType.PreLegal] = 'handler_prelegal',
|
|
2075
|
+
_b[consts_1.ProcessApprovalType.PreSRA] = 'handler_presra',
|
|
2076
|
+
_b[consts_1.ProcessApprovalType.PreCA] = 'handler_preca',
|
|
2077
|
+
_b[consts_1.ProcessApprovalType.Preguding] = 'handler_preguding',
|
|
2078
|
+
_b);
|
|
2079
|
+
var TYPE_TO_STATUS_FIELD = (_c = {},
|
|
2080
|
+
_c[consts_1.ProcessApprovalType.NS] = 'ns_approval_status',
|
|
2081
|
+
_c[consts_1.ProcessApprovalType.Legal] = 'legal_approval_status',
|
|
2082
|
+
_c[consts_1.ProcessApprovalType.SRA] = 'sra_approval_status',
|
|
2083
|
+
_c[consts_1.ProcessApprovalType.CA] = 'ca_approval_status',
|
|
2084
|
+
_c[consts_1.ProcessApprovalType.guding] = 'approval_status',
|
|
2085
|
+
_c[consts_1.ProcessApprovalType.Kids] = 'kids_approval_status',
|
|
2086
|
+
_c[consts_1.ProcessApprovalType.PreNS] = 'pre_ns_approval_status',
|
|
2087
|
+
_c[consts_1.ProcessApprovalType.PreLegal] = 'pre_legal_approval_status',
|
|
2088
|
+
_c[consts_1.ProcessApprovalType.PreSRA] = 'pre_sra_approval_status',
|
|
2089
|
+
_c[consts_1.ProcessApprovalType.PreCA] = 'pre_ca_approval_status',
|
|
2090
|
+
_c[consts_1.ProcessApprovalType.Preguding] = 'pre_approval_status',
|
|
2091
|
+
_c);
|
|
2092
|
+
var POSTPONE_REVIEW_TYPE_PRIORITY = [
|
|
2093
|
+
consts_1.ProcessApprovalType.CA,
|
|
2094
|
+
consts_1.ProcessApprovalType.SRA,
|
|
2095
|
+
consts_1.ProcessApprovalType.NS,
|
|
2096
|
+
consts_1.ProcessApprovalType.Legal,
|
|
2097
|
+
consts_1.ProcessApprovalType.guding,
|
|
2098
|
+
consts_1.ProcessApprovalType.PreCA,
|
|
2099
|
+
consts_1.ProcessApprovalType.PreSRA,
|
|
2100
|
+
consts_1.ProcessApprovalType.PreNS,
|
|
2101
|
+
consts_1.ProcessApprovalType.PreLegal,
|
|
2102
|
+
consts_1.ProcessApprovalType.Preguding
|
|
2103
|
+
];
|
|
2104
|
+
var getUsersValue = function (val) {
|
|
2105
|
+
if (!val)
|
|
2106
|
+
return [];
|
|
2107
|
+
return Array.isArray(val) ? val : [val];
|
|
2108
|
+
};
|
|
2109
|
+
var isUserInRecordType = function (record, type, userId) {
|
|
2110
|
+
var handlerField = TYPE_TO_HANDLER_FIELD[type];
|
|
2111
|
+
var reviewerField = TYPE_TO_REVIEWER_FIELD[type];
|
|
2112
|
+
var handlerUsers = handlerField ? getUsersValue(record[handlerField]) : [];
|
|
2113
|
+
var reviewerUsers = reviewerField ? getUsersValue(record[reviewerField]) : [];
|
|
2114
|
+
var candidateUsers = handlerUsers.length > 0 ? handlerUsers : reviewerUsers;
|
|
2115
|
+
return (0, lodash_1.includes)(candidateUsers, userId);
|
|
2116
|
+
};
|
|
2117
|
+
var getPostponeReviewDepartmentType = function (record, userProcessRecords, userId) {
|
|
2118
|
+
var processTypes = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.map)(userProcessRecords || [], 'type')));
|
|
2119
|
+
var eligibleProcessType = processTypes.find(function (type) {
|
|
2120
|
+
if (type === consts_1.ProcessApprovalType.Kids)
|
|
2121
|
+
return false;
|
|
2122
|
+
var statusField = TYPE_TO_STATUS_FIELD[type];
|
|
2123
|
+
return !!statusField && record[statusField] === false;
|
|
2124
|
+
});
|
|
2125
|
+
if (eligibleProcessType) {
|
|
2126
|
+
return eligibleProcessType;
|
|
2127
|
+
}
|
|
2128
|
+
if (userId) {
|
|
2129
|
+
var eligibleRecordType = POSTPONE_REVIEW_TYPE_PRIORITY.find(function (type) {
|
|
2130
|
+
var statusField = TYPE_TO_STATUS_FIELD[type];
|
|
2131
|
+
return !!statusField && record[statusField] === false && isUserInRecordType(record, type, userId);
|
|
2132
|
+
});
|
|
2133
|
+
if (eligibleRecordType) {
|
|
2134
|
+
return eligibleRecordType;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
if (processTypes.includes(consts_1.ProcessApprovalType.Kids) || (userId && isUserInRecordType(record, consts_1.ProcessApprovalType.Kids, userId))) {
|
|
2138
|
+
throw new Error('Kids审核人不支持延后审核操作');
|
|
2139
|
+
}
|
|
2140
|
+
throw new Error('仅驳回审批单后可以延后审核');
|
|
2141
|
+
};
|
|
2142
|
+
exports.getPostponeReviewDepartmentType = getPostponeReviewDepartmentType;
|
|
2143
|
+
var postponeReview = function (ctx, recordId, data) {
|
|
2144
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
2145
|
+
var user, record, reviewSteps, progessRecords, userProcessRecords, departmentType, statusField, reviewerField, handlerField, deptUserIds, now, unactivatedMarkers, latestMarker, _a, _b, marker, e_13_1, currentMarkerUsers, newMarkerUsers;
|
|
2146
|
+
var e_13, _c;
|
|
2147
|
+
return tslib_1.__generator(this, function (_d) {
|
|
2148
|
+
switch (_d.label) {
|
|
2149
|
+
case 0:
|
|
2150
|
+
user = ctx.meta.user;
|
|
2151
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
|
|
2152
|
+
case 1:
|
|
2153
|
+
record = _d.sent();
|
|
2154
|
+
reviewSteps = [consts_1.Step.departmental_review, consts_1.Step.personnel_review];
|
|
2155
|
+
if (!reviewSteps.includes(record.current_step) && record.current_step !== consts_1.Step.submitter_revisions) {
|
|
2156
|
+
throw new Error('当前步骤不支持延后审核操作');
|
|
2157
|
+
}
|
|
2158
|
+
if (record.is_urgent) {
|
|
2159
|
+
throw new Error('加急审批单不允许延后审核');
|
|
2160
|
+
}
|
|
2161
|
+
if (!(0, lodash_1.includes)(record.person_approved, user.userId)) {
|
|
2162
|
+
throw new Error('您不在当前已审批人列表中');
|
|
2163
|
+
}
|
|
2164
|
+
return [4, ctx.getObject('pepsico_approval_process').directFind({
|
|
2165
|
+
filters: [
|
|
2166
|
+
['pepsico_material_approval', '=', recordId],
|
|
2167
|
+
['owner', '=', user.userId],
|
|
2168
|
+
['approved', '=', 'progess'],
|
|
2169
|
+
['space', '=', record.space]
|
|
2170
|
+
]
|
|
2171
|
+
})];
|
|
2172
|
+
case 2:
|
|
2173
|
+
progessRecords = _d.sent();
|
|
2174
|
+
if (progessRecords.length > 0) {
|
|
2175
|
+
throw new Error('您还有待处理的审批任务,无法执行延后审核');
|
|
2176
|
+
}
|
|
2177
|
+
return [4, ctx.getObject('pepsico_approval_process').directFind({
|
|
2178
|
+
filters: [
|
|
2179
|
+
['pepsico_material_approval', '=', recordId],
|
|
2180
|
+
['owner', '=', user.userId],
|
|
2181
|
+
['space', '=', record.space]
|
|
2182
|
+
],
|
|
2183
|
+
sort: 'created desc',
|
|
2184
|
+
})];
|
|
2185
|
+
case 3:
|
|
2186
|
+
userProcessRecords = _d.sent();
|
|
2187
|
+
if (!userProcessRecords || userProcessRecords.length === 0) {
|
|
2188
|
+
throw new Error('未找到您的审核记录');
|
|
2189
|
+
}
|
|
2190
|
+
departmentType = (0, exports.getPostponeReviewDepartmentType)(record, userProcessRecords, user.userId);
|
|
2191
|
+
if (!departmentType) {
|
|
2192
|
+
throw new Error('无法确定您所在的审核部门');
|
|
2193
|
+
}
|
|
2194
|
+
statusField = TYPE_TO_STATUS_FIELD[departmentType];
|
|
2195
|
+
if (!statusField || record[statusField] !== false) {
|
|
2196
|
+
throw new Error('仅驳回审批单后可以延后审核');
|
|
2197
|
+
}
|
|
2198
|
+
reviewerField = TYPE_TO_REVIEWER_FIELD[departmentType];
|
|
2199
|
+
handlerField = TYPE_TO_HANDLER_FIELD[departmentType];
|
|
2200
|
+
deptUserIds = [];
|
|
2201
|
+
if (handlerField && record[handlerField]) {
|
|
2202
|
+
deptUserIds = getUsersValue(record[handlerField]);
|
|
2203
|
+
}
|
|
2204
|
+
else if (reviewerField && record[reviewerField]) {
|
|
2205
|
+
deptUserIds = getUsersValue(record[reviewerField]);
|
|
2206
|
+
}
|
|
2207
|
+
if (deptUserIds.length === 0) {
|
|
2208
|
+
deptUserIds = [user.userId];
|
|
2209
|
+
}
|
|
2210
|
+
now = new Date();
|
|
2211
|
+
return [4, ctx.getObject('pepsico_review_postpone').directFind({
|
|
2212
|
+
filters: [
|
|
2213
|
+
['pepsico_material_approval', '=', recordId],
|
|
2214
|
+
['postpone_by', '=', user.userId],
|
|
2215
|
+
['space', '=', record.space],
|
|
2216
|
+
['is_marker', '=', true]
|
|
2217
|
+
],
|
|
2218
|
+
sort: 'created desc'
|
|
2219
|
+
})];
|
|
2220
|
+
case 4:
|
|
2221
|
+
unactivatedMarkers = _d.sent();
|
|
2222
|
+
if (!(unactivatedMarkers && unactivatedMarkers.length > 0)) return [3, 14];
|
|
2223
|
+
latestMarker = unactivatedMarkers[0];
|
|
2224
|
+
return [4, ctx.getObject('pepsico_review_postpone').directUpdate(latestMarker._id, {
|
|
2225
|
+
department_type: departmentType,
|
|
2226
|
+
postpone_reason: data.postpone_reason || '',
|
|
2227
|
+
postpone_date: now,
|
|
2228
|
+
postponed_user_ids: deptUserIds.join(','),
|
|
2229
|
+
notification_sent: false,
|
|
2230
|
+
modified: now,
|
|
2231
|
+
modified_by: user.userId,
|
|
2232
|
+
name: "".concat(departmentType, " \u5EF6\u540E\u5BA1\u6838\u6807\u8BB0 ").concat(now.toISOString())
|
|
2233
|
+
})];
|
|
2234
|
+
case 5:
|
|
2235
|
+
_d.sent();
|
|
2236
|
+
_d.label = 6;
|
|
2237
|
+
case 6:
|
|
2238
|
+
_d.trys.push([6, 11, 12, 13]);
|
|
2239
|
+
_a = tslib_1.__values(unactivatedMarkers.slice(1)), _b = _a.next();
|
|
2240
|
+
_d.label = 7;
|
|
2241
|
+
case 7:
|
|
2242
|
+
if (!!_b.done) return [3, 10];
|
|
2243
|
+
marker = _b.value;
|
|
2244
|
+
return [4, ctx.getObject('pepsico_review_postpone').directUpdate(marker._id, {
|
|
2245
|
+
is_marker: false,
|
|
2246
|
+
notification_sent: true,
|
|
2247
|
+
modified: now,
|
|
2248
|
+
modified_by: user.userId
|
|
2249
|
+
})];
|
|
2250
|
+
case 8:
|
|
2251
|
+
_d.sent();
|
|
2252
|
+
_d.label = 9;
|
|
2253
|
+
case 9:
|
|
2254
|
+
_b = _a.next();
|
|
2255
|
+
return [3, 7];
|
|
2256
|
+
case 10: return [3, 13];
|
|
2257
|
+
case 11:
|
|
2258
|
+
e_13_1 = _d.sent();
|
|
2259
|
+
e_13 = { error: e_13_1 };
|
|
2260
|
+
return [3, 13];
|
|
2261
|
+
case 12:
|
|
2262
|
+
try {
|
|
2263
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2264
|
+
}
|
|
2265
|
+
finally { if (e_13) throw e_13.error; }
|
|
2266
|
+
return [7];
|
|
2267
|
+
case 13: return [3, 16];
|
|
2268
|
+
case 14: return [4, ctx.getObject('pepsico_review_postpone').insert({
|
|
2269
|
+
pepsico_material_approval: recordId,
|
|
2270
|
+
department_type: departmentType,
|
|
2271
|
+
postpone_by: user.userId,
|
|
2272
|
+
postpone_reason: data.postpone_reason || '',
|
|
2273
|
+
postpone_date: now,
|
|
2274
|
+
is_marker: true,
|
|
2275
|
+
notification_sent: false,
|
|
2276
|
+
postponed_user_ids: deptUserIds.join(','),
|
|
2277
|
+
space: record.space,
|
|
2278
|
+
created: now,
|
|
2279
|
+
created_by: user.userId,
|
|
2280
|
+
modified: now,
|
|
2281
|
+
modified_by: user.userId,
|
|
2282
|
+
name: "".concat(departmentType, " \u5EF6\u540E\u5BA1\u6838\u6807\u8BB0 ").concat(now.toISOString())
|
|
2283
|
+
})];
|
|
2284
|
+
case 15:
|
|
2285
|
+
_d.sent();
|
|
2286
|
+
_d.label = 16;
|
|
2287
|
+
case 16:
|
|
2288
|
+
console.log("[postponeReview] recordId=".concat(recordId, ", departmentType=").concat(departmentType, ", deptUserIds=").concat(deptUserIds, ", markedForNextRound=true"));
|
|
2289
|
+
currentMarkerUsers = record.postpone_marker_users || [];
|
|
2290
|
+
newMarkerUsers = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(currentMarkerUsers, deptUserIds)));
|
|
2291
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
|
|
2292
|
+
postpone_marker_users: newMarkerUsers
|
|
2293
|
+
})];
|
|
2294
|
+
case 17:
|
|
2295
|
+
_d.sent();
|
|
2296
|
+
return [2, {}];
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
});
|
|
2300
|
+
};
|
|
2301
|
+
exports.postponeReview = postponeReview;
|
|
2302
|
+
//# sourceMappingURL=approval_engine.js.map
|