refactor: 代码重构、分页数据组件支持多选

This commit is contained in:
meilin.huang
2023-07-01 14:34:42 +08:00
parent d423572e01
commit ce32fc7f2c
81 changed files with 937 additions and 759 deletions

View File

@@ -72,7 +72,8 @@
动态表头显示根据表格每条配置项中的show字段来决定改列是否显示或者隐藏
columns 就是我们表格配置的数组对象
-->
<el-popover placement="bottom" title="表格配置" :width="200" trigger="click">
<el-popover placement="bottom" title="表格配置"
popper-style="max-height: 550px; overflow: auto; max-width: 450px" width="auto" trigger="click">
<div v-for="(item, index) in props.columns" :key="index">
<el-checkbox v-model="item.show" :label="item.label" :true-label="true" :false-label="false" />
</div>
@@ -84,15 +85,10 @@
</div>
</div>
<el-table v-bind="$attrs" max-height="700" @current-change="choose" :data="props.data" border
highlight-current-row show-overflow-tooltip>
<el-table-column v-if="props.showChooseColumn" label="选择" align="center" width="53px">
<template #default="scope">
<el-radio v-model="state.chooseId" :label="scope.row.id">
<i></i>
</el-radio>
</template>
</el-table-column>
<el-table v-bind="$attrs" max-height="700" @selection-change="handleSelectionChange" :data="props.data" border
highlight-current-row show-overflow-tooltip v-loading="loadingData">
<el-table-column v-if="props.showSelection" type="selection" width="40" />
<template v-for="(item, index) in columns">
<el-table-column :key="index" v-if="item.show" :prop="item.prop" :label="item.label" :fixed="item.fixed"
@@ -126,22 +122,17 @@
import { toRefs, watch, reactive, onMounted } from 'vue';
import { TableColumn, TableQuery } from './index';
const emit = defineEmits(['update:queryForm', 'update:pageNum', 'update:pageSize', 'update:chooseData', 'pageChange'])
const emit = defineEmits(['update:queryForm', 'update:pageNum', 'update:pageSize', 'update:selectionData', 'pageChange'])
const props = defineProps({
// 是否显示选择列
showChooseColumn: {
showSelection: {
type: Boolean,
default: false,
},
// 选择列绑定的主键key字段名
chooseDataIdKey: {
type: String,
default: "id"
},
// 当前选择的数据
chooseData: {
type: Object
selectionData: {
type: Array<any>
},
// 列信息
columns: {
@@ -190,27 +181,20 @@ const state = reactive({
isOpenMoreQuery: false,
defaultQueryCount: 2, // 默认显示的查询参数个数
queryForm: {} as any,
loadingData: false,
})
const {
isOpenMoreQuery,
defaultQueryCount,
queryForm,
loadingData,
} = toRefs(state)
watch(() => props.queryForm, (newValue: any) => {
state.queryForm = newValue
})
watch(() => props.chooseData, (newValue: any) => {
state.chooseData = newValue
if (newValue) {
state.chooseId = state.chooseData[props.chooseDataIdKey]
} else {
state.chooseId = 0;
}
})
watch(() => props.pageNum, (newValue: any) => {
state.pageNum = newValue
})
@@ -227,6 +211,7 @@ watch(() => props.data, (newValue: any) => {
}
})
}
state.loadingData = false;
})
onMounted(() => {
@@ -235,38 +220,44 @@ onMounted(() => {
state.queryForm = props.queryForm;
})
// 处理选中了列表中的某一条数据
const choose = (item: any) => {
if (!item || !props.showChooseColumn) {
return;
}
state.chooseData = item;
state.chooseId = item[props.chooseDataIdKey]
emit('update:chooseData', state.chooseData)
};
const handleSelectionChange = (val: any) => {
emit('update:selectionData', val);
}
const handlePageChange = () => {
emit('update:pageNum', state.pageNum)
emit("pageChange")
execQuery();
}
const handleSizeChange = () => {
emit('update:pageSize', state.pageSize)
emit("pageChange")
emit('update:pageSize', state.pageSize);
execQuery();
}
const queryData = () => {
// 触发重新调用查询接口即可
emit("pageChange")
execQuery();
}
const reset = () => {
// 触发重新调用查询接口即可
state.queryForm = {};
emit('update:queryForm', state.queryForm)
execQuery();
}
const execQuery = () => {
emit("pageChange")
}
/**
* 是否正在加载数据
*/
const loading = (loading: boolean) => {
state.loadingData = loading;
}
defineExpose({ loading })
</script>
<style scoped lang="scss">
.page-table {

View File

@@ -61,7 +61,7 @@
<el-dialog title="OTP校验" v-model="otpDialog.visible" @close="loading.signIn = false" :close-on-click-modal="false"
width="350px" :destroy-on-close="true">
<el-form ref="otpFormRef" :model="otpDialog.form" :rules="otpDialog.rules" label-width="65px">
<el-form ref="otpFormRef" :model="otpDialog.form" :rules="otpDialog.rules" @submit.native.prevent label-width="65px">
<el-form-item v-if="otpDialog.otpUrl" label="二维码">
<qrcode-vue :value="otpDialog.otpUrl" :size="200" level="H" />
</el-form-item>

View File

@@ -1,7 +1,7 @@
<template>
<div class="db-list">
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="datas" :columns="state.columns" :total="total"
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="state.selectionData" :data="datas" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #tagPathSelect>
@@ -13,9 +13,9 @@
<template #queryRight>
<el-button v-auth="permissions.saveDb" type="primary" icon="plus" @click="editDb(true)">添加</el-button>
<el-button v-auth="permissions.saveDb" :disabled="!chooseData" @click="editDb(false)" type="primary"
icon="edit">编辑</el-button>
<el-button v-auth="permissions.delDb" :disabled="!chooseData" @click="deleteDb(chooseData.id)" type="danger"
<el-button v-auth="permissions.saveDb" :disabled="selectionData.length != 1" @click="editDb(false)"
type="primary" icon="edit">编辑</el-button>
<el-button v-auth="permissions.delDb" :disabled="selectionData.length < 1" @click="deleteDb()" type="danger"
icon="delete">删除</el-button>
</template>
@@ -262,7 +262,7 @@
</template>
<script lang='ts' setup>
import { toRefs, reactive, computed, onMounted, defineAsyncComponent } from 'vue';
import { ref, toRefs, reactive, computed, onMounted, defineAsyncComponent } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { formatByteSize } from '@/common/utils/format';
import { dbApi } from './api';
@@ -286,6 +286,8 @@ const permissions = {
delDb: 'db:del',
}
const pageTableRef: any = ref(null)
const state = reactive({
row: {},
dbId: 0,
@@ -294,7 +296,7 @@ const state = reactive({
/**
* 选中的数据
*/
chooseData: null as any,
selectionData: [],
/**
* 查询条件
*/
@@ -398,7 +400,7 @@ const {
dbId,
db,
tags,
chooseData,
selectionData,
query,
datas,
total,
@@ -443,14 +445,19 @@ const filterTableInfos = computed(() => {
});
const search = async () => {
let res: any = await dbApi.dbs.request(state.query);
// 切割数据库
res.list.forEach((e: any) => {
e.popoverSelectDbVisible = false;
e.dbs = e.database.split(' ');
});
state.datas = res.list;
state.total = res.total;
try {
pageTableRef.value.loading(true);
let res: any = await dbApi.dbs.request(state.query);
// 切割数据库
res.list.forEach((e: any) => {
e.popoverSelectDbVisible = false;
e.dbs = e.database.split(' ');
});
state.datas = res.list;
state.total = res.total;
} finally {
pageTableRef.value.loading(false);
}
};
const showInfo = (info: any) => {
@@ -467,27 +474,25 @@ const editDb = async (isAdd = false) => {
state.dbEditDialog.data = null;
state.dbEditDialog.title = '新增数据库资源';
} else {
state.dbEditDialog.data = state.chooseData;
state.dbEditDialog.data = state.selectionData[0];
state.dbEditDialog.title = '修改数据库资源';
}
state.dbEditDialog.visible = true;
};
const valChange = () => {
state.chooseData = null;
search();
};
const deleteDb = async (id: number) => {
const deleteDb = async () => {
try {
await ElMessageBox.confirm(`确定删除库?`, '提示', {
await ElMessageBox.confirm(`确定删除【${state.selectionData.map((x: any) => x.name).join(", ")}】库?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
await dbApi.deleteDb.request({ id });
await dbApi.deleteDb.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
ElMessage.success('删除成功');
state.chooseData = null;
search();
} catch (err) { }
};
@@ -626,7 +631,7 @@ const closeTableInfo = () => {
const showColumns = async (row: any) => {
state.chooseTableName = row.tableName;
state.columnDialog.columns = await dbApi.columnMetadata.request({
id: state.chooseData.id,
id: state.dbId,
db: state.db,
tableName: row.tableName,
});
@@ -637,7 +642,7 @@ const showColumns = async (row: any) => {
const showTableIndex = async (row: any) => {
state.chooseTableName = row.tableName;
state.indexDialog.indexs = await dbApi.tableIndex.request({
id: state.chooseData.id,
id: state.dbId,
db: state.db,
tableName: row.tableName,
});
@@ -648,7 +653,7 @@ const showTableIndex = async (row: any) => {
const showCreateDdl = async (row: any) => {
state.chooseTableName = row.tableName;
const res = await dbApi.tableDdl.request({
id: state.chooseData.id,
id: state.dbId,
db: state.db,
tableName: row.tableName,
});
@@ -669,10 +674,10 @@ const dropTable = async (row: any) => {
});
SqlExecBox({
sql: `DROP TABLE ${tableName}`,
dbId: state.chooseData.id,
dbId: state.dbId,
db: state.db,
runSuccessCallback: async () => {
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: state.chooseData.id, db: state.db });
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: state.dbId, db: state.db });
},
});
} catch (err) { }
@@ -708,12 +713,12 @@ const openEditTable = async (row: any) => {
if (row.tableName) {
state.tableCreateDialog.title = '修改表'
let indexs = await dbApi.tableIndex.request({
id: state.chooseData.id,
id: state.dbId,
db: state.db,
tableName: row.tableName,
});
let columns = await dbApi.columnMetadata.request({
id: state.chooseData.id,
id: state.dbId,
db: state.db,
tableName: row.tableName,
});

View File

@@ -6,11 +6,12 @@
</el-link>
<el-divider direction="vertical" border-style="dashed" />
<el-popover placement="bottom" title="表格字段配置" width="auto" trigger="click">
<el-popover popper-style="max-height: 550px; overflow: auto; max-width: 450px" placement="bottom"
width="auto" title="表格字段配置" trigger="click">
<div v-for="(item, index) in columns" :key="index">
<el-checkbox v-model="item.show"
:label="`${!item.columnComment ? item.columnName : item.columnName + ' [' + item.columnComment + ']'}`"
:true-label="true" :false-label="false" />
:true-label="true" :false-label="false" size="small" />
</div>
<template #reference>
<el-link icon="Operation" size="small" :underline="false"></el-link>

View File

@@ -7,7 +7,7 @@
</el-button>
</div>
</div>
<el-table :data="fileTable" stripe style="width: 100%">
<el-table :data="fileTable" stripe style="width: 100%" v-loading="loading">
<el-table-column prop="name" label="名称" width>
<template #default="scope">
<el-input v-model="scope.row.name" size="small" :disabled="scope.row.id != null" clearable>
@@ -51,8 +51,8 @@
<el-progress v-if="uploadProgressShow" style="width: 90%; margin-left: 20px" :text-inside="true"
:stroke-width="20" :percentage="progressNum" />
<div style="height: 45vh; overflow: auto">
<el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode"
:props="treeProps" lazy node-key="id" :expand-on-click-node="true">
<el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode" :props="treeProps"
lazy node-key="id" :expand-on-click-node="true">
<template #default="{ node, data }">
<span class="custom-tree-node">
<el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
@@ -80,8 +80,7 @@
</el-dropdown-item>
<span v-auth="'machine:file:write'">
<el-dropdown-item @click="showCreateFileDialog(node)"
v-if="data.type == 'd'">
<el-dropdown-item @click="showCreateFileDialog(node)" v-if="data.type == 'd'">
<el-link type="primary" icon="document" :underline="false"
style="margin-left: 2px">新建</el-link>
</el-dropdown-item>
@@ -148,8 +147,8 @@
</template>
</el-dialog>
<el-dialog :destroy-on-close="true" :title="fileContent.dialogTitle" v-model="fileContent.contentVisible" :close-on-click-modal="false"
top="5vh" width="70%">
<el-dialog :destroy-on-close="true" :title="fileContent.dialogTitle" v-model="fileContent.contentVisible"
:close-on-click-modal="false" top="5vh" width="70%">
<div>
<monaco-editor :can-change-mode="true" v-model="fileContent.content" :language="fileContent.type" />
</div>
@@ -206,6 +205,7 @@ const state = reactive({
pageNum: 1,
pageSize: 8,
},
loading: false,
form: {
id: null,
type: null,
@@ -250,6 +250,7 @@ const state = reactive({
const {
dialogVisible,
loading,
query,
total,
fileTable,
@@ -261,17 +262,22 @@ const {
} = toRefs(state)
watch(props, async (newValue) => {
state.dialogVisible = newValue.visible;
if (newValue.machineId && newValue.visible) {
await getFiles();
}
state.dialogVisible = newValue.visible;
});
const getFiles = async () => {
state.query.id = props.machineId as any;
const res = await files.request(state.query);
state.fileTable = res.list;
state.total = res.total;
try {
state.loading = true;
state.query.id = props.machineId as any;
const res = await files.request(state.query);
state.fileTable = res.list;
state.total = res.total;
} finally {
state.loading = false;
}
};
const handlePageChange = (curPage: number) => {
@@ -589,6 +595,4 @@ const formatFileSize = (size: any) => {
return '-';
};
</script>
<style lang="scss">
</style>
<style lang="scss"></style>

View File

@@ -1,7 +1,7 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="params" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="data.list" :columns="state.columns" :total="data.total"
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="params" :show-selection="true"
v-model:selection-data="state.selectionData" :data="data.list" :columns="state.columns" :total="data.total"
v-model:page-size="params.pageSize" v-model:page-num="params.pageNum" @pageChange="search()">
<template #tagPathSelect>
@@ -14,9 +14,9 @@
<template #queryRight>
<el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加
</el-button>
<el-button v-auth="'machine:update'" type="primary" icon="edit" :disabled="!chooseData"
@click="openFormDialog(chooseData)" plain>编辑</el-button>
<el-button v-auth="'machine:del'" :disabled="!chooseData" @click="deleteMachine(chooseData.id)"
<el-button v-auth="'machine:update'" type="primary" icon="edit" :disabled="selectionData.length != 1"
@click="openFormDialog(selectionData)" plain>编辑</el-button>
<el-button v-auth="'machine:del'" :disabled="selectionData.length < 1" @click="deleteMachine()"
type="danger" icon="delete">删除</el-button>
</template>
@@ -146,7 +146,7 @@
</template>
<script lang="ts" setup>
import { toRefs, reactive, onMounted, defineAsyncComponent } from 'vue';
import { ref, toRefs, reactive, onMounted, defineAsyncComponent } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { machineApi } from './api';
@@ -165,6 +165,8 @@ const MachineRec = defineAsyncComponent(() => import('./MachineRec.vue'));
const ProcessList = defineAsyncComponent(() => import('./ProcessList.vue'));
const router = useRouter();
const pageTableRef: any = ref(null)
const state = reactive({
tags: [] as any,
params: {
@@ -198,7 +200,7 @@ const state = reactive({
data: null as any,
},
// 当前选中数据
chooseData: null as any,
selectionData: [],
serviceDialog: {
visible: false,
machineId: 0,
@@ -236,7 +238,7 @@ const {
params,
data,
infoDialog,
chooseData,
selectionData,
serviceDialog,
processDialog,
fileDialog,
@@ -278,7 +280,7 @@ const getTags = async () => {
const openFormDialog = async (machine: any) => {
let dialogTitle;
if (machine) {
state.machineEditDialog.data = state.chooseData as any;
state.machineEditDialog.data = state.selectionData[0];
dialogTitle = '编辑机器';
} else {
state.machineEditDialog.data = null;
@@ -289,16 +291,15 @@ const openFormDialog = async (machine: any) => {
state.machineEditDialog.visible = true;
};
const deleteMachine = async (id: number) => {
const deleteMachine = async () => {
try {
await ElMessageBox.confirm(`确定删除机器信息? 该操作将同时删除脚本及文件配置信息`, '提示', {
await ElMessageBox.confirm(`确定删除${state.selectionData.map((x: any) => x.name).join(", ")}机器信息? 该操作将同时删除脚本及文件配置信息`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
await machineApi.del.request({ id });
await machineApi.del.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
ElMessage.success('操作成功');
state.chooseData = null;
search();
} catch (err) { }
};
@@ -329,19 +330,23 @@ const showMachineStats = async (machine: any) => {
};
const submitSuccess = () => {
state.chooseData = null;
search();
};
const showFileManage = (chooseData: any) => {
const showFileManage = (selectionData: any) => {
state.fileDialog.visible = true;
state.fileDialog.machineId = chooseData.id;
state.fileDialog.title = `${chooseData.name} => ${chooseData.ip}`;
state.fileDialog.machineId = selectionData.id;
state.fileDialog.title = `${selectionData.name} => ${selectionData.ip}`;
};
const search = async () => {
const res = await machineApi.list.request(state.params);
state.data = res;
try {
pageTableRef.value.loading(true);
const res = await machineApi.list.request(state.params);
state.data = res;
} finally {
pageTableRef.value.loading(false);
}
};
const showInfo = (info: any) => {

View File

@@ -10,8 +10,8 @@
</el-select>
</div>
<div style="float: right">
<el-button @click="editScript(currentData)" :disabled="currentId == null" type="primary"
icon="tickets" size="small" plain>查看</el-button>
<el-button @click="editScript(currentData)" :disabled="currentId == null" type="primary" icon="tickets"
size="small" plain>查看</el-button>
<el-button v-auth="'machine:script:save'" type="primary" @click="editScript(null)" icon="plus"
size="small" plain>添加</el-button>
<el-button v-auth="'machine:script:del'" :disabled="currentId == null" type="danger"
@@ -19,7 +19,8 @@
</div>
</div>
<el-table :data="scriptTable" @current-change="choose" stripe border size="small" style="width: 100%">
<el-table :data="scriptTable" @current-change="choose" stripe border size="small" v-loading="loading"
style="width: 100%">
<el-table-column label="选择" width="55px">
<template #default="scope">
<el-radio v-model="currentId" :label="scope.row.id">
@@ -39,8 +40,8 @@
<el-button v-if="scope.row.id == null" type="success" icon="el-icon-success" size="small" plain>
确定</el-button>
<el-button v-auth="'machine:script:run'" v-if="scope.row.id != null"
@click="runScript(scope.row)" type="primary" icon="video-play" size="small" plain>执行
<el-button v-auth="'machine:script:run'" v-if="scope.row.id != null" @click="runScript(scope.row)"
type="primary" icon="video-play" size="small" plain>执行
</el-button>
</template>
</el-table-column>
@@ -54,8 +55,8 @@
<el-dialog title="脚本参数" v-model="scriptParamsDialog.visible" width="400px">
<el-form ref="paramsForm" :model="scriptParamsDialog.params" label-width="70px" size="small">
<el-form-item v-for="item in scriptParamsDialog.paramsFormItem as any" :key="item.name"
:prop="item.model" :label="item.name" required>
<el-form-item v-for="item in scriptParamsDialog.paramsFormItem as any" :key="item.name" :prop="item.model"
:label="item.name" required>
<el-input v-if="!item.options" v-model="scriptParamsDialog.params[item.model]"
:placeholder="item.placeholder" autocomplete="off" clearable></el-input>
<el-select v-else v-model="scriptParamsDialog.params[item.model]" :placeholder="item.placeholder"
@@ -80,8 +81,7 @@
<el-dialog v-if="terminalDialog.visible" title="终端" v-model="terminalDialog.visible" width="80%"
:close-on-click-modal="false" :modal="false" @close="closeTermnial">
<ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId"
height="560px" />
<ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId" height="560px" />
</el-dialog>
<script-edit v-model:visible="editDialog.visible" v-model:data="editDialog.data" :title="editDialog.title"
@@ -111,6 +111,7 @@ const state = reactive({
type: 0,
currentId: null,
currentData: null,
loading: false,
query: {
machineId: 0 as any,
pageNum: 1,
@@ -142,6 +143,7 @@ const state = reactive({
const {
dialogVisible,
loading,
type,
currentId,
currentData,
@@ -155,19 +157,24 @@ const {
} = toRefs(state)
watch(props, async (newValue) => {
state.dialogVisible = newValue.visible;
if (props.machineId && newValue.visible) {
await getScripts();
}
state.dialogVisible = newValue.visible;
});
const getScripts = async () => {
state.currentId = null;
state.currentData = null;
state.query.machineId = state.type == 0 ? props.machineId : 9999999;
const res = await machineApi.scripts.request(state.query);
state.scriptTable = res.list;
state.total = res.total;
try {
state.loading = true;
state.currentId = null;
state.currentData = null;
state.query.machineId = state.type == 0 ? props.machineId : 9999999;
const res = await machineApi.scripts.request(state.query);
state.scriptTable = res.list;
state.total = res.total;
} finally {
state.loading = false;
}
};
const handlePageChange = (curPage: number) => {

View File

@@ -1,14 +1,15 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="authcerts" :columns="state.columns" :total="total"
<page-table :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="selectionData" :data="authcerts" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #queryRight>
<el-button type="primary" icon="plus" @click="edit(false)">添加</el-button>
<el-button :disabled="!chooseData" @click="edit(chooseData)" type="primary" icon="edit">编辑
<el-button :disabled="selectionData.length !== 1" @click="edit(selectionData)" type="primary" icon="edit">编辑
</el-button>
<el-button :disabled="!chooseData" @click="deleteAc(chooseData)" type="danger" icon="delete">删除
<el-button :disabled="selectionData.length < 1" @click="deleteAc(selectionData)" type="danger"
icon="delete">删除
</el-button>
</template>
@@ -52,7 +53,7 @@ const state = reactive({
],
total: 0,
authcerts: [],
chooseData: null as any,
selectionData: [],
paramsDialog: {
visible: false,
config: null as any,
@@ -70,7 +71,7 @@ const {
query,
total,
authcerts,
chooseData,
selectionData,
editor,
} = toRefs(state)
@@ -86,13 +87,12 @@ const search = async () => {
const editChange = () => {
ElMessage.success('保存成功');
state.chooseData = null;
search();
};
const edit = (data: any) => {
if (data) {
state.editor.authcert = data;
state.editor.authcert = data[0];
} else {
state.editor.authcert = false;
}
@@ -102,14 +102,13 @@ const edit = (data: any) => {
const deleteAc = async (data: any) => {
try {
await ElMessageBox.confirm(`确定删除该授权凭证?`, '提示', {
await ElMessageBox.confirm(`确定删除该${data.map((x: any) => x.name).join(", ")}授权凭证?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
await authCertApi.delete.request({ id: data.id });
await authCertApi.delete.request({ id: data.map((x: any) => x.id).join(",") });
ElMessage.success('删除成功');
state.chooseData = null;
search();
} catch (err) { }

View File

@@ -1,7 +1,7 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="list" :columns="state.columns" :total="total"
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="selectionData" :data="list" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #tagPathSelect>
@@ -13,9 +13,10 @@
<template #queryRight>
<el-button type="primary" icon="plus" @click="editMongo(true)" plain>添加</el-button>
<el-button type="primary" icon="edit" :disabled="!chooseData" @click="editMongo(false)" plain>编辑
<el-button type="primary" icon="edit" :disabled="selectionData.length != 1" @click="editMongo(false)"
plain>编辑
</el-button>
<el-button type="danger" icon="delete" :disabled="!chooseData" @click="deleteMongo" plain>删除
<el-button type="danger" icon="delete" :disabled="selectionData.length < 1" @click="deleteMongo" plain>删除
</el-button>
</template>
@@ -169,7 +170,7 @@
<script lang="ts" setup>
import { mongoApi } from './api';
import { toRefs, reactive, onMounted } from 'vue';
import { ref, toRefs, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { tagApi } from '../tag/api';
import MongoEdit from './MongoEdit.vue';
@@ -178,6 +179,8 @@ import TagInfo from '../component/TagInfo.vue';
import PageTable from '@/components/pagetable/PageTable.vue'
import { TableColumn, TableQuery } from '@/components/pagetable';
const pageTableRef: any = ref(null)
const state = reactive({
tags: [],
dbOps: {
@@ -186,7 +189,7 @@ const state = reactive({
},
list: [],
total: 0,
chooseData: null as any,
selectionData: [],
query: {
pageNum: 1,
pageSize: 10,
@@ -241,7 +244,7 @@ const {
tags,
list,
total,
chooseData,
selectionData,
query,
mongoEditDialog,
databaseDialog,
@@ -264,7 +267,7 @@ const showDatabases = async (id: number) => {
const showDatabaseStats = async (dbName: string) => {
state.databaseDialog.statsDialog.data = await mongoApi.runCommand.request({
id: state.chooseData.id,
id: state.dbOps.dbId,
database: dbName,
command: {
dbStats: 1,
@@ -283,7 +286,7 @@ const showCollections = async (database: string) => {
};
const setCollections = async (database: string) => {
const res = await mongoApi.collections.request({ id: state.chooseData.id, database });
const res = await mongoApi.collections.request({ id: state.dbOps.dbId, database });
const collections = [] as any;
for (let r of res) {
collections.push({ name: r });
@@ -296,7 +299,7 @@ const setCollections = async (database: string) => {
*/
const showCollectionStats = async (collection: string) => {
state.collectionsDialog.statsDialog.data = await mongoApi.runCommand.request({
id: state.chooseData.id,
id: state.dbOps.dbId,
database: state.collectionsDialog.database,
command: {
collStats: collection,
@@ -311,7 +314,7 @@ const showCollectionStats = async (collection: string) => {
*/
const onDeleteCollection = async (collection: string) => {
await mongoApi.runCommand.request({
id: state.chooseData.id,
id: state.dbOps.dbId,
database: state.collectionsDialog.database,
command: {
drop: collection,
@@ -328,7 +331,7 @@ const showCreateCollectionDialog = () => {
const onCreateCollection = async () => {
const form = state.createCollectionDialog.form;
await mongoApi.runCommand.request({
id: state.chooseData.id,
id: state.dbOps.dbId,
database: state.collectionsDialog.database,
command: {
create: form.name,
@@ -342,22 +345,26 @@ const onCreateCollection = async () => {
const deleteMongo = async () => {
try {
await ElMessageBox.confirm(`确定删除mongo?`, '提示', {
await ElMessageBox.confirm(`确定删除${state.selectionData.map((x: any) => x.name).join(", ")}mongo信息?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
await mongoApi.deleteMongo.request({ id: state.chooseData.id });
await mongoApi.deleteMongo.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
ElMessage.success('删除成功');
state.chooseData = null;
search();
} catch (err) { }
};
const search = async () => {
const res = await mongoApi.mongoList.request(state.query);
state.list = res.list;
state.total = res.total;
try {
pageTableRef.value.loading(true);
const res = await mongoApi.mongoList.request(state.query);
state.list = res.list;
state.total = res.total;
} finally {
pageTableRef.value.loading(false);
}
};
const getTags = async () => {
@@ -369,14 +376,13 @@ const editMongo = async (isAdd = false) => {
state.mongoEditDialog.data = null;
state.mongoEditDialog.title = '新增mongo';
} else {
state.mongoEditDialog.data = state.chooseData;
state.mongoEditDialog.data = state.selectionData[0];
state.mongoEditDialog.title = '修改mongo';
}
state.mongoEditDialog.visible = true;
};
const valChange = () => {
state.chooseData = null;
search();
};

View File

@@ -191,7 +191,7 @@ const setHeight = () => {
const instMap: Map<string, any[]> = new Map();
const getInsts = async () => {
const res = await redisApi.redisList.request({});
const res = await redisApi.redisList.request({ pageNum: 1, pageSize: 1000 });
if (!res.total) return
for (const redisInfo of res.list) {
const tagPath = redisInfo.tagPath;

View File

@@ -1,7 +1,7 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="redisTable" :columns="state.columns" :total="total"
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="selectionData" :data="redisTable" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #tagPathSelect>
@@ -13,9 +13,10 @@
<template #queryRight>
<el-button type="primary" icon="plus" @click="editRedis(true)" plain>添加</el-button>
<el-button type="primary" icon="edit" :disabled="!chooseData" @click="editRedis(false)" plain>编辑
<el-button type="primary" icon="edit" :disabled="selectionData.length != 1" @click="editRedis(false)"
plain>编辑
</el-button>
<el-button type="danger" icon="delete" :disabled="!chooseData" @click="deleteRedis" plain>删除
<el-button type="danger" icon="delete" :disabled="selectionData.length < 1" @click="deleteRedis" plain>删除
</el-button>
</template>
@@ -142,7 +143,7 @@
<script lang="ts" setup>
import Info from './Info.vue';
import { redisApi } from './api';
import { toRefs, reactive, onMounted } from 'vue';
import { ref, toRefs, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { tagApi } from '../tag/api';
import RedisEdit from './RedisEdit.vue';
@@ -151,11 +152,13 @@ import TagInfo from '../component/TagInfo.vue';
import PageTable from '@/components/pagetable/PageTable.vue'
import { TableColumn, TableQuery } from '@/components/pagetable';
const pageTableRef: any = ref(null)
const state = reactive({
tags: [],
redisTable: [],
total: 0,
chooseData: null as any,
selectionData: [],
query: {
tagPath: null,
pageNum: 1,
@@ -204,7 +207,7 @@ const {
tags,
redisTable,
total,
chooseData,
selectionData,
query,
detailDialog,
clusterInfoDialog,
@@ -224,14 +227,13 @@ const showDetail = (detail: any) => {
const deleteRedis = async () => {
try {
await ElMessageBox.confirm(`确定删除该redis?`, '提示', {
await ElMessageBox.confirm(`确定删除该${state.selectionData.map((x: any) => x.name).join(", ")}redis信息?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
await redisApi.delRedis.request({ id: state.chooseData.id });
await redisApi.delRedis.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
ElMessage.success('删除成功');
state.chooseData = null;
search();
} catch (err) { }
};
@@ -256,9 +258,15 @@ const onShowClusterInfo = async (redis: any) => {
};
const search = async () => {
const res = await redisApi.redisList.request(state.query);
state.redisTable = res.list;
state.total = res.total;
try {
pageTableRef.value.loading(true);
console.log(state.query);
const res = await redisApi.redisList.request(state.query);
state.redisTable = res.list;
state.total = res.total;
} finally {
pageTableRef.value.loading(false);
}
};
const getTags = async () => {
@@ -270,14 +278,13 @@ const editRedis = async (isAdd = false) => {
state.redisEditDialog.data = null;
state.redisEditDialog.title = '新增redis';
} else {
state.redisEditDialog.data = state.chooseData;
state.redisEditDialog.data = state.selectionData[0];
state.redisEditDialog.title = '修改redis';
}
state.redisEditDialog.visible = true;
};
const valChange = () => {
state.chooseData = null;
search();
};
</script>

View File

@@ -1,12 +1,12 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="data" :columns="state.columns" :total="total"
<page-table :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="selectionData" :data="data" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #queryRight>
<el-button v-auth="'team:save'" type="primary" icon="plus" @click="showSaveTeamDialog(false)">添加</el-button>
<el-button v-auth="'team:del'" :disabled="!chooseData" @click="deleteTeam(chooseData)" type="danger"
<el-button v-auth="'team:del'" :disabled="selectionData.length < 1" @click="deleteTeam()" type="danger"
icon="delete">删除</el-button>
</template>
@@ -167,7 +167,7 @@ const state = reactive({
],
total: 0,
data: [],
chooseData: null as any,
selectionData: [],
showMemDialog: {
visible: false,
chooseId: 0,
@@ -209,7 +209,7 @@ const {
addTeamDialog,
total,
data,
chooseData,
selectionData,
showMemDialog,
showTagDialog,
} = toRefs(state)
@@ -252,15 +252,14 @@ const cancelSaveTeam = () => {
teamForm.value.resetFields();
};
const deleteTeam = (data: any) => {
ElMessageBox.confirm(`此操作将删除 [${data.name}], 是否继续?`, '提示', {
const deleteTeam = () => {
ElMessageBox.confirm(`此操作将删除${state.selectionData.map((x: any) => x.name).join(", ")}】团队信息, 是否继续?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(async () => {
await tagApi.delTeam.request({ id: data.id });
await tagApi.delTeam.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
ElMessage.success('删除成功!');
state.chooseData = null;
search();
});
};
@@ -315,7 +314,7 @@ const showAddMemberDialog = () => {
const addMember = async () => {
const memForm = state.showMemDialog.memForm;
memForm.teamId = state.chooseData.id;
memForm.teamId = (state.selectionData[0] as any).id;
notBlank(memForm.accountIds, '请先选择账号');
await tagApi.saveTeamMem.request(memForm);

View File

@@ -1,16 +1,16 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="datas" :columns="state.columns" :total="total"
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="selectionData" :data="datas" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #queryRight>
<el-button v-auth="'account:add'" type="primary" icon="plus" @click="editAccount(true)">添加</el-button>
<el-button v-auth="'account:add'" :disabled="state.chooseData == null" @click="editAccount(false)"
<el-button v-auth="'account:add'" :disabled="state.selectionData.length != 1" @click="editAccount(false)"
type="primary" icon="edit">编辑</el-button>
<el-button v-auth="'account:saveRoles'" :disabled="state.chooseData == null" @click="showRoleEdit()"
<el-button v-auth="'account:saveRoles'" :disabled="state.selectionData.length != 1" @click="showRoleEdit()"
type="success" icon="setting">角色分配</el-button>
<el-button v-auth="'account:del'" :disabled="state.chooseData == null" @click="deleteAccount()"
<el-button v-auth="'account:del'" :disabled="state.selectionData.length < 1" @click="deleteAccount()"
type="danger" icon="delete">删除</el-button>
</template>
@@ -70,7 +70,7 @@
</template>
<script lang='ts' setup>
import { toRefs, reactive, onMounted } from 'vue';
import { ref, toRefs, reactive, onMounted } from 'vue';
import RoleEdit from './RoleEdit.vue';
import AccountEdit from './AccountEdit.vue';
import enums from '../enums';
@@ -80,11 +80,13 @@ import { dateFormat } from '@/common/utils/date';
import PageTable from '@/components/pagetable/PageTable.vue'
import { TableColumn, TableQuery } from '@/components/pagetable';
const pageTableRef: any = ref(null)
const state = reactive({
/**
* 选中的数据
*/
chooseData: null as any,
selectionData: [],
/**
* 查询条件
*/
@@ -136,6 +138,7 @@ const state = reactive({
});
const {
selectionData,
query,
datas,
total,
@@ -150,9 +153,14 @@ onMounted(() => {
});
const search = async () => {
let res: any = await accountApi.list.request(state.query);
state.datas = res.list;
state.total = res.total;
try {
pageTableRef.value.loading(true);
let res: any = await accountApi.list.request(state.query);
state.datas = res.list;
state.total = res.total;
} finally {
pageTableRef.value.loading(false);
}
};
const showResources = async (row: any) => {
@@ -194,24 +202,16 @@ const resetOtpSecret = async (row: any) => {
row.otpSecret = "-";
};
const handlePageChange = (curPage: number) => {
state.query.pageNum = curPage;
search();
};
const showRoleEdit = () => {
if (!state.chooseData) {
ElMessage.error('请选择账号');
}
state.roleDialog.visible = true;
state.roleDialog.account = state.chooseData;
state.roleDialog.account = state.selectionData[0];
};
const editAccount = (isAdd = false) => {
if (isAdd) {
state.accountDialog.data = null;
} else {
state.accountDialog.data = state.chooseData;
state.accountDialog.data = state.selectionData[0];
}
state.accountDialog.visible = true;
};
@@ -229,14 +229,13 @@ const valChange = () => {
const deleteAccount = async () => {
try {
await ElMessageBox.confirm(`确定删除账号?`, '提示', {
await ElMessageBox.confirm(`确定删除${state.selectionData.map((x: any) => x.name).join(", ")}】的账号?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
await accountApi.del.request({ id: state.chooseData.id });
await accountApi.del.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
ElMessage.success('删除成功');
state.chooseData = null;
search();
} catch (err) { }
};

View File

@@ -1,13 +1,12 @@
<template>
<div>
<page-table :show-choose-column="true" v-model:choose-data="state.chooseData" :data="configs"
:columns="state.columns" :total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum"
@pageChange="search()">
<page-table :show-selection="true" v-model:selection-data="selectionData" :data="configs" :columns="state.columns"
:total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #queryRight>
<el-button v-auth="'config:save'" type="primary" icon="plus" @click="editConfig(false)">添加</el-button>
<el-button v-auth="'config:save'" :disabled="chooseData == null" @click="editConfig(chooseData)"
type="primary" icon="edit">编辑
<el-button v-auth="'config:save'" :disabled="state.selectionData.length != 1"
@click="editConfig(state.selectionData[0])" type="primary" icon="edit">编辑
</el-button>
</template>
@@ -81,7 +80,7 @@ const state = reactive({
],
total: 0,
configs: [],
chooseData: null as any,
selectionData: [],
paramsDialog: {
visible: false,
config: null as any,
@@ -99,7 +98,7 @@ const {
query,
total,
configs,
chooseData,
selectionData,
paramsDialog,
configEdit,
} = toRefs(state)
@@ -187,7 +186,6 @@ const hasParam = (paramKey: string, paramItems: any) => {
const configEditChange = () => {
ElMessage.success('保存成功');
state.chooseData = null;
search();
};

View File

@@ -1,17 +1,17 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
v-model:choose-data="state.chooseData" :data="roles" :columns="state.columns" :total="total"
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
v-model:selection-data="selectionData" :data="roles" :columns="state.columns" :total="total"
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<template #queryRight>
<el-button v-auth="'role:add'" type="primary" icon="plus" @click="editRole(false)">添加</el-button>
<el-button v-auth="'role:update'" :disabled="chooseData == null" @click="editRole(chooseData)"
<el-button v-auth="'role:update'" :disabled="selectionData.length != 1" @click="editRole(selectionData)"
type="primary" icon="edit">编辑</el-button>
<el-button v-auth="'role:saveResources'" :disabled="chooseData == null" @click="editResource(chooseData)"
type="success" icon="setting">分配菜单&权限</el-button>
<el-button v-auth="'role:del'" :disabled="chooseData == null" @click="deleteRole(chooseData)" type="danger"
icon="delete">删除</el-button>
<el-button v-auth="'role:saveResources'" :disabled="selectionData.length != 1"
@click="editResource(selectionData)" type="success" icon="setting">分配菜单&权限</el-button>
<el-button v-auth="'role:del'" :disabled="selectionData.length < 1" @click="deleteRole(selectionData)"
type="danger" icon="delete">删除</el-button>
</template>
<template #status="{ data }">
@@ -35,7 +35,7 @@
</template>
<script lang="ts" setup>
import { toRefs, reactive, onMounted } from 'vue';
import { ref, toRefs, reactive, onMounted } from 'vue';
import RoleEdit from './RoleEdit.vue';
import ResourceEdit from './ResourceEdit.vue';
import ShowResource from './ShowResource.vue';
@@ -44,6 +44,8 @@ import { ElMessage, ElMessageBox } from 'element-plus';
import PageTable from '@/components/pagetable/PageTable.vue'
import { TableColumn, TableQuery } from '@/components/pagetable';
const pageTableRef: any = ref(null)
const state = reactive({
query: {
pageNum: 1,
@@ -66,7 +68,7 @@ const state = reactive({
],
total: 0,
roles: [],
chooseData: null as any,
selectionData: [],
resourceDialog: {
visible: false,
role: {},
@@ -89,7 +91,7 @@ const {
query,
total,
roles,
chooseData,
selectionData,
resourceDialog,
roleEditDialog,
showResourceDialog,
@@ -100,20 +102,24 @@ onMounted(() => {
});
const search = async () => {
let res = await roleApi.list.request(state.query);
state.roles = res.list;
state.total = res.total;
try {
pageTableRef.value.loading(true);
let res = await roleApi.list.request(state.query);
state.roles = res.list;
state.total = res.total;
} finally {
pageTableRef.value.loading(false);
}
};
const roleEditChange = () => {
ElMessage.success('修改成功!');
state.chooseData = null;
search();
};
const editRole = (data: any) => {
if (data) {
state.roleEditDialog.role = data;
state.roleEditDialog.role = data[0];
} else {
state.roleEditDialog.role = false;
}
@@ -124,7 +130,7 @@ const editRole = (data: any) => {
const deleteRole = async (data: any) => {
try {
await ElMessageBox.confirm(
`此操作将删除 [${data.name}] 该角色,以及与该角色有关的账号角色关联信息和资源角色关联信息, 是否继续?`,
`此操作将删除${data.map((x: any) => x.name).join(", ")}该角色,以及与该角色有关的账号角色关联信息和资源角色关联信息, 是否继续?`,
'提示',
{
confirmButtonText: '确定',
@@ -133,7 +139,7 @@ const deleteRole = async (data: any) => {
}
);
await roleApi.del.request({
id: data.id,
id: data.map((x: any) => x.id).join(","),
});
ElMessage.success('删除成功!');
search();

View File

@@ -1,7 +1,8 @@
<template>
<div>
<page-table :query="state.queryConfig" v-model:query-form="query" :data="logs" :columns="state.columns"
:total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :data="logs"
:columns="state.columns" :total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum"
@pageChange="search()">
<template #selectAccount>
<el-select remote :remote-method="getAccount" v-model="query.creatorId" filterable placeholder="请输入并选择账号"
@@ -20,11 +21,13 @@
</template>
<script lang="ts" setup>
import { toRefs, reactive, onMounted } from 'vue';
import { ref, toRefs, reactive, onMounted } from 'vue';
import { logApi, accountApi } from '../api';
import PageTable from '@/components/pagetable/PageTable.vue'
import { TableColumn, TableQuery } from '@/components/pagetable';
const pageTableRef: any = ref(null);
const state = reactive({
query: {
type: null,
@@ -64,9 +67,14 @@ onMounted(() => {
});
const search = async () => {
let res = await logApi.list.request(state.query);
state.logs = res.list;
state.total = res.total;
try {
pageTableRef.value.loading(true);
let res = await logApi.list.request(state.query);
state.logs = res.list;
state.total = res.total;
} finally {
pageTableRef.value.loading(false);
}
};
const getAccount = (username: any) => {

View File

@@ -11,6 +11,7 @@ import (
tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
@@ -40,7 +41,7 @@ func (d *Db) Dbs(rc *req.Ctx) {
// 不存在可访问标签id即没有可操作数据
tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
if len(tagIds) == 0 {
rc.ResData = model.EmptyPageResult()
rc.ResData = model.EmptyPageResult[any]()
return
}
condition.TagIds = tagIds
@@ -96,10 +97,18 @@ func (d *Db) GetDatabaseNames(rc *req.Ctx) {
}
func (d *Db) DeleteDb(rc *req.Ctx) {
dbId := GetDbId(rc.GinCtx)
d.DbApp.Delete(dbId)
// 删除该库的sql执行记录
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
idsStr := ginx.PathParam(rc.GinCtx, "dbId")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
dbId := uint64(value)
d.DbApp.Delete(dbId)
// 删除该库的sql执行记录
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
}
}
func (d *Db) TableInfos(rc *req.Ctx) {
@@ -381,21 +390,21 @@ func (d *Db) SaveSql(rc *req.Ctx) {
dbId := GetDbId(g)
// 判断dbId是否存在
err := model.GetById(new(entity.Db), dbId)
err := gormx.GetById(new(entity.Db), dbId)
biz.ErrIsNil(err, "该数据库信息不存在")
// 获取用于是否有该dbsql的保存记录有则更改否则新增
dbSql := &entity.DbSql{Type: dbSqlForm.Type, DbId: dbId, Name: dbSqlForm.Name, Db: dbSqlForm.Db}
dbSql.CreatorId = account.Id
e := model.GetBy(dbSql)
e := gormx.GetBy(dbSql)
dbSql.SetBaseInfo(account)
// 更新sql信息
dbSql.Sql = dbSqlForm.Sql
if e == nil {
model.UpdateById(dbSql)
gormx.UpdateById(dbSql)
} else {
model.Insert(dbSql)
gormx.Insert(dbSql)
}
}
@@ -406,7 +415,7 @@ func (d *Db) GetSqlNames(rc *req.Ctx) {
dbSql := &entity.DbSql{Type: 1, DbId: id, Db: db}
dbSql.CreatorId = rc.LoginAccount.Id
var sqls []entity.DbSql
model.ListBy(dbSql, &sqls, "id", "name")
gormx.ListBy(dbSql, &sqls, "id", "name")
rc.ResData = sqls
}
@@ -418,7 +427,7 @@ func (d *Db) DeleteSql(rc *req.Ctx) {
dbSql.Name = rc.GinCtx.Query("name")
dbSql.Db = rc.GinCtx.Query("db")
model.DeleteByCondition(dbSql)
gormx.DeleteByCondition(dbSql)
}
@@ -430,7 +439,7 @@ func (d *Db) GetSql(rc *req.Ctx) {
dbSql.CreatorId = rc.LoginAccount.Id
dbSql.Name = rc.GinCtx.Query("name")
e := model.GetBy(dbSql)
e := gormx.GetBy(dbSql)
if e != nil {
return
}

View File

@@ -21,7 +21,7 @@ import (
type Db interface {
// 分页获取
GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Count(condition *entity.DbQuery) int64
@@ -58,7 +58,7 @@ type dbAppImpl struct {
}
// 分页获取数据库信息列表
func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -52,7 +52,7 @@ type DbSqlExec interface {
DeleteBy(condition *entity.DbSqlExec)
// 分页获取
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
}
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
@@ -151,7 +151,7 @@ func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
d.dbSqlExecRepo.DeleteBy(condition)
}
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -7,7 +7,7 @@ import (
type Db interface {
// 分页获取机器信息列表
GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Count(condition *entity.DbQuery) int64

View File

@@ -11,5 +11,5 @@ type DbSqlExec interface {
DeleteBy(condition *entity.DbSqlExec)
// 分页获取
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
}

View File

@@ -1,13 +1,11 @@
package persistence
import (
"fmt"
"mayfly-go/internal/db/domain/entity"
"mayfly-go/internal/db/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils"
"strings"
)
type dbRepoImpl struct{}
@@ -17,27 +15,14 @@ func newDbRepo() repository.Db {
}
// 分页获取数据库信息列表
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
sql := "SELECT d.* FROM t_db d WHERE 1 = 1 "
values := make([]any, 0)
if condition.Host != "" {
sql = sql + " AND d.host LIKE ?"
values = append(values, "%"+condition.Host+"%")
}
if condition.Database != "" {
sql = sql + " AND d.database LIKE ?"
values = append(values, "%"+condition.Database+"%")
}
if len(condition.TagIds) > 0 {
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
}
if condition.TagPathLike != "" {
sql = sql + " AND d.tag_path LIKE ?"
values = append(values, "%"+condition.TagPathLike+"%")
}
sql = sql + " ORDER BY d.tag_path"
return model.GetPageBySql(sql, pageParam, toEntity, values...)
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(new(entity.Db)).
Like("host", condition.Host).
Like("database", condition.Database).
In("tag_id", condition.TagIds).
RLike("tag_path", condition.TagPathLike).
OrderByAsc("tag_path")
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
@@ -48,18 +33,18 @@ func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
if condition.TagId != 0 {
where["tag_id"] = condition.TagId
}
return model.CountByMap(new(entity.Db), where)
return gormx.CountByCond(new(entity.Db), where)
}
// 根据条件获取账号信息
func (d *dbRepoImpl) GetDb(condition *entity.Db, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
// 根据id获取
func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
db := new(entity.Db)
if err := model.GetById(db, id, cols...); err != nil {
if err := gormx.GetById(db, id, cols...); err != nil {
return nil
}
@@ -67,13 +52,13 @@ func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
}
func (d *dbRepoImpl) Insert(db *entity.Db) {
biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
biz.ErrIsNil(gormx.Insert(db), "新增数据库信息失败")
}
func (d *dbRepoImpl) Update(db *entity.Db) {
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
biz.ErrIsNil(gormx.UpdateById(db), "更新数据库信息失败")
}
func (d *dbRepoImpl) Delete(id uint64) {
model.DeleteById(new(entity.Db), id)
gormx.DeleteById(new(entity.Db), id)
}

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/db/domain/entity"
"mayfly-go/internal/db/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/model"
"mayfly-go/pkg/gormx"
)
type dbSqlRepoImpl struct{}
@@ -15,5 +15,5 @@ func newDbSqlRepo() repository.DbSql {
// 分页获取数据库信息列表
func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
biz.ErrIsNil(gormx.DeleteByCondition(condition), "删除sql失败")
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/db/domain/entity"
"mayfly-go/internal/db/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -14,14 +15,15 @@ func newDbSqlExecRepo() repository.DbSqlExec {
}
func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
model.Insert(dse)
gormx.Insert(dse)
}
func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
biz.ErrIsNil(gormx.DeleteByCondition(condition), "删除sql执行记录失败")
}
// 分页获取
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}

View File

@@ -5,9 +5,12 @@ import (
"mayfly-go/internal/machine/api/vo"
"mayfly-go/internal/machine/application"
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
"strconv"
"strings"
)
type AuthCert struct {
@@ -58,5 +61,13 @@ func (c *AuthCert) SaveAuthCert(rc *req.Ctx) {
}
func (c *AuthCert) Delete(rc *req.Ctx) {
c.AuthCertApp.DeleteById(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
idsStr := ginx.PathParam(rc.GinCtx, "id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
c.AuthCertApp.DeleteById(uint64(value))
}
}

View File

@@ -20,6 +20,7 @@ import (
"path"
"sort"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -40,19 +41,18 @@ func (m *Machine) Machines(rc *req.Ctx) {
// 不存在可访问标签id即没有可操作数据
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
if len(tagIds) == 0 {
rc.ResData = model.EmptyPageResult()
rc.ResData = model.EmptyPageResult[any]()
return
}
condition.TagIds = tagIds
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.MachineVO))
if res.Total == 0 {
rc.ResData = res
return
}
list := res.List.(*[]*vo.MachineVO)
for _, mv := range *list {
for _, mv := range *res.List {
mv.HasCli = machine.HasCli(mv.Id)
}
rc.ResData = res
@@ -99,9 +99,15 @@ func (m *Machine) ChangeStatus(rc *req.Ctx) {
}
func (m *Machine) DeleteMachine(rc *req.Ctx) {
id := uint64(ginx.PathParamInt(rc.GinCtx, "machineId"))
rc.ReqParam = id
m.MachineApp.Delete(id)
idsStr := ginx.PathParam(rc.GinCtx, "machineId")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
m.MachineApp.Delete(uint64(value))
}
}
// 关闭机器客户端

View File

@@ -8,7 +8,7 @@ import (
)
type AuthCert interface {
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Save(ac *entity.AuthCert)
@@ -29,7 +29,7 @@ type authCertAppImpl struct {
authCertRepo repository.AuthCert
}
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
}

View File

@@ -1,10 +1,12 @@
package application
import (
"mayfly-go/internal/machine/api/vo"
"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/gormx"
"mayfly-go/pkg/model"
"gorm.io/gorm"
@@ -30,7 +32,7 @@ type Machine interface {
GetById(id uint64, cols ...string) *entity.Machine
// 分页获取机器信息列表
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO]
// 获取机器连接
GetCli(id uint64) *machine.Cli
@@ -52,7 +54,7 @@ type machineAppImpl struct {
}
// 分页获取机器信息列表
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO] {
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
}
@@ -109,7 +111,7 @@ func (m *machineAppImpl) ChangeStatus(id uint64, status int8) {
func (m *machineAppImpl) Delete(id uint64) {
// 关闭连接
machine.DeleteCli(id)
model.Tx(
gormx.Tx(
func(db *gorm.DB) error {
// 删除machine表信息
return db.Delete(new(entity.Machine), "id = ?", id).Error

View File

@@ -8,6 +8,7 @@ import (
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/internal/machine/infrastructure/machine"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"os"
"strings"
@@ -17,7 +18,7 @@ import (
type MachineFile interface {
// 分页获取机器文件信息列表
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
// 根据条件获取
GetMachineFile(condition *entity.MachineFile, cols ...string) error
@@ -67,7 +68,7 @@ type machineFileAppImpl struct {
}
// 分页获取机器脚本信息列表
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}
@@ -86,9 +87,9 @@ func (m *machineFileAppImpl) Save(entity *entity.MachineFile) {
biz.NotNil(m.machineRepo.GetById(entity.MachineId, "Name"), "该机器不存在")
if entity.Id != 0 {
model.UpdateById(entity)
gormx.UpdateById(entity)
} else {
model.Insert(entity)
gormx.Insert(entity)
}
}

View File

@@ -4,12 +4,13 @@ import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
type MachineScript interface {
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
// 根据条件获取
GetMachineScript(condition *entity.MachineScript, cols ...string) error
@@ -40,7 +41,7 @@ const Common_Script_Machine_Id = 9999999
// machineScriptRepo: persistence.MachineScriptDao}
// 分页获取机器脚本信息列表
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return m.machineScriptRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}
@@ -62,9 +63,9 @@ func (m *machineScriptAppImpl) Save(entity *entity.MachineScript) {
}
if entity.Id != 0 {
model.UpdateById(entity)
gormx.UpdateById(entity)
} else {
model.Insert(entity)
gormx.Insert(entity)
}
}

View File

@@ -6,7 +6,7 @@ import (
)
type AuthCert interface {
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Insert(ac *entity.AuthCert)

View File

@@ -1,13 +1,14 @@
package repository
import (
"mayfly-go/internal/machine/api/vo"
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/pkg/model"
)
type Machine interface {
// 分页获取机器信息列表
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO]
Count(condition *entity.MachineQuery) int64

View File

@@ -7,7 +7,7 @@ import (
type MachineFile interface {
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
// 根据条件获取
GetMachineFile(condition *entity.MachineFile, cols ...string) error

View File

@@ -7,7 +7,7 @@ import (
type MachineScript interface {
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
// 根据条件获取
GetMachineScript(condition *entity.MachineScript, cols ...string) error

View File

@@ -6,7 +6,7 @@ import (
)
type MachineTaskConfig interface {
GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
// 根据条件获取
GetBy(condition *entity.MachineTaskConfig, cols ...string) error

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -13,21 +14,22 @@ func newAuthCertRepo() repository.AuthCert {
return new(authCertRepoImpl)
}
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity)
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *authCertRepoImpl) Insert(ac *entity.AuthCert) {
biz.ErrIsNil(model.Insert(ac), "新增授权凭证失败")
biz.ErrIsNil(gormx.Insert(ac), "新增授权凭证失败")
}
func (m *authCertRepoImpl) Update(ac *entity.AuthCert) {
biz.ErrIsNil(model.UpdateById(ac), "更新授权凭证失败")
biz.ErrIsNil(gormx.UpdateById(ac), "更新授权凭证失败")
}
func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
ac := new(entity.AuthCert)
err := model.GetById(ac, id)
err := gormx.GetById(ac, id)
if err != nil {
return nil
}
@@ -36,14 +38,14 @@ func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
acs := new([]*entity.AuthCert)
model.GetByIdIn(new(entity.AuthCert), acs, ids)
gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
return *acs
}
func (m *authCertRepoImpl) GetByCondition(condition *entity.AuthCert, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
func (m *authCertRepoImpl) DeleteById(id uint64) {
model.DeleteById(new(entity.AuthCert), id)
gormx.DeleteById(new(entity.AuthCert), id)
}

View File

@@ -1,10 +1,11 @@
package persistence
import (
"fmt"
"mayfly-go/internal/machine/api/vo"
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -15,28 +16,14 @@ func newMachineRepo() repository.Machine {
}
// 分页获取机器信息列表
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
sql := "SELECT m.* FROM t_machine m WHERE 1 = 1 "
values := make([]any, 0)
if condition.Ip != "" {
sql = sql + " AND m.ip LIKE ?"
values = append(values, "%"+condition.Ip+"%")
}
if condition.Name != "" {
sql = sql + " AND m.name LIKE ?"
values = append(values, "%"+condition.Name+"%")
}
if len(condition.TagIds) > 0 {
sql = fmt.Sprintf("%s AND m.tag_id IN ? ", sql)
values = append(values, condition.TagIds)
}
if condition.TagPathLike != "" {
sql = sql + " AND m.tag_path LIKE ?"
values = append(values, condition.TagPathLike+"%")
}
sql = sql + " ORDER BY m.tag_path"
return model.GetPageBySql(sql, pageParam, toEntity, values...)
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO] {
qd := gormx.NewQuery(new(entity.Machine)).
Like("ip", condition.Ip).
Like("name", condition.Name).
In("tag_id", condition.TagIds).
RLike("tag_path", condition.TagPathLike).
OrderByAsc("tag_path")
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
@@ -48,18 +35,18 @@ func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
where["tag_id"] = condition.TagId
}
return model.CountByMap(new(entity.Machine), where)
return gormx.CountByCond(new(entity.Machine), where)
}
// 根据条件获取账号信息
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
// 根据id获取
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
machine := new(entity.Machine)
if err := model.GetById(machine, id, cols...); err != nil {
if err := gormx.GetById(machine, id, cols...); err != nil {
return nil
}
@@ -67,9 +54,9 @@ func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
}
func (m *machineRepoImpl) Create(entity *entity.Machine) {
biz.ErrIsNilAppendErr(model.Insert(entity), "创建机器信息失败: %s")
biz.ErrIsNilAppendErr(gormx.Insert(entity), "创建机器信息失败: %s")
}
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
biz.ErrIsNilAppendErr(gormx.UpdateById(entity), "更新机器信息失败: %s")
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -14,19 +15,20 @@ func newMachineFileRepo() repository.MachineFile {
}
// 分页获取机器文件信息列表
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
// 根据条件获取账号信息
func (m *machineFileRepoImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.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 {
if err := gormx.GetById(ms, id, cols...); err != nil {
return nil
}
@@ -35,13 +37,13 @@ func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.Machine
// 根据id获取
func (m *machineFileRepoImpl) Delete(id uint64) {
biz.ErrIsNil(model.DeleteById(new(entity.MachineFile), id), "删除失败")
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineFile), id), "删除失败")
}
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) {
model.Insert(entity)
gormx.Insert(entity)
}
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
model.UpdateById(entity)
gormx.UpdateById(entity)
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -14,19 +15,20 @@ func newMachineScriptRepo() repository.MachineScript {
}
// 分页获取机器信息列表
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
// 根据条件获取账号信息
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.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 {
if err := gormx.GetById(ms, id, cols...); err != nil {
return nil
}
@@ -35,13 +37,13 @@ func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.Machi
// 根据id获取
func (m *machineScriptRepoImpl) Delete(id uint64) {
biz.ErrIsNil(model.DeleteById(new(entity.MachineScript), id), "删除失败")
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineScript), id), "删除失败")
}
func (m *machineScriptRepoImpl) Create(entity *entity.MachineScript) {
model.Insert(entity)
gormx.Insert(entity)
}
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
model.UpdateById(entity)
gormx.UpdateById(entity)
}

View File

@@ -13,6 +13,7 @@ import (
"mayfly-go/pkg/utils"
"regexp"
"strconv"
"strings"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
@@ -32,7 +33,7 @@ func (m *Mongo) Mongos(rc *req.Ctx) {
// 不存在可访问标签id即没有可操作数据
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
if len(tagIds) == 0 {
rc.ResData = model.EmptyPageResult()
rc.ResData = model.EmptyPageResult[any]()
return
}
condition.TagIds = tagIds
@@ -58,7 +59,15 @@ func (m *Mongo) Save(rc *req.Ctx) {
}
func (m *Mongo) DeleteMongo(rc *req.Ctx) {
m.MongoApp.Delete(m.GetMongoId(rc.GinCtx))
idsStr := ginx.PathParam(rc.GinCtx, "id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
m.MongoApp.Delete(uint64(value))
}
}
func (m *Mongo) Databases(rc *req.Ctx) {

View File

@@ -23,7 +23,7 @@ import (
type Mongo interface {
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Count(condition *entity.MongoQuery) int64
@@ -54,7 +54,7 @@ type mongoAppImpl struct {
}
// 分页获取数据库信息列表
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -7,7 +7,7 @@ import (
type Mongo interface {
// 分页获取列表
GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Count(condition *entity.MongoQuery) int64

View File

@@ -1,13 +1,11 @@
package persistence
import (
"fmt"
"mayfly-go/internal/mongo/domain/entity"
"mayfly-go/internal/mongo/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils"
"strings"
)
type mongoRepoImpl struct{}
@@ -17,20 +15,13 @@ func newMongoRepo() repository.Mongo {
}
// 分页获取数据库信息列表
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
sql := "SELECT d.* FROM t_mongo d WHERE 1=1 "
if len(condition.TagIds) > 0 {
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
}
values := make([]any, 0)
if condition.TagPathLike != "" {
values = append(values, condition.TagPathLike+"%")
sql = sql + " AND d.tag_path LIKE ?"
}
sql = sql + " ORDER BY d.tag_path"
return model.GetPageBySql(sql, pageParam, toEntity, values...)
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(new(entity.Mongo)).
Like("name", condition.Name).
In("tag_id", condition.TagIds).
RLike("tag_path", condition.TagPathLike).
OrderByAsc("tag_path")
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
@@ -41,18 +32,18 @@ func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
if condition.TagId != 0 {
where["tag_id"] = condition.TagId
}
return model.CountByMap(new(entity.Mongo), where)
return gormx.CountByCond(new(entity.Mongo), where)
}
// 根据条件获取
func (d *mongoRepoImpl) Get(condition *entity.Mongo, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
// 根据id获取
func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
db := new(entity.Mongo)
if err := model.GetById(db, id, cols...); err != nil {
if err := gormx.GetById(db, id, cols...); err != nil {
return nil
}
@@ -60,13 +51,13 @@ func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
}
func (d *mongoRepoImpl) Insert(db *entity.Mongo) {
biz.ErrIsNil(model.Insert(db), "新增mongo信息失败")
biz.ErrIsNil(gormx.Insert(db), "新增mongo信息失败")
}
func (d *mongoRepoImpl) Update(db *entity.Mongo) {
biz.ErrIsNil(model.UpdateById(db), "更新mongo信息失败")
biz.ErrIsNil(gormx.UpdateById(db), "更新mongo信息失败")
}
func (d *mongoRepoImpl) Delete(id uint64) {
model.DeleteById(new(entity.Mongo), id)
gormx.DeleteById(new(entity.Mongo), id)
}

View File

@@ -12,6 +12,7 @@ import (
"mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
"strconv"
"strings"
"github.com/gin-gonic/gin"
@@ -30,7 +31,7 @@ func (r *Redis) RedisList(rc *req.Ctx) {
// 不存在可访问标签id即没有可操作数据
tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
if len(tagIds) == 0 {
rc.ResData = model.EmptyPageResult()
rc.ResData = model.EmptyPageResult[any]()
return
}
condition.TagIds = tagIds
@@ -66,7 +67,15 @@ func (r *Redis) GetRedisPwd(rc *req.Ctx) {
}
func (r *Redis) DeleteRedis(rc *req.Ctx) {
r.RedisApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
idsStr := ginx.PathParam(rc.GinCtx, "id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
r.RedisApp.Delete(uint64(value))
}
}
func (r *Redis) RedisInfo(rc *req.Ctx) {

View File

@@ -23,7 +23,7 @@ import (
type Redis interface {
// 分页获取机器脚本信息列表
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Count(condition *entity.RedisQuery) int64
@@ -55,7 +55,7 @@ type redisAppImpl struct {
}
// 分页获取机器脚本信息列表
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -7,7 +7,7 @@ import (
type Redis interface {
// 分页获取机器信息列表
GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Count(condition *entity.RedisQuery) int64

View File

@@ -1,13 +1,11 @@
package persistence
import (
"fmt"
"mayfly-go/internal/redis/domain/entity"
"mayfly-go/internal/redis/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils"
"strings"
)
type redisRepoImpl struct{}
@@ -17,22 +15,13 @@ func newRedisRepo() repository.Redis {
}
// 分页获取机器信息列表
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
sql := "SELECT d.* FROM t_redis d WHERE 1=1 "
values := make([]any, 0)
if condition.Host != "" {
sql = sql + " AND d.host LIKE ?"
values = append(values, "%"+condition.Host+"%")
}
if len(condition.TagIds) > 0 {
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
}
if condition.TagPathLike != "" {
sql = sql + " AND d.tag_path LIKE ?"
values = append(values, condition.TagPathLike+"%")
}
sql = sql + " ORDER BY d.tag_path"
return model.GetPageBySql(sql, pageParam, toEntity, values...)
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(new(entity.Redis)).
Like("host", condition.Host).
In("tag_id", condition.TagIds).
RLike("tag_path", condition.TagPathLike).
OrderByAsc("tag_path")
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
@@ -44,30 +33,30 @@ func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
where["tag_id"] = condition.TagId
}
return model.CountByMap(new(entity.Redis), where)
return gormx.CountByCond(new(entity.Redis), where)
}
// 根据id获取
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
rd := new(entity.Redis)
if err := model.GetById(rd, id, cols...); err != nil {
if err := gormx.GetById(rd, id, cols...); err != nil {
return nil
}
return rd
}
func (r *redisRepoImpl) GetRedis(condition *entity.Redis, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
func (r *redisRepoImpl) Insert(redis *entity.Redis) {
biz.ErrIsNilAppendErr(model.Insert(redis), "新增失败: %s")
biz.ErrIsNilAppendErr(gormx.Insert(redis), "新增失败: %s")
}
func (r *redisRepoImpl) Update(redis *entity.Redis) {
biz.ErrIsNilAppendErr(model.UpdateById(redis), "更新失败: %s")
biz.ErrIsNilAppendErr(gormx.UpdateById(redis), "更新失败: %s")
}
func (r *redisRepoImpl) Delete(id uint64) {
biz.ErrIsNilAppendErr(model.DeleteById(new(entity.Redis), id), "删除失败: %s")
biz.ErrIsNilAppendErr(gormx.DeleteById(new(entity.Redis), id), "删除失败: %s")
}

View File

@@ -345,9 +345,15 @@ func (a *Account) ChangeStatus(rc *req.Ctx) {
}
func (a *Account) DeleteAccount(rc *req.Ctx) {
id := uint64(ginx.PathParamInt(rc.GinCtx, "id"))
rc.ReqParam = id
a.AccountApp.Delete(id)
idsStr := ginx.PathParam(rc.GinCtx, "id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
a.AccountApp.Delete(uint64(value))
}
}
// 获取账号角色id列表用户回显角色分配

View File

@@ -5,6 +5,7 @@ import (
"mayfly-go/internal/sys/api/vo"
"mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
@@ -40,7 +41,15 @@ func (r *Role) SaveRole(rc *req.Ctx) {
// 删除角色及其资源关联关系
func (r *Role) DelRole(rc *req.Ctx) {
r.RoleApp.DeleteRole(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
idsStr := ginx.PathParam(rc.GinCtx, "id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
r.RoleApp.DeleteRole(uint64(value))
}
}
// 获取角色关联的资源id数组用于分配资源时回显已拥有的资源

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils"
@@ -13,7 +14,7 @@ import (
type Account interface {
GetAccount(condition *entity.Account, cols ...string) error
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Create(account *entity.Account)
@@ -37,7 +38,7 @@ func (a *accountAppImpl) GetAccount(condition *entity.Account, cols ...string) e
return a.accountRepo.GetAccount(condition, cols...)
}
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return a.accountRepo.GetPageList(condition, pageParam, toEntity)
}
@@ -56,7 +57,7 @@ func (a *accountAppImpl) Update(account *entity.Account) {
}
func (a *accountAppImpl) Delete(id uint64) {
err := model.Tx(
err := gormx.Tx(
func(db *gorm.DB) error {
// 删除account表信息
return db.Delete(new(entity.Account), "id = ?", id).Error

View File

@@ -13,7 +13,7 @@ import (
const SysConfigKeyPrefix = "sys:config:"
type Config interface {
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Save(config *entity.Config)
@@ -31,7 +31,7 @@ type configAppImpl struct {
configRepo repository.Config
}
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return a.configRepo.GetPageList(condition, pageParam, toEntity)
}

View File

@@ -9,7 +9,7 @@ import (
)
type Msg interface {
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Create(msg *entity.Msg)
@@ -27,7 +27,7 @@ type msgAppImpl struct {
msgRepo repository.Msg
}
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
}

View File

@@ -5,7 +5,7 @@ import (
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/global"
"mayfly-go/pkg/model"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/utils"
"strings"
"time"
@@ -16,8 +16,6 @@ type Resource interface {
GetById(id uint64, cols ...string) *entity.Resource
GetByIdIn(ids []uint64, toEntity any, cols ...string)
Save(entity *entity.Resource)
ChangeStatus(resourceId uint64, status int8)
@@ -47,10 +45,6 @@ func (r *resourceAppImpl) GetById(id uint64, cols ...string) *entity.Resource {
return r.resourceRepo.GetById(id, cols...)
}
func (r *resourceAppImpl) GetByIdIn(ids []uint64, toEntity any, orderBy ...string) {
r.resourceRepo.GetByIdIn(ids, toEntity, orderBy...)
}
func (r *resourceAppImpl) Save(resource *entity.Resource) {
// 更新操作
if resource.Id != 0 {
@@ -61,7 +55,7 @@ func (r *resourceAppImpl) Save(resource *entity.Resource) {
r.checkCode(resource.Code)
}
}
model.UpdateById(resource)
gormx.UpdateById(resource)
return
}
@@ -80,7 +74,7 @@ func (r *resourceAppImpl) Save(resource *entity.Resource) {
}
r.checkCode(resource.Code)
resource.Weight = int(time.Now().Unix())
model.Insert(resource)
gormx.Insert(resource)
}
func (r *resourceAppImpl) ChangeStatus(resourceId uint64, status int8) {
@@ -148,7 +142,7 @@ func (r *resourceAppImpl) Sort(sortResource *entity.Resource) {
func (r *resourceAppImpl) checkCode(code string) {
biz.IsTrue(!strings.Contains(code, ","), "code不能包含','")
biz.IsEquals(model.CountBy(&entity.Resource{Code: code}), int64(0), "该code已存在")
biz.IsEquals(gormx.CountBy(&entity.Resource{Code: code}), int64(0), "该code已存在")
}
func (r *resourceAppImpl) Delete(id uint64) {
@@ -160,7 +154,7 @@ func (r *resourceAppImpl) Delete(id uint64) {
for _, v := range children {
r.resourceRepo.Delete(v.Id)
// 删除角色关联的资源信息
model.DeleteByCondition(&entity.RoleResource{ResourceId: v.Id})
gormx.DeleteByCondition(&entity.RoleResource{ResourceId: v.Id})
}
}

View File

@@ -3,12 +3,13 @@ package application
import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
"strings"
)
type Role interface {
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
SaveRole(role *entity.Role)
@@ -45,7 +46,7 @@ type roleAppImpl struct {
roleRepo repository.Role
}
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return m.roleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}
@@ -54,17 +55,17 @@ func (m *roleAppImpl) SaveRole(role *entity.Role) {
if role.Id != 0 {
// code不可更改防止误传
role.Code = ""
model.UpdateById(role)
gormx.UpdateById(role)
} else {
role.Status = 1
model.Insert(role)
gormx.Insert(role)
}
}
func (m *roleAppImpl) DeleteRole(id uint64) {
m.roleRepo.Delete(id)
// 删除角色与资源的关联关系
model.DeleteByCondition(&entity.RoleResource{RoleId: id})
gormx.DeleteByCondition(&entity.RoleResource{RoleId: id})
}
func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {

View File

@@ -13,7 +13,7 @@ import (
)
type Syslog interface {
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
// 从请求上下文的参数保存系统日志
SaveFromReq(req *req.Ctx)
@@ -29,7 +29,7 @@ type syslogAppImpl struct {
syslogRepo repository.Syslog
}
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -9,7 +9,7 @@ type Account interface {
// 根据条件获取账号信息
GetAccount(condition *entity.Account, cols ...string) error
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Insert(account *entity.Account)

View File

@@ -6,7 +6,7 @@ import (
)
type Config interface {
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Insert(config *entity.Config)

View File

@@ -6,7 +6,7 @@ import (
)
type Msg interface {
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Insert(msg *entity.Msg)
}

View File

@@ -10,8 +10,6 @@ type Resource interface {
GetById(id uint64, cols ...string) *entity.Resource
GetByIdIn(ids []uint64, toEntity any, orderBy ...string)
Delete(id uint64)
GetByCondition(condition *entity.Resource, cols ...string) error

View File

@@ -6,7 +6,7 @@ import (
)
type Role interface {
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Delete(id uint64)

View File

@@ -6,7 +6,7 @@ import (
)
type Syslog interface {
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Insert(log *entity.Syslog)
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -14,24 +15,20 @@ func newAccountRepo() repository.Account {
}
func (a *accountRepoImpl) GetAccount(condition *entity.Account, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
sql := "SELECT * FROM t_sys_account "
username := condition.Username
values := make([]any, 0)
if username != "" {
sql = sql + " WHERE username LIKE ?"
values = append(values, "%"+username+"%")
}
return model.GetPageBySql(sql, pageParam, toEntity, values...)
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(new(entity.Account)).
Like("name", condition.Name).
Like("username", condition.Username)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *accountRepoImpl) Insert(account *entity.Account) {
biz.ErrIsNil(model.Insert(account), "新增账号信息失败")
biz.ErrIsNil(gormx.Insert(account), "新增账号信息失败")
}
func (m *accountRepoImpl) Update(account *entity.Account) {
biz.ErrIsNil(model.UpdateById(account), "更新账号信息失败")
biz.ErrIsNil(gormx.UpdateById(account), "更新账号信息失败")
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -13,22 +14,23 @@ func newConfigRepo() repository.Config {
return new(configRepoImpl)
}
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity)
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *configRepoImpl) Insert(config *entity.Config) {
biz.ErrIsNil(model.Insert(config), "新增系统配置失败")
biz.ErrIsNil(gormx.Insert(config), "新增系统配置失败")
}
func (m *configRepoImpl) Update(config *entity.Config) {
biz.ErrIsNil(model.UpdateById(config), "更新系统配置失败")
biz.ErrIsNil(gormx.UpdateById(config), "更新系统配置失败")
}
func (m *configRepoImpl) GetConfig(condition *entity.Config, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
func (r *configRepoImpl) GetByCondition(condition *entity.Config, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -13,10 +14,11 @@ func newMsgRepo() repository.Msg {
return new(msgRepoImpl)
}
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity)
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *msgRepoImpl) Insert(account *entity.Msg) {
biz.ErrIsNil(model.Insert(account), "新增消息记录失败")
biz.ErrIsNil(gormx.Insert(account), "新增消息记录失败")
}

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/model"
"mayfly-go/pkg/gormx"
)
type resourceRepoImpl struct{}
@@ -14,40 +14,36 @@ func newResourceRepo() repository.Resource {
}
func (r *resourceRepoImpl) GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string) {
model.ListByOrder(condition, toEntity, orderBy...)
gormx.ListByOrder(condition, toEntity, orderBy...)
}
func (r *resourceRepoImpl) GetById(id uint64, cols ...string) *entity.Resource {
res := new(entity.Resource)
if err := model.GetById(res, id, cols...); err != nil {
if err := gormx.GetById(res, id, cols...); err != nil {
return nil
}
return res
}
func (r *resourceRepoImpl) GetByIdIn(ids []uint64, toEntity any, orderBy ...string) {
model.GetByIdIn(new(entity.Resource), toEntity, ids, orderBy...)
}
func (r *resourceRepoImpl) Delete(id uint64) {
biz.ErrIsNil(model.DeleteById(new(entity.Resource), id), "删除失败")
biz.ErrIsNil(gormx.DeleteById(new(entity.Resource), id), "删除失败")
}
func (r *resourceRepoImpl) GetByCondition(condition *entity.Resource, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
func (r *resourceRepoImpl) GetChildren(uiPath string) []entity.Resource {
sql := "SELECT id, ui_path FROM t_sys_resource WHERE ui_path LIKE ?"
var rs []entity.Resource
model.GetListBySql2Model(sql, &rs, uiPath+"%")
gormx.GetListBySql2Model(sql, &rs, uiPath+"%")
return rs
}
func (r *resourceRepoImpl) UpdateByUiPathLike(resource *entity.Resource) {
sql := "UPDATE t_sys_resource SET status=? WHERE (ui_path LIKE ?)"
model.ExecSql(sql, resource.Status, resource.UiPath+"%")
gormx.ExecSql(sql, resource.Status, resource.UiPath+"%")
}
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
@@ -84,5 +80,5 @@ func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
ORDER BY
m.pid ASC,
m.weight ASC`
biz.ErrIsNilAppendErr(model.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
biz.ErrIsNilAppendErr(gormx.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -13,12 +14,13 @@ func newRoleRepo() repository.Role {
return new(roleRepoImpl)
}
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *roleRepoImpl) Delete(id uint64) {
biz.ErrIsNil(model.DeleteById(new(entity.Role), id), "删除角色失败")
biz.ErrIsNil(gormx.DeleteById(new(entity.Role), id), "删除角色失败")
}
// 获取角色拥有的资源id数组从role_resource表获取
@@ -26,7 +28,7 @@ func (m *roleRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
var rrs []entity.RoleResource
condtion := &entity.RoleResource{RoleId: roleId}
model.ListBy(condtion, &rrs, "ResourceId")
gormx.ListBy(condtion, &rrs, "ResourceId")
var rids []uint64
for _, v := range rrs {
@@ -41,22 +43,22 @@ func (m *roleRepoImpl) GetRoleResources(roleId uint64, toEntity any) {
"FROM t_sys_role_resource rr JOIN t_sys_resource r ON rr.resource_id = r.id " +
"WHERE rr.role_id = ? " +
"ORDER BY r.pid ASC, r.weight ASC"
model.GetListBySql2Model(sql, toEntity, roleId)
gormx.GetListBySql2Model(sql, toEntity, roleId)
}
func (m *roleRepoImpl) SaveRoleResource(rr *entity.RoleResource) {
model.Insert(rr)
gormx.Insert(rr)
}
func (m *roleRepoImpl) DeleteRoleResource(roleId uint64, resourceId uint64) {
model.DeleteByCondition(&entity.RoleResource{RoleId: roleId, ResourceId: resourceId})
gormx.DeleteByCondition(&entity.RoleResource{RoleId: roleId, ResourceId: resourceId})
}
func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
var rrs []entity.AccountRole
condtion := &entity.AccountRole{AccountId: accountId}
model.ListBy(condtion, &rrs, "RoleId")
gormx.ListBy(condtion, &rrs, "RoleId")
var rids []uint64
for _, v := range rrs {
@@ -66,11 +68,11 @@ func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
}
func (m *roleRepoImpl) SaveAccountRole(ar *entity.AccountRole) {
model.Insert(ar)
gormx.Insert(ar)
}
func (m *roleRepoImpl) DeleteAccountRole(accountId, roleId uint64) {
model.DeleteByCondition(&entity.AccountRole{RoleId: roleId, AccountId: accountId})
gormx.DeleteByCondition(&entity.AccountRole{RoleId: roleId, AccountId: accountId})
}
// 获取账号角色信息列表
@@ -78,5 +80,5 @@ func (m *roleRepoImpl) GetAccountRoles(accountId uint64, toEntity any) {
sql := "SELECT r.status, r.name, ar.create_time AS CreateTime, ar.creator AS creator " +
"FROM t_sys_role r JOIN t_sys_account_role ar ON r.id = ar.role_id AND ar.account_id = ? " +
"ORDER BY ar.create_time DESC"
model.GetListBySql2Model(sql, toEntity, accountId)
gormx.GetListBySql2Model(sql, toEntity, accountId)
}

View File

@@ -3,6 +3,7 @@ package persistence
import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -12,10 +13,11 @@ func newSyslogRepo() repository.Syslog {
return new(syslogRepoImpl)
}
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *syslogRepoImpl) Insert(syslog *entity.Syslog) {
model.Insert(syslog)
gormx.Insert(syslog)
}

View File

@@ -12,6 +12,8 @@ import (
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
"strconv"
"strings"
)
type Team struct {
@@ -48,7 +50,15 @@ func (p *Team) SaveTeam(rc *req.Ctx) {
}
func (p *Team) DelTeam(rc *req.Ctx) {
p.TeamApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
idsStr := ginx.PathParam(rc.GinCtx, "id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
p.TeamApp.Delete(uint64(value))
}
}
// 获取团队的成员信息

View File

@@ -9,7 +9,7 @@ import (
type Team interface {
// 分页获取项目团队信息列表
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Save(team *entity.Team)
@@ -17,7 +17,7 @@ type Team interface {
//--------------- 团队成员相关接口 ---------------
GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult
GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any]
SaveMember(tagTeamMember *entity.TeamMember)
@@ -51,7 +51,7 @@ type teamAppImpl struct {
tagTreeTeamRepo repository.TagTreeTeam
}
func (p *teamAppImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
func (p *teamAppImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
return p.teamRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}
@@ -66,11 +66,12 @@ func (p *teamAppImpl) Save(team *entity.Team) {
func (p *teamAppImpl) Delete(id uint64) {
p.teamRepo.Delete(id)
p.teamMemberRepo.DeleteBy(&entity.TeamMember{TeamId: id})
p.tagTreeTeamRepo.DeleteBy(&entity.TagTreeTeam{TeamId: id})
}
// --------------- 团队成员相关接口 ---------------
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult {
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any] {
return p.teamMemberRepo.GetPageList(condition, pageParam, toEntity)
}

View File

@@ -6,7 +6,7 @@ import (
)
type Team interface {
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
Insert(p *entity.Team)

View File

@@ -12,7 +12,7 @@ type TeamMember interface {
Save(mp *entity.TeamMember)
GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult
GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any]
DeleteBy(condition *entity.TeamMember)

View File

@@ -5,7 +5,7 @@ import (
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/internal/tag/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/model"
"mayfly-go/pkg/gormx"
"strings"
)
@@ -49,29 +49,29 @@ func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEn
sql = sql + ")"
}
sql = sql + " ORDER BY p.code_path"
model.GetListBySql2Model(sql, toEntity)
gormx.GetListBySql2Model(sql, toEntity)
}
func (p *tagTreeRepoImpl) SelectById(id uint64) *entity.TagTree {
pt := new(entity.TagTree)
if err := model.GetById(pt, id); err != nil {
if err := gormx.GetById(pt, id); err != nil {
return nil
}
return pt
}
func (a *tagTreeRepoImpl) GetBy(condition *entity.TagTree, cols ...string) error {
return model.GetBy(condition, cols...)
return gormx.GetBy(condition, cols...)
}
func (p *tagTreeRepoImpl) Insert(tagTree *entity.TagTree) {
biz.ErrIsNil(model.Insert(tagTree), "新增标签失败")
biz.ErrIsNil(gormx.Insert(tagTree), "新增标签失败")
}
func (p *tagTreeRepoImpl) UpdateById(tagTree *entity.TagTree) {
biz.ErrIsNil(model.UpdateById(tagTree), "更新标签失败")
biz.ErrIsNil(gormx.UpdateById(tagTree), "更新标签失败")
}
func (p *tagTreeRepoImpl) Delete(id uint64) {
model.DeleteById(new(entity.TagTree), id)
gormx.DeleteById(new(entity.TagTree), id)
}

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/internal/tag/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/model"
"mayfly-go/pkg/gormx"
)
type tagTreeTeamRepoImpl struct{}
@@ -14,19 +14,19 @@ func newTagTreeTeamRepo() repository.TagTreeTeam {
}
func (p *tagTreeTeamRepoImpl) ListTag(condition *entity.TagTreeTeam, toEntity any, orderBy ...string) {
model.ListByOrder(condition, toEntity, orderBy...)
gormx.ListByOrder(condition, toEntity, orderBy...)
}
func (p *tagTreeTeamRepoImpl) Save(pm *entity.TagTreeTeam) {
biz.ErrIsNilAppendErr(model.Insert(pm), "保存团队项目信息失败:%s")
biz.ErrIsNilAppendErr(gormx.Insert(pm), "保存团队项目信息失败:%s")
}
func (p *tagTreeTeamRepoImpl) DeleteBy(condition *entity.TagTreeTeam) {
model.DeleteByCondition(condition)
gormx.DeleteByCondition(condition)
}
func (p *tagTreeTeamRepoImpl) SelectTagPathsByAccountId(accountId uint64) []string {
var res []string
model.GetListBySql2Model("SELECT DISTINCT(t1.tag_path) FROM t_tag_tree_team t1 JOIN t_team_member t2 ON t1.team_id = t2.team_id WHERE t2.account_id = ? ORDER BY t1.tag_path", &res, accountId)
gormx.GetListBySql2Model("SELECT DISTINCT(t1.tag_path) FROM t_tag_tree_team t1 JOIN t_team_member t2 ON t1.team_id = t2.team_id WHERE t2.account_id = ? ORDER BY t1.tag_path", &res, accountId)
return res
}

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/internal/tag/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -13,22 +14,23 @@ func newTeamRepo() repository.Team {
return new(teamRepoImpl)
}
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (p *teamRepoImpl) Insert(team *entity.Team) {
biz.ErrIsNil(model.Insert(team), "新增团队失败")
biz.ErrIsNil(gormx.Insert(team), "新增团队失败")
}
func (p *teamRepoImpl) UpdateById(team *entity.Team) {
biz.ErrIsNil(model.UpdateById(team), "更新团队失败")
biz.ErrIsNil(gormx.UpdateById(team), "更新团队失败")
}
func (p *teamRepoImpl) Delete(id uint64) {
model.DeleteById(new(entity.Team), id)
gormx.DeleteById(new(entity.Team), id)
}
func (p *teamRepoImpl) DeleteBy(team *entity.Team) {
model.DeleteByCondition(team)
gormx.DeleteByCondition(team)
}

View File

@@ -1,10 +1,10 @@
package persistence
import (
"fmt"
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/internal/tag/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -15,36 +15,28 @@ func newTeamMemberRepo() repository.TeamMember {
}
func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string) {
model.ListByOrder(condition, toEntity, orderBy...)
gormx.ListByOrder(condition, toEntity, orderBy...)
}
func (p *teamMemberRepoImpl) Save(pm *entity.TeamMember) {
biz.ErrIsNilAppendErr(model.Insert(pm), "保存团队成员失败:%s")
biz.ErrIsNilAppendErr(gormx.Insert(pm), "保存团队成员失败:%s")
}
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult {
sql := "SELECT d.*, a.name FROM t_team_member d JOIN t_sys_account a ON d.account_id = a.id WHERE a.status = 1 "
if condition.AccountId != 0 {
sql = fmt.Sprintf("%s AND d.account_id = %d", sql, condition.AccountId)
}
if condition.TeamId != 0 {
sql = fmt.Sprintf("%s AND d.team_id = %d", sql, condition.TeamId)
}
values := make([]any, 0)
if condition.Username != "" {
sql = sql + " AND d.Username LIKE ?"
values = append(values, "%"+condition.Username+"%")
}
sql = sql + " ORDER BY d.id DESC"
return model.GetPageBySql(sql, pageParam, toEntity, values...)
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any] {
qd := gormx.NewQuery(new(entity.TeamMember)).
Select("t_team_member.*, a.name").
Joins("JOIN t_sys_account a ON t_team_member.account_id = a.id AND a.status = 1").
Eq("account_id", condition.AccountId).
Eq("team_id", condition.TeamId).
Like("a.username", condition.Username).
OrderByDesc("t_team_member.id")
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (p *teamMemberRepoImpl) DeleteBy(condition *entity.TeamMember) {
model.DeleteByCondition(condition)
gormx.DeleteByCondition(condition)
}
func (p *teamMemberRepoImpl) IsExist(teamId, accountId uint64) bool {
return model.CountBy(&entity.TeamMember{TeamId: teamId, AccountId: accountId}) > 0
return gormx.CountBy(&entity.TeamMember{TeamId: teamId, AccountId: accountId}) > 0
}

View File

@@ -0,0 +1,33 @@
package consts
const (
Comma = ","
LeftBracket = "("
RightBracket = ")"
DefaultPrimaryName = "id"
)
const (
And = "AND"
Or = "OR"
In = "IN"
Not = "NOT"
Like = "LIKE"
Eq = "="
Ne = "<>"
Gt = ">"
Ge = ">="
Lt = "<"
Le = "<="
IsNull = "IS NULL"
IsNotNull = "IS NOT NULL"
Between = "BETWEEN"
Desc = "DESC"
Asc = "ASC"
As = "AS"
SUM = "SUM"
AVG = "AVG"
MAX = "MAX"
MIN = "MIN"
COUNT = "COUNT"
)

View File

@@ -53,10 +53,16 @@ func QueryInt(g *gin.Context, qm string, defaultInt int) int {
// 获取路径参数
func PathParamInt(g *gin.Context, pm string) int {
value, _ := strconv.Atoi(g.Param(pm))
value, err := strconv.Atoi(g.Param(pm))
biz.ErrIsNilAppendErr(err, "string类型转换int异常: %s")
return value
}
// 获取路径参数
func PathParam(g *gin.Context, pm string) string {
return g.Param(pm)
}
// 文件下载
func Download(g *gin.Context, reader io.Reader, filename string) {
g.Header("Content-Type", "application/octet-stream")

137
server/pkg/gormx/gormx.go Normal file
View File

@@ -0,0 +1,137 @@
package gormx
import (
"fmt"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/global"
"mayfly-go/pkg/model"
"strings"
"gorm.io/gorm"
)
// 根据id获取实体对象。model需为指针类型需要将查询出来的值赋值给model
//
// 若error不为nil则为不存在该记录
// @param model 数据库映射实体模型
func GetById(model any, id uint64, cols ...string) error {
return NewQuery(model).Eq("id", id).GenGdb().First(model).Error
}
// 根据id列表查询实体信息
// @param model 数据库映射实体模型
func GetByIdIn(model any, list any, ids []uint64, orderBy ...string) {
NewQuery(model).In("id", ids).GenGdb().Find(list)
}
// 获取满足model中不为空的字段值条件的单个对象。model需为指针类型需要将查询出来的值赋值给model
//
// 若 error不为nil则为不存在该记录
// @param model 数据库映射实体模型
func GetBy(model any, cols ...string) error {
return global.Db.Select(cols).Where(model).First(model).Error
}
// 根据model指定条件统计数量
func CountBy(model any) int64 {
var count int64
NewQuery(model).WithCondModel(model).GenGdb().Count(&count)
return count
}
// 根据条件model指定条件统计数量
func CountByCond(model any, condModel any) int64 {
var count int64
NewQuery(model).WithCondModel(condModel).GenGdb().Count(&count)
return count
}
// 根据查询条件分页查询数据
// 若未指定查询列则查询列以toModels字段为准
func PageQuery[T any](q *QueryCond, pageParam *model.PageParam, toModels T) *model.PageResult[T] {
gdb := q.GenGdb()
var count int64
err := gdb.Count(&count).Error
biz.ErrIsNilAppendErr(err, " 查询错误:%s")
if count == 0 {
return model.EmptyPageResult[T]()
}
page := pageParam.PageNum
pageSize := pageParam.PageSize
err = gdb.Limit(pageSize).Offset((page - 1) * pageSize).Find(toModels).Error
biz.ErrIsNil(err, "查询失败")
return &model.PageResult[T]{Total: count, List: toModels}
}
// 获取满足model中不为空的字段值条件的所有数据.
//
// @param list为数组类型 如 var users *[]User可指定为非model结构体即只包含需要返回的字段结构体
func ListBy(model any, list any, cols ...string) {
global.Db.Model(model).Select(cols).Where(model).Order("id desc").Find(list)
}
// 获取满足model中不为空的字段值条件的所有数据.
//
// @param list为数组类型 如 var users *[]User可指定为非model结构体
// @param model 数据库映射实体模型
func ListByOrder(model any, list any, order ...string) {
var orderByStr string
if order == nil {
orderByStr = "id desc"
} else {
orderByStr = strings.Join(order, ",")
}
global.Db.Model(model).Where(model).Order(orderByStr).Find(list)
}
func GetListBySql2Model(sql string, toEntity any, params ...any) error {
return global.Db.Raw(sql, params...).Find(toEntity).Error
}
func ExecSql(sql string, params ...any) {
global.Db.Exec(sql, params...)
}
// 插入model
// @param model 数据库映射实体模型
func Insert(model any) error {
return global.Db.Create(model).Error
}
// 根据id更新model更新字段为model中不为空的值即int类型不为0ptr类型不为nil这类字段值
// @param model 数据库映射实体模型
func UpdateById(model any) error {
return global.Db.Model(model).Updates(model).Error
}
// 根据id删除model
// @param model 数据库映射实体模型
func DeleteById(model any, id uint64) error {
return global.Db.Delete(model, "id = ?", id).Error
}
// 根据条件删除
// @param model 数据库映射实体模型
func DeleteByCondition(model any) error {
return global.Db.Where(model).Delete(model).Error
}
func Tx(funcs ...func(db *gorm.DB) error) (err error) {
tx := global.Db.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
err = fmt.Errorf("%v", err)
}
}()
for _, f := range funcs {
err = f(tx)
if err != nil {
tx.Rollback()
return
}
}
err = tx.Commit().Error
return
}

143
server/pkg/gormx/query.go Normal file
View File

@@ -0,0 +1,143 @@
package gormx
import (
"fmt"
"mayfly-go/pkg/consts"
"mayfly-go/pkg/global"
"mayfly-go/pkg/utils"
"strings"
"gorm.io/gorm"
)
type QueryCond struct {
selectColumns string // 查询的列信息
joins string // join 类似 left join emails on emails.user_id = users.id
dbModel any // 数据库模型
condModel any // 条件模型
columns []string // 查询的所有列与values一一对应
values []any // 查询列对应的值
orderBy []string
}
// NewQuery 构建查询条件
func NewQuery(dbModel any) *QueryCond {
return &QueryCond{dbModel: dbModel}
}
func (q *QueryCond) WithCondModel(condModel any) *QueryCond {
q.condModel = condModel
return q
}
func (q *QueryCond) WithOrderBy(orderBy ...string) *QueryCond {
q.orderBy = append(q.orderBy, orderBy...)
return q
}
func (q *QueryCond) Select(columns ...string) *QueryCond {
q.selectColumns = strings.Join(columns, ",")
return q
}
func (q *QueryCond) Joins(joins string) *QueryCond {
q.joins = joins
return q
}
// Eq 等于 =
func (q *QueryCond) Eq(column string, val any) *QueryCond {
return q.Cond(consts.Eq, column, val)
}
func (q *QueryCond) Like(column string, val string) *QueryCond {
if val == "" {
return q
}
return q.Cond(consts.Like, column, "%"+val+"%")
}
func (q *QueryCond) RLike(column string, val string) *QueryCond {
if val == "" {
return q
}
return q.Cond(consts.Like, column, val+"%")
}
func (q *QueryCond) In(column string, val any) *QueryCond {
return q.Cond(consts.In, column, val)
}
func (q *QueryCond) OrderByDesc(column string) *QueryCond {
q.orderBy = append(q.orderBy, fmt.Sprintf("%s DESC", column))
return q
}
func (q *QueryCond) OrderByAsc(column string) *QueryCond {
q.orderBy = append(q.orderBy, fmt.Sprintf("%s ASC", column))
return q
}
func (q *QueryCond) GenGdb() *gorm.DB {
gdb := global.Db.Model(q.dbModel)
if q.selectColumns != "" {
gdb.Select(q.selectColumns)
}
if q.joins != "" {
gdb.Joins(q.joins)
}
if q.condModel != nil {
gdb.Where(q.condModel)
}
for i, v := range q.columns {
gdb.Where(v, q.values[i])
}
if len(q.orderBy) > 0 {
gdb.Order(strings.Join(q.orderBy, ","))
} else {
gdb.Order("id desc")
}
return gdb
}
// // Ne 不等于 !=
func (q *QueryCond) Ne(column string, val any) *QueryCond {
q.Cond(consts.Ne, column, val)
return q
}
// Gt 大于 >
func (q *QueryCond) Gt(column string, val any) *QueryCond {
q.Cond(consts.Gt, column, val)
return q
}
// Ge 大于等于 >=
func (q *QueryCond) Ge(column string, val any) *QueryCond {
q.Cond(consts.Ge, column, val)
return q
}
// Lt 小于 <
func (q *QueryCond) Lt(column string, val any) *QueryCond {
q.Cond(consts.Lt, column, val)
return q
}
// Le 小于等于 <=
func (q *QueryCond) Le(column string, val any) *QueryCond {
q.Cond(consts.Le, column, val)
return q
}
func (q *QueryCond) Cond(cond, column string, val any) *QueryCond {
// 零值跳过
if utils.IsBlank(val) {
return q
}
q.columns = append(q.columns, fmt.Sprintf("%s %s ?", column, cond))
q.values = append(q.values, val)
return q
}

View File

@@ -1,15 +1,7 @@
package model
import (
"fmt"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/global"
"strconv"
"strings"
"time"
"gorm.io/gorm"
)
type Model struct {
@@ -43,195 +35,3 @@ func (m *Model) SetBaseInfo(account *LoginAccount) {
m.Modifier = name
m.ModifierId = id
}
func Tx(funcs ...func(db *gorm.DB) error) (err error) {
tx := global.Db.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
err = fmt.Errorf("%v", err)
}
}()
for _, f := range funcs {
err = f(tx)
if err != nil {
tx.Rollback()
return
}
}
err = tx.Commit().Error
return
}
// 根据id获取实体对象。model需为指针类型需要将查询出来的值赋值给model
//
// 若error不为nil则为不存在该记录
// @param model 数据库映射实体模型
func GetById(model any, id uint64, cols ...string) error {
return global.Db.Select(cols).Where("id = ?", id).First(model).Error
}
// 根据map条件查询列表map中的值如果为数组则使用in查询
// @param model 数据库映射实体模型
func GetByIdIn(model any, list any, ids []uint64, orderBy ...string) {
var orderByStr string
if orderBy == nil {
orderByStr = "id desc"
} else {
orderByStr = strings.Join(orderBy, ",")
}
global.Db.Model(model).Where("id in (?)", ids).Order(orderByStr).Find(list)
}
// 根据map指定条件查询列表
func SelectByMap(model any, list any, where map[string]any, orderBy ...string) {
var orderByStr string
if orderBy == nil {
orderByStr = "id desc"
} else {
orderByStr = strings.Join(orderBy, ",")
}
global.Db.Model(model).Where(where).Order(orderByStr).Find(list)
}
// 根据model指定条件统计数量
func CountBy(model any) int64 {
var count int64
global.Db.Model(model).Where(model).Count(&count)
return count
}
// 根据map为条件统计数量map中的值如果为数组则使用in查询
// @param model 数据库映射实体模型
// @param where 条件map
func CountByMap(model any, where map[string]any) int64 {
var count int64
global.Db.Model(model).Where(where).Count(&count)
return count
}
// 根据统计sql返回统计数量
func CountBySql(sql string) int64 {
var count int64
global.Db.Raw(sql).Scan(&count)
return count
}
// 根据id更新model更新字段为model中不为空的值即int类型不为0ptr类型不为nil这类字段值
// @param model 数据库映射实体模型
func UpdateById(model any) error {
return global.Db.Model(model).Updates(model).Error
}
// 根据id删除model
// @param model 数据库映射实体模型
func DeleteById(model any, id uint64) error {
return global.Db.Delete(model, "id = ?", id).Error
}
// 根据条件删除
// @param model 数据库映射实体模型
func DeleteByCondition(model any) error {
return global.Db.Where(model).Delete(model).Error
}
// 插入model
// @param model 数据库映射实体模型
func Insert(model any) error {
return global.Db.Create(model).Error
}
// 获取满足model中不为空的字段值条件的所有数据.
//
// @param list为数组类型 如 var users *[]User可指定为非model结构体即只包含需要返回的字段结构体
func ListBy(model any, list any, cols ...string) {
global.Db.Model(model).Select(cols).Where(model).Order("id desc").Find(list)
}
// 获取满足model中不为空的字段值条件的所有数据.
//
// @param list为数组类型 如 var users *[]User可指定为非model结构体
// @param model 数据库映射实体模型
func ListByOrder(model any, list any, order ...string) {
var orderByStr string
if order == nil {
orderByStr = "id desc"
} else {
orderByStr = strings.Join(order, ",")
}
global.Db.Model(model).Where(model).Order(orderByStr).Find(list)
}
// 获取满足model中不为空的字段值条件的单个对象。model需为指针类型需要将查询出来的值赋值给model
//
// 若 error不为nil则为不存在该记录
// @param model 数据库映射实体模型
func GetBy(model any, cols ...string) error {
return global.Db.Select(cols).Where(model).First(model).Error
}
// 获取满足conditionModel中不为空的字段值条件的单个对象。model需为指针类型需要将查询出来的值赋值给model
//
// @param toModel 需要查询的字段
//
// 若 error不为nil则为不存在该记录
func GetByConditionTo(conditionModel any, toModel any) error {
return global.Db.Model(conditionModel).Where(conditionModel).First(toModel).Error
}
// 获取分页结果
func GetPage(pageParam *PageParam, model any, conditionModel any, toModels any, orderBy ...string) *PageResult {
var count int64
err := global.Db.Model(model).Where(conditionModel).Count(&count).Error
biz.ErrIsNilAppendErr(err, " 查询错误:%s")
if count == 0 {
return &PageResult{Total: 0, List: []string{}}
}
page := pageParam.PageNum
pageSize := pageParam.PageSize
var orderByStr string
if orderBy == nil {
orderByStr = "id desc"
} else {
orderByStr = strings.Join(orderBy, ",")
}
err = global.Db.Model(model).Where(conditionModel).Order(orderByStr).Limit(pageSize).Offset((page - 1) * pageSize).Find(toModels).Error
biz.ErrIsNil(err, "查询失败")
return &PageResult{Total: count, List: toModels}
}
// 根据sql获取分页对象
func GetPageBySql(sql string, param *PageParam, toModel any, args ...any) *PageResult {
db := global.Db
selectIndex := strings.Index(sql, "SELECT ") + 7
fromIndex := strings.Index(sql, " FROM")
selectCol := sql[selectIndex:fromIndex]
countSql := strings.Replace(sql, selectCol, "COUNT(*) AS total ", 1)
// 查询count
var count int
err := db.Raw(countSql, args...).Scan(&count).Error
biz.ErrIsNilAppendErr(err, "查询失败: %s")
if count == 0 {
return &PageResult{Total: 0, List: []string{}}
}
// 分页查询
limitSql := sql + " LIMIT " + strconv.Itoa((param.PageNum-1)*param.PageSize) + ", " + strconv.Itoa(param.PageSize)
err = db.Raw(limitSql, args...).Scan(toModel).Error
biz.ErrIsNil(err, "查询失败: %s")
return &PageResult{Total: int64(count), List: toModel}
}
func GetListBySql(sql string, params ...any) []map[string]any {
var maps []map[string]any
global.Db.Raw(sql, params...).Scan(&maps)
return maps
}
func GetListBySql2Model(sql string, toEntity any, params ...any) error {
return global.Db.Raw(sql, params...).Find(toEntity).Error
}
func ExecSql(sql string, params ...any) {
global.Db.Exec(sql, params...)
}

View File

@@ -7,12 +7,12 @@ type PageParam struct {
}
// 分页结果
type PageResult struct {
type PageResult[T any] struct {
Total int64 `json:"total"`
List any `json:"list"`
List T `json:"list"`
}
// 空分页结果日志
func EmptyPageResult() *PageResult {
return &PageResult{Total: 0, List: make([]any, 0)}
// 空分页结果
func EmptyPageResult[T any]() *PageResult[T] {
return &PageResult[T]{Total: 0}
}