| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /**
- * 紧急修复 / 校验:sjnmtybt_jebz (1966) 字段元数据。
- * 注意:若物理列已存在,勿再走 addfieldList(会 ALTER 失败 500);只写 fieldList。
- */
- const http = require("http");
- const qs = require("querystring");
- const fs = require("fs");
- const path = require("path");
- const HOST = "121.43.55.7";
- const PORT = 2101;
- const MODEL_ID = 1966;
- function post(urlPath, fields, token) {
- return new Promise((resolve, reject) => {
- const body = qs.stringify(fields || {});
- const headers = {
- "Content-Type": "application/x-www-form-urlencoded",
- "Content-Length": Buffer.byteLength(body),
- };
- if (token) {
- headers.Token = token;
- headers.token = token;
- }
- const req = http.request(
- { hostname: HOST, port: PORT, path: urlPath, method: "POST", headers },
- (res) => {
- let data = "";
- res.on("data", (c) => (data += c));
- res.on("end", () => {
- try {
- resolve(JSON.parse(data));
- } catch (e) {
- resolve({ raw: data, status: res.statusCode });
- }
- });
- }
- );
- req.on("error", reject);
- req.write(body);
- req.end();
- });
- }
- function text(shortName, alias, must, seq) {
- return {
- alias,
- customType: "",
- describe: "格式为富文本",
- frontType: "content",
- id: 2,
- must: !!must,
- name: "c_" + shortName,
- searchType: "2",
- sequence: seq || 1,
- showParam: "name,alias,desc,type,front_type,must,default_value",
- type: "text",
- };
- }
- function num(shortName, alias, must, seq) {
- return {
- alias,
- customType: "",
- describe: "number",
- frontType: "float_num",
- id: 6,
- must: !!must,
- name: "c_" + shortName,
- searchType: "1,3",
- sequence: seq || 5,
- showParam: "name,alias,desc,type,front_type,must,default_value",
- sortType: "1,2",
- type: "double",
- };
- }
- function ts(shortName, alias, must, seq) {
- return {
- alias,
- customType: "",
- describe: "时间戳",
- frontType: "date_time",
- id: 3,
- must: !!must,
- name: "c_" + shortName,
- searchType: "3",
- sequence: seq || 2,
- showParam: "name,alias,describe,type,front_type,must,date_type,date_picker",
- sortType: "1,2",
- type: "timestamp",
- };
- }
- function normalizeFieldList(raw) {
- let fl = raw;
- if (typeof fl === "string") fl = JSON.parse(fl);
- const out = {};
- Object.keys(fl || {}).forEach((k) => {
- let v = fl[k];
- if (typeof v === "string") v = JSON.parse(v);
- out[k] = v;
- });
- return out;
- }
- (async () => {
- const login = await post("/proxy_oauth/user/login", {
- userName: "user_liu",
- password: "WE176852439@lmx",
- clientId: "1",
- });
- if (login.code != 200) throw new Error("login fail " + JSON.stringify(login));
- const token = login.message;
- const desired = {
- c_amount: num("amount", "金额", true, 5),
- c_date_time: ts("date_time", "生效时间", true, 6),
- c_remarks: text("remarks", "备注", false, 7),
- c_town_id: text("town_id", "街镇ID", true, 9),
- c_standard_type: text("standard_type", "标准类型", true, 10),
- c_expire_time: ts("expire_time", "失效时间", false, 11),
- c_current_flag: text("current_flag", "是否当前有效", true, 12),
- c_adjust_reason: text("adjust_reason", "调整原因", false, 13),
- c_funeral_amount: num("funeral_amount", "丧葬金额", false, 14),
- };
- const res = await post(
- "/proxy_dms/model/updateFieldList",
- {
- modelId: String(MODEL_ID),
- fieldList: JSON.stringify(desired),
- addfieldList: JSON.stringify({}),
- delfieldList: JSON.stringify({}),
- updatefieldList: JSON.stringify({}),
- },
- token
- );
- const verify = await post("/proxy_dms/model/getModelById", { modelId: String(MODEL_ID) }, token);
- const fields = Object.keys(normalizeFieldList(verify.content.fieldList)).sort();
- const out = {
- update: { code: res.code, message: res.message || res.content },
- fields,
- ok:
- fields.includes("c_amount") &&
- fields.includes("c_town_id") &&
- fields.includes("c_funeral_amount") &&
- fields.includes("c_standard_type"),
- };
- fs.writeFileSync(path.join(__dirname, "restore-jebz-model-fields-result.json"), JSON.stringify(out, null, 2));
- console.log(JSON.stringify(out, null, 2));
- if (!out.ok) process.exit(1);
- })().catch((e) => {
- console.error(e);
- process.exit(1);
- });
|