@steedos-labs/content-compliance 0.8.32 → 0.8.34
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/index.js +50 -3
- package/lib/index.js.map +1 -1
- package/lib/methods/__tests__/approvalReviewerTrigger.test.js +92 -2
- package/lib/methods/__tests__/approvalReviewerTrigger.test.js.map +1 -1
- package/lib/methods/__tests__/plsDuplicateUpload.test.d.ts +1 -0
- package/lib/methods/__tests__/plsDuplicateUpload.test.js +342 -0
- package/lib/methods/__tests__/plsDuplicateUpload.test.js.map +1 -0
- package/lib/methods/approval_engine.js +3 -1
- package/lib/methods/approval_engine.js.map +1 -1
- package/lib/methods/pls.d.ts +8 -1
- package/lib/methods/pls.js +363 -79
- package/lib/methods/pls.js.map +1 -1
- package/lib/pages/__tests__/plsReviewPage.test.js +22 -5
- package/lib/pages/__tests__/plsReviewPage.test.js.map +1 -1
- package/main/default/objects/pepsico_ai_review/fields/pls_material_content.field.yml +7 -0
- package/main/default/objects/pepsico_ai_review/fields/pls_reason.field.yml +7 -0
- package/main/default/objects/pepsico_ai_review/fields/pls_rule_content.field.yml +7 -0
- package/main/default/objects/pepsico_material/fields/ai_approval_status.field.yml +1 -1
- package/main/default/objects/pepsico_material/listviews/all.listview.yml +1 -0
- package/main/default/objects/pepsico_material_approval/fields/pls_upload_files.field.yml +50 -0
- package/main/default/pages/pepsico_material_detail.page.amis.json +8 -8
- package/main/default/pages/pepsico_material_detail_mobile.page.amis.json +4 -4
- package/main/default/triggers/pepsico_material_approval_change.trigger.yml +32 -3
- package/package.json +1 -1
package/lib/methods/pls.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPLSReviewGroups = exports.getActivePLSOptions = exports.replaceApprovalPLSSource = exports.invalidateApprovalAIReviews = 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 = exports.MAX_PLS_SOURCE_TOTAL = exports.MAX_PLS_SOURCE_PER_MODE = void 0;
|
|
3
|
+
exports.getPLSReviewGroups = exports.getActivePLSOptions = exports.replaceApprovalPLSSource = exports.invalidateApprovalAIReviews = exports.invalidatePLSReviews = exports.getMaterialReviewPermissions = exports.canAdoptReview = exports.isApprovalReviewer = exports.callExtractPLSRulesPriority = exports.callExtractPLSRules = exports.writeSystemLog = exports.logPLSChange = exports.setPLSFileActive = exports.createApplicationPLSFiles = exports.batchCreatePLSFiles = exports.buildDuplicatePLSMessage = exports.isVersionedForm = exports.findDuplicatePLSFilesSafely = exports.findDuplicatePLSFiles = exports.DUPLICATE_PLS_MESSAGE = exports.resetPLSFileAIExtract = exports.backfillPLSFileTitles = exports.scanPLSFiles = exports.MAX_PLS_SOURCE_TOTAL = exports.MAX_PLS_SOURCE_PER_MODE = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var _ = require('lodash');
|
|
6
|
+
var createHash = require('crypto').createHash;
|
|
6
7
|
var axios = require('axios');
|
|
7
8
|
var AI_HOST = process.env.PEPSICO_AI_HOST;
|
|
8
9
|
var AI_API_KEY = process.env.PEPSICO_AI_API_KEY;
|
|
@@ -312,9 +313,279 @@ var resetPLSFileAIExtract = function (ctx) { return tslib_1.__awaiter(void 0, vo
|
|
|
312
313
|
});
|
|
313
314
|
}); };
|
|
314
315
|
exports.resetPLSFileAIExtract = resetPLSFileAIExtract;
|
|
316
|
+
exports.DUPLICATE_PLS_MESSAGE = 'PLS文档已存在,请选择对应PLS知识库中对应pls文件';
|
|
317
|
+
var normalizePLSFileName = function (value) { return String(value || '')
|
|
318
|
+
.replace(/\.pdf$/i, '')
|
|
319
|
+
.replace(/\s+/g, ' ')
|
|
320
|
+
.trim()
|
|
321
|
+
.toLowerCase(); };
|
|
322
|
+
var PLS_CONTENT_MAX_CANDIDATES = 20;
|
|
323
|
+
var PLS_CONTENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
324
|
+
var PLS_CONTENT_READ_TIMEOUT = 10 * 1000;
|
|
325
|
+
var readFileBuffer = function (ctx, fileId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
326
|
+
var broker, timer, data, error_3;
|
|
327
|
+
return tslib_1.__generator(this, function (_a) {
|
|
328
|
+
switch (_a.label) {
|
|
329
|
+
case 0:
|
|
330
|
+
broker = ctx && ctx.broker;
|
|
331
|
+
if (!broker || !_.isFunction(broker.call)) {
|
|
332
|
+
return [2, null];
|
|
333
|
+
}
|
|
334
|
+
timer = null;
|
|
335
|
+
_a.label = 1;
|
|
336
|
+
case 1:
|
|
337
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
338
|
+
return [4, Promise.race([
|
|
339
|
+
broker.call('~packages-@steedos/service-files.getFileById', { fileId: fileId, collectionName: 'files' }),
|
|
340
|
+
new Promise(function (resolve) {
|
|
341
|
+
timer = setTimeout(function () { return resolve(null); }, PLS_CONTENT_READ_TIMEOUT);
|
|
342
|
+
})
|
|
343
|
+
])];
|
|
344
|
+
case 2:
|
|
345
|
+
data = _a.sent();
|
|
346
|
+
return [2, data ? Buffer.from(data) : null];
|
|
347
|
+
case 3:
|
|
348
|
+
error_3 = _a.sent();
|
|
349
|
+
console.error('[pls duplicate] 读取文件失败', fileId, error_3 && error_3.message);
|
|
350
|
+
return [2, null];
|
|
351
|
+
case 4:
|
|
352
|
+
if (timer) {
|
|
353
|
+
clearTimeout(timer);
|
|
354
|
+
}
|
|
355
|
+
return [7];
|
|
356
|
+
case 5: return [2];
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}); };
|
|
360
|
+
var getPLSFileMd5 = function (ctx, fileRecord, cache) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
361
|
+
var fileId, stored, value, size, buffer, md5;
|
|
362
|
+
return tslib_1.__generator(this, function (_a) {
|
|
363
|
+
switch (_a.label) {
|
|
364
|
+
case 0:
|
|
365
|
+
fileId = fileRecord && fileRecord._id;
|
|
366
|
+
if (!fileId) {
|
|
367
|
+
return [2, ''];
|
|
368
|
+
}
|
|
369
|
+
if (cache.has(fileId)) {
|
|
370
|
+
return [2, cache.get(fileId)];
|
|
371
|
+
}
|
|
372
|
+
stored = fileRecord.original && fileRecord.original.md5;
|
|
373
|
+
if (stored) {
|
|
374
|
+
value = String(stored).toLowerCase();
|
|
375
|
+
cache.set(fileId, value);
|
|
376
|
+
return [2, value];
|
|
377
|
+
}
|
|
378
|
+
size = (fileRecord.original && fileRecord.original.size) || 0;
|
|
379
|
+
if (size > PLS_CONTENT_MAX_BYTES) {
|
|
380
|
+
cache.set(fileId, '');
|
|
381
|
+
return [2, ''];
|
|
382
|
+
}
|
|
383
|
+
return [4, readFileBuffer(ctx, fileId)];
|
|
384
|
+
case 1:
|
|
385
|
+
buffer = _a.sent();
|
|
386
|
+
md5 = buffer ? createHash('md5').update(buffer).digest('hex') : '';
|
|
387
|
+
cache.set(fileId, md5);
|
|
388
|
+
return [2, md5];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}); };
|
|
392
|
+
var findDuplicatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
393
|
+
var ids, objFile, objPls, uploadedFiles, plsRecords, candidates, candidateFileIds, candidateFiles, candidateFileById, byName, bySize, candidates_1, candidates_1_1, record, plsFileId, file, names, names_1, names_1_1, name, size, group, md5Cache, duplicates, uploadedFiles_1, uploadedFiles_1_1, uploaded, fileName, nameHit, size, sizeGroup, uploadedMd5, sizeGroup_1, sizeGroup_1_1, item, candidateMd5, e_6_1, e_7_1;
|
|
394
|
+
var e_8, _a, e_9, _b, e_7, _c, e_6, _d;
|
|
395
|
+
return tslib_1.__generator(this, function (_e) {
|
|
396
|
+
switch (_e.label) {
|
|
397
|
+
case 0:
|
|
398
|
+
ids = _.uniq(_.compact(fileIds || []));
|
|
399
|
+
if (ids.length === 0) {
|
|
400
|
+
return [2, []];
|
|
401
|
+
}
|
|
402
|
+
objFile = ctx.getObject('cfs_files_filerecord');
|
|
403
|
+
objPls = ctx.getObject('pepsico_km_pls_file');
|
|
404
|
+
return [4, objFile.directFind({
|
|
405
|
+
filters: [['_id', 'in', ids]],
|
|
406
|
+
fields: ['_id', 'original']
|
|
407
|
+
})];
|
|
408
|
+
case 1:
|
|
409
|
+
uploadedFiles = _e.sent();
|
|
410
|
+
if (!uploadedFiles || uploadedFiles.length === 0) {
|
|
411
|
+
return [2, []];
|
|
412
|
+
}
|
|
413
|
+
return [4, objPls.directFind({
|
|
414
|
+
fields: ['_id', 'name', 'pls_file', 'is_active'],
|
|
415
|
+
top: 10000
|
|
416
|
+
})];
|
|
417
|
+
case 2:
|
|
418
|
+
plsRecords = _e.sent();
|
|
419
|
+
candidates = _.filter(plsRecords || [], function (record) {
|
|
420
|
+
if (!isNotExplicitlyInactive(record)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
var plsFileId = _.isArray(record.pls_file) ? record.pls_file[0] : record.pls_file;
|
|
424
|
+
return !!plsFileId && !_.includes(ids, plsFileId);
|
|
425
|
+
});
|
|
426
|
+
if (candidates.length === 0) {
|
|
427
|
+
return [2, []];
|
|
428
|
+
}
|
|
429
|
+
candidateFileIds = _.uniq(_.compact(_.map(candidates, function (record) { return (_.isArray(record.pls_file) ? record.pls_file[0] : record.pls_file); })));
|
|
430
|
+
return [4, objFile.directFind({
|
|
431
|
+
filters: [['_id', 'in', candidateFileIds]],
|
|
432
|
+
fields: ['_id', 'original']
|
|
433
|
+
})];
|
|
434
|
+
case 3:
|
|
435
|
+
candidateFiles = _e.sent();
|
|
436
|
+
candidateFileById = _.keyBy(candidateFiles || [], '_id');
|
|
437
|
+
byName = new Map();
|
|
438
|
+
bySize = new Map();
|
|
439
|
+
try {
|
|
440
|
+
for (candidates_1 = tslib_1.__values(candidates), candidates_1_1 = candidates_1.next(); !candidates_1_1.done; candidates_1_1 = candidates_1.next()) {
|
|
441
|
+
record = candidates_1_1.value;
|
|
442
|
+
plsFileId = _.isArray(record.pls_file) ? record.pls_file[0] : record.pls_file;
|
|
443
|
+
file = candidateFileById[plsFileId];
|
|
444
|
+
names = _.uniq(_.compact([
|
|
445
|
+
normalizePLSFileName(record.name),
|
|
446
|
+
normalizePLSFileName(file && file.original && file.original.name)
|
|
447
|
+
]));
|
|
448
|
+
try {
|
|
449
|
+
for (names_1 = (e_9 = void 0, tslib_1.__values(names)), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
|
|
450
|
+
name = names_1_1.value;
|
|
451
|
+
if (!byName.has(name)) {
|
|
452
|
+
byName.set(name, record);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
457
|
+
finally {
|
|
458
|
+
try {
|
|
459
|
+
if (names_1_1 && !names_1_1.done && (_b = names_1.return)) _b.call(names_1);
|
|
460
|
+
}
|
|
461
|
+
finally { if (e_9) throw e_9.error; }
|
|
462
|
+
}
|
|
463
|
+
size = (file && file.original && file.original.size) || 0;
|
|
464
|
+
if (size > 0) {
|
|
465
|
+
group = bySize.get(size) || [];
|
|
466
|
+
group.push({ record: record, file: file });
|
|
467
|
+
bySize.set(size, group);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
472
|
+
finally {
|
|
473
|
+
try {
|
|
474
|
+
if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
|
|
475
|
+
}
|
|
476
|
+
finally { if (e_8) throw e_8.error; }
|
|
477
|
+
}
|
|
478
|
+
md5Cache = new Map();
|
|
479
|
+
duplicates = [];
|
|
480
|
+
_e.label = 4;
|
|
481
|
+
case 4:
|
|
482
|
+
_e.trys.push([4, 16, 17, 18]);
|
|
483
|
+
uploadedFiles_1 = tslib_1.__values(uploadedFiles), uploadedFiles_1_1 = uploadedFiles_1.next();
|
|
484
|
+
_e.label = 5;
|
|
485
|
+
case 5:
|
|
486
|
+
if (!!uploadedFiles_1_1.done) return [3, 15];
|
|
487
|
+
uploaded = uploadedFiles_1_1.value;
|
|
488
|
+
fileName = (uploaded.original && uploaded.original.name) || '';
|
|
489
|
+
nameHit = byName.get(normalizePLSFileName(fileName));
|
|
490
|
+
if (nameHit) {
|
|
491
|
+
duplicates.push({ fileId: uploaded._id, fileName: fileName, reason: 'name', matchedId: nameHit._id, matchedName: nameHit.name });
|
|
492
|
+
return [3, 14];
|
|
493
|
+
}
|
|
494
|
+
size = (uploaded.original && uploaded.original.size) || 0;
|
|
495
|
+
sizeGroup = size > 0 ? (bySize.get(size) || []) : [];
|
|
496
|
+
if (sizeGroup.length === 0 || sizeGroup.length > PLS_CONTENT_MAX_CANDIDATES) {
|
|
497
|
+
return [3, 14];
|
|
498
|
+
}
|
|
499
|
+
return [4, getPLSFileMd5(ctx, uploaded, md5Cache)];
|
|
500
|
+
case 6:
|
|
501
|
+
uploadedMd5 = _e.sent();
|
|
502
|
+
if (!uploadedMd5) {
|
|
503
|
+
return [3, 14];
|
|
504
|
+
}
|
|
505
|
+
_e.label = 7;
|
|
506
|
+
case 7:
|
|
507
|
+
_e.trys.push([7, 12, 13, 14]);
|
|
508
|
+
sizeGroup_1 = (e_6 = void 0, tslib_1.__values(sizeGroup)), sizeGroup_1_1 = sizeGroup_1.next();
|
|
509
|
+
_e.label = 8;
|
|
510
|
+
case 8:
|
|
511
|
+
if (!!sizeGroup_1_1.done) return [3, 11];
|
|
512
|
+
item = sizeGroup_1_1.value;
|
|
513
|
+
return [4, getPLSFileMd5(ctx, item.file, md5Cache)];
|
|
514
|
+
case 9:
|
|
515
|
+
candidateMd5 = _e.sent();
|
|
516
|
+
if (candidateMd5 && candidateMd5 === uploadedMd5) {
|
|
517
|
+
duplicates.push({ fileId: uploaded._id, fileName: fileName, reason: 'content', matchedId: item.record._id, matchedName: item.record.name });
|
|
518
|
+
return [3, 11];
|
|
519
|
+
}
|
|
520
|
+
_e.label = 10;
|
|
521
|
+
case 10:
|
|
522
|
+
sizeGroup_1_1 = sizeGroup_1.next();
|
|
523
|
+
return [3, 8];
|
|
524
|
+
case 11: return [3, 14];
|
|
525
|
+
case 12:
|
|
526
|
+
e_6_1 = _e.sent();
|
|
527
|
+
e_6 = { error: e_6_1 };
|
|
528
|
+
return [3, 14];
|
|
529
|
+
case 13:
|
|
530
|
+
try {
|
|
531
|
+
if (sizeGroup_1_1 && !sizeGroup_1_1.done && (_d = sizeGroup_1.return)) _d.call(sizeGroup_1);
|
|
532
|
+
}
|
|
533
|
+
finally { if (e_6) throw e_6.error; }
|
|
534
|
+
return [7];
|
|
535
|
+
case 14:
|
|
536
|
+
uploadedFiles_1_1 = uploadedFiles_1.next();
|
|
537
|
+
return [3, 5];
|
|
538
|
+
case 15: return [3, 18];
|
|
539
|
+
case 16:
|
|
540
|
+
e_7_1 = _e.sent();
|
|
541
|
+
e_7 = { error: e_7_1 };
|
|
542
|
+
return [3, 18];
|
|
543
|
+
case 17:
|
|
544
|
+
try {
|
|
545
|
+
if (uploadedFiles_1_1 && !uploadedFiles_1_1.done && (_c = uploadedFiles_1.return)) _c.call(uploadedFiles_1);
|
|
546
|
+
}
|
|
547
|
+
finally { if (e_7) throw e_7.error; }
|
|
548
|
+
return [7];
|
|
549
|
+
case 18: return [2, duplicates];
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}); };
|
|
553
|
+
exports.findDuplicatePLSFiles = findDuplicatePLSFiles;
|
|
554
|
+
var findDuplicatePLSFilesSafely = function (ctx, fileIds) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
555
|
+
var error_4;
|
|
556
|
+
return tslib_1.__generator(this, function (_a) {
|
|
557
|
+
switch (_a.label) {
|
|
558
|
+
case 0:
|
|
559
|
+
_a.trys.push([0, 2, , 5]);
|
|
560
|
+
return [4, (0, exports.findDuplicatePLSFiles)(ctx, fileIds)];
|
|
561
|
+
case 1: return [2, _a.sent()];
|
|
562
|
+
case 2:
|
|
563
|
+
error_4 = _a.sent();
|
|
564
|
+
console.error('[pls duplicate] 查重失败, 本次放行', error_4 && error_4.message);
|
|
565
|
+
if (!(ctx && ctx.logger && _.isFunction(ctx.logger.warn))) return [3, 4];
|
|
566
|
+
return [4, ctx.logger.warn("[PLS\u67E5\u91CD\u5931\u8D25, \u672C\u6B21\u653E\u884C]: ".concat(error_4 && error_4.message), {
|
|
567
|
+
objectName: 'pepsico_km_pls_file',
|
|
568
|
+
file_ids: fileIds
|
|
569
|
+
})];
|
|
570
|
+
case 3:
|
|
571
|
+
_a.sent();
|
|
572
|
+
_a.label = 4;
|
|
573
|
+
case 4: return [2, []];
|
|
574
|
+
case 5: return [2];
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}); };
|
|
578
|
+
exports.findDuplicatePLSFilesSafely = findDuplicatePLSFilesSafely;
|
|
579
|
+
var isVersionedForm = function (approval) { return !!_.trim(approval && approval.form_version); };
|
|
580
|
+
exports.isVersionedForm = isVersionedForm;
|
|
581
|
+
var buildDuplicatePLSMessage = function (duplicates) {
|
|
582
|
+
var names = _.uniq(_.compact(_.map(duplicates || [], 'fileName')));
|
|
583
|
+
return "".concat(names.map(function (name) { return "\u300C".concat(name, "\u300D"); }).join('')).concat(exports.DUPLICATE_PLS_MESSAGE);
|
|
584
|
+
};
|
|
585
|
+
exports.buildDuplicatePLSMessage = buildDuplicatePLSMessage;
|
|
315
586
|
var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
316
|
-
var user, space, ids, objFile, objPls, existingRecords, existingByFile, records, skipped, ids_1, ids_1_1, fileId, reused, files, fileRecord, fileName, fileType, isPdf, now, record,
|
|
317
|
-
var
|
|
587
|
+
var user, space, ids, objFile, objPls, existingRecords, existingByFile, records, skipped, ids_1, ids_1_1, fileId, reused, files, fileRecord, fileName, fileType, isPdf, now, record, e_10_1, created;
|
|
588
|
+
var e_10, _a;
|
|
318
589
|
return tslib_1.__generator(this, function (_b) {
|
|
319
590
|
switch (_b.label) {
|
|
320
591
|
case 0:
|
|
@@ -383,14 +654,14 @@ var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(voi
|
|
|
383
654
|
return [3, 3];
|
|
384
655
|
case 7: return [3, 10];
|
|
385
656
|
case 8:
|
|
386
|
-
|
|
387
|
-
|
|
657
|
+
e_10_1 = _b.sent();
|
|
658
|
+
e_10 = { error: e_10_1 };
|
|
388
659
|
return [3, 10];
|
|
389
660
|
case 9:
|
|
390
661
|
try {
|
|
391
662
|
if (ids_1_1 && !ids_1_1.done && (_a = ids_1.return)) _a.call(ids_1);
|
|
392
663
|
}
|
|
393
|
-
finally { if (
|
|
664
|
+
finally { if (e_10) throw e_10.error; }
|
|
394
665
|
return [7];
|
|
395
666
|
case 10:
|
|
396
667
|
created = records.filter(function (record) { return record.isNew; }).length;
|
|
@@ -399,59 +670,72 @@ var batchCreatePLSFiles = function (ctx, fileIds) { return tslib_1.__awaiter(voi
|
|
|
399
670
|
});
|
|
400
671
|
}); };
|
|
401
672
|
exports.batchCreatePLSFiles = batchCreatePLSFiles;
|
|
402
|
-
var createApplicationPLSFiles = function (ctx, fileIds, approval, materialId
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
673
|
+
var createApplicationPLSFiles = function (ctx, fileIds, approval, materialId, options) {
|
|
674
|
+
if (options === void 0) { options = {}; }
|
|
675
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
676
|
+
var _a, checkDuplicate, duplicates, result, _b, _c, record, doc, e_11_1;
|
|
677
|
+
var e_11, _d;
|
|
678
|
+
return tslib_1.__generator(this, function (_e) {
|
|
679
|
+
switch (_e.label) {
|
|
680
|
+
case 0:
|
|
681
|
+
_a = options.checkDuplicate, checkDuplicate = _a === void 0 ? true : _a;
|
|
682
|
+
if (!(checkDuplicate && (!approval || (0, exports.isVersionedForm)(approval)))) return [3, 2];
|
|
683
|
+
return [4, (0, exports.findDuplicatePLSFilesSafely)(ctx, fileIds)];
|
|
684
|
+
case 1:
|
|
685
|
+
duplicates = _e.sent();
|
|
686
|
+
if (duplicates.length > 0) {
|
|
687
|
+
throw new Error((0, exports.buildDuplicatePLSMessage)(duplicates));
|
|
688
|
+
}
|
|
689
|
+
_e.label = 2;
|
|
690
|
+
case 2: return [4, (0, exports.batchCreatePLSFiles)(ctx, fileIds)];
|
|
691
|
+
case 3:
|
|
692
|
+
result = _e.sent();
|
|
693
|
+
_e.label = 4;
|
|
694
|
+
case 4:
|
|
695
|
+
_e.trys.push([4, 10, 11, 12]);
|
|
696
|
+
_b = tslib_1.__values(result.records), _c = _b.next();
|
|
697
|
+
_e.label = 5;
|
|
698
|
+
case 5:
|
|
699
|
+
if (!!_c.done) return [3, 9];
|
|
700
|
+
record = _c.value;
|
|
701
|
+
doc = {};
|
|
702
|
+
if (approval) {
|
|
703
|
+
doc.pepsico_material_approval = approval._id;
|
|
704
|
+
}
|
|
705
|
+
if (materialId) {
|
|
706
|
+
doc.pepsico_material = materialId;
|
|
707
|
+
}
|
|
708
|
+
if (!!_.isEmpty(doc)) return [3, 7];
|
|
709
|
+
doc.modified = new Date();
|
|
710
|
+
return [4, ctx.getObject('pepsico_km_pls_file').directUpdate(record.id, doc)];
|
|
711
|
+
case 6:
|
|
712
|
+
_e.sent();
|
|
713
|
+
_e.label = 7;
|
|
714
|
+
case 7:
|
|
715
|
+
if (record.isNew === false) {
|
|
716
|
+
return [3, 8];
|
|
717
|
+
}
|
|
718
|
+
(0, exports.callExtractPLSRulesPriority)(ctx, record.id).catch(function () { });
|
|
719
|
+
_e.label = 8;
|
|
720
|
+
case 8:
|
|
721
|
+
_c = _b.next();
|
|
722
|
+
return [3, 5];
|
|
723
|
+
case 9: return [3, 12];
|
|
724
|
+
case 10:
|
|
725
|
+
e_11_1 = _e.sent();
|
|
726
|
+
e_11 = { error: e_11_1 };
|
|
727
|
+
return [3, 12];
|
|
728
|
+
case 11:
|
|
729
|
+
try {
|
|
730
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
731
|
+
}
|
|
732
|
+
finally { if (e_11) throw e_11.error; }
|
|
733
|
+
return [7];
|
|
734
|
+
case 12: return [2, result];
|
|
735
|
+
}
|
|
736
|
+
});
|
|
453
737
|
});
|
|
454
|
-
}
|
|
738
|
+
};
|
|
455
739
|
exports.createApplicationPLSFiles = createApplicationPLSFiles;
|
|
456
740
|
var setPLSFileActive = function (ctx, fileId, active) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
457
741
|
var now, objPls, objRule, rules;
|
|
@@ -486,7 +770,7 @@ exports.setPLSFileActive = setPLSFileActive;
|
|
|
486
770
|
var logPLSChange = function (ctx, _a) {
|
|
487
771
|
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;
|
|
488
772
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
489
|
-
var beforeList, afterList, allIds, files, nameById_1, toNames,
|
|
773
|
+
var beforeList, afterList, allIds, files, nameById_1, toNames, e_12;
|
|
490
774
|
return tslib_1.__generator(this, function (_f) {
|
|
491
775
|
switch (_f.label) {
|
|
492
776
|
case 0:
|
|
@@ -524,10 +808,10 @@ var logPLSChange = function (ctx, _a) {
|
|
|
524
808
|
_f.sent();
|
|
525
809
|
return [3, 6];
|
|
526
810
|
case 3:
|
|
527
|
-
|
|
528
|
-
console.error('[写PLS变更日志失败]',
|
|
811
|
+
e_12 = _f.sent();
|
|
812
|
+
console.error('[写PLS变更日志失败]', e_12 && e_12.message);
|
|
529
813
|
if (!ctx.logger) return [3, 5];
|
|
530
|
-
return [4, ctx.logger.error('[写PLS变更日志失败]',
|
|
814
|
+
return [4, ctx.logger.error('[写PLS变更日志失败]', e_12 && e_12.message)];
|
|
531
815
|
case 4:
|
|
532
816
|
_f.sent();
|
|
533
817
|
_f.label = 5;
|
|
@@ -572,7 +856,7 @@ var getLogSpace = function (ctx, user) { return tslib_1.__awaiter(void 0, void 0
|
|
|
572
856
|
var writeSystemLog = function (ctx, level, data, name) {
|
|
573
857
|
if (name === void 0) { name = 'PLS规则提取'; }
|
|
574
858
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
575
|
-
var _a, _b,
|
|
859
|
+
var _a, _b, e_13;
|
|
576
860
|
var _c;
|
|
577
861
|
return tslib_1.__generator(this, function (_d) {
|
|
578
862
|
switch (_d.label) {
|
|
@@ -592,8 +876,8 @@ var writeSystemLog = function (ctx, level, data, name) {
|
|
|
592
876
|
_d.sent();
|
|
593
877
|
return [3, 4];
|
|
594
878
|
case 3:
|
|
595
|
-
|
|
596
|
-
console.error('[写系统日志失败]',
|
|
879
|
+
e_13 = _d.sent();
|
|
880
|
+
console.error('[写系统日志失败]', e_13 && e_13.message);
|
|
597
881
|
return [3, 4];
|
|
598
882
|
case 4: return [2];
|
|
599
883
|
}
|
|
@@ -602,7 +886,7 @@ var writeSystemLog = function (ctx, level, data, name) {
|
|
|
602
886
|
};
|
|
603
887
|
exports.writeSystemLog = writeSystemLog;
|
|
604
888
|
var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
605
|
-
var userId, start, result, data, cost,
|
|
889
|
+
var userId, start, result, data, cost, e_14, error_5, cost;
|
|
606
890
|
return tslib_1.__generator(this, function (_a) {
|
|
607
891
|
switch (_a.label) {
|
|
608
892
|
case 0:
|
|
@@ -641,8 +925,8 @@ var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void
|
|
|
641
925
|
_a.sent();
|
|
642
926
|
return [3, 7];
|
|
643
927
|
case 6:
|
|
644
|
-
|
|
645
|
-
console.error("[\u8C03\u7528 execute-pls API] \u6807\u8BB0 extracting \u5931\u8D25-".concat(fileId),
|
|
928
|
+
e_14 = _a.sent();
|
|
929
|
+
console.error("[\u8C03\u7528 execute-pls API] \u6807\u8BB0 extracting \u5931\u8D25-".concat(fileId), e_14 && e_14.message);
|
|
646
930
|
return [3, 7];
|
|
647
931
|
case 7: return [4, (0, exports.writeSystemLog)(ctx, 'info', {
|
|
648
932
|
action: 'execute-pls',
|
|
@@ -657,10 +941,10 @@ var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void
|
|
|
657
941
|
_a.sent();
|
|
658
942
|
return [2, data];
|
|
659
943
|
case 9:
|
|
660
|
-
|
|
944
|
+
error_5 = _a.sent();
|
|
661
945
|
cost = new Date().getTime() - start;
|
|
662
|
-
console.error("[\u8C03\u7528 execute-pls API]-".concat(fileId),
|
|
663
|
-
return [4, ctx.logger.error("[\u8C03\u7528 execute-pls API]-".concat(fileId),
|
|
946
|
+
console.error("[\u8C03\u7528 execute-pls API]-".concat(fileId), error_5 && error_5.message, new Date());
|
|
947
|
+
return [4, ctx.logger.error("[\u8C03\u7528 execute-pls API]-".concat(fileId), error_5 && error_5.message)];
|
|
664
948
|
case 10:
|
|
665
949
|
_a.sent();
|
|
666
950
|
return [4, (0, exports.writeSystemLog)(ctx, 'error', {
|
|
@@ -670,18 +954,18 @@ var callExtractPLSRules = function (ctx, fileId) { return tslib_1.__awaiter(void
|
|
|
670
954
|
url: "".concat(AI_HOST, "/execute-pls"),
|
|
671
955
|
status: 'fail',
|
|
672
956
|
cost: cost,
|
|
673
|
-
error:
|
|
957
|
+
error: error_5 && error_5.message
|
|
674
958
|
})];
|
|
675
959
|
case 11:
|
|
676
960
|
_a.sent();
|
|
677
|
-
throw
|
|
961
|
+
throw error_5;
|
|
678
962
|
case 12: return [2];
|
|
679
963
|
}
|
|
680
964
|
});
|
|
681
965
|
}); };
|
|
682
966
|
exports.callExtractPLSRules = callExtractPLSRules;
|
|
683
967
|
var callExtractPLSRulesPriority = function (ctx, fileId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
684
|
-
var userId, start, url, result, data, cost,
|
|
968
|
+
var userId, start, url, result, data, cost, error_6, cost;
|
|
685
969
|
return tslib_1.__generator(this, function (_a) {
|
|
686
970
|
switch (_a.label) {
|
|
687
971
|
case 0:
|
|
@@ -717,9 +1001,9 @@ var callExtractPLSRulesPriority = function (ctx, fileId) { return tslib_1.__awai
|
|
|
717
1001
|
_a.sent();
|
|
718
1002
|
return [2, data];
|
|
719
1003
|
case 5:
|
|
720
|
-
|
|
1004
|
+
error_6 = _a.sent();
|
|
721
1005
|
cost = new Date().getTime() - start;
|
|
722
|
-
return [4, ctx.logger.error("[\u8C03\u7528 PLS\u4F18\u5148\u63D0\u53D6\u89C4\u5219 API]-".concat(fileId),
|
|
1006
|
+
return [4, ctx.logger.error("[\u8C03\u7528 PLS\u4F18\u5148\u63D0\u53D6\u89C4\u5219 API]-".concat(fileId), error_6 && error_6.message)];
|
|
723
1007
|
case 6:
|
|
724
1008
|
_a.sent();
|
|
725
1009
|
return [4, (0, exports.writeSystemLog)(ctx, 'error', {
|
|
@@ -729,11 +1013,11 @@ var callExtractPLSRulesPriority = function (ctx, fileId) { return tslib_1.__awai
|
|
|
729
1013
|
url: url,
|
|
730
1014
|
status: 'fail',
|
|
731
1015
|
cost: cost,
|
|
732
|
-
error:
|
|
1016
|
+
error: error_6 && error_6.message
|
|
733
1017
|
})];
|
|
734
1018
|
case 7:
|
|
735
1019
|
_a.sent();
|
|
736
|
-
throw
|
|
1020
|
+
throw error_6;
|
|
737
1021
|
case 8: return [2];
|
|
738
1022
|
}
|
|
739
1023
|
});
|
|
@@ -974,7 +1258,7 @@ var getPLSReviewGroups = function (ctx, materialId) { return tslib_1.__awaiter(v
|
|
|
974
1258
|
['pepsico_material', '=', materialId],
|
|
975
1259
|
['review_type', '=', 'pls']
|
|
976
1260
|
],
|
|
977
|
-
fields: ['_id', '
|
|
1261
|
+
fields: ['_id', 'pls_reason', 'pls_material_content', 'pls_rule_content', 'evidence_image', 'evidence_image_file', 'is_adoption', 'pls_file', 'is_active'],
|
|
978
1262
|
sort: 'created desc',
|
|
979
1263
|
top: 500
|
|
980
1264
|
})];
|