create-special-biz-column.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * 创建特殊业务栏目 sjnmtybt_tsyw
  3. */
  4. const http = require("http");
  5. const qs = require("querystring");
  6. const fs = require("fs");
  7. const path = require("path");
  8. const HOST = "121.43.55.7";
  9. const PORT = 2101;
  10. const PARENT_COLUMN_ID = 1840;
  11. function post(urlPath, fields, token, method) {
  12. return new Promise((resolve, reject) => {
  13. const body = qs.stringify(fields || {});
  14. const headers = {
  15. "Content-Type": "application/x-www-form-urlencoded",
  16. "Content-Length": Buffer.byteLength(body),
  17. };
  18. if (token) {
  19. headers.Token = token;
  20. headers.token = token;
  21. }
  22. const req = http.request(
  23. { hostname: HOST, port: PORT, path: urlPath, method: method || "POST", headers },
  24. (res) => {
  25. let data = "";
  26. res.on("data", (c) => (data += c));
  27. res.on("end", () => {
  28. try {
  29. resolve(JSON.parse(data));
  30. } catch (e) {
  31. resolve({ raw: data, status: res.statusCode });
  32. }
  33. });
  34. }
  35. );
  36. req.on("error", reject);
  37. req.write(body);
  38. req.end();
  39. });
  40. }
  41. function text(shortName, alias, must, seq) {
  42. return {
  43. alias,
  44. customType: "",
  45. describe: "格式为富文本",
  46. frontType: "content",
  47. id: 2,
  48. must: !!must,
  49. name: shortName,
  50. searchType: "2",
  51. sequence: seq || 1,
  52. showParam: "name,alias,desc,type,front_type,must,default_value",
  53. type: "text",
  54. };
  55. }
  56. function num(shortName, alias, must, seq) {
  57. return {
  58. alias,
  59. customType: "",
  60. describe: "number",
  61. frontType: "float_num",
  62. id: 6,
  63. must: !!must,
  64. name: shortName,
  65. searchType: "1,3",
  66. sequence: seq || 5,
  67. showParam: "name,alias,desc,type,front_type,must,default_value",
  68. sortType: "1,2",
  69. type: "double",
  70. };
  71. }
  72. function flatten(nodes, out) {
  73. out = out || [];
  74. (nodes || []).forEach((n) => {
  75. out.push(n);
  76. if (n.columnList) flatten(n.columnList, out);
  77. });
  78. return out;
  79. }
  80. (async () => {
  81. const login = await post("/proxy_oauth/user/login", {
  82. userName: "user_liu",
  83. password: "WE176852439@lmx",
  84. clientId: "1",
  85. });
  86. if (login.code != 200) throw new Error("login fail");
  87. const token = login.message;
  88. const cols = await post("/proxy_dms/column/getColumnList", {}, token);
  89. const exist = flatten(cols.content || []).find((c) => c.tag === "sjnmtybt_tsyw");
  90. if (exist) {
  91. console.log("already exists", exist.id, exist.modelId);
  92. fs.writeFileSync(
  93. path.join(__dirname, "create-special-biz-column-result.json"),
  94. JSON.stringify({ columnId: exist.id, modelId: exist.modelId, existed: true }, null, 2)
  95. );
  96. return;
  97. }
  98. const fieldList = {
  99. personnel_id: text("personnel_id", "人员ID", true, 1),
  100. name: text("name", "姓名", false, 2),
  101. batch_no: text("batch_no", "批次号", false, 3),
  102. biz_type: text("biz_type", "业务类型", true, 4),
  103. reason: text("reason", "原因", false, 5),
  104. amount: num("amount", "金额", false, 6),
  105. heir_name: text("heir_name", "继承人姓名", false, 7),
  106. heir_id_number: text("heir_id_number", "继承人身份证", false, 8),
  107. heir_bank_card: text("heir_bank_card", "继承人银行卡", false, 9),
  108. approve_status: text("approve_status", "审批状态", true, 10),
  109. opinion: text("opinion", "审批意见", false, 11),
  110. remarks: text("remarks", "备注", false, 12),
  111. };
  112. const payload = {
  113. type: 1,
  114. parentId: String(PARENT_COLUMN_ID),
  115. tag: "sjnmtybt_tsyw",
  116. title: "特殊业务",
  117. content: "丧葬/暂停恢复/调标等特殊业务申请",
  118. state: 0,
  119. level: 0,
  120. "model.modelName": "special_biz",
  121. "model.modelAlias": "特殊业务",
  122. "model.pageSize": 20,
  123. "model.type": 1,
  124. "model.fieldList": JSON.stringify(fieldList),
  125. "model.searchField": "[]",
  126. "model.sortField": "[]",
  127. };
  128. const res = await post("/proxy_dms/column/addColumn", payload, token, "PUT");
  129. console.log(JSON.stringify(res).slice(0, 800));
  130. const cols2 = await post("/proxy_dms/column/getColumnList", {}, token);
  131. const created = flatten(cols2.content || []).find((c) => c.tag === "sjnmtybt_tsyw");
  132. const out = {
  133. addResult: { code: res.code, message: res.message, content: res.content },
  134. columnId: created && created.id,
  135. modelId: created && created.modelId,
  136. };
  137. fs.writeFileSync(path.join(__dirname, "create-special-biz-column-result.json"), JSON.stringify(out, null, 2));
  138. console.log("DONE", out);
  139. })().catch((e) => {
  140. console.error(e);
  141. process.exit(1);
  142. });