UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

429 lines (426 loc) 11.8 kB
import { b as __awaiter, c as __generator, _ as __assign } from '../../tslib.es6-096fffdd.js'; import axios from 'axios'; import { getCredential } from './credential.mjs'; /** * 根据项目id获取分数信息 * @ignore * @param {object} options 参数 * @param {Array<number>} options.projectIdList 项目Id列表 * @param {string} options.date 日期,yyyyMMdd格式 * @param {object} options.secretInfo 密钥信息 * @param {string} options.secretInfo.apiKey apiKey * @param {string} options.secretInfo.loginName loginName * @param {Function} options.secretInfo.getPwdCode getPwdCode * @param {Function} options.secretInfo.encrypt encrypt * @returns {Promise<Array<object>>} 分数信息 * @example * getTAMScoreInfoByProjectId({ * projectId: 123123, * date: 20210106 * secretInfo: { * apiKey: '', * loginName: '', * getPwdCode() {}, * encrypt() {}, * } * }).then((data) => { * console.log(data) * }) * * [ * { * ProjectName: '社区', * PagePv: 99, * PageError: 0, * PageDuration: 1409.8333, * StaticFail: 8, * CreateTime: '', * ProjectId: 123123, * PageUv: 23, * ApiNum: 521, * ApiFail: 78, * ApiDuration: 1813.3333, * StaticNum: 1494, * StaticDuration: 103.75, * Score: 80.9167, * CreateUser: 'lee', * GroupName: 'aGroup', * }, * ] * */ function getTAMScoreInfoByProjectId(_a) { var _b; var projectId = _a.projectId, startDate = _a.startDate, secretInfo = _a.secretInfo; return __awaiter(this, void 0, void 0, function () { var credential, result; return __generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, getCredential(secretInfo)]; case 1: credential = _c.sent(); return [4 /*yield*/, axios({ method: 'GET', url: "/api/interface/pro/scoreInfo?projectID=".concat(projectId, "&startDate=").concat(startDate), headers: __assign({}, credential) })["catch"](function (err) { console.log('[getTAMScoreInfoByProjectId.err]', err); })]; case 2: result = _c.sent(); return [2 /*return*/, ((_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.message) || []]; } }); }); } /** * 根据 groupId 获取项目列表 * @ignore * @param {object} options 配置 * @param {number} options.groupId 小组Id * @param {object} options.secretInfo 密钥信息 * @param {string} options.secretInfo.apiKey apiKey * @param {string} options.secretInfo.loginName loginName * @param {Function} options.secretInfo.getPwdCode getPwdCode * @param {Function} options.secretInfo.encrypt encrypt * @returns {Promise<array<object>>} 项目列表 * @example * getProjectByGroupId({ * groupId: 1, * secretInfo: { * apiKey: '', * loginName: '', * getPwdCode() {}, * encrypt() {}, * } * }).then(resp => { * console.log(resp) * }) * [ * { * ID: 56564, * ProjectName: 'name', * ProjectDesc: 'desc', * ProjectKey: 'xxx', * ProjectType: 'web', * GroupId: 123, * GroupName: 'xxx', * GroupKey: 'xxx', * InstanceID: 'rum-xxx', * Url: '*.qq.com', * CodePath: '', * Rate: '100', * CreateUser: 'xxx', * EnableUrlGroup: true, * KafkaHost: '', * KafkaTopic: '', * KafkaVersion: '', * SaslUserName: '', * SaslPassword: '', * SaslMechanism: '', * IsFollow: false, * CreateTime: '2021-10-01T11:34:32+08:00', * }, * { * ID: 12345, * // ... * }, * ]; * */ function getProjectByGroupId(_a) { var _b; var groupId = _a.groupId, secretInfo = _a.secretInfo; return __awaiter(this, void 0, void 0, function () { var credential, result; return __generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, getCredential(secretInfo)]; case 1: credential = _c.sent(); return [4 /*yield*/, axios({ method: 'GET', url: "/api/interface/pro/list?groupID=".concat(groupId), headers: __assign({}, credential) })["catch"](function (err) { console.log('[getProjectByGroupId.err]', err); })]; case 2: result = _c.sent(); return [2 /*return*/, ((_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.result) || []]; } }); }); } /** * 根据 groupIdList 获取 projectList * @ignore * @param {object} options 配置 * @param {Array<number>} options.groupIdList 小组Id列表 * @param {object} options.secretInfo 密钥信息 * @param {string} options.secretInfo.apiKey apiKey * @param {string} options.secretInfo.loginName loginName * @param {Function} options.secretInfo.getPwdCode getPwdCode * @param {Function} options.secretInfo.encrypt encrypt * @returns {Array<object>} 项目列表 * @example * getAllProjectList({ * groupIdList: [1,2,3], * secretInfo: { * apiKey: '', * loginName: '', * getPwdCode() {}, * encrypt() {}, * } * }).then(resp => { * console.log('resp) * }) * [ * { * ID: 56564, * ProjectName: 'name', * ProjectDesc: 'desc', * ProjectKey: 'xxx', * ProjectType: 'web', * GroupId: 123, * GroupName: 'xxx', * GroupKey: 'xxx', * InstanceID: 'rum-xxx', * Url: '*.qq.com', * CodePath: '', * Rate: '100', * CreateUser: 'xxx', * EnableUrlGroup: true, * KafkaHost: '', * KafkaTopic: '', * KafkaVersion: '', * SaslUserName: '', * SaslPassword: '', * SaslMechanism: '', * IsFollow: false, * CreateTime: '2021-10-01T11:34:32+08:00', * }, * { * ID: 12345, * // ... * }, * ]; */ function getAllProjectList(_a) { var groupIdList = _a.groupIdList, secretInfo = _a.secretInfo; return __awaiter(this, void 0, void 0, function () { var res, _i, groupIdList_1, groupId, projectList; return __generator(this, function (_b) { switch (_b.label) { case 0: res = []; _i = 0, groupIdList_1 = groupIdList; _b.label = 1; case 1: if (!(_i < groupIdList_1.length)) return [3 /*break*/, 4]; groupId = groupIdList_1[_i]; return [4 /*yield*/, getProjectByGroupId({ groupId: groupId, secretInfo: secretInfo })]; case 2: projectList = _b.sent(); res.push.apply(res, projectList || []); _b.label = 3; case 3: _i++; return [3 /*break*/, 1]; case 4: return [2 /*return*/, res]; } }); }); } /** * 根据 projectIdList 获取一天的汇总分数 * @ignore * @param {object} options 参数 * @param {Array<number>} options.projectIdList 项目Id列表 * @param {string} options.date 日期,yyyyMMdd格式 * @param {object} options.secretInfo 密钥信息 * @param {string} options.secretInfo.apiKey apiKey * @param {string} options.secretInfo.loginName loginName * @param {Function} options.secretInfo.getPwdCode getPwdCode * @param {Function} options.secretInfo.encrypt encrypt * @returns {Promise<Array<object>>} 分数列表 * * @example * getSummaryScoreByProjectList({ * projectList: [], * date: 20210106 * secretInfo: { * apiKey: '', * loginName: '', * getPwdCode() {}, * encrypt() {}, * } * }).then((data) => { * console.log(data) * }) * * [ * { * ProjectName: 'name', * PagePv: 99, * PageError: 0, * PageDuration: 1409.8333, * StaticFail: 8, * CreateTime: '', * ProjectId: 123123, * PageUv: 23, * ApiNum: 521, * ApiFail: 78, * ApiDuration: 1813.3333, * StaticNum: 1494, * StaticDuration: 103.75, * Score: 80.9167, * CreateUser: 'xxx', * GroupName: 'xxx', * }, * { * // ... * } * ] */ function getSummaryScoreByProjectList(_a) { var projectList = _a.projectList, date = _a.date, secretInfo = _a.secretInfo; return __awaiter(this, void 0, void 0, function () { var res, _i, projectList_1, project, temp, projectInfo; return __generator(this, function (_b) { switch (_b.label) { case 0: res = []; _i = 0, projectList_1 = projectList; _b.label = 1; case 1: if (!(_i < projectList_1.length)) return [3 /*break*/, 4]; project = projectList_1[_i]; return [4 /*yield*/, getTAMScoreInfoByProjectId({ projectId: project.ID, startDate: date, secretInfo: secretInfo })]; case 2: temp = _b.sent(); projectInfo = __assign(__assign({}, project), temp[0] || {}); // 过滤掉没有数据的项目 if (!projectInfo.PagePv) { return [3 /*break*/, 3]; } res.push(projectInfo); _b.label = 3; case 3: _i++; return [3 /*break*/, 1]; case 4: return [2 /*return*/, res]; } }); }); } /** * 根据 groupIdList 获取汇总数据 * @ignore * @param {object} options 配置 * @param {string} options.date 日期,yyyyMMdd格式 * @param {Array<number>} options.groupIdList groupId列表 * @param {object} options.secretInfo 密钥信息 * @param {string} options.secretInfo.apiKey apiKey * @param {string} options.secretInfo.loginName loginName * @param {Function} options.secretInfo.getPwdCode getPwdCode * @param {Function} options.secretInfo.encrypt encrypt * @returns {Promise<({ data: object, projectIdList: Array<number> })>} 汇总数据 * @example * getTAMSummaryScoreByGroupIdList({ * groupIdList: [1,2,3], * date: '20210106', * secretInfo: { * apiKey: '', * loginName: '', * getPwdCode() {}, * encrypt() {}, * } * }).then(resp => { * console.log(resp) * }) * * { * data: * [ * { * ProjectName: '社区', * PagePv: 99, * PageError: 0, * PageDuration: 1409.8333, * StaticFail: 8, * CreateTime: '', * ProjectId: 123123, * PageUv: 23, * ApiNum: 521, * ApiFail: 78, * ApiDuration: 1813.3333, * StaticNum: 1494, * StaticDuration: 103.75, * Score: 80.9167, * CreateUser: 'lee', * GroupName: 'aGroup', * }, * { * ProjectId: 123, * // ... * }, * ], * projectIdList: [ * 123123, * 123, * ], * }; * */ function getTAMSummaryScoreByGroupIdList(_a) { var date = _a.date, groupIdList = _a.groupIdList, secretInfo = _a.secretInfo; return __awaiter(this, void 0, void 0, function () { var projectList, projectIdList, res; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, getAllProjectList({ groupIdList: groupIdList, secretInfo: secretInfo })]; case 1: projectList = _b.sent(); projectIdList = projectList.map(function (item) { return item.ID; }); return [4 /*yield*/, getSummaryScoreByProjectList({ date: date, projectList: projectList, secretInfo: secretInfo })]; case 2: res = _b.sent(); return [2 /*return*/, { data: res, projectIdList: projectIdList }]; } }); }); } export { getProjectByGroupId, getTAMScoreInfoByProjectId, getTAMSummaryScoreByGroupIdList };