/** * 金额标准 sjnmtybt_jebz (modelId=1966) 增加 c_funeral_amount(丧葬金额), * 支撑「年度标准」一行双金额(土地 c_amount + 丧葬 c_funeral_amount)。 */ 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, method) { 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: 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 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 normalizeFieldList(raw) { let fl = raw; if (typeof fl === "string") { try { fl = JSON.parse(fl); } catch (e) { return {}; } } const out = {}; Object.keys(fl || {}).forEach((k) => { let v = fl[k]; if (typeof v === "string") { try { v = JSON.parse(v); } catch (e) { return; } } out[k] = v; }); return out; } async function login() { const res = await post("/proxy_oauth/user/login", { userName: "user_liu", password: "WE176852439@lmx", clientId: "1", }); if (res.code != 200) throw new Error("login failed: " + JSON.stringify(res)); return res.message; } async function getModel(token, modelId) { const res = await post("/proxy_dms/model/getModelById", { modelId: String(modelId) }, token); if (res.code != 200) throw new Error("getModelById fail: " + JSON.stringify(res)); return res.content; } async function main() { const token = await login(); const model = await getModel(token, MODEL_ID); const fieldList = normalizeFieldList(model.fieldList); if (Object.keys(fieldList).length < 5) { throw new Error( "fieldList 异常(仅 " + Object.keys(fieldList).length + " 个字段),请先运行 restore-jebz-model-fields.js,避免再次覆盖模型。" ); } const addfieldList = {}; const shortName = "funeral_amount"; const full = "c_" + shortName; if (!fieldList[full]) { const p = num(shortName, "丧葬金额", false, 14); fieldList[full] = p; addfieldList[shortName] = { alias: p.alias, type: p.type, frontType: p.frontType, must: p.must, name: shortName, describe: p.describe, searchType: p.searchType, sortType: p.sortType, sequence: p.sequence, showParam: p.showParam, customType: "", id: p.id, }; } const payload = { modelId: String(MODEL_ID), fieldList: JSON.stringify(fieldList), addfieldList: JSON.stringify(addfieldList), delfieldList: JSON.stringify({}), updatefieldList: JSON.stringify({}), }; const res = await post("/proxy_dms/model/updateFieldList", payload, token); const verify = await getModel(token, MODEL_ID); const fields = Object.keys(normalizeFieldList(verify.fieldList)).sort(); const out = { update: { code: res.code, message: res.message || res.content, added: Object.keys(addfieldList) }, fields, hasFuneralAmount: fields.includes("c_funeral_amount"), }; const outPath = path.join(__dirname, "migrate-jebz-funeral-amount-result.json"); fs.writeFileSync(outPath, JSON.stringify(out, null, 2), "utf8"); console.log(JSON.stringify(out, null, 2)); if (!out.hasFuneralAmount) process.exit(1); } main().catch((e) => { console.error(e); process.exit(1); });