@steedos-labs/content-compliance-bev 0.2.3 → 0.2.4
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/spotCheckMaterial.d.ts +19 -0
- package/lib/actions/spotCheckMaterial.js +418 -67
- package/lib/actions/spotCheckMaterial.js.map +1 -1
- package/lib/const.d.ts +1 -1
- package/lib/index.js +66 -33
- package/lib/index.js.map +1 -1
- package/main/default/applications/pepsico_content_review.app.yml +6 -0
- package/main/default/applications/pepsico_content_setting.app.yml +11 -0
- package/main/default/objects/pepsico_approval_process/fields/owner.field.yml +1 -0
- package/package.json +1 -1
- package/tsconfig.json +2 -0
|
@@ -64,3 +64,22 @@ export declare const generateSpotCheckPool: {
|
|
|
64
64
|
};
|
|
65
65
|
handler(ctx: any): Promise<void>;
|
|
66
66
|
};
|
|
67
|
+
export declare const remindSpotCheckIncomplete: {
|
|
68
|
+
rest: {
|
|
69
|
+
method: string;
|
|
70
|
+
path: string;
|
|
71
|
+
};
|
|
72
|
+
handler(ctx: any): Promise<{
|
|
73
|
+
success: boolean;
|
|
74
|
+
message: string;
|
|
75
|
+
yearMonth?: undefined;
|
|
76
|
+
totalUsers?: undefined;
|
|
77
|
+
results?: undefined;
|
|
78
|
+
} | {
|
|
79
|
+
success: boolean;
|
|
80
|
+
yearMonth: any;
|
|
81
|
+
totalUsers: number;
|
|
82
|
+
results: any[];
|
|
83
|
+
message?: undefined;
|
|
84
|
+
}>;
|
|
85
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateSpotCheckPool = exports.clickPoolSpotEmail = exports.clickReportSpotEmail = exports.sendMonthlySpotCheckReport = exports.clickSpotEmail = exports.spotCheckMaterial = void 0;
|
|
3
|
+
exports.remindSpotCheckIncomplete = exports.generateSpotCheckPool = exports.clickPoolSpotEmail = exports.clickReportSpotEmail = exports.sendMonthlySpotCheckReport = exports.clickSpotEmail = exports.spotCheckMaterial = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var lodash_1 = require("lodash");
|
|
6
6
|
var axios_1 = require("axios");
|
|
@@ -858,34 +858,34 @@ exports.generateSpotCheckPool = {
|
|
|
858
858
|
},
|
|
859
859
|
handler: function (ctx) {
|
|
860
860
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
861
|
-
var user, pid, logger, pool, yearMonth, pools, logs, _a, _b, material, approval, e_5_1,
|
|
862
|
-
var e_5,
|
|
863
|
-
return tslib_1.__generator(this, function (
|
|
864
|
-
switch (
|
|
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;
|
|
862
|
+
var e_5, _j, e_9, _k, e_6, _l, e_7, _m, e_8, _o;
|
|
863
|
+
return tslib_1.__generator(this, function (_p) {
|
|
864
|
+
switch (_p.label) {
|
|
865
865
|
case 0:
|
|
866
866
|
user = ctx.meta.user;
|
|
867
867
|
pid = ctx.params.pid;
|
|
868
868
|
ctx.getObject = this.getObject;
|
|
869
869
|
return [4, this.getLogger()];
|
|
870
870
|
case 1:
|
|
871
|
-
logger =
|
|
871
|
+
logger = _p.sent();
|
|
872
872
|
ctx.logger = logger;
|
|
873
873
|
if (user && !user.is_space_admin) {
|
|
874
874
|
throw new Error('无权限');
|
|
875
875
|
}
|
|
876
876
|
return [4, ctx.getObject('pepsico_spot_check_pool').findOne(pid)];
|
|
877
877
|
case 2:
|
|
878
|
-
pool =
|
|
878
|
+
pool = _p.sent();
|
|
879
879
|
if (!pool) {
|
|
880
880
|
throw new Error('无效的id');
|
|
881
881
|
}
|
|
882
882
|
yearMonth = pool.year_month;
|
|
883
|
-
|
|
883
|
+
_p.label = 3;
|
|
884
884
|
case 3:
|
|
885
|
-
|
|
885
|
+
_p.trys.push([3, 56, , 57]);
|
|
886
886
|
return [4, getSpotCheckPool(yearMonth)];
|
|
887
887
|
case 4:
|
|
888
|
-
pools =
|
|
888
|
+
pools = _p.sent();
|
|
889
889
|
console.log('=== 腰部(Mid-tier)抽查池子 ===');
|
|
890
890
|
console.log("\u603B\u62BD\u6837\u6570: ".concat(pools['Mid-tier'].samplingPool.length), (0, lodash_1.map)(pools['Mid-tier'].samplingPool, function (item) { return (0, lodash_1.pick)(item, ['_id', 'product']); }));
|
|
891
891
|
console.log('品牌统计:', pools['Mid-tier'].statistics.byBrand);
|
|
@@ -897,17 +897,18 @@ exports.generateSpotCheckPool = {
|
|
|
897
897
|
console.log('无可抽查素材. 不发送邮件.');
|
|
898
898
|
return [2];
|
|
899
899
|
}
|
|
900
|
-
|
|
900
|
+
departmentUserIds_2 = new Set();
|
|
901
|
+
_p.label = 5;
|
|
901
902
|
case 5:
|
|
902
|
-
|
|
903
|
+
_p.trys.push([5, 11, 12, 13]);
|
|
903
904
|
_a = tslib_1.__values(pools['Mid-tier'].samplingPool), _b = _a.next();
|
|
904
|
-
|
|
905
|
+
_p.label = 6;
|
|
905
906
|
case 6:
|
|
906
907
|
if (!!_b.done) return [3, 10];
|
|
907
908
|
material = _b.value;
|
|
908
909
|
return [4, ctx.getObject('pepsico_material_approval').findOne(material.pepsico_material_approval)];
|
|
909
910
|
case 7:
|
|
910
|
-
approval =
|
|
911
|
+
approval = _p.sent();
|
|
911
912
|
return [4, ctx.getObject('pepsico_material').directUpdate(material._id, {
|
|
912
913
|
spot_check_pool_year_month: yearMonth,
|
|
913
914
|
spot_checked: true,
|
|
@@ -918,97 +919,447 @@ exports.generateSpotCheckPool = {
|
|
|
918
919
|
ca_spot_check_user: approval.ca_spot_check
|
|
919
920
|
})];
|
|
920
921
|
case 8:
|
|
921
|
-
|
|
922
|
-
|
|
922
|
+
_p.sent();
|
|
923
|
+
try {
|
|
924
|
+
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()) {
|
|
925
|
+
field = _d.value;
|
|
926
|
+
users = approval[field];
|
|
927
|
+
if (users) {
|
|
928
|
+
(Array.isArray(users) ? users : [users]).forEach(function (id) { return departmentUserIds_2.add(id); });
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
933
|
+
finally {
|
|
934
|
+
try {
|
|
935
|
+
if (_d && !_d.done && (_k = _c.return)) _k.call(_c);
|
|
936
|
+
}
|
|
937
|
+
finally { if (e_9) throw e_9.error; }
|
|
938
|
+
}
|
|
939
|
+
_p.label = 9;
|
|
923
940
|
case 9:
|
|
924
941
|
_b = _a.next();
|
|
925
942
|
return [3, 6];
|
|
926
943
|
case 10: return [3, 13];
|
|
927
944
|
case 11:
|
|
928
|
-
e_5_1 =
|
|
945
|
+
e_5_1 = _p.sent();
|
|
929
946
|
e_5 = { error: e_5_1 };
|
|
930
947
|
return [3, 13];
|
|
931
948
|
case 12:
|
|
932
949
|
try {
|
|
933
|
-
if (_b && !_b.done && (
|
|
950
|
+
if (_b && !_b.done && (_j = _a.return)) _j.call(_a);
|
|
934
951
|
}
|
|
935
952
|
finally { if (e_5) throw e_5.error; }
|
|
936
953
|
return [7];
|
|
937
954
|
case 13:
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
_g.label = 14;
|
|
955
|
+
specialistUserIds_2 = new Set();
|
|
956
|
+
_p.label = 14;
|
|
941
957
|
case 14:
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
958
|
+
_p.trys.push([14, 20, 21, 22]);
|
|
959
|
+
_e = tslib_1.__values(pools['Micro'].samplingPool), _f = _e.next();
|
|
960
|
+
_p.label = 15;
|
|
945
961
|
case 15:
|
|
946
|
-
|
|
962
|
+
if (!!_f.done) return [3, 19];
|
|
963
|
+
material = _f.value;
|
|
964
|
+
return [4, ctx.getObject('pepsico_material_approval').findOne(material.pepsico_material_approval)];
|
|
965
|
+
case 16:
|
|
966
|
+
approval = _p.sent();
|
|
947
967
|
return [4, ctx.getObject('pepsico_material').directUpdate(material._id, {
|
|
948
968
|
spot_check_pool_year_month: yearMonth,
|
|
949
969
|
spot_checked: true,
|
|
950
970
|
spot_check_type: '审核专员抽查',
|
|
951
971
|
guding_spot_check_user: approval.special_spot_check || []
|
|
952
972
|
})];
|
|
953
|
-
case 16:
|
|
954
|
-
_g.sent();
|
|
955
|
-
_g.label = 17;
|
|
956
973
|
case 17:
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
974
|
+
_p.sent();
|
|
975
|
+
sUsers = approval.special_spot_check;
|
|
976
|
+
if (sUsers) {
|
|
977
|
+
(Array.isArray(sUsers) ? sUsers : [sUsers]).forEach(function (id) { return specialistUserIds_2.add(id); });
|
|
978
|
+
}
|
|
979
|
+
_p.label = 18;
|
|
980
|
+
case 18:
|
|
981
|
+
_f = _e.next();
|
|
982
|
+
return [3, 15];
|
|
983
|
+
case 19: return [3, 22];
|
|
964
984
|
case 20:
|
|
985
|
+
e_6_1 = _p.sent();
|
|
986
|
+
e_6 = { error: e_6_1 };
|
|
987
|
+
return [3, 22];
|
|
988
|
+
case 21:
|
|
965
989
|
try {
|
|
966
|
-
if (
|
|
990
|
+
if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
|
|
967
991
|
}
|
|
968
992
|
finally { if (e_6) throw e_6.error; }
|
|
969
993
|
return [7];
|
|
970
|
-
case 21:
|
|
971
|
-
subject = '【系统通知】抽查素材通知';
|
|
972
|
-
html = "\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\uFF0C\u8BF7\u767B\u5F55Bev\u5185\u5BB9\u5BA1\u6838\u7CFB\u7EDF\u8FDB\u884C\u7D20\u6750\u62BD\u67E5\u3002</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 ");
|
|
973
|
-
toUsers = [];
|
|
974
|
-
return [4, ctx.getObject('permission_set').directFind({
|
|
975
|
-
filters: ['name', '=', 'pepsico_spot_check_users']
|
|
976
|
-
})];
|
|
977
994
|
case 22:
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
995
|
+
ROOT_URL = process.env.ROOT_URL;
|
|
996
|
+
subject = '【系统通知】抽查素材通知';
|
|
997
|
+
midTierLink = "".concat(ROOT_URL, "/app/pepsico_content_review/pepsico_midtier_spot_check");
|
|
998
|
+
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
|
+
departmentToUsers = [];
|
|
1000
|
+
if (!(departmentUserIds_2.size > 0)) return [3, 26];
|
|
1001
|
+
_p.label = 23;
|
|
981
1002
|
case 23:
|
|
982
|
-
|
|
983
|
-
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in',
|
|
1003
|
+
_p.trys.push([23, 25, , 26]);
|
|
1004
|
+
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', Array.from(departmentUserIds_2)] })];
|
|
984
1005
|
case 24:
|
|
985
|
-
toUsersAll =
|
|
986
|
-
|
|
1006
|
+
toUsersAll = _p.sent();
|
|
1007
|
+
departmentToUsers = toUsersAll.filter(function (u) { return u.email && u.email.endsWith('@pepsico.com'); });
|
|
987
1008
|
return [3, 26];
|
|
988
1009
|
case 25:
|
|
989
|
-
error_6 =
|
|
1010
|
+
error_6 = _p.sent();
|
|
990
1011
|
console.log(error_6);
|
|
991
1012
|
return [3, 26];
|
|
992
1013
|
case 26:
|
|
993
|
-
|
|
994
|
-
return [4, sendEmail(process.env.B6_EMAIL_FROM, (0, lodash_1.join)((0, lodash_1.map)(
|
|
1014
|
+
if (!(departmentToUsers.length > 0)) return [3, 28];
|
|
1015
|
+
return [4, sendEmail(process.env.B6_EMAIL_FROM, (0, lodash_1.join)((0, lodash_1.map)(departmentToUsers, 'email'), ';'), subject, '', midTierHtml, '')];
|
|
995
1016
|
case 27:
|
|
996
|
-
|
|
997
|
-
return [
|
|
998
|
-
mail_send: true,
|
|
999
|
-
mail_send_date: new Date(),
|
|
1000
|
-
mid_tier_pepsico_material: (0, lodash_1.map)(pools['Mid-tier'].samplingPool, '_id'),
|
|
1001
|
-
micro_pepsico_material: (0, lodash_1.map)(pools['Micro'].samplingPool, '_id'),
|
|
1002
|
-
logs: logs + '\r\n' + "=== \u53D1\u9001\u90AE\u4EF6 === \r\n\n \u90AE\u4EF6\u4E3B\u9898: ".concat(subject, "\r\n\n \u6536\u4EF6\u4EBA: ").concat((0, lodash_1.join)((0, lodash_1.map)(toUsers, 'email'), ';'), "\r\n\n \u6284\u9001: ").concat((0, lodash_1.join)((0, lodash_1.map)(ccUsers, 'email'), ';'), "\r\n\n \u90AE\u4EF6\u5185\u5BB9: ").concat(html, "\r\n\n \u90AE\u4EF6\u53D1\u9001\u7ED3\u679C: ").concat(result, "\n ")
|
|
1003
|
-
})];
|
|
1017
|
+
_g = _p.sent();
|
|
1018
|
+
return [3, 29];
|
|
1004
1019
|
case 28:
|
|
1005
|
-
_g
|
|
1006
|
-
|
|
1020
|
+
_g = '无收件人';
|
|
1021
|
+
_p.label = 29;
|
|
1007
1022
|
case 29:
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1023
|
+
midTierResult = _g;
|
|
1024
|
+
microLink = "".concat(ROOT_URL, "/app/pepsico_content_review/pepsico_spot_check");
|
|
1025
|
+
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
|
+
specialistToUsers = [];
|
|
1027
|
+
if (!(specialistUserIds_2.size > 0)) return [3, 33];
|
|
1028
|
+
_p.label = 30;
|
|
1029
|
+
case 30:
|
|
1030
|
+
_p.trys.push([30, 32, , 33]);
|
|
1031
|
+
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', Array.from(specialistUserIds_2)] })];
|
|
1032
|
+
case 31:
|
|
1033
|
+
toUsersAll = _p.sent();
|
|
1034
|
+
specialistToUsers = toUsersAll.filter(function (u) { return u.email && u.email.endsWith('@pepsico.com'); });
|
|
1035
|
+
return [3, 33];
|
|
1036
|
+
case 32:
|
|
1037
|
+
error_7 = _p.sent();
|
|
1038
|
+
console.log(error_7);
|
|
1039
|
+
return [3, 33];
|
|
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];
|
|
1046
|
+
case 35:
|
|
1047
|
+
_h = '无收件人';
|
|
1048
|
+
_p.label = 36;
|
|
1049
|
+
case 36:
|
|
1050
|
+
microResult = _h;
|
|
1051
|
+
_p.label = 37;
|
|
1052
|
+
case 37:
|
|
1053
|
+
_p.trys.push([37, 53, , 54]);
|
|
1054
|
+
_p.label = 38;
|
|
1055
|
+
case 38:
|
|
1056
|
+
_p.trys.push([38, 43, 44, 45]);
|
|
1057
|
+
departmentUserIds_1 = tslib_1.__values(departmentUserIds_2), departmentUserIds_1_1 = departmentUserIds_1.next();
|
|
1058
|
+
_p.label = 39;
|
|
1059
|
+
case 39:
|
|
1060
|
+
if (!!departmentUserIds_1_1.done) return [3, 42];
|
|
1061
|
+
userId = departmentUserIds_1_1.value;
|
|
1062
|
+
return [4, ctx.broker.call('notifications.add', {
|
|
1063
|
+
message: {
|
|
1064
|
+
name: "\u3010".concat(yearMonth, "\u3011\u6708\u5EA6\u62BD\u67E5\u7D20\u6750\u6C60\u5DF2\u751F\u6210\uFF0C\u8BF7\u8FDB\u884C\u8170\u90E8\u7D20\u6750\u62BD\u67E5"),
|
|
1065
|
+
body: '',
|
|
1066
|
+
related_to: { o: 'pepsico_spot_check_pool', ids: [pid] },
|
|
1067
|
+
related_name: pool.name || yearMonth,
|
|
1068
|
+
from: user.userId,
|
|
1069
|
+
space: pool.space
|
|
1070
|
+
},
|
|
1071
|
+
from: user.userId,
|
|
1072
|
+
to: userId
|
|
1073
|
+
})];
|
|
1074
|
+
case 40:
|
|
1075
|
+
_p.sent();
|
|
1076
|
+
_p.label = 41;
|
|
1077
|
+
case 41:
|
|
1078
|
+
departmentUserIds_1_1 = departmentUserIds_1.next();
|
|
1079
|
+
return [3, 39];
|
|
1080
|
+
case 42: return [3, 45];
|
|
1081
|
+
case 43:
|
|
1082
|
+
e_7_1 = _p.sent();
|
|
1083
|
+
e_7 = { error: e_7_1 };
|
|
1084
|
+
return [3, 45];
|
|
1085
|
+
case 44:
|
|
1086
|
+
try {
|
|
1087
|
+
if (departmentUserIds_1_1 && !departmentUserIds_1_1.done && (_m = departmentUserIds_1.return)) _m.call(departmentUserIds_1);
|
|
1088
|
+
}
|
|
1089
|
+
finally { if (e_7) throw e_7.error; }
|
|
1090
|
+
return [7];
|
|
1091
|
+
case 45:
|
|
1092
|
+
_p.trys.push([45, 50, 51, 52]);
|
|
1093
|
+
specialistUserIds_1 = tslib_1.__values(specialistUserIds_2), specialistUserIds_1_1 = specialistUserIds_1.next();
|
|
1094
|
+
_p.label = 46;
|
|
1095
|
+
case 46:
|
|
1096
|
+
if (!!specialistUserIds_1_1.done) return [3, 49];
|
|
1097
|
+
userId = specialistUserIds_1_1.value;
|
|
1098
|
+
return [4, ctx.broker.call('notifications.add', {
|
|
1099
|
+
message: {
|
|
1100
|
+
name: "\u3010".concat(yearMonth, "\u3011\u6708\u5EA6\u62BD\u67E5\u7D20\u6750\u6C60\u5DF2\u751F\u6210\uFF0C\u8BF7\u8FDB\u884C\u5C3E\u90E8\u7D20\u6750\u62BD\u67E5"),
|
|
1101
|
+
body: '',
|
|
1102
|
+
related_to: { o: 'pepsico_spot_check_pool', ids: [pid] },
|
|
1103
|
+
related_name: pool.name || yearMonth,
|
|
1104
|
+
from: user.userId,
|
|
1105
|
+
space: pool.space
|
|
1106
|
+
},
|
|
1107
|
+
from: user.userId,
|
|
1108
|
+
to: userId
|
|
1109
|
+
})];
|
|
1110
|
+
case 47:
|
|
1111
|
+
_p.sent();
|
|
1112
|
+
_p.label = 48;
|
|
1113
|
+
case 48:
|
|
1114
|
+
specialistUserIds_1_1 = specialistUserIds_1.next();
|
|
1115
|
+
return [3, 46];
|
|
1116
|
+
case 49: return [3, 52];
|
|
1117
|
+
case 50:
|
|
1118
|
+
e_8_1 = _p.sent();
|
|
1119
|
+
e_8 = { error: e_8_1 };
|
|
1120
|
+
return [3, 52];
|
|
1121
|
+
case 51:
|
|
1122
|
+
try {
|
|
1123
|
+
if (specialistUserIds_1_1 && !specialistUserIds_1_1.done && (_o = specialistUserIds_1.return)) _o.call(specialistUserIds_1);
|
|
1124
|
+
}
|
|
1125
|
+
finally { if (e_8) throw e_8.error; }
|
|
1126
|
+
return [7];
|
|
1127
|
+
case 52: return [3, 54];
|
|
1128
|
+
case 53:
|
|
1129
|
+
error_8 = _p.sent();
|
|
1130
|
+
console.log('站内通知发送失败:', error_8);
|
|
1131
|
+
return [3, 54];
|
|
1132
|
+
case 54: return [4, ctx.getObject('pepsico_spot_check_pool').directUpdate(pid, {
|
|
1133
|
+
mail_send: true,
|
|
1134
|
+
mail_send_date: new Date(),
|
|
1135
|
+
mid_tier_pepsico_material: (0, lodash_1.map)(pools['Mid-tier'].samplingPool, '_id'),
|
|
1136
|
+
micro_pepsico_material: (0, lodash_1.map)(pools['Micro'].samplingPool, '_id'),
|
|
1137
|
+
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
|
+
})];
|
|
1139
|
+
case 55:
|
|
1140
|
+
_p.sent();
|
|
1141
|
+
return [3, 57];
|
|
1142
|
+
case 56:
|
|
1143
|
+
error_9 = _p.sent();
|
|
1144
|
+
console.error('执行失败:', error_9);
|
|
1145
|
+
return [3, 57];
|
|
1146
|
+
case 57: return [2];
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
exports.remindSpotCheckIncomplete = {
|
|
1153
|
+
rest: {
|
|
1154
|
+
method: "GET",
|
|
1155
|
+
path: "/remind/spot-check-incomplete"
|
|
1156
|
+
},
|
|
1157
|
+
handler: function (ctx) {
|
|
1158
|
+
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, user, 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
|
+
var e_11, _c, e_12, _d, e_13, _e, e_14, _f, e_15, _g, e_10, _h;
|
|
1161
|
+
return tslib_1.__generator(this, function (_j) {
|
|
1162
|
+
switch (_j.label) {
|
|
1163
|
+
case 0:
|
|
1164
|
+
yearMonth = moment().format('YYYY-MM');
|
|
1165
|
+
console.log("[remindSpotCheckIncomplete] \u5F00\u59CB\u626B\u63CF ".concat(yearMonth, " \u672A\u5B8C\u6210\u62BD\u67E5\u4EFB\u52A1..."));
|
|
1166
|
+
pendingUsers = new Map();
|
|
1167
|
+
return [4, ctx.getObject('pepsico_material').find({
|
|
1168
|
+
filters: [
|
|
1169
|
+
['spot_check_pool_year_month', '=', yearMonth],
|
|
1170
|
+
['spot_checked', '=', true],
|
|
1171
|
+
['spot_checked_done', '!=', true],
|
|
1172
|
+
['spot_check_type', '=', '四部门抽查']
|
|
1173
|
+
]
|
|
1174
|
+
})];
|
|
1175
|
+
case 1:
|
|
1176
|
+
midTierMaterials = _j.sent();
|
|
1177
|
+
console.log("[remindSpotCheckIncomplete] \u8170\u90E8\u672A\u5B8C\u6210\u7D20\u6750: ".concat(midTierMaterials.length));
|
|
1178
|
+
try {
|
|
1179
|
+
for (midTierMaterials_1 = tslib_1.__values(midTierMaterials), midTierMaterials_1_1 = midTierMaterials_1.next(); !midTierMaterials_1_1.done; midTierMaterials_1_1 = midTierMaterials_1.next()) {
|
|
1180
|
+
material = midTierMaterials_1_1.value;
|
|
1181
|
+
deptFields = [
|
|
1182
|
+
{ done: 'legal_spot_check', user: 'legal_spot_check_user' },
|
|
1183
|
+
{ done: 'ns_spot_check', user: 'ns_spot_check_user' },
|
|
1184
|
+
{ done: 'sra_spot_check', user: 'sra_spot_check_user' },
|
|
1185
|
+
{ done: 'ca_spot_check', user: 'ca_spot_check_user' },
|
|
1186
|
+
];
|
|
1187
|
+
try {
|
|
1188
|
+
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, user = _a.user;
|
|
1190
|
+
if (!material[done] && material[user]) {
|
|
1191
|
+
users = Array.isArray(material[user]) ? material[user] : [material[user]];
|
|
1192
|
+
try {
|
|
1193
|
+
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
|
+
uid = users_2_1.value;
|
|
1195
|
+
if (uid) {
|
|
1196
|
+
existing = pendingUsers.get(uid) || { count: 0, type: '四部门抽查' };
|
|
1197
|
+
existing.count++;
|
|
1198
|
+
pendingUsers.set(uid, existing);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1203
|
+
finally {
|
|
1204
|
+
try {
|
|
1205
|
+
if (users_2_1 && !users_2_1.done && (_e = users_2.return)) _e.call(users_2);
|
|
1206
|
+
}
|
|
1207
|
+
finally { if (e_13) throw e_13.error; }
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
1213
|
+
finally {
|
|
1214
|
+
try {
|
|
1215
|
+
if (deptFields_1_1 && !deptFields_1_1.done && (_d = deptFields_1.return)) _d.call(deptFields_1);
|
|
1216
|
+
}
|
|
1217
|
+
finally { if (e_12) throw e_12.error; }
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1222
|
+
finally {
|
|
1223
|
+
try {
|
|
1224
|
+
if (midTierMaterials_1_1 && !midTierMaterials_1_1.done && (_c = midTierMaterials_1.return)) _c.call(midTierMaterials_1);
|
|
1225
|
+
}
|
|
1226
|
+
finally { if (e_11) throw e_11.error; }
|
|
1227
|
+
}
|
|
1228
|
+
return [4, ctx.getObject('pepsico_material').find({
|
|
1229
|
+
filters: [
|
|
1230
|
+
['spot_check_pool_year_month', '=', yearMonth],
|
|
1231
|
+
['spot_checked', '=', true],
|
|
1232
|
+
['spot_checked_done', '!=', true],
|
|
1233
|
+
['spot_check_type', '=', '审核专员抽查']
|
|
1234
|
+
]
|
|
1235
|
+
})];
|
|
1236
|
+
case 2:
|
|
1237
|
+
microMaterials = _j.sent();
|
|
1238
|
+
console.log("[remindSpotCheckIncomplete] \u5C3E\u90E8\u672A\u5B8C\u6210\u7D20\u6750: ".concat(microMaterials.length));
|
|
1239
|
+
try {
|
|
1240
|
+
for (microMaterials_1 = tslib_1.__values(microMaterials), microMaterials_1_1 = microMaterials_1.next(); !microMaterials_1_1.done; microMaterials_1_1 = microMaterials_1.next()) {
|
|
1241
|
+
material = microMaterials_1_1.value;
|
|
1242
|
+
if (!material.guding_spot_check && material.guding_spot_check_user) {
|
|
1243
|
+
users = Array.isArray(material.guding_spot_check_user) ? material.guding_spot_check_user : [material.guding_spot_check_user];
|
|
1244
|
+
try {
|
|
1245
|
+
for (users_3 = (e_15 = void 0, tslib_1.__values(users)), users_3_1 = users_3.next(); !users_3_1.done; users_3_1 = users_3.next()) {
|
|
1246
|
+
uid = users_3_1.value;
|
|
1247
|
+
if (uid) {
|
|
1248
|
+
existing = pendingUsers.get(uid) || { count: 0, type: '审核专员抽查' };
|
|
1249
|
+
existing.count++;
|
|
1250
|
+
pendingUsers.set(uid, existing);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1255
|
+
finally {
|
|
1256
|
+
try {
|
|
1257
|
+
if (users_3_1 && !users_3_1.done && (_g = users_3.return)) _g.call(users_3);
|
|
1258
|
+
}
|
|
1259
|
+
finally { if (e_15) throw e_15.error; }
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1265
|
+
finally {
|
|
1266
|
+
try {
|
|
1267
|
+
if (microMaterials_1_1 && !microMaterials_1_1.done && (_f = microMaterials_1.return)) _f.call(microMaterials_1);
|
|
1268
|
+
}
|
|
1269
|
+
finally { if (e_14) throw e_14.error; }
|
|
1270
|
+
}
|
|
1271
|
+
if (pendingUsers.size === 0) {
|
|
1272
|
+
console.log("[remindSpotCheckIncomplete] \u5F53\u6708\u65E0\u672A\u5B8C\u6210\u62BD\u67E5\u4EFB\u52A1\uFF0C\u65E0\u9700\u50AC\u529E\u3002");
|
|
1273
|
+
return [2, { success: true, message: '无未完成抽查任务' }];
|
|
1274
|
+
}
|
|
1275
|
+
console.log("[remindSpotCheckIncomplete] \u9700\u50AC\u529E\u7528\u6237\u6570: ".concat(pendingUsers.size));
|
|
1276
|
+
ROOT_URL = process.env.ROOT_URL;
|
|
1277
|
+
midTierLink = "".concat(ROOT_URL, "/app/pepsico_content_review/pepsico_midtier_spot_check");
|
|
1278
|
+
microLink = "".concat(ROOT_URL, "/app/pepsico_content_review/pepsico_spot_check");
|
|
1279
|
+
subject = '【催办通知】您有未完成的抽查任务';
|
|
1280
|
+
results = [];
|
|
1281
|
+
userIds = Array.from(pendingUsers.keys());
|
|
1282
|
+
return [4, ctx.getObject('space_users').find({ filters: ['user', 'in', userIds] })];
|
|
1283
|
+
case 3:
|
|
1284
|
+
spaceUsers = _j.sent();
|
|
1285
|
+
_loop_2 = function (userId, info) {
|
|
1286
|
+
var spaceUser, link, html, error_10, error_11;
|
|
1287
|
+
return tslib_1.__generator(this, function (_k) {
|
|
1288
|
+
switch (_k.label) {
|
|
1289
|
+
case 0:
|
|
1290
|
+
spaceUser = (0, lodash_1.find)(spaceUsers, function (u) { return u.user === userId; });
|
|
1291
|
+
if (!spaceUser)
|
|
1292
|
+
return [2, "continue"];
|
|
1293
|
+
link = info.type === '四部门抽查' ? midTierLink : microLink;
|
|
1294
|
+
html = "\n <p>\u4EB2\u7231\u7684\u5BA1\u6838\u8001\u5E08\uFF0C</p>\n <p>\u60A8\u5728\u3010".concat(yearMonth, "\u3011\u62BD\u67E5\u5E93\u4E2D\u4ECD\u6709 <b>").concat(info.count, "</b> \u4E2A\u7D20\u6750\u5C1A\u672A\u5B8C\u6210\u62BD\u67E5\uFF0C\u8BF7\u5728\u6708\u5E95\u524D\u5B8C\u6210\u3002</p>\n <p>\u8BF7\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u8FDB\u5165\u62BD\u67E5\u9875\u9762\uFF1A</p>\n <p><a href=\"").concat(link, "\">\u70B9\u51FB\u8FDB\u5165\u62BD\u67E5</a></p>\n <p>\u5982\u6709\u7591\u95EE\uFF0C\u8BF7\u8054\u7CFB\u7CFB\u7EDF\u7BA1\u7406\u5458\u3002</p>\n ");
|
|
1295
|
+
if (!(spaceUser.email && spaceUser.email.endsWith('@pepsico.com'))) return [3, 4];
|
|
1296
|
+
_k.label = 1;
|
|
1297
|
+
case 1:
|
|
1298
|
+
_k.trys.push([1, 3, , 4]);
|
|
1299
|
+
return [4, sendEmail(process.env.B6_EMAIL_FROM, spaceUser.email, subject, '', html, '')];
|
|
1300
|
+
case 2:
|
|
1301
|
+
_k.sent();
|
|
1302
|
+
results.push({ userId: userId, email: spaceUser.email, status: 'sent' });
|
|
1303
|
+
return [3, 4];
|
|
1304
|
+
case 3:
|
|
1305
|
+
error_10 = _k.sent();
|
|
1306
|
+
console.log("[remindSpotCheckIncomplete] \u90AE\u4EF6\u53D1\u9001\u5931\u8D25: ".concat(spaceUser.email), error_10);
|
|
1307
|
+
results.push({ userId: userId, email: spaceUser.email, status: 'failed' });
|
|
1308
|
+
return [3, 4];
|
|
1309
|
+
case 4:
|
|
1310
|
+
_k.trys.push([4, 6, , 7]);
|
|
1311
|
+
return [4, ctx.broker.call('notifications.add', {
|
|
1312
|
+
message: {
|
|
1313
|
+
name: "\u3010\u50AC\u529E\u3011\u60A8\u6709 ".concat(info.count, " \u4E2A\u7D20\u6750\u672A\u5B8C\u6210\u62BD\u67E5\uFF0C\u8BF7\u5C3D\u5FEB\u5904\u7406"),
|
|
1314
|
+
body: '',
|
|
1315
|
+
related_to: { o: 'pepsico_material', ids: [] },
|
|
1316
|
+
related_name: "".concat(yearMonth, " \u62BD\u67E5\u50AC\u529E"),
|
|
1317
|
+
from: spaceUser.user,
|
|
1318
|
+
space: spaceUser.space
|
|
1319
|
+
},
|
|
1320
|
+
from: spaceUser.user,
|
|
1321
|
+
to: userId
|
|
1322
|
+
})];
|
|
1323
|
+
case 5:
|
|
1324
|
+
_k.sent();
|
|
1325
|
+
return [3, 7];
|
|
1326
|
+
case 6:
|
|
1327
|
+
error_11 = _k.sent();
|
|
1328
|
+
console.log("[remindSpotCheckIncomplete] \u7AD9\u5185\u901A\u77E5\u53D1\u9001\u5931\u8D25: ".concat(userId), error_11);
|
|
1329
|
+
return [3, 7];
|
|
1330
|
+
case 7: return [2];
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
};
|
|
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
|
+
_j.label = 5;
|
|
1339
|
+
case 5:
|
|
1340
|
+
if (!!pendingUsers_1_1.done) return [3, 8];
|
|
1341
|
+
_b = tslib_1.__read(pendingUsers_1_1.value, 2), userId = _b[0], info = _b[1];
|
|
1342
|
+
return [5, _loop_2(userId, info)];
|
|
1343
|
+
case 6:
|
|
1344
|
+
_j.sent();
|
|
1345
|
+
_j.label = 7;
|
|
1346
|
+
case 7:
|
|
1347
|
+
pendingUsers_1_1 = pendingUsers_1.next();
|
|
1348
|
+
return [3, 5];
|
|
1349
|
+
case 8: return [3, 11];
|
|
1350
|
+
case 9:
|
|
1351
|
+
e_10_1 = _j.sent();
|
|
1352
|
+
e_10 = { error: e_10_1 };
|
|
1353
|
+
return [3, 11];
|
|
1354
|
+
case 10:
|
|
1355
|
+
try {
|
|
1356
|
+
if (pendingUsers_1_1 && !pendingUsers_1_1.done && (_h = pendingUsers_1.return)) _h.call(pendingUsers_1);
|
|
1357
|
+
}
|
|
1358
|
+
finally { if (e_10) throw e_10.error; }
|
|
1359
|
+
return [7];
|
|
1360
|
+
case 11:
|
|
1361
|
+
console.log("[remindSpotCheckIncomplete] \u50AC\u529E\u5B8C\u6210\u3002\u7ED3\u679C:", results);
|
|
1362
|
+
return [2, { success: true, yearMonth: yearMonth, totalUsers: pendingUsers.size, results: results }];
|
|
1012
1363
|
}
|
|
1013
1364
|
});
|
|
1014
1365
|
});
|