/** * 创建特殊业务栏目 sjnmtybt_tsyw */ 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 PARENT_COLUMN_ID = 1840; 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 text(shortName, alias, must, seq) { return { alias, customType: "", describe: "格式为富文本", frontType: "content", id: 2, must: !!must, name: 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: shortName, searchType: "1,3", sequence: seq || 5, showParam: "name,alias,desc,type,front_type,must,default_value", sortType: "1,2", type: "double", }; } function flatten(nodes, out) { out = out || []; (nodes || []).forEach((n) => { out.push(n); if (n.columnList) flatten(n.columnList, out); }); 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"); const token = login.message; const cols = await post("/proxy_dms/column/getColumnList", {}, token); const exist = flatten(cols.content || []).find((c) => c.tag === "sjnmtybt_tsyw"); if (exist) { console.log("already exists", exist.id, exist.modelId); fs.writeFileSync( path.join(__dirname, "create-special-biz-column-result.json"), JSON.stringify({ columnId: exist.id, modelId: exist.modelId, existed: true }, null, 2) ); return; } const fieldList = { personnel_id: text("personnel_id", "人员ID", true, 1), name: text("name", "姓名", false, 2), batch_no: text("batch_no", "批次号", false, 3), biz_type: text("biz_type", "业务类型", true, 4), reason: text("reason", "原因", false, 5), amount: num("amount", "金额", false, 6), heir_name: text("heir_name", "继承人姓名", false, 7), heir_id_number: text("heir_id_number", "继承人身份证", false, 8), heir_bank_card: text("heir_bank_card", "继承人银行卡", false, 9), approve_status: text("approve_status", "审批状态", true, 10), opinion: text("opinion", "审批意见", false, 11), remarks: text("remarks", "备注", false, 12), }; const payload = { type: 1, parentId: String(PARENT_COLUMN_ID), tag: "sjnmtybt_tsyw", title: "特殊业务", content: "丧葬/暂停恢复/调标等特殊业务申请", state: 0, level: 0, "model.modelName": "special_biz", "model.modelAlias": "特殊业务", "model.pageSize": 20, "model.type": 1, "model.fieldList": JSON.stringify(fieldList), "model.searchField": "[]", "model.sortField": "[]", }; const res = await post("/proxy_dms/column/addColumn", payload, token, "PUT"); console.log(JSON.stringify(res).slice(0, 800)); const cols2 = await post("/proxy_dms/column/getColumnList", {}, token); const created = flatten(cols2.content || []).find((c) => c.tag === "sjnmtybt_tsyw"); const out = { addResult: { code: res.code, message: res.message, content: res.content }, columnId: created && created.id, modelId: created && created.modelId, }; fs.writeFileSync(path.join(__dirname, "create-special-biz-column-result.json"), JSON.stringify(out, null, 2)); console.log("DONE", out); })().catch((e) => { console.error(e); process.exit(1); });