From 5de91493af2d076f273a88d4d8d322296f5cfcaa Mon Sep 17 00:00:00 2001 From: funjia <13429193897@163.com> Date: Mon, 14 Apr 2025 01:17:15 +0800 Subject: [PATCH] first commit --- convertData/dataDict.ts | 29 ++++++++++++++++++++ convertData/questionAnswer.ts | 51 +++++++++++++++++++++++++++++++++++ convertData/tag.ts | 29 ++++++++++++++++++++ convertData/test.js | 22 +++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 convertData/dataDict.ts create mode 100644 convertData/questionAnswer.ts create mode 100644 convertData/tag.ts create mode 100644 convertData/test.js diff --git a/convertData/dataDict.ts b/convertData/dataDict.ts new file mode 100644 index 0000000..02f8e54 --- /dev/null +++ b/convertData/dataDict.ts @@ -0,0 +1,29 @@ +(async function () { + const res = await fetch("http://all.funjia.top/api/dynamic/list/dataDict", { + method: "post", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ "page": 1, "pageSize": 100000, "userId": "cl3fqx6zb000034ny90rd333s" }) + }); + + const importData = await res.json(); + importData.data.forEach(element => { + console.log(element) + saveData({ unionKey: element.unionKey, value: element.value, desc: element.desc }); + }); +})() + +function saveData(importData) { + fetch("http://127.0.0.1:1337/api/data-dicts", { + method: "post", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ data: importData }) + }).then((res) => { + console.log(res); + }).catch((err) => { + console.log(err) + }) +} \ No newline at end of file diff --git a/convertData/questionAnswer.ts b/convertData/questionAnswer.ts new file mode 100644 index 0000000..9e215b3 --- /dev/null +++ b/convertData/questionAnswer.ts @@ -0,0 +1,51 @@ +(async function () { + const res = await fetch("http://all.funjia.top/api/QA/list", { + method: "post", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ "page": 1, "pageSize": 100000, "userId": "cl3fqx6zb000034ny90rd333s" }) + }); + + const importDataObj = await res.json(), + tagDataObj = await getTag(), + importData = importDataObj.data, + tagData = tagDataObj.data; + // console.log(tagData); + // return; + for (const item of importData) { + console.log(item.tag); + const tag = tagData.filter(tDItem => (Array.isArray(item.tag) ? item.tag : [item.tag]).some((child) => child == tDItem.name)); + console.log(tag); + await saveData({ question: item.question, answer: item.answer, tags: tag.map((child) => child.documentId) }); + await sleep(200); + } +})() + +async function sleep(timeout) { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, timeout); + }); +} + +async function getTag() { + const res = await fetch("http://127.0.0.1:1337/api/tags", { + method: "get", + headers: { + "Content-Type": "application/json" + } + }); + return res.json(); +} + +function saveData(importData) { + return fetch("http://127.0.0.1:1337/api/question-answers", { + method: "post", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ data: importData }) + }) +} \ No newline at end of file diff --git a/convertData/tag.ts b/convertData/tag.ts new file mode 100644 index 0000000..8745463 --- /dev/null +++ b/convertData/tag.ts @@ -0,0 +1,29 @@ +(async function () { + const res = await fetch("http://all.funjia.top/api/dynamic/list/tag", { + method: "post", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ "page": 1, "pageSize": 100000, "userId": "cl3fqx6zb000034ny90rd333s" }) + }); + + const importData = await res.json(); + importData.data.forEach(element => { + // console.log(element) + saveData({name:element.name}); + }); +})() + +function saveData(importData) { + fetch("http://127.0.0.1:1337/api/tags", { + method: "post", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ data: importData }) + }).then((res) => { + console.log(res); + }).catch((err) => { + console.log(err) + }) +} \ No newline at end of file diff --git a/convertData/test.js b/convertData/test.js new file mode 100644 index 0000000..27b554b --- /dev/null +++ b/convertData/test.js @@ -0,0 +1,22 @@ +fetch("http://localhost:1337/api/data-dicts", { + "headers": { + "accept": "application/json", + // "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", + // "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzQ0MDMxMzczLCJleHAiOjE3NDY2MjMzNzN9.FWwOQj0R91paBYDIptE1z0o4BZroJbHhgj1IFPTqw_Q", + "content-type": "application/json", + // "sec-ch-ua": "\"Microsoft Edge\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\"", + // "sec-ch-ua-mobile": "?0", + // "sec-ch-ua-platform": "\"Windows\"", + // "sec-fetch-dest": "empty", + // "sec-fetch-mode": "cors", + // "sec-fetch-site": "same-origin" + }, + "referrer": "http://localhost:1337/api/data-dicts", + "referrerPolicy": "same-origin", + "body": "{\"unionKey\":\"test\",\"value\":\"test\",\"desc\":\"test2\"}", + "method": "POST", + "mode": "cors", + "credentials": "include" +}).then(async (res)=>{ + console.log(await res.text()); +}); \ No newline at end of file