Skip to content

Commit

Permalink
mindspor增加course搜索源
Browse files Browse the repository at this point in the history
  • Loading branch information
2511689622 committed Nov 14, 2024
1 parent b17a377 commit ff30825
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
12 changes: 11 additions & 1 deletion mindspore/src/main/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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<String, File> hashMap = Map.of("paper", indexPaperFile, "case", indexCaseFile);
Map<String, File> hashMap = Map.of("paper", indexPaperFile, "case", indexCaseFile, "course", indexCourseFile);
hashMap.entrySet().forEach(entry -> {
try {
updatePortal(entry.getKey(), entry.getValue());
Expand All @@ -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;
}
Expand Down
70 changes: 70 additions & 0 deletions mindspore/src/main/java/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,76 @@ public static List<Map<String, Object>> parseCaseJson(File jsonFile) {
return ansList;
}

public static List<Map<String, Object>> parseCourseJson(File jsonFile) {
ObjectMapper objectMapper = new ObjectMapper();
List<Map<String, Object>> 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<String, Object> 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<String, Object> jsonMap, String fileContent) {
String title = "";
String textContent = "";
Expand Down
5 changes: 4 additions & 1 deletion mindspore/src/main/resources/initDoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}/
cp -r ${SOURCE}/mindspore-portal/packages/website/data/cases/* ${TARGET_CASES}/
cp -r ${SOURCE}/mindspore-portal/packages/website/data/courses/* ${TARGET_COURSES}/

0 comments on commit ff30825

Please sign in to comment.