mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-30 13:00:32 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22c401f9d8 | ||
|
|
be00b90c1d | ||
|
|
fb3f89c594 | ||
|
|
e7a66378ea |
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
### 介绍
|
### 介绍
|
||||||
基于DDD分层实现的web版 **linux(终端 文件 脚本 进程)、数据库(mysql postgres)、redis(单机 哨兵 集群)、mongo统一管理操作平台**
|
web版 **linux(终端[终端回放] 文件 脚本 进程)、数据库(mysql postgres)、redis(单机 哨兵 集群)、mongo统一管理操作平台**
|
||||||
|
|
||||||
|
|
||||||
### 开发语言与主要框架
|
### 开发语言与主要框架
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ function buildWindows() {
|
|||||||
build "$1/mayfly-go-windows" "windows" "amd64" $2
|
build "$1/mayfly-go-windows" "windows" "amd64" $2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildMac() {
|
||||||
|
build "$1/mayfly-go-mac" "darwin" "amd64" $2
|
||||||
|
}
|
||||||
|
|
||||||
function runBuild() {
|
function runBuild() {
|
||||||
# 构建结果的目的路径
|
# 构建结果的目的路径
|
||||||
read -p "请输入构建产物输出目录: " toPath
|
read -p "请输入构建产物输出目录: " toPath
|
||||||
@@ -107,7 +111,7 @@ function runBuild() {
|
|||||||
toPath=`pwd`
|
toPath=`pwd`
|
||||||
|
|
||||||
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static/static]: " runBuildWeb
|
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static/static]: " runBuildWeb
|
||||||
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows]: " buildType
|
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows 4->mac]: " buildType
|
||||||
|
|
||||||
|
|
||||||
if [ "${runBuildWeb}" == "1" ] || [ "${runBuildWeb}" == "2" ] ; then
|
if [ "${runBuildWeb}" == "1" ] || [ "${runBuildWeb}" == "2" ] ; then
|
||||||
@@ -124,10 +128,14 @@ function runBuild() {
|
|||||||
"3")
|
"3")
|
||||||
buildWindows ${toPath} ${runBuildWeb}
|
buildWindows ${toPath} ${runBuildWeb}
|
||||||
;;
|
;;
|
||||||
|
"4")
|
||||||
|
buildMac ${toPath} ${runBuildWeb}
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||||
buildWindows ${toPath} ${runBuildWeb}
|
buildWindows ${toPath} ${runBuildWeb}
|
||||||
|
buildMac ${toPath} ${runBuildWeb}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"countup.js": "^2.0.7",
|
"countup.js": "^2.0.7",
|
||||||
"cropperjs": "^1.5.11",
|
"cropperjs": "^1.5.11",
|
||||||
"echarts": "^5.3.3",
|
"echarts": "^5.3.3",
|
||||||
"element-plus": "^2.2.15",
|
"element-plus": "^2.2.17",
|
||||||
"jsencrypt": "^3.2.1",
|
"jsencrypt": "^3.2.1",
|
||||||
"jsoneditor": "^9.9.0",
|
"jsoneditor": "^9.9.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
@@ -26,8 +26,8 @@
|
|||||||
"vue-clipboard3": "^1.0.1",
|
"vue-clipboard3": "^1.0.1",
|
||||||
"vue-router": "^4.1.2",
|
"vue-router": "^4.1.2",
|
||||||
"vuex": "^4.0.2",
|
"vuex": "^4.0.2",
|
||||||
"xterm": "^4.19.0",
|
"xterm": "^5.0.0",
|
||||||
"xterm-addon-fit": "^0.5.0"
|
"xterm-addon-fit": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash": "^4.14.178",
|
"@types/lodash": "^4.14.178",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ body,
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font-family: Microsoft YaHei, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, SimSun, sans-serif;
|
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
||||||
font-weight: 450;
|
font-weight: 450;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
|
import { nextTick, onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { initBackEndControlRoutesFun } from '@/router/index.ts';
|
import { initBackEndControlRoutesFun } from '@/router/index.ts';
|
||||||
@@ -95,7 +95,7 @@ export default defineComponent({
|
|||||||
const changePwdFormRef: any = ref(null);
|
const changePwdFormRef: any = ref(null);
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
useLoginCaptcha: true,
|
useLoginCaptcha: false,
|
||||||
captchaImage: '',
|
captchaImage: '',
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: '',
|
username: '',
|
||||||
@@ -133,11 +133,13 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 移除公钥, 方便后续重新获取
|
nextTick(async () => {
|
||||||
sessionStorage.removeItem('RsaPublicKey');
|
|
||||||
state.useLoginCaptcha = await useLoginCaptcha();
|
state.useLoginCaptcha = await useLoginCaptcha();
|
||||||
getCaptcha();
|
getCaptcha();
|
||||||
});
|
});
|
||||||
|
// 移除公钥, 方便后续重新获取
|
||||||
|
sessionStorage.removeItem('RsaPublicKey');
|
||||||
|
});
|
||||||
|
|
||||||
const getCaptcha = async () => {
|
const getCaptcha = async () => {
|
||||||
if (!state.useLoginCaptcha) {
|
if (!state.useLoginCaptcha) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
>删除</el-button
|
>删除</el-button
|
||||||
>
|
>
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
<el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
|
<el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
|
||||||
@@ -29,8 +29,12 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="type" label="类型" min-width="90"></el-table-column>
|
<el-table-column prop="type" label="类型" min-width="90"></el-table-column>
|
||||||
<el-table-column prop="database" label="数据库" min-width="160">
|
<el-table-column prop="database" label="数据库" min-width="80">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
|
<el-popover :width="250" placement="right" trigger="click">
|
||||||
|
<template #reference>
|
||||||
|
<el-link type="primary" :underline="false" plain>查看</el-link>
|
||||||
|
</template>
|
||||||
<el-tag
|
<el-tag
|
||||||
@click="showTableInfo(scope.row, db)"
|
@click="showTableInfo(scope.row, db)"
|
||||||
effect="plain"
|
effect="plain"
|
||||||
@@ -38,9 +42,10 @@
|
|||||||
size="small"
|
size="small"
|
||||||
v-for="db in scope.row.dbs"
|
v-for="db in scope.row.dbs"
|
||||||
:key="db"
|
:key="db"
|
||||||
style="cursor: pointer; margin-left: 3px"
|
style="cursor: pointer; margin-left: 3px; margin-bottom: 3px;"
|
||||||
>{{ db }}</el-tag
|
>{{ db }}</el-tag
|
||||||
>
|
>
|
||||||
|
</el-popover>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
|
<el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
|
||||||
@@ -161,8 +166,10 @@
|
|||||||
v-model="sqlExecLogDialog.visible"
|
v-model="sqlExecLogDialog.visible"
|
||||||
>
|
>
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<el-input v-model="sqlExecLogDialog.query.db" placeholder="请输入数据库名" clearable style="width: 150px" />
|
<el-select v-model="sqlExecLogDialog.query.db" placeholder="请选择数据库" filterable clearable>
|
||||||
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 150px" />
|
<el-option v-for="item in sqlExecLogDialog.dbs" :key="item" :label="`${item}`" :value="item"> </el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 180px" />
|
||||||
<el-select v-model="sqlExecLogDialog.query.type" placeholder="请选择操作类型" clearable class="ml5">
|
<el-select v-model="sqlExecLogDialog.query.type" placeholder="请选择操作类型" clearable class="ml5">
|
||||||
<el-option v-for="item in enums.DbSqlExecTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
<el-option v-for="item in enums.DbSqlExecTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
@@ -307,6 +314,7 @@ export default defineComponent({
|
|||||||
visible: false,
|
visible: false,
|
||||||
data: [],
|
data: [],
|
||||||
total: 0,
|
total: 0,
|
||||||
|
dbs: [],
|
||||||
query: {
|
query: {
|
||||||
dbId: 0,
|
dbId: 0,
|
||||||
db: '',
|
db: '',
|
||||||
@@ -398,8 +406,12 @@ export default defineComponent({
|
|||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const editDb = async (isAdd = false) => {
|
const getProjects = async () => {
|
||||||
state.projects = await projectApi.accountProjects.request(null);
|
state.projects = await projectApi.accountProjects.request(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const editDb = async (isAdd = false) => {
|
||||||
|
await getProjects();
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
state.dbEditDialog.data = null;
|
state.dbEditDialog.data = null;
|
||||||
state.dbEditDialog.title = '新增数据库资源';
|
state.dbEditDialog.title = '新增数据库资源';
|
||||||
@@ -434,6 +446,7 @@ export default defineComponent({
|
|||||||
const onShowSqlExec = async (row: any) => {
|
const onShowSqlExec = async (row: any) => {
|
||||||
state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
|
state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
|
||||||
state.sqlExecLogDialog.query.dbId = row.id;
|
state.sqlExecLogDialog.query.dbId = row.id;
|
||||||
|
state.sqlExecLogDialog.dbs = row.database.split(' ');
|
||||||
searchSqlExecLog();
|
searchSqlExecLog();
|
||||||
state.sqlExecLogDialog.visible = true;
|
state.sqlExecLogDialog.visible = true;
|
||||||
};
|
};
|
||||||
@@ -441,6 +454,7 @@ export default defineComponent({
|
|||||||
const onBeforeCloseSqlExecDialog = () => {
|
const onBeforeCloseSqlExecDialog = () => {
|
||||||
state.sqlExecLogDialog.visible = false;
|
state.sqlExecLogDialog.visible = false;
|
||||||
state.sqlExecLogDialog.data = [];
|
state.sqlExecLogDialog.data = [];
|
||||||
|
state.sqlExecLogDialog.dbs = [];
|
||||||
state.sqlExecLogDialog.total = 0;
|
state.sqlExecLogDialog.total = 0;
|
||||||
state.sqlExecLogDialog.query.dbId = 0;
|
state.sqlExecLogDialog.query.dbId = 0;
|
||||||
state.sqlExecLogDialog.query.pageNum = 1;
|
state.sqlExecLogDialog.query.pageNum = 1;
|
||||||
@@ -602,6 +616,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
|
getProjects,
|
||||||
filterTableInfos,
|
filterTableInfos,
|
||||||
enums,
|
enums,
|
||||||
search,
|
search,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="50%">
|
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="70%">
|
||||||
<el-progress
|
<el-progress
|
||||||
v-if="uploadProgressShow"
|
v-if="uploadProgressShow"
|
||||||
style="width: 90%; margin-left: 20px"
|
style="width: 90%; margin-left: 20px"
|
||||||
@@ -85,6 +85,10 @@
|
|||||||
{{ node.label }}
|
{{ node.label }}
|
||||||
<span style="color: #67c23a" v-if="data.type == '-'"> [{{ formatFileSize(data.size) }}]</span>
|
<span style="color: #67c23a" v-if="data.type == '-'"> [{{ formatFileSize(data.size) }}]</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<span style="display: inline-block">
|
||||||
|
<span v-if="data.mode" style="color: #67c23a"> [{{ data.mode }} {{ data.modTime }}]</span>
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
>删除</el-button
|
>删除</el-button
|
||||||
>
|
>
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
<el-select v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
|
<el-select @focus="getProjects" v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
|
||||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-input
|
<el-input
|
||||||
@@ -166,8 +166,6 @@
|
|||||||
:machineId="machineStatsDialog.machineId"
|
:machineId="machineStatsDialog.machineId"
|
||||||
:title="machineStatsDialog.title"
|
:title="machineStatsDialog.title"
|
||||||
></machine-stats>
|
></machine-stats>
|
||||||
|
|
||||||
<!-- <machine-rec v-model:visible="machineRecDialog.visible" :title="machineRecDialog.title" :machine-id="machineRecDialog.machineId" /> -->
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -182,7 +180,6 @@ import FileManage from './FileManage.vue';
|
|||||||
import MachineEdit from './MachineEdit.vue';
|
import MachineEdit from './MachineEdit.vue';
|
||||||
import ProcessList from './ProcessList.vue';
|
import ProcessList from './ProcessList.vue';
|
||||||
import MachineStats from './MachineStats.vue';
|
import MachineStats from './MachineStats.vue';
|
||||||
// import MachineRec from './MachineRec.vue';
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'MachineList',
|
name: 'MachineList',
|
||||||
@@ -192,7 +189,6 @@ export default defineComponent({
|
|||||||
FileManage,
|
FileManage,
|
||||||
MachineEdit,
|
MachineEdit,
|
||||||
MachineStats,
|
MachineStats,
|
||||||
// MachineRec,
|
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -279,8 +275,12 @@ export default defineComponent({
|
|||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const openFormDialog = async (machine: any) => {
|
const getProjects = async () => {
|
||||||
state.projects = await projectApi.accountProjects.request(null);
|
state.projects = await projectApi.accountProjects.request(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openFormDialog = async (machine: any) => {
|
||||||
|
await getProjects();
|
||||||
let dialogTitle;
|
let dialogTitle;
|
||||||
if (machine) {
|
if (machine) {
|
||||||
state.machineEditDialog.data = state.currentData as any;
|
state.machineEditDialog.data = state.currentData as any;
|
||||||
@@ -372,6 +372,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
choose,
|
choose,
|
||||||
|
getProjects,
|
||||||
showTerminal,
|
showTerminal,
|
||||||
openFormDialog,
|
openFormDialog,
|
||||||
deleteMachine,
|
deleteMachine,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
|
<el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
|
||||||
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
|
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
<el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||||
@@ -370,8 +370,12 @@ export default defineComponent({
|
|||||||
state.total = res.total;
|
state.total = res.total;
|
||||||
};
|
};
|
||||||
|
|
||||||
const editMongo = async (isAdd = false) => {
|
const getProjects = async () => {
|
||||||
state.projects = await projectApi.accountProjects.request(null);
|
state.projects = await projectApi.accountProjects.request(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const editMongo = async (isAdd = false) => {
|
||||||
|
await getProjects();
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
state.mongoEditDialog.data = null;
|
state.mongoEditDialog.data = null;
|
||||||
state.mongoEditDialog.title = '新增mongo';
|
state.mongoEditDialog.title = '新增mongo';
|
||||||
@@ -390,6 +394,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
|
getProjects,
|
||||||
search,
|
search,
|
||||||
handlePageChange,
|
handlePageChange,
|
||||||
choose,
|
choose,
|
||||||
|
|||||||
@@ -80,9 +80,18 @@
|
|||||||
<el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
|
<el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<el-button @click="showAddEnvDialog" v-auth="permissions.saveMember" type="primary" icon="plus">添加</el-button>
|
<el-button @click="showAddEnvDialog" v-auth="permissions.saveMember" type="primary" icon="plus">添加</el-button>
|
||||||
<!-- <el-button v-auth="'role:update'" :disabled="chooseId == null" type="danger" icon="delete">删除</el-button> -->
|
<el-button @click="deleteEnv" v-auth="permissions.delProject" :disabled="showEnvDialog.chooseId == null" type="danger" icon="delete"
|
||||||
|
>删除</el-button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<el-table border :data="showEnvDialog.envs">
|
<el-table @current-change="chooseEnv" border :data="showEnvDialog.envs">
|
||||||
|
<el-table-column label="选择" width="50px">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-radio v-model="showEnvDialog.chooseId" :label="scope.row.id">
|
||||||
|
<i></i>
|
||||||
|
</el-radio>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column property="name" label="环境名" width="125"></el-table-column>
|
<el-table-column property="name" label="环境名" width="125"></el-table-column>
|
||||||
<el-table-column property="remark" label="描述" width="125"></el-table-column>
|
<el-table-column property="remark" label="描述" width="125"></el-table-column>
|
||||||
<el-table-column property="createTime" label="创建时间">
|
<el-table-column property="createTime" label="创建时间">
|
||||||
@@ -207,6 +216,8 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
showEnvDialog: {
|
showEnvDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
|
chooseId: null,
|
||||||
|
chooseData: null,
|
||||||
envs: [],
|
envs: [],
|
||||||
title: '',
|
title: '',
|
||||||
addVisible: false,
|
addVisible: false,
|
||||||
@@ -340,6 +351,21 @@ export default defineComponent({
|
|||||||
state.showEnvDialog.visible = true;
|
state.showEnvDialog.visible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const chooseEnv = (item: any) => {
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.showEnvDialog.chooseData = item;
|
||||||
|
state.showEnvDialog.chooseId = item.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteEnv = async () => {
|
||||||
|
notNull(state.showEnvDialog.chooseData, '请选选择环境');
|
||||||
|
await projectApi.delProjectEnvs.request({ id: state.showEnvDialog.chooseId });
|
||||||
|
ElMessage.success('删除成功');
|
||||||
|
state.showEnvDialog.envs = await projectApi.projectEnvs.request({ projectId: state.chooseId });
|
||||||
|
};
|
||||||
|
|
||||||
const showAddMemberDialog = () => {
|
const showAddMemberDialog = () => {
|
||||||
state.showMemDialog.addVisible = true;
|
state.showMemDialog.addVisible = true;
|
||||||
};
|
};
|
||||||
@@ -398,12 +424,14 @@ export default defineComponent({
|
|||||||
showMembers,
|
showMembers,
|
||||||
setMemebers,
|
setMemebers,
|
||||||
showEnv,
|
showEnv,
|
||||||
|
deleteEnv,
|
||||||
showAddMemberDialog,
|
showAddMemberDialog,
|
||||||
addMember,
|
addMember,
|
||||||
chooseMember,
|
chooseMember,
|
||||||
deleteMember,
|
deleteMember,
|
||||||
cancelAddMember,
|
cancelAddMember,
|
||||||
showAddEnvDialog,
|
showAddEnvDialog,
|
||||||
|
chooseEnv,
|
||||||
addEnv,
|
addEnv,
|
||||||
cancelAddEnv,
|
cancelAddEnv,
|
||||||
getAccount,
|
getAccount,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const projectApi = {
|
|||||||
delProject: Api.create("/projects", 'delete'),
|
delProject: Api.create("/projects", 'delete'),
|
||||||
// 获取项目下的环境信息
|
// 获取项目下的环境信息
|
||||||
projectEnvs: Api.create("/projects/{projectId}/envs", 'get'),
|
projectEnvs: Api.create("/projects/{projectId}/envs", 'get'),
|
||||||
|
delProjectEnvs: Api.create("/projects/envs", 'delete'),
|
||||||
saveProjectEnv: Api.create("/projects/{projectId}/envs", 'post'),
|
saveProjectEnv: Api.create("/projects/{projectId}/envs", 'post'),
|
||||||
// 获取项目下的成员信息
|
// 获取项目下的成员信息
|
||||||
projectMems: Api.create("/projects/{projectId}/members", 'get'),
|
projectMems: Api.create("/projects/{projectId}/members", 'get'),
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
<el-tag @click="onAddData('string')" :color="getTypeColor('string')" style="cursor: pointer">string</el-tag>
|
<el-tag @click="onAddData('string')" :color="getTypeColor('string')" style="cursor: pointer">string</el-tag>
|
||||||
<el-tag @click="onAddData('hash')" :color="getTypeColor('hash')" class="ml5" style="cursor: pointer">hash</el-tag>
|
<el-tag @click="onAddData('hash')" :color="getTypeColor('hash')" class="ml5" style="cursor: pointer">hash</el-tag>
|
||||||
<el-tag @click="onAddData('set')" :color="getTypeColor('set')" class="ml5" style="cursor: pointer">set</el-tag>
|
<el-tag @click="onAddData('set')" :color="getTypeColor('set')" class="ml5" style="cursor: pointer">set</el-tag>
|
||||||
|
<!-- <el-tag @click="onAddData('list')" :color="getTypeColor('list')" class="ml5" style="cursor: pointer">list</el-tag> -->
|
||||||
</el-popover>
|
</el-popover>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
@@ -105,6 +106,16 @@
|
|||||||
@valChange="searchKey"
|
@valChange="searchKey"
|
||||||
@cancel="onCancelDataEdit"
|
@cancel="onCancelDataEdit"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<list-value
|
||||||
|
v-model:visible="listValueDialog.visible"
|
||||||
|
:title="dataEdit.title"
|
||||||
|
:keyInfo="dataEdit.keyInfo"
|
||||||
|
:redisId="scanParam.id"
|
||||||
|
:operationType="dataEdit.operationType"
|
||||||
|
@valChange="searchKey"
|
||||||
|
@cancel="onCancelDataEdit"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -116,6 +127,7 @@ import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
|||||||
import HashValue from './HashValue.vue';
|
import HashValue from './HashValue.vue';
|
||||||
import StringValue from './StringValue.vue';
|
import StringValue from './StringValue.vue';
|
||||||
import SetValue from './SetValue.vue';
|
import SetValue from './SetValue.vue';
|
||||||
|
import ListValue from './ListValue.vue';
|
||||||
import { isTrue, notBlank, notNull } from '@/common/assert';
|
import { isTrue, notBlank, notNull } from '@/common/assert';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -124,6 +136,7 @@ export default defineComponent({
|
|||||||
StringValue,
|
StringValue,
|
||||||
HashValue,
|
HashValue,
|
||||||
SetValue,
|
SetValue,
|
||||||
|
ListValue,
|
||||||
ProjectEnvSelect,
|
ProjectEnvSelect,
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
@@ -158,6 +171,9 @@ export default defineComponent({
|
|||||||
setValueDialog: {
|
setValueDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
},
|
},
|
||||||
|
listValueDialog: {
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
keys: [],
|
keys: [],
|
||||||
dbsize: 0,
|
dbsize: 0,
|
||||||
});
|
});
|
||||||
@@ -253,6 +269,8 @@ export default defineComponent({
|
|||||||
state.stringValueDialog.visible = true;
|
state.stringValueDialog.visible = true;
|
||||||
} else if (type == 'set') {
|
} else if (type == 'set') {
|
||||||
state.setValueDialog.visible = true;
|
state.setValueDialog.visible = true;
|
||||||
|
} else if (type == 'list') {
|
||||||
|
state.listValueDialog.visible = true;
|
||||||
} else {
|
} else {
|
||||||
ElMessage.warning('暂不支持该类型');
|
ElMessage.warning('暂不支持该类型');
|
||||||
}
|
}
|
||||||
@@ -270,6 +288,8 @@ export default defineComponent({
|
|||||||
state.stringValueDialog.visible = true;
|
state.stringValueDialog.visible = true;
|
||||||
} else if (type == 'set') {
|
} else if (type == 'set') {
|
||||||
state.setValueDialog.visible = true;
|
state.setValueDialog.visible = true;
|
||||||
|
} else if (type == 'list') {
|
||||||
|
state.listValueDialog.visible = true;
|
||||||
} else {
|
} else {
|
||||||
ElMessage.warning('暂不支持该类型');
|
ElMessage.warning('暂不支持该类型');
|
||||||
}
|
}
|
||||||
|
|||||||
205
mayfly_go_web/src/views/ops/redis/ListValue.vue
Normal file
205
mayfly_go_web/src/views/ops/redis/ListValue.vue
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
|
||||||
|
<el-form label-width="85px">
|
||||||
|
<el-form-item prop="key" label="key:">
|
||||||
|
<el-input :disabled="operationType == 2" v-model="key.key"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="timed" label="过期时间:">
|
||||||
|
<el-input v-model.number="key.timed" type="number"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="dataType" label="数据类型:">
|
||||||
|
<el-input v-model="key.type" disabled></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- <el-button @click="onAddListValue" icon="plus" size="small" plain class="mt10">添加</el-button> -->
|
||||||
|
<div v-if="operationType == 2" class="mt10" style="float: left">
|
||||||
|
<span>len: {{ len }}</span>
|
||||||
|
</div>
|
||||||
|
<el-table :data="value" stripe style="width: 100%">
|
||||||
|
<el-table-column prop="value" label="value" min-width="200">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-input v-model="scope.row.value" clearable type="textarea" :autosize="{ minRows: 2, maxRows: 10 }" size="small"></el-input>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" width="140">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
v-if="operationType == 2"
|
||||||
|
type="success"
|
||||||
|
@click="lset(scope.row, scope.$index)"
|
||||||
|
icon="check"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
></el-button>
|
||||||
|
<!-- <el-button type="danger" @click="set.value.splice(scope.$index, 1)" icon="delete" size="small" plain></el-button> -->
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||||
|
<el-pagination
|
||||||
|
style="text-align: right"
|
||||||
|
:total="len"
|
||||||
|
layout="prev, pager, next, total"
|
||||||
|
@current-change="handlePageChange"
|
||||||
|
v-model:current-page="pageNum"
|
||||||
|
:page-size="pageSize"
|
||||||
|
></el-pagination>
|
||||||
|
</el-row>
|
||||||
|
</el-form>
|
||||||
|
<!-- <template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button @click="cancel()">取 消</el-button>
|
||||||
|
<el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
|
||||||
|
</div>
|
||||||
|
</template> -->
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent, reactive, watch, toRefs } from 'vue';
|
||||||
|
import { redisApi } from './api';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import { isTrue, notEmpty } from '@/common/assert';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'ListValue',
|
||||||
|
components: {},
|
||||||
|
props: {
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
redisId: {
|
||||||
|
type: [Number],
|
||||||
|
require: true,
|
||||||
|
},
|
||||||
|
keyInfo: {
|
||||||
|
type: [Object],
|
||||||
|
},
|
||||||
|
// 操作类型,1:新增,2:修改
|
||||||
|
operationType: {
|
||||||
|
type: [Number],
|
||||||
|
},
|
||||||
|
listValue: {
|
||||||
|
type: [Array, Object],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['valChange', 'cancel', 'update:visible'],
|
||||||
|
setup(props: any, { emit }) {
|
||||||
|
const state = reactive({
|
||||||
|
dialogVisible: false,
|
||||||
|
operationType: 1,
|
||||||
|
redisId: '',
|
||||||
|
key: {
|
||||||
|
key: '',
|
||||||
|
type: 'string',
|
||||||
|
timed: -1,
|
||||||
|
},
|
||||||
|
value: [{ value: '' }],
|
||||||
|
len: 0,
|
||||||
|
start: 0,
|
||||||
|
stop: 0,
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
const cancel = () => {
|
||||||
|
emit('update:visible', false);
|
||||||
|
emit('cancel');
|
||||||
|
setTimeout(() => {
|
||||||
|
state.key = {
|
||||||
|
key: '',
|
||||||
|
type: 'string',
|
||||||
|
timed: -1,
|
||||||
|
};
|
||||||
|
state.value = [];
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(props, async (newValue) => {
|
||||||
|
state.dialogVisible = newValue.visible;
|
||||||
|
state.key = newValue.key;
|
||||||
|
state.redisId = newValue.redisId;
|
||||||
|
state.key = newValue.keyInfo;
|
||||||
|
state.operationType = newValue.operationType;
|
||||||
|
// 如果是查看编辑操作,则获取值
|
||||||
|
if (state.dialogVisible && state.operationType == 2) {
|
||||||
|
getListValue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const getListValue = async () => {
|
||||||
|
const pageNum = state.pageNum;
|
||||||
|
const pageSize = state.pageSize;
|
||||||
|
const res = await redisApi.getListValue.request({
|
||||||
|
id: state.redisId,
|
||||||
|
key: state.key.key,
|
||||||
|
start: (pageNum - 1) * pageSize,
|
||||||
|
stop: pageNum * pageSize - 1,
|
||||||
|
});
|
||||||
|
state.len = res.len;
|
||||||
|
state.value = res.list.map((x: any) => {
|
||||||
|
return {
|
||||||
|
value: x,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const lset = async (row: any, rowIndex: number) => {
|
||||||
|
await redisApi.setListValue.request({
|
||||||
|
id: state.redisId,
|
||||||
|
key: state.key.key,
|
||||||
|
index: (state.pageNum - 1) * state.pageSize + rowIndex,
|
||||||
|
value: row.value,
|
||||||
|
});
|
||||||
|
ElMessage.success('数据保存成功');
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveValue = async () => {
|
||||||
|
notEmpty(state.key.key, 'key不能为空');
|
||||||
|
isTrue(state.value.length > 0, 'list内容不能为空');
|
||||||
|
// const sv = { value: state.value.map((x) => x.value), id: state.redisId };
|
||||||
|
// Object.assign(sv, state.key);
|
||||||
|
// await redisApi.saveSetValue.request(sv);
|
||||||
|
|
||||||
|
ElMessage.success('数据保存成功');
|
||||||
|
cancel();
|
||||||
|
emit('valChange');
|
||||||
|
};
|
||||||
|
|
||||||
|
const onAddListValue = () => {
|
||||||
|
state.value.unshift({ value: '' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageChange = (curPage: number) => {
|
||||||
|
state.pageNum = curPage;
|
||||||
|
getListValue();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
saveValue,
|
||||||
|
handlePageChange,
|
||||||
|
cancel,
|
||||||
|
lset,
|
||||||
|
onAddListValue,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<style lang="scss">
|
||||||
|
#string-value-text {
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.text-type-select {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
right: 10px;
|
||||||
|
top: 10px;
|
||||||
|
max-width: 70px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<el-button type="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑</el-button>
|
<el-button type="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑</el-button>
|
||||||
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
|
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
<el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||||
@@ -263,8 +263,12 @@ export default defineComponent({
|
|||||||
state.total = res.total;
|
state.total = res.total;
|
||||||
};
|
};
|
||||||
|
|
||||||
const editRedis = async (isAdd = false) => {
|
const getProjects = async () => {
|
||||||
state.projects = await projectApi.accountProjects.request(null);
|
state.projects = await projectApi.accountProjects.request(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const editRedis = async (isAdd = false) => {
|
||||||
|
await getProjects();
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
state.redisEditDialog.data = null;
|
state.redisEditDialog.data = null;
|
||||||
state.redisEditDialog.title = '新增redis';
|
state.redisEditDialog.title = '新增redis';
|
||||||
@@ -283,6 +287,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
|
getProjects,
|
||||||
search,
|
search,
|
||||||
handlePageChange,
|
handlePageChange,
|
||||||
choose,
|
choose,
|
||||||
|
|||||||
@@ -20,4 +20,7 @@ export const redisApi = {
|
|||||||
saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
|
saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
|
||||||
del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'),
|
del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'),
|
||||||
delKey: Api.create("/redis/{id}/key", 'delete'),
|
delKey: Api.create("/redis/{id}/key", 'delete'),
|
||||||
|
getListValue: Api.create("/redis/{id}/list-value", 'get'),
|
||||||
|
saveListValue: Api.create("/redis/{id}/list-value", 'post'),
|
||||||
|
setListValue: Api.create("/redis/{id}/list-value/lset", 'post'),
|
||||||
}
|
}
|
||||||
@@ -44,17 +44,17 @@
|
|||||||
minimatch "^3.0.4"
|
minimatch "^3.0.4"
|
||||||
strip-json-comments "^3.1.1"
|
strip-json-comments "^3.1.1"
|
||||||
|
|
||||||
"@floating-ui/core@^0.7.3":
|
"@floating-ui/core@^1.0.1":
|
||||||
version "0.7.3"
|
version "1.0.1"
|
||||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-0.7.3.tgz"
|
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-1.0.1.tgz#00e64d74e911602c8533957af0cce5af6b2e93c8"
|
||||||
integrity sha512-buc8BXHmG9l82+OQXOFU3Kr2XQx9ys01U/Q9HMIrZ300iLc8HLMgh7dcCqgYzAzf4BkoQvDcXf5Y+CuEZ5JBYg==
|
integrity sha512-bO37brCPfteXQfFY0DyNDGB3+IMe4j150KFQcgJ5aBP295p9nBGeHEs/p0czrRbtlHq4Px/yoPXO/+dOCcF4uA==
|
||||||
|
|
||||||
"@floating-ui/dom@^0.5.4":
|
"@floating-ui/dom@^1.0.1":
|
||||||
version "0.5.4"
|
version "1.0.1"
|
||||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-0.5.4.tgz"
|
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-1.0.1.tgz#3321d4e799d6ac2503e729131d07ad0e714aabeb"
|
||||||
integrity sha512-419BMceRLq0RrmTSDxn8hf9R3VCJv2K9PUfugh5JyEFmdjzDo+e8U5EdR8nzKq8Yj1htzLm3b6eQEEam3/rrtg==
|
integrity sha512-wBDiLUKWU8QNPNOTAFHiIAkBv1KlHauG2AhqjSeh2H+wR8PX+AArXfz8NkRexH5PgMJMmSOS70YS89AbWYh5dA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@floating-ui/core" "^0.7.3"
|
"@floating-ui/core" "^1.0.1"
|
||||||
|
|
||||||
"@humanwhocodes/config-array@^0.9.2":
|
"@humanwhocodes/config-array@^0.9.2":
|
||||||
version "0.9.2"
|
version "0.9.2"
|
||||||
@@ -658,14 +658,14 @@ echarts@^5.3.3:
|
|||||||
tslib "2.3.0"
|
tslib "2.3.0"
|
||||||
zrender "5.3.2"
|
zrender "5.3.2"
|
||||||
|
|
||||||
element-plus@^2.2.15:
|
element-plus@^2.2.17:
|
||||||
version "2.2.15"
|
version "2.2.17"
|
||||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.15.tgz#862bb6ecbd15b2d82d79dcf56bbbc30010771132"
|
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.17.tgz#abbb12c19dc029c95b0271822ea9a0e635704bc2"
|
||||||
integrity sha512-SMIx8xKB1YawT9JocyFhbs3Av2rXFfxrCVTLMYS0DK0xnW+fKvwjZngLfwF6MyRzXIuzNW17XFtu0iP3tlJHbA==
|
integrity sha512-MGwMIE/q+FFD3kgS23x8HIe5043tmD1cTRwjhIX9o6fim1avFnUkrsfYRvybbz4CkyqSb185EheZS5AUPpXh2g==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@ctrl/tinycolor" "^3.4.1"
|
"@ctrl/tinycolor" "^3.4.1"
|
||||||
"@element-plus/icons-vue" "^2.0.6"
|
"@element-plus/icons-vue" "^2.0.6"
|
||||||
"@floating-ui/dom" "^0.5.4"
|
"@floating-ui/dom" "^1.0.1"
|
||||||
"@popperjs/core" "npm:@sxzz/popperjs-es@^2.11.7"
|
"@popperjs/core" "npm:@sxzz/popperjs-es@^2.11.7"
|
||||||
"@types/lodash" "^4.14.182"
|
"@types/lodash" "^4.14.182"
|
||||||
"@types/lodash-es" "^4.17.6"
|
"@types/lodash-es" "^4.17.6"
|
||||||
@@ -1810,15 +1810,15 @@ wrappy@1:
|
|||||||
resolved "https://registry.nlark.com/wrappy/download/wrappy-1.0.2.tgz?cache=0&sync_timestamp=1619133505879&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fwrappy%2Fdownload%2Fwrappy-1.0.2.tgz"
|
resolved "https://registry.nlark.com/wrappy/download/wrappy-1.0.2.tgz?cache=0&sync_timestamp=1619133505879&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fwrappy%2Fdownload%2Fwrappy-1.0.2.tgz"
|
||||||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
||||||
|
|
||||||
xterm-addon-fit@^0.5.0:
|
xterm-addon-fit@^0.6.0:
|
||||||
version "0.5.0"
|
version "0.6.0"
|
||||||
resolved "https://registry.npmmirror.com/xterm-addon-fit/download/xterm-addon-fit-0.5.0.tgz"
|
resolved "https://registry.npmmirror.com/xterm-addon-fit/-/xterm-addon-fit-0.6.0.tgz#142e1ce181da48763668332593fc440349c88c34"
|
||||||
integrity sha1-LVG5g7eGqX3NbN6AXnAMf5E7xZY=
|
integrity sha512-9/7A+1KEjkFam0yxTaHfuk9LEvvTSBi0PZmEkzJqgafXPEXL9pCMAVV7rB09sX6ATRDXAdBpQhZkhKj7CGvYeg==
|
||||||
|
|
||||||
xterm@^4.19.0:
|
xterm@^5.0.0:
|
||||||
version "4.19.0"
|
version "5.0.0"
|
||||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-4.19.0.tgz"
|
resolved "https://registry.npmmirror.com/xterm/-/xterm-5.0.0.tgz#0af50509b33d0dc62fde7a4ec17750b8e453cc5c"
|
||||||
integrity sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==
|
integrity sha512-tmVsKzZovAYNDIaUinfz+VDclraQpPUnAME+JawosgWRMphInDded/PuY0xmU5dOhyeYZsI0nz5yd8dPYsdLTA==
|
||||||
|
|
||||||
yallist@^4.0.0:
|
yallist@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module mayfly-go
|
module mayfly-go
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.8.1
|
github.com/gin-gonic/gin v1.8.1
|
||||||
@@ -15,7 +15,8 @@ require (
|
|||||||
github.com/sirupsen/logrus v1.9.0
|
github.com/sirupsen/logrus v1.9.0
|
||||||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
|
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
|
||||||
go.mongodb.org/mongo-driver v1.9.1 // mongo
|
go.mongodb.org/mongo-driver v1.9.1 // mongo
|
||||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // ssh
|
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0
|
||||||
|
// ssh
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
// gorm
|
// gorm
|
||||||
gorm.io/driver/mysql v1.3.5
|
gorm.io/driver/mysql v1.3.5
|
||||||
|
|||||||
@@ -4,12 +4,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
common_router "mayfly-go/internal/common/router"
|
common_router "mayfly-go/internal/common/router"
|
||||||
devops_router "mayfly-go/internal/devops/router"
|
db_router "mayfly-go/internal/db/router"
|
||||||
|
machine_router "mayfly-go/internal/machine/router"
|
||||||
|
mongo_router "mayfly-go/internal/mongo/router"
|
||||||
|
project_router "mayfly-go/internal/project/router"
|
||||||
|
redis_router "mayfly-go/internal/redis/router"
|
||||||
sys_router "mayfly-go/internal/sys/router"
|
sys_router "mayfly-go/internal/sys/router"
|
||||||
"mayfly-go/pkg/config"
|
"mayfly-go/pkg/config"
|
||||||
"mayfly-go/pkg/middleware"
|
"mayfly-go/pkg/middleware"
|
||||||
"mayfly-go/static"
|
"mayfly-go/static"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@@ -17,6 +22,7 @@ import (
|
|||||||
func WrapStaticHandler(h http.Handler) gin.HandlerFunc {
|
func WrapStaticHandler(h http.Handler) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
c.Writer.Header().Set("Cache-Control", `public, max-age=31536000`)
|
c.Writer.Header().Set("Cache-Control", `public, max-age=31536000`)
|
||||||
|
c.Request.URL.Path = strings.Split(c.Request.RequestURI, "/mayfly")[1]
|
||||||
h.ServeHTTP(c.Writer, c.Request)
|
h.ServeHTTP(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,22 +74,13 @@ func InitRouter() *gin.Engine {
|
|||||||
common_router.InitIndexRouter(api)
|
common_router.InitIndexRouter(api)
|
||||||
common_router.InitCommonRouter(api)
|
common_router.InitCommonRouter(api)
|
||||||
|
|
||||||
sys_router.InitCaptchaRouter(api)
|
sys_router.Init(api)
|
||||||
sys_router.InitAccountRouter(api) // 注册account路由
|
|
||||||
sys_router.InitResourceRouter(api)
|
|
||||||
sys_router.InitRoleRouter(api)
|
|
||||||
sys_router.InitSystemRouter(api)
|
|
||||||
sys_router.InitSyslogRouter(api)
|
|
||||||
sys_router.InitSysConfigRouter(api)
|
|
||||||
|
|
||||||
devops_router.InitProjectRouter(api)
|
project_router.Init(api)
|
||||||
devops_router.InitDbRouter(api)
|
machine_router.Init(api)
|
||||||
devops_router.InitDbSqlExecRouter(api)
|
db_router.Init(api)
|
||||||
devops_router.InitRedisRouter(api)
|
redis_router.Init(api)
|
||||||
devops_router.InitMachineRouter(api)
|
mongo_router.Init(api)
|
||||||
devops_router.InitMachineScriptRouter(api)
|
|
||||||
devops_router.InitMachineFileRouter(api)
|
|
||||||
devops_router.InitMongoRouter(api)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package initialize
|
package initialize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sys_application "mayfly-go/internal/sys/application"
|
sysapp "mayfly-go/internal/sys/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitSaveLogFunc() ctx.SaveLogFunc {
|
func InitSaveLogFunc() ctx.SaveLogFunc {
|
||||||
return sys_application.SyslogApp.SaveFromReq
|
return sysapp.GetSyslogApp().SaveFromReq
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,30 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/application"
|
dbapp "mayfly-go/internal/db/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
dbentity "mayfly-go/internal/db/domain/entity"
|
||||||
|
machineentity "mayfly-go/internal/machine/domain/entity"
|
||||||
|
projectentity "mayfly-go/internal/project/domain/entity"
|
||||||
|
redisentity "mayfly-go/internal/redis/domain/entity"
|
||||||
|
|
||||||
|
machineapp "mayfly-go/internal/machine/application"
|
||||||
|
projectapp "mayfly-go/internal/project/application"
|
||||||
|
redisapp "mayfly-go/internal/redis/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Index struct {
|
type Index struct {
|
||||||
ProjectApp application.Project
|
ProjectApp projectapp.Project
|
||||||
MachineApp application.Machine
|
MachineApp machineapp.Machine
|
||||||
DbApp application.Db
|
DbApp dbapp.Db
|
||||||
RedisApp application.Redis
|
RedisApp redisapp.Redis
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Index) Count(rc *ctx.ReqCtx) {
|
func (i *Index) Count(rc *ctx.ReqCtx) {
|
||||||
rc.ResData = map[string]interface{}{
|
rc.ResData = map[string]interface{}{
|
||||||
"projectNum": i.ProjectApp.Count(new(entity.Project)),
|
"projectNum": i.ProjectApp.Count(new(projectentity.Project)),
|
||||||
"machineNum": i.MachineApp.Count(new(entity.Machine)),
|
"machineNum": i.MachineApp.Count(new(machineentity.Machine)),
|
||||||
"dbNum": i.DbApp.Count(new(entity.Db)),
|
"dbNum": i.DbApp.Count(new(dbentity.Db)),
|
||||||
"redisNum": i.RedisApp.Count(new(entity.Redis)),
|
"redisNum": i.RedisApp.Count(new(redisentity.Redis)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/common/api"
|
"mayfly-go/internal/common/api"
|
||||||
devops_app "mayfly-go/internal/devops/application"
|
dbapp "mayfly-go/internal/db/application"
|
||||||
|
machineapp "mayfly-go/internal/machine/application"
|
||||||
|
projectapp "mayfly-go/internal/project/application"
|
||||||
|
redisapp "mayfly-go/internal/redis/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -11,10 +14,10 @@ import (
|
|||||||
func InitIndexRouter(router *gin.RouterGroup) {
|
func InitIndexRouter(router *gin.RouterGroup) {
|
||||||
index := router.Group("common/index")
|
index := router.Group("common/index")
|
||||||
i := &api.Index{
|
i := &api.Index{
|
||||||
ProjectApp: devops_app.ProjectApp,
|
ProjectApp: projectapp.GetProjectApp(),
|
||||||
MachineApp: devops_app.MachineApp,
|
MachineApp: machineapp.GetMachineApp(),
|
||||||
DbApp: devops_app.DbApp,
|
DbApp: dbapp.GetDbApp(),
|
||||||
RedisApp: devops_app.RedisApp,
|
RedisApp: redisapp.GetRedisApp(),
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 首页基本信息统计
|
// 首页基本信息统计
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mayfly-go/internal/devops/api/form"
|
"mayfly-go/internal/db/api/form"
|
||||||
"mayfly-go/internal/devops/api/vo"
|
"mayfly-go/internal/db/api/vo"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/db/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
sysApplication "mayfly-go/internal/sys/application"
|
projectapp "mayfly-go/internal/project/application"
|
||||||
|
sysapp "mayfly-go/internal/sys/application"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
@@ -25,8 +26,8 @@ import (
|
|||||||
type Db struct {
|
type Db struct {
|
||||||
DbApp application.Db
|
DbApp application.Db
|
||||||
DbSqlExecApp application.DbSqlExec
|
DbSqlExecApp application.DbSqlExec
|
||||||
MsgApp sysApplication.Msg
|
MsgApp sysapp.Msg
|
||||||
ProjectApp application.Project
|
ProjectApp projectapp.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_COLUMN_SIZE = 500
|
const DEFAULT_COLUMN_SIZE = 500
|
||||||
@@ -129,37 +130,21 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
rc.ReqParam = fmt.Sprintf("db: %d:%s | sql: %s", id, db, sql)
|
rc.ReqParam = fmt.Sprintf("db: %d:%s | sql: %s", id, db, sql)
|
||||||
|
|
||||||
biz.NotEmpty(sql, "sql不能为空")
|
biz.NotEmpty(sql, "sql不能为空")
|
||||||
if strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select") || strings.HasPrefix(sql, "show") || strings.HasPrefix(sql, "explain") {
|
|
||||||
colNames, res, err := dbInstance.SelectData(sql)
|
|
||||||
biz.ErrIsNilAppendErr(err, "查询失败: %s")
|
|
||||||
colAndRes := make(map[string]interface{})
|
|
||||||
colAndRes["colNames"] = colNames
|
|
||||||
colAndRes["res"] = res
|
|
||||||
rc.ResData = colAndRes
|
|
||||||
} else {
|
|
||||||
// 根据执行sql,生成执行记录
|
|
||||||
execRecord := d.DbSqlExecApp.GenExecLog(rc.LoginAccount, id, db, sql, dbInstance)
|
|
||||||
|
|
||||||
rowsAffected, err := dbInstance.Exec(sql)
|
execRes, err := d.DbSqlExecApp.Exec(&application.DbSqlExecReq{
|
||||||
|
DbId: id,
|
||||||
|
Db: db,
|
||||||
|
Sql: sql,
|
||||||
|
Remark: form.Remark,
|
||||||
|
DbInstance: dbInstance,
|
||||||
|
LoginAccount: rc.LoginAccount,
|
||||||
|
})
|
||||||
biz.ErrIsNilAppendErr(err, "执行失败: %s")
|
biz.ErrIsNilAppendErr(err, "执行失败: %s")
|
||||||
res := make([]map[string]string, 0)
|
|
||||||
resData := make(map[string]string)
|
|
||||||
resData["影响条数"] = fmt.Sprintf("%d", rowsAffected)
|
|
||||||
res = append(res, resData)
|
|
||||||
|
|
||||||
colAndRes := make(map[string]interface{})
|
colAndRes := make(map[string]interface{})
|
||||||
colAndRes["colNames"] = []string{"影响条数"}
|
colAndRes["colNames"] = execRes.ColNames
|
||||||
colAndRes["res"] = res
|
colAndRes["res"] = execRes.Res
|
||||||
|
|
||||||
rc.ResData = colAndRes
|
rc.ResData = colAndRes
|
||||||
// 保存sql执行记录
|
|
||||||
if res[0]["影响条数"] > "0" {
|
|
||||||
execRecord.Remark = form.Remark
|
|
||||||
d.DbSqlExecApp.Save(execRecord)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 执行sql文件
|
// 执行sql文件
|
||||||
@@ -255,7 +240,13 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
|||||||
countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
|
countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
|
||||||
_, countRes, _ := dbInstance.SelectData(countSql)
|
_, countRes, _ := dbInstance.SelectData(countSql)
|
||||||
// 查询出所有列信息总数,手动分页获取所有数据
|
// 查询出所有列信息总数,手动分页获取所有数据
|
||||||
maCount := int(countRes[0]["count"].(int64))
|
maCount := 0
|
||||||
|
// 查询出所有列信息总数,手动分页获取所有数据
|
||||||
|
if count64, is64 := countRes[0]["maNum"].(int64); is64 {
|
||||||
|
maCount = int(count64)
|
||||||
|
} else {
|
||||||
|
maCount = countRes[0]["maNum"].(int)
|
||||||
|
}
|
||||||
// 计算需要查询的页数
|
// 计算需要查询的页数
|
||||||
pageNum := maCount / DEFAULT_COLUMN_SIZE
|
pageNum := maCount / DEFAULT_COLUMN_SIZE
|
||||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||||
@@ -264,9 +255,9 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
|||||||
|
|
||||||
var sqlTmp string
|
var sqlTmp string
|
||||||
switch dbInstance.Type {
|
switch dbInstance.Type {
|
||||||
case "mysql":
|
case entity.DbTypeMysql:
|
||||||
sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
|
sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
|
||||||
case "postgres":
|
case entity.DbTypePostgres:
|
||||||
sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
|
sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
|
||||||
}
|
}
|
||||||
for index := 0; index < pageNum; index++ {
|
for index := 0; index < pageNum; index++ {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/db/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
)
|
)
|
||||||
16
server/internal/db/application/application.go
Normal file
16
server/internal/db/application/application.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import "mayfly-go/internal/db/infrastructure/persistence"
|
||||||
|
|
||||||
|
var (
|
||||||
|
dbApp Db = newDbApp(persistence.GetDbRepo(), persistence.GetDbSqlRepo())
|
||||||
|
dbSqlExecApp DbSqlExec = newDbSqlExecApp(persistence.GetDbSqlExecRepo())
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDbApp() Db {
|
||||||
|
return dbApp
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDbSqlExecApp() DbSqlExec {
|
||||||
|
return dbSqlExecApp
|
||||||
|
}
|
||||||
@@ -3,13 +3,12 @@ package application
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/constant"
|
"mayfly-go/internal/constant"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/db/domain/repository"
|
||||||
"mayfly-go/internal/devops/infrastructure/machine"
|
machineapp "mayfly-go/internal/machine/application"
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
"mayfly-go/internal/machine/infrastructure/machine"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/cache"
|
"mayfly-go/pkg/cache"
|
||||||
"mayfly-go/pkg/global"
|
"mayfly-go/pkg/global"
|
||||||
@@ -52,16 +51,18 @@ type Db interface {
|
|||||||
GetDatabases(entity *entity.Db) []string
|
GetDatabases(entity *entity.Db) []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newDbApp(dbRepo repository.Db, dbSqlRepo repository.DbSql) Db {
|
||||||
|
return &dbAppImpl{
|
||||||
|
dbRepo: dbRepo,
|
||||||
|
dbSqlRepo: dbSqlRepo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type dbAppImpl struct {
|
type dbAppImpl struct {
|
||||||
dbRepo repository.Db
|
dbRepo repository.Db
|
||||||
dbSqlRepo repository.DbSql
|
dbSqlRepo repository.DbSql
|
||||||
}
|
}
|
||||||
|
|
||||||
var DbApp Db = &dbAppImpl{
|
|
||||||
dbRepo: persistence.DbDao,
|
|
||||||
dbSqlRepo: persistence.DbSqlDao,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分页获取数据库信息列表
|
// 分页获取数据库信息列表
|
||||||
func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||||
@@ -232,7 +233,7 @@ var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second).
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
machine.AddCheckSshTunnelMachineUseFunc(func(machineId uint64) bool {
|
machine.AddCheckSshTunnelMachineUseFunc(func(machineId uint64) bool {
|
||||||
// 遍历所有db连接实例,若存在redis实例使用该ssh隧道机器,则返回true,表示还在使用中...
|
// 遍历所有db连接实例,若存在db实例使用该ssh隧道机器,则返回true,表示还在使用中...
|
||||||
items := dbCache.Items()
|
items := dbCache.Items()
|
||||||
for _, v := range items {
|
for _, v := range items {
|
||||||
if v.Value.(*DbInstance).sshTunnelMachineId == machineId {
|
if v.Value.(*DbInstance).sshTunnelMachineId == machineId {
|
||||||
@@ -265,7 +266,7 @@ func TestConnection(d *entity.Db) {
|
|||||||
func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
|
func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
|
||||||
// SSH Conect
|
// SSH Conect
|
||||||
if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
|
if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
|
||||||
sshTunnelMachine := MachineApp.GetSshTunnelMachine(d.SshTunnelMachineId)
|
sshTunnelMachine := machineapp.GetMachineApp().GetSshTunnelMachine(d.SshTunnelMachineId)
|
||||||
if d.Type == entity.DbTypeMysql {
|
if d.Type == entity.DbTypeMysql {
|
||||||
mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
|
mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
return sshTunnelMachine.GetDialConn("tcp", addr)
|
return sshTunnelMachine.GetDialConn("tcp", addr)
|
||||||
@@ -410,14 +411,6 @@ type DbInstance struct {
|
|||||||
// 执行查询语句
|
// 执行查询语句
|
||||||
// 依次返回 列名数组,结果map,错误
|
// 依次返回 列名数组,结果map,错误
|
||||||
func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
|
func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
|
||||||
execSql = strings.Trim(execSql, " ")
|
|
||||||
isSelect := strings.HasPrefix(execSql, "SELECT") || strings.HasPrefix(execSql, "select")
|
|
||||||
isShow := strings.HasPrefix(execSql, "show")
|
|
||||||
isExplain := strings.HasPrefix(execSql, "explain")
|
|
||||||
|
|
||||||
if !isSelect && !isShow && !isExplain {
|
|
||||||
return nil, nil, errors.New("该sql非查询语句")
|
|
||||||
}
|
|
||||||
return SelectDataByDb(d.db, execSql)
|
return SelectDataByDb(d.db, execSql)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,8 +551,14 @@ func (mm *MysqlMetadata) GetColumns(tableNames ...string) []map[string]interface
|
|||||||
if len(tableNames) > 1 {
|
if len(tableNames) > 1 {
|
||||||
countSql := fmt.Sprintf(MYSQL_COLOUMN_MA_COUNT, tableName)
|
countSql := fmt.Sprintf(MYSQL_COLOUMN_MA_COUNT, tableName)
|
||||||
_, countRes, _ := mm.di.SelectData(countSql)
|
_, countRes, _ := mm.di.SelectData(countSql)
|
||||||
|
maCount := 0
|
||||||
// 查询出所有列信息总数,手动分页获取所有数据
|
// 查询出所有列信息总数,手动分页获取所有数据
|
||||||
maCount := int(countRes[0]["maNum"].(int64))
|
if count64, is64 := countRes[0]["maNum"].(int64); is64 {
|
||||||
|
maCount = int(count64)
|
||||||
|
} else {
|
||||||
|
maCount = countRes[0]["maNum"].(int)
|
||||||
|
}
|
||||||
|
|
||||||
// 计算需要查询的页数
|
// 计算需要查询的页数
|
||||||
pageNum = maCount / DEFAULT_COLUMN_SIZE
|
pageNum = maCount / DEFAULT_COLUMN_SIZE
|
||||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||||
@@ -672,8 +671,13 @@ func (pm *PgsqlMetadata) GetColumns(tableNames ...string) []map[string]interface
|
|||||||
if len(tableNames) > 1 {
|
if len(tableNames) > 1 {
|
||||||
countSql := fmt.Sprintf(PGSQL_COLUMN_MA_COUNT, tableName)
|
countSql := fmt.Sprintf(PGSQL_COLUMN_MA_COUNT, tableName)
|
||||||
_, countRes, _ := pm.di.SelectData(countSql)
|
_, countRes, _ := pm.di.SelectData(countSql)
|
||||||
|
maCount := 0
|
||||||
// 查询出所有列信息总数,手动分页获取所有数据
|
// 查询出所有列信息总数,手动分页获取所有数据
|
||||||
maCount := int(countRes[0]["maNum"].(int64))
|
if count64, is64 := countRes[0]["maNum"].(int64); is64 {
|
||||||
|
maCount = int(count64)
|
||||||
|
} else {
|
||||||
|
maCount = countRes[0]["maNum"].(int)
|
||||||
|
}
|
||||||
// 计算需要查询的页数
|
// 计算需要查询的页数
|
||||||
pageNum = maCount / DEFAULT_COLUMN_SIZE
|
pageNum = maCount / DEFAULT_COLUMN_SIZE
|
||||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||||
200
server/internal/db/application/db_sql_exec.go
Normal file
200
server/internal/db/application/db_sql_exec.go
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"mayfly-go/internal/db/domain/entity"
|
||||||
|
"mayfly-go/internal/db/domain/repository"
|
||||||
|
"mayfly-go/pkg/global"
|
||||||
|
"mayfly-go/pkg/model"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/xwb1989/sqlparser"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbSqlExecReq struct {
|
||||||
|
DbId uint64
|
||||||
|
Db string
|
||||||
|
Sql string
|
||||||
|
Remark string
|
||||||
|
LoginAccount *model.LoginAccount
|
||||||
|
DbInstance *DbInstance
|
||||||
|
}
|
||||||
|
|
||||||
|
type DbSqlExecRes struct {
|
||||||
|
ColNames []string
|
||||||
|
Res []map[string]interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DbSqlExec interface {
|
||||||
|
// 执行sql
|
||||||
|
Exec(execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error)
|
||||||
|
|
||||||
|
// 根据条件删除sql执行记录
|
||||||
|
DeleteBy(condition *entity.DbSqlExec)
|
||||||
|
|
||||||
|
// 分页获取
|
||||||
|
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
||||||
|
return &dbSqlExecAppImpl{
|
||||||
|
dbSqlExecRepo: dbExecSqlRepo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type dbSqlExecAppImpl struct {
|
||||||
|
dbSqlExecRepo repository.DbSqlExec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbSqlExecAppImpl) Exec(execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error) {
|
||||||
|
sql := execSqlReq.Sql
|
||||||
|
loginAccount := execSqlReq.LoginAccount
|
||||||
|
|
||||||
|
// 如果是pgsql并且为查询语句,则直接返回,sqlparser不支持解析pgsql select语句
|
||||||
|
if execSqlReq.DbInstance.Type == entity.DbTypePostgres && (strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select")) {
|
||||||
|
return doSelect(nil, execSqlReq, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt, err := sqlparser.Parse(sql)
|
||||||
|
if err != nil {
|
||||||
|
global.Log.Error("sql解析失败: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dbSqlExecRecord := new(entity.DbSqlExec)
|
||||||
|
dbSqlExecRecord.DbId = execSqlReq.DbId
|
||||||
|
dbSqlExecRecord.Db = execSqlReq.Db
|
||||||
|
dbSqlExecRecord.Sql = sql
|
||||||
|
dbSqlExecRecord.Remark = execSqlReq.Remark
|
||||||
|
dbSqlExecRecord.SetBaseInfo(loginAccount)
|
||||||
|
|
||||||
|
var execRes *DbSqlExecRes
|
||||||
|
isSelect := false
|
||||||
|
switch stmt := stmt.(type) {
|
||||||
|
case *sqlparser.Select:
|
||||||
|
isSelect = true
|
||||||
|
execRes, err = doSelect(stmt, execSqlReq, dbSqlExecRecord)
|
||||||
|
case *sqlparser.Show:
|
||||||
|
isSelect = true
|
||||||
|
execRes, err = doSelect(nil, execSqlReq, dbSqlExecRecord)
|
||||||
|
case *sqlparser.OtherRead:
|
||||||
|
isSelect = true
|
||||||
|
execRes, err = doSelect(nil, execSqlReq, dbSqlExecRecord)
|
||||||
|
case *sqlparser.Update:
|
||||||
|
execRes, err = doUpdate(stmt, execSqlReq, dbSqlExecRecord)
|
||||||
|
case *sqlparser.Delete:
|
||||||
|
execRes, err = doDelete(stmt, execSqlReq, dbSqlExecRecord)
|
||||||
|
case *sqlparser.Insert:
|
||||||
|
execRes, err = doInsert(stmt, execSqlReq, dbSqlExecRecord)
|
||||||
|
default:
|
||||||
|
execRes, err = doExec(execSqlReq.Sql, execSqlReq.DbInstance)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isSelect {
|
||||||
|
// 保存执行记录
|
||||||
|
d.dbSqlExecRepo.Insert(dbSqlExecRecord)
|
||||||
|
}
|
||||||
|
return execRes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||||
|
d.dbSqlExecRepo.DeleteBy(condition)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
|
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func doSelect(selectStmt *sqlparser.Select, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||||
|
dbInstance := execSqlReq.DbInstance
|
||||||
|
sql := execSqlReq.Sql
|
||||||
|
colNames, res, err := dbInstance.SelectData(sql)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &DbSqlExecRes{
|
||||||
|
ColNames: colNames,
|
||||||
|
Res: res,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doUpdate(update *sqlparser.Update, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||||
|
dbInstance := execSqlReq.DbInstance
|
||||||
|
|
||||||
|
tableStr := sqlparser.String(update.TableExprs)
|
||||||
|
// 可能使用别名,故空格切割
|
||||||
|
tableName := strings.Split(tableStr, " ")[0]
|
||||||
|
where := sqlparser.String(update.Where)
|
||||||
|
|
||||||
|
updateExprs := update.Exprs
|
||||||
|
updateColumns := make([]string, 0)
|
||||||
|
for _, v := range updateExprs {
|
||||||
|
updateColumns = append(updateColumns, v.Name.Name.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取表主键列名,排除使用别名
|
||||||
|
primaryKey := dbInstance.GetMeta().GetPrimaryKey(tableName)
|
||||||
|
|
||||||
|
updateColumnsAndPrimaryKey := strings.Join(updateColumns, ",") + "," + primaryKey
|
||||||
|
// 查询要更新字段数据的旧值,以及主键值
|
||||||
|
selectSql := fmt.Sprintf("SELECT %s FROM %s %s LIMIT 200", updateColumnsAndPrimaryKey, tableStr, where)
|
||||||
|
_, res, _ := dbInstance.SelectData(selectSql)
|
||||||
|
|
||||||
|
bytes, _ := json.Marshal(res)
|
||||||
|
dbSqlExec.OldValue = string(bytes)
|
||||||
|
dbSqlExec.Table = tableName
|
||||||
|
dbSqlExec.Type = entity.DbSqlExecTypeUpdate
|
||||||
|
|
||||||
|
return doExec(execSqlReq.Sql, dbInstance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func doDelete(delete *sqlparser.Delete, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||||
|
dbInstance := execSqlReq.DbInstance
|
||||||
|
|
||||||
|
tableStr := sqlparser.String(delete.TableExprs)
|
||||||
|
// 可能使用别名,故空格切割
|
||||||
|
table := strings.Split(tableStr, " ")[0]
|
||||||
|
where := sqlparser.String(delete.Where)
|
||||||
|
|
||||||
|
// 查询删除数据
|
||||||
|
selectSql := fmt.Sprintf("SELECT * FROM %s %s LIMIT 200", tableStr, where)
|
||||||
|
_, res, _ := dbInstance.SelectData(selectSql)
|
||||||
|
|
||||||
|
bytes, _ := json.Marshal(res)
|
||||||
|
dbSqlExec.OldValue = string(bytes)
|
||||||
|
dbSqlExec.Table = table
|
||||||
|
dbSqlExec.Type = entity.DbSqlExecTypeDelete
|
||||||
|
|
||||||
|
return doExec(execSqlReq.Sql, dbInstance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func doInsert(insert *sqlparser.Insert, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||||
|
tableStr := sqlparser.String(insert.Table)
|
||||||
|
// 可能使用别名,故空格切割
|
||||||
|
table := strings.Split(tableStr, " ")[0]
|
||||||
|
dbSqlExec.Table = table
|
||||||
|
dbSqlExec.Type = entity.DbSqlExecTypeInsert
|
||||||
|
|
||||||
|
return doExec(execSqlReq.Sql, execSqlReq.DbInstance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func doExec(sql string, dbInstance *DbInstance) (*DbSqlExecRes, error) {
|
||||||
|
rowsAffected, err := dbInstance.Exec(sql)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res := make([]map[string]interface{}, 0)
|
||||||
|
resData := make(map[string]interface{})
|
||||||
|
resData["影响条数"] = rowsAffected
|
||||||
|
res = append(res, resData)
|
||||||
|
|
||||||
|
return &DbSqlExecRes{
|
||||||
|
ColNames: []string{"影响条数"},
|
||||||
|
Res: res,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import "mayfly-go/internal/devops/domain/entity"
|
import "mayfly-go/internal/db/domain/entity"
|
||||||
|
|
||||||
type DbSql interface {
|
type DbSql interface {
|
||||||
DeleteBy(condition *entity.DbSql)
|
DeleteBy(condition *entity.DbSql)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2,18 +2,20 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/db/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dbRepo struct{}
|
type dbRepoImpl struct{}
|
||||||
|
|
||||||
var DbDao repository.Db = &dbRepo{}
|
func newDbRepo() repository.Db {
|
||||||
|
return new(dbRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
// 分页获取数据库信息列表
|
// 分页获取数据库信息列表
|
||||||
func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (d *dbRepoImpl) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
||||||
if condition.CreatorId != 0 {
|
if condition.CreatorId != 0 {
|
||||||
// 使用创建者id模拟项目成员id
|
// 使用创建者id模拟项目成员id
|
||||||
@@ -35,17 +37,17 @@ func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toE
|
|||||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbRepo) Count(condition *entity.Db) int64 {
|
func (d *dbRepoImpl) Count(condition *entity.Db) int64 {
|
||||||
return model.CountBy(condition)
|
return model.CountBy(condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据条件获取账号信息
|
// 根据条件获取账号信息
|
||||||
func (d *dbRepo) GetDb(condition *entity.Db, cols ...string) error {
|
func (d *dbRepoImpl) GetDb(condition *entity.Db, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return model.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
|
func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
||||||
db := new(entity.Db)
|
db := new(entity.Db)
|
||||||
if err := model.GetById(db, id, cols...); err != nil {
|
if err := model.GetById(db, id, cols...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -54,14 +56,14 @@ func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
|
|||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbRepo) Insert(db *entity.Db) {
|
func (d *dbRepoImpl) Insert(db *entity.Db) {
|
||||||
biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
|
biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbRepo) Update(db *entity.Db) {
|
func (d *dbRepoImpl) Update(db *entity.Db) {
|
||||||
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
|
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbRepo) Delete(id uint64) {
|
func (d *dbRepoImpl) Delete(id uint64) {
|
||||||
model.DeleteById(new(entity.Db), id)
|
model.DeleteById(new(entity.Db), id)
|
||||||
}
|
}
|
||||||
19
server/internal/db/infrastructure/persistence/db_sql.go
Normal file
19
server/internal/db/infrastructure/persistence/db_sql.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mayfly-go/internal/db/domain/entity"
|
||||||
|
"mayfly-go/internal/db/domain/repository"
|
||||||
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type dbSqlRepoImpl struct{}
|
||||||
|
|
||||||
|
func newDbSqlRepo() repository.DbSql {
|
||||||
|
return new(dbSqlRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页获取数据库信息列表
|
||||||
|
func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
|
||||||
|
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
|
||||||
|
}
|
||||||
27
server/internal/db/infrastructure/persistence/db_sql_exec.go
Normal file
27
server/internal/db/infrastructure/persistence/db_sql_exec.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mayfly-go/internal/db/domain/entity"
|
||||||
|
"mayfly-go/internal/db/domain/repository"
|
||||||
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type dbSqlExecRepoImpl struct{}
|
||||||
|
|
||||||
|
func newDbSqlExecRepo() repository.DbSqlExec {
|
||||||
|
return new(dbSqlExecRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
|
||||||
|
model.Insert(dse)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||||
|
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页获取
|
||||||
|
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
|
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||||
|
}
|
||||||
21
server/internal/db/infrastructure/persistence/persistence.go
Normal file
21
server/internal/db/infrastructure/persistence/persistence.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import "mayfly-go/internal/db/domain/repository"
|
||||||
|
|
||||||
|
var (
|
||||||
|
dbRepo repository.Db = newDbRepo()
|
||||||
|
dbSqlRepo repository.DbSql = newDbSqlRepo()
|
||||||
|
dbSqlExecRepo repository.DbSqlExec = newDbSqlExecRepo()
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDbRepo() repository.Db {
|
||||||
|
return dbRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDbSqlRepo() repository.DbSql {
|
||||||
|
return dbSqlRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDbSqlExecRepo() repository.DbSqlExec {
|
||||||
|
return dbSqlExecRepo
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/api"
|
"mayfly-go/internal/db/api"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/db/application"
|
||||||
sysApplication "mayfly-go/internal/sys/application"
|
projectapp "mayfly-go/internal/project/application"
|
||||||
|
sysapp "mayfly-go/internal/sys/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -13,10 +14,10 @@ func InitDbRouter(router *gin.RouterGroup) {
|
|||||||
db := router.Group("dbs")
|
db := router.Group("dbs")
|
||||||
{
|
{
|
||||||
d := &api.Db{
|
d := &api.Db{
|
||||||
DbApp: application.DbApp,
|
DbApp: application.GetDbApp(),
|
||||||
DbSqlExecApp: application.DbSqlExecApp,
|
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||||
MsgApp: sysApplication.MsgApp,
|
MsgApp: sysapp.GetMsgApp(),
|
||||||
ProjectApp: application.ProjectApp,
|
ProjectApp: projectapp.GetProjectApp(),
|
||||||
}
|
}
|
||||||
// 获取所有数据库列表
|
// 获取所有数据库列表
|
||||||
db.GET("", func(c *gin.Context) {
|
db.GET("", func(c *gin.Context) {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/api"
|
"mayfly-go/internal/db/api"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/db/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -12,7 +12,7 @@ func InitDbSqlExecRouter(router *gin.RouterGroup) {
|
|||||||
db := router.Group("/dbs/:dbId/sql-execs")
|
db := router.Group("/dbs/:dbId/sql-execs")
|
||||||
{
|
{
|
||||||
d := &api.DbSqlExec{
|
d := &api.DbSqlExec{
|
||||||
DbSqlExecApp: application.DbSqlExecApp,
|
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||||
}
|
}
|
||||||
// 获取所有数据库sql执行记录列表
|
// 获取所有数据库sql执行记录列表
|
||||||
db.GET("", func(c *gin.Context) {
|
db.GET("", func(c *gin.Context) {
|
||||||
8
server/internal/db/router/router.go
Normal file
8
server/internal/db/router/router.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func Init(router *gin.RouterGroup) {
|
||||||
|
InitDbRouter(router)
|
||||||
|
InitDbSqlExecRouter(router)
|
||||||
|
}
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
package application
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
|
||||||
"mayfly-go/pkg/global"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/xwb1989/sqlparser"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DbSqlExec interface {
|
|
||||||
// 生成sql执行记录
|
|
||||||
GenExecLog(loginAccount *model.LoginAccount, dbId uint64, db string, sql string, dbInstance *DbInstance) *entity.DbSqlExec
|
|
||||||
|
|
||||||
// 保存sql执行记录
|
|
||||||
Save(*entity.DbSqlExec)
|
|
||||||
|
|
||||||
// 根据条件删除sql执行记录
|
|
||||||
DeleteBy(condition *entity.DbSqlExec)
|
|
||||||
|
|
||||||
// 分页获取
|
|
||||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
|
||||||
}
|
|
||||||
|
|
||||||
type dbSqlExecAppImpl struct {
|
|
||||||
dbSqlExecRepo repository.DbSqlExec
|
|
||||||
}
|
|
||||||
|
|
||||||
var DbSqlExecApp DbSqlExec = &dbSqlExecAppImpl{
|
|
||||||
dbSqlExecRepo: persistence.DbSqlExecDao,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dbSqlExecAppImpl) GenExecLog(loginAccount *model.LoginAccount, dbId uint64, db string, sql string, dbInstance *DbInstance) *entity.DbSqlExec {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
global.Log.Error("生成sql执行记录失败", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
stmt, err := sqlparser.Parse(sql)
|
|
||||||
if err != nil {
|
|
||||||
global.Log.Error("记录数据库sql执行记录失败", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dbSqlExecRecord := new(entity.DbSqlExec)
|
|
||||||
dbSqlExecRecord.DbId = dbId
|
|
||||||
dbSqlExecRecord.Db = db
|
|
||||||
dbSqlExecRecord.Sql = sql
|
|
||||||
dbSqlExecRecord.SetBaseInfo(loginAccount)
|
|
||||||
|
|
||||||
switch stmt := stmt.(type) {
|
|
||||||
case *sqlparser.Update:
|
|
||||||
doUpdate(stmt, dbInstance, dbSqlExecRecord)
|
|
||||||
case *sqlparser.Delete:
|
|
||||||
doDelete(stmt, dbInstance, dbSqlExecRecord)
|
|
||||||
case *sqlparser.Insert:
|
|
||||||
doInsert(stmt, dbSqlExecRecord)
|
|
||||||
}
|
|
||||||
|
|
||||||
return dbSqlExecRecord
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dbSqlExecAppImpl) Save(dse *entity.DbSqlExec) {
|
|
||||||
d.dbSqlExecRepo.Insert(dse)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
|
||||||
d.dbSqlExecRepo.DeleteBy(condition)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
||||||
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func doUpdate(update *sqlparser.Update, dbInstance *DbInstance, dbSqlExec *entity.DbSqlExec) {
|
|
||||||
tableStr := sqlparser.String(update.TableExprs)
|
|
||||||
// 可能使用别名,故空格切割
|
|
||||||
tableName := strings.Split(tableStr, " ")[0]
|
|
||||||
where := sqlparser.String(update.Where)
|
|
||||||
|
|
||||||
updateExprs := update.Exprs
|
|
||||||
updateColumns := make([]string, 0)
|
|
||||||
for _, v := range updateExprs {
|
|
||||||
updateColumns = append(updateColumns, v.Name.Name.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取表主键列名,排除使用别名
|
|
||||||
primaryKey := dbInstance.GetMeta().GetPrimaryKey(tableName)
|
|
||||||
|
|
||||||
updateColumnsAndPrimaryKey := strings.Join(updateColumns, ",") + "," + primaryKey
|
|
||||||
// 查询要更新字段数据的旧值,以及主键值
|
|
||||||
selectSql := fmt.Sprintf("SELECT %s FROM %s %s LIMIT 200", updateColumnsAndPrimaryKey, tableStr, where)
|
|
||||||
_, res, _ := dbInstance.SelectData(selectSql)
|
|
||||||
|
|
||||||
bytes, _ := json.Marshal(res)
|
|
||||||
dbSqlExec.OldValue = string(bytes)
|
|
||||||
dbSqlExec.Table = tableName
|
|
||||||
dbSqlExec.Type = entity.DbSqlExecTypeUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
func doDelete(delete *sqlparser.Delete, dbInstance *DbInstance, dbSqlExec *entity.DbSqlExec) {
|
|
||||||
tableStr := sqlparser.String(delete.TableExprs)
|
|
||||||
// 可能使用别名,故空格切割
|
|
||||||
table := strings.Split(tableStr, " ")[0]
|
|
||||||
where := sqlparser.String(delete.Where)
|
|
||||||
|
|
||||||
// 查询删除数据
|
|
||||||
selectSql := fmt.Sprintf("SELECT * FROM %s %s LIMIT 200", tableStr, where)
|
|
||||||
_, res, _ := dbInstance.SelectData(selectSql)
|
|
||||||
|
|
||||||
bytes, _ := json.Marshal(res)
|
|
||||||
dbSqlExec.OldValue = string(bytes)
|
|
||||||
dbSqlExec.Table = table
|
|
||||||
dbSqlExec.Type = entity.DbSqlExecTypeDelete
|
|
||||||
}
|
|
||||||
|
|
||||||
func doInsert(insert *sqlparser.Insert, dbSqlExec *entity.DbSqlExec) {
|
|
||||||
tableStr := sqlparser.String(insert.Table)
|
|
||||||
// 可能使用别名,故空格切割
|
|
||||||
table := strings.Split(tableStr, " ")[0]
|
|
||||||
dbSqlExec.Table = table
|
|
||||||
dbSqlExec.Type = entity.DbSqlExecTypeInsert
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type dbSqlExecRepo struct{}
|
|
||||||
|
|
||||||
var DbSqlExecDao repository.DbSqlExec = &dbSqlExecRepo{}
|
|
||||||
|
|
||||||
func (d *dbSqlExecRepo) Insert(dse *entity.DbSqlExec) {
|
|
||||||
model.Insert(dse)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dbSqlExecRepo) DeleteBy(condition *entity.DbSqlExec) {
|
|
||||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分页获取
|
|
||||||
func (d *dbSqlExecRepo) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
||||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type dbSqlRepo struct{}
|
|
||||||
|
|
||||||
var DbSqlDao repository.DbSql = &dbSqlRepo{}
|
|
||||||
|
|
||||||
// 分页获取数据库信息列表
|
|
||||||
func (d *dbSqlRepo) DeleteBy(condition *entity.DbSql) {
|
|
||||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type machineFileRepo struct{}
|
|
||||||
|
|
||||||
var MachineFileDao repository.MachineFile = &machineFileRepo{}
|
|
||||||
|
|
||||||
// 分页获取机器文件信息列表
|
|
||||||
func (m *machineFileRepo) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
||||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据条件获取账号信息
|
|
||||||
func (m *machineFileRepo) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
|
||||||
return model.GetBy(condition, cols...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据id获取
|
|
||||||
func (m *machineFileRepo) GetById(id uint64, cols ...string) *entity.MachineFile {
|
|
||||||
ms := new(entity.MachineFile)
|
|
||||||
if err := model.GetById(ms, id, cols...); err != nil {
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据id获取
|
|
||||||
func (m *machineFileRepo) Delete(id uint64) {
|
|
||||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineFile), id), "删除失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *machineFileRepo) Create(entity *entity.MachineFile) {
|
|
||||||
model.Insert(entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *machineFileRepo) UpdateById(entity *entity.MachineFile) {
|
|
||||||
model.UpdateById(entity)
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type machineScriptRepo struct{}
|
|
||||||
|
|
||||||
var MachineScriptDao repository.MachineScript = &machineScriptRepo{}
|
|
||||||
|
|
||||||
// 分页获取机器信息列表
|
|
||||||
func (m *machineScriptRepo) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
||||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据条件获取账号信息
|
|
||||||
func (m *machineScriptRepo) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
|
||||||
return model.GetBy(condition, cols...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据id获取
|
|
||||||
func (m *machineScriptRepo) GetById(id uint64, cols ...string) *entity.MachineScript {
|
|
||||||
ms := new(entity.MachineScript)
|
|
||||||
if err := model.GetById(ms, id, cols...); err != nil {
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据id获取
|
|
||||||
func (m *machineScriptRepo) Delete(id uint64) {
|
|
||||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineScript), id), "删除失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *machineScriptRepo) Create(entity *entity.MachineScript) {
|
|
||||||
model.Insert(entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *machineScriptRepo) UpdateById(entity *entity.MachineScript) {
|
|
||||||
model.UpdateById(entity)
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type projectEnvRepo struct{}
|
|
||||||
|
|
||||||
var ProjectEnvRepo repository.ProjectEnv = &projectEnvRepo{}
|
|
||||||
|
|
||||||
func (p *projectEnvRepo) ListEnv(condition *entity.ProjectEnv, toEntity interface{}, orderBy ...string) {
|
|
||||||
model.ListByOrder(condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectEnvRepo) Save(entity *entity.ProjectEnv) {
|
|
||||||
biz.ErrIsNilAppendErr(model.Insert(entity), "保存环境失败:%s")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectEnvRepo) DeleteEnvs(projectId uint64) {
|
|
||||||
model.DeleteByCondition(&entity.ProjectEnv{ProjectId: projectId})
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type projectMemeberRepo struct{}
|
|
||||||
|
|
||||||
var ProjectMemberRepo repository.ProjectMemeber = &projectMemeberRepo{}
|
|
||||||
|
|
||||||
func (p *projectMemeberRepo) ListMemeber(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string) {
|
|
||||||
model.ListByOrder(condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectMemeberRepo) Save(pm *entity.ProjectMember) {
|
|
||||||
biz.ErrIsNilAppendErr(model.Insert(pm), "保存项目成员失败:%s")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectMemeberRepo) GetPageList(condition *entity.ProjectMember, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
||||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectMemeberRepo) DeleteByPidMid(projectId, accountId uint64) {
|
|
||||||
model.DeleteByCondition(&entity.ProjectMember{ProjectId: projectId, AccountId: accountId})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectMemeberRepo) DeleteMems(projectId uint64) {
|
|
||||||
model.DeleteByCondition(&entity.ProjectMember{ProjectId: projectId})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectMemeberRepo) IsExist(projectId, accountId uint64) bool {
|
|
||||||
return model.CountBy(&entity.ProjectMember{ProjectId: projectId, AccountId: accountId}) > 0
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package persistence
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type projectRepo struct{}
|
|
||||||
|
|
||||||
var ProjectRepo repository.Project = &projectRepo{}
|
|
||||||
|
|
||||||
func (p *projectRepo) GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
||||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectRepo) Count(condition *entity.Project) int64 {
|
|
||||||
return model.CountBy(condition)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectRepo) GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string) {
|
|
||||||
model.GetByIdIn(new(entity.Project), toEntity, ids, orderBy...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectRepo) Save(project *entity.Project) {
|
|
||||||
biz.ErrIsNil(model.Insert(project), "保存项目失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectRepo) Update(project *entity.Project) {
|
|
||||||
biz.ErrIsNil(model.UpdateById(project), "更新项目信息")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectRepo) Delete(id uint64) {
|
|
||||||
model.DeleteById(new(entity.Project), id)
|
|
||||||
}
|
|
||||||
@@ -3,11 +3,12 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/devops/api/form"
|
"mayfly-go/internal/machine/api/form"
|
||||||
"mayfly-go/internal/devops/api/vo"
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/machine/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/devops/infrastructure/machine"
|
"mayfly-go/internal/machine/infrastructure/machine"
|
||||||
|
projectapp "mayfly-go/internal/project/application"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/config"
|
"mayfly-go/pkg/config"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
@@ -18,7 +19,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
type Machine struct {
|
type Machine struct {
|
||||||
MachineApp application.Machine
|
MachineApp application.Machine
|
||||||
ProjectApp application.Project
|
ProjectApp projectapp.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) Machines(rc *ctx.ReqCtx) {
|
func (m *Machine) Machines(rc *ctx.ReqCtx) {
|
||||||
@@ -175,8 +175,6 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
|||||||
|
|
||||||
var recorder *machine.Recorder
|
var recorder *machine.Recorder
|
||||||
if cli.GetMachine().EnableRecorder == 1 {
|
if cli.GetMachine().EnableRecorder == 1 {
|
||||||
mask := syscall.Umask(0)
|
|
||||||
defer syscall.Umask(mask)
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
// 回放文件路径为: 基础配置路径/机器id/操作日期/操作者账号/操作时间.cast
|
// 回放文件路径为: 基础配置路径/机器id/操作日期/操作者账号/操作时间.cast
|
||||||
recPath := fmt.Sprintf("%s/%d/%s/%s", config.Conf.Server.GetMachineRecPath(), cli.GetMachine().Id, now.Format("20060102"), rc.LoginAccount.Username)
|
recPath := fmt.Sprintf("%s/%d/%s/%s", config.Conf.Server.GetMachineRecPath(), cli.GetMachine().Id, now.Format("20060102"), rc.LoginAccount.Username)
|
||||||
@@ -4,10 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"mayfly-go/internal/devops/api/form"
|
"mayfly-go/internal/machine/api/form"
|
||||||
"mayfly-go/internal/devops/api/vo"
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/machine/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
sysApplication "mayfly-go/internal/sys/application"
|
sysApplication "mayfly-go/internal/sys/application"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
@@ -121,6 +121,7 @@ func (m *MachineFile) GetDirEntry(rc *ctx.ReqCtx) {
|
|||||||
Path: readPath + fi.Name(),
|
Path: readPath + fi.Name(),
|
||||||
Type: getFileType(fi.Mode()),
|
Type: getFileType(fi.Mode()),
|
||||||
Mode: fi.Mode().String(),
|
Mode: fi.Mode().String(),
|
||||||
|
ModTime: fi.ModTime().Format("2006-01-02 15:04:05"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
rc.ResData = fisVO
|
rc.ResData = fisVO
|
||||||
@@ -2,10 +2,11 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/devops/api/form"
|
"mayfly-go/internal/machine/api/form"
|
||||||
"mayfly-go/internal/devops/api/vo"
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/machine/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
|
projectapp "mayfly-go/internal/project/application"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
@@ -18,7 +19,7 @@ import (
|
|||||||
type MachineScript struct {
|
type MachineScript struct {
|
||||||
MachineScriptApp application.MachineScript
|
MachineScriptApp application.MachineScript
|
||||||
MachineApp application.Machine
|
MachineApp application.Machine
|
||||||
ProjectApp application.Project
|
ProjectApp projectapp.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) {
|
func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) {
|
||||||
@@ -61,6 +61,7 @@ type MachineFileInfo struct {
|
|||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
|
ModTime string `json:"modTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoleVO struct {
|
type RoleVO struct {
|
||||||
21
server/internal/machine/application/application.go
Normal file
21
server/internal/machine/application/application.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import "mayfly-go/internal/machine/infrastructure/persistence"
|
||||||
|
|
||||||
|
var (
|
||||||
|
machineApp Machine = newMachineApp(persistence.GetMachineRepo())
|
||||||
|
machineFileApp MachineFile = newMachineFileApp(persistence.GetMachineFileRepo(), persistence.GetMachineRepo())
|
||||||
|
machineScriptApp MachineScript = newMachineScriptApp(persistence.GetMachineScriptRepo(), persistence.GetMachineRepo())
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMachineApp() Machine {
|
||||||
|
return machineApp
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMachineFileApp() MachineFile {
|
||||||
|
return machineFileApp
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMachineScriptApp() MachineScript {
|
||||||
|
return machineScriptApp
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/internal/devops/infrastructure/machine"
|
"mayfly-go/internal/machine/infrastructure/machine"
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
|
|
||||||
@@ -37,12 +36,15 @@ type Machine interface {
|
|||||||
GetSshTunnelMachine(id uint64) *machine.SshTunnelMachine
|
GetSshTunnelMachine(id uint64) *machine.SshTunnelMachine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newMachineApp(machineRepo repository.Machine) Machine {
|
||||||
|
return &machineAppImpl{machineRepo: machineRepo}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type machineAppImpl struct {
|
type machineAppImpl struct {
|
||||||
machineRepo repository.Machine
|
machineRepo repository.Machine
|
||||||
}
|
}
|
||||||
|
|
||||||
var MachineApp Machine = &machineAppImpl{machineRepo: persistence.MachineDao}
|
|
||||||
|
|
||||||
// 分页获取机器信息列表
|
// 分页获取机器信息列表
|
||||||
func (m *machineAppImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (m *machineAppImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||||
@@ -56,7 +58,11 @@ func (m *machineAppImpl) Count(condition *entity.Machine) int64 {
|
|||||||
func (m *machineAppImpl) Save(me *entity.Machine) {
|
func (m *machineAppImpl) Save(me *entity.Machine) {
|
||||||
// ’修改机器信息且密码不为空‘ or ‘新增’需要测试是否可连接
|
// ’修改机器信息且密码不为空‘ or ‘新增’需要测试是否可连接
|
||||||
if (me.Id != 0 && me.Password != "") || me.Id == 0 {
|
if (me.Id != 0 && me.Password != "") || me.Id == 0 {
|
||||||
biz.ErrIsNilAppendErr(machine.TestConn(*me, func(u uint64) *entity.Machine { return m.GetById(u) }), "该机器无法连接: %s")
|
biz.ErrIsNilAppendErr(machine.TestConn(*me, func(u uint64) *entity.Machine {
|
||||||
|
me := m.GetById(u)
|
||||||
|
me.PwdDecrypt()
|
||||||
|
return me
|
||||||
|
}), "该机器无法连接: %s")
|
||||||
}
|
}
|
||||||
|
|
||||||
oldMachine := &entity.Machine{Ip: me.Ip, Port: me.Port, Username: me.Username}
|
oldMachine := &entity.Machine{Ip: me.Ip, Port: me.Port, Username: me.Username}
|
||||||
@@ -4,9 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"os"
|
"os"
|
||||||
@@ -53,17 +52,16 @@ type MachineFile interface {
|
|||||||
RemoveFile(fileId uint64, path string)
|
RemoveFile(fileId uint64, path string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newMachineFileApp(machineFileRepo repository.MachineFile, machineRepo repository.Machine) MachineFile {
|
||||||
|
return &machineFileAppImpl{machineRepo: machineRepo, machineFileRepo: machineFileRepo}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type machineFileAppImpl struct {
|
type machineFileAppImpl struct {
|
||||||
machineFileRepo repository.MachineFile
|
machineFileRepo repository.MachineFile
|
||||||
machineRepo repository.Machine
|
machineRepo repository.Machine
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实现类单例
|
|
||||||
var MachineFileApp MachineFile = &machineFileAppImpl{
|
|
||||||
machineRepo: persistence.MachineDao,
|
|
||||||
machineFileRepo: persistence.MachineFileDao,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分页获取机器脚本信息列表
|
// 分页获取机器脚本信息列表
|
||||||
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
@@ -176,7 +174,7 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
|||||||
err = sftpCli.RemoveDirectory(path)
|
err = sftpCli.RemoveDirectory(path)
|
||||||
// 如果文件夹有内容会删除失败,则使用rm -rf命令删除
|
// 如果文件夹有内容会删除失败,则使用rm -rf命令删除
|
||||||
if err != nil {
|
if err != nil {
|
||||||
MachineApp.GetCli(machineId).Run(fmt.Sprintf("rm -rf %s", path))
|
GetMachineApp().GetCli(machineId).Run(fmt.Sprintf("rm -rf %s", path))
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -187,7 +185,7 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
|||||||
|
|
||||||
// 获取sftp client
|
// 获取sftp client
|
||||||
func (m *machineFileAppImpl) getSftpCli(machineId uint64) *sftp.Client {
|
func (m *machineFileAppImpl) getSftpCli(machineId uint64) *sftp.Client {
|
||||||
return MachineApp.GetCli(machineId).GetSftpCli()
|
return GetMachineApp().GetCli(machineId).GetSftpCli()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验并返回实际可访问的文件path
|
// 校验并返回实际可访问的文件path
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
@@ -23,6 +22,11 @@ type MachineScript interface {
|
|||||||
Delete(id uint64)
|
Delete(id uint64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newMachineScriptApp(machineScriptRepo repository.MachineScript, machineRepo repository.Machine) MachineScript {
|
||||||
|
return &machineScriptAppImpl{machineRepo: machineRepo, machineScriptRepo: machineScriptRepo}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type machineScriptAppImpl struct {
|
type machineScriptAppImpl struct {
|
||||||
machineScriptRepo repository.MachineScript
|
machineScriptRepo repository.MachineScript
|
||||||
machineRepo repository.Machine
|
machineRepo repository.Machine
|
||||||
@@ -30,10 +34,10 @@ type machineScriptAppImpl struct {
|
|||||||
|
|
||||||
const Common_Script_Machine_Id = 9999999
|
const Common_Script_Machine_Id = 9999999
|
||||||
|
|
||||||
// 实现类单例
|
// // 实现类单例
|
||||||
var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
// var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
||||||
machineRepo: persistence.MachineDao,
|
// machineRepo: persistence.MachineDao,
|
||||||
machineScriptRepo: persistence.MachineScriptDao}
|
// machineScriptRepo: persistence.MachineScriptDao}
|
||||||
|
|
||||||
// 分页获取机器脚本信息列表
|
// 分页获取机器脚本信息列表
|
||||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/constant"
|
"mayfly-go/internal/constant"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/cache"
|
"mayfly-go/pkg/cache"
|
||||||
"mayfly-go/pkg/global"
|
"mayfly-go/pkg/global"
|
||||||
@@ -3,7 +3,7 @@ package machine
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/pkg/global"
|
"mayfly-go/pkg/global"
|
||||||
"mayfly-go/pkg/scheduler"
|
"mayfly-go/pkg/scheduler"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
@@ -279,16 +279,21 @@ func getCPU(cpuInfo string, stats *Stats) (err error) {
|
|||||||
value := strings.Split(cpuInfo, ":")[1]
|
value := strings.Split(cpuInfo, ":")[1]
|
||||||
values := strings.Split(value, ",")
|
values := strings.Split(value, ",")
|
||||||
|
|
||||||
us, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[0]), " ")[0], 32)
|
separator := " "
|
||||||
|
// 兼容旧版本使用%的情况
|
||||||
|
if strings.Contains(values[0], "%") {
|
||||||
|
separator = "%"
|
||||||
|
}
|
||||||
|
us, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[0]), separator)[0], 32)
|
||||||
stats.CPU.User = float32(us)
|
stats.CPU.User = float32(us)
|
||||||
|
|
||||||
sy, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[1]), " ")[0], 32)
|
sy, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[1]), separator)[0], 32)
|
||||||
stats.CPU.System = float32(sy)
|
stats.CPU.System = float32(sy)
|
||||||
|
|
||||||
id, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[3]), " ")[0], 32)
|
id, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[3]), separator)[0], 32)
|
||||||
stats.CPU.Idle = float32(id)
|
stats.CPU.Idle = float32(id)
|
||||||
|
|
||||||
wa, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[4]), " ")[0], 32)
|
wa, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[4]), separator)[0], 32)
|
||||||
stats.CPU.Iowait = float32(wa)
|
stats.CPU.Iowait = float32(wa)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -2,18 +2,20 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type machineRepo struct{}
|
type machineRepoImpl struct{}
|
||||||
|
|
||||||
var MachineDao repository.Machine = &machineRepo{}
|
func newMachineRepo() repository.Machine {
|
||||||
|
return new(machineRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
// 分页获取机器信息列表
|
// 分页获取机器信息列表
|
||||||
func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (m *machineRepoImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
sql := "SELECT m.* FROM t_machine m JOIN t_project_member pm ON m.project_id = pm.project_id WHERE 1 = 1 "
|
sql := "SELECT m.* FROM t_machine m JOIN t_project_member pm ON m.project_id = pm.project_id WHERE 1 = 1 "
|
||||||
if condition.CreatorId != 0 {
|
if condition.CreatorId != 0 {
|
||||||
// 使用创建者id模拟项目成员id
|
// 使用创建者id模拟项目成员id
|
||||||
@@ -32,17 +34,17 @@ func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model
|
|||||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *machineRepo) Count(condition *entity.Machine) int64 {
|
func (m *machineRepoImpl) Count(condition *entity.Machine) int64 {
|
||||||
return model.CountBy(condition)
|
return model.CountBy(condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据条件获取账号信息
|
// 根据条件获取账号信息
|
||||||
func (m *machineRepo) GetMachine(condition *entity.Machine, cols ...string) error {
|
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return model.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (m *machineRepo) GetById(id uint64, cols ...string) *entity.Machine {
|
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||||
machine := new(entity.Machine)
|
machine := new(entity.Machine)
|
||||||
if err := model.GetById(machine, id, cols...); err != nil {
|
if err := model.GetById(machine, id, cols...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -51,10 +53,10 @@ func (m *machineRepo) GetById(id uint64, cols ...string) *entity.Machine {
|
|||||||
return machine
|
return machine
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *machineRepo) Create(entity *entity.Machine) {
|
func (m *machineRepoImpl) Create(entity *entity.Machine) {
|
||||||
biz.ErrIsNilAppendErr(model.Insert(entity), "创建机器信息失败: %s")
|
biz.ErrIsNilAppendErr(model.Insert(entity), "创建机器信息失败: %s")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *machineRepo) UpdateById(entity *entity.Machine) {
|
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
|
||||||
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
|
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type machineFileRepoImpl struct{}
|
||||||
|
|
||||||
|
func newMachineFileRepo() repository.MachineFile {
|
||||||
|
return new(machineFileRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页获取机器文件信息列表
|
||||||
|
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
|
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据条件获取账号信息
|
||||||
|
func (m *machineFileRepoImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
||||||
|
return model.GetBy(condition, cols...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据id获取
|
||||||
|
func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.MachineFile {
|
||||||
|
ms := new(entity.MachineFile)
|
||||||
|
if err := model.GetById(ms, id, cols...); err != nil {
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据id获取
|
||||||
|
func (m *machineFileRepoImpl) Delete(id uint64) {
|
||||||
|
biz.ErrIsNil(model.DeleteById(new(entity.MachineFile), id), "删除失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) {
|
||||||
|
model.Insert(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
|
||||||
|
model.UpdateById(entity)
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type machineScriptRepoImpl struct{}
|
||||||
|
|
||||||
|
func newMachineScriptRepo() repository.MachineScript {
|
||||||
|
return new(machineScriptRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页获取机器信息列表
|
||||||
|
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
|
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据条件获取账号信息
|
||||||
|
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
||||||
|
return model.GetBy(condition, cols...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据id获取
|
||||||
|
func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
||||||
|
ms := new(entity.MachineScript)
|
||||||
|
if err := model.GetById(ms, id, cols...); err != nil {
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据id获取
|
||||||
|
func (m *machineScriptRepoImpl) Delete(id uint64) {
|
||||||
|
biz.ErrIsNil(model.DeleteById(new(entity.MachineScript), id), "删除失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *machineScriptRepoImpl) Create(entity *entity.MachineScript) {
|
||||||
|
model.Insert(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
|
||||||
|
model.UpdateById(entity)
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import "mayfly-go/internal/machine/domain/repository"
|
||||||
|
|
||||||
|
var (
|
||||||
|
machineRepo repository.Machine = newMachineRepo()
|
||||||
|
machineFileRepo repository.MachineFile = newMachineFileRepo()
|
||||||
|
machineScriptRepo repository.MachineScript = newMachineScriptRepo()
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMachineRepo() repository.Machine {
|
||||||
|
return machineRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMachineFileRepo() repository.MachineFile {
|
||||||
|
return machineFileRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMachineScriptRepo() repository.MachineScript {
|
||||||
|
return machineScriptRepo
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/api"
|
"mayfly-go/internal/machine/api"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/machine/application"
|
||||||
|
projectapp "mayfly-go/internal/project/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -10,8 +11,8 @@ import (
|
|||||||
|
|
||||||
func InitMachineRouter(router *gin.RouterGroup) {
|
func InitMachineRouter(router *gin.RouterGroup) {
|
||||||
m := &api.Machine{
|
m := &api.Machine{
|
||||||
MachineApp: application.MachineApp,
|
MachineApp: application.GetMachineApp(),
|
||||||
ProjectApp: application.ProjectApp,
|
ProjectApp: projectapp.GetProjectApp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
machines := router.Group("machines")
|
machines := router.Group("machines")
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/api"
|
"mayfly-go/internal/machine/api"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/machine/application"
|
||||||
sysApplication "mayfly-go/internal/sys/application"
|
sysApplication "mayfly-go/internal/sys/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
|
|||||||
machineFile := router.Group("machines")
|
machineFile := router.Group("machines")
|
||||||
{
|
{
|
||||||
mf := &api.MachineFile{
|
mf := &api.MachineFile{
|
||||||
MachineFileApp: application.MachineFileApp,
|
MachineFileApp: application.GetMachineFileApp(),
|
||||||
MachineApp: application.MachineApp,
|
MachineApp: application.GetMachineApp(),
|
||||||
MsgApp: sysApplication.MsgApp,
|
MsgApp: sysApplication.GetMsgApp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取指定机器文件列表
|
// 获取指定机器文件列表
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/api"
|
"mayfly-go/internal/machine/api"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/machine/application"
|
||||||
|
projectapp "mayfly-go/internal/project/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -12,9 +13,9 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
|
|||||||
machines := router.Group("machines")
|
machines := router.Group("machines")
|
||||||
{
|
{
|
||||||
ms := &api.MachineScript{
|
ms := &api.MachineScript{
|
||||||
MachineScriptApp: application.MachineScriptApp,
|
MachineScriptApp: application.GetMachineScriptApp(),
|
||||||
MachineApp: application.MachineApp,
|
MachineApp: application.GetMachineApp(),
|
||||||
ProjectApp: application.ProjectApp,
|
ProjectApp: projectapp.GetProjectApp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取指定机器脚本列表
|
// 获取指定机器脚本列表
|
||||||
9
server/internal/machine/router/router.go
Normal file
9
server/internal/machine/router/router.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func Init(router *gin.RouterGroup) {
|
||||||
|
InitMachineRouter(router)
|
||||||
|
InitMachineFileRouter(router)
|
||||||
|
InitMachineScriptRouter(router)
|
||||||
|
}
|
||||||
@@ -2,9 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"mayfly-go/internal/devops/api/form"
|
"mayfly-go/internal/mongo/api/form"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/mongo/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/mongo/domain/entity"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
11
server/internal/mongo/application/application.go
Normal file
11
server/internal/mongo/application/application.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import "mayfly-go/internal/mongo/infrastructure/persistence"
|
||||||
|
|
||||||
|
var (
|
||||||
|
mongoApp Mongo = newMongoAppImpl(persistence.GetMongoRepo())
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMongoApp() Mongo {
|
||||||
|
return mongoApp
|
||||||
|
}
|
||||||
@@ -3,10 +3,10 @@ package application
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"mayfly-go/internal/constant"
|
"mayfly-go/internal/constant"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
machineapp "mayfly-go/internal/machine/application"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/machine/infrastructure/machine"
|
||||||
"mayfly-go/internal/devops/infrastructure/machine"
|
"mayfly-go/internal/mongo/domain/entity"
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
"mayfly-go/internal/mongo/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/cache"
|
"mayfly-go/pkg/cache"
|
||||||
"mayfly-go/pkg/global"
|
"mayfly-go/pkg/global"
|
||||||
@@ -42,12 +42,14 @@ type Mongo interface {
|
|||||||
GetMongoCli(id uint64) *mongo.Client
|
GetMongoCli(id uint64) *mongo.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
type mongoAppImpl struct {
|
func newMongoAppImpl(mongoRepo repository.Mongo) Mongo {
|
||||||
mongoRepo repository.Mongo
|
return &mongoAppImpl{
|
||||||
|
mongoRepo: mongoRepo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var MongoApp Mongo = &mongoAppImpl{
|
type mongoAppImpl struct {
|
||||||
mongoRepo: persistence.MongoDao,
|
mongoRepo repository.Mongo
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分页获取数据库信息列表
|
// 分页获取数据库信息列表
|
||||||
@@ -191,7 +193,7 @@ type MongoSshDialer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sd *MongoSshDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
func (sd *MongoSshDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
if sshConn, err := MachineApp.GetSshTunnelMachine(sd.machineId).GetDialConn(network, address); err == nil {
|
if sshConn, err := machineapp.GetMachineApp().GetSshTunnelMachine(sd.machineId).GetDialConn(network, address); err == nil {
|
||||||
// 将ssh conn包装,否则内部部设置超时会报错,ssh conn不支持设置超时会返回错误: ssh: tcpChan: deadline not supported
|
// 将ssh conn包装,否则内部部设置超时会报错,ssh conn不支持设置超时会返回错误: ssh: tcpChan: deadline not supported
|
||||||
return &utils.WrapSshConn{Conn: sshConn}, nil
|
return &utils.WrapSshConn{Conn: sshConn}, nil
|
||||||
} else {
|
} else {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/mongo/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2,18 +2,20 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/mongo/domain/entity"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
"mayfly-go/internal/mongo/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mongoRepo struct{}
|
type mongoRepoImpl struct{}
|
||||||
|
|
||||||
var MongoDao repository.Mongo = &mongoRepo{}
|
func newMongoRepo() repository.Mongo {
|
||||||
|
return new(mongoRepoImpl)
|
||||||
|
}
|
||||||
|
|
||||||
// 分页获取数据库信息列表
|
// 分页获取数据库信息列表
|
||||||
func (d *mongoRepo) GetList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
func (d *mongoRepoImpl) GetList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||||
sql := "SELECT d.* FROM t_mongo d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
sql := "SELECT d.* FROM t_mongo d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
||||||
if condition.CreatorId != 0 {
|
if condition.CreatorId != 0 {
|
||||||
// 使用创建者id模拟项目成员id
|
// 使用创建者id模拟项目成员id
|
||||||
@@ -29,17 +31,17 @@ func (d *mongoRepo) GetList(condition *entity.Mongo, pageParam *model.PageParam,
|
|||||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *mongoRepo) Count(condition *entity.Mongo) int64 {
|
func (d *mongoRepoImpl) Count(condition *entity.Mongo) int64 {
|
||||||
return model.CountBy(condition)
|
return model.CountBy(condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据条件获取
|
// 根据条件获取
|
||||||
func (d *mongoRepo) Get(condition *entity.Mongo, cols ...string) error {
|
func (d *mongoRepoImpl) Get(condition *entity.Mongo, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return model.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (d *mongoRepo) GetById(id uint64, cols ...string) *entity.Mongo {
|
func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
||||||
db := new(entity.Mongo)
|
db := new(entity.Mongo)
|
||||||
if err := model.GetById(db, id, cols...); err != nil {
|
if err := model.GetById(db, id, cols...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -48,14 +50,14 @@ func (d *mongoRepo) GetById(id uint64, cols ...string) *entity.Mongo {
|
|||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *mongoRepo) Insert(db *entity.Mongo) {
|
func (d *mongoRepoImpl) Insert(db *entity.Mongo) {
|
||||||
biz.ErrIsNil(model.Insert(db), "新增mongo信息失败")
|
biz.ErrIsNil(model.Insert(db), "新增mongo信息失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *mongoRepo) Update(db *entity.Mongo) {
|
func (d *mongoRepoImpl) Update(db *entity.Mongo) {
|
||||||
biz.ErrIsNil(model.UpdateById(db), "更新mongo信息失败")
|
biz.ErrIsNil(model.UpdateById(db), "更新mongo信息失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *mongoRepo) Delete(id uint64) {
|
func (d *mongoRepoImpl) Delete(id uint64) {
|
||||||
model.DeleteById(new(entity.Mongo), id)
|
model.DeleteById(new(entity.Mongo), id)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mayfly-go/internal/mongo/domain/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
mongoRepo repository.Mongo = newMongoRepo()
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMongoRepo() repository.Mongo {
|
||||||
|
return mongoRepo
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/api"
|
"mayfly-go/internal/mongo/api"
|
||||||
"mayfly-go/internal/devops/application"
|
"mayfly-go/internal/mongo/application"
|
||||||
"mayfly-go/pkg/ctx"
|
"mayfly-go/pkg/ctx"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -12,7 +12,7 @@ func InitMongoRouter(router *gin.RouterGroup) {
|
|||||||
m := router.Group("mongos")
|
m := router.Group("mongos")
|
||||||
{
|
{
|
||||||
ma := &api.Mongo{
|
ma := &api.Mongo{
|
||||||
MongoApp: application.MongoApp,
|
MongoApp: application.GetMongoApp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有mongo列表
|
// 获取所有mongo列表
|
||||||
7
server/internal/mongo/router/router.go
Normal file
7
server/internal/mongo/router/router.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func Init(router *gin.RouterGroup) {
|
||||||
|
InitMongoRouter(router)
|
||||||
|
}
|
||||||
@@ -2,9 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/devops/api/vo"
|
"mayfly-go/internal/project/api/vo"
|
||||||
"mayfly-go/internal/devops/application"
|
projectapp "mayfly-go/internal/project/application"
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/project/domain/entity"
|
||||||
sys_applicaiton "mayfly-go/internal/sys/application"
|
sys_applicaiton "mayfly-go/internal/sys/application"
|
||||||
sys_entity "mayfly-go/internal/sys/domain/entity"
|
sys_entity "mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
ProjectApp application.Project
|
ProjectApp projectapp.Project
|
||||||
AccountApp sys_applicaiton.Account
|
AccountApp sys_applicaiton.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +54,10 @@ func (p *Project) DelProject(rc *ctx.ReqCtx) {
|
|||||||
p.ProjectApp.DelProject(uint64(ginx.QueryInt(rc.GinCtx, "id", 0)))
|
p.ProjectApp.DelProject(uint64(ginx.QueryInt(rc.GinCtx, "id", 0)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Project) DelProjectEnv(rc *ctx.ReqCtx) {
|
||||||
|
p.ProjectApp.DelProjectEnv(uint64(ginx.QueryInt(rc.GinCtx, "id", 0)))
|
||||||
|
}
|
||||||
|
|
||||||
// 获取项目下的环境信息
|
// 获取项目下的环境信息
|
||||||
func (p *Project) GetProjectEnvs(rc *ctx.ReqCtx) {
|
func (p *Project) GetProjectEnvs(rc *ctx.ReqCtx) {
|
||||||
projectEnvs := &[]entity.ProjectEnv{}
|
projectEnvs := &[]entity.ProjectEnv{}
|
||||||
25
server/internal/project/application/application.go
Normal file
25
server/internal/project/application/application.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
dbapp "mayfly-go/internal/db/application"
|
||||||
|
machineapp "mayfly-go/internal/machine/application"
|
||||||
|
mongoapp "mayfly-go/internal/mongo/application"
|
||||||
|
"mayfly-go/internal/project/infrastructure/persistence"
|
||||||
|
redisapp "mayfly-go/internal/redis/application"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
projectApp Project = newProjectApp(
|
||||||
|
persistence.GetProjectRepo(),
|
||||||
|
persistence.GetProjectEnvRepo(),
|
||||||
|
persistence.GetProjectMemberRepo(),
|
||||||
|
machineapp.GetMachineApp(),
|
||||||
|
redisapp.GetRedisApp(),
|
||||||
|
dbapp.GetDbApp(),
|
||||||
|
mongoapp.GetMongoApp(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetProjectApp() Project {
|
||||||
|
return projectApp
|
||||||
|
}
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
dbapp "mayfly-go/internal/db/application"
|
||||||
"mayfly-go/internal/devops/domain/repository"
|
dbentity "mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
machineapp "mayfly-go/internal/machine/application"
|
||||||
|
machineentity "mayfly-go/internal/machine/domain/entity"
|
||||||
|
mongoapp "mayfly-go/internal/mongo/application"
|
||||||
|
mongoentity "mayfly-go/internal/mongo/domain/entity"
|
||||||
|
"mayfly-go/internal/project/domain/entity"
|
||||||
|
"mayfly-go/internal/project/domain/repository"
|
||||||
|
redisapp "mayfly-go/internal/redis/application"
|
||||||
|
redisentity "mayfly-go/internal/redis/domain/entity"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
@@ -20,6 +27,8 @@ type Project interface {
|
|||||||
|
|
||||||
DelProject(id uint64)
|
DelProject(id uint64)
|
||||||
|
|
||||||
|
DelProjectEnv(id uint64)
|
||||||
|
|
||||||
// 根据项目id获取所有该项目下的环境信息列表
|
// 根据项目id获取所有该项目下的环境信息列表
|
||||||
ListEnvByProjectId(projectId uint64, listPtr interface{})
|
ListEnvByProjectId(projectId uint64, listPtr interface{})
|
||||||
|
|
||||||
@@ -40,22 +49,31 @@ type Project interface {
|
|||||||
CanAccess(accountId, projectId uint64) error
|
CanAccess(accountId, projectId uint64) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newProjectApp(projectRepo repository.Project,
|
||||||
|
projectEnvRepo repository.ProjectEnv,
|
||||||
|
projectMemberRepo repository.ProjectMemeber,
|
||||||
|
machineApp machineapp.Machine,
|
||||||
|
redisApp redisapp.Redis,
|
||||||
|
dbApp dbapp.Db,
|
||||||
|
mongoApp mongoapp.Mongo) Project {
|
||||||
|
return &projectAppImpl{
|
||||||
|
projectRepo: projectRepo,
|
||||||
|
projectEnvRepo: projectEnvRepo,
|
||||||
|
projectMemberRepo: projectMemberRepo,
|
||||||
|
machineApp: machineApp,
|
||||||
|
redisApp: redisApp,
|
||||||
|
dbApp: dbApp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type projectAppImpl struct {
|
type projectAppImpl struct {
|
||||||
projectRepo repository.Project
|
projectRepo repository.Project
|
||||||
projectEnvRepo repository.ProjectEnv
|
projectEnvRepo repository.ProjectEnv
|
||||||
projectMemberRepo repository.ProjectMemeber
|
projectMemberRepo repository.ProjectMemeber
|
||||||
machineRepo repository.Machine
|
machineApp machineapp.Machine
|
||||||
redisRepo repository.Redis
|
redisApp redisapp.Redis
|
||||||
dbRepo repository.Db
|
mongoApp mongoapp.Mongo
|
||||||
}
|
dbApp dbapp.Db
|
||||||
|
|
||||||
var ProjectApp Project = &projectAppImpl{
|
|
||||||
projectRepo: persistence.ProjectRepo,
|
|
||||||
projectEnvRepo: persistence.ProjectEnvRepo,
|
|
||||||
projectMemberRepo: persistence.ProjectMemberRepo,
|
|
||||||
machineRepo: persistence.MachineDao,
|
|
||||||
redisRepo: persistence.RedisDao,
|
|
||||||
dbRepo: persistence.DbDao,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分页获取项目信息列表
|
// 分页获取项目信息列表
|
||||||
@@ -82,9 +100,10 @@ func (p *projectAppImpl) SaveProject(project *entity.Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *projectAppImpl) DelProject(id uint64) {
|
func (p *projectAppImpl) DelProject(id uint64) {
|
||||||
biz.IsTrue(p.machineRepo.Count(&entity.Machine{ProjectId: id}) == 0, "请先删除该项目关联的机器信息")
|
biz.IsTrue(p.machineApp.Count(&machineentity.Machine{ProjectId: id}) == 0, "请先删除该项目关联的机器信息")
|
||||||
biz.IsTrue(p.redisRepo.Count(&entity.Redis{ProjectId: id}) == 0, "请先删除该项目关联的redis信息")
|
biz.IsTrue(p.redisApp.Count(&redisentity.Redis{ProjectId: id}) == 0, "请先删除该项目关联的redis信息")
|
||||||
biz.IsTrue(p.dbRepo.Count(&entity.Db{ProjectId: id}) == 0, "请先删除该项目关联的数据库信息")
|
biz.IsTrue(p.dbApp.Count(&dbentity.Db{ProjectId: id}) == 0, "请先删除该项目关联的数据库信息")
|
||||||
|
biz.IsTrue(p.mongoApp.Count(&mongoentity.Mongo{ProjectId: id}) == 0, "请先删除该项目关联的Mongo信息")
|
||||||
p.projectRepo.Delete(id)
|
p.projectRepo.Delete(id)
|
||||||
p.projectEnvRepo.DeleteEnvs(id)
|
p.projectEnvRepo.DeleteEnvs(id)
|
||||||
p.projectMemberRepo.DeleteMems(id)
|
p.projectMemberRepo.DeleteMems(id)
|
||||||
@@ -100,6 +119,14 @@ func (p *projectAppImpl) SaveProjectEnv(projectEnv *entity.ProjectEnv) {
|
|||||||
p.projectEnvRepo.Save(projectEnv)
|
p.projectEnvRepo.Save(projectEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除项目环境信息
|
||||||
|
func (p *projectAppImpl) DelProjectEnv(id uint64) {
|
||||||
|
biz.IsTrue(p.redisApp.Count(&redisentity.Redis{EnvId: id}) == 0, "请先删除该项目环境关联的redis信息")
|
||||||
|
biz.IsTrue(p.dbApp.Count(&dbentity.Db{EnvId: id}) == 0, "请先删除该项目环境关联的数据库信息")
|
||||||
|
biz.IsTrue(p.mongoApp.Count(&mongoentity.Mongo{ProjectId: id}) == 0, "请先删除该项目环境关联的Mongo信息")
|
||||||
|
p.projectEnvRepo.DeleteEnv(id)
|
||||||
|
}
|
||||||
|
|
||||||
// 根据条件获取项目成员信息
|
// 根据条件获取项目成员信息
|
||||||
func (p *projectAppImpl) ListMember(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string) {
|
func (p *projectAppImpl) ListMember(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string) {
|
||||||
p.projectMemberRepo.ListMemeber(condition, toEntity, orderBy...)
|
p.projectMemberRepo.ListMemeber(condition, toEntity, orderBy...)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/project/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import "mayfly-go/internal/devops/domain/entity"
|
import "mayfly-go/internal/project/domain/entity"
|
||||||
|
|
||||||
type ProjectEnv interface {
|
type ProjectEnv interface {
|
||||||
// 获取项目环境列表
|
// 获取项目环境列表
|
||||||
@@ -9,4 +9,6 @@ type ProjectEnv interface {
|
|||||||
Save(entity *entity.ProjectEnv)
|
Save(entity *entity.ProjectEnv)
|
||||||
|
|
||||||
DeleteEnvs(projectId uint64)
|
DeleteEnvs(projectId uint64)
|
||||||
|
|
||||||
|
DeleteEnv(envId uint64)
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayfly-go/internal/devops/domain/entity"
|
"mayfly-go/internal/project/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user