es功能开发

This commit is contained in:
暮光:城中城
2019-07-27 00:47:46 +08:00
parent 9d7149aa04
commit 116e04e3bf
13 changed files with 305 additions and 31 deletions

View File

@@ -0,0 +1,131 @@
package com.zyplayer.doc.data.repository.manage.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author 暮光:城中城
* @since 2019-07-27
*/
public class EsDatasource implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键自增ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 数据源名称
*/
private String name;
/**
* 地址和端口
*/
private String hostPort;
/**
* schemehttp或其他
*/
private String scheme;
/**
* 创建人ID
*/
private Long createUserId;
/**
* 创建人名字
*/
private String createUserName;
/**
* 创建时间
*/
private Date createTime;
/**
* 是否有效 0=无效 1=有效
*/
private Integer yn;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHostPort() {
return hostPort;
}
public void setHostPort(String hostPort) {
this.hostPort = hostPort;
}
public String getScheme() {
return scheme;
}
public void setScheme(String scheme) {
this.scheme = scheme;
}
public Long getCreateUserId() {
return createUserId;
}
public void setCreateUserId(Long createUserId) {
this.createUserId = createUserId;
}
public String getCreateUserName() {
return createUserName;
}
public void setCreateUserName(String createUserName) {
this.createUserName = createUserName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getYn() {
return yn;
}
public void setYn(Integer yn) {
this.yn = yn;
}
@Override
public String toString() {
return "EsDatasource{" +
"id=" + id +
", name=" + name +
", hostPort=" + hostPort +
", scheme=" + scheme +
", createUserId=" + createUserId +
", createUserName=" + createUserName +
", createTime=" + createTime +
", yn=" + yn +
"}";
}
}

View File

@@ -0,0 +1,16 @@
package com.zyplayer.doc.data.repository.manage.mapper;
import com.zyplayer.doc.data.repository.manage.entity.EsDatasource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author 暮光:城中城
* @since 2019-07-27
*/
public interface EsDatasourceMapper extends BaseMapper<EsDatasource> {
}

View File

