逆天版SpringBoot畢業論文知識圖譜及可視化系統 軟件開發實錄

最近閒來無事 開發了一套知識圖譜系統 特地再次跟大家分享軟件開發過程

技術

技術挺簡單的 就是按照下面開發的
Java後端:SpringBoot JPA mysql neo4j圖數據庫
前端:echarts vue.js elementUI

功能

功能圖

寫好以後運行圖

登錄
用戶管理
論文信息管理
論文技術類別維護
用戶自定義詞彙維護
知識圖譜
具體實現代碼如下:

package org.qust.controller.admin;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.qust.common.Result;
import org.qust.common.StatusCode;
import org.qust.entity.BaseInfo;
import org.qust.entity.TechnologyInfo;
import org.qust.entity.TitleType;
import org.qust.entity.neo4j.EchartsData;
import org.qust.entity.neo4j.EchartsLinks;
import org.qust.entity.neo4j.Thesis;
import org.qust.entity.neo4j.Topic;
import org.qust.service.BaseInfoService;
import org.qust.service.TechnologyInfoService;
import org.qust.service.TitleTypeService;
import org.qust.service.neo4j.ThesisService;
import org.qust.service.neo4j.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:知識圖譜維護-Neo4j
 * User:lock
 * Date:2020-04-28
 * Time:00:50
 */
@RestController
@RequestMapping("/kgraph")
public class KGraphController {
    @Autowired
    private BaseInfoService baseInfoService;
    @Autowired
    private ThesisService thesisService;
    @Autowired
    private TitleTypeService titleTypeService;
    @Autowired
    private TopicService topicService;
    @Autowired
    private TechnologyInfoService technologyInfoService;

    // 生成所有的知識圖譜
    @RequiresRoles("user")
    @RequestMapping(method = RequestMethod.GET,value = "/geneAll")
    public Result geneAll(){

        for (BaseInfo baseInfo : baseInfoService.findAll()) {
            thesisService.add(new Thesis(baseInfo.getSno(),baseInfo.getSname(),baseInfo.getTitle()));
        }
        for (TitleType titleType : titleTypeService.findAll()) {
            List<TechnologyInfo> technologyInfoList = technologyInfoService.findByTechnology(titleType.getType());
            Topic topic = new Topic();
            topic.setName(titleType.getType());
            if(technologyInfoList.size()>0){
                List<Thesis> thesesList = new ArrayList<>();
                for (TechnologyInfo technologyInfo : technologyInfoList) {
                    thesesList.add(thesisService.findBySno(technologyInfo.getSno()));
                }
                topic.setTheses(thesesList);
            }
            topicService.add(topic);
        }
        return new Result(true, StatusCode.OK,"已全部加載到Neo4j數據庫!");
    }

    // 查找全部
    @RequiresRoles("user")
    @RequestMapping(method = RequestMethod.GET,value = "/getAll")
    public Result getAll(){
        return new Result(true, StatusCode.OK,"查找成功!",modifyJson(topicService.findAll()));
    }

    // 根據名稱模糊查詢
    @RequiresRoles("user")
    @RequestMapping(method = RequestMethod.GET,value = "/getAll/{name}")
    public Result getByNameLike(@PathVariable String name){
        return new Result(true, StatusCode.OK,"查找成功!",modifyJson(topicService.findByNameLike("*"+name+"*")));
    }

    // 清空知識圖譜
    @RequiresRoles("user")
    @RequestMapping(method = RequestMethod.DELETE,value = "/delete")
    public Result deleteAll(){
        thesisService.deleteAll();
        topicService.deleteAll();
        return new Result(true, StatusCode.OK,"Neo4j 數據已經全部清空!");
    }

    // 修改爲Echarts接受的格式類型
    @RequiresRoles("user")
    public Map<String,Object> modifyJson(Iterable<Topic> topics){
        Map<String,Object> map = new HashMap<>();
        List<EchartsData> data = new ArrayList<>();
        List<EchartsLinks> links = new ArrayList<>();
        List<String> thesisTitle = new ArrayList<>();
        // 處理爲Echarts需要的格式
        for (Topic topic : topics) {
            Map<String,Object> topicDes = new HashMap<>();
            topicDes.put("title",topic.getName());
            data.add(new EchartsData(topic.getName(),topicDes,40,0));
            List<Thesis> theses = topic.getTheses();
            if(theses!=null){
                for (Thesis  t: theses) {
                    if(!thesisTitle.contains(t.getTitle())){
                        thesisTitle.add(t.getTitle());
                        data.add(new EchartsData(t.getTitle(),t,40,1));
                    }
                    links.add(new EchartsLinks(t.getTitle(),topic.getName(),"屬於","屬於"));
                }
            }
        }
        map.put("data",data);
        map.put("links",links);
        return map;
    }
}

