mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: 代码重构、分页数据组件支持多选
This commit is contained in:
@@ -72,7 +72,8 @@
|
|||||||
动态表头显示,根据表格每条配置项中的show字段来决定改列是否显示或者隐藏
|
动态表头显示,根据表格每条配置项中的show字段来决定改列是否显示或者隐藏
|
||||||
columns 就是我们表格配置的数组对象
|
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">
|
<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" />
|
<el-checkbox v-model="item.show" :label="item.label" :true-label="true" :false-label="false" />
|
||||||
</div>
|
</div>
|
||||||
@@ -84,15 +85,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-table v-bind="$attrs" max-height="700" @current-change="choose" :data="props.data" border
|
<el-table v-bind="$attrs" max-height="700" @selection-change="handleSelectionChange" :data="props.data" border
|
||||||
highlight-current-row show-overflow-tooltip>
|
highlight-current-row show-overflow-tooltip v-loading="loadingData">
|
||||||
<el-table-column v-if="props.showChooseColumn" label="选择" align="center" width="53px">
|
|
||||||
<template #default="scope">
|
<el-table-column v-if="props.showSelection" type="selection" width="40" />
|
||||||
<el-radio v-model="state.chooseId" :label="scope.row.id">
|
|
||||||
<i></i>
|
|
||||||
</el-radio>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<template v-for="(item, index) in columns">
|
<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"
|
<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 { toRefs, watch, reactive, onMounted } from 'vue';
|
||||||
import { TableColumn, TableQuery } from './index';
|
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({
|
const props = defineProps({
|
||||||
// 是否显示选择列
|
// 是否显示选择列
|
||||||
showChooseColumn: {
|
showSelection: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
// 选择列绑定的主键key字段名
|
|
||||||
chooseDataIdKey: {
|
|
||||||
type: String,
|
|
||||||
default: "id"
|
|
||||||
},
|
|
||||||
// 当前选择的数据
|
// 当前选择的数据
|
||||||
chooseData: {
|
selectionData: {
|
||||||
type: Object
|
type: Array<any>
|
||||||
},
|
},
|
||||||
// 列信息
|
// 列信息
|
||||||
columns: {
|
columns: {
|
||||||
@@ -190,27 +181,20 @@ const state = reactive({
|
|||||||
isOpenMoreQuery: false,
|
isOpenMoreQuery: false,
|
||||||
defaultQueryCount: 2, // 默认显示的查询参数个数
|
defaultQueryCount: 2, // 默认显示的查询参数个数
|
||||||
queryForm: {} as any,
|
queryForm: {} as any,
|
||||||
|
loadingData: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isOpenMoreQuery,
|
isOpenMoreQuery,
|
||||||
defaultQueryCount,
|
defaultQueryCount,
|
||||||
queryForm,
|
queryForm,
|
||||||
|
loadingData,
|
||||||
} = toRefs(state)
|
} = toRefs(state)
|
||||||
|
|
||||||
watch(() => props.queryForm, (newValue: any) => {
|
watch(() => props.queryForm, (newValue: any) => {
|
||||||
state.queryForm = newValue
|
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) => {
|
watch(() => props.pageNum, (newValue: any) => {
|
||||||
state.pageNum = newValue
|
state.pageNum = newValue
|
||||||
})
|
})
|
||||||
@@ -227,6 +211,7 @@ watch(() => props.data, (newValue: any) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
state.loadingData = false;
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -235,38 +220,44 @@ onMounted(() => {
|
|||||||
state.queryForm = props.queryForm;
|
state.queryForm = props.queryForm;
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理选中了列表中的某一条数据
|
const handleSelectionChange = (val: any) => {
|
||||||
const choose = (item: any) => {
|
emit('update:selectionData', val);
|
||||||
if (!item || !props.showChooseColumn) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
state.chooseData = item;
|
|
||||||
state.chooseId = item[props.chooseDataIdKey]
|
|
||||||
emit('update:chooseData', state.chooseData)
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePageChange = () => {
|
const handlePageChange = () => {
|
||||||
emit('update:pageNum', state.pageNum)
|
emit('update:pageNum', state.pageNum)
|
||||||
emit("pageChange")
|
execQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSizeChange = () => {
|
const handleSizeChange = () => {
|
||||||
emit('update:pageSize', state.pageSize)
|
emit('update:pageSize', state.pageSize);
|
||||||
emit("pageChange")
|
execQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryData = () => {
|
const queryData = () => {
|
||||||
// 触发重新调用查询接口即可
|
execQuery();
|
||||||
emit("pageChange")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
// 触发重新调用查询接口即可
|
// 触发重新调用查询接口即可
|
||||||
state.queryForm = {};
|
state.queryForm = {};
|
||||||
emit('update:queryForm', state.queryForm)
|
emit('update:queryForm', state.queryForm)
|
||||||
|
execQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
const execQuery = () => {
|
||||||
emit("pageChange")
|
emit("pageChange")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否正在加载数据
|
||||||
|
*/
|
||||||
|
const loading = (loading: boolean) => {
|
||||||
|
state.loadingData = loading;
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ loading })
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.page-table {
|
.page-table {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
<el-dialog title="OTP校验" v-model="otpDialog.visible" @close="loading.signIn = false" :close-on-click-modal="false"
|
<el-dialog title="OTP校验" v-model="otpDialog.visible" @close="loading.signIn = false" :close-on-click-modal="false"
|
||||||
width="350px" :destroy-on-close="true">
|
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="二维码">
|
<el-form-item v-if="otpDialog.otpUrl" label="二维码">
|
||||||
<qrcode-vue :value="otpDialog.otpUrl" :size="200" level="H" />
|
<qrcode-vue :value="otpDialog.otpUrl" :size="200" level="H" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="db-list">
|
<div class="db-list">
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="datas" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #tagPathSelect>
|
<template #tagPathSelect>
|
||||||
@@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button v-auth="permissions.saveDb" type="primary" icon="plus" @click="editDb(true)">添加</el-button>
|
<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"
|
<el-button v-auth="permissions.saveDb" :disabled="selectionData.length != 1" @click="editDb(false)"
|
||||||
icon="edit">编辑</el-button>
|
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.delDb" :disabled="selectionData.length < 1" @click="deleteDb()" type="danger"
|
||||||
icon="delete">删除</el-button>
|
icon="delete">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang='ts' setup>
|
<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 { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import { formatByteSize } from '@/common/utils/format';
|
import { formatByteSize } from '@/common/utils/format';
|
||||||
import { dbApi } from './api';
|
import { dbApi } from './api';
|
||||||
@@ -286,6 +286,8 @@ const permissions = {
|
|||||||
delDb: 'db:del',
|
delDb: 'db:del',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pageTableRef: any = ref(null)
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
row: {},
|
row: {},
|
||||||
dbId: 0,
|
dbId: 0,
|
||||||
@@ -294,7 +296,7 @@ const state = reactive({
|
|||||||
/**
|
/**
|
||||||
* 选中的数据
|
* 选中的数据
|
||||||
*/
|
*/
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
/**
|
/**
|
||||||
* 查询条件
|
* 查询条件
|
||||||
*/
|
*/
|
||||||
@@ -398,7 +400,7 @@ const {
|
|||||||
dbId,
|
dbId,
|
||||||
db,
|
db,
|
||||||
tags,
|
tags,
|
||||||
chooseData,
|
selectionData,
|
||||||
query,
|
query,
|
||||||
datas,
|
datas,
|
||||||
total,
|
total,
|
||||||
@@ -443,14 +445,19 @@ const filterTableInfos = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
let res: any = await dbApi.dbs.request(state.query);
|
try {
|
||||||
// 切割数据库
|
pageTableRef.value.loading(true);
|
||||||
res.list.forEach((e: any) => {
|
let res: any = await dbApi.dbs.request(state.query);
|
||||||
e.popoverSelectDbVisible = false;
|
// 切割数据库
|
||||||
e.dbs = e.database.split(' ');
|
res.list.forEach((e: any) => {
|
||||||
});
|
e.popoverSelectDbVisible = false;
|
||||||
state.datas = res.list;
|
e.dbs = e.database.split(' ');
|
||||||
state.total = res.total;
|
});
|
||||||
|
state.datas = res.list;
|
||||||
|
state.total = res.total;
|
||||||
|
} finally {
|
||||||
|
pageTableRef.value.loading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const showInfo = (info: any) => {
|
const showInfo = (info: any) => {
|
||||||
@@ -467,27 +474,25 @@ const editDb = async (isAdd = false) => {
|
|||||||
state.dbEditDialog.data = null;
|
state.dbEditDialog.data = null;
|
||||||
state.dbEditDialog.title = '新增数据库资源';
|
state.dbEditDialog.title = '新增数据库资源';
|
||||||
} else {
|
} else {
|
||||||
state.dbEditDialog.data = state.chooseData;
|
state.dbEditDialog.data = state.selectionData[0];
|
||||||
state.dbEditDialog.title = '修改数据库资源';
|
state.dbEditDialog.title = '修改数据库资源';
|
||||||
}
|
}
|
||||||
state.dbEditDialog.visible = true;
|
state.dbEditDialog.visible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const valChange = () => {
|
const valChange = () => {
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteDb = async (id: number) => {
|
const deleteDb = async () => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(`确定删除该库?`, '提示', {
|
await ElMessageBox.confirm(`确定删除【${state.selectionData.map((x: any) => x.name).join(", ")}】库?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
});
|
});
|
||||||
await dbApi.deleteDb.request({ id });
|
await dbApi.deleteDb.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
|
||||||
ElMessage.success('删除成功');
|
ElMessage.success('删除成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
} catch (err) { }
|
} catch (err) { }
|
||||||
};
|
};
|
||||||
@@ -626,7 +631,7 @@ const closeTableInfo = () => {
|
|||||||
const showColumns = async (row: any) => {
|
const showColumns = async (row: any) => {
|
||||||
state.chooseTableName = row.tableName;
|
state.chooseTableName = row.tableName;
|
||||||
state.columnDialog.columns = await dbApi.columnMetadata.request({
|
state.columnDialog.columns = await dbApi.columnMetadata.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbId,
|
||||||
db: state.db,
|
db: state.db,
|
||||||
tableName: row.tableName,
|
tableName: row.tableName,
|
||||||
});
|
});
|
||||||
@@ -637,7 +642,7 @@ const showColumns = async (row: any) => {
|
|||||||
const showTableIndex = async (row: any) => {
|
const showTableIndex = async (row: any) => {
|
||||||
state.chooseTableName = row.tableName;
|
state.chooseTableName = row.tableName;
|
||||||
state.indexDialog.indexs = await dbApi.tableIndex.request({
|
state.indexDialog.indexs = await dbApi.tableIndex.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbId,
|
||||||
db: state.db,
|
db: state.db,
|
||||||
tableName: row.tableName,
|
tableName: row.tableName,
|
||||||
});
|
});
|
||||||
@@ -648,7 +653,7 @@ const showTableIndex = async (row: any) => {
|
|||||||
const showCreateDdl = async (row: any) => {
|
const showCreateDdl = async (row: any) => {
|
||||||
state.chooseTableName = row.tableName;
|
state.chooseTableName = row.tableName;
|
||||||
const res = await dbApi.tableDdl.request({
|
const res = await dbApi.tableDdl.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbId,
|
||||||
db: state.db,
|
db: state.db,
|
||||||
tableName: row.tableName,
|
tableName: row.tableName,
|
||||||
});
|
});
|
||||||
@@ -669,10 +674,10 @@ const dropTable = async (row: any) => {
|
|||||||
});
|
});
|
||||||
SqlExecBox({
|
SqlExecBox({
|
||||||
sql: `DROP TABLE ${tableName}`,
|
sql: `DROP TABLE ${tableName}`,
|
||||||
dbId: state.chooseData.id,
|
dbId: state.dbId,
|
||||||
db: state.db,
|
db: state.db,
|
||||||
runSuccessCallback: async () => {
|
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) { }
|
} catch (err) { }
|
||||||
@@ -708,12 +713,12 @@ const openEditTable = async (row: any) => {
|
|||||||
if (row.tableName) {
|
if (row.tableName) {
|
||||||
state.tableCreateDialog.title = '修改表'
|
state.tableCreateDialog.title = '修改表'
|
||||||
let indexs = await dbApi.tableIndex.request({
|
let indexs = await dbApi.tableIndex.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbId,
|
||||||
db: state.db,
|
db: state.db,
|
||||||
tableName: row.tableName,
|
tableName: row.tableName,
|
||||||
});
|
});
|
||||||
let columns = await dbApi.columnMetadata.request({
|
let columns = await dbApi.columnMetadata.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbId,
|
||||||
db: state.db,
|
db: state.db,
|
||||||
tableName: row.tableName,
|
tableName: row.tableName,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
</el-link>
|
</el-link>
|
||||||
<el-divider direction="vertical" border-style="dashed" />
|
<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">
|
<div v-for="(item, index) in columns" :key="index">
|
||||||
<el-checkbox v-model="item.show"
|
<el-checkbox v-model="item.show"
|
||||||
:label="`${!item.columnComment ? item.columnName : item.columnName + ' [' + item.columnComment + ']'}`"
|
:label="`${!item.columnComment ? item.columnName : item.columnName + ' [' + item.columnComment + ']'}`"
|
||||||
:true-label="true" :false-label="false" />
|
:true-label="true" :false-label="false" size="small" />
|
||||||
</div>
|
</div>
|
||||||
<template #reference>
|
<template #reference>
|
||||||
<el-link icon="Operation" size="small" :underline="false"></el-link>
|
<el-link icon="Operation" size="small" :underline="false"></el-link>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
<el-table-column prop="name" label="名称" width>
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-input v-model="scope.row.name" size="small" :disabled="scope.row.id != null" clearable>
|
<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"
|
<el-progress v-if="uploadProgressShow" style="width: 90%; margin-left: 20px" :text-inside="true"
|
||||||
:stroke-width="20" :percentage="progressNum" />
|
:stroke-width="20" :percentage="progressNum" />
|
||||||
<div style="height: 45vh; overflow: auto">
|
<div style="height: 45vh; overflow: auto">
|
||||||
<el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode"
|
<el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode" :props="treeProps"
|
||||||
:props="treeProps" lazy node-key="id" :expand-on-click-node="true">
|
lazy node-key="id" :expand-on-click-node="true">
|
||||||
<template #default="{ node, data }">
|
<template #default="{ node, data }">
|
||||||
<span class="custom-tree-node">
|
<span class="custom-tree-node">
|
||||||
<el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
|
<el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
|
||||||
@@ -80,8 +80,7 @@
|
|||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
|
|
||||||
<span v-auth="'machine:file:write'">
|
<span v-auth="'machine:file:write'">
|
||||||
<el-dropdown-item @click="showCreateFileDialog(node)"
|
<el-dropdown-item @click="showCreateFileDialog(node)" v-if="data.type == 'd'">
|
||||||
v-if="data.type == 'd'">
|
|
||||||
<el-link type="primary" icon="document" :underline="false"
|
<el-link type="primary" icon="document" :underline="false"
|
||||||
style="margin-left: 2px">新建</el-link>
|
style="margin-left: 2px">新建</el-link>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@@ -148,8 +147,8 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<el-dialog :destroy-on-close="true" :title="fileContent.dialogTitle" v-model="fileContent.contentVisible" :close-on-click-modal="false"
|
<el-dialog :destroy-on-close="true" :title="fileContent.dialogTitle" v-model="fileContent.contentVisible"
|
||||||
top="5vh" width="70%">
|
:close-on-click-modal="false" top="5vh" width="70%">
|
||||||
<div>
|
<div>
|
||||||
<monaco-editor :can-change-mode="true" v-model="fileContent.content" :language="fileContent.type" />
|
<monaco-editor :can-change-mode="true" v-model="fileContent.content" :language="fileContent.type" />
|
||||||
</div>
|
</div>
|
||||||
@@ -206,6 +205,7 @@ const state = reactive({
|
|||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 8,
|
pageSize: 8,
|
||||||
},
|
},
|
||||||
|
loading: false,
|
||||||
form: {
|
form: {
|
||||||
id: null,
|
id: null,
|
||||||
type: null,
|
type: null,
|
||||||
@@ -250,6 +250,7 @@ const state = reactive({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
dialogVisible,
|
dialogVisible,
|
||||||
|
loading,
|
||||||
query,
|
query,
|
||||||
total,
|
total,
|
||||||
fileTable,
|
fileTable,
|
||||||
@@ -261,17 +262,22 @@ const {
|
|||||||
} = toRefs(state)
|
} = toRefs(state)
|
||||||
|
|
||||||
watch(props, async (newValue) => {
|
watch(props, async (newValue) => {
|
||||||
|
state.dialogVisible = newValue.visible;
|
||||||
if (newValue.machineId && newValue.visible) {
|
if (newValue.machineId && newValue.visible) {
|
||||||
await getFiles();
|
await getFiles();
|
||||||
}
|
}
|
||||||
state.dialogVisible = newValue.visible;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const getFiles = async () => {
|
const getFiles = async () => {
|
||||||
state.query.id = props.machineId as any;
|
try {
|
||||||
const res = await files.request(state.query);
|
state.loading = true;
|
||||||
state.fileTable = res.list;
|
state.query.id = props.machineId as any;
|
||||||
state.total = res.total;
|
const res = await files.request(state.query);
|
||||||
|
state.fileTable = res.list;
|
||||||
|
state.total = res.total;
|
||||||
|
} finally {
|
||||||
|
state.loading = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePageChange = (curPage: number) => {
|
const handlePageChange = (curPage: number) => {
|
||||||
@@ -589,6 +595,4 @@ const formatFileSize = (size: any) => {
|
|||||||
return '-';
|
return '-';
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss"></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="params" :show-choose-column="true"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="params" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="data.list" :columns="state.columns" :total="data.total"
|
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()">
|
v-model:page-size="params.pageSize" v-model:page-num="params.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #tagPathSelect>
|
<template #tagPathSelect>
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加
|
<el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button v-auth="'machine:update'" type="primary" icon="edit" :disabled="!chooseData"
|
<el-button v-auth="'machine:update'" type="primary" icon="edit" :disabled="selectionData.length != 1"
|
||||||
@click="openFormDialog(chooseData)" plain>编辑</el-button>
|
@click="openFormDialog(selectionData)" plain>编辑</el-button>
|
||||||
<el-button v-auth="'machine:del'" :disabled="!chooseData" @click="deleteMachine(chooseData.id)"
|
<el-button v-auth="'machine:del'" :disabled="selectionData.length < 1" @click="deleteMachine()"
|
||||||
type="danger" icon="delete">删除</el-button>
|
type="danger" icon="delete">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<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 { useRouter } from 'vue-router';
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import { machineApi } from './api';
|
import { machineApi } from './api';
|
||||||
@@ -165,6 +165,8 @@ const MachineRec = defineAsyncComponent(() => import('./MachineRec.vue'));
|
|||||||
const ProcessList = defineAsyncComponent(() => import('./ProcessList.vue'));
|
const ProcessList = defineAsyncComponent(() => import('./ProcessList.vue'));
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const pageTableRef: any = ref(null)
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
tags: [] as any,
|
tags: [] as any,
|
||||||
params: {
|
params: {
|
||||||
@@ -198,7 +200,7 @@ const state = reactive({
|
|||||||
data: null as any,
|
data: null as any,
|
||||||
},
|
},
|
||||||
// 当前选中数据
|
// 当前选中数据
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
serviceDialog: {
|
serviceDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
machineId: 0,
|
machineId: 0,
|
||||||
@@ -236,7 +238,7 @@ const {
|
|||||||
params,
|
params,
|
||||||
data,
|
data,
|
||||||
infoDialog,
|
infoDialog,
|
||||||
chooseData,
|
selectionData,
|
||||||
serviceDialog,
|
serviceDialog,
|
||||||
processDialog,
|
processDialog,
|
||||||
fileDialog,
|
fileDialog,
|
||||||
@@ -278,7 +280,7 @@ const getTags = async () => {
|
|||||||
const openFormDialog = async (machine: any) => {
|
const openFormDialog = async (machine: any) => {
|
||||||
let dialogTitle;
|
let dialogTitle;
|
||||||
if (machine) {
|
if (machine) {
|
||||||
state.machineEditDialog.data = state.chooseData as any;
|
state.machineEditDialog.data = state.selectionData[0];
|
||||||
dialogTitle = '编辑机器';
|
dialogTitle = '编辑机器';
|
||||||
} else {
|
} else {
|
||||||
state.machineEditDialog.data = null;
|
state.machineEditDialog.data = null;
|
||||||
@@ -289,16 +291,15 @@ const openFormDialog = async (machine: any) => {
|
|||||||
state.machineEditDialog.visible = true;
|
state.machineEditDialog.visible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteMachine = async (id: number) => {
|
const deleteMachine = async () => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(`确定删除该机器信息? 该操作将同时删除脚本及文件配置信息`, '提示', {
|
await ElMessageBox.confirm(`确定删除【${state.selectionData.map((x: any) => x.name).join(", ")}】机器信息? 该操作将同时删除脚本及文件配置信息`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
});
|
});
|
||||||
await machineApi.del.request({ id });
|
await machineApi.del.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
|
||||||
ElMessage.success('操作成功');
|
ElMessage.success('操作成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
} catch (err) { }
|
} catch (err) { }
|
||||||
};
|
};
|
||||||
@@ -329,19 +330,23 @@ const showMachineStats = async (machine: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const submitSuccess = () => {
|
const submitSuccess = () => {
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const showFileManage = (chooseData: any) => {
|
const showFileManage = (selectionData: any) => {
|
||||||
state.fileDialog.visible = true;
|
state.fileDialog.visible = true;
|
||||||
state.fileDialog.machineId = chooseData.id;
|
state.fileDialog.machineId = selectionData.id;
|
||||||
state.fileDialog.title = `${chooseData.name} => ${chooseData.ip}`;
|
state.fileDialog.title = `${selectionData.name} => ${selectionData.ip}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
const res = await machineApi.list.request(state.params);
|
try {
|
||||||
state.data = res;
|
pageTableRef.value.loading(true);
|
||||||
|
const res = await machineApi.list.request(state.params);
|
||||||
|
state.data = res;
|
||||||
|
} finally {
|
||||||
|
pageTableRef.value.loading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const showInfo = (info: any) => {
|
const showInfo = (info: any) => {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
<el-button @click="editScript(currentData)" :disabled="currentId == null" type="primary"
|
<el-button @click="editScript(currentData)" :disabled="currentId == null" type="primary" icon="tickets"
|
||||||
icon="tickets" size="small" plain>查看</el-button>
|
size="small" plain>查看</el-button>
|
||||||
<el-button v-auth="'machine:script:save'" type="primary" @click="editScript(null)" icon="plus"
|
<el-button v-auth="'machine:script:save'" type="primary" @click="editScript(null)" icon="plus"
|
||||||
size="small" plain>添加</el-button>
|
size="small" plain>添加</el-button>
|
||||||
<el-button v-auth="'machine:script:del'" :disabled="currentId == null" type="danger"
|
<el-button v-auth="'machine:script:del'" :disabled="currentId == null" type="danger"
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<el-table-column label="选择" width="55px">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-radio v-model="currentId" :label="scope.row.id">
|
<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 v-if="scope.row.id == null" type="success" icon="el-icon-success" size="small" plain>
|
||||||
确定</el-button>
|
确定</el-button>
|
||||||
|
|
||||||
<el-button v-auth="'machine:script:run'" v-if="scope.row.id != null"
|
<el-button v-auth="'machine:script:run'" v-if="scope.row.id != null" @click="runScript(scope.row)"
|
||||||
@click="runScript(scope.row)" type="primary" icon="video-play" size="small" plain>执行
|
type="primary" icon="video-play" size="small" plain>执行
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -54,8 +55,8 @@
|
|||||||
|
|
||||||
<el-dialog title="脚本参数" v-model="scriptParamsDialog.visible" width="400px">
|
<el-dialog title="脚本参数" v-model="scriptParamsDialog.visible" width="400px">
|
||||||
<el-form ref="paramsForm" :model="scriptParamsDialog.params" label-width="70px" size="small">
|
<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"
|
<el-form-item v-for="item in scriptParamsDialog.paramsFormItem as any" :key="item.name" :prop="item.model"
|
||||||
:prop="item.model" :label="item.name" required>
|
:label="item.name" required>
|
||||||
<el-input v-if="!item.options" v-model="scriptParamsDialog.params[item.model]"
|
<el-input v-if="!item.options" v-model="scriptParamsDialog.params[item.model]"
|
||||||
:placeholder="item.placeholder" autocomplete="off" clearable></el-input>
|
:placeholder="item.placeholder" autocomplete="off" clearable></el-input>
|
||||||
<el-select v-else v-model="scriptParamsDialog.params[item.model]" :placeholder="item.placeholder"
|
<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%"
|
<el-dialog v-if="terminalDialog.visible" title="终端" v-model="terminalDialog.visible" width="80%"
|
||||||
:close-on-click-modal="false" :modal="false" @close="closeTermnial">
|
:close-on-click-modal="false" :modal="false" @close="closeTermnial">
|
||||||
<ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId"
|
<ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId" height="560px" />
|
||||||
height="560px" />
|
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<script-edit v-model:visible="editDialog.visible" v-model:data="editDialog.data" :title="editDialog.title"
|
<script-edit v-model:visible="editDialog.visible" v-model:data="editDialog.data" :title="editDialog.title"
|
||||||
@@ -111,6 +111,7 @@ const state = reactive({
|
|||||||
type: 0,
|
type: 0,
|
||||||
currentId: null,
|
currentId: null,
|
||||||
currentData: null,
|
currentData: null,
|
||||||
|
loading: false,
|
||||||
query: {
|
query: {
|
||||||
machineId: 0 as any,
|
machineId: 0 as any,
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -142,6 +143,7 @@ const state = reactive({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
dialogVisible,
|
dialogVisible,
|
||||||
|
loading,
|
||||||
type,
|
type,
|
||||||
currentId,
|
currentId,
|
||||||
currentData,
|
currentData,
|
||||||
@@ -155,19 +157,24 @@ const {
|
|||||||
} = toRefs(state)
|
} = toRefs(state)
|
||||||
|
|
||||||
watch(props, async (newValue) => {
|
watch(props, async (newValue) => {
|
||||||
|
state.dialogVisible = newValue.visible;
|
||||||
if (props.machineId && newValue.visible) {
|
if (props.machineId && newValue.visible) {
|
||||||
await getScripts();
|
await getScripts();
|
||||||
}
|
}
|
||||||
state.dialogVisible = newValue.visible;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const getScripts = async () => {
|
const getScripts = async () => {
|
||||||
state.currentId = null;
|
try {
|
||||||
state.currentData = null;
|
state.loading = true;
|
||||||
state.query.machineId = state.type == 0 ? props.machineId : 9999999;
|
state.currentId = null;
|
||||||
const res = await machineApi.scripts.request(state.query);
|
state.currentData = null;
|
||||||
state.scriptTable = res.list;
|
state.query.machineId = state.type == 0 ? props.machineId : 9999999;
|
||||||
state.total = res.total;
|
const res = await machineApi.scripts.request(state.query);
|
||||||
|
state.scriptTable = res.list;
|
||||||
|
state.total = res.total;
|
||||||
|
} finally {
|
||||||
|
state.loading = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePageChange = (curPage: number) => {
|
const handlePageChange = (curPage: number) => {
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="authcerts" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button type="primary" icon="plus" @click="edit(false)">添加</el-button>
|
<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>
|
||||||
<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>
|
</el-button>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
@@ -52,7 +53,7 @@ const state = reactive({
|
|||||||
],
|
],
|
||||||
total: 0,
|
total: 0,
|
||||||
authcerts: [],
|
authcerts: [],
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
paramsDialog: {
|
paramsDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
config: null as any,
|
config: null as any,
|
||||||
@@ -70,7 +71,7 @@ const {
|
|||||||
query,
|
query,
|
||||||
total,
|
total,
|
||||||
authcerts,
|
authcerts,
|
||||||
chooseData,
|
selectionData,
|
||||||
editor,
|
editor,
|
||||||
} = toRefs(state)
|
} = toRefs(state)
|
||||||
|
|
||||||
@@ -86,13 +87,12 @@ const search = async () => {
|
|||||||
|
|
||||||
const editChange = () => {
|
const editChange = () => {
|
||||||
ElMessage.success('保存成功');
|
ElMessage.success('保存成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const edit = (data: any) => {
|
const edit = (data: any) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
state.editor.authcert = data;
|
state.editor.authcert = data[0];
|
||||||
} else {
|
} else {
|
||||||
state.editor.authcert = false;
|
state.editor.authcert = false;
|
||||||
}
|
}
|
||||||
@@ -102,14 +102,13 @@ const edit = (data: any) => {
|
|||||||
|
|
||||||
const deleteAc = async (data: any) => {
|
const deleteAc = async (data: any) => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(`确定删除该授权凭证?`, '提示', {
|
await ElMessageBox.confirm(`确定删除该【${data.map((x: any) => x.name).join(", ")}授权凭证?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
});
|
});
|
||||||
await authCertApi.delete.request({ id: data.id });
|
await authCertApi.delete.request({ id: data.map((x: any) => x.id).join(",") });
|
||||||
ElMessage.success('删除成功');
|
ElMessage.success('删除成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
} catch (err) { }
|
} catch (err) { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="list" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #tagPathSelect>
|
<template #tagPathSelect>
|
||||||
@@ -13,9 +13,10 @@
|
|||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button type="primary" icon="plus" @click="editMongo(true)" plain>添加</el-button>
|
<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>
|
||||||
<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>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { mongoApi } from './api';
|
import { mongoApi } from './api';
|
||||||
import { toRefs, reactive, onMounted } from 'vue';
|
import { ref, toRefs, reactive, onMounted } from 'vue';
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import { tagApi } from '../tag/api';
|
import { tagApi } from '../tag/api';
|
||||||
import MongoEdit from './MongoEdit.vue';
|
import MongoEdit from './MongoEdit.vue';
|
||||||
@@ -178,6 +179,8 @@ import TagInfo from '../component/TagInfo.vue';
|
|||||||
import PageTable from '@/components/pagetable/PageTable.vue'
|
import PageTable from '@/components/pagetable/PageTable.vue'
|
||||||
import { TableColumn, TableQuery } from '@/components/pagetable';
|
import { TableColumn, TableQuery } from '@/components/pagetable';
|
||||||
|
|
||||||
|
const pageTableRef: any = ref(null)
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
tags: [],
|
tags: [],
|
||||||
dbOps: {
|
dbOps: {
|
||||||
@@ -186,7 +189,7 @@ const state = reactive({
|
|||||||
},
|
},
|
||||||
list: [],
|
list: [],
|
||||||
total: 0,
|
total: 0,
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
query: {
|
query: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
@@ -241,7 +244,7 @@ const {
|
|||||||
tags,
|
tags,
|
||||||
list,
|
list,
|
||||||
total,
|
total,
|
||||||
chooseData,
|
selectionData,
|
||||||
query,
|
query,
|
||||||
mongoEditDialog,
|
mongoEditDialog,
|
||||||
databaseDialog,
|
databaseDialog,
|
||||||
@@ -264,7 +267,7 @@ const showDatabases = async (id: number) => {
|
|||||||
|
|
||||||
const showDatabaseStats = async (dbName: string) => {
|
const showDatabaseStats = async (dbName: string) => {
|
||||||
state.databaseDialog.statsDialog.data = await mongoApi.runCommand.request({
|
state.databaseDialog.statsDialog.data = await mongoApi.runCommand.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbOps.dbId,
|
||||||
database: dbName,
|
database: dbName,
|
||||||
command: {
|
command: {
|
||||||
dbStats: 1,
|
dbStats: 1,
|
||||||
@@ -283,7 +286,7 @@ const showCollections = async (database: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const setCollections = 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;
|
const collections = [] as any;
|
||||||
for (let r of res) {
|
for (let r of res) {
|
||||||
collections.push({ name: r });
|
collections.push({ name: r });
|
||||||
@@ -296,7 +299,7 @@ const setCollections = async (database: string) => {
|
|||||||
*/
|
*/
|
||||||
const showCollectionStats = async (collection: string) => {
|
const showCollectionStats = async (collection: string) => {
|
||||||
state.collectionsDialog.statsDialog.data = await mongoApi.runCommand.request({
|
state.collectionsDialog.statsDialog.data = await mongoApi.runCommand.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbOps.dbId,
|
||||||
database: state.collectionsDialog.database,
|
database: state.collectionsDialog.database,
|
||||||
command: {
|
command: {
|
||||||
collStats: collection,
|
collStats: collection,
|
||||||
@@ -311,7 +314,7 @@ const showCollectionStats = async (collection: string) => {
|
|||||||
*/
|
*/
|
||||||
const onDeleteCollection = async (collection: string) => {
|
const onDeleteCollection = async (collection: string) => {
|
||||||
await mongoApi.runCommand.request({
|
await mongoApi.runCommand.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbOps.dbId,
|
||||||
database: state.collectionsDialog.database,
|
database: state.collectionsDialog.database,
|
||||||
command: {
|
command: {
|
||||||
drop: collection,
|
drop: collection,
|
||||||
@@ -328,7 +331,7 @@ const showCreateCollectionDialog = () => {
|
|||||||
const onCreateCollection = async () => {
|
const onCreateCollection = async () => {
|
||||||
const form = state.createCollectionDialog.form;
|
const form = state.createCollectionDialog.form;
|
||||||
await mongoApi.runCommand.request({
|
await mongoApi.runCommand.request({
|
||||||
id: state.chooseData.id,
|
id: state.dbOps.dbId,
|
||||||
database: state.collectionsDialog.database,
|
database: state.collectionsDialog.database,
|
||||||
command: {
|
command: {
|
||||||
create: form.name,
|
create: form.name,
|
||||||
@@ -342,22 +345,26 @@ const onCreateCollection = async () => {
|
|||||||
|
|
||||||
const deleteMongo = async () => {
|
const deleteMongo = async () => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(`确定删除该mongo?`, '提示', {
|
await ElMessageBox.confirm(`确定删除【${state.selectionData.map((x: any) => x.name).join(", ")}】mongo信息?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
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('删除成功');
|
ElMessage.success('删除成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
} catch (err) { }
|
} catch (err) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
const res = await mongoApi.mongoList.request(state.query);
|
try {
|
||||||
state.list = res.list;
|
pageTableRef.value.loading(true);
|
||||||
state.total = res.total;
|
const res = await mongoApi.mongoList.request(state.query);
|
||||||
|
state.list = res.list;
|
||||||
|
state.total = res.total;
|
||||||
|
} finally {
|
||||||
|
pageTableRef.value.loading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTags = async () => {
|
const getTags = async () => {
|
||||||
@@ -369,14 +376,13 @@ const editMongo = async (isAdd = false) => {
|
|||||||
state.mongoEditDialog.data = null;
|
state.mongoEditDialog.data = null;
|
||||||
state.mongoEditDialog.title = '新增mongo';
|
state.mongoEditDialog.title = '新增mongo';
|
||||||
} else {
|
} else {
|
||||||
state.mongoEditDialog.data = state.chooseData;
|
state.mongoEditDialog.data = state.selectionData[0];
|
||||||
state.mongoEditDialog.title = '修改mongo';
|
state.mongoEditDialog.title = '修改mongo';
|
||||||
}
|
}
|
||||||
state.mongoEditDialog.visible = true;
|
state.mongoEditDialog.visible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const valChange = () => {
|
const valChange = () => {
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ const setHeight = () => {
|
|||||||
const instMap: Map<string, any[]> = new Map();
|
const instMap: Map<string, any[]> = new Map();
|
||||||
|
|
||||||
const getInsts = async () => {
|
const getInsts = async () => {
|
||||||
const res = await redisApi.redisList.request({});
|
const res = await redisApi.redisList.request({ pageNum: 1, pageSize: 1000 });
|
||||||
if (!res.total) return
|
if (!res.total) return
|
||||||
for (const redisInfo of res.list) {
|
for (const redisInfo of res.list) {
|
||||||
const tagPath = redisInfo.tagPath;
|
const tagPath = redisInfo.tagPath;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="redisTable" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #tagPathSelect>
|
<template #tagPathSelect>
|
||||||
@@ -13,9 +13,10 @@
|
|||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button type="primary" icon="plus" @click="editRedis(true)" plain>添加</el-button>
|
<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>
|
||||||
<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>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Info from './Info.vue';
|
import Info from './Info.vue';
|
||||||
import { redisApi } from './api';
|
import { redisApi } from './api';
|
||||||
import { toRefs, reactive, onMounted } from 'vue';
|
import { ref, toRefs, reactive, onMounted } from 'vue';
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import { tagApi } from '../tag/api';
|
import { tagApi } from '../tag/api';
|
||||||
import RedisEdit from './RedisEdit.vue';
|
import RedisEdit from './RedisEdit.vue';
|
||||||
@@ -151,11 +152,13 @@ import TagInfo from '../component/TagInfo.vue';
|
|||||||
import PageTable from '@/components/pagetable/PageTable.vue'
|
import PageTable from '@/components/pagetable/PageTable.vue'
|
||||||
import { TableColumn, TableQuery } from '@/components/pagetable';
|
import { TableColumn, TableQuery } from '@/components/pagetable';
|
||||||
|
|
||||||
|
const pageTableRef: any = ref(null)
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
tags: [],
|
tags: [],
|
||||||
redisTable: [],
|
redisTable: [],
|
||||||
total: 0,
|
total: 0,
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
query: {
|
query: {
|
||||||
tagPath: null,
|
tagPath: null,
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -204,7 +207,7 @@ const {
|
|||||||
tags,
|
tags,
|
||||||
redisTable,
|
redisTable,
|
||||||
total,
|
total,
|
||||||
chooseData,
|
selectionData,
|
||||||
query,
|
query,
|
||||||
detailDialog,
|
detailDialog,
|
||||||
clusterInfoDialog,
|
clusterInfoDialog,
|
||||||
@@ -224,14 +227,13 @@ const showDetail = (detail: any) => {
|
|||||||
|
|
||||||
const deleteRedis = async () => {
|
const deleteRedis = async () => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(`确定删除该redis?`, '提示', {
|
await ElMessageBox.confirm(`确定删除该【${state.selectionData.map((x: any) => x.name).join(", ")}】redis信息?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
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('删除成功');
|
ElMessage.success('删除成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
} catch (err) { }
|
} catch (err) { }
|
||||||
};
|
};
|
||||||
@@ -256,9 +258,15 @@ const onShowClusterInfo = async (redis: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
const res = await redisApi.redisList.request(state.query);
|
try {
|
||||||
state.redisTable = res.list;
|
pageTableRef.value.loading(true);
|
||||||
state.total = res.total;
|
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 () => {
|
const getTags = async () => {
|
||||||
@@ -270,14 +278,13 @@ const editRedis = async (isAdd = false) => {
|
|||||||
state.redisEditDialog.data = null;
|
state.redisEditDialog.data = null;
|
||||||
state.redisEditDialog.title = '新增redis';
|
state.redisEditDialog.title = '新增redis';
|
||||||
} else {
|
} else {
|
||||||
state.redisEditDialog.data = state.chooseData;
|
state.redisEditDialog.data = state.selectionData[0];
|
||||||
state.redisEditDialog.title = '修改redis';
|
state.redisEditDialog.title = '修改redis';
|
||||||
}
|
}
|
||||||
state.redisEditDialog.visible = true;
|
state.redisEditDialog.visible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const valChange = () => {
|
const valChange = () => {
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="data" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button v-auth="'team:save'" type="primary" icon="plus" @click="showSaveTeamDialog(false)">添加</el-button>
|
<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>
|
icon="delete">删除</el-button>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
@@ -167,7 +167,7 @@ const state = reactive({
|
|||||||
],
|
],
|
||||||
total: 0,
|
total: 0,
|
||||||
data: [],
|
data: [],
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
showMemDialog: {
|
showMemDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
chooseId: 0,
|
chooseId: 0,
|
||||||
@@ -209,7 +209,7 @@ const {
|
|||||||
addTeamDialog,
|
addTeamDialog,
|
||||||
total,
|
total,
|
||||||
data,
|
data,
|
||||||
chooseData,
|
selectionData,
|
||||||
showMemDialog,
|
showMemDialog,
|
||||||
showTagDialog,
|
showTagDialog,
|
||||||
} = toRefs(state)
|
} = toRefs(state)
|
||||||
@@ -252,15 +252,14 @@ const cancelSaveTeam = () => {
|
|||||||
teamForm.value.resetFields();
|
teamForm.value.resetFields();
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteTeam = (data: any) => {
|
const deleteTeam = () => {
|
||||||
ElMessageBox.confirm(`此操作将删除 [${data.name}], 是否继续?`, '提示', {
|
ElMessageBox.confirm(`此操作将删除【${state.selectionData.map((x: any) => x.name).join(", ")}】团队信息, 是否继续?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
}).then(async () => {
|
}).then(async () => {
|
||||||
await tagApi.delTeam.request({ id: data.id });
|
await tagApi.delTeam.request({ id: state.selectionData.map((x: any) => x.id).join(",") });
|
||||||
ElMessage.success('删除成功!');
|
ElMessage.success('删除成功!');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -315,7 +314,7 @@ const showAddMemberDialog = () => {
|
|||||||
|
|
||||||
const addMember = async () => {
|
const addMember = async () => {
|
||||||
const memForm = state.showMemDialog.memForm;
|
const memForm = state.showMemDialog.memForm;
|
||||||
memForm.teamId = state.chooseData.id;
|
memForm.teamId = (state.selectionData[0] as any).id;
|
||||||
notBlank(memForm.accountIds, '请先选择账号');
|
notBlank(memForm.accountIds, '请先选择账号');
|
||||||
|
|
||||||
await tagApi.saveTeamMem.request(memForm);
|
await tagApi.saveTeamMem.request(memForm);
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="datas" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button v-auth="'account:add'" type="primary" icon="plus" @click="editAccount(true)">添加</el-button>
|
<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>
|
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>
|
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>
|
type="danger" icon="delete">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang='ts' setup>
|
<script lang='ts' setup>
|
||||||
import { toRefs, reactive, onMounted } from 'vue';
|
import { ref, toRefs, reactive, onMounted } from 'vue';
|
||||||
import RoleEdit from './RoleEdit.vue';
|
import RoleEdit from './RoleEdit.vue';
|
||||||
import AccountEdit from './AccountEdit.vue';
|
import AccountEdit from './AccountEdit.vue';
|
||||||
import enums from '../enums';
|
import enums from '../enums';
|
||||||
@@ -80,11 +80,13 @@ import { dateFormat } from '@/common/utils/date';
|
|||||||
import PageTable from '@/components/pagetable/PageTable.vue'
|
import PageTable from '@/components/pagetable/PageTable.vue'
|
||||||
import { TableColumn, TableQuery } from '@/components/pagetable';
|
import { TableColumn, TableQuery } from '@/components/pagetable';
|
||||||
|
|
||||||
|
const pageTableRef: any = ref(null)
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
/**
|
/**
|
||||||
* 选中的数据
|
* 选中的数据
|
||||||
*/
|
*/
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
/**
|
/**
|
||||||
* 查询条件
|
* 查询条件
|
||||||
*/
|
*/
|
||||||
@@ -136,6 +138,7 @@ const state = reactive({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
selectionData,
|
||||||
query,
|
query,
|
||||||
datas,
|
datas,
|
||||||
total,
|
total,
|
||||||
@@ -150,9 +153,14 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
let res: any = await accountApi.list.request(state.query);
|
try {
|
||||||
state.datas = res.list;
|
pageTableRef.value.loading(true);
|
||||||
state.total = res.total;
|
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) => {
|
const showResources = async (row: any) => {
|
||||||
@@ -194,24 +202,16 @@ const resetOtpSecret = async (row: any) => {
|
|||||||
row.otpSecret = "-";
|
row.otpSecret = "-";
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePageChange = (curPage: number) => {
|
|
||||||
state.query.pageNum = curPage;
|
|
||||||
search();
|
|
||||||
};
|
|
||||||
|
|
||||||
const showRoleEdit = () => {
|
const showRoleEdit = () => {
|
||||||
if (!state.chooseData) {
|
|
||||||
ElMessage.error('请选择账号');
|
|
||||||
}
|
|
||||||
state.roleDialog.visible = true;
|
state.roleDialog.visible = true;
|
||||||
state.roleDialog.account = state.chooseData;
|
state.roleDialog.account = state.selectionData[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
const editAccount = (isAdd = false) => {
|
const editAccount = (isAdd = false) => {
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
state.accountDialog.data = null;
|
state.accountDialog.data = null;
|
||||||
} else {
|
} else {
|
||||||
state.accountDialog.data = state.chooseData;
|
state.accountDialog.data = state.selectionData[0];
|
||||||
}
|
}
|
||||||
state.accountDialog.visible = true;
|
state.accountDialog.visible = true;
|
||||||
};
|
};
|
||||||
@@ -229,14 +229,13 @@ const valChange = () => {
|
|||||||
|
|
||||||
const deleteAccount = async () => {
|
const deleteAccount = async () => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(`确定删除该账号?`, '提示', {
|
await ElMessageBox.confirm(`确定删除【${state.selectionData.map((x: any) => x.name).join(", ")}】的账号?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
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('删除成功');
|
ElMessage.success('删除成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
} catch (err) { }
|
} catch (err) { }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :show-choose-column="true" v-model:choose-data="state.chooseData" :data="configs"
|
<page-table :show-selection="true" v-model:selection-data="selectionData" :data="configs" :columns="state.columns"
|
||||||
:columns="state.columns" :total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum"
|
:total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
@pageChange="search()">
|
|
||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button v-auth="'config:save'" type="primary" icon="plus" @click="editConfig(false)">添加</el-button>
|
<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)"
|
<el-button v-auth="'config:save'" :disabled="state.selectionData.length != 1"
|
||||||
type="primary" icon="edit">编辑
|
@click="editConfig(state.selectionData[0])" type="primary" icon="edit">编辑
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -81,7 +80,7 @@ const state = reactive({
|
|||||||
],
|
],
|
||||||
total: 0,
|
total: 0,
|
||||||
configs: [],
|
configs: [],
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
paramsDialog: {
|
paramsDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
config: null as any,
|
config: null as any,
|
||||||
@@ -99,7 +98,7 @@ const {
|
|||||||
query,
|
query,
|
||||||
total,
|
total,
|
||||||
configs,
|
configs,
|
||||||
chooseData,
|
selectionData,
|
||||||
paramsDialog,
|
paramsDialog,
|
||||||
configEdit,
|
configEdit,
|
||||||
} = toRefs(state)
|
} = toRefs(state)
|
||||||
@@ -187,7 +186,6 @@ const hasParam = (paramKey: string, paramItems: any) => {
|
|||||||
|
|
||||||
const configEditChange = () => {
|
const configEditChange = () => {
|
||||||
ElMessage.success('保存成功');
|
ElMessage.success('保存成功');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :show-choose-column="true"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :show-selection="true"
|
||||||
v-model:choose-data="state.chooseData" :data="roles" :columns="state.columns" :total="total"
|
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()">
|
v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
||||||
|
|
||||||
<template #queryRight>
|
<template #queryRight>
|
||||||
<el-button v-auth="'role:add'" type="primary" icon="plus" @click="editRole(false)">添加</el-button>
|
<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>
|
type="primary" icon="edit">编辑</el-button>
|
||||||
<el-button v-auth="'role:saveResources'" :disabled="chooseData == null" @click="editResource(chooseData)"
|
<el-button v-auth="'role:saveResources'" :disabled="selectionData.length != 1"
|
||||||
type="success" icon="setting">分配菜单&权限</el-button>
|
@click="editResource(selectionData)" type="success" icon="setting">分配菜单&权限</el-button>
|
||||||
<el-button v-auth="'role:del'" :disabled="chooseData == null" @click="deleteRole(chooseData)" type="danger"
|
<el-button v-auth="'role:del'" :disabled="selectionData.length < 1" @click="deleteRole(selectionData)"
|
||||||
icon="delete">删除</el-button>
|
type="danger" icon="delete">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #status="{ data }">
|
<template #status="{ data }">
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { toRefs, reactive, onMounted } from 'vue';
|
import { ref, toRefs, reactive, onMounted } from 'vue';
|
||||||
import RoleEdit from './RoleEdit.vue';
|
import RoleEdit from './RoleEdit.vue';
|
||||||
import ResourceEdit from './ResourceEdit.vue';
|
import ResourceEdit from './ResourceEdit.vue';
|
||||||
import ShowResource from './ShowResource.vue';
|
import ShowResource from './ShowResource.vue';
|
||||||
@@ -44,6 +44,8 @@ import { ElMessage, ElMessageBox } from 'element-plus';
|
|||||||
import PageTable from '@/components/pagetable/PageTable.vue'
|
import PageTable from '@/components/pagetable/PageTable.vue'
|
||||||
import { TableColumn, TableQuery } from '@/components/pagetable';
|
import { TableColumn, TableQuery } from '@/components/pagetable';
|
||||||
|
|
||||||
|
const pageTableRef: any = ref(null)
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
query: {
|
query: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -66,7 +68,7 @@ const state = reactive({
|
|||||||
],
|
],
|
||||||
total: 0,
|
total: 0,
|
||||||
roles: [],
|
roles: [],
|
||||||
chooseData: null as any,
|
selectionData: [],
|
||||||
resourceDialog: {
|
resourceDialog: {
|
||||||
visible: false,
|
visible: false,
|
||||||
role: {},
|
role: {},
|
||||||
@@ -89,7 +91,7 @@ const {
|
|||||||
query,
|
query,
|
||||||
total,
|
total,
|
||||||
roles,
|
roles,
|
||||||
chooseData,
|
selectionData,
|
||||||
resourceDialog,
|
resourceDialog,
|
||||||
roleEditDialog,
|
roleEditDialog,
|
||||||
showResourceDialog,
|
showResourceDialog,
|
||||||
@@ -100,20 +102,24 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
let res = await roleApi.list.request(state.query);
|
try {
|
||||||
state.roles = res.list;
|
pageTableRef.value.loading(true);
|
||||||
state.total = res.total;
|
let res = await roleApi.list.request(state.query);
|
||||||
|
state.roles = res.list;
|
||||||
|
state.total = res.total;
|
||||||
|
} finally {
|
||||||
|
pageTableRef.value.loading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const roleEditChange = () => {
|
const roleEditChange = () => {
|
||||||
ElMessage.success('修改成功!');
|
ElMessage.success('修改成功!');
|
||||||
state.chooseData = null;
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const editRole = (data: any) => {
|
const editRole = (data: any) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
state.roleEditDialog.role = data;
|
state.roleEditDialog.role = data[0];
|
||||||
} else {
|
} else {
|
||||||
state.roleEditDialog.role = false;
|
state.roleEditDialog.role = false;
|
||||||
}
|
}
|
||||||
@@ -124,7 +130,7 @@ const editRole = (data: any) => {
|
|||||||
const deleteRole = async (data: any) => {
|
const deleteRole = async (data: any) => {
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(
|
await ElMessageBox.confirm(
|
||||||
`此操作将删除 [${data.name}] 该角色,以及与该角色有关的账号角色关联信息和资源角色关联信息, 是否继续?`,
|
`此操作将删除【${data.map((x: any) => x.name).join(", ")}】该角色,以及与该角色有关的账号角色关联信息和资源角色关联信息, 是否继续?`,
|
||||||
'提示',
|
'提示',
|
||||||
{
|
{
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
@@ -133,7 +139,7 @@ const deleteRole = async (data: any) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await roleApi.del.request({
|
await roleApi.del.request({
|
||||||
id: data.id,
|
id: data.map((x: any) => x.id).join(","),
|
||||||
});
|
});
|
||||||
ElMessage.success('删除成功!');
|
ElMessage.success('删除成功!');
|
||||||
search();
|
search();
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<page-table :query="state.queryConfig" v-model:query-form="query" :data="logs" :columns="state.columns"
|
<page-table ref="pageTableRef" :query="state.queryConfig" v-model:query-form="query" :data="logs"
|
||||||
:total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum" @pageChange="search()">
|
:columns="state.columns" :total="total" v-model:page-size="query.pageSize" v-model:page-num="query.pageNum"
|
||||||
|
@pageChange="search()">
|
||||||
|
|
||||||
<template #selectAccount>
|
<template #selectAccount>
|
||||||
<el-select remote :remote-method="getAccount" v-model="query.creatorId" filterable placeholder="请输入并选择账号"
|
<el-select remote :remote-method="getAccount" v-model="query.creatorId" filterable placeholder="请输入并选择账号"
|
||||||
@@ -20,11 +21,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { toRefs, reactive, onMounted } from 'vue';
|
import { ref, toRefs, reactive, onMounted } from 'vue';
|
||||||
import { logApi, accountApi } from '../api';
|
import { logApi, accountApi } from '../api';
|
||||||
import PageTable from '@/components/pagetable/PageTable.vue'
|
import PageTable from '@/components/pagetable/PageTable.vue'
|
||||||
import { TableColumn, TableQuery } from '@/components/pagetable';
|
import { TableColumn, TableQuery } from '@/components/pagetable';
|
||||||
|
|
||||||
|
const pageTableRef: any = ref(null);
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
query: {
|
query: {
|
||||||
type: null,
|
type: null,
|
||||||
@@ -64,9 +67,14 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
let res = await logApi.list.request(state.query);
|
try {
|
||||||
state.logs = res.list;
|
pageTableRef.value.loading(true);
|
||||||
state.total = res.total;
|
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) => {
|
const getAccount = (username: any) => {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
tagapp "mayfly-go/internal/tag/application"
|
tagapp "mayfly-go/internal/tag/application"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
@@ -40,7 +41,7 @@ func (d *Db) Dbs(rc *req.Ctx) {
|
|||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
if len(tagIds) == 0 {
|
if len(tagIds) == 0 {
|
||||||
rc.ResData = model.EmptyPageResult()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
condition.TagIds = tagIds
|
||||||
@@ -96,10 +97,18 @@ func (d *Db) GetDatabaseNames(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Db) DeleteDb(rc *req.Ctx) {
|
func (d *Db) DeleteDb(rc *req.Ctx) {
|
||||||
dbId := GetDbId(rc.GinCtx)
|
idsStr := ginx.PathParam(rc.GinCtx, "dbId")
|
||||||
d.DbApp.Delete(dbId)
|
rc.ReqParam = idsStr
|
||||||
// 删除该库的sql执行记录
|
ids := strings.Split(idsStr, ",")
|
||||||
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
|
|
||||||
|
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) {
|
func (d *Db) TableInfos(rc *req.Ctx) {
|
||||||
@@ -381,21 +390,21 @@ func (d *Db) SaveSql(rc *req.Ctx) {
|
|||||||
|
|
||||||
dbId := GetDbId(g)
|
dbId := GetDbId(g)
|
||||||
// 判断dbId是否存在
|
// 判断dbId是否存在
|
||||||
err := model.GetById(new(entity.Db), dbId)
|
err := gormx.GetById(new(entity.Db), dbId)
|
||||||
biz.ErrIsNil(err, "该数据库信息不存在")
|
biz.ErrIsNil(err, "该数据库信息不存在")
|
||||||
|
|
||||||
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
||||||
dbSql := &entity.DbSql{Type: dbSqlForm.Type, DbId: dbId, Name: dbSqlForm.Name, Db: dbSqlForm.Db}
|
dbSql := &entity.DbSql{Type: dbSqlForm.Type, DbId: dbId, Name: dbSqlForm.Name, Db: dbSqlForm.Db}
|
||||||
dbSql.CreatorId = account.Id
|
dbSql.CreatorId = account.Id
|
||||||
e := model.GetBy(dbSql)
|
e := gormx.GetBy(dbSql)
|
||||||
|
|
||||||
dbSql.SetBaseInfo(account)
|
dbSql.SetBaseInfo(account)
|
||||||
// 更新sql信息
|
// 更新sql信息
|
||||||
dbSql.Sql = dbSqlForm.Sql
|
dbSql.Sql = dbSqlForm.Sql
|
||||||
if e == nil {
|
if e == nil {
|
||||||
model.UpdateById(dbSql)
|
gormx.UpdateById(dbSql)
|
||||||
} else {
|
} 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 := &entity.DbSql{Type: 1, DbId: id, Db: db}
|
||||||
dbSql.CreatorId = rc.LoginAccount.Id
|
dbSql.CreatorId = rc.LoginAccount.Id
|
||||||
var sqls []entity.DbSql
|
var sqls []entity.DbSql
|
||||||
model.ListBy(dbSql, &sqls, "id", "name")
|
gormx.ListBy(dbSql, &sqls, "id", "name")
|
||||||
|
|
||||||
rc.ResData = sqls
|
rc.ResData = sqls
|
||||||
}
|
}
|
||||||
@@ -418,7 +427,7 @@ func (d *Db) DeleteSql(rc *req.Ctx) {
|
|||||||
dbSql.Name = rc.GinCtx.Query("name")
|
dbSql.Name = rc.GinCtx.Query("name")
|
||||||
dbSql.Db = rc.GinCtx.Query("db")
|
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.CreatorId = rc.LoginAccount.Id
|
||||||
dbSql.Name = rc.GinCtx.Query("name")
|
dbSql.Name = rc.GinCtx.Query("name")
|
||||||
|
|
||||||
e := model.GetBy(dbSql)
|
e := gormx.GetBy(dbSql)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
type Db interface {
|
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
|
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...)
|
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ type DbSqlExec interface {
|
|||||||
DeleteBy(condition *entity.DbSqlExec)
|
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 {
|
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
||||||
@@ -151,7 +151,7 @@ func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
|||||||
d.dbSqlExecRepo.DeleteBy(condition)
|
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...)
|
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type Db interface {
|
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
|
Count(condition *entity.DbQuery) int64
|
||||||
|
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ type DbSqlExec interface {
|
|||||||
DeleteBy(condition *entity.DbSqlExec)
|
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]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"mayfly-go/internal/db/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/internal/db/domain/repository"
|
"mayfly-go/internal/db/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type dbRepoImpl struct{}
|
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 {
|
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
sql := "SELECT d.* FROM t_db d WHERE 1 = 1 "
|
qd := gormx.NewQuery(new(entity.Db)).
|
||||||
|
Like("host", condition.Host).
|
||||||
values := make([]any, 0)
|
Like("database", condition.Database).
|
||||||
if condition.Host != "" {
|
In("tag_id", condition.TagIds).
|
||||||
sql = sql + " AND d.host LIKE ?"
|
RLike("tag_path", condition.TagPathLike).
|
||||||
values = append(values, "%"+condition.Host+"%")
|
OrderByAsc("tag_path")
|
||||||
}
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
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) Count(condition *entity.DbQuery) int64 {
|
func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
||||||
@@ -48,18 +33,18 @@ func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
|||||||
if condition.TagId != 0 {
|
if condition.TagId != 0 {
|
||||||
where["tag_id"] = condition.TagId
|
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 {
|
func (d *dbRepoImpl) GetDb(condition *entity.Db, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return gormx.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
||||||
db := new(entity.Db)
|
db := new(entity.Db)
|
||||||
if err := model.GetById(db, id, cols...); err != nil {
|
if err := gormx.GetById(db, id, cols...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -67,13 +52,13 @@ func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbRepoImpl) Insert(db *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) {
|
func (d *dbRepoImpl) Update(db *entity.Db) {
|
||||||
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
|
biz.ErrIsNil(gormx.UpdateById(db), "更新数据库信息失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbRepoImpl) Delete(id uint64) {
|
func (d *dbRepoImpl) Delete(id uint64) {
|
||||||
model.DeleteById(new(entity.Db), id)
|
gormx.DeleteById(new(entity.Db), id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/db/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/internal/db/domain/repository"
|
"mayfly-go/internal/db/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/gormx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dbSqlRepoImpl struct{}
|
type dbSqlRepoImpl struct{}
|
||||||
@@ -15,5 +15,5 @@ func newDbSqlRepo() repository.DbSql {
|
|||||||
|
|
||||||
// 分页获取数据库信息列表
|
// 分页获取数据库信息列表
|
||||||
func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
|
func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
|
||||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
|
biz.ErrIsNil(gormx.DeleteByCondition(condition), "删除sql失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/db/domain/entity"
|
"mayfly-go/internal/db/domain/entity"
|
||||||
"mayfly-go/internal/db/domain/repository"
|
"mayfly-go/internal/db/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,14 +15,15 @@ func newDbSqlExecRepo() repository.DbSqlExec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
|
func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
|
||||||
model.Insert(dse)
|
gormx.Insert(dse)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
|
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 {
|
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import (
|
|||||||
"mayfly-go/internal/machine/api/vo"
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/machine/application"
|
"mayfly-go/internal/machine/application"
|
||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthCert struct {
|
type AuthCert struct {
|
||||||
@@ -58,5 +61,13 @@ func (c *AuthCert) SaveAuthCert(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *AuthCert) Delete(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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -40,19 +41,18 @@ func (m *Machine) Machines(rc *req.Ctx) {
|
|||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
if len(tagIds) == 0 {
|
if len(tagIds) == 0 {
|
||||||
rc.ResData = model.EmptyPageResult()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
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 {
|
if res.Total == 0 {
|
||||||
rc.ResData = res
|
rc.ResData = res
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
list := res.List.(*[]*vo.MachineVO)
|
for _, mv := range *res.List {
|
||||||
for _, mv := range *list {
|
|
||||||
mv.HasCli = machine.HasCli(mv.Id)
|
mv.HasCli = machine.HasCli(mv.Id)
|
||||||
}
|
}
|
||||||
rc.ResData = res
|
rc.ResData = res
|
||||||
@@ -99,9 +99,15 @@ func (m *Machine) ChangeStatus(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) DeleteMachine(rc *req.Ctx) {
|
func (m *Machine) DeleteMachine(rc *req.Ctx) {
|
||||||
id := uint64(ginx.PathParamInt(rc.GinCtx, "machineId"))
|
idsStr := ginx.PathParam(rc.GinCtx, "machineId")
|
||||||
rc.ReqParam = id
|
rc.ReqParam = idsStr
|
||||||
m.MachineApp.Delete(id)
|
ids := strings.Split(idsStr, ",")
|
||||||
|
|
||||||
|
for _, v := range ids {
|
||||||
|
value, err := strconv.Atoi(v)
|
||||||
|
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||||
|
m.MachineApp.Delete(uint64(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭机器客户端
|
// 关闭机器客户端
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AuthCert interface {
|
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)
|
Save(ac *entity.AuthCert)
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ type authCertAppImpl struct {
|
|||||||
authCertRepo repository.AuthCert
|
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)
|
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/internal/machine/infrastructure/machine"
|
"mayfly-go/internal/machine/infrastructure/machine"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -30,7 +32,7 @@ type Machine interface {
|
|||||||
GetById(id uint64, cols ...string) *entity.Machine
|
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
|
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...)
|
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) {
|
func (m *machineAppImpl) Delete(id uint64) {
|
||||||
// 关闭连接
|
// 关闭连接
|
||||||
machine.DeleteCli(id)
|
machine.DeleteCli(id)
|
||||||
model.Tx(
|
gormx.Tx(
|
||||||
func(db *gorm.DB) error {
|
func(db *gorm.DB) error {
|
||||||
// 删除machine表信息
|
// 删除machine表信息
|
||||||
return db.Delete(new(entity.Machine), "id = ?", id).Error
|
return db.Delete(new(entity.Machine), "id = ?", id).Error
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/internal/machine/infrastructure/machine"
|
"mayfly-go/internal/machine/infrastructure/machine"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,7 +18,7 @@ import (
|
|||||||
|
|
||||||
type MachineFile interface {
|
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
|
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...)
|
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"), "该机器不存在")
|
biz.NotNil(m.machineRepo.GetById(entity.MachineId, "Name"), "该机器不存在")
|
||||||
|
|
||||||
if entity.Id != 0 {
|
if entity.Id != 0 {
|
||||||
model.UpdateById(entity)
|
gormx.UpdateById(entity)
|
||||||
} else {
|
} else {
|
||||||
model.Insert(entity)
|
gormx.Insert(entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MachineScript interface {
|
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
|
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
||||||
@@ -40,7 +41,7 @@ const Common_Script_Machine_Id = 9999999
|
|||||||
// machineScriptRepo: persistence.MachineScriptDao}
|
// 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...)
|
return m.machineScriptRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +63,9 @@ func (m *machineScriptAppImpl) Save(entity *entity.MachineScript) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if entity.Id != 0 {
|
if entity.Id != 0 {
|
||||||
model.UpdateById(entity)
|
gormx.UpdateById(entity)
|
||||||
} else {
|
} else {
|
||||||
model.Insert(entity)
|
gormx.Insert(entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AuthCert interface {
|
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)
|
Insert(ac *entity.AuthCert)
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Machine interface {
|
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
|
Count(condition *entity.MachineQuery) int64
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type MachineFile interface {
|
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
|
GetMachineFile(condition *entity.MachineFile, cols ...string) error
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type MachineScript interface {
|
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
|
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MachineTaskConfig interface {
|
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
|
GetBy(condition *entity.MachineTaskConfig, cols ...string) error
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,21 +14,22 @@ func newAuthCertRepo() repository.AuthCert {
|
|||||||
return new(authCertRepoImpl)
|
return new(authCertRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *authCertRepoImpl) Insert(ac *entity.AuthCert) {
|
func (m *authCertRepoImpl) Insert(ac *entity.AuthCert) {
|
||||||
biz.ErrIsNil(model.Insert(ac), "新增授权凭证失败")
|
biz.ErrIsNil(gormx.Insert(ac), "新增授权凭证失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *authCertRepoImpl) Update(ac *entity.AuthCert) {
|
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 {
|
func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
|
||||||
ac := new(entity.AuthCert)
|
ac := new(entity.AuthCert)
|
||||||
err := model.GetById(ac, id)
|
err := gormx.GetById(ac, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -36,14 +38,14 @@ func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
|
|||||||
|
|
||||||
func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
||||||
acs := new([]*entity.AuthCert)
|
acs := new([]*entity.AuthCert)
|
||||||
model.GetByIdIn(new(entity.AuthCert), acs, ids)
|
gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
|
||||||
return *acs
|
return *acs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *authCertRepoImpl) GetByCondition(condition *entity.AuthCert, cols ...string) error {
|
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) {
|
func (m *authCertRepoImpl) DeleteById(id uint64) {
|
||||||
model.DeleteById(new(entity.AuthCert), id)
|
gormx.DeleteById(new(entity.AuthCert), id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"mayfly-go/internal/machine/api/vo"
|
||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"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 {
|
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO] {
|
||||||
sql := "SELECT m.* FROM t_machine m WHERE 1 = 1 "
|
qd := gormx.NewQuery(new(entity.Machine)).
|
||||||
|
Like("ip", condition.Ip).
|
||||||
values := make([]any, 0)
|
Like("name", condition.Name).
|
||||||
if condition.Ip != "" {
|
In("tag_id", condition.TagIds).
|
||||||
sql = sql + " AND m.ip LIKE ?"
|
RLike("tag_path", condition.TagPathLike).
|
||||||
values = append(values, "%"+condition.Ip+"%")
|
OrderByAsc("tag_path")
|
||||||
}
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
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) Count(condition *entity.MachineQuery) int64 {
|
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
|
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 {
|
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return gormx.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||||
machine := new(entity.Machine)
|
machine := new(entity.Machine)
|
||||||
if err := model.GetById(machine, id, cols...); err != nil {
|
if err := gormx.GetById(machine, id, cols...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -67,9 +54,9 @@ func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *machineRepoImpl) Create(entity *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) {
|
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
|
||||||
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
|
biz.ErrIsNilAppendErr(gormx.UpdateById(entity), "更新机器信息失败: %s")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"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 {
|
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据条件获取账号信息
|
// 根据条件获取账号信息
|
||||||
func (m *machineFileRepoImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
func (m *machineFileRepoImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return gormx.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.MachineFile {
|
func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.MachineFile {
|
||||||
ms := new(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
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,13 +37,13 @@ func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.Machine
|
|||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (m *machineFileRepoImpl) Delete(id uint64) {
|
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) {
|
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) {
|
||||||
model.Insert(entity)
|
gormx.Insert(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
|
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
|
||||||
model.UpdateById(entity)
|
gormx.UpdateById(entity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/machine/domain/entity"
|
"mayfly-go/internal/machine/domain/entity"
|
||||||
"mayfly-go/internal/machine/domain/repository"
|
"mayfly-go/internal/machine/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"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 {
|
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据条件获取账号信息
|
// 根据条件获取账号信息
|
||||||
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return gormx.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
||||||
ms := new(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
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,13 +37,13 @@ func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.Machi
|
|||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (m *machineScriptRepoImpl) Delete(id uint64) {
|
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) {
|
func (m *machineScriptRepoImpl) Create(entity *entity.MachineScript) {
|
||||||
model.Insert(entity)
|
gormx.Insert(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
|
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
|
||||||
model.UpdateById(entity)
|
gormx.UpdateById(entity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@@ -32,7 +33,7 @@ func (m *Mongo) Mongos(rc *req.Ctx) {
|
|||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
if len(tagIds) == 0 {
|
if len(tagIds) == 0 {
|
||||||
rc.ResData = model.EmptyPageResult()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
condition.TagIds = tagIds
|
||||||
@@ -58,7 +59,15 @@ func (m *Mongo) Save(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mongo) DeleteMongo(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) {
|
func (m *Mongo) Databases(rc *req.Ctx) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
type Mongo interface {
|
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
|
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...)
|
return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type Mongo interface {
|
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
|
Count(condition *entity.MongoQuery) int64
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"mayfly-go/internal/mongo/domain/entity"
|
"mayfly-go/internal/mongo/domain/entity"
|
||||||
"mayfly-go/internal/mongo/domain/repository"
|
"mayfly-go/internal/mongo/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type mongoRepoImpl struct{}
|
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 {
|
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
sql := "SELECT d.* FROM t_mongo d WHERE 1=1 "
|
qd := gormx.NewQuery(new(entity.Mongo)).
|
||||||
|
Like("name", condition.Name).
|
||||||
if len(condition.TagIds) > 0 {
|
In("tag_id", condition.TagIds).
|
||||||
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
|
RLike("tag_path", condition.TagPathLike).
|
||||||
}
|
OrderByAsc("tag_path")
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
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) Count(condition *entity.MongoQuery) int64 {
|
func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
||||||
@@ -41,18 +32,18 @@ func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
|||||||
if condition.TagId != 0 {
|
if condition.TagId != 0 {
|
||||||
where["tag_id"] = condition.TagId
|
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 {
|
func (d *mongoRepoImpl) Get(condition *entity.Mongo, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return gormx.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
||||||
db := new(entity.Mongo)
|
db := new(entity.Mongo)
|
||||||
if err := model.GetById(db, id, cols...); err != nil {
|
if err := gormx.GetById(db, id, cols...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,13 +51,13 @@ func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *mongoRepoImpl) Insert(db *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) {
|
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) {
|
func (d *mongoRepoImpl) Delete(id uint64) {
|
||||||
model.DeleteById(new(entity.Mongo), id)
|
gormx.DeleteById(new(entity.Mongo), id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -30,7 +31,7 @@ func (r *Redis) RedisList(rc *req.Ctx) {
|
|||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
if len(tagIds) == 0 {
|
if len(tagIds) == 0 {
|
||||||
rc.ResData = model.EmptyPageResult()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
condition.TagIds = tagIds
|
||||||
@@ -66,7 +67,15 @@ func (r *Redis) GetRedisPwd(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Redis) DeleteRedis(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) {
|
func (r *Redis) RedisInfo(rc *req.Ctx) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
type Redis interface {
|
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
|
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...)
|
return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type Redis interface {
|
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
|
Count(condition *entity.RedisQuery) int64
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"mayfly-go/internal/redis/domain/entity"
|
"mayfly-go/internal/redis/domain/entity"
|
||||||
"mayfly-go/internal/redis/domain/repository"
|
"mayfly-go/internal/redis/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type redisRepoImpl struct{}
|
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 {
|
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
sql := "SELECT d.* FROM t_redis d WHERE 1=1 "
|
qd := gormx.NewQuery(new(entity.Redis)).
|
||||||
values := make([]any, 0)
|
Like("host", condition.Host).
|
||||||
if condition.Host != "" {
|
In("tag_id", condition.TagIds).
|
||||||
sql = sql + " AND d.host LIKE ?"
|
RLike("tag_path", condition.TagPathLike).
|
||||||
values = append(values, "%"+condition.Host+"%")
|
OrderByAsc("tag_path")
|
||||||
}
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
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) Count(condition *entity.RedisQuery) int64 {
|
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
|
where["tag_id"] = condition.TagId
|
||||||
}
|
}
|
||||||
|
|
||||||
return model.CountByMap(new(entity.Redis), where)
|
return gormx.CountByCond(new(entity.Redis), where)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id获取
|
// 根据id获取
|
||||||
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
|
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
|
||||||
rd := new(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 nil
|
||||||
}
|
}
|
||||||
return rd
|
return rd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *redisRepoImpl) GetRedis(condition *entity.Redis, cols ...string) error {
|
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) {
|
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) {
|
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) {
|
func (r *redisRepoImpl) Delete(id uint64) {
|
||||||
biz.ErrIsNilAppendErr(model.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
biz.ErrIsNilAppendErr(gormx.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -345,9 +345,15 @@ func (a *Account) ChangeStatus(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) DeleteAccount(rc *req.Ctx) {
|
func (a *Account) DeleteAccount(rc *req.Ctx) {
|
||||||
id := uint64(ginx.PathParamInt(rc.GinCtx, "id"))
|
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||||
rc.ReqParam = id
|
rc.ReqParam = idsStr
|
||||||
a.AccountApp.Delete(id)
|
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列表,用户回显角色分配
|
// 获取账号角色id列表,用户回显角色分配
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/api/vo"
|
"mayfly-go/internal/sys/api/vo"
|
||||||
"mayfly-go/internal/sys/application"
|
"mayfly-go/internal/sys/application"
|
||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
@@ -40,7 +41,15 @@ func (r *Role) SaveRole(rc *req.Ctx) {
|
|||||||
|
|
||||||
// 删除角色及其资源关联关系
|
// 删除角色及其资源关联关系
|
||||||
func (r *Role) DelRole(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数组,用于分配资源时回显已拥有的资源
|
// 获取角色关联的资源id数组,用于分配资源时回显已拥有的资源
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ import (
|
|||||||
type Account interface {
|
type Account interface {
|
||||||
GetAccount(condition *entity.Account, cols ...string) error
|
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)
|
Create(account *entity.Account)
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ func (a *accountAppImpl) GetAccount(condition *entity.Account, cols ...string) e
|
|||||||
return a.accountRepo.GetAccount(condition, cols...)
|
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)
|
return a.accountRepo.GetPageList(condition, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ func (a *accountAppImpl) Update(account *entity.Account) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *accountAppImpl) Delete(id uint64) {
|
func (a *accountAppImpl) Delete(id uint64) {
|
||||||
err := model.Tx(
|
err := gormx.Tx(
|
||||||
func(db *gorm.DB) error {
|
func(db *gorm.DB) error {
|
||||||
// 删除account表信息
|
// 删除account表信息
|
||||||
return db.Delete(new(entity.Account), "id = ?", id).Error
|
return db.Delete(new(entity.Account), "id = ?", id).Error
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
const SysConfigKeyPrefix = "sys:config:"
|
const SysConfigKeyPrefix = "sys:config:"
|
||||||
|
|
||||||
type Config interface {
|
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)
|
Save(config *entity.Config)
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ type configAppImpl struct {
|
|||||||
configRepo repository.Config
|
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)
|
return a.configRepo.GetPageList(condition, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Msg interface {
|
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)
|
Create(msg *entity.Msg)
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ type msgAppImpl struct {
|
|||||||
msgRepo repository.Msg
|
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)
|
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/global"
|
"mayfly-go/pkg/global"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -16,8 +16,6 @@ type Resource interface {
|
|||||||
|
|
||||||
GetById(id uint64, cols ...string) *entity.Resource
|
GetById(id uint64, cols ...string) *entity.Resource
|
||||||
|
|
||||||
GetByIdIn(ids []uint64, toEntity any, cols ...string)
|
|
||||||
|
|
||||||
Save(entity *entity.Resource)
|
Save(entity *entity.Resource)
|
||||||
|
|
||||||
ChangeStatus(resourceId uint64, status int8)
|
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...)
|
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) {
|
func (r *resourceAppImpl) Save(resource *entity.Resource) {
|
||||||
// 更新操作
|
// 更新操作
|
||||||
if resource.Id != 0 {
|
if resource.Id != 0 {
|
||||||
@@ -61,7 +55,7 @@ func (r *resourceAppImpl) Save(resource *entity.Resource) {
|
|||||||
r.checkCode(resource.Code)
|
r.checkCode(resource.Code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.UpdateById(resource)
|
gormx.UpdateById(resource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +74,7 @@ func (r *resourceAppImpl) Save(resource *entity.Resource) {
|
|||||||
}
|
}
|
||||||
r.checkCode(resource.Code)
|
r.checkCode(resource.Code)
|
||||||
resource.Weight = int(time.Now().Unix())
|
resource.Weight = int(time.Now().Unix())
|
||||||
model.Insert(resource)
|
gormx.Insert(resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceAppImpl) ChangeStatus(resourceId uint64, status int8) {
|
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) {
|
func (r *resourceAppImpl) checkCode(code string) {
|
||||||
biz.IsTrue(!strings.Contains(code, ","), "code不能包含','")
|
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) {
|
func (r *resourceAppImpl) Delete(id uint64) {
|
||||||
@@ -160,7 +154,7 @@ func (r *resourceAppImpl) Delete(id uint64) {
|
|||||||
for _, v := range children {
|
for _, v := range children {
|
||||||
r.resourceRepo.Delete(v.Id)
|
r.resourceRepo.Delete(v.Id)
|
||||||
// 删除角色关联的资源信息
|
// 删除角色关联的资源信息
|
||||||
model.DeleteByCondition(&entity.RoleResource{ResourceId: v.Id})
|
gormx.DeleteByCondition(&entity.RoleResource{ResourceId: v.Id})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package application
|
|||||||
import (
|
import (
|
||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Role interface {
|
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)
|
SaveRole(role *entity.Role)
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ type roleAppImpl struct {
|
|||||||
roleRepo repository.Role
|
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...)
|
return m.roleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,17 +55,17 @@ func (m *roleAppImpl) SaveRole(role *entity.Role) {
|
|||||||
if role.Id != 0 {
|
if role.Id != 0 {
|
||||||
// code不可更改,防止误传
|
// code不可更改,防止误传
|
||||||
role.Code = ""
|
role.Code = ""
|
||||||
model.UpdateById(role)
|
gormx.UpdateById(role)
|
||||||
} else {
|
} else {
|
||||||
role.Status = 1
|
role.Status = 1
|
||||||
model.Insert(role)
|
gormx.Insert(role)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleAppImpl) DeleteRole(id uint64) {
|
func (m *roleAppImpl) DeleteRole(id uint64) {
|
||||||
m.roleRepo.Delete(id)
|
m.roleRepo.Delete(id)
|
||||||
// 删除角色与资源的关联关系
|
// 删除角色与资源的关联关系
|
||||||
model.DeleteByCondition(&entity.RoleResource{RoleId: id})
|
gormx.DeleteByCondition(&entity.RoleResource{RoleId: id})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Syslog interface {
|
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)
|
SaveFromReq(req *req.Ctx)
|
||||||
@@ -29,7 +29,7 @@ type syslogAppImpl struct {
|
|||||||
syslogRepo repository.Syslog
|
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...)
|
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ type Account interface {
|
|||||||
// 根据条件获取账号信息
|
// 根据条件获取账号信息
|
||||||
GetAccount(condition *entity.Account, cols ...string) error
|
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)
|
Insert(account *entity.Account)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config interface {
|
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)
|
Insert(config *entity.Config)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Msg interface {
|
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)
|
Insert(msg *entity.Msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ type Resource interface {
|
|||||||
|
|
||||||
GetById(id uint64, cols ...string) *entity.Resource
|
GetById(id uint64, cols ...string) *entity.Resource
|
||||||
|
|
||||||
GetByIdIn(ids []uint64, toEntity any, orderBy ...string)
|
|
||||||
|
|
||||||
Delete(id uint64)
|
Delete(id uint64)
|
||||||
|
|
||||||
GetByCondition(condition *entity.Resource, cols ...string) error
|
GetByCondition(condition *entity.Resource, cols ...string) error
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Role interface {
|
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)
|
Delete(id uint64)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Syslog interface {
|
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)
|
Insert(log *entity.Syslog)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,24 +15,20 @@ func newAccountRepo() repository.Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *accountRepoImpl) GetAccount(condition *entity.Account, cols ...string) error {
|
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 {
|
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
sql := "SELECT * FROM t_sys_account "
|
qd := gormx.NewQuery(new(entity.Account)).
|
||||||
username := condition.Username
|
Like("name", condition.Name).
|
||||||
values := make([]any, 0)
|
Like("username", condition.Username)
|
||||||
if username != "" {
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
sql = sql + " WHERE username LIKE ?"
|
|
||||||
values = append(values, "%"+username+"%")
|
|
||||||
}
|
|
||||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *accountRepoImpl) Insert(account *entity.Account) {
|
func (m *accountRepoImpl) Insert(account *entity.Account) {
|
||||||
biz.ErrIsNil(model.Insert(account), "新增账号信息失败")
|
biz.ErrIsNil(gormx.Insert(account), "新增账号信息失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *accountRepoImpl) Update(account *entity.Account) {
|
func (m *accountRepoImpl) Update(account *entity.Account) {
|
||||||
biz.ErrIsNil(model.UpdateById(account), "更新账号信息失败")
|
biz.ErrIsNil(gormx.UpdateById(account), "更新账号信息失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,22 +14,23 @@ func newConfigRepo() repository.Config {
|
|||||||
return new(configRepoImpl)
|
return new(configRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *configRepoImpl) Insert(config *entity.Config) {
|
func (m *configRepoImpl) Insert(config *entity.Config) {
|
||||||
biz.ErrIsNil(model.Insert(config), "新增系统配置失败")
|
biz.ErrIsNil(gormx.Insert(config), "新增系统配置失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *configRepoImpl) Update(config *entity.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 {
|
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 {
|
func (r *configRepoImpl) GetByCondition(condition *entity.Config, cols ...string) error {
|
||||||
return model.GetBy(condition, cols...)
|
return gormx.GetBy(condition, cols...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,10 +14,11 @@ func newMsgRepo() repository.Msg {
|
|||||||
return new(msgRepoImpl)
|
return new(msgRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *msgRepoImpl) Insert(account *entity.Msg) {
|
func (m *msgRepoImpl) Insert(account *entity.Msg) {
|
||||||
biz.ErrIsNil(model.Insert(account), "新增消息记录失败")
|
biz.ErrIsNil(gormx.Insert(account), "新增消息记录失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/gormx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type resourceRepoImpl struct{}
|
type resourceRepoImpl struct{}
|
||||||
@@ -14,40 +14,36 @@ func newResourceRepo() repository.Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceRepoImpl) GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string) {
|
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 {
|
func (r *resourceRepoImpl) GetById(id uint64, cols ...string) *entity.Resource {
|
||||||
res := new(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 nil
|
||||||
|
|
||||||
}
|
}
|
||||||
return res
|
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) {
|
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 {
|
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 {
|
func (r *resourceRepoImpl) GetChildren(uiPath string) []entity.Resource {
|
||||||
sql := "SELECT id, ui_path FROM t_sys_resource WHERE ui_path LIKE ?"
|
sql := "SELECT id, ui_path FROM t_sys_resource WHERE ui_path LIKE ?"
|
||||||
var rs []entity.Resource
|
var rs []entity.Resource
|
||||||
model.GetListBySql2Model(sql, &rs, uiPath+"%")
|
gormx.GetListBySql2Model(sql, &rs, uiPath+"%")
|
||||||
return rs
|
return rs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceRepoImpl) UpdateByUiPathLike(resource *entity.Resource) {
|
func (r *resourceRepoImpl) UpdateByUiPathLike(resource *entity.Resource) {
|
||||||
sql := "UPDATE t_sys_resource SET status=? WHERE (ui_path LIKE ?)"
|
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) {
|
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||||
@@ -84,5 +80,5 @@ func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
m.pid ASC,
|
m.pid ASC,
|
||||||
m.weight ASC`
|
m.weight ASC`
|
||||||
biz.ErrIsNilAppendErr(model.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
|
biz.ErrIsNilAppendErr(gormx.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,12 +14,13 @@ func newRoleRepo() repository.Role {
|
|||||||
return new(roleRepoImpl)
|
return new(roleRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleRepoImpl) Delete(id uint64) {
|
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表获取
|
// 获取角色拥有的资源id数组,从role_resource表获取
|
||||||
@@ -26,7 +28,7 @@ func (m *roleRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
|||||||
var rrs []entity.RoleResource
|
var rrs []entity.RoleResource
|
||||||
|
|
||||||
condtion := &entity.RoleResource{RoleId: roleId}
|
condtion := &entity.RoleResource{RoleId: roleId}
|
||||||
model.ListBy(condtion, &rrs, "ResourceId")
|
gormx.ListBy(condtion, &rrs, "ResourceId")
|
||||||
|
|
||||||
var rids []uint64
|
var rids []uint64
|
||||||
for _, v := range rrs {
|
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 " +
|
"FROM t_sys_role_resource rr JOIN t_sys_resource r ON rr.resource_id = r.id " +
|
||||||
"WHERE rr.role_id = ? " +
|
"WHERE rr.role_id = ? " +
|
||||||
"ORDER BY r.pid ASC, r.weight ASC"
|
"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) {
|
func (m *roleRepoImpl) SaveRoleResource(rr *entity.RoleResource) {
|
||||||
model.Insert(rr)
|
gormx.Insert(rr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleRepoImpl) DeleteRoleResource(roleId uint64, resourceId uint64) {
|
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 {
|
func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
|
||||||
var rrs []entity.AccountRole
|
var rrs []entity.AccountRole
|
||||||
|
|
||||||
condtion := &entity.AccountRole{AccountId: accountId}
|
condtion := &entity.AccountRole{AccountId: accountId}
|
||||||
model.ListBy(condtion, &rrs, "RoleId")
|
gormx.ListBy(condtion, &rrs, "RoleId")
|
||||||
|
|
||||||
var rids []uint64
|
var rids []uint64
|
||||||
for _, v := range rrs {
|
for _, v := range rrs {
|
||||||
@@ -66,11 +68,11 @@ func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleRepoImpl) SaveAccountRole(ar *entity.AccountRole) {
|
func (m *roleRepoImpl) SaveAccountRole(ar *entity.AccountRole) {
|
||||||
model.Insert(ar)
|
gormx.Insert(ar)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *roleRepoImpl) DeleteAccountRole(accountId, roleId uint64) {
|
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 " +
|
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 = ? " +
|
"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"
|
"ORDER BY ar.create_time DESC"
|
||||||
model.GetListBySql2Model(sql, toEntity, accountId)
|
gormx.GetListBySql2Model(sql, toEntity, accountId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package persistence
|
|||||||
import (
|
import (
|
||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/internal/sys/domain/repository"
|
"mayfly-go/internal/sys/domain/repository"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,10 +13,11 @@ func newSyslogRepo() repository.Syslog {
|
|||||||
return new(syslogRepoImpl)
|
return new(syslogRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *syslogRepoImpl) Insert(syslog *entity.Syslog) {
|
func (m *syslogRepoImpl) Insert(syslog *entity.Syslog) {
|
||||||
model.Insert(syslog)
|
gormx.Insert(syslog)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Team struct {
|
type Team struct {
|
||||||
@@ -48,7 +50,15 @@ func (p *Team) SaveTeam(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Team) DelTeam(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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取团队的成员信息
|
// 获取团队的成员信息
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type Team interface {
|
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)
|
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)
|
SaveMember(tagTeamMember *entity.TeamMember)
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ type teamAppImpl struct {
|
|||||||
tagTreeTeamRepo repository.TagTreeTeam
|
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...)
|
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) {
|
func (p *teamAppImpl) Delete(id uint64) {
|
||||||
p.teamRepo.Delete(id)
|
p.teamRepo.Delete(id)
|
||||||
p.teamMemberRepo.DeleteBy(&entity.TeamMember{TeamId: 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)
|
return p.teamMemberRepo.GetPageList(condition, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Team interface {
|
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)
|
Insert(p *entity.Team)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type TeamMember interface {
|
|||||||
|
|
||||||
Save(mp *entity.TeamMember)
|
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)
|
DeleteBy(condition *entity.TeamMember)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"mayfly-go/internal/tag/domain/entity"
|
"mayfly-go/internal/tag/domain/entity"
|
||||||
"mayfly-go/internal/tag/domain/repository"
|
"mayfly-go/internal/tag/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/gormx"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,29 +49,29 @@ func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEn
|
|||||||
sql = sql + ")"
|
sql = sql + ")"
|
||||||
}
|
}
|
||||||
sql = sql + " ORDER BY p.code_path"
|
sql = sql + " ORDER BY p.code_path"
|
||||||
model.GetListBySql2Model(sql, toEntity)
|
gormx.GetListBySql2Model(sql, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *tagTreeRepoImpl) SelectById(id uint64) *entity.TagTree {
|
func (p *tagTreeRepoImpl) SelectById(id uint64) *entity.TagTree {
|
||||||
pt := new(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 nil
|
||||||
}
|
}
|
||||||
return pt
|
return pt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *tagTreeRepoImpl) GetBy(condition *entity.TagTree, cols ...string) error {
|
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) {
|
func (p *tagTreeRepoImpl) Insert(tagTree *entity.TagTree) {
|
||||||
biz.ErrIsNil(model.Insert(tagTree), "新增标签失败")
|
biz.ErrIsNil(gormx.Insert(tagTree), "新增标签失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *tagTreeRepoImpl) UpdateById(tagTree *entity.TagTree) {
|
func (p *tagTreeRepoImpl) UpdateById(tagTree *entity.TagTree) {
|
||||||
biz.ErrIsNil(model.UpdateById(tagTree), "更新标签失败")
|
biz.ErrIsNil(gormx.UpdateById(tagTree), "更新标签失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *tagTreeRepoImpl) Delete(id uint64) {
|
func (p *tagTreeRepoImpl) Delete(id uint64) {
|
||||||
model.DeleteById(new(entity.TagTree), id)
|
gormx.DeleteById(new(entity.TagTree), id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/tag/domain/entity"
|
"mayfly-go/internal/tag/domain/entity"
|
||||||
"mayfly-go/internal/tag/domain/repository"
|
"mayfly-go/internal/tag/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/gormx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tagTreeTeamRepoImpl struct{}
|
type tagTreeTeamRepoImpl struct{}
|
||||||
@@ -14,19 +14,19 @@ func newTagTreeTeamRepo() repository.TagTreeTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *tagTreeTeamRepoImpl) ListTag(condition *entity.TagTreeTeam, toEntity any, orderBy ...string) {
|
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) {
|
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) {
|
func (p *tagTreeTeamRepoImpl) DeleteBy(condition *entity.TagTreeTeam) {
|
||||||
model.DeleteByCondition(condition)
|
gormx.DeleteByCondition(condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *tagTreeTeamRepoImpl) SelectTagPathsByAccountId(accountId uint64) []string {
|
func (p *tagTreeTeamRepoImpl) SelectTagPathsByAccountId(accountId uint64) []string {
|
||||||
var res []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
|
return res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"mayfly-go/internal/tag/domain/entity"
|
"mayfly-go/internal/tag/domain/entity"
|
||||||
"mayfly-go/internal/tag/domain/repository"
|
"mayfly-go/internal/tag/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,22 +14,23 @@ func newTeamRepo() repository.Team {
|
|||||||
return new(teamRepoImpl)
|
return new(teamRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *teamRepoImpl) Insert(team *entity.Team) {
|
func (p *teamRepoImpl) Insert(team *entity.Team) {
|
||||||
biz.ErrIsNil(model.Insert(team), "新增团队失败")
|
biz.ErrIsNil(gormx.Insert(team), "新增团队失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *teamRepoImpl) UpdateById(team *entity.Team) {
|
func (p *teamRepoImpl) UpdateById(team *entity.Team) {
|
||||||
biz.ErrIsNil(model.UpdateById(team), "更新团队失败")
|
biz.ErrIsNil(gormx.UpdateById(team), "更新团队失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *teamRepoImpl) Delete(id uint64) {
|
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) {
|
func (p *teamRepoImpl) DeleteBy(team *entity.Team) {
|
||||||
model.DeleteByCondition(team)
|
gormx.DeleteByCondition(team)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"mayfly-go/internal/tag/domain/entity"
|
"mayfly-go/internal/tag/domain/entity"
|
||||||
"mayfly-go/internal/tag/domain/repository"
|
"mayfly-go/internal/tag/domain/repository"
|
||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
|
"mayfly-go/pkg/gormx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,36 +15,28 @@ func newTeamMemberRepo() repository.TeamMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string) {
|
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) {
|
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 {
|
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any] {
|
||||||
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 "
|
qd := gormx.NewQuery(new(entity.TeamMember)).
|
||||||
|
Select("t_team_member.*, a.name").
|
||||||
if condition.AccountId != 0 {
|
Joins("JOIN t_sys_account a ON t_team_member.account_id = a.id AND a.status = 1").
|
||||||
sql = fmt.Sprintf("%s AND d.account_id = %d", sql, condition.AccountId)
|
Eq("account_id", condition.AccountId).
|
||||||
}
|
Eq("team_id", condition.TeamId).
|
||||||
if condition.TeamId != 0 {
|
Like("a.username", condition.Username).
|
||||||
sql = fmt.Sprintf("%s AND d.team_id = %d", sql, condition.TeamId)
|
OrderByDesc("t_team_member.id")
|
||||||
}
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
|
|
||||||
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) DeleteBy(condition *entity.TeamMember) {
|
func (p *teamMemberRepoImpl) DeleteBy(condition *entity.TeamMember) {
|
||||||
model.DeleteByCondition(condition)
|
gormx.DeleteByCondition(condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *teamMemberRepoImpl) IsExist(teamId, accountId uint64) bool {
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
33
server/pkg/consts/gormx.go
Normal file
33
server/pkg/consts/gormx.go
Normal 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"
|
||||||
|
)
|
||||||
@@ -53,10 +53,16 @@ func QueryInt(g *gin.Context, qm string, defaultInt int) int {
|
|||||||
|
|
||||||
// 获取路径参数
|
// 获取路径参数
|
||||||
func PathParamInt(g *gin.Context, pm string) 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
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取路径参数
|
||||||
|
func PathParam(g *gin.Context, pm string) string {
|
||||||
|
return g.Param(pm)
|
||||||
|
}
|
||||||
|
|
||||||
// 文件下载
|
// 文件下载
|
||||||
func Download(g *gin.Context, reader io.Reader, filename string) {
|
func Download(g *gin.Context, reader io.Reader, filename string) {
|
||||||
g.Header("Content-Type", "application/octet-stream")
|
g.Header("Content-Type", "application/octet-stream")
|
||||||
|
|||||||
137
server/pkg/gormx/gormx.go
Normal file
137
server/pkg/gormx/gormx.go
Normal 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类型不为0,ptr类型不为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
143
server/pkg/gormx/query.go
Normal 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
|
||||||
|
}
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"mayfly-go/pkg/biz"
|
|
||||||
"mayfly-go/pkg/global"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
@@ -43,195 +35,3 @@ func (m *Model) SetBaseInfo(account *LoginAccount) {
|
|||||||
m.Modifier = name
|
m.Modifier = name
|
||||||
m.ModifierId = id
|
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类型不为0,ptr类型不为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...)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ type PageParam struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分页结果
|
// 分页结果
|
||||||
type PageResult struct {
|
type PageResult[T any] struct {
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
List any `json:"list"`
|
List T `json:"list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 空分页结果日志
|
// 空分页结果
|
||||||
func EmptyPageResult() *PageResult {
|
func EmptyPageResult[T any]() *PageResult[T] {
|
||||||
return &PageResult{Total: 0, List: make([]any, 0)}
|
return &PageResult[T]{Total: 0}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user