@steedos-labs/content-compliance-bev 0.2.4 → 0.2.5
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/README.md +33 -0
- package/dist/index.js +1 -1
- package/lib/actions/spotCheckMaterial.d.ts +36 -3
- package/lib/actions/spotCheckMaterial.js +244 -158
- package/lib/actions/spotCheckMaterial.js.map +1 -1
- package/main/default/objects/pepsico_spot_check_pool/buttons/remind_spot_check_incomplete.button.yml +55 -0
- package/main/default/objects/pepsico_spot_check_pool/buttons/send_mail.button.yml +17 -1
- package/main/default/objects/pepsico_spot_check_report/buttons/send_mail.button.yml +17 -1
- package/package.json +1 -1
|
@@ -428,7 +428,7 @@ exports.sendMonthlySpotCheckReport = {
|
|
|
428
428
|
},
|
|
429
429
|
handler: function (ctx) {
|
|
430
430
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
431
|
-
var user, rid, logger, report, yearMonth, data, _a, monthStart, monthEnd, brandList, brandLeaderList, _loop_1, brandLeaderList_1, brandLeaderList_1_1, brandLeader, e_3_1;
|
|
431
|
+
var user, rid, logger, report, yearMonth, data, _a, monthStart, monthEnd, brandList, brandLeaderList, results, skipped, _loop_1, brandLeaderList_1, brandLeaderList_1_1, brandLeader, e_3_1;
|
|
432
432
|
var e_3, _b;
|
|
433
433
|
return tslib_1.__generator(this, function (_c) {
|
|
434
434
|
switch (_c.label) {
|
|
@@ -462,6 +462,8 @@ exports.sendMonthlySpotCheckReport = {
|
|
|
462
462
|
return [4, ctx.getObject('pepsico_brand_leader').directFind({ filters: [] })];
|
|
463
463
|
case 3:
|
|
464
464
|
brandLeaderList = _c.sent();
|
|
465
|
+
results = [];
|
|
466
|
+
skipped = [];
|
|
465
467
|
_loop_1 = function (brandLeader) {
|
|
466
468
|
var list, subject, brand, lid, html, toUsers, toUsersAll, error_3, ccUsers, ccUsersAll, error_4, result;
|
|
467
469
|
return tslib_1.__generator(this, function (_d) {
|
|
@@ -474,46 +476,65 @@ exports.sendMonthlySpotCheckReport = {
|
|
|
474
476
|
console.log('sendMonthlySpotCheckReport find', brandLeader.name, list.length, JSON.stringify({
|
|
475
477
|
filters: [['spot_checked_done', '=', true], ['product', '=', brandLeader.name], ['classification', '=', brandLeader.classification], ['spot_checked_done_time', '>=', monthStart], ['spot_checked_done_time', '<=', monthEnd]]
|
|
476
478
|
}));
|
|
477
|
-
if (!(list.length > 0)) return [3,
|
|
479
|
+
if (!(list.length > 0)) return [3, 14];
|
|
478
480
|
subject = "\u3010\u7CFB\u7EDF\u901A\u77E5\u3011".concat(brandLeader.remark, "\u6708\u5EA6\u62BD\u67E5\u62A5\u544A[").concat(yearMonth, "]");
|
|
479
481
|
brand = (0, lodash_1.find)(brandList, function (item) { return item.value === brandLeader.name; });
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
+
if (!!brand) return [3, 2];
|
|
483
|
+
skipped.push({
|
|
484
|
+
product: brandLeader.name,
|
|
485
|
+
classification: brandLeader.classification,
|
|
486
|
+
count: list.length,
|
|
487
|
+
reason: '未找到品牌映射'
|
|
488
|
+
});
|
|
489
|
+
console.log('sendMonthlySpotCheckReport skip unknown brand', brandLeader.name, brandLeader.classification);
|
|
490
|
+
return [3, 14];
|
|
482
491
|
case 2:
|
|
492
|
+
if (!brandLeader) return [3, 14];
|
|
493
|
+
return [4, ctx.getObject('pepsico_mail_send_log')._makeNewID()];
|
|
494
|
+
case 3:
|
|
483
495
|
lid = _d.sent();
|
|
484
496
|
html = "\n <p>\u4EB2\u7231\u7684\u7528\u6237\uFF0C</p>\n <p>\u672C\u6708".concat(brand.label, "\u62BD\u67E5\u7D20\u6750\u62A5\u544A\u5DF2\u751F\u6210\u3002 \u8BF7\u70B9\u51FB\u4E0B\u9762\u94FE\u63A5\u67E5\u770B").concat(brand.label, "\u6708\u5EA6\u62BD\u67E5\u62A5\u544A\uFF0C\u5EFA\u8BAE\u5206\u4EAB\u7ED9\u56E2\u961F\u6210\u5458\u8FDB\u884C\u5B66\u4E60\u3002</p>\n <a href=\"").concat(process.env.ROOT_URL, "/api/pepsico-content/material/click/spot-report/").concat(rid, "/").concat(lid, "\">").concat(brandLeader.remark, "\uFF1A").concat(yearMonth, "</a>\n <p>\u6709\u4EFB\u4F55\u7591\u95EE\uFF0C\u8BF7\u8054\u7CFB\u7CFB\u7EDF\u7BA1\u7406\u5458\u3002</p>\n <p>\u8C22\u8C22\uFF01</p>\n ");
|
|
485
497
|
toUsers = [];
|
|
486
|
-
if (!brandLeader.to) return [3,
|
|
487
|
-
_d.label =
|
|
488
|
-
case 3:
|
|
489
|
-
_d.trys.push([3, 5, , 6]);
|
|
490
|
-
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', brandLeader.to] })];
|
|
498
|
+
if (!brandLeader.to) return [3, 7];
|
|
499
|
+
_d.label = 4;
|
|
491
500
|
case 4:
|
|
501
|
+
_d.trys.push([4, 6, , 7]);
|
|
502
|
+
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', brandLeader.to] })];
|
|
503
|
+
case 5:
|
|
492
504
|
toUsersAll = _d.sent();
|
|
493
505
|
toUsers = toUsersAll.filter(function (u) { return u.email && u.email.endsWith('@pepsico.com'); });
|
|
494
|
-
return [3,
|
|
495
|
-
case
|
|
506
|
+
return [3, 7];
|
|
507
|
+
case 6:
|
|
496
508
|
error_3 = _d.sent();
|
|
497
509
|
console.log(error_3);
|
|
498
|
-
return [3,
|
|
499
|
-
case 6:
|
|
500
|
-
ccUsers = [];
|
|
501
|
-
if (!brandLeader.cc) return [3, 10];
|
|
502
|
-
_d.label = 7;
|
|
510
|
+
return [3, 7];
|
|
503
511
|
case 7:
|
|
504
|
-
|
|
505
|
-
|
|
512
|
+
ccUsers = [];
|
|
513
|
+
if (!brandLeader.cc) return [3, 11];
|
|
514
|
+
_d.label = 8;
|
|
506
515
|
case 8:
|
|
516
|
+
_d.trys.push([8, 10, , 11]);
|
|
517
|
+
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', brandLeader.cc] })];
|
|
518
|
+
case 9:
|
|
507
519
|
ccUsersAll = _d.sent();
|
|
508
520
|
ccUsers = ccUsersAll.filter(function (u) { return u.email && u.email.endsWith('@pepsico.com'); });
|
|
509
|
-
return [3,
|
|
510
|
-
case
|
|
521
|
+
return [3, 11];
|
|
522
|
+
case 10:
|
|
511
523
|
error_4 = _d.sent();
|
|
512
524
|
console.log(error_4);
|
|
513
|
-
return [3,
|
|
514
|
-
case
|
|
515
|
-
case
|
|
525
|
+
return [3, 11];
|
|
526
|
+
case 11: return [4, sendEmail(process.env.B6_EMAIL_FROM, (0, lodash_1.join)((0, lodash_1.map)(toUsers, 'email'), ';'), subject, '', html, (0, lodash_1.join)((0, lodash_1.map)(ccUsers, 'email'), ';'))];
|
|
527
|
+
case 12:
|
|
516
528
|
result = _d.sent();
|
|
529
|
+
results.push({
|
|
530
|
+
product: brand.value,
|
|
531
|
+
product_label: brand.label,
|
|
532
|
+
classification: brandLeader.classification,
|
|
533
|
+
count: list.length,
|
|
534
|
+
to: (0, lodash_1.map)(toUsers, 'email'),
|
|
535
|
+
cc: (0, lodash_1.map)(ccUsers, 'email'),
|
|
536
|
+
result: result
|
|
537
|
+
});
|
|
517
538
|
return [4, ctx.getObject('pepsico_mail_send_log').insert({
|
|
518
539
|
_id: lid,
|
|
519
540
|
name: subject,
|
|
@@ -528,10 +549,10 @@ exports.sendMonthlySpotCheckReport = {
|
|
|
528
549
|
result: result,
|
|
529
550
|
space: report.space
|
|
530
551
|
}, user)];
|
|
531
|
-
case
|
|
552
|
+
case 13:
|
|
532
553
|
_d.sent();
|
|
533
|
-
_d.label =
|
|
534
|
-
case
|
|
554
|
+
_d.label = 14;
|
|
555
|
+
case 14: return [2];
|
|
535
556
|
}
|
|
536
557
|
});
|
|
537
558
|
};
|
|
@@ -567,7 +588,18 @@ exports.sendMonthlySpotCheckReport = {
|
|
|
567
588
|
})];
|
|
568
589
|
case 12:
|
|
569
590
|
_c.sent();
|
|
570
|
-
return [2
|
|
591
|
+
return [2, {
|
|
592
|
+
status: 200,
|
|
593
|
+
msg: '月度抽查报告邮件发送完成',
|
|
594
|
+
data: {
|
|
595
|
+
year_month: yearMonth,
|
|
596
|
+
brand_leader_count: brandLeaderList.length,
|
|
597
|
+
sent_count: results.length,
|
|
598
|
+
skipped_count: skipped.length,
|
|
599
|
+
results: results,
|
|
600
|
+
skipped: skipped
|
|
601
|
+
}
|
|
602
|
+
}];
|
|
571
603
|
}
|
|
572
604
|
});
|
|
573
605
|
});
|
|
@@ -858,7 +890,7 @@ exports.generateSpotCheckPool = {
|
|
|
858
890
|
},
|
|
859
891
|
handler: function (ctx) {
|
|
860
892
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
861
|
-
var user, pid, logger, pool, yearMonth, pools, logs, departmentUserIds_2, _a, _b, material, approval, _c, _d, field, users, e_5_1, specialistUserIds_2, _e, _f, material, approval, sUsers, e_6_1, ROOT_URL, subject, midTierLink, midTierHtml, departmentToUsers, toUsersAll, error_6, midTierResult, _g, microLink, microHtml, specialistToUsers, toUsersAll, error_7, microResult, _h, departmentUserIds_1, departmentUserIds_1_1, userId, e_7_1, specialistUserIds_1, specialistUserIds_1_1, userId, e_8_1, error_8, error_9;
|
|
893
|
+
var user, pid, logger, pool, yearMonth, pools, logs, logs_1, departmentUserIds_2, _a, _b, material, approval, _c, _d, field, users, e_5_1, specialistUserIds_2, _e, _f, material, approval, sUsers, e_6_1, ROOT_URL, subject, midTierLink, midTierHtml, departmentToUsers, toUsersAll, error_6, midTierResult, _g, microLink, microHtml, specialistToUsers, toUsersAll, error_7, microResult, _h, fromUserId, departmentUserIds_1, departmentUserIds_1_1, userId, e_7_1, specialistUserIds_1, specialistUserIds_1_1, userId, e_8_1, error_8, error_9, message, updateError_1;
|
|
862
894
|
var e_5, _j, e_9, _k, e_6, _l, e_7, _m, e_8, _o;
|
|
863
895
|
return tslib_1.__generator(this, function (_p) {
|
|
864
896
|
switch (_p.label) {
|
|
@@ -882,7 +914,7 @@ exports.generateSpotCheckPool = {
|
|
|
882
914
|
yearMonth = pool.year_month;
|
|
883
915
|
_p.label = 3;
|
|
884
916
|
case 3:
|
|
885
|
-
_p.trys.push([3,
|
|
917
|
+
_p.trys.push([3, 58, , 63]);
|
|
886
918
|
return [4, getSpotCheckPool(yearMonth)];
|
|
887
919
|
case 4:
|
|
888
920
|
pools = _p.sent();
|
|
@@ -893,22 +925,38 @@ exports.generateSpotCheckPool = {
|
|
|
893
925
|
console.log("\u603B\u62BD\u6837\u6570: ".concat(pools['Micro'].samplingPool.length), (0, lodash_1.map)(pools['Micro'].samplingPool, function (item) { return (0, lodash_1.pick)(item, ['_id', 'product']); }));
|
|
894
926
|
console.log('品牌统计:', pools['Micro'].statistics.byBrand);
|
|
895
927
|
logs = "\n [".concat(yearMonth, "] \u627E\u5230 ").concat(pools.count, " \u4E2A\u5BA1\u6279\u5B8C\u6210\u7684\u7D20\u6750 \r\n\n === \u8170\u90E8(Mid-tier)\u62BD\u67E5\u6C60\u5B50 === \r\n\n \u603B\u62BD\u6837\u6570: ").concat(pools['Mid-tier'].samplingPool.length, ", ").concat(JSON.stringify((0, lodash_1.map)(pools['Mid-tier'].samplingPool, function (item) { return (0, lodash_1.pick)(item, ['_id', 'product']); })), " \r\n\n \u54C1\u724C\u7EDF\u8BA1:, ").concat(JSON.stringify(pools['Mid-tier'].statistics.byBrand), " \r\n\n \n=== \u5C3E\u90E8(Micro)\u62BD\u67E5\u6C60\u5B50 ===' \r\n\n \u603B\u62BD\u6837\u6570: ").concat(pools['Micro'].samplingPool.length, ", ").concat(JSON.stringify((0, lodash_1.map)(pools['Micro'].samplingPool, function (item) { return (0, lodash_1.pick)(item, ['_id', 'product']); })), " \r\n\n \u54C1\u724C\u7EDF\u8BA1:, ").concat(JSON.stringify(pools['Micro'].statistics.byBrand), " \r\n\n ");
|
|
896
|
-
if (pools.count < 1)
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
928
|
+
if (!(pools.count < 1)) return [3, 6];
|
|
929
|
+
logs_1 = "[".concat(yearMonth, "] \u627E\u5230 0 \u4E2A\u5BA1\u6279\u5B8C\u6210\u7684\u7D20\u6750\uFF0C\u672A\u53D1\u9001\u90AE\u4EF6\u3002");
|
|
930
|
+
console.log('无可抽查素材. 不发送邮件.');
|
|
931
|
+
return [4, ctx.getObject('pepsico_spot_check_pool').directUpdate(pid, {
|
|
932
|
+
logs: logs_1
|
|
933
|
+
})];
|
|
902
934
|
case 5:
|
|
903
|
-
_p.
|
|
904
|
-
|
|
905
|
-
|
|
935
|
+
_p.sent();
|
|
936
|
+
return [2, {
|
|
937
|
+
status: 200,
|
|
938
|
+
msg: '无可抽查素材,未发送邮件',
|
|
939
|
+
data: {
|
|
940
|
+
year_month: yearMonth,
|
|
941
|
+
count: pools.count
|
|
942
|
+
}
|
|
943
|
+
}];
|
|
906
944
|
case 6:
|
|
907
|
-
|
|
945
|
+
departmentUserIds_2 = new Set();
|
|
946
|
+
_p.label = 7;
|
|
947
|
+
case 7:
|
|
948
|
+
_p.trys.push([7, 13, 14, 15]);
|
|
949
|
+
_a = tslib_1.__values(pools['Mid-tier'].samplingPool), _b = _a.next();
|
|
950
|
+
_p.label = 8;
|
|
951
|
+
case 8:
|
|
952
|
+
if (!!_b.done) return [3, 12];
|
|
908
953
|
material = _b.value;
|
|
909
954
|
return [4, ctx.getObject('pepsico_material_approval').findOne(material.pepsico_material_approval)];
|
|
910
|
-
case
|
|
955
|
+
case 9:
|
|
911
956
|
approval = _p.sent();
|
|
957
|
+
if (!approval) {
|
|
958
|
+
throw new Error("\u7D20\u6750 ".concat(material._id, " \u672A\u627E\u5230\u5173\u8054\u7684\u7D20\u6750\u5BA1\u6279\u5355"));
|
|
959
|
+
}
|
|
912
960
|
return [4, ctx.getObject('pepsico_material').directUpdate(material._id, {
|
|
913
961
|
spot_check_pool_year_month: yearMonth,
|
|
914
962
|
spot_checked: true,
|
|
@@ -918,7 +966,7 @@ exports.generateSpotCheckPool = {
|
|
|
918
966
|
ns_spot_check_user: approval.ns_spot_check,
|
|
919
967
|
ca_spot_check_user: approval.ca_spot_check
|
|
920
968
|
})];
|
|
921
|
-
case
|
|
969
|
+
case 10:
|
|
922
970
|
_p.sent();
|
|
923
971
|
try {
|
|
924
972
|
for (_c = (e_9 = void 0, tslib_1.__values(['legal_spot_check', 'sra_spot_check', 'ns_spot_check', 'ca_spot_check'])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -936,128 +984,132 @@ exports.generateSpotCheckPool = {
|
|
|
936
984
|
}
|
|
937
985
|
finally { if (e_9) throw e_9.error; }
|
|
938
986
|
}
|
|
939
|
-
_p.label =
|
|
940
|
-
case 9:
|
|
941
|
-
_b = _a.next();
|
|
942
|
-
return [3, 6];
|
|
943
|
-
case 10: return [3, 13];
|
|
987
|
+
_p.label = 11;
|
|
944
988
|
case 11:
|
|
989
|
+
_b = _a.next();
|
|
990
|
+
return [3, 8];
|
|
991
|
+
case 12: return [3, 15];
|
|
992
|
+
case 13:
|
|
945
993
|
e_5_1 = _p.sent();
|
|
946
994
|
e_5 = { error: e_5_1 };
|
|
947
|
-
return [3,
|
|
948
|
-
case
|
|
995
|
+
return [3, 15];
|
|
996
|
+
case 14:
|
|
949
997
|
try {
|
|
950
998
|
if (_b && !_b.done && (_j = _a.return)) _j.call(_a);
|
|
951
999
|
}
|
|
952
1000
|
finally { if (e_5) throw e_5.error; }
|
|
953
1001
|
return [7];
|
|
954
|
-
case
|
|
1002
|
+
case 15:
|
|
955
1003
|
specialistUserIds_2 = new Set();
|
|
956
|
-
_p.label =
|
|
957
|
-
case
|
|
958
|
-
_p.trys.push([
|
|
1004
|
+
_p.label = 16;
|
|
1005
|
+
case 16:
|
|
1006
|
+
_p.trys.push([16, 22, 23, 24]);
|
|
959
1007
|
_e = tslib_1.__values(pools['Micro'].samplingPool), _f = _e.next();
|
|
960
|
-
_p.label =
|
|
961
|
-
case
|
|
962
|
-
if (!!_f.done) return [3,
|
|
1008
|
+
_p.label = 17;
|
|
1009
|
+
case 17:
|
|
1010
|
+
if (!!_f.done) return [3, 21];
|
|
963
1011
|
material = _f.value;
|
|
964
1012
|
return [4, ctx.getObject('pepsico_material_approval').findOne(material.pepsico_material_approval)];
|
|
965
|
-
case
|
|
1013
|
+
case 18:
|
|
966
1014
|
approval = _p.sent();
|
|
1015
|
+
if (!approval) {
|
|
1016
|
+
throw new Error("\u7D20\u6750 ".concat(material._id, " \u672A\u627E\u5230\u5173\u8054\u7684\u7D20\u6750\u5BA1\u6279\u5355"));
|
|
1017
|
+
}
|
|
967
1018
|
return [4, ctx.getObject('pepsico_material').directUpdate(material._id, {
|
|
968
1019
|
spot_check_pool_year_month: yearMonth,
|
|
969
1020
|
spot_checked: true,
|
|
970
1021
|
spot_check_type: '审核专员抽查',
|
|
971
1022
|
guding_spot_check_user: approval.special_spot_check || []
|
|
972
1023
|
})];
|
|
973
|
-
case
|
|
1024
|
+
case 19:
|
|
974
1025
|
_p.sent();
|
|
975
1026
|
sUsers = approval.special_spot_check;
|
|
976
1027
|
if (sUsers) {
|
|
977
1028
|
(Array.isArray(sUsers) ? sUsers : [sUsers]).forEach(function (id) { return specialistUserIds_2.add(id); });
|
|
978
1029
|
}
|
|
979
|
-
_p.label =
|
|
980
|
-
case 18:
|
|
981
|
-
_f = _e.next();
|
|
982
|
-
return [3, 15];
|
|
983
|
-
case 19: return [3, 22];
|
|
1030
|
+
_p.label = 20;
|
|
984
1031
|
case 20:
|
|
1032
|
+
_f = _e.next();
|
|
1033
|
+
return [3, 17];
|
|
1034
|
+
case 21: return [3, 24];
|
|
1035
|
+
case 22:
|
|
985
1036
|
e_6_1 = _p.sent();
|
|
986
1037
|
e_6 = { error: e_6_1 };
|
|
987
|
-
return [3,
|
|
988
|
-
case
|
|
1038
|
+
return [3, 24];
|
|
1039
|
+
case 23:
|
|
989
1040
|
try {
|
|
990
1041
|
if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
|
|
991
1042
|
}
|
|
992
1043
|
finally { if (e_6) throw e_6.error; }
|
|
993
1044
|
return [7];
|
|
994
|
-
case
|
|
1045
|
+
case 24:
|
|
995
1046
|
ROOT_URL = process.env.ROOT_URL;
|
|
996
1047
|
subject = '【系统通知】抽查素材通知';
|
|
997
1048
|
midTierLink = "".concat(ROOT_URL, "/app/pepsico_content_review/pepsico_midtier_spot_check");
|
|
998
1049
|
midTierHtml = "\n <p>\u4EB2\u7231\u7684\u7528\u6237\uFF0C</p>\n <p>\u3010".concat(yearMonth, "\u3011\u6708\u5EA6\u62BD\u67E5\u7D20\u6750\u6C60\u5DF2\u751F\u6210\u3002\u8BF7\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u8FDB\u5165\u62BD\u67E5\u9875\u9762\uFF1A</p>\n <p><a href=\"").concat(midTierLink, "\">\u70B9\u51FB\u8FDB\u5165\u62BD\u67E5</a></p>\n <p>\u6709\u4EFB\u4F55\u7591\u95EE\uFF0C\u8BF7\u8054\u7CFB\u7CFB\u7EDF\u7BA1\u7406\u5458\u3002</p>\n <p>\u8C22\u8C22\uFF01</p>\n ");
|
|
999
1050
|
departmentToUsers = [];
|
|
1000
|
-
if (!(departmentUserIds_2.size > 0)) return [3,
|
|
1001
|
-
_p.label =
|
|
1002
|
-
case
|
|
1003
|
-
_p.trys.push([
|
|
1051
|
+
if (!(departmentUserIds_2.size > 0)) return [3, 28];
|
|
1052
|
+
_p.label = 25;
|
|
1053
|
+
case 25:
|
|
1054
|
+
_p.trys.push([25, 27, , 28]);
|
|
1004
1055
|
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', Array.from(departmentUserIds_2)] })];
|
|
1005
|
-
case
|
|
1056
|
+
case 26:
|
|
1006
1057
|
toUsersAll = _p.sent();
|
|
1007
1058
|
departmentToUsers = toUsersAll.filter(function (u) { return u.email && u.email.endsWith('@pepsico.com'); });
|
|
1008
|
-
return [3,
|
|
1009
|
-
case
|
|
1059
|
+
return [3, 28];
|
|
1060
|
+
case 27:
|
|
1010
1061
|
error_6 = _p.sent();
|
|
1011
1062
|
console.log(error_6);
|
|
1012
|
-
return [3,
|
|
1013
|
-
case
|
|
1014
|
-
if (!(departmentToUsers.length > 0)) return [3,
|
|
1063
|
+
return [3, 28];
|
|
1064
|
+
case 28:
|
|
1065
|
+
if (!(departmentToUsers.length > 0)) return [3, 30];
|
|
1015
1066
|
return [4, sendEmail(process.env.B6_EMAIL_FROM, (0, lodash_1.join)((0, lodash_1.map)(departmentToUsers, 'email'), ';'), subject, '', midTierHtml, '')];
|
|
1016
|
-
case
|
|
1067
|
+
case 29:
|
|
1017
1068
|
_g = _p.sent();
|
|
1018
|
-
return [3,
|
|
1019
|
-
case
|
|
1069
|
+
return [3, 31];
|
|
1070
|
+
case 30:
|
|
1020
1071
|
_g = '无收件人';
|
|
1021
|
-
_p.label =
|
|
1022
|
-
case
|
|
1072
|
+
_p.label = 31;
|
|
1073
|
+
case 31:
|
|
1023
1074
|
midTierResult = _g;
|
|
1024
1075
|
microLink = "".concat(ROOT_URL, "/app/pepsico_content_review/pepsico_spot_check");
|
|
1025
1076
|
microHtml = "\n <p>\u4EB2\u7231\u7684\u7528\u6237\uFF0C</p>\n <p>\u3010".concat(yearMonth, "\u3011\u6708\u5EA6\u62BD\u67E5\u7D20\u6750\u6C60\u5DF2\u751F\u6210\u3002\u8BF7\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u8FDB\u5165\u62BD\u67E5\u9875\u9762\uFF1A</p>\n <p><a href=\"").concat(microLink, "\">\u70B9\u51FB\u8FDB\u5165\u62BD\u67E5</a></p>\n <p>\u6709\u4EFB\u4F55\u7591\u95EE\uFF0C\u8BF7\u8054\u7CFB\u7CFB\u7EDF\u7BA1\u7406\u5458\u3002</p>\n <p>\u8C22\u8C22\uFF01</p>\n ");
|
|
1026
1077
|
specialistToUsers = [];
|
|
1027
|
-
if (!(specialistUserIds_2.size > 0)) return [3,
|
|
1028
|
-
_p.label =
|
|
1029
|
-
case
|
|
1030
|
-
_p.trys.push([
|
|
1078
|
+
if (!(specialistUserIds_2.size > 0)) return [3, 35];
|
|
1079
|
+
_p.label = 32;
|
|
1080
|
+
case 32:
|
|
1081
|
+
_p.trys.push([32, 34, , 35]);
|
|
1031
1082
|
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', Array.from(specialistUserIds_2)] })];
|
|
1032
|
-
case
|
|
1083
|
+
case 33:
|
|
1033
1084
|
toUsersAll = _p.sent();
|
|
1034
1085
|
specialistToUsers = toUsersAll.filter(function (u) { return u.email && u.email.endsWith('@pepsico.com'); });
|
|
1035
|
-
return [3,
|
|
1036
|
-
case
|
|
1086
|
+
return [3, 35];
|
|
1087
|
+
case 34:
|
|
1037
1088
|
error_7 = _p.sent();
|
|
1038
1089
|
console.log(error_7);
|
|
1039
|
-
return [3,
|
|
1040
|
-
case 33:
|
|
1041
|
-
if (!(specialistToUsers.length > 0)) return [3, 35];
|
|
1042
|
-
return [4, sendEmail(process.env.B6_EMAIL_FROM, (0, lodash_1.join)((0, lodash_1.map)(specialistToUsers, 'email'), ';'), subject, '', microHtml, '')];
|
|
1043
|
-
case 34:
|
|
1044
|
-
_h = _p.sent();
|
|
1045
|
-
return [3, 36];
|
|
1090
|
+
return [3, 35];
|
|
1046
1091
|
case 35:
|
|
1047
|
-
|
|
1048
|
-
|
|
1092
|
+
if (!(specialistToUsers.length > 0)) return [3, 37];
|
|
1093
|
+
return [4, sendEmail(process.env.B6_EMAIL_FROM, (0, lodash_1.join)((0, lodash_1.map)(specialistToUsers, 'email'), ';'), subject, '', microHtml, '')];
|
|
1049
1094
|
case 36:
|
|
1050
|
-
|
|
1051
|
-
|
|
1095
|
+
_h = _p.sent();
|
|
1096
|
+
return [3, 38];
|
|
1052
1097
|
case 37:
|
|
1053
|
-
|
|
1098
|
+
_h = '无收件人';
|
|
1054
1099
|
_p.label = 38;
|
|
1055
1100
|
case 38:
|
|
1056
|
-
|
|
1057
|
-
departmentUserIds_1 = tslib_1.__values(departmentUserIds_2), departmentUserIds_1_1 = departmentUserIds_1.next();
|
|
1101
|
+
microResult = _h;
|
|
1058
1102
|
_p.label = 39;
|
|
1059
1103
|
case 39:
|
|
1060
|
-
|
|
1104
|
+
_p.trys.push([39, 55, , 56]);
|
|
1105
|
+
fromUserId = (user === null || user === void 0 ? void 0 : user.userId) || pool.owner || pool.created_by;
|
|
1106
|
+
_p.label = 40;
|
|
1107
|
+
case 40:
|
|
1108
|
+
_p.trys.push([40, 45, 46, 47]);
|
|
1109
|
+
departmentUserIds_1 = tslib_1.__values(departmentUserIds_2), departmentUserIds_1_1 = departmentUserIds_1.next();
|
|
1110
|
+
_p.label = 41;
|
|
1111
|
+
case 41:
|
|
1112
|
+
if (!!departmentUserIds_1_1.done) return [3, 44];
|
|
1061
1113
|
userId = departmentUserIds_1_1.value;
|
|
1062
1114
|
return [4, ctx.broker.call('notifications.add', {
|
|
1063
1115
|
message: {
|
|
@@ -1065,35 +1117,35 @@ exports.generateSpotCheckPool = {
|
|
|
1065
1117
|
body: '',
|
|
1066
1118
|
related_to: { o: 'pepsico_spot_check_pool', ids: [pid] },
|
|
1067
1119
|
related_name: pool.name || yearMonth,
|
|
1068
|
-
from:
|
|
1120
|
+
from: fromUserId,
|
|
1069
1121
|
space: pool.space
|
|
1070
1122
|
},
|
|
1071
|
-
from:
|
|
1123
|
+
from: fromUserId,
|
|
1072
1124
|
to: userId
|
|
1073
1125
|
})];
|
|
1074
|
-
case
|
|
1126
|
+
case 42:
|
|
1075
1127
|
_p.sent();
|
|
1076
|
-
_p.label =
|
|
1077
|
-
case 41:
|
|
1078
|
-
departmentUserIds_1_1 = departmentUserIds_1.next();
|
|
1079
|
-
return [3, 39];
|
|
1080
|
-
case 42: return [3, 45];
|
|
1128
|
+
_p.label = 43;
|
|
1081
1129
|
case 43:
|
|
1130
|
+
departmentUserIds_1_1 = departmentUserIds_1.next();
|
|
1131
|
+
return [3, 41];
|
|
1132
|
+
case 44: return [3, 47];
|
|
1133
|
+
case 45:
|
|
1082
1134
|
e_7_1 = _p.sent();
|
|
1083
1135
|
e_7 = { error: e_7_1 };
|
|
1084
|
-
return [3,
|
|
1085
|
-
case
|
|
1136
|
+
return [3, 47];
|
|
1137
|
+
case 46:
|
|
1086
1138
|
try {
|
|
1087
1139
|
if (departmentUserIds_1_1 && !departmentUserIds_1_1.done && (_m = departmentUserIds_1.return)) _m.call(departmentUserIds_1);
|
|
1088
1140
|
}
|
|
1089
1141
|
finally { if (e_7) throw e_7.error; }
|
|
1090
1142
|
return [7];
|
|
1091
|
-
case
|
|
1092
|
-
_p.trys.push([
|
|
1143
|
+
case 47:
|
|
1144
|
+
_p.trys.push([47, 52, 53, 54]);
|
|
1093
1145
|
specialistUserIds_1 = tslib_1.__values(specialistUserIds_2), specialistUserIds_1_1 = specialistUserIds_1.next();
|
|
1094
|
-
_p.label =
|
|
1095
|
-
case
|
|
1096
|
-
if (!!specialistUserIds_1_1.done) return [3,
|
|
1146
|
+
_p.label = 48;
|
|
1147
|
+
case 48:
|
|
1148
|
+
if (!!specialistUserIds_1_1.done) return [3, 51];
|
|
1097
1149
|
userId = specialistUserIds_1_1.value;
|
|
1098
1150
|
return [4, ctx.broker.call('notifications.add', {
|
|
1099
1151
|
message: {
|
|
@@ -1101,49 +1153,74 @@ exports.generateSpotCheckPool = {
|
|
|
1101
1153
|
body: '',
|
|
1102
1154
|
related_to: { o: 'pepsico_spot_check_pool', ids: [pid] },
|
|
1103
1155
|
related_name: pool.name || yearMonth,
|
|
1104
|
-
from:
|
|
1156
|
+
from: fromUserId,
|
|
1105
1157
|
space: pool.space
|
|
1106
1158
|
},
|
|
1107
|
-
from:
|
|
1159
|
+
from: fromUserId,
|
|
1108
1160
|
to: userId
|
|
1109
1161
|
})];
|
|
1110
|
-
case
|
|
1162
|
+
case 49:
|
|
1111
1163
|
_p.sent();
|
|
1112
|
-
_p.label =
|
|
1113
|
-
case 48:
|
|
1114
|
-
specialistUserIds_1_1 = specialistUserIds_1.next();
|
|
1115
|
-
return [3, 46];
|
|
1116
|
-
case 49: return [3, 52];
|
|
1164
|
+
_p.label = 50;
|
|
1117
1165
|
case 50:
|
|
1166
|
+
specialistUserIds_1_1 = specialistUserIds_1.next();
|
|
1167
|
+
return [3, 48];
|
|
1168
|
+
case 51: return [3, 54];
|
|
1169
|
+
case 52:
|
|
1118
1170
|
e_8_1 = _p.sent();
|
|
1119
1171
|
e_8 = { error: e_8_1 };
|
|
1120
|
-
return [3,
|
|
1121
|
-
case
|
|
1172
|
+
return [3, 54];
|
|
1173
|
+
case 53:
|
|
1122
1174
|
try {
|
|
1123
1175
|
if (specialistUserIds_1_1 && !specialistUserIds_1_1.done && (_o = specialistUserIds_1.return)) _o.call(specialistUserIds_1);
|
|
1124
1176
|
}
|
|
1125
1177
|
finally { if (e_8) throw e_8.error; }
|
|
1126
1178
|
return [7];
|
|
1127
|
-
case
|
|
1128
|
-
case
|
|
1179
|
+
case 54: return [3, 56];
|
|
1180
|
+
case 55:
|
|
1129
1181
|
error_8 = _p.sent();
|
|
1130
1182
|
console.log('站内通知发送失败:', error_8);
|
|
1131
|
-
return [3,
|
|
1132
|
-
case
|
|
1183
|
+
return [3, 56];
|
|
1184
|
+
case 56: return [4, ctx.getObject('pepsico_spot_check_pool').directUpdate(pid, {
|
|
1133
1185
|
mail_send: true,
|
|
1134
1186
|
mail_send_date: new Date(),
|
|
1135
1187
|
mid_tier_pepsico_material: (0, lodash_1.map)(pools['Mid-tier'].samplingPool, '_id'),
|
|
1136
1188
|
micro_pepsico_material: (0, lodash_1.map)(pools['Micro'].samplingPool, '_id'),
|
|
1137
1189
|
logs: logs + '\r\n' + "=== \u53D1\u9001\u90AE\u4EF6\uFF08\u56DB\u90E8\u95E8-\u8170\u90E8\uFF09 === \r\n\n \u90AE\u4EF6\u4E3B\u9898: ".concat(subject, "\r\n\n \u6536\u4EF6\u4EBA: ").concat((0, lodash_1.join)((0, lodash_1.map)(departmentToUsers, 'email'), ';'), "\r\n\n \u90AE\u4EF6\u5185\u5BB9: ").concat(midTierHtml, "\r\n\n \u90AE\u4EF6\u53D1\u9001\u7ED3\u679C: ").concat(midTierResult, "\r\n\n === \u53D1\u9001\u90AE\u4EF6\uFF08\u4E13\u5458-\u5C3E\u90E8\uFF09 === \r\n\n \u90AE\u4EF6\u4E3B\u9898: ").concat(subject, "\r\n\n \u6536\u4EF6\u4EBA: ").concat((0, lodash_1.join)((0, lodash_1.map)(specialistToUsers, 'email'), ';'), "\r\n\n \u90AE\u4EF6\u5185\u5BB9: ").concat(microHtml, "\r\n\n \u90AE\u4EF6\u53D1\u9001\u7ED3\u679C: ").concat(microResult, "\n ")
|
|
1138
1190
|
})];
|
|
1139
|
-
case
|
|
1191
|
+
case 57:
|
|
1140
1192
|
_p.sent();
|
|
1141
|
-
return [
|
|
1142
|
-
|
|
1193
|
+
return [2, {
|
|
1194
|
+
status: 200,
|
|
1195
|
+
msg: '抽查素材池邮件发送完成',
|
|
1196
|
+
data: {
|
|
1197
|
+
year_month: yearMonth,
|
|
1198
|
+
count: pools.count,
|
|
1199
|
+
mid_tier_count: pools['Mid-tier'].samplingPool.length,
|
|
1200
|
+
micro_count: pools['Micro'].samplingPool.length,
|
|
1201
|
+
mid_tier_mail_result: midTierResult,
|
|
1202
|
+
micro_mail_result: microResult
|
|
1203
|
+
}
|
|
1204
|
+
}];
|
|
1205
|
+
case 58:
|
|
1143
1206
|
error_9 = _p.sent();
|
|
1207
|
+
message = (error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || String(error_9);
|
|
1144
1208
|
console.error('执行失败:', error_9);
|
|
1145
|
-
|
|
1146
|
-
case
|
|
1209
|
+
_p.label = 59;
|
|
1210
|
+
case 59:
|
|
1211
|
+
_p.trys.push([59, 61, , 62]);
|
|
1212
|
+
return [4, ctx.getObject('pepsico_spot_check_pool').directUpdate(pid, {
|
|
1213
|
+
logs: "[".concat(yearMonth, "] \u62BD\u67E5\u7D20\u6750\u6C60\u90AE\u4EF6\u53D1\u9001\u5931\u8D25\uFF1A").concat(message)
|
|
1214
|
+
})];
|
|
1215
|
+
case 60:
|
|
1216
|
+
_p.sent();
|
|
1217
|
+
return [3, 62];
|
|
1218
|
+
case 61:
|
|
1219
|
+
updateError_1 = _p.sent();
|
|
1220
|
+
console.error('记录抽查素材池失败日志失败:', updateError_1);
|
|
1221
|
+
return [3, 62];
|
|
1222
|
+
case 62: throw error_9;
|
|
1223
|
+
case 63: return [2];
|
|
1147
1224
|
}
|
|
1148
1225
|
});
|
|
1149
1226
|
});
|
|
@@ -1152,15 +1229,24 @@ exports.generateSpotCheckPool = {
|
|
|
1152
1229
|
exports.remindSpotCheckIncomplete = {
|
|
1153
1230
|
rest: {
|
|
1154
1231
|
method: "GET",
|
|
1155
|
-
|
|
1232
|
+
fullPath: "/api/pepsico-content/remind/spot-check-incomplete"
|
|
1156
1233
|
},
|
|
1157
1234
|
handler: function (ctx) {
|
|
1158
1235
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1159
|
-
var yearMonth, pendingUsers, midTierMaterials, midTierMaterials_1, midTierMaterials_1_1, material, deptFields, deptFields_1, deptFields_1_1, _a, done,
|
|
1236
|
+
var user, logger, yearMonth, pendingUsers, midTierMaterials, midTierMaterials_1, midTierMaterials_1_1, material, deptFields, deptFields_1, deptFields_1_1, _a, done, user_1, users, users_2, users_2_1, uid, existing, microMaterials, microMaterials_1, microMaterials_1_1, material, users, users_3, users_3_1, uid, existing, ROOT_URL, midTierLink, microLink, subject, results, userIds, spaceUsers, _loop_2, pendingUsers_1, pendingUsers_1_1, _b, userId, info, e_10_1;
|
|
1160
1237
|
var e_11, _c, e_12, _d, e_13, _e, e_14, _f, e_15, _g, e_10, _h;
|
|
1161
1238
|
return tslib_1.__generator(this, function (_j) {
|
|
1162
1239
|
switch (_j.label) {
|
|
1163
1240
|
case 0:
|
|
1241
|
+
user = ctx.meta.user;
|
|
1242
|
+
if (user && !user.is_space_admin) {
|
|
1243
|
+
throw new Error('无权限');
|
|
1244
|
+
}
|
|
1245
|
+
ctx.getObject = this.getObject;
|
|
1246
|
+
return [4, this.getLogger()];
|
|
1247
|
+
case 1:
|
|
1248
|
+
logger = _j.sent();
|
|
1249
|
+
ctx.logger = logger;
|
|
1164
1250
|
yearMonth = moment().format('YYYY-MM');
|
|
1165
1251
|
console.log("[remindSpotCheckIncomplete] \u5F00\u59CB\u626B\u63CF ".concat(yearMonth, " \u672A\u5B8C\u6210\u62BD\u67E5\u4EFB\u52A1..."));
|
|
1166
1252
|
pendingUsers = new Map();
|
|
@@ -1172,7 +1258,7 @@ exports.remindSpotCheckIncomplete = {
|
|
|
1172
1258
|
['spot_check_type', '=', '四部门抽查']
|
|
1173
1259
|
]
|
|
1174
1260
|
})];
|
|
1175
|
-
case
|
|
1261
|
+
case 2:
|
|
1176
1262
|
midTierMaterials = _j.sent();
|
|
1177
1263
|
console.log("[remindSpotCheckIncomplete] \u8170\u90E8\u672A\u5B8C\u6210\u7D20\u6750: ".concat(midTierMaterials.length));
|
|
1178
1264
|
try {
|
|
@@ -1186,9 +1272,9 @@ exports.remindSpotCheckIncomplete = {
|
|
|
1186
1272
|
];
|
|
1187
1273
|
try {
|
|
1188
1274
|
for (deptFields_1 = (e_12 = void 0, tslib_1.__values(deptFields)), deptFields_1_1 = deptFields_1.next(); !deptFields_1_1.done; deptFields_1_1 = deptFields_1.next()) {
|
|
1189
|
-
_a = deptFields_1_1.value, done = _a.done,
|
|
1190
|
-
if (!material[done] && material[
|
|
1191
|
-
users = Array.isArray(material[
|
|
1275
|
+
_a = deptFields_1_1.value, done = _a.done, user_1 = _a.user;
|
|
1276
|
+
if (!material[done] && material[user_1]) {
|
|
1277
|
+
users = Array.isArray(material[user_1]) ? material[user_1] : [material[user_1]];
|
|
1192
1278
|
try {
|
|
1193
1279
|
for (users_2 = (e_13 = void 0, tslib_1.__values(users)), users_2_1 = users_2.next(); !users_2_1.done; users_2_1 = users_2.next()) {
|
|
1194
1280
|
uid = users_2_1.value;
|
|
@@ -1233,7 +1319,7 @@ exports.remindSpotCheckIncomplete = {
|
|
|
1233
1319
|
['spot_check_type', '=', '审核专员抽查']
|
|
1234
1320
|
]
|
|
1235
1321
|
})];
|
|
1236
|
-
case
|
|
1322
|
+
case 3:
|
|
1237
1323
|
microMaterials = _j.sent();
|
|
1238
1324
|
console.log("[remindSpotCheckIncomplete] \u5C3E\u90E8\u672A\u5B8C\u6210\u7D20\u6750: ".concat(microMaterials.length));
|
|
1239
1325
|
try {
|
|
@@ -1280,7 +1366,7 @@ exports.remindSpotCheckIncomplete = {
|
|
|
1280
1366
|
results = [];
|
|
1281
1367
|
userIds = Array.from(pendingUsers.keys());
|
|
1282
1368
|
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', userIds] })];
|
|
1283
|
-
case
|
|
1369
|
+
case 4:
|
|
1284
1370
|
spaceUsers = _j.sent();
|
|
1285
1371
|
_loop_2 = function (userId, info) {
|
|
1286
1372
|
var spaceUser, link, html, error_10, error_11;
|
|
@@ -1331,33 +1417,33 @@ exports.remindSpotCheckIncomplete = {
|
|
|
1331
1417
|
}
|
|
1332
1418
|
});
|
|
1333
1419
|
};
|
|
1334
|
-
_j.label = 4;
|
|
1335
|
-
case 4:
|
|
1336
|
-
_j.trys.push([4, 9, 10, 11]);
|
|
1337
|
-
pendingUsers_1 = tslib_1.__values(pendingUsers), pendingUsers_1_1 = pendingUsers_1.next();
|
|
1338
1420
|
_j.label = 5;
|
|
1339
1421
|
case 5:
|
|
1340
|
-
|
|
1422
|
+
_j.trys.push([5, 10, 11, 12]);
|
|
1423
|
+
pendingUsers_1 = tslib_1.__values(pendingUsers), pendingUsers_1_1 = pendingUsers_1.next();
|
|
1424
|
+
_j.label = 6;
|
|
1425
|
+
case 6:
|
|
1426
|
+
if (!!pendingUsers_1_1.done) return [3, 9];
|
|
1341
1427
|
_b = tslib_1.__read(pendingUsers_1_1.value, 2), userId = _b[0], info = _b[1];
|
|
1342
1428
|
return [5, _loop_2(userId, info)];
|
|
1343
|
-
case 6:
|
|
1344
|
-
_j.sent();
|
|
1345
|
-
_j.label = 7;
|
|
1346
1429
|
case 7:
|
|
1430
|
+
_j.sent();
|
|
1431
|
+
_j.label = 8;
|
|
1432
|
+
case 8:
|
|
1347
1433
|
pendingUsers_1_1 = pendingUsers_1.next();
|
|
1348
|
-
return [3,
|
|
1349
|
-
case
|
|
1350
|
-
case
|
|
1434
|
+
return [3, 6];
|
|
1435
|
+
case 9: return [3, 12];
|
|
1436
|
+
case 10:
|
|
1351
1437
|
e_10_1 = _j.sent();
|
|
1352
1438
|
e_10 = { error: e_10_1 };
|
|
1353
|
-
return [3,
|
|
1354
|
-
case
|
|
1439
|
+
return [3, 12];
|
|
1440
|
+
case 11:
|
|
1355
1441
|
try {
|
|
1356
1442
|
if (pendingUsers_1_1 && !pendingUsers_1_1.done && (_h = pendingUsers_1.return)) _h.call(pendingUsers_1);
|
|
1357
1443
|
}
|
|
1358
1444
|
finally { if (e_10) throw e_10.error; }
|
|
1359
1445
|
return [7];
|
|
1360
|
-
case
|
|
1446
|
+
case 12:
|
|
1361
1447
|
console.log("[remindSpotCheckIncomplete] \u50AC\u529E\u5B8C\u6210\u3002\u7ED3\u679C:", results);
|
|
1362
1448
|
return [2, { success: true, yearMonth: yearMonth, totalUsers: pendingUsers.size, results: results }];
|
|
1363
1449
|
}
|