Kaynağa Gözat

数据治理-数据库创建与查询

ZHOUTD 1 yıl önce
ebeveyn
işleme
2ff9dc00e8

+ 107 - 96
xzl-admin/src/main/java/com/xzl/web/controller/userPortrait/ViewController.java

@@ -1,7 +1,9 @@
 package com.xzl.web.controller.userPortrait;
 
 import com.xzl.common.utils.DateUtils;
+import com.xzl.web.service.UserPortraitService;
 import org.aspectj.util.FileUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -10,13 +12,9 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -31,100 +29,113 @@ import java.util.Map;
 @RequestMapping("/user-portait")
 public class ViewController {
 
-  @Value("${pythonFilePath}")
-  String pythonFilePath;
-
-  @Value("${pythonPath}")
-  String pythonPath;
-
-  @GetMapping("/show")
-  public void show(HttpServletResponse response) throws Exception {
-    String wordcloudImageFileName = "wordcloud.png";
-    File wordcloudImageFile = new File(pythonFilePath, wordcloudImageFileName);
-    if (wordcloudImageFile.exists()) {
-      InputStream inputStream = null;
-      ServletOutputStream outputStream = null;
-      try {
-        inputStream = new FileInputStream(wordcloudImageFile);
-        outputStream = response.getOutputStream();
-        response.setHeader("Content-Disposition", String.format(
-          "attachment; filename=\"%s\"",
-          java.net.URLEncoder.encode(wordcloudImageFile.getName(), "UTF-8")));
-        response.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);
+    @Autowired
+    private UserPortraitService userPortraitService;
+
+    @Value("${pythonFilePath}")
+    String pythonFilePath;
+
+    @Value("${pythonPath}")
+    String pythonPath;
+
+    @GetMapping("/show")
+    public void show(HttpServletResponse response) throws Exception {
+        String wordcloudImageFileName = "wordcloud.png";
+        File wordcloudImageFile = new File(pythonFilePath, wordcloudImageFileName);
+        if (wordcloudImageFile.exists()) {
+            InputStream inputStream = null;
+            ServletOutputStream outputStream = null;
+            try {
+                inputStream = new FileInputStream(wordcloudImageFile);
+                outputStream = response.getOutputStream();
+                response.setHeader("Content-Disposition", String.format(
+                        "attachment; filename=\"%s\"",
+                        java.net.URLEncoder.encode(wordcloudImageFile.getName(), "UTF-8")));
+                response.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) {
+                e.printStackTrace();
+            } finally {
+                if (inputStream != null) {
+                    inputStream.close();
+                }
+                if (outputStream != null) {
+                    outputStream.close();
+                }
+            }
         }
-        outputStream.flush();
-      } catch (Exception e) {
-        e.printStackTrace();
-      } finally {
-        if (inputStream != null) {
-          inputStream.close();
+    }
+
+    @PostMapping("/generate")
+    public Map generate() throws Exception {
+        Map rs = new HashMap();
+        // 先判断有没有 wordcloud.txt, 没有就生成一个,有就备份一个,然后重新生成新的内容
+        String wordcloudFileName = "wordcloud.txt";
+        File wordcloudFile = new File(pythonFilePath, wordcloudFileName);
+
+        String wordcloudImageFileName = "wordcloud.png";
+        File wordcloudImageFile = new File(pythonFilePath, wordcloudImageFileName);
+
+        // 如果词云文件存在,就先都备份一下,然后再生成新的
+        String timePrefix = DateUtils.dateTimeNow();
+        if (wordcloudFile.exists()) {
+            FileUtil.copyFile(wordcloudFile, new File(pythonFilePath, timePrefix + "-" + wordcloudFileName));
         }
-        if (outputStream != null) {
-          outputStream.close();
+        if (wordcloudImageFile.exists()) {
+            FileUtil.copyFile(wordcloudImageFile, new File(pythonFilePath, timePrefix + "-" + wordcloudImageFileName));
         }
-      }
-    }
-  }
-
-  @PostMapping("/generate")
-  public Map generate() throws Exception {
-    Map rs = new HashMap();
-    // 先判断有没有 wordcloud.txt, 没有就生成一个,有就备份一个,然后重新生成新的内容
-    String wordcloudFileName = "wordcloud.txt";
-    File wordcloudFile = new File(pythonFilePath, wordcloudFileName);
-
-    String wordcloudImageFileName = "wordcloud.png";
-    File wordcloudImageFile = new File(pythonFilePath, wordcloudImageFileName);
-
-    // 如果词云文件存在,就先都备份一下,然后再生成新的
-    String timePrefix = DateUtils.dateTimeNow();
-    if (wordcloudFile.exists()) {
-      FileUtil.copyFile(wordcloudFile, new File(pythonFilePath, timePrefix + "-" + wordcloudFileName));
-    }
-    if (wordcloudImageFile.exists()) {
-      FileUtil.copyFile(wordcloudImageFile, new File(pythonFilePath, timePrefix + "-" + wordcloudImageFileName));
-    }
-    //TODO 获取新的内容,写入 wordcloud.txt
-
-    // 调用python脚本, 生成新的词云图片
-    String[] commands = {pythonPath, "/usr/local/python/word-cloud.py"};
-    ProcessBuilder processBuilder = new ProcessBuilder(commands);
-    Process process = processBuilder.start();
-    // 等待命令执行完成
-    int exitCode = process.waitFor();
-    System.out.println("命令执行结果:" + exitCode);
-    rs.put("exitCode", exitCode);
-    return rs;
-  }
-
-
-  /**
-   * 执行Linux命令
-   *
-   * @param command 需要执行的Linux命令
-   * @return 执行结果
-   */
-  public String executeCommand(String command) throws IOException {
-    // 创建一个新进程
-    Process process = Runtime.getRuntime().exec(command);
-
-    // 获取进程的输入流并转换为字符串
-    InputStream inputStream = process.getInputStream();
-    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-    StringBuilder result = new StringBuilder();
-    String line;
-    while ((line = reader.readLine()) != null) {
-      result.append(line).append("\n");
+
+        //获取新的内容,写入 wordcloud.txt
+        List<String> wordCloudInfo = userPortraitService.getWordCloudInfo();
+        FileWriter out = new FileWriter(wordcloudFile);
+        BufferedWriter bw= new BufferedWriter(out);
+        for (String info : wordCloudInfo) {
+            bw.write(info + "\t");
+            bw.newLine();
+        }
+        bw.close();
+        out.close();
+
+        // 调用python脚本, 生成新的词云图片
+        String[] commands = {pythonPath, "/usr/local/python/word-cloud.py"};
+        ProcessBuilder processBuilder = new ProcessBuilder(commands);
+        Process process = processBuilder.start();
+        // 等待命令执行完成
+        int exitCode = process.waitFor();
+        System.out.println("命令执行结果:" + exitCode);
+        rs.put("exitCode", exitCode);
+        return rs;
     }
 
-    // 关闭输入流和进程
-    reader.close();
-    process.destroy();
 
-    return result.toString();
-  }
+    /**
+     * 执行Linux命令
+     *
+     * @param command 需要执行的Linux命令
+     * @return 执行结果
+     */
+    public String executeCommand(String command) throws IOException {
+        // 创建一个新进程
+        Process process = Runtime.getRuntime().exec(command);
+
+        // 获取进程的输入流并转换为字符串
+        InputStream inputStream = process.getInputStream();
+        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+        StringBuilder result = new StringBuilder();
+        String line;
+        while ((line = reader.readLine()) != null) {
+            result.append(line).append("\n");
+        }
+
+        // 关闭输入流和进程
+        reader.close();
+        process.destroy();
+
+        return result.toString();
+    }
 }

+ 1 - 1
xzl-admin/src/main/java/com/xzl/web/core/config/SwaggerConfig.java

@@ -113,7 +113,7 @@ public class SwaggerConfig
         // 用ApiInfoBuilder进行定制
         return new ApiInfoBuilder()
                 // 设置标题
-                .title("标题:XZL管理系统_接口文档")
+                .title("标题:用户画像与数据治理_接口文档")
                 // 描述
                 .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
                 // 作者信息

+ 10 - 0
xzl-admin/src/main/java/com/xzl/web/mapper/UserPortraitMapper.java

@@ -0,0 +1,10 @@
+package com.xzl.web.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface UserPortraitMapper {
+    List<String> getWordCloudInfo();
+}

+ 7 - 0
xzl-admin/src/main/java/com/xzl/web/service/UserPortraitService.java

@@ -0,0 +1,7 @@
+package com.xzl.web.service;
+
+import java.util.List;
+
+public interface UserPortraitService {
+    List<String> getWordCloudInfo();
+}

+ 2 - 2
xzl-admin/src/main/java/com/xzl/web/service/impl/DataGovernanceServiceImpl.java

@@ -74,11 +74,11 @@ public class DataGovernanceServiceImpl implements DataGovernanceService {
                 return result;
             }
             if(!column.getType().equals("text") && column.getLength().isEmpty()){
-                result.put("message","类型为varchar或integer时长度不能为空!");
+                result.put("message","类型为varchar或int时长度不能为空!");
                 result.put("type","error");
                 return result;
             }
-            if(column.getType().equals("varchar") && Integer.parseInt(column.getLength())>255){
+            if(!column.getType().equals("text") && Integer.parseInt(column.getLength())>255){
                 column.setLength("255");
             }
         }

+ 21 - 0
xzl-admin/src/main/java/com/xzl/web/service/impl/UserPortraitServiceImpl.java

@@ -0,0 +1,21 @@
+package com.xzl.web.service.impl;
+
+import com.xzl.web.mapper.UserPortraitMapper;
+import com.xzl.web.service.UserPortraitService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class UserPortraitServiceImpl implements UserPortraitService {
+
+    @Autowired
+    private UserPortraitMapper userPortraitMapper;
+
+
+    @Override
+    public List<String> getWordCloudInfo() {
+        return userPortraitMapper.getWordCloudInfo();
+    }
+}

+ 7 - 0
xzl-admin/src/main/resources/mapper/UserPortraitMapper.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.xzl.web.mapper.UserPortraitMapper">
+    <select id="getWordCloudInfo" parameterType="string" resultType="string">
+        select distinct goods_name from d_order
+    </select>
+</mapper>

+ 2 - 2
xzl-ui/.env.development

@@ -1,10 +1,10 @@
 # 页面标题
-VUE_APP_TITLE = XZL管理系统
+VUE_APP_TITLE = 用户画像与数据治理
 
 # 开发环境配置
 ENV = 'development'
 
-# XZL管理系统/开发环境
+# 用户画像与数据治理/开发环境
 VUE_APP_BASE_API = '/dev-api'
 
 # 路由懒加载

+ 2 - 2
xzl-ui/.env.staging

@@ -1,10 +1,10 @@
 # 页面标题
-VUE_APP_TITLE = XZL管理系统
+VUE_APP_TITLE = 用户画像与数据治理
 
 NODE_ENV = production
 
 # 测试环境配置
 ENV = 'staging'
 
-# XZL管理系统/测试环境
+# 用户画像与数据治理/测试环境
 VUE_APP_BASE_API = '/stage-api'

+ 0 - 7
xzl-ui/src/views/dataGovernance/databaseManage.vue

@@ -50,13 +50,6 @@
           >
             查看
           </el-button>
-          <el-button
-            @click.native.prevent="change(scope.$index, tableData)"
-            type="text"
-            size="small"
-          >
-            修改
-          </el-button>
         </template>
       </el-table-column>
     </el-table>

+ 25 - 7
xzl-ui/src/views/dataGovernance/tableManage.vue

@@ -71,6 +71,8 @@
       </el-table-column>
     </el-table>
 
+
+    <!--添加表的弹窗-->
     <el-dialog
       title="数据库管理"
       :visible.sync="formVisible"
@@ -80,7 +82,7 @@
       <el-row style="height: 60px;padding-top: 7.2px;padding-left: 15px">
         <el-button type="success" size="small" @click="handleAddRow">添加字段</el-button>
         数据表名称:
-        <el-input size="small" v-model="form.tableName" autocomplete="off" style="width: 150px" ></el-input>
+        <el-input size="small" v-model="form.tableName" autocomplete="off" style="width: 150px"></el-input>
       </el-row>
       <el-table :data="form.columns" :border=true style="width: 99.99%;">
         <el-table-column prop="name" label="名称" min-width="10%">
@@ -105,7 +107,7 @@
 
         <el-table-column prop="isNotNull" label="不为NULL" min-width="7%">
           <template slot-scope="scope">
-            <el-switch v-model="scope.row.isNotNull" ></el-switch>
+            <el-switch v-model="scope.row.isNotNull"></el-switch>
           </template>
         </el-table-column>
         <el-table-column prop="isKey" label="主键" min-width="5%">
@@ -120,7 +122,7 @@
         </el-table-column>
         <el-table-column label="操作" min-width="10%">
           <template slot-scope="scope">
-            <el-button size="mini" type="danger" plain @click="delmembers(scope.$index, scope.row)">删除</el-button>
+            <el-button size="mini" type="danger" plain @click="deleteMember(scope.$index, form.columns)">删除</el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -173,12 +175,23 @@ export default {
     handleAdd() {
       this.formVisible = true;
     },
-    handleAddRow(){
-      this.form.columns.push({name: "", type: "", length: "", decimal: "", isNotNull: false, isKey: false, exegesis: ""})
+    handleAddRow() {
+      this.form.columns.push({
+        name: "",
+        type: "",
+        length: "",
+        decimal: "",
+        isNotNull: false,
+        isKey: false,
+        exegesis: ""
+      })
+    },
+    deleteMember(index, form) {
+      this.form.columns.splice(index, 1);
     },
     handleClose() {
       this.formVisible = false;
-      this.form=this.formDefault;
+      this.form = this.formDefault;
     },
     handleSave() {
       const t = this;
@@ -189,16 +202,21 @@ export default {
         data: t.form
       }).then(rs => {
         t.$message(rs);
-        if(rs.type=="success"){
+        if (rs.type == "success") {
           t.handleClose();
           t.initData()
         }
       })
     },
     view(index, table) {
+
+
+
+
     },
     change(index, table) {
     }
+
   }
 }
 </script>

+ 1 - 1
xzl-ui/vue.config.js

@@ -7,7 +7,7 @@ function resolve(dir) {
 
 const CompressionPlugin = require('compression-webpack-plugin')
 
-const name = process.env.VUE_APP_TITLE || 'XZL管理系统' // 网页标题
+const name = process.env.VUE_APP_TITLE || '用户画像与数据治理' // 网页标题
 
 const port = process.env.port || process.env.npm_config_port || 80 // 端口