熱門技術Top15
具體實現代碼如下:

package org.qust.controller.admin;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.qust.common.Result;
import org.qust.common.StatusCode;
import org.qust.entity.TitleType;
import org.qust.entity.TypeAndNum;
import org.qust.service.BaseInfoService;
import org.qust.service.TechnologyInfoService;
import org.qust.service.TitleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:charts數據生成
 * User:lock
 * Date:2020-05-07
 * Time:08:52
 */
@RestController
@RequestMapping("/charts")
public class ChartsController {

    @Autowired
    private TechnologyInfoService technologyInfoService;
    @Autowired
    private TitleTypeService titleTypeService;
    @Autowired
    private BaseInfoService baseInfoService;

    // 得到 dataSetCharts 數據
    @RequiresRoles("user")
    @RequestMapping(value = "/geneDataSetCharts", method = RequestMethod.GET)
    public Result geneDataSetCharts(){
//        ['product', '2012', '2013', '2014', '2015', '2016', '2017'],
//        ['Matcha Latte', 41.1, 30.4, 65.1, 53.3, 83.8, 98.7],
//        ['Milk Tea', 86.5, 92.1, 85.7, 83.1, 73.4, 55.1],
//        ['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4, 65.2, 82.5],
//        ['Walnut Brownie', 55.2, 67.1, 69.2, 72.4, 53.9, 39.1]
        List<String> product = new ArrayList<>();
        List<String> allSemester = technologyInfoService.findAllSemester();
        product.add("product");
        product.addAll(allSemester);
        List<List<String>> res = new ArrayList<>();
        res.add(product);
        for (TitleType titleType : titleTypeService.findAll()) {
            List<String> type = new ArrayList<>();
            type.add(titleType.getType());
            for (String semester : allSemester) {
                int size = technologyInfoService.findByTechnologyAndSemester(titleType.getType(), semester).size();
                type.add(String.valueOf(size));
            }
            res.add(type);
        }
        return new Result(true, StatusCode.OK,"查詢成功!",res);
    }

    // 得到 barCharts 數據
    @RequiresRoles("user")
    @RequestMapping(value = "/getBarChartRace", method = RequestMethod.GET)
    public Result getBarChartRace(){
        Map<String,Object> map1 = new HashMap<>();
        List<String> allSemester = technologyInfoService.findAllSemester();
        List<String> years = new ArrayList<>();
        List<List<String>> jdData = new ArrayList<>();
        List<List<Integer>> data = new ArrayList<>();
        for (String semester : allSemester) {
            years.add(semester);
            List<String> jdData_item = new ArrayList<>();
            List<Integer> data_item = new ArrayList<>();
            for (TypeAndNum typeAndNum : technologyInfoService.findTypeAndNumBySemester(semester)) {
                jdData_item.add(typeAndNum.getType());
                data_item.add(typeAndNum.getNum());
            }
            jdData.add(jdData_item);
            data.add(data_item);
        }
        map1.put("years",years);
        map1.put("jdData",jdData);
        map1.put("data",data);
        return new Result(true, StatusCode.OK,"查詢成功!",map1);
    }

    // 得到 全部類別 數據
    @RequiresRoles("user")
    @RequestMapping(value = "/getAllTypes", method = RequestMethod.GET)
    public Result getAllTypes(){
        return new Result(true, StatusCode.OK,"查詢成功!",titleTypeService.findAll());
    }

    // 得到 getOrderByOrigin 數據
    @RequiresRoles("user")
    @RequestMapping(value = "/getOrderByOrigin", method = RequestMethod.GET)
    public Result getOrderByOrigin(){
        Map<String, Object> resMap = new HashMap<>();
        List<String> title = new ArrayList<>();
        List<Map<String, Object>> data = new ArrayList<>();
        for (TypeAndNum typeAndNum : baseInfoService.orderByOrigin()) {
            title.add(typeAndNum.getType());
            Map<String, Object> map = new HashMap<>();
            map.put("value",typeAndNum.getNum());
            map.put("name",typeAndNum.getType());
            data.add(map);
        }
        resMap.put("title", title);
        resMap.put("data", data);
        return new Result(true, StatusCode.OK,"查詢成功!",resMap);
    }

