From ff308254fc39298fd51bced745898c84d1859c66 Mon Sep 17 00:00:00 2001 From: XieChengzhi Date: Thu, 14 Nov 2024 19:32:17 +0800 Subject: [PATCH] =?UTF-8?q?mindspor=E5=A2=9E=E5=8A=A0course=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mindspore/src/main/java/App.java | 12 ++++- mindspore/src/main/java/Parse.java | 70 +++++++++++++++++++++++++ mindspore/src/main/resources/initDoc.sh | 5 +- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/mindspore/src/main/java/App.java b/mindspore/src/main/java/App.java index 18d4ba9..9d2c462 100644 --- a/mindspore/src/main/java/App.java +++ b/mindspore/src/main/java/App.java @@ -10,6 +10,8 @@ public class App { private static final String TARGET_CASES = System.getenv("TARGET") + "/cases"; + private static final String TARGET_COURSES = System.getenv("TARGET") + "/courses"; + private static final String APPLICATION_PATH = System.getenv("APPLICATION_PATH"); private static final String MAPPING_PATH = System.getenv("MAPPING_PATH"); @@ -36,6 +38,7 @@ public static void main(String[] args) { public static void portalData() throws Exception { File indexPaperFile = new File(TARGET_PAPERS); File indexCaseFile = new File(TARGET_CASES); + File indexCourseFile = new File(TARGET_COURSES); if (!indexPaperFile.exists()) { System.out.printf("%s folder does not exist%n", indexPaperFile.getPath()); return; @@ -44,8 +47,12 @@ public static void portalData() throws Exception { System.out.printf("%s folder does not exist%n", indexCaseFile.getPath()); return; } + if (!indexCourseFile.exists()) { + System.out.printf("%s folder does not exist%n", indexCourseFile.getPath()); + } + System.out.println("begin to update portal data,开始更新"); - Map hashMap = Map.of("paper", indexPaperFile, "case", indexCaseFile); + Map hashMap = Map.of("paper", indexPaperFile, "case", indexCaseFile, "course", indexCourseFile); hashMap.entrySet().forEach(entry -> { try { updatePortal(entry.getKey(), entry.getValue()); @@ -69,6 +76,9 @@ public static void updatePortal(String category, File indexFile) throws Exceptio case "case": escapeList = Parse.parseCaseJson(paresFile); break; + case "course": + escapeList = Parse.parseCourseJson(paresFile); + break; default: break; } diff --git a/mindspore/src/main/java/Parse.java b/mindspore/src/main/java/Parse.java index 7b59e9e..e48dce0 100644 --- a/mindspore/src/main/java/Parse.java +++ b/mindspore/src/main/java/Parse.java @@ -204,6 +204,76 @@ public static List> parseCaseJson(File jsonFile) { return ansList; } + public static List> parseCourseJson(File jsonFile) { + ObjectMapper objectMapper = new ObjectMapper(); + List> ansList = new ArrayList<>(); + try { + JsonNode rootNode = objectMapper.readTree(jsonFile); + if(rootNode.isArray()) { + for (JsonNode courseNode : rootNode) { + String courseId = (courseNode.get("id") != null) ? courseNode.get("id").asText() : null; + String courseCatalog = (courseNode.get("catalog") != null) ? courseNode.get("catalog").asText() : null; + String courseDescription = (courseNode.get("description") != null) ? courseNode.get("description").asText() : null; + String courseSeries = (courseNode.get("series") != null) ? courseNode.get("series").asText() : null; + String courseClasses = (courseNode.get("classes") != null) ? courseNode.get("classes").asText() : null; + String courseCover = (courseNode.get("cover") != null) ? courseNode.get("cover").asText() : null; + String courseCatalogName = (courseNode.get("catalogName") != null) ? courseNode.get("catalogName").asText() : null; + String courseCatalogDesc = (courseNode.get("catalogDesc") != null) ? courseNode.get("catalogDesc").asText() : null; + JsonNode childrenNodes = courseNode.get("children"); + if (childrenNodes != null && childrenNodes.isArray()) { + for (JsonNode childrenNode : childrenNodes) { + String childrenId = (childrenNode.get("id") != null) ? childrenNode.get("id").asText() : null; + String childrenName = (childrenNode.get("name") != null) ? childrenNode.get("name").asText() : null; + String childrenCount = (childrenNode.get("count") != null) ? childrenNode.get("count").asText() : null; + String childrenCoverImg = (childrenNode.get("coverImg") != null) ? childrenNode.get("coverImg").asText() : null; + JsonNode courseListNodes = (childrenNode.get("courseList") != null) ? childrenNode.get("courseList") : null; + if (courseListNodes != null && courseListNodes.isArray()) { + for (JsonNode courseListNode : courseListNodes) { + Map jsonMap = new HashMap<>(); + String courseListId = (courseListNode.get("id") != null) ? courseListNode.get("id").asText() : null; + String courseListCategoryId = (courseListNode.get("categoryId") != null) ? courseListNode.get("categoryId").asText() : null; + String courseListTitle = (courseListNode.get("title") != null) ? courseListNode.get("title").asText() : null; + String courseListLable = (courseListNode.get("lable") != null) ? courseListNode.get("lable").asText() : null; + String courseListLang = (courseListNode.get("lang") != null) ? courseListNode.get("lang").asText() : null; + String courseListForm = (courseListNode.get("form") != null) ? courseListNode.get("form").asText() : null; + String courseListVideoType = (courseListNode.get("videoType") != null) ? courseListNode.get("videoType").asText() : null; + String courseListVideoUrl = (courseListNode.get("videoUrl") != null) ? courseListNode.get("videoUrl").asText() : null; + String courseListPlayMin = (courseListNode.get("playMin") != null) ? courseListNode.get("playMin").asText() : null; + jsonMap.put("type", "course"); + jsonMap.put("courseListPlayMin", courseListPlayMin); + jsonMap.put("path", courseListVideoUrl); + jsonMap.put("courseListVideoType", courseListVideoType); + jsonMap.put("courseListForm", courseListForm); + jsonMap.put("lang", courseListLang); + jsonMap.put("courseListLable", courseListLable); + jsonMap.put("title", courseListTitle); + jsonMap.put("courseListCategoryId", courseListCategoryId); + jsonMap.put("courseListId", courseListId); + jsonMap.put("childrenCoverImg", childrenCoverImg); + jsonMap.put("childrenCount", childrenCount); + jsonMap.put("textContent", childrenName); + jsonMap.put("childrenId", childrenId); + jsonMap.put("courseCatalogDesc", courseCatalogDesc); + jsonMap.put("courseCatalogName", courseCatalogName); + jsonMap.put("courseCover", courseCover); + jsonMap.put("courseClasses", courseClasses); + jsonMap.put("courseSeries", courseSeries); + jsonMap.put("courseDescription", courseDescription); + jsonMap.put("courseCatalog", courseCatalog); + jsonMap.put("courseId", courseId); + ansList.add(jsonMap); + } + } + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return ansList; + } + public static Boolean parseHtml(Map jsonMap, String fileContent) { String title = ""; String textContent = ""; diff --git a/mindspore/src/main/resources/initDoc.sh b/mindspore/src/main/resources/initDoc.sh index 3e25570..ba0cb80 100644 --- a/mindspore/src/main/resources/initDoc.sh +++ b/mindspore/src/main/resources/initDoc.sh @@ -3,10 +3,12 @@ SOURCE=/docs-file/source TARGET=/docs-file/target TARGET_PAPERS=/docs-file/target/papers TARGET_CASES=/docs-file/target/cases +TARGET_COURSES=/docs-file/target/courses mkdir -p ${SOURCE} mkdir -p ${TARGET} mkdir -p ${TARGET_PAPERS} mkdir -p ${TARGET_CASES} +mkdir -p ${TARGET_COURSES} # shellcheck disable=SC2164 cd ${SOURCE} @@ -88,4 +90,5 @@ fi cd ${SOURCE}/mindspore-portal cp -r ${SOURCE}/mindspore-portal/packages/website/data/papers/* ${TARGET_PAPERS}/ -cp -r ${SOURCE}/mindspore-portal/packages/website/data/cases/* ${TARGET_CASES}/ \ No newline at end of file +cp -r ${SOURCE}/mindspore-portal/packages/website/data/cases/* ${TARGET_CASES}/ +cp -r ${SOURCE}/mindspore-portal/packages/website/data/courses/* ${TARGET_COURSES}/ \ No newline at end of file