@@ -19,7 +19,8 @@ public class CodeGenerator {
final String moduleName = "manage";
// final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info", "db_datasource" };
// final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
final String[] tableName = { "db_datasource" };
// final String[] tableName = { "db_datasource" };
final String[] tableName = { "es_datasource" };
// 代码生成器
AutoGenerator mpg = new AutoGenerator();

View File

@@ -0,0 +1,16 @@
package com.zyplayer.doc.data.service.manage;
import com.zyplayer.doc.data.repository.manage.entity.EsDatasource;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author 暮光:城中城
* @since 2019-07-27
*/
public interface EsDatasourceService extends IService<EsDatasource> {
}

View File

@@ -0,0 +1,20 @@
package com.zyplayer.doc.data.service.manage.impl;
import com.zyplayer.doc.data.repository.manage.entity.EsDatasource;
import com.zyplayer.doc.data.repository.manage.mapper.EsDatasourceMapper;
import com.zyplayer.doc.data.service.manage.EsDatasourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author 暮光:城中城
* @since 2019-07-27
*/
@Service
public class EsDatasourceServiceImpl extends ServiceImpl<EsDatasourceMapper, EsDatasource> implements EsDatasourceService {
}

View File

@@ -0,0 +1,5 @@
<?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.zyplayer.doc.data.repository.manage.mapper.EsDatasourceMapper">
</mapper>

View File

@@ -0,0 +1,70 @@
package com.zyplayer.doc.elasticsearch.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyplayer.doc.core.annotation.AuthMan;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.EsDatasource;
import com.zyplayer.doc.data.service.manage.EsDatasourceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
* 数据源控制器
*
* @author 暮光:城中城
* @since 2019年7月27日
*/
@AuthMan("ES_DATASOURCE_MANAGE")
@RestController
@RequestMapping("/zyplayer-doc-es/datasource")
public class EsDatasourceController {
@Resource
EsDatasourceService esDatasourceService;
@PostMapping(value = "/list")
public ResponseJson list() {
QueryWrapper<EsDatasource> wrapper = new QueryWrapper<>();
wrapper.eq("yn", 1);
List<EsDatasource> datasourceList = esDatasourceService.list(wrapper);
return DocResponseJson.ok(datasourceList);
}
@PostMapping(value = "/update")
public ResponseJson update(EsDatasource esDatasource) {
if (StringUtils.isBlank(esDatasource.getName())) {
return DocResponseJson.warn("名字必填");
} else if (StringUtils.isBlank(esDatasource.getHostPort())) {
return DocResponseJson.warn("地址端口必选");
} else if (StringUtils.isBlank(esDatasource.getScheme())) {
return DocResponseJson.warn("scheme必填");
}
Long sourceId = Optional.ofNullable(esDatasource.getId()).orElse(0L);
if (sourceId > 0) {
// 这三项不需要修改
esDatasource.setCreateTime(null);
esDatasource.setCreateUserId(null);
esDatasource.setCreateUserName(null);
esDatasourceService.updateById(esDatasource);
} else {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
esDatasource.setCreateTime(new Date());
esDatasource.setCreateUserId(currentUser.getUserId());
esDatasource.setCreateUserName(currentUser.getUsername());
esDatasource.setYn(1);
esDatasourceService.save(esDatasource);
}
return DocResponseJson.ok();
}
}

View File

@@ -23,6 +23,9 @@ CREATE TABLE `db_datasource` (
INSERT INTO `auth_info`(`auth_name`, `auth_desc`, `can_edit`, `create_uid`, `creation_time`, `auth_type`)
VALUES ( 'DB_DATASOURCE_MANAGE', '数据源管理权', 0, 1, '2019-06-29 13:01:20', 1);
INSERT INTO `auth_info`(`auth_name`, `auth_desc`, `can_edit`, `create_uid`, `creation_time`, `auth_type`)
VALUES ( 'ES_DATASOURCE_MANAGE', 'ES数据源管理权', 0, 1, '2019-07-27 00:39:20', 1);
insert into user_auth(`user_id`, `auth_id`, `create_uid`, `del_flag`, `creation_time`)
select a.id, b.id, a.id, 0, now() from user_info a,auth_info b
where a.user_no='zyplayer' and b.auth_name='DB_DATASOURCE_MANAGE';
@@ -31,6 +34,21 @@ ALTER TABLE `wiki_page_content` MODIFY COLUMN `preview` varchar(16000) CHARACTER
-- alter table `db_datasource` add `name` varchar(50) DEFAULT NULL COMMENT '数据源名称';
CREATE TABLE `es_datasource` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
`name` varchar(50) DEFAULT NULL COMMENT '数据源名称',
`host_port` varchar(512) DEFAULT NULL COMMENT '地址和端口',
`scheme` varchar(512) DEFAULT NULL COMMENT 'schemehttp或其他',
`create_user_id` bigint(20) DEFAULT NULL COMMENT '创建人ID',
`create_user_name` varchar(20) DEFAULT NULL COMMENT '创建人名字',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`yn` tinyint(4) DEFAULT NULL COMMENT '是否有效 0=无效 1=有效',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- ------------------------全新的库:------------------------

View File

@@ -15,6 +15,13 @@
</template>
<el-menu-item index="/data/datasourceManage"><i class="el-icon-coin"></i>数据源管理</el-menu-item>
</el-submenu>
<el-submenu index="2">
<template slot="title">
<img src="./assets/img/elasticsearch.png" style="width: 18px;height: 18px;padding: 0 4px;">
<span slot="title">ES功能列表</span>
</template>
<el-menu-item index="/index/executer"><i class="el-icon-coin"></i>数据查询</el-menu-item>
</el-submenu>
</el-menu>
<el-tree :props="defaultProps" :data="esIndexList" @node-click="handleNodeClick"
ref="databaseTree" highlight-current draggable

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -11,8 +11,8 @@ var URL = {
updateTableDesc: '/zyplayer-doc-db/doc-db/updateTableDesc',
updateTableColumnDesc: '/zyplayer-doc-db/doc-db/updateTableColumnDesc',
manageDatasourceList: '/zyplayer-doc-db/datasource/list',
manageUpdateDatasource: '/zyplayer-doc-db/datasource/update',
manageDatasourceList: '/zyplayer-doc-es/datasource/list',
manageUpdateDatasource: '/zyplayer-doc-es/datasource/update',
esMappings: '/zyplayer-doc-es/es-mapping/mappings',
esExecuter: '/zyplayer-doc-es/es-mapping/execute',

View File

@@ -8,10 +8,9 @@
<el-button style="float: right;" v-on:click="addDatasource" type="primary" icon="el-icon-circle-plus-outline" size="small">新增</el-button>
</div>
<el-table :data="datasourceList" stripe border style="width: 100%; margin-bottom: 5px;">
<el-table-column prop="driverClassName" label="驱动类" width="200"></el-table-column>
<el-table-column prop="sourceUrl" label="数据源URL"></el-table-column>
<el-table-column prop="sourceName" label="账号"></el-table-column>
<el-table-column prop="sourcePassword" label="密码"></el-table-column>
<el-table-column prop="name" label="名字" width="200"></el-table-column>
<el-table-column prop="hostPort" label="地址和端口"></el-table-column>
<el-table-column prop="scheme" label="scheme"></el-table-column>
<el-table-column label="操作" width="150">
<template slot-scope="scope">
<el-button v-on:click="editDatasource(scope.row)" type="primary" size="small">修改</el-button>
@@ -23,27 +22,17 @@
</div>
<!--增加数据源弹窗-->
<el-dialog :inline="true" :title="newDatasource.id>0?'编辑数据源':'新增数据源'" :visible.sync="datasourceDialogVisible" width="600px">
<el-alert
title="重要提醒"
description="请录入正确可用的数据库连接、账号、密码信息,否则初始化数据源失败将影响整个系统,有可能需要重启服务才能解决"
type="warning" :closable="false"
show-icon style="margin-bottom: 10px;">
</el-alert>
<el-form label-width="120px">
<el-form-item label="驱动类">
<el-select v-model="newDatasource.driverClassName" placeholder="驱动类" style="width: 100%">
<el-option label="com.mysql.jdbc.Driver" value="com.mysql.jdbc.Driver"></el-option>
<el-option label="net.sourceforge.jtds.jdbc.Driver" value="net.sourceforge.jtds.jdbc.Driver"></el-option>
</el-select>
<el-form-item label="名字">
<el-input v-model="newDatasource.name" placeholder="中文名字"></el-input>
</el-form-item>
<el-form-item label="数据源URL">
<el-input v-model="newDatasource.sourceUrl" placeholder="数据源URL"></el-input>
<el-input v-model="newDatasource.hostPort" placeholder="地址和端口"></el-input>
</el-form-item>
<el-form-item label="账号">
<el-input v-model="newDatasource.sourceName" placeholder="账号"></el-input>
</el-form-item>
<el-form-item label="密码:">
<el-input v-model="newDatasource.sourcePassword" placeholder="密码"></el-input>
<el-form-item label="scheme">
<el-select v-model="newDatasource.scheme" placeholder="scheme" style="width: 100%">
<el-option label="http" value="http"></el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" style="text-align: center;">
@@ -76,7 +65,7 @@
methods: {
addDatasource() {
this.datasourceDialogVisible = true;
this.newDatasource = {driverClassName: "", sourceUrl: "", sourceName: "", sourcePassword: ""};
this.newDatasource = {name: "", hostPort: "", scheme: "http"};
},
editDatasource(row) {
this.newDatasource = row;

View File

@@ -9,12 +9,12 @@
</div>
<el-input type="textarea" v-model="executeParam.sql" :rows="10" placeholder="请输入"></el-input>
<div style="text-align: center;margin: 10px 0;">
<el-button type="primary" v-on:click="submitExecute">执行</el-button>
<el-button type="primary" icon="el-icon-video-play" v-on:click="submitExecute">执行</el-button>
</div>
</el-card>
<el-card style="margin: 10px;">
<el-card style="margin: 10px;" v-loading="executeLoading">
<div style="margin: 10px 0;">
<span>执行结果{{executeResult.errCode == 200 ? '成功' : '失败'}}</span>
<span>执行状态{{executeResult.errCode == 200 ? '成功' : '失败'}}</span>
</div>
<div style="margin: 10px 0;" v-if="executeResult.errCode == 200">
<div style="margin: 10px 0;">返回结果</div>
@@ -36,7 +36,6 @@
export default {
data() {
return {
indexMappingListLoading: false,
vueQueryParam: {},
indexMappingList: [],
executeParam: {
@@ -44,6 +43,7 @@
index: '',
},
executeResult: {},
executeLoading: false,
};
},
beforeRouteUpdate(to, from, next) {
@@ -60,7 +60,7 @@
},
methods: {
submitExecute() {
this.indexMappingListLoading = true;
this.executeLoading = true;
this.executeResult = {};
this.common.postNonCheck(this.apilist1.esExecuter, this.executeParam, function (json) {
var executeResult = json;
@@ -70,7 +70,8 @@
executeResult.data = "结果解析失败";
}
app.executeResult = executeResult;
app.indexMappingListLoading = false;
// 防止遮罩消失太快~
setTimeout(()=>{app.executeLoading = false;}, 500);
});
},
executeResultClick(e) {