    // 得到 getOrderByType 數據
    @RequiresRoles("user")
    @RequestMapping(value = "/getOrderByType", method = RequestMethod.GET)
    public Result getOrderByType(){
        Map<String, Object> resMap = new HashMap<>();
        List<String> title = new ArrayList<>();
        List<Map<String, Object>> data = new ArrayList<>();
        for (TypeAndNum typeAndNum : baseInfoService.orderByType()) {
            title.add(typeAndNum.getType());
            Map<String, Object> map = new HashMap<>();
            map.put("value",typeAndNum.getNum());
            map.put("name",typeAndNum.getType());
            data.add(map);
        }
        resMap.put("title", title);
        resMap.put("data", data);
        return new Result(true, StatusCode.OK,"查詢成功!",resMap);
    }


    @RequiresRoles("user")
    @RequestMapping(value = "/getOrderByTeacher", method = RequestMethod.GET)
    public Result getOrderByTeacher(){
        Map<String, Object> resMap = new HashMap<>();
        List<String> title = new ArrayList<>();
        List<Map<String, Object>> data = new ArrayList<>();
        for (TypeAndNum typeAndNum : baseInfoService.orderByTeacher()) {
            title.add(typeAndNum.getType());
            Map<String, Object> map = new HashMap<>();
            map.put("value",typeAndNum.getNum());
            map.put("name",typeAndNum.getType());
            data.add(map);
        }
        resMap.put("title", title);
        resMap.put("data", data);
        return new Result(true, StatusCode.OK,"查詢成功!",resMap);
    }
}

熱門技術曲線
其他信息統計
其他信息統計
詞雲
具體實現代碼如下:

package org.qust.controller.admin;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.qust.common.Result;
import org.qust.common.StatusCode;
import org.qust.entity.BaseInfo;
import org.qust.entity.WordCloud;
import org.qust.service.BaseInfoService;
import org.qust.service.WordCloudService;
import org.qust.service.WordUtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:詞彙雲維護
 * User:lock
 * Date:2020-04-28
 * Time:00:37
 */
@RestController
@RequestMapping("/wordCloud")
public class WordCloudController {

    @Autowired
    private BaseInfoService baseInfoService;
    @Autowired
    private WordUtilService wordUtilService;
    @Autowired
    private WordCloudService wordCloudService;
    // 獲得標籤雲信息
    @RequiresRoles("user")
    @RequestMapping(value = "/geneWordCloud",method = RequestMethod.GET)
    public Result geneWordCloud(){
        // 先全部刪除
        wordCloudService.deleteAll();
        List<String> words = new ArrayList<>();
        for (BaseInfo baseInfo : baseInfoService.findAll()) {
            words.addAll(wordUtilService.segment(baseInfo.getTitle()));
        }
        List<Map.Entry<String, Integer>> freWords = this.getFreWords(words);
        for(int i=0; i<150; i++){
            Map.Entry<String, Integer> freWord = freWords.get(i);
            WordCloud wordCloud = new WordCloud(freWord.getKey(), freWord.getValue());
            wordCloudService.add(wordCloud);
        }
        return new Result(true, StatusCode.OK,"生成標籤雲信息成功!");
    }
    // 獲得標籤雲信息
    @RequiresRoles("user")
    @RequestMapping(value = "/getWordCloud",method = RequestMethod.GET)
    public Result getWordCloud(){
        List<Map<String,Object>> words = new ArrayList<>();
        for (WordCloud wordCloud : wordCloudService.findAll()) {
            Map<String,Object> map = new HashMap<>();
            map.put("name", wordCloud.getName());
            map.put("value",wordCloud.getValue());
            words.add(map);
        }
        return new Result(true, StatusCode.OK,"獲取標籤雲信息成功!",words);
    }
    // 統計關鍵詞詞頻
    public List<Map.Entry<String, Integer>> getFreWords(List<String> words){
        Map<String, Integer> map = new HashMap<>();
        for (String word : words) {
            if(map.containsKey(word)){
                int num = map.get(word);
                map.put(word, ++num);
            }else{
                map.put(word, 1);
            }
        }
        List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
        list.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue()));
        return list;
    }

}

數據庫表設計

數據庫表設計

運行視頻

我錄製好了 如果大家想學習的話可以跟我交流,畢竟源碼對外免費開放,可以跟大家一起進步,未來可期!

炸天版SpringBoot知識圖譜-畢業論文可視化 畢業設計可視化

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章