Explorar o código

数据库ER图查看

ZHOUTD hai 1 ano
pai
achega
74a43af81c

+ 34 - 0
xzl-admin/src/main/java/com/xzl/web/controller/DataGovernanceController.java

@@ -12,6 +12,7 @@ import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -34,6 +35,9 @@ public class DataGovernanceController {
     @Autowired
     private DataGovernanceService dataGovernanceService;
 
+    @Value("${ERImagePath}")
+    private String ERImagePath;
+
 
     @RequestMapping(value = "/databaseList",method = RequestMethod.GET)
     public List<DatabaseInfo> databaseList(){
@@ -118,4 +122,34 @@ public class DataGovernanceController {
             e.printStackTrace();
         }
     }
+
+    @RequestMapping(value = "/loadERImage")
+    public void loadFile(@RequestParam(value = "databaseName") String databaseName, HttpServletResponse servletResponse) throws Exception{
+        File image = new File(ERImagePath+databaseName+".jpg");
+        InputStream inputStream = null;
+        ServletOutputStream outputStream = null;
+        try {
+            inputStream = new FileInputStream(image);
+            outputStream = servletResponse.getOutputStream();
+            servletResponse.setHeader("Content-Disposition", String.format(
+                    "attachment; filename=\"%s\"",
+                    java.net.URLEncoder.encode(image.getName(), "UTF-8")));
+            servletResponse.setContentType("application/octet-stream;charset=UTF-8");
+            int count = 0;
+            byte[] buffer = new byte[1024 * 1024];
+            while ((count = inputStream.read(buffer)) != -1) {
+                outputStream.write(buffer, 0, count);
+            }
+            outputStream.flush();
+        } catch (Exception e) {
+            logger.error("文件加载失败", e);
+        } finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
+            if (outputStream != null) {
+                outputStream.close();
+            }
+        }
+    }
 }

+ 2 - 1
xzl-admin/src/main/resources/application-dev.yml

@@ -65,4 +65,5 @@ spring:
                         multi-statement-allow: true
 pythonFilePath: /usr/local/python/
 pythonPath: /usr/local/Cellar/python@3.10/3.10.11/bin/python3.10
-sqlFilePath: D:/sql
+sqlFilePath: D:/sql
+ERImagePath: D:/ERImage/

+ 2 - 0
xzl-framework/src/main/java/com/xzl/framework/config/SecurityConfig.java

@@ -111,6 +111,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
       .antMatchers("/login", "/register", "/captchaImage").permitAll()
       // 用户画像
       .antMatchers("/user-portait/**").permitAll()
+      //数据库ER图
+      .antMatchers("/dataGovernance/loadERImage").permitAll()
       // 静态资源,可匿名访问
       .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
       .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 30 - 4
xzl-ui/src/views/dataGovernance/databaseManage.vue

@@ -56,6 +56,13 @@
           >
             查看
           </el-button>
+          <el-button
+            @click.native.prevent="showERImage(scope.$index, tableData)"
+            type="text"
+            size="small"
+          >
+            查看ER图
+          </el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -85,6 +92,13 @@
       style="display: none"
       :auto-upload="false"
     ></el-upload>
+    <el-dialog
+      :title="erDialog.title"
+      :visible.sync="erDialog.show"
+      width="80%"
+      center>
+      <img :src="erDialog.erSrc" style="width: 100%;height: 100%"/>
+    </el-dialog>
   </div>
 </template>
 <script>
@@ -100,7 +114,12 @@ export default {
       },
       multipleSelection: [],
       fileList:[],
-      databaseName:""
+      databaseName:"",
+      erDialog:{
+        title: "",
+        show: false,
+        erSrc: ""
+      }
     }
   },
   mounted() {
@@ -127,11 +146,18 @@ export default {
         this.$refs.file.clearFiles();
         this.$message({
           type:"error",
-          message:"请选择sql文件"
+          message:"请选择sql文件!"
         });
       }
-
-
+    },
+    showERImage(index,tableData){
+      var param={
+        title:tableData[index].databaseName,
+        show:false,
+        erSrc: process.env.VUE_APP_BASE_API+'/dataGovernance/loadERImage?databaseName='+tableData[index].databaseName
+      }
+      this.erDialog=param;
+      this.erDialog.show=true;
     },
     importBtn(index,tableData){
       this.databaseName=tableData[index].databaseName;