@steedos-labs/content-compliance 0.8.8 → 0.8.10
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 -1
- package/lib/actions/bypassApproval.js +18 -0
- package/lib/actions/bypassApproval.js.map +1 -1
- package/lib/actions/bypassMaterial.js +12 -0
- package/lib/actions/bypassMaterial.js.map +1 -1
- package/lib/index.js +153 -0
- package/lib/index.js.map +1 -1
- package/lib/methods/AI.d.ts +6 -0
- package/lib/methods/AI.js +116 -15
- package/lib/methods/AI.js.map +1 -1
- package/lib/methods/__tests__/plsReview.test.d.ts +1 -0
- package/lib/methods/__tests__/plsReview.test.js +736 -0
- package/lib/methods/__tests__/plsReview.test.js.map +1 -0
- package/lib/methods/__tests__/postponeReview.test.js +21 -0
- package/lib/methods/__tests__/postponeReview.test.js.map +1 -1
- package/lib/methods/__tests__/qcParallelReview.test.d.ts +1 -0
- package/lib/methods/__tests__/qcParallelReview.test.js +53 -0
- package/lib/methods/__tests__/qcParallelReview.test.js.map +1 -0
- package/lib/methods/__tests__/qcPreReview.test.d.ts +1 -0
- package/lib/methods/__tests__/qcPreReview.test.js +65 -0
- package/lib/methods/__tests__/qcPreReview.test.js.map +1 -0
- package/lib/methods/approval_engine.d.ts +4 -0
- package/lib/methods/approval_engine.js +388 -221
- package/lib/methods/approval_engine.js.map +1 -1
- package/lib/methods/consts.d.ts +35 -0
- package/lib/methods/consts.js +2 -0
- package/lib/methods/consts.js.map +1 -1
- package/lib/methods/material.js +13 -0
- package/lib/methods/material.js.map +1 -1
- package/lib/methods/pls.d.ts +37 -0
- package/lib/methods/pls.js +480 -130
- package/lib/methods/pls.js.map +1 -1
- package/lib/pages/__tests__/aiReviewCardStyles.test.d.ts +1 -0
- package/lib/pages/__tests__/aiReviewCardStyles.test.js +36 -0
- package/lib/pages/__tests__/aiReviewCardStyles.test.js.map +1 -0
- package/lib/pages/__tests__/aiReviewChineseColons.test.d.ts +1 -0
- package/lib/pages/__tests__/aiReviewChineseColons.test.js +132 -0
- package/lib/pages/__tests__/aiReviewChineseColons.test.js.map +1 -0
- package/lib/pages/__tests__/clientCssCacheVersion.test.d.ts +1 -0
- package/lib/pages/__tests__/clientCssCacheVersion.test.js +31 -0
- package/lib/pages/__tests__/clientCssCacheVersion.test.js.map +1 -0
- package/lib/pages/__tests__/materialDetailAIReviewFilter.test.d.ts +1 -0
- package/lib/pages/__tests__/materialDetailAIReviewFilter.test.js +51 -0
- package/lib/pages/__tests__/materialDetailAIReviewFilter.test.js.map +1 -0
- package/lib/pages/__tests__/plsReviewCardStyles.test.d.ts +1 -0
- package/lib/pages/__tests__/plsReviewCardStyles.test.js +98 -0
- package/lib/pages/__tests__/plsReviewCardStyles.test.js.map +1 -0
- package/lib/pages/__tests__/plsReviewPage.test.d.ts +1 -0
- package/lib/pages/__tests__/plsReviewPage.test.js +338 -0
- package/lib/pages/__tests__/plsReviewPage.test.js.map +1 -0
- package/main/default/applications/pepsico_content_setting.app.yml +4 -0
- package/main/default/client/pepsico_content.client.js +8 -3
- package/main/default/objects/ai_process_detail/ai_process_detail.object.yml +1 -0
- package/main/default/objects/ai_process_detail/fields/pls_extracted_data.field.yml +9 -0
- package/main/default/objects/ai_process_detail/fields/pls_file_ids.field.yml +9 -0
- package/main/default/objects/ai_process_detail/fields/pls_product_name_matched.field.yml +9 -0
- package/main/default/objects/ai_process_detail/fields/pls_rule_unique_matched.field.yml +9 -0
- package/main/default/objects/pepesio_ch__c/fields/company_id.field.yml +14 -0
- package/main/default/objects/pepesio_ch__c/fields/company_ids.field.yml +16 -0
- package/main/default/objects/pepesio_ch__c/fields/created.field.yml +10 -0
- package/main/default/objects/pepesio_ch__c/fields/created_by.field.yml +9 -0
- package/main/default/objects/pepesio_ch__c/fields/file_name.field.yml +8 -0
- package/main/default/objects/pepesio_ch__c/fields/instance_state.field.yml +25 -0
- package/main/default/objects/pepesio_ch__c/fields/locked.field.yml +12 -0
- package/main/default/objects/pepesio_ch__c/fields/material_type.field.yml +10 -0
- package/main/default/objects/pepesio_ch__c/fields/media_type.field.yml +13 -0
- package/main/default/objects/pepesio_ch__c/fields/modified.field.yml +10 -0
- package/main/default/objects/pepesio_ch__c/fields/modified_by.field.yml +9 -0
- package/main/default/objects/pepesio_ch__c/fields/name.field.yml +11 -0
- package/main/default/objects/pepesio_ch__c/fields/owner.field.yml +12 -0
- package/main/default/objects/pepesio_ch__c/fields/product.field.yml +10 -0
- package/main/default/objects/pepesio_ch__c/fields/time.field.yml +8 -0
- package/main/default/objects/pepesio_ch__c/fields/type.field.yml +22 -0
- package/main/default/objects/pepesio_ch__c/listviews/all.listview.yml +21 -0
- package/main/default/objects/pepesio_ch__c/listviews/recent.listview.yml +11 -0
- package/main/default/objects/pepesio_ch__c/pepesio_ch__c.object.yml +31 -0
- package/main/default/objects/pepesio_ch__c/permissions/admin.permission.yml +9 -0
- package/main/default/objects/pepesio_ch__c/permissions/user.permission.yml +9 -0
- package/main/default/objects/pepsico_ai_review/buttons/pepsico_adopt.button.yml +15 -3
- package/main/default/objects/pepsico_ai_review/fields/is_active.field.yml +7 -0
- package/main/default/objects/pepsico_ai_review/fields/pepsico_material_approval.field.yml +7 -0
- package/main/default/objects/pepsico_ai_review/fields/pls_file.field.yml +7 -0
- package/main/default/objects/pepsico_ai_review/fields/review_type.field.yml +12 -0
- package/main/default/objects/pepsico_approval_process/fields/type.field.yml +5 -1
- package/main/default/objects/pepsico_km_pls/fields/allergen_statement.field.yml +9 -0
- package/main/default/objects/pepsico_km_pls/fields/ingredient_list.field.yml +9 -0
- package/main/default/objects/pepsico_km_pls/listviews/all.listview.yml +6 -0
- package/main/default/objects/pepsico_km_pls_file/listviews/lookup.listview.yml +19 -0
- package/main/default/objects/pepsico_km_pls_file/permissions/user.permission.yml +2 -2
- package/main/default/objects/pepsico_material/fields/pre_qc_approval_status.field.yml +16 -0
- package/main/default/objects/pepsico_material/fields/qc_approval_status.field.yml +16 -0
- package/main/default/objects/pepsico_material/fields/qc_bypass_reason.field.yml +11 -0
- package/main/default/objects/pepsico_material/fields/qc_bypassed.field.yml +12 -0
- package/main/default/objects/pepsico_material/fields/qc_bypassed_at.field.yml +11 -0
- package/main/default/objects/pepsico_material/fields/qc_bypassed_by.field.yml +12 -0
- package/main/default/objects/pepsico_material/listviews/all.listview.yml +1 -0
- package/main/default/objects/pepsico_material_approval/buttons/pepsico_modify_pls.button.yml +70 -0
- package/main/default/objects/pepsico_material_approval/buttons/pepsico_postpone_review.button.yml +62 -37
- package/main/default/objects/pepsico_material_approval/buttons/pre_review_approve.button.yml +1 -1
- package/main/default/objects/pepsico_material_approval/buttons/pre_review_reject.button.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/approved_flows.field.yml +2 -2
- package/main/default/objects/pepsico_material_approval/fields/assistance.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/ca_assistance.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/classification.field.yml +15 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_food_name.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_ingredients.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_net_content.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_producer_address.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_producer_name.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_shelf_life.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_standard_code.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_check_storage_condition.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_has_detail_page.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_producers.$.field.yml +5 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_producers.$.producer_address.field.yml +7 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_producers.$.producer_name.field.yml +7 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_producers.field.yml +16 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_qc_production_email.field.yml +16 -0
- package/main/default/objects/pepsico_material_approval/fields/ec_related_approval.field.yml +9 -0
- package/main/default/objects/pepsico_material_approval/fields/form_version.field.yml +10 -0
- package/main/default/objects/pepsico_material_approval/fields/handler_preca.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/handler_preguding.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/handler_prens.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/handler_preqc.field.yml +22 -0
- package/main/default/objects/pepsico_material_approval/fields/handler_presra.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/handler_qc.field.yml +20 -0
- package/main/default/objects/pepsico_material_approval/fields/has_nutrition_table.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/legal_assistance.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/ns_assistance.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/pls_file.field.yml +2 -2
- package/main/default/objects/pepsico_material_approval/fields/pls_km_files.field.yml +28 -0
- package/main/default/objects/pepsico_material_approval/fields/pls_upload_files.field.yml +21 -0
- package/main/default/objects/pepsico_material_approval/fields/pre_ca_reviewer.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/pre_ns_reviewer.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/pre_qc_approval_status.field.yml +17 -0
- package/main/default/objects/pepsico_material_approval/fields/pre_qc_materials_quantity.field.yml +21 -0
- package/main/default/objects/pepsico_material_approval/fields/pre_qc_reviewer.field.yml +19 -0
- package/main/default/objects/pepsico_material_approval/fields/pre_reviewer.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/pre_sra_reviewer.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/product.field.yml +15 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_approval_status.field.yml +18 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_assistance.field.yml +22 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_bypass_reason.field.yml +8 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_bypassed.field.yml +12 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_bypassed_at.field.yml +8 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_bypassed_by.field.yml +8 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_materials_quantity.field.yml +21 -0
- package/main/default/objects/pepsico_material_approval/fields/qc_reviewer.field.yml +22 -0
- package/main/default/objects/pepsico_material_approval/fields/sra_assistance.field.yml +1 -1
- package/main/default/objects/pepsico_material_approval/listviews/all.listview.yml +2 -0
- package/main/default/objects/pepsico_material_approval/pepsico_material_approval.object.yml +4 -0
- package/main/default/objects/pepsico_pls_change_log/fields/after_pls_files.field.yml +9 -0
- package/main/default/objects/pepsico_pls_change_log/fields/after_pls_names.field.yml +7 -0
- package/main/default/objects/pepsico_pls_change_log/fields/approval.field.yml +7 -0
- package/main/default/objects/pepsico_pls_change_log/fields/approval_name.field.yml +6 -0
- package/main/default/objects/pepsico_pls_change_log/fields/before_pls_files.field.yml +9 -0
- package/main/default/objects/pepsico_pls_change_log/fields/before_pls_names.field.yml +7 -0
- package/main/default/objects/pepsico_pls_change_log/fields/material.field.yml +8 -0
- package/main/default/objects/pepsico_pls_change_log/fields/operator.field.yml +7 -0
- package/main/default/objects/pepsico_pls_change_log/fields/scene.field.yml +13 -0
- package/main/default/objects/pepsico_pls_change_log/fields/source.field.yml +14 -0
- package/main/default/objects/pepsico_pls_change_log/fields/space.field.yml +6 -0
- package/main/default/objects/pepsico_pls_change_log/listviews/all.listview.yml +25 -0
- package/main/default/objects/pepsico_pls_change_log/pepsico_pls_change_log.object.yml +16 -0
- package/main/default/objects/pepsico_pls_change_log/permissions/admin.permission.yml +15 -0
- package/main/default/objects/pepsico_pls_change_log/permissions/user.permission.yml +14 -0
- package/main/default/objects/pepsico_review_postpone/fields/department_type.field.yml +4 -0
- package/main/default/objects/pepsico_reviewer/fields/pre_qc_reviewer.field.yml +10 -0
- package/main/default/objects/pepsico_reviewer/fields/qc_assistance.field.yml +14 -0
- package/main/default/objects/pepsico_reviewer/fields/qc_reviewer.field.yml +12 -0
- package/main/default/objects/pepsico_reviewer/listviews/all.listview.yml +4 -0
- package/main/default/pages/pepsico_content_review_detail.page.amis.json +19 -1
- package/main/default/pages/pepsico_material_detail.page.amis.json +698 -52
- package/main/default/pages/pepsico_material_detail_mobile.page.amis.json +332 -8
- package/main/default/tabs/object_pepsico_pls_change_log.tab.yml +14 -0
- package/main/default/triggers/pepsico_material_approval_change.trigger.yml +3 -0
- package/package.json +1 -1
- package/public/content-review/amis.css +344 -9
package/lib/methods/pls.js
CHANGED
|
@@ -1,48 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callExtractPLSRules = exports.setPLSFileActive = exports.batchCreatePLSFiles = exports.resetPLSFileAIExtract = exports.backfillPLSFileTitles = exports.scanPLSFiles = void 0;
|
|
3
|
+
exports.getPLSReviewGroups = exports.getActivePLSOptions = exports.replaceApprovalPLSSource = exports.invalidatePLSReviews = exports.getMaterialReviewPermissions = exports.canAdoptReview = exports.isApprovalReviewer = exports.callExtractPLSRulesPriority = exports.callExtractPLSRules = exports.writeSystemLog = exports.logPLSChange = exports.setPLSFileActive = exports.createApplicationPLSFiles = exports.batchCreatePLSFiles = exports.resetPLSFileAIExtract = exports.backfillPLSFileTitles = exports.scanPLSFiles = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var _ = require('lodash');
|
|
6
6
|
var axios = require('axios');
|
|
7
7
|
var AI_HOST = process.env.PEPSICO_AI_HOST;
|
|
8
8
|
var AI_API_KEY = process.env.PEPSICO_AI_API_KEY;
|
|
9
|
+
var PLS_REVIEW_OBJECT = 'pepsico_ai_review';
|
|
10
|
+
var isNotExplicitlyInactive = function (record) { return !!record && record.is_active !== false; };
|
|
11
|
+
var REVIEW_STEPS = ['departmental_review', 'personnel_review'];
|
|
12
|
+
var SPOT_CHECK_ADOPTION_STEPS = ['awaiting_deployment', 'conclusion'];
|
|
13
|
+
var SPOT_CHECK_ROLE = 'pepsico_spot_check';
|
|
14
|
+
var decodePLSDisplayName = function (value) { return _.unescape(String(value || '')); };
|
|
9
15
|
var getPLSFileTitle = function (fileRecord) {
|
|
10
16
|
var fileName = (fileRecord && fileRecord.original && fileRecord.original.name) || '';
|
|
11
17
|
return fileName.replace(/\.pdf$/i, '');
|
|
12
18
|
};
|
|
13
|
-
var getProductName = function (ctx, productId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
14
|
-
var products, pLists, pRecords_1, pNames_1;
|
|
15
|
-
return tslib_1.__generator(this, function (_a) {
|
|
16
|
-
switch (_a.label) {
|
|
17
|
-
case 0:
|
|
18
|
-
products = _.split(productId, '-');
|
|
19
|
-
return [4, ctx.getObject('picklists').directFind({ filters: ["code", "=",
|
|
20
|
-
"223321001114213"] })];
|
|
21
|
-
case 1:
|
|
22
|
-
pLists = _a.sent();
|
|
23
|
-
if (!(products.length > 0 && pLists.length > 0)) return [3, 3];
|
|
24
|
-
return [4, ctx.getObject('picklist_options').directFind({
|
|
25
|
-
filters: [
|
|
26
|
-
["picklist", "=", pLists[0]._id],
|
|
27
|
-
["value", "in", products]
|
|
28
|
-
]
|
|
29
|
-
})];
|
|
30
|
-
case 2:
|
|
31
|
-
pRecords_1 = _a.sent();
|
|
32
|
-
pNames_1 = [];
|
|
33
|
-
_.each(products, function (pId) {
|
|
34
|
-
var pRecord = _.find(pRecords_1, { value: pId });
|
|
35
|
-
if (pRecord) {
|
|
36
|
-
pNames_1.push(pRecord.name);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return [2, _.join(pNames_1, '-')];
|
|
40
|
-
case 3: return [2, ''];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}); };
|
|
44
19
|
var scanPLSFiles = function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
45
|
-
var approvalId, approvals, addPLSCount, approvals_1, approvals_1_1, approval,
|
|
20
|
+
var approvalId, approvals, addPLSCount, approvals_1, approvals_1_1, approval, materials, materials_1, materials_1_1, material, filters, files, files_1, files_1_1, file, e_1_1, e_2_1, _a, _b, fileId, plsFiles, e_3_1, error_1, e_4_1;
|
|
46
21
|
var e_4, _c, e_2, _d, e_1, _e, e_3, _f;
|
|
47
22
|
return tslib_1.__generator(this, function (_g) {
|
|
48
23
|
switch (_g.label) {
|
|
@@ -56,35 +31,31 @@ var scanPLSFiles = function (ctx) { return tslib_1.__awaiter(void 0, void 0, voi
|
|
|
56
31
|
addPLSCount = 0;
|
|
57
32
|
_g.label = 2;
|
|
58
33
|
case 2:
|
|
59
|
-
_g.trys.push([2, 36, 37
|
|
34
|
+
_g.trys.push([2, 35, 36, 37]);
|
|
60
35
|
approvals_1 = tslib_1.__values(approvals), approvals_1_1 = approvals_1.next();
|
|
61
36
|
_g.label = 3;
|
|
62
37
|
case 3:
|
|
63
|
-
if (!!approvals_1_1.done) return [3,
|
|
38
|
+
if (!!approvals_1_1.done) return [3, 34];
|
|
64
39
|
approval = approvals_1_1.value;
|
|
65
40
|
_g.label = 4;
|
|
66
41
|
case 4:
|
|
67
|
-
_g.trys.push([4,
|
|
42
|
+
_g.trys.push([4, 31, , 33]);
|
|
68
43
|
approvalId = approval._id;
|
|
69
|
-
productId = approval.product;
|
|
70
|
-
return [4, getProductName(ctx, productId)];
|
|
71
|
-
case 5:
|
|
72
|
-
productName = _g.sent();
|
|
73
44
|
return [4, ctx.getObject('pepsico_material').directFind({
|
|
74
45
|
filters: [
|
|
75
46
|
['pepsico_material_approval', '=', approvalId]
|
|
76
47
|
]
|
|
77
48
|
})];
|
|
78
|
-
case
|
|
49
|
+
case 5:
|
|
79
50
|
materials = _g.sent();
|
|
80
51
|
console.error("[scan pls files]: approvalId", approvalId);
|
|
52
|
+
_g.label = 6;
|
|
53
|
+
case 6:
|
|
54
|
+
_g.trys.push([6, 18, 19, 20]);
|
|
55
|
+
materials_1 = (e_2 = void 0, tslib_1.__values(materials)), materials_1_1 = materials_1.next();
|
|
81
56
|
_g.label = 7;
|
|
82
57
|
case 7:
|
|
83
|
-
|
|
84
|
-
materials_1 = (e_2 = void 0, tslib_1.__values(materials)), materials_1_1 = materials_1.next();
|
|
85
|
-
_g.label = 8;
|
|
86
|
-
case 8:
|
|
87
|
-
if (!!materials_1_1.done) return [3, 18];
|
|
58
|
+
if (!!materials_1_1.done) return [3, 17];
|
|
88
59
|
material = materials_1_1.value;
|
|
89
60
|
filters = [
|
|
90
61
|
['metadata/record_id', '=', "objects:pepsico_material:".concat(material._id)],
|
|
@@ -96,132 +67,128 @@ var scanPLSFiles = function (ctx) { return tslib_1.__awaiter(void 0, void 0, voi
|
|
|
96
67
|
return [4, ctx.getObject('cfs_files_filerecord').directFind({
|
|
97
68
|
filters: filters
|
|
98
69
|
})];
|
|
99
|
-
case
|
|
70
|
+
case 8:
|
|
100
71
|
files = _g.sent();
|
|
101
72
|
console.error("[scan pls files]: approvalId", approvalId, "material-".concat(material._id), 'files.length: ', files.length);
|
|
73
|
+
_g.label = 9;
|
|
74
|
+
case 9:
|
|
75
|
+
_g.trys.push([9, 14, 15, 16]);
|
|
76
|
+
files_1 = (e_1 = void 0, tslib_1.__values(files)), files_1_1 = files_1.next();
|
|
102
77
|
_g.label = 10;
|
|
103
78
|
case 10:
|
|
104
|
-
|
|
105
|
-
files_1 = (e_1 = void 0, tslib_1.__values(files)), files_1_1 = files_1.next();
|
|
106
|
-
_g.label = 11;
|
|
107
|
-
case 11:
|
|
108
|
-
if (!!files_1_1.done) return [3, 14];
|
|
79
|
+
if (!!files_1_1.done) return [3, 13];
|
|
109
80
|
file = files_1_1.value;
|
|
110
81
|
return [4, ctx.getObject('pepsico_km_pls_file').directInsert({
|
|
111
82
|
name: getPLSFileTitle(file),
|
|
112
|
-
brand: productName,
|
|
113
83
|
ai_extract: false,
|
|
114
84
|
pls_file: file._id,
|
|
115
85
|
pepsico_material: material._id,
|
|
116
|
-
product: productId,
|
|
117
86
|
pepsico_material_approval: approvalId,
|
|
118
87
|
space: approval.space,
|
|
119
88
|
created: new Date(),
|
|
120
89
|
modified: new Date()
|
|
121
90
|
})];
|
|
122
|
-
case
|
|
91
|
+
case 11:
|
|
123
92
|
_g.sent();
|
|
124
93
|
addPLSCount++;
|
|
125
|
-
_g.label =
|
|
126
|
-
case
|
|
94
|
+
_g.label = 12;
|
|
95
|
+
case 12:
|
|
127
96
|
files_1_1 = files_1.next();
|
|
128
|
-
return [3,
|
|
129
|
-
case
|
|
130
|
-
case
|
|
97
|
+
return [3, 10];
|
|
98
|
+
case 13: return [3, 16];
|
|
99
|
+
case 14:
|
|
131
100
|
e_1_1 = _g.sent();
|
|
132
101
|
e_1 = { error: e_1_1 };
|
|
133
|
-
return [3,
|
|
134
|
-
case
|
|
102
|
+
return [3, 16];
|
|
103
|
+
case 15:
|
|
135
104
|
try {
|
|
136
105
|
if (files_1_1 && !files_1_1.done && (_e = files_1.return)) _e.call(files_1);
|
|
137
106
|
}
|
|
138
107
|
finally { if (e_1) throw e_1.error; }
|
|
139
108
|
return [7];
|
|
140
|
-
case
|
|
109
|
+
case 16:
|
|
141
110
|
materials_1_1 = materials_1.next();
|
|
142
|
-
return [3,
|
|
143
|
-
case
|
|
144
|
-
case
|
|
111
|
+
return [3, 7];
|
|
112
|
+
case 17: return [3, 20];
|
|
113
|
+
case 18:
|
|
145
114
|
e_2_1 = _g.sent();
|
|
146
115
|
e_2 = { error: e_2_1 };
|
|
147
|
-
return [3,
|
|
148
|
-
case
|
|
116
|
+
return [3, 20];
|
|
117
|
+
case 19:
|
|
149
118
|
try {
|
|
150
119
|
if (materials_1_1 && !materials_1_1.done && (_d = materials_1.return)) _d.call(materials_1);
|
|
151
120
|
}
|
|
152
121
|
finally { if (e_2) throw e_2.error; }
|
|
153
122
|
return [7];
|
|
123
|
+
case 20:
|
|
124
|
+
if (!(approval.pls_file && approval.pls_file.length > 0)) return [3, 29];
|
|
125
|
+
_g.label = 21;
|
|
154
126
|
case 21:
|
|
155
|
-
|
|
127
|
+
_g.trys.push([21, 27, 28, 29]);
|
|
128
|
+
_a = (e_3 = void 0, tslib_1.__values(approval.pls_file)), _b = _a.next();
|
|
156
129
|
_g.label = 22;
|
|
157
130
|
case 22:
|
|
158
|
-
|
|
159
|
-
_a = (e_3 = void 0, tslib_1.__values(approval.pls_file)), _b = _a.next();
|
|
160
|
-
_g.label = 23;
|
|
161
|
-
case 23:
|
|
162
|
-
if (!!_b.done) return [3, 27];
|
|
131
|
+
if (!!_b.done) return [3, 26];
|
|
163
132
|
fileId = _b.value;
|
|
164
133
|
return [4, ctx.getObject('cfs_files_filerecord').directFind({ filters: [['_id', '=', fileId]], fields: ['original'] })];
|
|
165
|
-
case
|
|
134
|
+
case 23:
|
|
166
135
|
plsFiles = _g.sent();
|
|
167
136
|
return [4, ctx.getObject('pepsico_km_pls_file').directInsert({
|
|
168
137
|
name: getPLSFileTitle(plsFiles && plsFiles[0]),
|
|
169
|
-
brand: productName,
|
|
170
138
|
ai_extract: false,
|
|
171
139
|
pls_file: fileId,
|
|
172
|
-
product: productId,
|
|
173
140
|
pepsico_material_approval: approvalId,
|
|
174
141
|
space: approval.space,
|
|
175
142
|
created_by: approval.created_by,
|
|
176
143
|
created: new Date(),
|
|
177
144
|
modified: new Date()
|
|
178
145
|
})];
|
|
179
|
-
case
|
|
146
|
+
case 24:
|
|
180
147
|
_g.sent();
|
|
181
|
-
_g.label =
|
|
182
|
-
case
|
|
148
|
+
_g.label = 25;
|
|
149
|
+
case 25:
|
|
183
150
|
_b = _a.next();
|
|
184
|
-
return [3,
|
|
185
|
-
case
|
|
186
|
-
case
|
|
151
|
+
return [3, 22];
|
|
152
|
+
case 26: return [3, 29];
|
|
153
|
+
case 27:
|
|
187
154
|
e_3_1 = _g.sent();
|
|
188
155
|
e_3 = { error: e_3_1 };
|
|
189
|
-
return [3,
|
|
190
|
-
case
|
|
156
|
+
return [3, 29];
|
|
157
|
+
case 28:
|
|
191
158
|
try {
|
|
192
159
|
if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
|
|
193
160
|
}
|
|
194
161
|
finally { if (e_3) throw e_3.error; }
|
|
195
162
|
return [7];
|
|
196
|
-
case
|
|
163
|
+
case 29: return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalId, {
|
|
197
164
|
scanned_pls: true,
|
|
198
165
|
scanned_pls_date: new Date()
|
|
199
166
|
})];
|
|
200
|
-
case
|
|
167
|
+
case 30:
|
|
201
168
|
_g.sent();
|
|
202
|
-
return [3,
|
|
203
|
-
case
|
|
169
|
+
return [3, 33];
|
|
170
|
+
case 31:
|
|
204
171
|
error_1 = _g.sent();
|
|
205
172
|
console.error("[scan pls files]-".concat(approvalId), error_1, new Date());
|
|
206
173
|
return [4, ctx.logger.error("[scan pls files]-".concat(approvalId), error_1.message)];
|
|
207
|
-
case
|
|
174
|
+
case 32:
|
|
208
175
|
_g.sent();
|
|
209
|
-
return [3,
|
|
210
|
-
case
|
|
176
|
+
return [3, 33];
|
|
177
|
+
case 33:
|
|
211
178
|
approvals_1_1 = approvals_1.next();
|
|
212
179
|
return [3, 3];
|
|
213
|
-
case
|
|
214
|
-
case
|
|
180
|
+
case 34: return [3, 37];
|
|
181
|
+
case 35:
|
|
215
182
|
e_4_1 = _g.sent();
|
|
216
183
|
e_4 = { error: e_4_1 };
|
|
217
|
-
return [3,
|
|
218
|
-
case
|
|
184
|
+
return [3, 37];
|
|
185
|
+
case 36:
|
|
219
186
|
try {
|
|
220
187
|
if (approvals_1_1 && !approvals_1_1.done && (_c = approvals_1.return)) _c.call(approvals_1);
|
|
221
188
|
}
|
|
222
189
|
finally { if (e_4) throw e_4.error; }
|
|
223
190
|
return [7];
|
|
224
|
-
case
|
|
191
|
+
case 37: return [2, addPLSCount];
|
|
225
192
|
}
|
|
226
193
|
});
|
|
227
194
|
}); };
|
|
@@ -327,7 +294,7 @@ var resetPLSFileAIExtract = function (ctx) { return tslib_1.__awaiter(void 0, vo
|
|
|
327
294
|
}); };
|
|
328
295
|
exports.resetPLSFileAIExtract = resetPLSFileAIExtract;
|
|
329
296
|
var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
330
|
-
var user, space, ids, objFile, objPls,
|
|
297
|
+
var user, space, ids, objFile, objPls, records, skipped, ids_1, ids_1_1, fileId, files, fileRecord, fileName, fileType, isPdf, now, record, e_6_1;
|
|
331
298
|
var e_6, _a;
|
|
332
299
|
return tslib_1.__generator(this, function (_b) {
|
|
333
300
|
switch (_b.label) {
|
|
@@ -339,11 +306,11 @@ var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(voi
|
|
|
339
306
|
}
|
|
340
307
|
ids = _.uniq(_.compact(fileIds || []));
|
|
341
308
|
if (ids.length === 0) {
|
|
342
|
-
return [2, { created: 0, skipped: 0 }];
|
|
309
|
+
return [2, { created: 0, skipped: 0, records: [] }];
|
|
343
310
|
}
|
|
344
311
|
objFile = ctx.getObject('cfs_files_filerecord');
|
|
345
312
|
objPls = ctx.getObject('pepsico_km_pls_file');
|
|
346
|
-
|
|
313
|
+
records = [];
|
|
347
314
|
skipped = [];
|
|
348
315
|
_b.label = 1;
|
|
349
316
|
case 1:
|
|
@@ -368,7 +335,6 @@ var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(voi
|
|
|
368
335
|
return [4, objPls.directInsert({
|
|
369
336
|
name: fileName.replace(/\.pdf$/i, ''),
|
|
370
337
|
ai_extract: false,
|
|
371
|
-
is_active: false,
|
|
372
338
|
pls_file: fileId,
|
|
373
339
|
space: space,
|
|
374
340
|
owner: user.userId,
|
|
@@ -378,8 +344,8 @@ var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(voi
|
|
|
378
344
|
modified_by: user.userId
|
|
379
345
|
})];
|
|
380
346
|
case 4:
|
|
381
|
-
_b.sent();
|
|
382
|
-
|
|
347
|
+
record = _b.sent();
|
|
348
|
+
records.push({ id: record._id, name: record.name || fileName.replace(/\.pdf$/i, '') });
|
|
383
349
|
_b.label = 5;
|
|
384
350
|
case 5:
|
|
385
351
|
ids_1_1 = ids_1.next();
|
|
@@ -395,11 +361,57 @@ var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(voi
|
|
|
395
361
|
}
|
|
396
362
|
finally { if (e_6) throw e_6.error; }
|
|
397
363
|
return [7];
|
|
398
|
-
case 9: return [2, { created:
|
|
364
|
+
case 9: return [2, { created: records.length, skipped: skipped.length, records: records }];
|
|
399
365
|
}
|
|
400
366
|
});
|
|
401
367
|
}); };
|
|
402
368
|
exports.batchCreatePLSFiles = batchCreatePLSFiles;
|
|
369
|
+
var createApplicationPLSFiles = function (ctx, fileIds, approval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
370
|
+
var result, _a, _b, record, e_7_1;
|
|
371
|
+
var e_7, _c;
|
|
372
|
+
return tslib_1.__generator(this, function (_d) {
|
|
373
|
+
switch (_d.label) {
|
|
374
|
+
case 0: return [4, (0, exports.batchCreatePLSFiles)(ctx, fileIds)];
|
|
375
|
+
case 1:
|
|
376
|
+
result = _d.sent();
|
|
377
|
+
_d.label = 2;
|
|
378
|
+
case 2:
|
|
379
|
+
_d.trys.push([2, 8, 9, 10]);
|
|
380
|
+
_a = tslib_1.__values(result.records), _b = _a.next();
|
|
381
|
+
_d.label = 3;
|
|
382
|
+
case 3:
|
|
383
|
+
if (!!_b.done) return [3, 7];
|
|
384
|
+
record = _b.value;
|
|
385
|
+
if (!approval) return [3, 5];
|
|
386
|
+
return [4, ctx.getObject('pepsico_km_pls_file').directUpdate(record.id, {
|
|
387
|
+
pepsico_material_approval: approval._id,
|
|
388
|
+
modified: new Date()
|
|
389
|
+
})];
|
|
390
|
+
case 4:
|
|
391
|
+
_d.sent();
|
|
392
|
+
_d.label = 5;
|
|
393
|
+
case 5:
|
|
394
|
+
(0, exports.callExtractPLSRulesPriority)(ctx, record.id).catch(function () { });
|
|
395
|
+
_d.label = 6;
|
|
396
|
+
case 6:
|
|
397
|
+
_b = _a.next();
|
|
398
|
+
return [3, 3];
|
|
399
|
+
case 7: return [3, 10];
|
|
400
|
+
case 8:
|
|
401
|
+
e_7_1 = _d.sent();
|
|
402
|
+
e_7 = { error: e_7_1 };
|
|
403
|
+
return [3, 10];
|
|
404
|
+
case 9:
|
|
405
|
+
try {
|
|
406
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
407
|
+
}
|
|
408
|
+
finally { if (e_7) throw e_7.error; }
|
|
409
|
+
return [7];
|
|
410
|
+
case 10: return [2, result];
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}); };
|
|
414
|
+
exports.createApplicationPLSFiles = createApplicationPLSFiles;
|
|
403
415
|
var setPLSFileActive = function (ctx, fileId, active) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
404
416
|
var now, objPls, objRule, rules;
|
|
405
417
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -430,30 +442,89 @@ var setPLSFileActive = function (ctx, fileId, active) { return tslib_1.__awaiter
|
|
|
430
442
|
});
|
|
431
443
|
}); };
|
|
432
444
|
exports.setPLSFileActive = setPLSFileActive;
|
|
433
|
-
var
|
|
434
|
-
var
|
|
435
|
-
return tslib_1.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
445
|
+
var logPLSChange = function (ctx, _a) {
|
|
446
|
+
var approval = _a.approval, scene = _a.scene, _b = _a.materialId, materialId = _b === void 0 ? null : _b, _c = _a.beforeIds, beforeIds = _c === void 0 ? [] : _c, _d = _a.afterIds, afterIds = _d === void 0 ? [] : _d, _e = _a.source, source = _e === void 0 ? null : _e;
|
|
447
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
448
|
+
var beforeList, afterList, allIds, files, nameById_1, toNames, e_8;
|
|
449
|
+
return tslib_1.__generator(this, function (_f) {
|
|
450
|
+
switch (_f.label) {
|
|
451
|
+
case 0:
|
|
452
|
+
_f.trys.push([0, 3, , 6]);
|
|
453
|
+
beforeList = _.uniq(_.compact(beforeIds));
|
|
454
|
+
afterList = _.uniq(_.compact(afterIds));
|
|
455
|
+
if (beforeList.length === 0 && afterList.length === 0) {
|
|
456
|
+
return [2];
|
|
457
|
+
}
|
|
458
|
+
allIds = _.uniq(beforeList.concat(afterList));
|
|
459
|
+
return [4, ctx.getObject('pepsico_km_pls_file').directFind({
|
|
460
|
+
filters: [['_id', 'in', allIds]],
|
|
461
|
+
fields: ['_id', 'name']
|
|
462
|
+
})];
|
|
463
|
+
case 1:
|
|
464
|
+
files = _f.sent();
|
|
465
|
+
nameById_1 = _.keyBy(files, '_id');
|
|
466
|
+
toNames = function (ids) { return ids.map(function (id) { return (nameById_1[id] && nameById_1[id].name) || id; }).join('、'); };
|
|
467
|
+
return [4, ctx.getObject('pepsico_pls_change_log').directInsert({
|
|
468
|
+
approval: approval._id,
|
|
469
|
+
approval_name: approval.name,
|
|
470
|
+
material: materialId,
|
|
471
|
+
scene: scene,
|
|
472
|
+
source: source,
|
|
473
|
+
before_pls_files: beforeList,
|
|
474
|
+
before_pls_names: toNames(beforeList),
|
|
475
|
+
after_pls_files: afterList,
|
|
476
|
+
after_pls_names: toNames(afterList),
|
|
477
|
+
operator: ctx.meta && ctx.meta.user && ctx.meta.user.userId,
|
|
478
|
+
space: approval.space,
|
|
479
|
+
created: new Date(),
|
|
480
|
+
modified: new Date()
|
|
481
|
+
})];
|
|
482
|
+
case 2:
|
|
483
|
+
_f.sent();
|
|
484
|
+
return [3, 6];
|
|
485
|
+
case 3:
|
|
486
|
+
e_8 = _f.sent();
|
|
487
|
+
console.error('[写PLS变更日志失败]', e_8 && e_8.message);
|
|
488
|
+
if (!ctx.logger) return [3, 5];
|
|
489
|
+
return [4, ctx.logger.error('[写PLS变更日志失败]', e_8 && e_8.message)];
|
|
490
|
+
case 4:
|
|
491
|
+
_f.sent();
|
|
492
|
+
_f.label = 5;
|
|
493
|
+
case 5: return [3, 6];
|
|
494
|
+
case 6: return [2];
|
|
495
|
+
}
|
|
496
|
+
});
|
|
453
497
|
});
|
|
454
|
-
}
|
|
498
|
+
};
|
|
499
|
+
exports.logPLSChange = logPLSChange;
|
|
500
|
+
var writeSystemLog = function (ctx, level, data, name) {
|
|
501
|
+
if (name === void 0) { name = 'PLS规则提取'; }
|
|
502
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
503
|
+
var e_9;
|
|
504
|
+
return tslib_1.__generator(this, function (_a) {
|
|
505
|
+
switch (_a.label) {
|
|
506
|
+
case 0:
|
|
507
|
+
_a.trys.push([0, 2, , 3]);
|
|
508
|
+
return [4, ctx.getObject('logs').directInsert({
|
|
509
|
+
name: name,
|
|
510
|
+
level: level,
|
|
511
|
+
data: JSON.stringify(data)
|
|
512
|
+
})];
|
|
513
|
+
case 1:
|
|
514
|
+
_a.sent();
|
|
515
|
+
return [3, 3];
|
|
516
|
+
case 2:
|
|
517
|
+
e_9 = _a.sent();
|
|
518
|
+
console.error('[写系统日志失败]', e_9 && e_9.message);
|
|
519
|
+
return [3, 3];
|
|
520
|
+
case 3: return [2];
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
exports.writeSystemLog = writeSystemLog;
|
|
455
526
|
var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
456
|
-
var userId, start, result, data, cost,
|
|
527
|
+
var userId, start, result, data, cost, e_10, error_3, cost;
|
|
457
528
|
return tslib_1.__generator(this, function (_a) {
|
|
458
529
|
switch (_a.label) {
|
|
459
530
|
case 0:
|
|
@@ -492,10 +563,10 @@ var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void
|
|
|
492
563
|
_a.sent();
|
|
493
564
|
return [3, 7];
|
|
494
565
|
case 6:
|
|
495
|
-
|
|
496
|
-
console.error("[\u8C03\u7528 execute-pls API] \u6807\u8BB0 extracting \u5931\u8D25-".concat(fileId),
|
|
566
|
+
e_10 = _a.sent();
|
|
567
|
+
console.error("[\u8C03\u7528 execute-pls API] \u6807\u8BB0 extracting \u5931\u8D25-".concat(fileId), e_10 && e_10.message);
|
|
497
568
|
return [3, 7];
|
|
498
|
-
case 7: return [4, writeSystemLog(ctx, 'info', {
|
|
569
|
+
case 7: return [4, (0, exports.writeSystemLog)(ctx, 'info', {
|
|
499
570
|
action: 'execute-pls',
|
|
500
571
|
id: fileId,
|
|
501
572
|
operator: userId,
|
|
@@ -514,7 +585,7 @@ var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void
|
|
|
514
585
|
return [4, ctx.logger.error("[\u8C03\u7528 execute-pls API]-".concat(fileId), error_3 && error_3.message)];
|
|
515
586
|
case 10:
|
|
516
587
|
_a.sent();
|
|
517
|
-
return [4, writeSystemLog(ctx, 'error', {
|
|
588
|
+
return [4, (0, exports.writeSystemLog)(ctx, 'error', {
|
|
518
589
|
action: 'execute-pls',
|
|
519
590
|
id: fileId,
|
|
520
591
|
operator: userId,
|
|
@@ -531,4 +602,283 @@ var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void
|
|
|
531
602
|
});
|
|
532
603
|
}); };
|
|
533
604
|
exports.callExtractPLSRules = callExtractPLSRules;
|
|
605
|
+
var callExtractPLSRulesPriority = function (ctx, fileId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
606
|
+
var userId, start, url, result, data, cost, error_4, cost;
|
|
607
|
+
return tslib_1.__generator(this, function (_a) {
|
|
608
|
+
switch (_a.label) {
|
|
609
|
+
case 0:
|
|
610
|
+
if (!fileId) {
|
|
611
|
+
throw new Error('缺少记录ID');
|
|
612
|
+
}
|
|
613
|
+
userId = ctx.meta && ctx.meta.user && ctx.meta.user.userId;
|
|
614
|
+
start = new Date().getTime();
|
|
615
|
+
url = "".concat(AI_HOST, "/execute-pls-priority");
|
|
616
|
+
_a.label = 1;
|
|
617
|
+
case 1:
|
|
618
|
+
_a.trys.push([1, 5, , 8]);
|
|
619
|
+
return [4, axios.post(url, { id: fileId }, {
|
|
620
|
+
headers: { 'Content-Type': 'application/json' }
|
|
621
|
+
})];
|
|
622
|
+
case 2:
|
|
623
|
+
result = _a.sent();
|
|
624
|
+
data = result.data;
|
|
625
|
+
cost = new Date().getTime() - start;
|
|
626
|
+
return [4, ctx.logger.info("[\u8C03\u7528 PLS\u4F18\u5148\u63D0\u53D6\u89C4\u5219 API]-".concat(fileId), data)];
|
|
627
|
+
case 3:
|
|
628
|
+
_a.sent();
|
|
629
|
+
return [4, (0, exports.writeSystemLog)(ctx, 'info', {
|
|
630
|
+
action: 'extract-pls-priority',
|
|
631
|
+
id: fileId,
|
|
632
|
+
operator: userId,
|
|
633
|
+
url: url,
|
|
634
|
+
status: 'success',
|
|
635
|
+
cost: cost,
|
|
636
|
+
response: data
|
|
637
|
+
})];
|
|
638
|
+
case 4:
|
|
639
|
+
_a.sent();
|
|
640
|
+
return [2, data];
|
|
641
|
+
case 5:
|
|
642
|
+
error_4 = _a.sent();
|
|
643
|
+
cost = new Date().getTime() - start;
|
|
644
|
+
return [4, ctx.logger.error("[\u8C03\u7528 PLS\u4F18\u5148\u63D0\u53D6\u89C4\u5219 API]-".concat(fileId), error_4 && error_4.message)];
|
|
645
|
+
case 6:
|
|
646
|
+
_a.sent();
|
|
647
|
+
return [4, (0, exports.writeSystemLog)(ctx, 'error', {
|
|
648
|
+
action: 'extract-pls-priority',
|
|
649
|
+
id: fileId,
|
|
650
|
+
operator: userId,
|
|
651
|
+
url: url,
|
|
652
|
+
status: 'fail',
|
|
653
|
+
cost: cost,
|
|
654
|
+
error: error_4 && error_4.message
|
|
655
|
+
})];
|
|
656
|
+
case 7:
|
|
657
|
+
_a.sent();
|
|
658
|
+
throw error_4;
|
|
659
|
+
case 8: return [2];
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}); };
|
|
663
|
+
exports.callExtractPLSRulesPriority = callExtractPLSRulesPriority;
|
|
664
|
+
var getReviewerIds = function (approval) { return approval ? _.compact(_.flatten([
|
|
665
|
+
approval.reviewer,
|
|
666
|
+
approval.ns_reviewer,
|
|
667
|
+
approval.legal_reviewer,
|
|
668
|
+
approval.sra_reviewer,
|
|
669
|
+
approval.ca_reviewer,
|
|
670
|
+
approval.qc_reviewer,
|
|
671
|
+
approval.kids_reviewer,
|
|
672
|
+
approval.pre_reviewer,
|
|
673
|
+
approval.pre_ns_reviewer,
|
|
674
|
+
approval.pre_legal_reviewer,
|
|
675
|
+
approval.pre_sra_reviewer,
|
|
676
|
+
approval.pre_ca_reviewer,
|
|
677
|
+
approval.pre_qc_reviewer
|
|
678
|
+
])) : []; };
|
|
679
|
+
var isApprovalReviewer = function (approval, userId) {
|
|
680
|
+
return !!userId && _.includes(getReviewerIds(approval), userId);
|
|
681
|
+
};
|
|
682
|
+
exports.isApprovalReviewer = isApprovalReviewer;
|
|
683
|
+
var canAdoptReview = function (approval, userId, roles) {
|
|
684
|
+
if (roles === void 0) { roles = []; }
|
|
685
|
+
if (!approval || !userId) {
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
var isPendingReviewer = _.includes(REVIEW_STEPS, approval.current_step)
|
|
689
|
+
&& _.includes(approval.person_pending_approve || [], userId);
|
|
690
|
+
var isSpotCheckOperator = _.includes(SPOT_CHECK_ADOPTION_STEPS, approval.current_step)
|
|
691
|
+
&& _.includes(roles || [], SPOT_CHECK_ROLE);
|
|
692
|
+
return isPendingReviewer || isSpotCheckOperator;
|
|
693
|
+
};
|
|
694
|
+
exports.canAdoptReview = canAdoptReview;
|
|
695
|
+
var getMaterialReviewPermissions = function (ctx, materialId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
696
|
+
var material, approval, _a, currentUser;
|
|
697
|
+
return tslib_1.__generator(this, function (_b) {
|
|
698
|
+
switch (_b.label) {
|
|
699
|
+
case 0: return [4, ctx.getObject('pepsico_material').findOne(materialId)];
|
|
700
|
+
case 1:
|
|
701
|
+
material = _b.sent();
|
|
702
|
+
if (!material) {
|
|
703
|
+
throw new Error('素材不存在');
|
|
704
|
+
}
|
|
705
|
+
if (!material.pepsico_material_approval) return [3, 3];
|
|
706
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(material.pepsico_material_approval)];
|
|
707
|
+
case 2:
|
|
708
|
+
_a = _b.sent();
|
|
709
|
+
return [3, 4];
|
|
710
|
+
case 3:
|
|
711
|
+
_a = null;
|
|
712
|
+
_b.label = 4;
|
|
713
|
+
case 4:
|
|
714
|
+
approval = _a;
|
|
715
|
+
currentUser = ctx.meta && ctx.meta.user;
|
|
716
|
+
return [2, {
|
|
717
|
+
canAdopt: (0, exports.canAdoptReview)(approval, currentUser && currentUser.userId, currentUser && currentUser.roles),
|
|
718
|
+
hasPLSFile: _.compact((approval && approval.pls_km_files) || []).length > 0
|
|
719
|
+
}];
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
}); };
|
|
723
|
+
exports.getMaterialReviewPermissions = getMaterialReviewPermissions;
|
|
724
|
+
var invalidatePLSReviews = function (ctx, approvalId, plsFileId, materialId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
725
|
+
var filters, candidates, records;
|
|
726
|
+
return tslib_1.__generator(this, function (_a) {
|
|
727
|
+
switch (_a.label) {
|
|
728
|
+
case 0:
|
|
729
|
+
filters = [
|
|
730
|
+
['pepsico_material_approval', '=', approvalId],
|
|
731
|
+
['review_type', '=', 'pls']
|
|
732
|
+
];
|
|
733
|
+
if (plsFileId) {
|
|
734
|
+
filters.push(['pls_file', '=', plsFileId]);
|
|
735
|
+
}
|
|
736
|
+
if (materialId) {
|
|
737
|
+
filters.push(['pepsico_material', '=', materialId]);
|
|
738
|
+
}
|
|
739
|
+
return [4, ctx.getObject(PLS_REVIEW_OBJECT).directFind({
|
|
740
|
+
filters: filters,
|
|
741
|
+
fields: ['_id', 'is_active']
|
|
742
|
+
})];
|
|
743
|
+
case 1:
|
|
744
|
+
candidates = _a.sent();
|
|
745
|
+
records = candidates.filter(isNotExplicitlyInactive);
|
|
746
|
+
if (!(records.length > 0)) return [3, 3];
|
|
747
|
+
return [4, ctx.getObject(PLS_REVIEW_OBJECT).directUpdateMany(['_id', 'in', records.map(function (item) { return item._id; })], { is_active: false, modified: new Date() })];
|
|
748
|
+
case 2:
|
|
749
|
+
_a.sent();
|
|
750
|
+
_a.label = 3;
|
|
751
|
+
case 3: return [2, records.length];
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
}); };
|
|
755
|
+
exports.invalidatePLSReviews = invalidatePLSReviews;
|
|
756
|
+
var replaceApprovalPLSSource = function (ctx, approvalId, oldPlsFileId, newPlsFileId, materialId, source) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
757
|
+
var userId, approval, currentIds, nextIds, invalidated;
|
|
758
|
+
return tslib_1.__generator(this, function (_a) {
|
|
759
|
+
switch (_a.label) {
|
|
760
|
+
case 0:
|
|
761
|
+
userId = ctx.meta && ctx.meta.user && ctx.meta.user.userId;
|
|
762
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(approvalId)];
|
|
763
|
+
case 1:
|
|
764
|
+
approval = _a.sent();
|
|
765
|
+
if (!approval) {
|
|
766
|
+
throw new Error('审批单不存在');
|
|
767
|
+
}
|
|
768
|
+
if (!(0, exports.isApprovalReviewer)(approval, userId)) {
|
|
769
|
+
throw new Error('只有审核人可以应用新的PLS规则');
|
|
770
|
+
}
|
|
771
|
+
currentIds = _.uniq(_.compact(approval.pls_km_files || []));
|
|
772
|
+
if (!_.includes(currentIds, oldPlsFileId)) {
|
|
773
|
+
throw new Error('当前PLS来源未关联到审批单');
|
|
774
|
+
}
|
|
775
|
+
nextIds = _.uniq(currentIds.map(function (id) { return id === oldPlsFileId ? newPlsFileId : id; }));
|
|
776
|
+
return [4, ctx.getObject('pepsico_material_approval').directUpdate(approvalId, {
|
|
777
|
+
pls_km_files: nextIds,
|
|
778
|
+
modified: new Date(),
|
|
779
|
+
modified_by: userId
|
|
780
|
+
})];
|
|
781
|
+
case 2:
|
|
782
|
+
_a.sent();
|
|
783
|
+
return [4, (0, exports.invalidatePLSReviews)(ctx, approvalId, oldPlsFileId, materialId)];
|
|
784
|
+
case 3:
|
|
785
|
+
invalidated = _a.sent();
|
|
786
|
+
return [4, (0, exports.logPLSChange)(ctx, {
|
|
787
|
+
approval: approval,
|
|
788
|
+
scene: 'reviewer_change',
|
|
789
|
+
materialId: materialId,
|
|
790
|
+
beforeIds: [oldPlsFileId],
|
|
791
|
+
afterIds: [newPlsFileId],
|
|
792
|
+
source: source
|
|
793
|
+
})];
|
|
794
|
+
case 4:
|
|
795
|
+
_a.sent();
|
|
796
|
+
return [2, { approvalId: approvalId, materialId: materialId, oldPlsFileId: oldPlsFileId, newPlsFileId: newPlsFileId, pls_km_files: nextIds, invalidated: invalidated }];
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}); };
|
|
800
|
+
exports.replaceApprovalPLSSource = replaceApprovalPLSSource;
|
|
801
|
+
var getActivePLSOptions = function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
802
|
+
var records;
|
|
803
|
+
return tslib_1.__generator(this, function (_a) {
|
|
804
|
+
switch (_a.label) {
|
|
805
|
+
case 0: return [4, ctx.getObject('pepsico_km_pls_file').find({
|
|
806
|
+
fields: ['_id', 'name', 'brand', 'version', 'is_active'],
|
|
807
|
+
sort: 'modified desc',
|
|
808
|
+
top: 500
|
|
809
|
+
})];
|
|
810
|
+
case 1:
|
|
811
|
+
records = _a.sent();
|
|
812
|
+
return [2, records.filter(isNotExplicitlyInactive).map(function (record) { return ({
|
|
813
|
+
label: _.compact([record.name, record.brand, record.version])
|
|
814
|
+
.map(decodePLSDisplayName)
|
|
815
|
+
.join(' · '),
|
|
816
|
+
value: record._id
|
|
817
|
+
}); })];
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}); };
|
|
821
|
+
exports.getActivePLSOptions = getActivePLSOptions;
|
|
822
|
+
var getPLSReviewGroups = function (ctx, materialId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
823
|
+
var material, approval, reviewCandidates, reviews, plsIds, plsFiles, _a, plsById, currentUser, canManage, canAdopt, groups;
|
|
824
|
+
return tslib_1.__generator(this, function (_b) {
|
|
825
|
+
switch (_b.label) {
|
|
826
|
+
case 0: return [4, ctx.getObject('pepsico_material').findOne(materialId)];
|
|
827
|
+
case 1:
|
|
828
|
+
material = _b.sent();
|
|
829
|
+
if (!material) {
|
|
830
|
+
throw new Error('素材不存在');
|
|
831
|
+
}
|
|
832
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(material.pepsico_material_approval)];
|
|
833
|
+
case 2:
|
|
834
|
+
approval = _b.sent();
|
|
835
|
+
return [4, ctx.getObject(PLS_REVIEW_OBJECT).find({
|
|
836
|
+
filters: [
|
|
837
|
+
['pepsico_material', '=', materialId],
|
|
838
|
+
['review_type', '=', 'pls']
|
|
839
|
+
],
|
|
840
|
+
fields: ['_id', 'name', 'rule_category', 'reason', 'rule_content', 'evidence_image', 'evidence_image_file', 'is_adoption', 'pls_file', 'is_active'],
|
|
841
|
+
sort: 'created desc',
|
|
842
|
+
top: 500
|
|
843
|
+
})];
|
|
844
|
+
case 3:
|
|
845
|
+
reviewCandidates = _b.sent();
|
|
846
|
+
reviews = reviewCandidates.filter(isNotExplicitlyInactive);
|
|
847
|
+
plsIds = _.uniq(_.compact(reviews.map(function (review) { return review.pls_file; })));
|
|
848
|
+
if (!(plsIds.length > 0)) return [3, 5];
|
|
849
|
+
return [4, ctx.getObject('pepsico_km_pls_file').directFind({
|
|
850
|
+
filters: [['_id', 'in', plsIds]],
|
|
851
|
+
fields: ['_id', 'name', 'brand', 'version', 'is_active']
|
|
852
|
+
})];
|
|
853
|
+
case 4:
|
|
854
|
+
_a = _b.sent();
|
|
855
|
+
return [3, 6];
|
|
856
|
+
case 5:
|
|
857
|
+
_a = [];
|
|
858
|
+
_b.label = 6;
|
|
859
|
+
case 6:
|
|
860
|
+
plsFiles = _a;
|
|
861
|
+
plsById = _.keyBy(plsFiles, '_id');
|
|
862
|
+
currentUser = ctx.meta && ctx.meta.user;
|
|
863
|
+
canManage = (0, exports.isApprovalReviewer)(approval, currentUser && currentUser.userId);
|
|
864
|
+
canAdopt = (0, exports.canAdoptReview)(approval, currentUser && currentUser.userId, currentUser && currentUser.roles);
|
|
865
|
+
groups = _.map(_.groupBy(reviews, 'pls_file'), function (items, plsFileId) { return ({
|
|
866
|
+
plsFileId: plsFileId,
|
|
867
|
+
plsName: decodePLSDisplayName(plsById[plsFileId] && plsById[plsFileId].name) || 'PLS文件',
|
|
868
|
+
plsActive: isNotExplicitlyInactive(plsById[plsFileId]),
|
|
869
|
+
approvalId: (approval && approval._id) || material.pepsico_material_approval,
|
|
870
|
+
materialId: materialId,
|
|
871
|
+
canManage: canManage,
|
|
872
|
+
canAdopt: canAdopt,
|
|
873
|
+
reviews: items
|
|
874
|
+
}); });
|
|
875
|
+
return [2, {
|
|
876
|
+
groups: groups,
|
|
877
|
+
canManage: canManage,
|
|
878
|
+
canAdopt: canAdopt
|
|
879
|
+
}];
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}); };
|
|
883
|
+
exports.getPLSReviewGroups = getPLSReviewGroups;
|
|
534
884
|
//# sourceMappingURL=pls.js.map
|