mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +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
|
||||
}
|
||||
|
||||
function buildMac() {
|
||||
build "$1/mayfly-go-mac" "darwin" "amd64" $2
|
||||
}
|
||||
|
||||
function runBuild() {
|
||||
# 构建结果的目的路径
|
||||
read -p "请输入构建产物输出目录: " toPath
|
||||
@@ -107,7 +111,7 @@ function runBuild() {
|
||||
toPath=`pwd`
|
||||
|
||||
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
|
||||
@@ -124,10 +128,14 @@ function runBuild() {
|
||||
"3")
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"4")
|
||||
buildMac ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
*)
|
||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
buildMac ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"countup.js": "^2.0.7",
|
||||
"cropperjs": "^1.5.11",
|
||||
"echarts": "^5.3.3",
|
||||
"element-plus": "^2.2.15",
|
||||
"element-plus": "^2.2.17",
|
||||
"jsencrypt": "^3.2.1",
|
||||
"jsoneditor": "^9.9.0",
|
||||
"lodash": "^4.17.21",
|
||||
@@ -26,8 +26,8 @@
|
||||
"vue-clipboard3": "^1.0.1",
|
||||
"vue-router": "^4.1.2",
|
||||
"vuex": "^4.0.2",
|
||||
"xterm": "^4.19.0",
|
||||
"xterm-addon-fit": "^0.5.0"
|
||||
"xterm": "^5.0.0",
|
||||
"xterm-addon-fit": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.178",
|
||||
|
||||
@@ -14,7 +14,7 @@ body,
|
||||
padding: 0;
|
||||
width: 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;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
</template>
|
||||
|
||||
<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 { ElMessage } from 'element-plus';
|
||||
import { initBackEndControlRoutesFun } from '@/router/index.ts';
|
||||
@@ -95,7 +95,7 @@ export default defineComponent({
|
||||
const changePwdFormRef: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
useLoginCaptcha: true,
|
||||
useLoginCaptcha: false,
|
||||
captchaImage: '',
|
||||
loginForm: {
|
||||
username: '',
|
||||
@@ -133,10 +133,12 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
nextTick(async () => {
|
||||
state.useLoginCaptcha = await useLoginCaptcha();
|
||||
getCaptcha();
|
||||
});
|
||||
// 移除公钥, 方便后续重新获取
|
||||
sessionStorage.removeItem('RsaPublicKey');
|
||||
state.useLoginCaptcha = await useLoginCaptcha();
|
||||
getCaptcha();
|
||||
});
|
||||
|
||||
const getCaptcha = async () => {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
>删除</el-button
|
||||
>
|
||||
<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-select>
|
||||
<el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
|
||||
@@ -29,18 +29,23 @@
|
||||
</template>
|
||||
</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">
|
||||
<el-tag
|
||||
@click="showTableInfo(scope.row, db)"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
v-for="db in scope.row.dbs"
|
||||
:key="db"
|
||||
style="cursor: pointer; margin-left: 3px"
|
||||
>{{ db }}</el-tag
|
||||
>
|
||||
<el-popover :width="250" placement="right" trigger="click">
|
||||
<template #reference>
|
||||
<el-link type="primary" :underline="false" plain>查看</el-link>
|
||||
</template>
|
||||
<el-tag
|
||||
@click="showTableInfo(scope.row, db)"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
v-for="db in scope.row.dbs"
|
||||
:key="db"
|
||||
style="cursor: pointer; margin-left: 3px; margin-bottom: 3px;"
|
||||
>{{ db }}</el-tag
|
||||
>
|
||||
</el-popover>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
|
||||
@@ -161,8 +166,10 @@
|
||||
v-model="sqlExecLogDialog.visible"
|
||||
>
|
||||
<div class="toolbar">
|
||||
<el-input v-model="sqlExecLogDialog.query.db" placeholder="请输入数据库名" clearable style="width: 150px" />
|
||||
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 150px" />
|
||||
<el-select v-model="sqlExecLogDialog.query.db" placeholder="请选择数据库" filterable clearable>
|
||||
<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-option v-for="item in enums.DbSqlExecTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
</el-select>
|
||||
@@ -307,6 +314,7 @@ export default defineComponent({
|
||||
visible: false,
|
||||
data: [],
|
||||
total: 0,
|
||||
dbs: [],
|
||||
query: {
|
||||
dbId: 0,
|
||||
db: '',
|
||||
@@ -398,8 +406,12 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const editDb = async (isAdd = false) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const editDb = async (isAdd = false) => {
|
||||
await getProjects();
|
||||
if (isAdd) {
|
||||
state.dbEditDialog.data = null;
|
||||
state.dbEditDialog.title = '新增数据库资源';
|
||||
@@ -434,6 +446,7 @@ export default defineComponent({
|
||||
const onShowSqlExec = async (row: any) => {
|
||||
state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
|
||||
state.sqlExecLogDialog.query.dbId = row.id;
|
||||
state.sqlExecLogDialog.dbs = row.database.split(' ');
|
||||
searchSqlExecLog();
|
||||
state.sqlExecLogDialog.visible = true;
|
||||
};
|
||||
@@ -441,6 +454,7 @@ export default defineComponent({
|
||||
const onBeforeCloseSqlExecDialog = () => {
|
||||
state.sqlExecLogDialog.visible = false;
|
||||
state.sqlExecLogDialog.data = [];
|
||||
state.sqlExecLogDialog.dbs = [];
|
||||
state.sqlExecLogDialog.total = 0;
|
||||
state.sqlExecLogDialog.query.dbId = 0;
|
||||
state.sqlExecLogDialog.query.pageNum = 1;
|
||||
@@ -602,6 +616,7 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProjects,
|
||||
filterTableInfos,
|
||||
enums,
|
||||
search,
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
</el-row>
|
||||
</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
|
||||
v-if="uploadProgressShow"
|
||||
style="width: 90%; margin-left: 20px"
|
||||
@@ -85,6 +85,10 @@
|
||||
{{ node.label }}
|
||||
<span style="color: #67c23a" v-if="data.type == '-'"> [{{ formatFileSize(data.size) }}]</span>
|
||||
</span>
|
||||
|
||||
<span style="display: inline-block">
|
||||
<span v-if="data.mode" style="color: #67c23a"> [{{ data.mode }} {{ data.modTime }}]</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<template #dropdown>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
>删除</el-button
|
||||
>
|
||||
<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-select>
|
||||
<el-input
|
||||
@@ -166,8 +166,6 @@
|
||||
:machineId="machineStatsDialog.machineId"
|
||||
:title="machineStatsDialog.title"
|
||||
></machine-stats>
|
||||
|
||||
<!-- <machine-rec v-model:visible="machineRecDialog.visible" :title="machineRecDialog.title" :machine-id="machineRecDialog.machineId" /> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -182,7 +180,6 @@ import FileManage from './FileManage.vue';
|
||||
import MachineEdit from './MachineEdit.vue';
|
||||
import ProcessList from './ProcessList.vue';
|
||||
import MachineStats from './MachineStats.vue';
|
||||
// import MachineRec from './MachineRec.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MachineList',
|
||||
@@ -192,7 +189,6 @@ export default defineComponent({
|
||||
FileManage,
|
||||
MachineEdit,
|
||||
MachineStats,
|
||||
// MachineRec,
|
||||
},
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
@@ -279,8 +275,12 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const openFormDialog = async (machine: any) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const openFormDialog = async (machine: any) => {
|
||||
await getProjects();
|
||||
let dialogTitle;
|
||||
if (machine) {
|
||||
state.machineEditDialog.data = state.currentData as any;
|
||||
@@ -372,6 +372,7 @@ export default defineComponent({
|
||||
return {
|
||||
...toRefs(state),
|
||||
choose,
|
||||
getProjects,
|
||||
showTerminal,
|
||||
openFormDialog,
|
||||
deleteMachine,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<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>
|
||||
<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-select>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
@@ -370,8 +370,12 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const editMongo = async (isAdd = false) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const editMongo = async (isAdd = false) => {
|
||||
await getProjects();
|
||||
if (isAdd) {
|
||||
state.mongoEditDialog.data = null;
|
||||
state.mongoEditDialog.title = '新增mongo';
|
||||
@@ -390,6 +394,7 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProjects,
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
|
||||
@@ -80,9 +80,18 @@
|
||||
<el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
|
||||
<div class="toolbar">
|
||||
<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>
|
||||
<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="remark" label="描述" width="125"></el-table-column>
|
||||
<el-table-column property="createTime" label="创建时间">
|
||||
@@ -207,6 +216,8 @@ export default defineComponent({
|
||||
},
|
||||
showEnvDialog: {
|
||||
visible: false,
|
||||
chooseId: null,
|
||||
chooseData: null,
|
||||
envs: [],
|
||||
title: '',
|
||||
addVisible: false,
|
||||
@@ -340,6 +351,21 @@ export default defineComponent({
|
||||
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 = () => {
|
||||
state.showMemDialog.addVisible = true;
|
||||
};
|
||||
@@ -398,12 +424,14 @@ export default defineComponent({
|
||||
showMembers,
|
||||
setMemebers,
|
||||
showEnv,
|
||||
deleteEnv,
|
||||
showAddMemberDialog,
|
||||
addMember,
|
||||
chooseMember,
|
||||
deleteMember,
|
||||
cancelAddMember,
|
||||
showAddEnvDialog,
|
||||
chooseEnv,
|
||||
addEnv,
|
||||
cancelAddEnv,
|
||||
getAccount,
|
||||
|
||||
@@ -8,6 +8,7 @@ export const projectApi = {
|
||||
delProject: Api.create("/projects", 'delete'),
|
||||
// 获取项目下的环境信息
|
||||
projectEnvs: Api.create("/projects/{projectId}/envs", 'get'),
|
||||
delProjectEnvs: Api.create("/projects/envs", 'delete'),
|
||||
saveProjectEnv: Api.create("/projects/{projectId}/envs", 'post'),
|
||||
// 获取项目下的成员信息
|
||||
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('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('list')" :color="getTypeColor('list')" class="ml5" style="cursor: pointer">list</el-tag> -->
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
<div style="float: right">
|
||||
@@ -105,6 +106,16 @@
|
||||
@valChange="searchKey"
|
||||
@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>
|
||||
</template>
|
||||
|
||||
@@ -116,6 +127,7 @@ import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
||||
import HashValue from './HashValue.vue';
|
||||
import StringValue from './StringValue.vue';
|
||||
import SetValue from './SetValue.vue';
|
||||
import ListValue from './ListValue.vue';
|
||||
import { isTrue, notBlank, notNull } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -124,6 +136,7 @@ export default defineComponent({
|
||||
StringValue,
|
||||
HashValue,
|
||||
SetValue,
|
||||
ListValue,
|
||||
ProjectEnvSelect,
|
||||
},
|
||||
setup() {
|
||||
@@ -158,6 +171,9 @@ export default defineComponent({
|
||||
setValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
listValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
keys: [],
|
||||
dbsize: 0,
|
||||
});
|
||||
@@ -253,6 +269,8 @@ export default defineComponent({
|
||||
state.stringValueDialog.visible = true;
|
||||
} else if (type == 'set') {
|
||||
state.setValueDialog.visible = true;
|
||||
} else if (type == 'list') {
|
||||
state.listValueDialog.visible = true;
|
||||
} else {
|
||||
ElMessage.warning('暂不支持该类型');
|
||||
}
|
||||
@@ -270,6 +288,8 @@ export default defineComponent({
|
||||
state.stringValueDialog.visible = true;
|
||||
} else if (type == 'set') {
|
||||
state.setValueDialog.visible = true;
|
||||
} else if (type == 'list') {
|
||||
state.listValueDialog.visible = true;
|
||||
} else {
|
||||
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="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
|
||||
<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-select>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
@@ -263,8 +263,12 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const editRedis = async (isAdd = false) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const editRedis = async (isAdd = false) => {
|
||||
await getProjects();
|
||||
if (isAdd) {
|
||||
state.redisEditDialog.data = null;
|
||||
state.redisEditDialog.title = '新增redis';
|
||||
@@ -283,6 +287,7 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProjects,
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
|
||||
@@ -20,4 +20,7 @@ export const redisApi = {
|
||||
saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
|
||||
del: Api.create("/redis/{id}/scan/{cursor}/{count}", '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"
|
||||
strip-json-comments "^3.1.1"
|
||||
|
||||
"@floating-ui/core@^0.7.3":
|
||||
version "0.7.3"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-0.7.3.tgz"
|
||||
integrity sha512-buc8BXHmG9l82+OQXOFU3Kr2XQx9ys01U/Q9HMIrZ300iLc8HLMgh7dcCqgYzAzf4BkoQvDcXf5Y+CuEZ5JBYg==
|
||||
"@floating-ui/core@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-1.0.1.tgz#00e64d74e911602c8533957af0cce5af6b2e93c8"
|
||||
integrity sha512-bO37brCPfteXQfFY0DyNDGB3+IMe4j150KFQcgJ5aBP295p9nBGeHEs/p0czrRbtlHq4Px/yoPXO/+dOCcF4uA==
|
||||
|
||||
"@floating-ui/dom@^0.5.4":
|
||||
version "0.5.4"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-0.5.4.tgz"
|
||||
integrity sha512-419BMceRLq0RrmTSDxn8hf9R3VCJv2K9PUfugh5JyEFmdjzDo+e8U5EdR8nzKq8Yj1htzLm3b6eQEEam3/rrtg==
|
||||
"@floating-ui/dom@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-1.0.1.tgz#3321d4e799d6ac2503e729131d07ad0e714aabeb"
|
||||
integrity sha512-wBDiLUKWU8QNPNOTAFHiIAkBv1KlHauG2AhqjSeh2H+wR8PX+AArXfz8NkRexH5PgMJMmSOS70YS89AbWYh5dA==
|
||||
dependencies:
|
||||
"@floating-ui/core" "^0.7.3"
|
||||
"@floating-ui/core" "^1.0.1"
|
||||
|
||||
"@humanwhocodes/config-array@^0.9.2":
|
||||
version "0.9.2"
|
||||
@@ -658,14 +658,14 @@ echarts@^5.3.3:
|
||||
tslib "2.3.0"
|
||||
zrender "5.3.2"
|
||||
|
||||
element-plus@^2.2.15:
|
||||
version "2.2.15"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.15.tgz#862bb6ecbd15b2d82d79dcf56bbbc30010771132"
|
||||
integrity sha512-SMIx8xKB1YawT9JocyFhbs3Av2rXFfxrCVTLMYS0DK0xnW+fKvwjZngLfwF6MyRzXIuzNW17XFtu0iP3tlJHbA==
|
||||
element-plus@^2.2.17:
|
||||
version "2.2.17"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.17.tgz#abbb12c19dc029c95b0271822ea9a0e635704bc2"
|
||||
integrity sha512-MGwMIE/q+FFD3kgS23x8HIe5043tmD1cTRwjhIX9o6fim1avFnUkrsfYRvybbz4CkyqSb185EheZS5AUPpXh2g==
|
||||
dependencies:
|
||||
"@ctrl/tinycolor" "^3.4.1"
|
||||
"@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"
|
||||
"@types/lodash" "^4.14.182"
|
||||
"@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"
|
||||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
||||
|
||||
xterm-addon-fit@^0.5.0:
|
||||
version "0.5.0"
|
||||
resolved "https://registry.npmmirror.com/xterm-addon-fit/download/xterm-addon-fit-0.5.0.tgz"
|
||||
integrity sha1-LVG5g7eGqX3NbN6AXnAMf5E7xZY=
|
||||
xterm-addon-fit@^0.6.0:
|
||||
version "0.6.0"
|
||||
resolved "https://registry.npmmirror.com/xterm-addon-fit/-/xterm-addon-fit-0.6.0.tgz#142e1ce181da48763668332593fc440349c88c34"
|
||||
integrity sha512-9/7A+1KEjkFam0yxTaHfuk9LEvvTSBi0PZmEkzJqgafXPEXL9pCMAVV7rB09sX6ATRDXAdBpQhZkhKj7CGvYeg==
|
||||
|
||||
xterm@^4.19.0:
|
||||
version "4.19.0"
|
||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-4.19.0.tgz"
|
||||
integrity sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==
|
||||
xterm@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-5.0.0.tgz#0af50509b33d0dc62fde7a4ec17750b8e453cc5c"
|
||||
integrity sha512-tmVsKzZovAYNDIaUinfz+VDclraQpPUnAME+JawosgWRMphInDded/PuY0xmU5dOhyeYZsI0nz5yd8dPYsdLTA==
|
||||
|
||||
yallist@^4.0.0:
|
||||
version "4.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module mayfly-go
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
@@ -15,7 +15,8 @@ require (
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
|
||||
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
|
||||
// gorm
|
||||
gorm.io/driver/mysql v1.3.5
|
||||
|
||||
@@ -4,12 +4,17 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
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"
|
||||
"mayfly-go/pkg/config"
|
||||
"mayfly-go/pkg/middleware"
|
||||
"mayfly-go/static"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -17,6 +22,7 @@ import (
|
||||
func WrapStaticHandler(h http.Handler) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -68,22 +74,13 @@ func InitRouter() *gin.Engine {
|
||||
common_router.InitIndexRouter(api)
|
||||
common_router.InitCommonRouter(api)
|
||||
|
||||
sys_router.InitCaptchaRouter(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)
|
||||
sys_router.Init(api)
|
||||
|
||||
devops_router.InitProjectRouter(api)
|
||||
devops_router.InitDbRouter(api)
|
||||
devops_router.InitDbSqlExecRouter(api)
|
||||
devops_router.InitRedisRouter(api)
|
||||
devops_router.InitMachineRouter(api)
|
||||
devops_router.InitMachineScriptRouter(api)
|
||||
devops_router.InitMachineFileRouter(api)
|
||||
devops_router.InitMongoRouter(api)
|
||||
project_router.Init(api)
|
||||
machine_router.Init(api)
|
||||
db_router.Init(api)
|
||||
redis_router.Init(api)
|
||||
mongo_router.Init(api)
|
||||
}
|
||||
|
||||
return router
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
sys_application "mayfly-go/internal/sys/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
)
|
||||
|
||||
func InitSaveLogFunc() ctx.SaveLogFunc {
|
||||
return sys_application.SyslogApp.SaveFromReq
|
||||
return sysapp.GetSyslogApp().SaveFromReq
|
||||
}
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
dbapp "mayfly-go/internal/db/application"
|
||||
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"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
ProjectApp application.Project
|
||||
MachineApp application.Machine
|
||||
DbApp application.Db
|
||||
RedisApp application.Redis
|
||||
ProjectApp projectapp.Project
|
||||
MachineApp machineapp.Machine
|
||||
DbApp dbapp.Db
|
||||
RedisApp redisapp.Redis
|
||||
}
|
||||
|
||||
func (i *Index) Count(rc *ctx.ReqCtx) {
|
||||
rc.ResData = map[string]interface{}{
|
||||
"projectNum": i.ProjectApp.Count(new(entity.Project)),
|
||||
"machineNum": i.MachineApp.Count(new(entity.Machine)),
|
||||
"dbNum": i.DbApp.Count(new(entity.Db)),
|
||||
"redisNum": i.RedisApp.Count(new(entity.Redis)),
|
||||
"projectNum": i.ProjectApp.Count(new(projectentity.Project)),
|
||||
"machineNum": i.MachineApp.Count(new(machineentity.Machine)),
|
||||
"dbNum": i.DbApp.Count(new(dbentity.Db)),
|
||||
"redisNum": i.RedisApp.Count(new(redisentity.Redis)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package router
|
||||
|
||||
import (
|
||||
"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"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,10 +14,10 @@ import (
|
||||
func InitIndexRouter(router *gin.RouterGroup) {
|
||||
index := router.Group("common/index")
|
||||
i := &api.Index{
|
||||
ProjectApp: devops_app.ProjectApp,
|
||||
MachineApp: devops_app.MachineApp,
|
||||
DbApp: devops_app.DbApp,
|
||||
RedisApp: devops_app.RedisApp,
|
||||
ProjectApp: projectapp.GetProjectApp(),
|
||||
MachineApp: machineapp.GetMachineApp(),
|
||||
DbApp: dbapp.GetDbApp(),
|
||||
RedisApp: redisapp.GetRedisApp(),
|
||||
}
|
||||
{
|
||||
// 首页基本信息统计
|
||||
|
||||
@@ -3,11 +3,12 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/db/api/form"
|
||||
"mayfly-go/internal/db/api/vo"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
@@ -25,8 +26,8 @@ import (
|
||||
type Db struct {
|
||||
DbApp application.Db
|
||||
DbSqlExecApp application.DbSqlExec
|
||||
MsgApp sysApplication.Msg
|
||||
ProjectApp application.Project
|
||||
MsgApp sysapp.Msg
|
||||
ProjectApp projectapp.Project
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
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["colNames"] = []string{"影响条数"}
|
||||
colAndRes["res"] = res
|
||||
|
||||
rc.ResData = colAndRes
|
||||
// 保存sql执行记录
|
||||
if res[0]["影响条数"] > "0" {
|
||||
execRecord.Remark = form.Remark
|
||||
d.DbSqlExecApp.Save(execRecord)
|
||||
}
|
||||
}
|
||||
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")
|
||||
colAndRes := make(map[string]interface{})
|
||||
colAndRes["colNames"] = execRes.ColNames
|
||||
colAndRes["res"] = execRes.Res
|
||||
rc.ResData = colAndRes
|
||||
}
|
||||
|
||||
// 执行sql文件
|
||||
@@ -255,7 +240,13 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
||||
countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
|
||||
_, 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
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
@@ -264,9 +255,9 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
||||
|
||||
var sqlTmp string
|
||||
switch dbInstance.Type {
|
||||
case "mysql":
|
||||
case entity.DbTypeMysql:
|
||||
sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
|
||||
case "postgres":
|
||||
case entity.DbTypePostgres:
|
||||
sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
|
||||
}
|
||||
for index := 0; index < pageNum; index++ {
|
||||
@@ -1,8 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"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 (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/internal/constant"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
machineapp "mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
@@ -52,16 +51,18 @@ type Db interface {
|
||||
GetDatabases(entity *entity.Db) []string
|
||||
}
|
||||
|
||||
func newDbApp(dbRepo repository.Db, dbSqlRepo repository.DbSql) Db {
|
||||
return &dbAppImpl{
|
||||
dbRepo: dbRepo,
|
||||
dbSqlRepo: dbSqlRepo,
|
||||
}
|
||||
}
|
||||
|
||||
type dbAppImpl struct {
|
||||
dbRepo repository.Db
|
||||
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 {
|
||||
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||
@@ -232,7 +233,7 @@ var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second).
|
||||
|
||||
func init() {
|
||||
machine.AddCheckSshTunnelMachineUseFunc(func(machineId uint64) bool {
|
||||
// 遍历所有db连接实例,若存在redis实例使用该ssh隧道机器,则返回true,表示还在使用中...
|
||||
// 遍历所有db连接实例,若存在db实例使用该ssh隧道机器,则返回true,表示还在使用中...
|
||||
items := dbCache.Items()
|
||||
for _, v := range items {
|
||||
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) {
|
||||
// SSH Conect
|
||||
if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
|
||||
sshTunnelMachine := MachineApp.GetSshTunnelMachine(d.SshTunnelMachineId)
|
||||
sshTunnelMachine := machineapp.GetMachineApp().GetSshTunnelMachine(d.SshTunnelMachineId)
|
||||
if d.Type == entity.DbTypeMysql {
|
||||
mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return sshTunnelMachine.GetDialConn("tcp", addr)
|
||||
@@ -410,14 +411,6 @@ type DbInstance struct {
|
||||
// 执行查询语句
|
||||
// 依次返回 列名数组,结果map,错误
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -558,8 +551,14 @@ func (mm *MysqlMetadata) GetColumns(tableNames ...string) []map[string]interface
|
||||
if len(tableNames) > 1 {
|
||||
countSql := fmt.Sprintf(MYSQL_COLOUMN_MA_COUNT, tableName)
|
||||
_, 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
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
@@ -672,8 +671,13 @@ func (pm *PgsqlMetadata) GetColumns(tableNames ...string) []map[string]interface
|
||||
if len(tableNames) > 1 {
|
||||
countSql := fmt.Sprintf(PGSQL_COLUMN_MA_COUNT, tableName)
|
||||
_, 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
|
||||
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
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package repository
|
||||
|
||||
import "mayfly-go/internal/devops/domain/entity"
|
||||
import "mayfly-go/internal/db/domain/entity"
|
||||
|
||||
type DbSql interface {
|
||||
DeleteBy(condition *entity.DbSql)
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -2,18 +2,20 @@ package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"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 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
@@ -35,17 +37,17 @@ func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toE
|
||||
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)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
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...)
|
||||
}
|
||||
|
||||
// 根据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)
|
||||
if err := model.GetById(db, id, cols...); err != nil {
|
||||
return nil
|
||||
@@ -54,14 +56,14 @@ func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
|
||||
return db
|
||||
}
|
||||
|
||||
func (d *dbRepo) Insert(db *entity.Db) {
|
||||
func (d *dbRepoImpl) Insert(db *entity.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), "更新数据库信息失败")
|
||||
}
|
||||
|
||||
func (d *dbRepo) Delete(id uint64) {
|
||||
func (d *dbRepoImpl) Delete(id uint64) {
|
||||
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
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/db/api"
|
||||
"mayfly-go/internal/db/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,10 +14,10 @@ func InitDbRouter(router *gin.RouterGroup) {
|
||||
db := router.Group("dbs")
|
||||
{
|
||||
d := &api.Db{
|
||||
DbApp: application.DbApp,
|
||||
DbSqlExecApp: application.DbSqlExecApp,
|
||||
MsgApp: sysApplication.MsgApp,
|
||||
ProjectApp: application.ProjectApp,
|
||||
DbApp: application.GetDbApp(),
|
||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||
MsgApp: sysapp.GetMsgApp(),
|
||||
ProjectApp: projectapp.GetProjectApp(),
|
||||
}
|
||||
// 获取所有数据库列表
|
||||
db.GET("", func(c *gin.Context) {
|
||||
@@ -1,8 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/db/api"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,7 +12,7 @@ func InitDbSqlExecRouter(router *gin.RouterGroup) {
|
||||
db := router.Group("/dbs/:dbId/sql-execs")
|
||||
{
|
||||
d := &api.DbSqlExec{
|
||||
DbSqlExecApp: application.DbSqlExecApp,
|
||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||
}
|
||||
// 获取所有数据库sql执行记录列表
|
||||
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 (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/config"
|
||||
"mayfly-go/pkg/ctx"
|
||||
@@ -18,7 +19,6 @@ import (
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
type Machine struct {
|
||||
MachineApp application.Machine
|
||||
ProjectApp application.Project
|
||||
ProjectApp projectapp.Project
|
||||
}
|
||||
|
||||
func (m *Machine) Machines(rc *ctx.ReqCtx) {
|
||||
@@ -175,8 +175,6 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
||||
|
||||
var recorder *machine.Recorder
|
||||
if cli.GetMachine().EnableRecorder == 1 {
|
||||
mask := syscall.Umask(0)
|
||||
defer syscall.Umask(mask)
|
||||
now := time.Now()
|
||||
// 回放文件路径为: 基础配置路径/机器id/操作日期/操作者账号/操作时间.cast
|
||||
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"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
@@ -116,11 +116,12 @@ func (m *MachineFile) GetDirEntry(rc *ctx.ReqCtx) {
|
||||
fisVO := make([]vo.MachineFileInfo, 0)
|
||||
for _, fi := range fis {
|
||||
fisVO = append(fisVO, vo.MachineFileInfo{
|
||||
Name: fi.Name(),
|
||||
Size: fi.Size(),
|
||||
Path: readPath + fi.Name(),
|
||||
Type: getFileType(fi.Mode()),
|
||||
Mode: fi.Mode().String(),
|
||||
Name: fi.Name(),
|
||||
Size: fi.Size(),
|
||||
Path: readPath + fi.Name(),
|
||||
Type: getFileType(fi.Mode()),
|
||||
Mode: fi.Mode().String(),
|
||||
ModTime: fi.ModTime().Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
rc.ResData = fisVO
|
||||
@@ -2,10 +2,11 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
@@ -18,7 +19,7 @@ import (
|
||||
type MachineScript struct {
|
||||
MachineScriptApp application.MachineScript
|
||||
MachineApp application.Machine
|
||||
ProjectApp application.Project
|
||||
ProjectApp projectapp.Project
|
||||
}
|
||||
|
||||
func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) {
|
||||
@@ -56,11 +56,12 @@ type MachineFileVO struct {
|
||||
}
|
||||
|
||||
type MachineFileInfo struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
ModTime string `json:"modTime"`
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
|
||||
@@ -37,12 +36,15 @@ type Machine interface {
|
||||
GetSshTunnelMachine(id uint64) *machine.SshTunnelMachine
|
||||
}
|
||||
|
||||
func newMachineApp(machineRepo repository.Machine) Machine {
|
||||
return &machineAppImpl{machineRepo: machineRepo}
|
||||
|
||||
}
|
||||
|
||||
type machineAppImpl struct {
|
||||
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 {
|
||||
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) {
|
||||
// ’修改机器信息且密码不为空‘ or ‘新增’需要测试是否可连接
|
||||
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}
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"os"
|
||||
@@ -53,17 +52,16 @@ type MachineFile interface {
|
||||
RemoveFile(fileId uint64, path string)
|
||||
}
|
||||
|
||||
func newMachineFileApp(machineFileRepo repository.MachineFile, machineRepo repository.Machine) MachineFile {
|
||||
return &machineFileAppImpl{machineRepo: machineRepo, machineFileRepo: machineFileRepo}
|
||||
|
||||
}
|
||||
|
||||
type machineFileAppImpl struct {
|
||||
machineFileRepo repository.MachineFile
|
||||
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 {
|
||||
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
@@ -176,7 +174,7 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
||||
err = sftpCli.RemoveDirectory(path)
|
||||
// 如果文件夹有内容会删除失败,则使用rm -rf命令删除
|
||||
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
|
||||
}
|
||||
} else {
|
||||
@@ -187,7 +185,7 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
||||
|
||||
// 获取sftp client
|
||||
func (m *machineFileAppImpl) getSftpCli(machineId uint64) *sftp.Client {
|
||||
return MachineApp.GetCli(machineId).GetSftpCli()
|
||||
return GetMachineApp().GetCli(machineId).GetSftpCli()
|
||||
}
|
||||
|
||||
// 校验并返回实际可访问的文件path
|
||||
@@ -1,9 +1,8 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
@@ -23,6 +22,11 @@ type MachineScript interface {
|
||||
Delete(id uint64)
|
||||
}
|
||||
|
||||
func newMachineScriptApp(machineScriptRepo repository.MachineScript, machineRepo repository.Machine) MachineScript {
|
||||
return &machineScriptAppImpl{machineRepo: machineRepo, machineScriptRepo: machineScriptRepo}
|
||||
|
||||
}
|
||||
|
||||
type machineScriptAppImpl struct {
|
||||
machineScriptRepo repository.MachineScript
|
||||
machineRepo repository.Machine
|
||||
@@ -30,10 +34,10 @@ type machineScriptAppImpl struct {
|
||||
|
||||
const Common_Script_Machine_Id = 9999999
|
||||
|
||||
// 实现类单例
|
||||
var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
||||
machineRepo: persistence.MachineDao,
|
||||
machineScriptRepo: persistence.MachineScriptDao}
|
||||
// // 实现类单例
|
||||
// var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
||||
// machineRepo: persistence.MachineDao,
|
||||
// machineScriptRepo: persistence.MachineScriptDao}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/internal/constant"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
@@ -27,7 +27,7 @@ type Cli struct {
|
||||
sshTunnelMachineId uint64
|
||||
}
|
||||
|
||||
//连接
|
||||
// 连接
|
||||
func (c *Cli) connect() error {
|
||||
// 如果已经有client则直接返回
|
||||
if c.client != nil {
|
||||
@@ -90,8 +90,8 @@ func (c *Cli) GetSession() (*ssh.Session, error) {
|
||||
return c.client.NewSession()
|
||||
}
|
||||
|
||||
//执行shell
|
||||
//@param shell shell脚本命令
|
||||
// 执行shell
|
||||
// @param shell shell脚本命令
|
||||
func (c *Cli) Run(shell string) (*string, error) {
|
||||
session, err := c.GetSession()
|
||||
if err != nil {
|
||||
@@ -236,7 +236,7 @@ func GetSshClient(m *entity.Machine) (*ssh.Client, error) {
|
||||
return sshClient, nil
|
||||
}
|
||||
|
||||
//根据机器信息创建客户端对象
|
||||
// 根据机器信息创建客户端对象
|
||||
func newClient(machine *entity.Machine) (*Cli, error) {
|
||||
if machine == nil {
|
||||
return nil, errors.New("机器不存在")
|
||||
@@ -3,7 +3,7 @@ package machine
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/scheduler"
|
||||
"mayfly-go/pkg/utils"
|
||||
@@ -279,16 +279,21 @@ func getCPU(cpuInfo string, stats *Stats) (err error) {
|
||||
value := strings.Split(cpuInfo, ":")[1]
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
return nil
|
||||
@@ -2,18 +2,20 @@ package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"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 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
@@ -32,17 +34,17 @@ func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model
|
||||
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)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
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...)
|
||||
}
|
||||
|
||||
// 根据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)
|
||||
if err := model.GetById(machine, id, cols...); err != nil {
|
||||
return nil
|
||||
@@ -51,10 +53,10 @@ func (m *machineRepo) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
return machine
|
||||
}
|
||||
|
||||
func (m *machineRepo) Create(entity *entity.Machine) {
|
||||
func (m *machineRepoImpl) Create(entity *entity.Machine) {
|
||||
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")
|
||||
}
|
||||
@@ -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
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/machine/api"
|
||||
"mayfly-go/internal/machine/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -10,8 +11,8 @@ import (
|
||||
|
||||
func InitMachineRouter(router *gin.RouterGroup) {
|
||||
m := &api.Machine{
|
||||
MachineApp: application.MachineApp,
|
||||
ProjectApp: application.ProjectApp,
|
||||
MachineApp: application.GetMachineApp(),
|
||||
ProjectApp: projectapp.GetProjectApp(),
|
||||
}
|
||||
|
||||
machines := router.Group("machines")
|
||||
@@ -1,8 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/machine/api"
|
||||
"mayfly-go/internal/machine/application"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
@@ -13,9 +13,9 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
|
||||
machineFile := router.Group("machines")
|
||||
{
|
||||
mf := &api.MachineFile{
|
||||
MachineFileApp: application.MachineFileApp,
|
||||
MachineApp: application.MachineApp,
|
||||
MsgApp: sysApplication.MsgApp,
|
||||
MachineFileApp: application.GetMachineFileApp(),
|
||||
MachineApp: application.GetMachineApp(),
|
||||
MsgApp: sysApplication.GetMsgApp(),
|
||||
}
|
||||
|
||||
// 获取指定机器文件列表
|
||||
@@ -1,8 +1,9 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/machine/api"
|
||||
"mayfly-go/internal/machine/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,9 +13,9 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
|
||||
machines := router.Group("machines")
|
||||
{
|
||||
ms := &api.MachineScript{
|
||||
MachineScriptApp: application.MachineScriptApp,
|
||||
MachineApp: application.MachineApp,
|
||||
ProjectApp: application.ProjectApp,
|
||||
MachineScriptApp: application.GetMachineScriptApp(),
|
||||
MachineApp: application.GetMachineApp(),
|
||||
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 (
|
||||
"context"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/mongo/api/form"
|
||||
"mayfly-go/internal/mongo/application"
|
||||
"mayfly-go/internal/mongo/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"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 (
|
||||
"context"
|
||||
"mayfly-go/internal/constant"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
machineapp "mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/internal/mongo/domain/entity"
|
||||
"mayfly-go/internal/mongo/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
@@ -42,12 +42,14 @@ type Mongo interface {
|
||||
GetMongoCli(id uint64) *mongo.Client
|
||||
}
|
||||
|
||||
type mongoAppImpl struct {
|
||||
mongoRepo repository.Mongo
|
||||
func newMongoAppImpl(mongoRepo repository.Mongo) Mongo {
|
||||
return &mongoAppImpl{
|
||||
mongoRepo: mongoRepo,
|
||||
}
|
||||
}
|
||||
|
||||
var MongoApp Mongo = &mongoAppImpl{
|
||||
mongoRepo: persistence.MongoDao,
|
||||
type mongoAppImpl struct {
|
||||
mongoRepo repository.Mongo
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
@@ -191,7 +193,7 @@ type MongoSshDialer struct {
|
||||
}
|
||||
|
||||
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
|
||||
return &utils.WrapSshConn{Conn: sshConn}, nil
|
||||
} else {
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/mongo/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -2,18 +2,20 @@ package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/mongo/domain/entity"
|
||||
"mayfly-go/internal/mongo/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"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 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
@@ -29,17 +31,17 @@ func (d *mongoRepo) GetList(condition *entity.Mongo, pageParam *model.PageParam,
|
||||
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)
|
||||
}
|
||||
|
||||
// 根据条件获取
|
||||
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...)
|
||||
}
|
||||
|
||||
// 根据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)
|
||||
if err := model.GetById(db, id, cols...); err != nil {
|
||||
return nil
|
||||
@@ -48,14 +50,14 @@ func (d *mongoRepo) GetById(id uint64, cols ...string) *entity.Mongo {
|
||||
return db
|
||||
}
|
||||
|
||||
func (d *mongoRepo) Insert(db *entity.Mongo) {
|
||||
func (d *mongoRepoImpl) Insert(db *entity.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信息失败")
|
||||
}
|
||||
|
||||
func (d *mongoRepo) Delete(id uint64) {
|
||||
func (d *mongoRepoImpl) Delete(id uint64) {
|
||||
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
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/mongo/api"
|
||||
"mayfly-go/internal/mongo/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,7 +12,7 @@ func InitMongoRouter(router *gin.RouterGroup) {
|
||||
m := router.Group("mongos")
|
||||
{
|
||||
ma := &api.Mongo{
|
||||
MongoApp: application.MongoApp,
|
||||
MongoApp: application.GetMongoApp(),
|
||||
}
|
||||
|
||||
// 获取所有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 (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/project/api/vo"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/internal/project/domain/entity"
|
||||
sys_applicaiton "mayfly-go/internal/sys/application"
|
||||
sys_entity "mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
ProjectApp application.Project
|
||||
ProjectApp projectapp.Project
|
||||
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)))
|
||||
}
|
||||
|
||||
func (p *Project) DelProjectEnv(rc *ctx.ReqCtx) {
|
||||
p.ProjectApp.DelProjectEnv(uint64(ginx.QueryInt(rc.GinCtx, "id", 0)))
|
||||
}
|
||||
|
||||
// 获取项目下的环境信息
|
||||
func (p *Project) GetProjectEnvs(rc *ctx.ReqCtx) {
|
||||
projectEnvs := &[]entity.ProjectEnv{}
|
||||
@@ -61,7 +65,7 @@ func (p *Project) GetProjectEnvs(rc *ctx.ReqCtx) {
|
||||
rc.ResData = projectEnvs
|
||||
}
|
||||
|
||||
//保存项目下的环境信息
|
||||
// 保存项目下的环境信息
|
||||
func (p *Project) SaveProjectEnvs(rc *ctx.ReqCtx) {
|
||||
projectEnv := &entity.ProjectEnv{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, projectEnv)
|
||||
@@ -78,7 +82,7 @@ func (p *Project) GetProjectMembers(rc *ctx.ReqCtx) {
|
||||
ginx.GetPageParam(rc.GinCtx), projectMems)
|
||||
}
|
||||
|
||||
//保存项目的成员信息
|
||||
// 保存项目的成员信息
|
||||
func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
|
||||
projectMem := &entity.ProjectMember{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, projectMem)
|
||||
@@ -95,7 +99,7 @@ func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
|
||||
p.ProjectApp.SaveProjectMember(projectMem)
|
||||
}
|
||||
|
||||
//删除项目成员
|
||||
// 删除项目成员
|
||||
func (p *Project) DelProjectMember(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
pid := ginx.PathParamInt(g, "projectId")
|
||||
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
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
dbapp "mayfly-go/internal/db/application"
|
||||
dbentity "mayfly-go/internal/db/domain/entity"
|
||||
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/model"
|
||||
)
|
||||
@@ -20,6 +27,8 @@ type Project interface {
|
||||
|
||||
DelProject(id uint64)
|
||||
|
||||
DelProjectEnv(id uint64)
|
||||
|
||||
// 根据项目id获取所有该项目下的环境信息列表
|
||||
ListEnvByProjectId(projectId uint64, listPtr interface{})
|
||||
|
||||
@@ -40,22 +49,31 @@ type Project interface {
|
||||
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 {
|
||||
projectRepo repository.Project
|
||||
projectEnvRepo repository.ProjectEnv
|
||||
projectMemberRepo repository.ProjectMemeber
|
||||
machineRepo repository.Machine
|
||||
redisRepo repository.Redis
|
||||
dbRepo repository.Db
|
||||
}
|
||||
|
||||
var ProjectApp Project = &projectAppImpl{
|
||||
projectRepo: persistence.ProjectRepo,
|
||||
projectEnvRepo: persistence.ProjectEnvRepo,
|
||||
projectMemberRepo: persistence.ProjectMemberRepo,
|
||||
machineRepo: persistence.MachineDao,
|
||||
redisRepo: persistence.RedisDao,
|
||||
dbRepo: persistence.DbDao,
|
||||
machineApp machineapp.Machine
|
||||
redisApp redisapp.Redis
|
||||
mongoApp mongoapp.Mongo
|
||||
dbApp dbapp.Db
|
||||
}
|
||||
|
||||
// 分页获取项目信息列表
|
||||
@@ -82,9 +100,10 @@ func (p *projectAppImpl) SaveProject(project *entity.Project) {
|
||||
}
|
||||
|
||||
func (p *projectAppImpl) DelProject(id uint64) {
|
||||
biz.IsTrue(p.machineRepo.Count(&entity.Machine{ProjectId: id}) == 0, "请先删除该项目关联的机器信息")
|
||||
biz.IsTrue(p.redisRepo.Count(&entity.Redis{ProjectId: id}) == 0, "请先删除该项目关联的redis信息")
|
||||
biz.IsTrue(p.dbRepo.Count(&entity.Db{ProjectId: id}) == 0, "请先删除该项目关联的数据库信息")
|
||||
biz.IsTrue(p.machineApp.Count(&machineentity.Machine{ProjectId: id}) == 0, "请先删除该项目关联的机器信息")
|
||||
biz.IsTrue(p.redisApp.Count(&redisentity.Redis{ProjectId: id}) == 0, "请先删除该项目关联的redis信息")
|
||||
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.projectEnvRepo.DeleteEnvs(id)
|
||||
p.projectMemberRepo.DeleteMems(id)
|
||||
@@ -100,6 +119,14 @@ func (p *projectAppImpl) SaveProjectEnv(projectEnv *entity.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) {
|
||||
p.projectMemberRepo.ListMemeber(condition, toEntity, orderBy...)
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/project/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package repository
|
||||
|
||||
import "mayfly-go/internal/devops/domain/entity"
|
||||
import "mayfly-go/internal/project/domain/entity"
|
||||
|
||||
type ProjectEnv interface {
|
||||
// 获取项目环境列表
|
||||
@@ -9,4 +9,6 @@ type ProjectEnv interface {
|
||||
Save(entity *entity.ProjectEnv)
|
||||
|
||||
DeleteEnvs(projectId uint64)
|
||||
|
||||
DeleteEnv(envId uint64)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/project/domain/entity"
|
||||
"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