run-away-from-sdu
Version:
山大? 快润! 山东大学一键申请出校脚本
227 lines (226 loc) • 14.3 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyGoOut = exports.getCustomizedFormData = exports.getFormTplStr = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const axios_1 = __importDefault(require("axios"));
const moment_1 = __importDefault(require("moment"));
/**
* 从服务中心获取并处理得到最新的表单模板
* @param Cookie
* @returns 表单字符串模板
*/
const getFormTplStr = (Cookie) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
// 获取出校申请表单模板
const res = yield (0, axios_1.default)('https://scenter.sdu.edu.cn/tp_fp/formParser?status=select&formid=d05bb8b4-4a36-4e13-8d73-f681e03e&service_id=87dc6da9-9ad8-4458-9654-90823be0d5f6&process=c5c3de57-4044-43e9-bc25-f88206c0c74d&seqId=&seqPid=&privilegeId=2476634395f5754441ad9f3090319790', {
method: 'GET',
headers: { Cookie },
});
const formTplStr = (_a = /<script type="text\/tpl" id="dcstr">(.+?)<\/script>/g.exec(res.data)) === null || _a === void 0 ? void 0 : _a[1];
// eslint-disable-next-line prefer-const
let formTpl = {};
if (formTplStr) {
// 得到的模板字符串不是标准的JSON格式,直接通过eval获取对象
eval('formTpl =' + formTplStr);
}
else
throw new Error('无法获取表单模板');
// 将_record历史数据作为新表单中填写的数据
Object.keys(formTpl.body.dataStores).forEach((key) => {
if (key.endsWith('_record')) {
// deep clone _record字段
formTpl.body.dataStores[key.replace(/_record/g, '')] = JSON.parse(JSON.stringify(formTpl.body.dataStores[key]));
// 校正表单参数
formTpl.body.dataStores[key.replace(/_record/g, '')].name = key.replace(/_record/g, '');
// 通过diff发现新表单还要订正以下数据,别问 问就是不知道这些字段啥意思
if (key.includes('-')) {
formTpl.body.dataStores[key.replace(/_record/g, '')].recordCount = 1;
formTpl.body.dataStores[key.replace(/_record/g, '')].rowSet.primary[0]['_o'] = {
StudentIdNo: null,
user_name: null,
gender: null,
age: null,
unit_name: null,
major: null,
phone: null,
xslx: null,
jjlxrxm: null,
jjlxdh: null,
fayxm_TEXT: null,
fayxm: null,
fdydh: null,
CRXQ_TEXT: null,
CRXQ: null,
SFLKHCQ: null,
wclx: null,
wcsy: null,
jtsyms: null,
wcmdd: null,
wcxq_TEXT: null,
wcxq: null,
wcmddbc: null,
SF_TEXT: null,
SF: null,
SQ_TEXT: null,
SQ: null,
XS_TEXT: null,
XS: null,
XXDZ: null,
CZJTGJ_TEXT: null,
CZJTGJ: null,
BC: null,
sfxwzs: null,
xwzsdz: null,
cxrq: null,
cxsj_TEXT: null,
cxsj: null,
CXSJT: null,
FXSJT: null,
CXSJTEXT: null,
FXSJTEXT: null,
fxrq: null,
fxsj_TEXT: null,
fxsj: null,
GDCRCXSJ: null,
GDCRFXSJ: null,
yjstx: null,
cn: null,
SFZXPD: null,
JJBG: null,
GKYJ: null,
WCTS: null,
LXSJ01: null,
zts: null,
fdysh: null,
pdgq: null,
xqsd: null,
GJXYXS: null,
DSPPD: null,
YYPXS: null,
};
delete formTpl.body.dataStores[key.replace(/_record/g, '')].rowSet
.primary[0].pk_id;
delete formTpl.body.dataStores[key.replace(/_record/g, '')].rowSet
.primary[0].fk_id;
delete formTpl.body.dataStores[key.replace(/_record/g, '')].parameters
.exist;
}
}
});
// 继续订正一些数据
delete formTpl.body.parameters.record_fk;
formTpl.body.parameters.strUserId = '';
formTpl.body.parameters.strUserIdCC = '';
formTpl.body.parameters.nextActId = '';
return JSON.stringify(formTpl);
});
exports.getFormTplStr = getFormTplStr;
/**
* 获取用特定日期定制后的完整表单数据
* @param formTplStr 表单字符串模板
* @param dateTimeStp 要定制的申请日期时间戳
* @returns 用特定日期定制后的表单数据
*/
const getCustomizedFormData = (formTplStr, dateTimeStp // 要申请日期的时间戳
) => __awaiter(void 0, void 0, void 0, function* () {
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
let res = formTplStr;
// 以下信息均从上次申请的记录中取
const fdyId = ((_b = /"fdysh":"0,(\d*)"/.exec(res)) === null || _b === void 0 ? void 0 : _b[1]) || ''; // 辅导员工号
const sflx = ((_c = /"name":".+?.SFLX","value":"(.+?)"/.exec(res)) === null || _c === void 0 ? void 0 : _c[1]) || ''; // 学生类型
const wcsy = ((_d = /"wcsy":"(.+?)"/.exec(res)) === null || _d === void 0 ? void 0 : _d[1]) || ''; // 外出类型
const date = (0, moment_1.default)(new Date(dateTimeStp)).format('YYYY-MM-DD').toString();
const xq = ((_e = /"xqsd":"(.+?)"/.exec(res)) === null || _e === void 0 ? void 0 : _e[1]) || ''; // 校区
const dw = ((_f = /"unit_name":"(.+?)"/.exec(res)) === null || _f === void 0 ? void 0 : _f[1]) || ''; // 单位
const xm = ((_g = /"user_name":"(.+?)"/.exec(res)) === null || _g === void 0 ? void 0 : _g[1]) || ''; // 姓名
const xh = ((_h = /"StudentIdNo":"(.+?)"/.exec(res)) === null || _h === void 0 ? void 0 : _h[1]) || ''; // 学号
const crxq = ((_j = /"CRXQ":"(.+?)"/.exec(res)) === null || _j === void 0 ? void 0 : _j[1]) || ''; // 出入校区
const dsppd = ((_k = /"DSPPD":"(.+?)"/.exec(res)) === null || _k === void 0 ? void 0 : _k[1]) || '';
const yypxs = ((_l = /"YYPXS":"(.+?)"/.exec(res)) === null || _l === void 0 ? void 0 : _l[1]) || '';
const jtsyms = ((_m = /"jtsyms":"(.+?)"/.exec(res)) === null || _m === void 0 ? void 0 : _m[1]) || ''; // 出校理由
res = res
.replace(/"name":"zts","source":"process","type":"string","value":""/g, '"name":"zts","source":"process","type":"string","value":"0","_t": 1,"_o": { "value": "" }')
.replace(/"name":"GJXYXS","source":"process","type":"string","value":""/g, '"name":"GJXYXS","source":"process","type":"string","value":"","_t": 1')
.replace(/"name":"PDGQ","source":"process","type":"string","value":""/g, '"name":"PDGQ","source":"process","type":"string","value":"","_t": 1')
.replace(/"name":"JJBG","source":"process","type":"string","value":""/g, `"name":"JJBG","source":"process","type":"string","value":"0","_t": 1,"_o": { "value": "" }` // 补全辅导员工号
)
.replace(/"name":"GKYJ","source":"process","type":"string","value":""/g, `"name":"GKYJ","source":"process","type":"string","value":"0","_t": 1,"_o": { "value": "" }` // 补全辅导员工号
)
.replace(/"name":"FDYSH","source":"process","type":"string","value":""/g, `"name":"FDYSH","source":"process","type":"string","value":"0,${fdyId}","_t": 1,"_o": { "value": "" }` // 补全辅导员工号
)
.replace(/"name":"SFLX","source":"process","type":"string","value":""/g, `"name":"SFLX","source":"process","type":"string","value":"${sflx}","_t": 1,"_o": { "value": "" }` // 补全学生类型
)
.replace(/"name":"CRXQ","source":"process","type":"string","value":""/g, `"name":"CRXQ","source":"process","type":"string","value":"${crxq}","_t": 1,"_o": { "value": "" }` // 补全出入校区
)
.replace(/"name":"WCSY","source":"process","type":"string","value":""/g, `"name":"WCSY","source":"process","type":"string","value":"${wcsy}","_t": 1,"_o": { "value": "" }` // 补全外出类型
)
.replace(/"name":"WCTS","source":"process","type":"string","value":""/g, `"name":"WCTS","source":"process","type":"string","value":"0","_t": 1,"_o": { "value": "" }`)
.replace(/"name":"FXSJT","source":"process","type":"string","value":""/g, `"name":"FXSJT","source":"process","type":"string","value":"${date}","_t": 1,"_o": { "value": "" }` // 返校日期
)
.replace(/\d{4}-\d{2}-\d{2}/g, date) // 全局日期替换
.replace(/"fxrq":".+?",/g, `"fxrq":"${date}",`)
.replace(/"cxrq":".+?",/g, `"cxrq":"${date}",`)
.replace(/"name":"FXSJTEXT","source":"process","type":"string","value":""/g, `"name":"FXSJTEXT","source":"process","type":"string","value":"22:00","_t": 1,"_o": { "value": "" }` // 返校时间
)
.replace(/"name":"XQ","source":"process","type":"string","value":""/g, `"name":"XQ","source":"process","type":"string","value":"${xq}","_t": 1,"_o": { "value": "" }` // 校区
)
.replace(/"name":"DW","source":"process","type":"string","value":""/g, `"name":"DW","source":"process","type":"string","value":"${dw}","_t": 1,"_o": { "value": "" }` // 单位
)
.replace(/"name":"CXSJT","source":"process","type":"string","value":""/g, `"name":"CXSJT","source":"process","type":"string","value":"${date}","_t": 1,"_o": { "value": "" }` // 出校日期
)
.replace(/"name":"CXSJTEXT","source":"process","type":"string","value":""/g, `"name":"CXSJTEXT","source":"process","type":"string","value":"04:00","_t": 1,"_o": { "value": "" }` // 出校时间
)
.replace(/"name":"JTSYMS","source":"process","type":"string","value":""/g, `"name":"JTSYMS","source":"process","type":"string","value":"${jtsyms}","_t": 1,"_o": { "value": "" }` // 出校理由
)
.replace(/"name":"XM","source":"process","type":"string","value":""/g, `"name":"XM","source":"process","type":"string","value":"${xm}","_t": 1,"_o": { "value": "" }` // 姓名
)
.replace(/"name":"WCMDD","source":"process","type":"string","value":""/g, `"name":"WCMDD","source":"process","type":"string","value":"本市 Local city","_t": 1,"_o": { "value": "" }` // 外出目的地
)
.replace(/"name":"XH","source":"process","type":"string","value":""/g, `"name":"XH","source":"process","type":"string","value":"${xh}","_t": 1,"_o": { "value": "" }` // 学号
)
.replace(/"name":"WCLX","source":"process","type":"string","value":""/g, `"name":"WCLX","source":"process","type":"string","value":"临时外出 Temporary out","_t": 1,"_o": { "value": "" }` // 外出类型
)
.replace(/"name":"SYS_USER","source":"process","type":"string","value":""/g, `"name":"SYS_USER","source":"process","type":"string","value":"${xm}"`)
.replace(/"name":"SYS_UNIT","source":"process","type":"string","value":""/g, `"name":"SYS_UNIT","source":"process","type":"string","value":"${dw}"`)
.replace(/"name":"SYS_DATE","source":"process","type":"string","value":""/g, `"name":"SYS_DATE","source":"process","type":"string","value":"${new Date().valueOf()}"`)
.replace(/"name":"DSPPD","source":"process","type":"string","value":""/g, `"name":"DSPPD","source":"process","type":"string","value":"${dsppd}","_t": 1,"_o": { "value": "" }`)
.replace(/"name":"SFLKHCQ","source":"process","type":"string","value":""/g, `"name":"SFLKHCQ","source":"process","type":"string","value":"","_t": 1`)
.replace(/"name":"YYPXS","source":"process","type":"string","value":""/g, `"name":"YYPXS","source":"process","type":"string","value":"${yypxs}","_t": 1,"_o": { "value": "" }`);
return res;
});
exports.getCustomizedFormData = getCustomizedFormData;
/**
* 提交单次出校申请
* @param formTplStr 表单字符串模板
* @param dateTimeStp 申请日期时间戳
* @param Cookie 服务中心的登录态Cookie
*/
const applyGoOut = (formTplStr, dateTimeStp, Cookie) => __awaiter(void 0, void 0, void 0, function* () {
const data = yield (0, exports.getCustomizedFormData)(formTplStr, dateTimeStp);
const res = yield (0, axios_1.default)('https://scenter.sdu.edu.cn/tp_fp/formParser?status=update&formid=d05bb8b4-4a36-4e13-8d73-f681e03e&workflowAction=startProcess&seqId=&unitId=&workitemid=&process=c5c3de57-4044-43e9-bc25-f88206c0c74d', {
method: 'POST',
headers: {
'content-type': 'text/plain;charset=UTF-8',
Cookie,
Referer: 'https://scenter.sdu.edu.cn/tp_fp/formParser?status=select&formid=d05bb8b4-4a36-4e13-8d73-f681e03e&service_id=87dc6da9-9ad8-4458-9654-90823be0d5f6&process=c5c3de57-4044-43e9-bc25-f88206c0c74d&seqId=&seqPid=&privilegeId=2476634395f5754441ad9f3090319790',
},
data,
});
if (!res.data.SYS_FK) {
console.error(res.data);
throw new Error(res.data.message || '申请失败,可能是表单信息失效');
}
});
exports.applyGoOut = applyGoOut;